Skip to content

Commit 43df467

Browse files
committed
WIP
1 parent 9e5ed00 commit 43df467

4 files changed

Lines changed: 22 additions & 82 deletions

File tree

packages/eds-core-react/src/components/Checkbox/Checkbox.new.stories.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,14 @@ export const ErrorState: StoryFn<CheckboxProps> = () => {
349349
onChange={(e: ChangeEvent<HTMLInputElement>) =>
350350
setChecked(e.target.checked)
351351
}
352-
errorLabel={
353-
checked ? undefined : 'You must accept the terms and conditions'
354-
}
352+
error={!checked}
355353
/>
354+
<Typography
355+
variant="caption"
356+
style={{ marginTop: '0.5rem', color: 'var(--eds-color-text-danger-strong)' }}
357+
>
358+
{!checked && 'You must accept the terms and conditions'}
359+
</Typography>
356360
</div>
357361
)
358362
}
@@ -361,7 +365,7 @@ ErrorState.parameters = {
361365
docs: {
362366
description: {
363367
story:
364-
'Error state is shown by providing an `errorLabel` which displays an error message below the checkbox. The error typically disappears when the checkbox is checked. This is commonly used for required fields like accepting terms and conditions.',
368+
'Error state is shown by setting the `error` prop to true, which applies red styling to the checkbox. Error messages should be provided by a separate form field component. This is commonly used for required fields like accepting terms and conditions.',
365369
},
366370
},
367371
}

packages/eds-core-react/src/components/Checkbox/Checkbox.new.tsx

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
checkbox,
55
checkbox_outline,
66
checkbox_indeterminate,
7-
warning_outlined,
87
} from '@equinor/eds-icons'
98
import { TypographyNext } from '../Typography'
109
import type { CheckboxProps } from './Checkbox.new.types'
@@ -19,7 +18,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
1918
label,
2019
disabled = false,
2120
indeterminate = false,
22-
errorLabel,
21+
error = false,
2322
className,
2423
style,
2524
labelProps,
@@ -36,25 +35,21 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
3635
}
3736
}, [indeterminate, inputRef])
3837

39-
const hasError = !!errorLabel
40-
4138
const wrapperClasses = classNames(
4239
'checkbox',
4340
disabled && 'checkbox--disabled',
44-
hasError && 'checkbox--error',
41+
error && 'checkbox--error',
4542
className,
4643
)
4744

4845
const labelClasses = classNames(
4946
'checkbox__label',
5047
disabled && 'checkbox__label--disabled',
51-
hasError && 'checkbox__label--error',
5248
)
5349

5450
const iconClasses = classNames(
5551
'checkbox__icon',
5652
disabled && 'checkbox__icon--disabled',
57-
hasError && 'checkbox__icon--error',
5853
)
5954

6055
const checkboxInput = (
@@ -63,7 +58,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
6358
type="checkbox"
6459
aria-checked={indeterminate ? 'mixed' : rest.checked}
6560
aria-disabled={disabled || undefined}
66-
aria-invalid={hasError || undefined}
61+
aria-invalid={error || undefined}
6762
className="checkbox__input"
6863
disabled={disabled}
6964
ref={inputRef}
@@ -138,38 +133,6 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
138133
{label}
139134
</TypographyNext>
140135
</span>
141-
{errorLabel && (
142-
<span className="checkbox__error-label">
143-
<svg
144-
className="checkbox__error-icon"
145-
viewBox="0 0 24 24"
146-
xmlns="http://www.w3.org/2000/svg"
147-
aria-hidden="true"
148-
>
149-
<path
150-
fillRule="evenodd"
151-
clipRule="evenodd"
152-
d={
153-
Array.isArray(warning_outlined.svgPathData)
154-
? warning_outlined.svgPathData.join(' ')
155-
: warning_outlined.svgPathData
156-
}
157-
/>
158-
</svg>
159-
<TypographyNext
160-
as="span"
161-
family="ui"
162-
size="sm"
163-
baseline="center"
164-
lineHeight="squished"
165-
weight="normal"
166-
tracking="normal"
167-
className="checkbox__error-text"
168-
>
169-
{errorLabel}
170-
</TypographyNext>
171-
</span>
172-
)}
173136
</label>
174137
)
175138
}

