Skip to content

Commit c875ffa

Browse files
Merge pull request #458 from loo41/features/form-disabled
feat(form): add "is-disabled" class
2 parents 444faf0 + 27bbae1 commit c875ffa

8 files changed

Lines changed: 101 additions & 6 deletions

File tree

scss/form/checkboxes.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,32 @@
103103
color: $color-white;
104104
}
105105
}
106+
&.is-disabled {
107+
$color: map-get($disabled-colors, "normal");
108+
$colors-radio-disabled: ($color, map-get($disabled-colors, "shadow"));
109+
110+
+ span {
111+
color: $color;
112+
cursor: not-allowed;
113+
}
114+
115+
/* stylelint-disable-next-line no-descending-specificity */
116+
+ span::before {
117+
color: $color;
118+
cursor: not-allowed;
119+
}
120+
121+
/* stylelint-disable-next-line no-descending-specificity */
122+
&:checked + span::before {
123+
@include pixelize(2px, $checkbox-checked-focus, $colors-radio-disabled);
124+
125+
color: $color;
126+
}
127+
128+
&:checked:focus + span::before {
129+
@include pixelize(2px, $checkbox-checked-focus, $colors-radio-disabled);
130+
131+
color: $color;
132+
}
133+
}
106134
}

scss/form/inputs.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
&.is-error {
2929
@include border-style(map-get($error-colors, "normal"), map-get($error-colors, "hover"));
3030
}
31+
&.is-disabled {
32+
@include border-style(map-get($disabled-colors, "normal"), map-get($disabled-colors, "shadow"));
33+
34+
color: map-get($disabled-colors, "normal");
35+
cursor: not-allowed;
36+
}
3137
}
3238

3339
.nes-field {

scss/form/radios.scss

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,39 @@
7373
color: $color-white;
7474
}
7575
}
76+
&.is-disabled {
77+
$color: map-get($disabled-colors, "normal");
78+
$colors-radio-disabled: ($color, map-get($disabled-colors, "shadow"));
79+
80+
+ span {
81+
color: $color;
82+
cursor: not-allowed;
83+
}
84+
85+
/* stylelint-disable-next-line no-descending-specificity */
86+
+ span::before {
87+
color: $color;
88+
cursor: not-allowed;
89+
}
90+
91+
&:checked:hover,
92+
&:checked:focus {
93+
& + span::before {
94+
animation: unset;
95+
}
96+
}
97+
98+
/* stylelint-disable-next-line no-descending-specificity */
99+
&:checked + span::before {
100+
@include pixelize(2px, $radio-checked-focus, $colors-radio-disabled);
101+
102+
color: $color;
103+
}
104+
105+
&:checked:focus + span::before {
106+
@include pixelize(2px, $radio-checked-focus, $colors-radio-disabled);
107+
108+
color: $color;
109+
}
110+
}
76111
}

scss/form/selects.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"dark" map-get($default-colors, "normal") map-get($default-colors, "hover"),
5151
"success" map-get($success-colors, "normal") map-get($success-colors, "hover"),
5252
"warning" map-get($warning-colors, "normal") map-get($warning-colors, "hover"),
53-
"error" map-get($error-colors, "normal") map-get($error-colors, "hover");
53+
"error" map-get($error-colors, "normal") map-get($error-colors, "hover"),
54+
"disable" map-get($disabled-colors, "normal") map-get($disabled-colors, "shadow");
5455
@each $type in $types {
5556
&.is-#{nth($type, 1)} {
5657
$color: nth($type, 2);
@@ -66,4 +67,11 @@
6667
}
6768
}
6869
}
70+
&.is-disabled {
71+
@extend .is-disable;
72+
select {
73+
color: map-get($disabled-colors, "normal");
74+
cursor: not-allowed;
75+
}
76+
}
6977
}

story/inputs/checkboxes.template.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import classNames from 'classnames';
33

44
export default () => {
55
const isDark = boolean('is-dark', false);
6+
const isDisabled = boolean('is-disabled', false);
67

78
const checkBoxClasses = classNames(
89
'nes-checkbox',
910
{
1011
'is-dark': isDark,
1112
},
13+
{
14+
'is-disabled': isDisabled,
15+
},
1216
);
1317

1418
return `
1519
<div style="${isDark ? 'background-color: black;' : ''}">
1620
<label>
17-
<input type="checkbox" class="${checkBoxClasses}" checked />
21+
<input type="checkbox" ${isDisabled && 'disabled'} class="${checkBoxClasses}" checked />
1822
<span>Enable</span>
1923
</label>
2024
</div>

story/inputs/input.template.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import classNames from 'classnames';
44
import sharedOptions from '../_helpers/shared';
55

66
export default () => {
7+
const disabled = 'is-disabled';
78
const inputOptions = select('Input Classes', {
89
default: '',
910
...sharedOptions,
11+
[disabled]: disabled,
1012
}, '');
1113

1214
const inputClasses = classNames(
@@ -15,6 +17,12 @@ export default () => {
1517
);
1618

1719
return `
18-
<input type="text" id="name_field" class="${inputClasses}" placeholder="NES.css">
20+
<input
21+
type="text"
22+
id="name_field"
23+
${inputOptions.includes(disabled) && 'disabled'}
24+
class="${inputClasses}"
25+
placeholder="NES.css"
26+
/>
1927
`;
2028
};

story/inputs/radio.template.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import classNames from 'classnames';
44

55
export default () => {
66
const isDark = boolean('is-dark', false);
7+
const isDisabled = boolean('is-disabled', false);
78

89
const radioClasses = classNames(
910
'nes-radio',
1011
{
1112
'is-dark': isDark,
1213
},
14+
{
15+
'is-disabled': isDisabled,
16+
},
1317
);
1418

1519
return `
1620
<div style="${isDark ? 'background-color: black;' : ''}">
1721
<label>
18-
<input type="radio" class="${radioClasses}" name="answer" checked />
22+
<input type="radio" ${isDisabled && 'disabled'} class="${radioClasses}" name="answer" checked />
1923
<span>Yes</span>
2024
</label>
2125
<label>
22-
<input type="radio" class="${radioClasses}" name="answer" />
26+
<input type="radio" ${isDisabled && 'disabled'} class="${radioClasses}" name="answer" />
2327
<span>No</span>
2428
</label>
2529
</div>

story/select/select.template.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import sharedOptions from '../_helpers/shared';
55

66
export default () => {
77
const isDark = boolean('is-dark', false);
8+
const disabled = 'is-disabled';
89
const selectOptions = select('class', {
910
default: '',
1011
...sharedOptions,
12+
[disabled]: disabled,
1113
}, '');
1214

1315
const selectedClasses = classNames(
@@ -18,7 +20,7 @@ export default () => {
1820

1921
return `
2022
<div class="${selectedClasses}">
21-
<select required>
23+
<select required ${selectOptions.includes(disabled) && 'disabled'} >
2224
<option value="" disabled selected hidden>Select...</option>
2325
<option value="0">To be</option>
2426
<option value="1">Not to be</option>

0 commit comments

Comments
 (0)