From bf9c0d653be5af5473a7b616f2c91803db46beb3 Mon Sep 17 00:00:00 2001 From: Diana Date: Thu, 14 Nov 2024 09:51:10 +0200 Subject: [PATCH] feat(ui5-color-picker): add simplified display mode (#10153) Introducing a new property `displayMode` for the `ui5-color-picker` allowing users to select between the `default` (classic) color picker or the new `simplified` color picker. The simplified picker does not include the RGB inputs and alpha slider. You can create a color picker in simplified mode as follows: Fixes: #9979 --- packages/main/cypress/specs/ColorPicker.cy.ts | 27 ++++ packages/main/src/ColorPicker.hbs | 116 +++++++++--------- packages/main/src/ColorPicker.ts | 14 +++ .../main/src/types/ColorPickerDisplayMode.ts | 19 +++ packages/main/test/pages/ColorPicker.html | 8 ++ .../_components_pages/main/ColorPicker.mdx | 8 +- .../main/ColorPicker/Simplified/Simplified.md | 4 + .../main/ColorPicker/Simplified/main.js | 1 + .../main/ColorPicker/Simplified/sample.html | 20 +++ 9 files changed, 160 insertions(+), 57 deletions(-) create mode 100644 packages/main/cypress/specs/ColorPicker.cy.ts create mode 100644 packages/main/src/types/ColorPickerDisplayMode.ts create mode 100644 packages/website/docs/_samples/main/ColorPicker/Simplified/Simplified.md create mode 100644 packages/website/docs/_samples/main/ColorPicker/Simplified/main.js create mode 100644 packages/website/docs/_samples/main/ColorPicker/Simplified/sample.html diff --git a/packages/main/cypress/specs/ColorPicker.cy.ts b/packages/main/cypress/specs/ColorPicker.cy.ts new file mode 100644 index 000000000000..30805685506c --- /dev/null +++ b/packages/main/cypress/specs/ColorPicker.cy.ts @@ -0,0 +1,27 @@ +import { html } from "lit"; +import "../../src/ColorPicker.js"; +import type ColorPicker from "../../src/ColorPicker.js"; + +describe("Color Picker tests", () => { + it("should not display color channel inputs and alpha slider in simplified mode", () => { + cy.mount(html``); + + cy.get("ui5-color-picker") + .as("colorPicker"); + + cy.get("@colorPicker") + .shadow() + .find(".ui5-color-picker-hex-input") + .should("exist"); + + cy.get("@colorPicker") + .shadow() + .find("#red") + .should("not.exist"); + + cy.get("@colorPicker") + .shadow() + .find("#alpha") + .should("not.exist"); + }); +}); diff --git a/packages/main/src/ColorPicker.hbs b/packages/main/src/ColorPicker.hbs index 73a256664477..76b5aad81cbe 100644 --- a/packages/main/src/ColorPicker.hbs +++ b/packages/main/src/ColorPicker.hbs @@ -23,16 +23,18 @@ accessible-name="{{hueSliderLabel}}" @ui5-input="{{_handleHueInput}}" > - + {{#if _isDefaultPickerMode}} + + {{/if}}
@@ -56,51 +58,53 @@
-
-
- - R -
-
- - G -
-
- - B -
-
- - A + {{#if _isDefaultPickerMode}} +
+
+ + R +
+
+ + G +
+
+ + B +
+
+ + A +
-
+ {{/if}} diff --git a/packages/main/src/ColorPicker.ts b/packages/main/src/ColorPicker.ts index e2040b5fa32f..c75f5391d308 100644 --- a/packages/main/src/ColorPicker.ts +++ b/packages/main/src/ColorPicker.ts @@ -22,6 +22,7 @@ import ColorPickerTemplate from "./generated/templates/ColorPickerTemplate.lit.j import Input from "./Input.js"; import Slider from "./Slider.js"; import Label from "./Label.js"; +import ColorPickerDisplayMode from "./types/ColorPickerDisplayMode.js"; import { COLORPICKER_ALPHA_SLIDER, @@ -111,6 +112,15 @@ class ColorPicker extends UI5Element implements IFormInputElement { @property() name?: string; + /** + * Defines the display mode of the component. + * @default "Default" + * @public + * @since 2.5.0 + */ + @property() + displayMode: `${ColorPickerDisplayMode}` = "Default"; + /** * Defines the HEX code of the currently selected color * @@ -529,6 +539,10 @@ class ColorPicker extends UI5Element implements IFormInputElement { return this._wrongHEX ? "Error" : undefined; } + get _isDefaultPickerMode() { + return this.displayMode === ColorPickerDisplayMode.Default; + } + get styles() { return { mainColor: { diff --git a/packages/main/src/types/ColorPickerDisplayMode.ts b/packages/main/src/types/ColorPickerDisplayMode.ts new file mode 100644 index 000000000000..5914080b26d4 --- /dev/null +++ b/packages/main/src/types/ColorPickerDisplayMode.ts @@ -0,0 +1,19 @@ +/** + * ColorPicker display modes. + * @public + */ +enum ColorPickerDisplayMode { + /** + * Default display mode. Includes all color picker features. + * @public + */ + Default = "Default", + + /** + * Simplified display mode. Doesn't include alpha slider and inputs for RGB values. + * @public + */ + Simplified = "Simplified", +} + +export default ColorPickerDisplayMode; diff --git a/packages/main/test/pages/ColorPicker.html b/packages/main/test/pages/ColorPicker.html index 3e2cac1f1e7d..7bf1cbf5b891 100644 --- a/packages/main/test/pages/ColorPicker.html +++ b/packages/main/test/pages/ColorPicker.html @@ -45,6 +45,14 @@ +
+
+
+ + Simplified Color Picker +
+ + + + + +