packages/eds-core-react/src/components/Checkbox/Checkbox.new.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export type CheckboxProps = {
99
* set the native element to indeterminate yourself.
1010
*/
1111
indeterminate?: boolean
12-
/** Error message to display below the checkbox. When set, the checkbox will be in error state. */
13-
errorLabel?: string
12+
/** If true, the checkbox will be in error state with red styling */
13+
error?: boolean
1414
/** Props to apply to the label element (when label prop is provided) */
1515
labelProps?: LabelHTMLAttributes<HTMLLabelElement>
1616
} & InputHTMLAttributes<HTMLInputElement>

packages/eds-core-react/src/components/Checkbox/checkbox.new.css

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
position: relative;
1111
/* Default hover size */
1212
--checkbox-hover-size: 40px;
13+
/* CSS custom properties for colors - can be overridden externally */
14+
--checkbox-icon-color: var(--eds-color-border-accent-strong);
15+
--checkbox-hover-color: var(--eds-color-bg-accent-fill-muted-default);
1316
}
1417

1518
/* Label wrapper contains checkbox + label text */
@@ -35,6 +38,9 @@
3538

3639
.checkbox--error {
3740
cursor: pointer;
41+
/* Override colors for error state */
42+
--checkbox-icon-color: var(--eds-color-border-danger-strong);
43+
--checkbox-hover-color: var(--eds-color-bg-danger-fill-muted-default);
3844
}
3945

4046
/* Checkbox input wrapper */
@@ -71,20 +77,14 @@
7177

7278
@media (hover: hover) and (pointer: fine) {
7379
.checkbox__label-wrapper:hover .checkbox__input-wrapper::before {
74-
background-color: var(--eds-color-bg-accent-fill-muted-default);
80+
background-color: var(--checkbox-hover-color);
7581
}
7682

7783
.checkbox--disabled
7884
.checkbox__label-wrapper:hover
7985
.checkbox__input-wrapper::before {
8086
background-color: transparent;
8187
}
82-
83-
.checkbox--error
84-
.checkbox__label-wrapper:hover
85-
.checkbox__input-wrapper::before {
86-
background-color: var(--eds-color-bg-danger-fill-muted-default);
87-
}
8888
}
8989

9090
/* Native checkbox input */
@@ -138,7 +138,7 @@
138138
/* Fixed 24px - standard EDS icon size */
139139
width: 24px;
140140
height: 24px;
141-
fill: var(--eds-color-border-accent-strong);
141+
fill: var(--checkbox-icon-color);
142142
border-radius: var(--eds-shape-corner-medium);
143143
position: relative;
144144
z-index: 2;
@@ -148,9 +148,7 @@
148148
fill: var(--eds-color-text-neutral-subtle);
149149
}
150150

151-
.checkbox__icon--error {
152-
fill: var(--eds-color-border-danger-strong);
153-
}
151+
/* Remove --error modifier, use CSS variable override instead */
154152

155153
/* Icon paths visibility */
156154
.checkbox__icon-path--checked {
@@ -204,28 +202,3 @@
204202
.checkbox__label--disabled {
205203
color: var(--eds-color-text-neutral-subtle);
206204
}
207-
208-
.checkbox__label--error {
209-
color: var(--eds-color-text-neutral-strong);
210-
}
211-
212-
/* Error label container */
213-
.checkbox__error-label {
214-
display: inline-flex;
215-
align-items: center;
216-
gap: var(--eds-spacing-inline-2-xs);
217-
margin-left: calc(24px + var(--eds-spacing-inline-sm));
218-
}
219-
220-
/* Error icon */
221-
.checkbox__error-icon {
222-
width: 16px;
223-
height: 16px;
224-
fill: var(--eds-color-text-danger-strong);
225-
flex-shrink: 0;
226-
}
227-
228-
/* Error text */
229-
.checkbox__error-text {
230-
color: var(--eds-color-text-danger-strong);
231-
}

0 commit comments

Comments
 (0)