Skip to content

Commit e69a8f9

Browse files
committed
🎨 Unified disabled form component appearance
1 parent 5ae7b6f commit e69a8f9

File tree

32 files changed

+274
-30
lines changed

32 files changed

+274
-30
lines changed

src/framework/components/checkbox-group/checkbox-group.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ checkbox-group {
33
width: 100%;
44
position: relative;
55

6-
&.is-disabled {
6+
&[state="DISABLED"] {
77
p {
8+
opacity: 0.6;
89
color: var(--grey-400) !important;
910

1011
strong {
@@ -14,10 +15,11 @@ checkbox-group {
1415

1516
@media (prefers-color-scheme: dark) {
1617
p {
17-
color: var(--grey-500) !important;
18+
color: var(--grey-300) !important;
19+
opacity: 0.3;
1820

1921
strong {
20-
color: var(--grey-500) !important;
22+
color: var(--grey-300) !important;
2123
}
2224
}
2325
}

src/framework/components/checkbox-group/checkbox-group.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class CheckboxGroup extends Component<ICheckboxGroup> {
3737
settings.options.map((option) => {
3838
option.disabled = settings?.disabled ?? false;
3939
});
40+
this.state = settings.disabled ? "DISABLED" : "IDLING";
4041
this.set(settings);
4142
}
4243

@@ -82,6 +83,7 @@ export default class CheckboxGroup extends Component<ICheckboxGroup> {
8283
}
8384

8485
override render() {
86+
this.setAttribute("state", this.state);
8587
this.setAttribute("form-input", "");
8688
const view = html`
8789
<p>

src/framework/components/checkbox-group/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
data-options='[{"label": "Example 1","value":"example1"},{"label": "Example 2","value":"example2"},{"label": "Example 3","checked": true,"value":"example3"}]'
66
></checkbox-group>
77

8+
<checkbox-group
9+
class="mt-2"
10+
data-label="Example"
11+
data-name="example"
12+
data-instructions="Lorem ipsum and wat knot..."
13+
data-options='[{"label": "Example 1","value":"example1"},{"label": "Example 2","value":"example2"},{"label": "Example 3","checked": true,"value":"example3"}]'
14+
data-disabled="true"
15+
></checkbox-group>
16+
817
<script type="module" src="/js/checkbox-group.js"></script>
918
<script>
1019
document.querySelector('checkbox-group').addEventListener('change', (event) => {

src/framework/components/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default class Checkbox extends Component<ICheckbox> {
6363

6464
private handleChange: EventListener = (e: Event) => {
6565
e.stopImmediatePropagation();
66+
if (this.model.disabled) return;
6667
const isChecked = !this.model.checked;
6768
this.set({
6869
checked: isChecked,

src/framework/components/checkbox/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
data-name="example"
44
></checkbox-component>
55

6+
<checkbox-component
7+
class="mt-1"
8+
data-label="Example"
9+
data-name="example"
10+
data-disabled="true"
11+
></checkbox-component>
12+
613
<script type="module" src="/js/checkbox.js"></script>
714

815
<script>

src/framework/components/inputs/color-input/color-input.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ color-input {
55
width: 100%;
66
height: 36px;
77

8+
&[state="DISABLED"] {
9+
opacity: 0.6;
10+
cursor: not-allowed !important;
11+
12+
@media (prefers-color-scheme: dark) {
13+
opacity: 0.3;
14+
}
15+
}
16+
817
input[type="color"] {
918
opacity: 0;
1019
visibility: hidden;
@@ -16,10 +25,6 @@ color-input {
1625
& + label {
1726
cursor: not-allowed !important;
1827

19-
color-preview {
20-
background-color: var(--grey-300) !important;
21-
}
22-
2328
span {
2429
color: var(--grey-400) !important;
2530
}

src/framework/components/inputs/color-input/color-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default class ColorInput extends InputBase<IColorInput> {
5656
};
5757

5858
override render() {
59+
this.setAttribute("state", this.state);
5960
const view = html`
6061
<input
6162
name="${this.model.name}"

src/framework/components/inputs/color-input/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
data-value="#ff0000"
55
></color-input>
66

7+
<color-input
8+
class="mt-2"
9+
data-name="demo"
10+
data-label="Background Color"
11+
data-value="#ff0000"
12+
data-disabled="true"
13+
></color-input>
14+
715
<script type="module" src="/js/color-input.js"></script>
816
<script>
917
const colorInput = document.querySelector('color-input');

src/framework/components/inputs/date-input/date-input.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,27 @@ export default class DateInput extends InputBase<IDateInput> {
199199
autocapitalize=${this.model.autocapitalize}
200200
autocomplete="${this.model.autocomplete}"
201201
?required=${this.model.required}
202-
?disalbed=${this.model.disabled}
202+
?disabled=${this.model.disabled}
203203
?autofocus=${this.model.autofocus}
204204
/>
205205
</input-container>
206206
`;
207207
render(view, this);
208208

209-
const input = this.querySelector("input");
210-
flatpickr(input, {
211-
dateFormat: this.model.dateFormat,
212-
enableTime: this.model.enableTime,
213-
altFormat: this.model.displayFormat,
214-
altInput: true,
215-
minDate: this.model.minDate,
216-
maxDate: this.model.maxDate,
217-
mode: this.model.mode,
218-
noCalendar: this.model.disableCalendar,
219-
time_24hr: this.model.timeFormat === "24",
220-
});
209+
if (this.state !== "DISABLED") {
210+
const input = this.querySelector("input");
211+
flatpickr(input, {
212+
dateFormat: this.model.dateFormat,
213+
enableTime: this.model.enableTime,
214+
altFormat: this.model.displayFormat,
215+
altInput: true,
216+
minDate: this.model.minDate,
217+
maxDate: this.model.maxDate,
218+
mode: this.model.mode,
219+
noCalendar: this.model.disableCalendar,
220+
time_24hr: this.model.timeFormat === "24",
221+
});
222+
}
221223
this.firstRender = false;
222224
}
223225
}

src/framework/components/inputs/date-input/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
class="mb-2"
66
></date-input-component>
77

8+
<date-input-component
9+
data-label="Example"
10+
data-icon='<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" /></svg>'
11+
data-mode="single"
12+
data-disabled="true"
13+
class="mb-2"
14+
></date-input-component>
15+
816
<script>
917
const dateInput = document.querySelector('date-input-component');
1018
dateInput.addEventListener('change', (e) => {

0 commit comments

Comments
 (0)