Skip to content

Commit 1d397d2

Browse files
committed
feat(color-picker): add standard input field props, e.g. disabled, etc…
Also `required`, `invalid`, and `placeholder`. These will help to use this component more like a standard input field in a form.
1 parent 2abf220 commit 1d397d2

File tree

5 files changed

+154
-12
lines changed

5 files changed

+154
-12
lines changed

etc/lime-elements.api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,13 @@ export namespace Components {
322322
"language": Languages;
323323
}
324324
export interface LimelColorPicker {
325+
"disabled": boolean;
325326
"helperText": string;
327+
"invalid": boolean;
326328
"label": string;
327329
"palette"?: Array<string | CustomColorSwatch>;
328330
"paletteColumnCount"?: number;
331+
"placeholder": string;
329332
"readonly": boolean;
330333
"required": boolean;
331334
"tooltipLabel": string;
@@ -335,8 +338,10 @@ export namespace Components {
335338
export interface LimelColorPickerPalette {
336339
"columnCount"?: number;
337340
"helperText": string;
341+
"invalid": boolean;
338342
"label": string;
339343
"palette"?: CustomPalette;
344+
"placeholder": string;
340345
"required": boolean;
341346
"value": string;
342347
}
@@ -1471,11 +1476,14 @@ export namespace JSX {
14711476
"onOpen"?: (event: LimelCollapsibleSectionCustomEvent<void>) => void;
14721477
}
14731478
export interface LimelColorPicker {
1479+
"disabled"?: boolean;
14741480
"helperText"?: string;
1481+
"invalid"?: boolean;
14751482
"label"?: string;
14761483
"onChange"?: (event: LimelColorPickerCustomEvent<string>) => void;
14771484
"palette"?: Array<string | CustomColorSwatch>;
14781485
"paletteColumnCount"?: number;
1486+
"placeholder"?: string;
14791487
"readonly"?: boolean;
14801488
"required"?: boolean;
14811489
"tooltipLabel"?: string;
@@ -1485,9 +1493,11 @@ export namespace JSX {
14851493
export interface LimelColorPickerPalette {
14861494
"columnCount"?: number;
14871495
"helperText"?: string;
1496+
"invalid"?: boolean;
14881497
"label"?: string;
14891498
"onChange"?: (event: LimelColorPickerPaletteCustomEvent<string>) => void;
14901499
"palette"?: CustomPalette;
1500+
"placeholder"?: string;
14911501
"required"?: boolean;
14921502
"value"?: string;
14931503
}

src/components/color-picker/color-picker-palette.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,26 @@ export class Palette implements FormComponent {
3030
@Prop({ reflect: true })
3131
public helperText: string;
3232

33+
/**
34+
* The placeholder text shown inside the input field,
35+
* when the field is focused and empty.
36+
*/
37+
@Prop({ reflect: true })
38+
public placeholder: string;
39+
3340
/**
3441
* Set to `true` if a value is required
3542
*/
3643
@Prop({ reflect: true })
3744
public required: boolean;
3845

46+
/**
47+
* Set to `true` to indicate that the current value of the input field is
48+
* invalid.
49+
*/
50+
@Prop({ reflect: true })
51+
public invalid = false;
52+
3953
/**
4054
* Defines the number of columns in the color swatch grid.
4155
* If not provided, it will default to the number of colors in the palette.
@@ -74,6 +88,8 @@ export class Palette implements FormComponent {
7488
value={this.value}
7589
onChange={this.handleChange}
7690
required={this.required}
91+
invalid={this.invalid}
92+
placeholder={this.placeholder}
7793
/>
7894
<div class="chosen-color-preview" style={background} />
7995
</div>,

src/components/color-picker/color-picker.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ button[slot='trigger'] {
5757
)
5858
);
5959
}
60+
}
6061

62+
:host([readonly]:not([readonly='false'])),
63+
:host([disabled]:not([disabled='false'])) {
6164
button[slot='trigger'] {
6265
border: 1px solid rgba(var(--contrast-700), 0.65);
6366
}

src/components/color-picker/color-picker.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,35 @@ export class ColorPicker implements FormComponent {
6262
public required: boolean;
6363

6464
/**
65-
* Set to `true` if a value is readonly. This makes the component un-interactive.
65+
* Set to `true` to disable the field.
66+
* Use `disabled` to indicate that the field can normally be interacted
67+
* with, but is currently disabled. This tells the user that if certain
68+
* requirements are met, the field may become enabled again.
6669
*/
6770
@Prop({ reflect: true })
68-
public readonly: boolean;
71+
public disabled = false;
72+
73+
/**
74+
* Set to `true` to make the field read-only.
75+
* Use `readonly` when the field is only there to present the data it holds,
76+
* and will not become possible for the current user to edit.
77+
*/
78+
@Prop({ reflect: true })
79+
public readonly = false;
80+
81+
/**
82+
* Set to `true` to indicate that the current value of the input field is
83+
* invalid.
84+
*/
85+
@Prop({ reflect: true })
86+
public invalid = false;
87+
88+
/**
89+
* The placeholder text shown inside the input field,
90+
* when the field is focused and empty.
91+
*/
92+
@Prop({ reflect: true })
93+
public placeholder: string;
6994

7095
/**
7196
* An array of either color value strings, or objects with a `name` and a `value`,
@@ -115,6 +140,9 @@ export class ColorPicker implements FormComponent {
115140
onChange={this.handleChange}
116141
required={this.required}
117142
readonly={this.readonly}
143+
disabled={this.disabled}
144+
invalid={this.invalid}
145+
placeholder={this.placeholder}
118146
/>
119147
</Host>
120148
);
@@ -147,6 +175,8 @@ export class ColorPicker implements FormComponent {
147175
value={this.value}
148176
label={this.label}
149177
helperText={this.helperText}
178+
placeholder={this.placeholder}
179+
invalid={this.invalid}
150180
onChange={this.handleChange}
151181
required={this.required}
152182
palette={this.palette as any}
@@ -166,7 +196,7 @@ export class ColorPicker implements FormComponent {
166196
role="button"
167197
onClick={this.openPopover}
168198
id="tooltip-button"
169-
disabled={this.readonly}
199+
disabled={this.readonly || this.disabled}
170200
/>
171201
);
172202
};
Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,105 @@
1-
import { Component, h } from '@stencil/core';
1+
import { Component, h, Host, State } from '@stencil/core';
22
/**
3-
* Using the component in `readonly` mode
4-
* It is possible to use the component to visualize a color of your choice.
5-
* In this case, users cannot pick any colors, but they can view what you have picked.
3+
* Composite example
64
*/
75

86
@Component({
97
tag: 'limel-example-color-picker-readonly',
108
shadow: true,
119
})
1210
export class ColorPickerReadonlyExample {
11+
@State()
12+
private value = 'rgba(var(--color-red-default), 0.4)';
13+
14+
@State()
15+
private required = false;
16+
17+
@State()
18+
private disabled = false;
19+
20+
@State()
21+
private invalid = false;
22+
23+
@State()
24+
private readonly = false;
25+
26+
@State()
27+
private placeholder = 'Any valid CSS color format is accepted';
28+
1329
public render() {
1430
return (
15-
<limel-color-picker
16-
label="Look at this beautiful color!"
17-
readonly={true}
18-
value="rgba(var(--color-red-default), 0.4)"
19-
/>
31+
<Host>
32+
<limel-color-picker
33+
label="Select a beautiful color"
34+
value={this.value}
35+
placeholder={this.placeholder}
36+
readonly={this.readonly}
37+
required={this.required}
38+
disabled={this.disabled}
39+
invalid={this.invalid}
40+
onChange={this.onChange}
41+
/>
42+
<limel-example-controls>
43+
<limel-checkbox
44+
checked={this.required}
45+
label="Required"
46+
onChange={this.setRequired}
47+
/>
48+
<limel-checkbox
49+
checked={this.disabled}
50+
label="Disabled"
51+
onChange={this.setDisabled}
52+
/>
53+
<limel-checkbox
54+
checked={this.invalid}
55+
label="Invalid"
56+
onChange={this.setInvalid}
57+
/>
58+
<limel-checkbox
59+
checked={this.readonly}
60+
label="Readonly"
61+
onChange={this.setReadonly}
62+
/>
63+
<limel-input-field
64+
label="Placeholder"
65+
value={this.placeholder}
66+
onChange={this.setPlaceholder}
67+
style={{
68+
gridColumn: '1/-1',
69+
marginTop: '1rem',
70+
}}
71+
/>
72+
</limel-example-controls>
73+
</Host>
2074
);
2175
}
76+
77+
private onChange = (event: CustomEvent<string>) => {
78+
this.value = event.detail;
79+
};
80+
81+
private setRequired = (event: CustomEvent<boolean>) => {
82+
event.stopPropagation();
83+
this.required = event.detail;
84+
};
85+
86+
private setDisabled = (event: CustomEvent<boolean>) => {
87+
event.stopPropagation();
88+
this.disabled = event.detail;
89+
};
90+
91+
private setInvalid = (event: CustomEvent<boolean>) => {
92+
event.stopPropagation();
93+
this.invalid = event.detail;
94+
};
95+
96+
private setReadonly = (event: CustomEvent<boolean>) => {
97+
event.stopPropagation();
98+
this.readonly = event.detail;
99+
};
100+
101+
private setPlaceholder = (event: CustomEvent<string>) => {
102+
event.stopPropagation();
103+
this.placeholder = event.detail;
104+
};
22105
}

0 commit comments

Comments
 (0)