Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 6bb2d50

Browse files
feat(#353): use color picker to select code's colors
1 parent 1649a13 commit 6bb2d50

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

studio/src/app/popovers/editor/app-code/app-code.tsx

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export class AppCode {
3838
@Prop()
3939
codeDidChange: EventEmitter<HTMLElement>;
4040

41-
private hidePopoverTimer;
42-
4341
private prismService: PrismService;
4442

4543
private currentLanguage: string = 'javascript';
@@ -98,20 +96,18 @@ export class AppCode {
9896
});
9997
}
10098

101-
private selectColor($event, colorFunction: Function): Promise<void> {
99+
private selectColor($event: CustomEvent, colorFunction: Function): Promise<void> {
102100
return new Promise<void>(async (resolve) => {
103101
if (!this.selectedElement || !this.selectedElement.parentElement) {
104102
resolve();
105103
return;
106104
}
107105

108-
if (!$event || !$event.target || !$event.target.value) {
106+
if (!$event || !$event.detail) {
109107
resolve();
110108
return;
111109
}
112110

113-
await this.privateHideShowPopover();
114-
115111
colorFunction($event);
116112

117113
this.emitCodeDidChange();
@@ -120,34 +116,16 @@ export class AppCode {
120116
});
121117
}
122118

123-
private setCodeColor = ($event) => {
124-
this.codeColor = $event.target.value;
125-
this.selectedElement.style.setProperty(this.getStyle(), $event.target.value);
119+
private setCodeColor = ($event: CustomEvent) => {
120+
this.codeColor = $event.detail.hex;
121+
this.selectedElement.style.setProperty(this.getStyle(), $event.detail.hex);
126122
};
127123

128-
private setHighlightColor = ($event) => {
129-
this.highlightColor = $event.target.value;
130-
this.selectedElement.style.setProperty('--deckgo-highlight-code-line-background', $event.target.value);
124+
private setHighlightColor = ($event: CustomEvent) => {
125+
this.highlightColor = $event.detail.hex;
126+
this.selectedElement.style.setProperty('--deckgo-highlight-code-line-background', $event.detail.hex);
131127
};
132128

133-
private privateHideShowPopover(): Promise<void> {
134-
return new Promise<void>((resolve) => {
135-
const popover: HTMLIonPopoverElement = this.el.closest('ion-popover');
136-
137-
popover.style.visibility = 'hidden';
138-
139-
if (this.hidePopoverTimer) {
140-
clearTimeout(this.hidePopoverTimer);
141-
}
142-
143-
this.hidePopoverTimer = setTimeout(() => {
144-
popover.style.visibility = 'initial';
145-
}, 1000);
146-
147-
resolve();
148-
});
149-
}
150-
151129
private toggleCodeLanguage($event: CustomEvent): Promise<void> {
152130
return new Promise<void>(async (resolve) => {
153131
if (!this.selectedElement) {
@@ -432,9 +410,9 @@ export class AppCode {
432410
</ion-item>
433411

434412
<ion-item disabled={this.codeColorType === undefined}>
435-
<ion-label>Color</ion-label>
436-
<input type="color" value={this.codeColor}
437-
onChange={(e) => this.selectColor(e, this.setCodeColor)}></input>
413+
<deckgo-color class="ion-padding-top ion-padding-bottom" onColorChange={($event: CustomEvent) => this.selectColor($event, this.setCodeColor)} color-hex={this.codeColor}>
414+
<ion-icon name="more" ios="md-mode" md="md-more" slot="more" aria-label="More" class="more"></ion-icon>
415+
</deckgo-color>
438416
</ion-item>
439417

440418
<ion-item-divider class="ion-padding-top">
@@ -451,9 +429,9 @@ export class AppCode {
451429
</ion-item>
452430

453431
<ion-item disabled={!this.highlightLines}>
454-
<ion-label>Color</ion-label>
455-
<input type="color" value={this.highlightColor}
456-
onChange={(e) => this.selectColor(e, this.setHighlightColor)}></input>
432+
<deckgo-color class="ion-padding-top ion-padding-bottom" onColorChange={($event: CustomEvent) => this.selectColor($event, this.setHighlightColor)} color-hex={this.highlightColor}>
433+
<ion-icon name="more" ios="md-mode" md="md-more" slot="more" aria-label="More" class="more"></ion-icon>
434+
</deckgo-color>
457435
</ion-item>
458436
</ion-list>]
459437
}

0 commit comments

Comments
 (0)