Skip to content

Commit c7d74bc

Browse files
authored
Merge branch 'v1/contrib' into feature/color-swatch-readonly
2 parents 54edc33 + eae3730 commit c7d74bc

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

packages/uui-color-area/lib/uui-color-area.element.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ import { UUIColorAreaEvent } from './UUIColorAreaEvent';
1919
export class UUIColorAreaElement extends LitElement {
2020
@state() private isDraggingGridHandle = false;
2121

22+
/**
23+
* Sets the color area to disabled.
24+
* @type {boolean}
25+
* @attr
26+
* @default false
27+
*/
28+
@property({ type: Boolean, reflect: true })
29+
disabled = false;
30+
31+
/**
32+
* Sets the color area to readonly mode.
33+
* @type {boolean}
34+
* @attr
35+
* @default false
36+
*/
37+
@property({ type: Boolean, reflect: true })
38+
readonly = false;
39+
2240
/**
2341
* The current hue.
2442
* @attr
@@ -114,11 +132,9 @@ export class UUIColorAreaElement extends LitElement {
114132
}
115133
}
116134

117-
/** Disables the color area. */
118-
@property({ type: Boolean, reflect: true }) disabled = false;
119-
120135
handleGridDrag(event: PointerEvent) {
121-
if (this.disabled) return;
136+
if (this.disabled || this.readonly) return;
137+
122138
const grid = this.shadowRoot!.querySelector<HTMLElement>('.color-area')!;
123139
const handle = grid.querySelector<HTMLElement>('.color-area__handle')!;
124140
const { width, height } = grid.getBoundingClientRect();
@@ -272,6 +288,11 @@ export class UUIColorAreaElement extends LitElement {
272288
opacity: 0.55;
273289
}
274290
291+
:host([readonly]) {
292+
pointer-events: none;
293+
cursor: default;
294+
}
295+
275296
.color-area {
276297
position: relative;
277298
height: 100%;

packages/uui-color-area/lib/uui-color-area.story.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
import type { StoryFn, Meta, StoryObj } from '@storybook/web-components';
2+
import type { UUIColorAreaElement } from './uui-color-area.element';
13
import '.';
24
import readme from '../README.md?raw';
35
import { html } from 'lit';
4-
import type { Meta, StoryObj } from '@storybook/web-components';
56
import { spread } from '../../../storyhelpers';
67

78
const meta: Meta = {
89
id: 'uui-color-area',
910
component: 'uui-color-area',
11+
args: {
12+
hue: 0,
13+
saturation: 0,
14+
lightness: 0,
15+
brightness: 0,
16+
alpha: 100,
17+
disabled: false,
18+
readonly: false,
19+
value: '',
20+
},
1021
title: 'Inputs/Color/Color Area',
1122
argTypes: {
1223
value: { control: 'color' },
@@ -22,4 +33,49 @@ const meta: Meta = {
2233
export default meta;
2334
type Story = StoryObj;
2435

36+
const Template: StoryFn<UUIColorAreaElement> = props => {
37+
return html`<uui-color-area
38+
.hue=${props.hue}
39+
.saturation=${props.saturation}
40+
.lightness=${props.lightness}
41+
.brightness=${props.brightness}
42+
.alpha=${props.alpha}
43+
.value=${props.value}
44+
.disabled=${props.disabled}
45+
.readonly=${props.readonly}>
46+
</uui-color-area>`;
47+
};
48+
49+
export const AAAOverview = Template.bind({});
50+
AAAOverview.storyName = 'Overview';
51+
52+
export const Disabled = Template.bind({});
53+
54+
Disabled.args = {
55+
disabled: true,
56+
};
57+
58+
Disabled.parameters = {
59+
controls: { include: ['disabled'] },
60+
docs: {
61+
source: {
62+
code: `<uui-color-area disabled></uui-color-area>`,
63+
},
64+
},
65+
};
66+
67+
export const Readonly = Template.bind({});
68+
69+
Readonly.args = {
70+
readonly: true,
71+
};
72+
73+
Readonly.parameters = {
74+
controls: { include: ['readonly'] },
75+
docs: {
76+
source: {
77+
code: `<uui-color-area readonly></uui-color-area>`,
78+
},
79+
},
80+
};
2581
export const Default: Story = {};

0 commit comments

Comments
 (0)