Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rework the ColorPaletteMoreColors feature #10505

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/base/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { JSX } from "./jsx-runtime.d.ts";
export type UI5CustomEvent<T extends UI5Element, N extends keyof T["eventDetails"]> = CustomEvent<T["eventDetails"][N]>;
export type JsxTemplateResult = JSX.Element | void;
export type JsxTemplate = () => JsxTemplateResult;
export type JsxTemplateModule = { default: JsxTemplate };

export type * from "./types.d.ts";
export type * from "./jsx-runtime.d.ts";
39 changes: 18 additions & 21 deletions packages/main/src/ColorPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation
import type { ITabbable } from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
import ItemNavigationBehavior from "@ui5/webcomponents-base/dist/types/ItemNavigationBehavior.js";
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
import type { JsxTemplateModule } from "@ui5/webcomponents-base/dist/index.js";
import {
isSpace,
isEnter,
isDown,
isUp,
isTabNext,
} from "@ui5/webcomponents-base/dist/Keys.js";
import { getComponentFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
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 ColorPaletteMoreColors from "./features/ColorPaletteMoreColors.js";
import type ColorPicker from "./ColorPicker.js";

import {
COLORPALETTE_CONTAINER_LABEL,
COLOR_PALETTE_MORE_COLORS_TEXT,
COLOR_PALETTE_DEFAULT_COLOR_TEXT,
COLOR_PALETTE_DIALOG_CANCEL_BUTTON,
COLOR_PALETTE_DIALOG_OK_BUTTON,
COLOR_PALETTE_DIALOG_TITLE,
} from "./generated/i18n/i18n-defaults.js";

// Styles
Expand Down Expand Up @@ -73,7 +75,6 @@ type ColorPaletteItemClickEventDetail = {
@customElement({
tag: "ui5-color-palette",
renderer: jsxRenderer,
features: ["ColorPaletteMoreColors"],
template: ColorPaletteTemplate,
styles: [ColorPaletteCss, ColorPaletteDialogCss],
})
Expand Down Expand Up @@ -148,6 +149,13 @@ class ColorPalette extends UI5Element {
@property({ type: Boolean })
onPhone = false;

/**
* The showMoreColors template module.
* @private
*/
@property({ type: Object })
showMoreColorsTemplateModule?: JsxTemplateModule;

/**
* Defines the `ui5-color-palette-item` elements.
* @public
Expand All @@ -164,7 +172,6 @@ class ColorPalette extends UI5Element {
_itemNavigation: ItemNavigation;
_itemNavigationRecentColors: ItemNavigation;
_recentColors: Array<string>;
moreColorsFeature?: ColorPaletteMoreColors;
_currentlySelected?: ColorPaletteItem;
_shouldFocusRecentColors = false;

Expand Down Expand Up @@ -201,21 +208,15 @@ class ColorPalette extends UI5Element {
item.index = index + 1;
});

if (this.showMoreColors) {
const ColorPaletteMoreColorsClass = getComponentFeature<typeof ColorPaletteMoreColors>("ColorPaletteMoreColors");
if (ColorPaletteMoreColorsClass) {
ColorPaletteMoreColorsClass.i18nBundle = ColorPalette.i18nBundle;
this.moreColorsFeature = new ColorPaletteMoreColorsClass();
}
if (this.showMoreColors && !this.showMoreColorsTemplateModule) {
import("./features/ColorPaletteMoreColorsTemplate.js").then(module => {
this.showMoreColorsTemplateModule = module;
});
}

this.onPhone = isPhone();
}

get _effectiveShowMoreColors() {
return !!(this.showMoreColors && this.moreColorsFeature);
}

onAfterRendering() {
if (this.hasRecentColors && this._shouldFocusRecentColors) {
if (this.selectedItem) {
Expand Down Expand Up @@ -526,15 +527,15 @@ class ColorPalette extends UI5Element {
}

get colorPaletteDialogTitle() {
return this.moreColorsFeature?.colorPaletteDialogTitle;
return ColorPalette.i18nBundle.getText(COLOR_PALETTE_DIALOG_TITLE);
}

get colorPaletteDialogOKButton() {
return this.moreColorsFeature?.colorPaletteDialogOKButton;
return ColorPalette.i18nBundle.getText(COLOR_PALETTE_DIALOG_OK_BUTTON);
}

get colorPaletteCancelButton() {
return this.moreColorsFeature?.colorPaletteCancelButton;
return ColorPalette.i18nBundle.getText(COLOR_PALETTE_DIALOG_CANCEL_BUTTON);
}

/**
Expand All @@ -561,10 +562,6 @@ class ColorPalette extends UI5Element {
return ColorPalette.i18nBundle.getText(COLOR_PALETTE_DEFAULT_COLOR_TEXT);
}

get _showMoreColors() {
return this.showMoreColors && this.moreColorsFeature;
}

get rowSize() {
return 5;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/ColorPaletteTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ColorPaletteTemplate(this: ColorPalette) {
)}
</div>

{this._showMoreColors &&
{this.showMoreColors &&
<div class="ui5-cp-more-colors-wrapper">
<div class="ui5-cp-separator"></div>
<Button
Expand All @@ -66,7 +66,7 @@ export default function ColorPaletteTemplate(this: ColorPalette) {
}
</div>

{ this._effectiveShowMoreColors && this.moreColorsFeature?.template.call(this) }
{ this.showMoreColors && this.showMoreColorsTemplateModule?.default.call(this) }
</>
);
}
34 changes: 1 addition & 33 deletions packages/main/src/features/ColorPaletteMoreColors.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1 @@
import { ComponentFeature, registerComponentFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
nnaydenow marked this conversation as resolved.
Show resolved Hide resolved
import ColorPaletteMoreColorsTemplate from "./ColorPaletteMoreColorsTemplate.js";

import {
COLOR_PALETTE_DIALOG_CANCEL_BUTTON,
COLOR_PALETTE_DIALOG_OK_BUTTON,
COLOR_PALETTE_DIALOG_TITLE,
} from "../generated/i18n/i18n-defaults.js";

class ColorPaletteMoreColors extends ComponentFeature {
static i18nBundle: I18nBundle;

get template() {
return ColorPaletteMoreColorsTemplate;
}

get colorPaletteDialogTitle() {
return ColorPaletteMoreColors.i18nBundle.getText(COLOR_PALETTE_DIALOG_TITLE);
}

get colorPaletteDialogOKButton() {
return ColorPaletteMoreColors.i18nBundle.getText(COLOR_PALETTE_DIALOG_OK_BUTTON);
}

get colorPaletteCancelButton() {
return ColorPaletteMoreColors.i18nBundle.getText(COLOR_PALETTE_DIALOG_CANCEL_BUTTON);
}
}

registerComponentFeature("ColorPaletteMoreColors", ColorPaletteMoreColors);

export default ColorPaletteMoreColors;
import "./ColorPaletteMoreColorsTemplate.js";
Loading