Skip to content

Commit

Permalink
chore: rework to be declarative
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev committed Jan 9, 2025
1 parent 927ea9e commit 12ebf81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
38 changes: 20 additions & 18 deletions packages/main/src/ColorPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import ColorPaletteTemplate from "./ColorPaletteTemplate.js";
import type ColorPaletteItem from "./ColorPaletteItem.js";
import type Button from "./Button.js";
import type Dialog from "./Dialog.js";
import type ColorPicker from "./ColorPicker.js";

import {
Expand Down Expand Up @@ -156,6 +155,18 @@ class ColorPalette extends UI5Element {
@property({ type: Object })
showMoreColorsTemplateModule?: JsxTemplateModule;

/**
* @private
*/
@property({ type: Boolean })
dialogOpen = false;

/**
* @private
*/
@property()
colorPickerValue = "rgba(255,255,255,1)";

/**
* Defines the `ui5-color-palette-item` elements.
* @public
Expand Down Expand Up @@ -471,9 +482,12 @@ class ColorPalette extends UI5Element {
return this.colorPaletteNavigationElements[0];
}

onColorPickerChange(e: Event) {
this.colorPickerValue = (e.target as ColorPicker).value;
}

_chooseCustomColor() {
const colorPicker = this.getColorPicker();
this._setColor(colorPicker.value);
this._setColor(this.colorPickerValue);
this._closeDialog();
this._shouldFocusRecentColors = true;
}
Expand All @@ -488,19 +502,16 @@ class ColorPalette extends UI5Element {
}

_closeDialog() {
const dialog = this._getDialog();
dialog.open = false;
this.dialogOpen = false;
}

_openMoreColorsDialog() {
const dialog = this._getDialog();
const colorPicker = this.getColorPicker();
const value = this._currentlySelected ? this._currentlySelected.value : undefined;

if (value) {
colorPicker.value = value;
this.colorPickerValue = value;
}
dialog.open = true;
this.dialogOpen = true;
}

_onDefaultColorClick() {
Expand Down Expand Up @@ -625,15 +636,6 @@ class ColorPalette extends UI5Element {
},
};
}

_getDialog() {
return this.shadowRoot!.querySelector<Dialog>("[ui5-dialog]")!;
}

getColorPicker() {
const dialog = this._getDialog();
return dialog.content[0].querySelector<ColorPicker>("[ui5-color-picker]")!;
}
}

ColorPalette.define();
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/features/ColorPaletteMoreColorsTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import ColorPicker from "../ColorPicker.js";

export default function ColorPaletteMoreColorsTemplate(this: ColorPalette) {
return (
<Dialog headerText={this.colorPaletteDialogTitle}>
<Dialog open={this.dialogOpen} headerText={this.colorPaletteDialogTitle}>
<div class="ui5-cp-dialog-content">
<ColorPicker />
<ColorPicker value={this.colorPickerValue} onChange={this.onColorPickerChange} />
</div>

<div slot="footer" class="ui5-cp-dialog-footer">
Expand Down

0 comments on commit 12ebf81

Please sign in to comment.