From 2442a2fb3184faf8da5f032f70435bb291290ca7 Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Sun, 22 Sep 2024 12:20:00 +0200 Subject: [PATCH] Add readonly to color area --- .../lib/uui-color-area.element.ts | 29 +++++++-- .../lib/uui-color-area.story.ts | 59 ++++++++++++++++++- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/packages/uui-color-area/lib/uui-color-area.element.ts b/packages/uui-color-area/lib/uui-color-area.element.ts index ea96a80a0..e68273c03 100644 --- a/packages/uui-color-area/lib/uui-color-area.element.ts +++ b/packages/uui-color-area/lib/uui-color-area.element.ts @@ -19,6 +19,24 @@ import { UUIColorAreaEvent } from './UUIColorAreaEvent'; export class UUIColorAreaElement extends LitElement { @state() private isDraggingGridHandle = false; + /** + * Sets the color area to disabled. + * @type {boolean} + * @attr + * @default false + */ + @property({ type: Boolean, reflect: true }) + disabled = false; + + /** + * Sets the color area to readonly mode. + * @type {boolean} + * @attr + * @default false + */ + @property({ type: Boolean, reflect: true }) + readonly = false; + /** * The current hue. * @attr @@ -114,11 +132,9 @@ export class UUIColorAreaElement extends LitElement { } } - /** Disables the color area. */ - @property({ type: Boolean, reflect: true }) disabled = false; - handleGridDrag(event: PointerEvent) { - if (this.disabled) return; + if (this.disabled || this.readonly) return; + const grid = this.shadowRoot!.querySelector('.color-area')!; const handle = grid.querySelector('.color-area__handle')!; const { width, height } = grid.getBoundingClientRect(); @@ -272,6 +288,11 @@ export class UUIColorAreaElement extends LitElement { opacity: 0.55; } + :host([readonly]) { + pointer-events: none; + cursor: default; + } + .color-area { position: relative; height: 100%; diff --git a/packages/uui-color-area/lib/uui-color-area.story.ts b/packages/uui-color-area/lib/uui-color-area.story.ts index e6db34511..9a7e0b6cd 100644 --- a/packages/uui-color-area/lib/uui-color-area.story.ts +++ b/packages/uui-color-area/lib/uui-color-area.story.ts @@ -1,4 +1,5 @@ -import type { Meta, StoryObj } from '@storybook/web-components'; +import type { Meta, StoryFn } from '@storybook/web-components'; +import { html } from 'lit'; import { withActions } from '@storybook/addon-actions/decorator'; import type { UUIColorAreaElement } from './uui-color-area.element'; import readme from '../README.md?raw'; @@ -9,6 +10,16 @@ const meta: Meta = { id: 'uui-color-area', title: 'Inputs/Color/Color Area', component: 'uui-color-area', + args: { + hue: 0, + saturation: 0, + lightness: 0, + brightness: 0, + alpha: 100, + disabled: false, + readonly: false, + value: '', + }, argTypes: { value: { control: 'color' }, }, @@ -30,6 +41,48 @@ const meta: Meta = { export default meta; -type Story = StoryObj; +const Template: StoryFn = props => { + return html` + `; +}; + +export const AAAOverview = Template.bind({}); +AAAOverview.storyName = 'Overview'; + +export const Disabled = Template.bind({}); + +Disabled.args = { + disabled: true, +}; + +Disabled.parameters = { + controls: { include: ['disbled'] }, + docs: { + source: { + code: ``, + }, + }, +}; + +export const Readonly = Template.bind({}); + +Readonly.args = { + readonly: true, +}; -export const Overview: Story = {}; +Readonly.parameters = { + controls: { include: ['readonly'] }, + docs: { + source: { + code: ``, + }, + }, +};