Skip to content

Commit 3e71157

Browse files
committed
refactor: use Icon component in Checkbox
1 parent bda4228 commit 3e71157

2 files changed

Lines changed: 24 additions & 78 deletions

File tree

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

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
checkbox_indeterminate,
77
} from '@equinor/eds-icons'
88
import { TypographyNext } from '../../Typography'
9+
import { Icon } from '../Icon'
910
import type { CheckboxProps } from './Checkbox.types'
1011

1112
const classNames = (...classes: (string | boolean | undefined)[]) =>
@@ -39,8 +40,6 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
3940

4041
const labelClasses = classNames('eds-checkbox__label')
4142

42-
const iconClasses = classNames('eds-checkbox__icon')
43-
4443
const sharedWrapperProps: Record<string, unknown> = {
4544
style,
4645
'data-disabled': disabled ? 'true' : undefined,
@@ -64,53 +63,18 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
6463
data-indeterminate={indeterminate}
6564
{...rest}
6665
/>
67-
{indeterminate ? (
68-
<svg
69-
className={iconClasses}
70-
viewBox="0 0 24 24"
71-
xmlns="http://www.w3.org/2000/svg"
72-
aria-hidden="true"
73-
>
74-
<path
75-
className="eds-checkbox__icon-path eds-checkbox__icon-path--indeterminate"
76-
fillRule="evenodd"
77-
clipRule="evenodd"
78-
d={
79-
Array.isArray(checkbox_indeterminate.svgPathData)
80-
? checkbox_indeterminate.svgPathData.join(' ')
81-
: checkbox_indeterminate.svgPathData
82-
}
83-
/>
84-
</svg>
85-
) : (
86-
<svg
87-
className={iconClasses}
88-
viewBox="0 0 24 24"
89-
xmlns="http://www.w3.org/2000/svg"
90-
aria-hidden="true"
91-
>
92-
<path
93-
className="eds-checkbox__icon-path eds-checkbox__icon-path--checked"
94-
fillRule="evenodd"
95-
clipRule="evenodd"
96-
d={
97-
Array.isArray(checkbox.svgPathData)
98-
? checkbox.svgPathData.join(' ')
99-
: checkbox.svgPathData
100-
}
101-
/>
102-
<path
103-
className="eds-checkbox__icon-path eds-checkbox__icon-path--unchecked"
104-
fillRule="evenodd"
105-
clipRule="evenodd"
106-
d={
107-
Array.isArray(checkbox_outline.svgPathData)
108-
? checkbox_outline.svgPathData.join(' ')
109-
: checkbox_outline.svgPathData
110-
}
111-
/>
112-
</svg>
113-
)}
66+
<Icon
67+
data={checkbox}
68+
className="eds-checkbox__icon eds-checkbox__icon--checked"
69+
/>
70+
<Icon
71+
data={checkbox_outline}
72+
className="eds-checkbox__icon eds-checkbox__icon--unchecked"
73+
/>
74+
<Icon
75+
data={checkbox_indeterminate}
76+
className="eds-checkbox__icon eds-checkbox__icon--indeterminate"
77+
/>
11478
</span>
11579
)
11680

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

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,52 +118,34 @@
118118
fill: var(--eds-color-border-neutral-medium);
119119
}
120120

121-
/* Icon paths visibility */
122-
.eds-checkbox__icon-path--checked {
121+
/* Icon visibility logic is controlled by CSS - default state: show unchecked, hide others */
122+
.eds-checkbox__icon--checked,
123+
.eds-checkbox__icon--indeterminate {
123124
display: none;
124125
}
125126

126-
.eds-checkbox__input:checked
127-
~ .eds-checkbox__icon
128-
.eds-checkbox__icon-path--checked {
127+
.eds-checkbox__icon--unchecked {
129128
display: inline;
130129
}
131130

132-
.eds-checkbox__input:checked
133-
~ .eds-checkbox__icon
134-
.eds-checkbox__icon-path--unchecked {
135-
display: none;
136-
}
137-
138-
.eds-checkbox__input:not(:checked)
139-
~ .eds-checkbox__icon
140-
.eds-checkbox__icon-path--checked {
141-
display: none;
142-
}
143-
144-
.eds-checkbox__input:not(:checked)
145-
~ .eds-checkbox__icon
146-
.eds-checkbox__icon-path--unchecked {
131+
/* Checked state: show checked icon, hide others */
132+
.eds-checkbox__input:checked ~ .eds-checkbox__icon--checked {
147133
display: inline;
148134
}
149135

150-
/* Indeterminate state */
151-
.eds-checkbox__icon-path--indeterminate {
136+
.eds-checkbox__input:checked ~ .eds-checkbox__icon--unchecked {
152137
display: none;
153138
}
154139

140+
/* Indeterminate state: show indeterminate icon, hide others */
155141
.eds-checkbox__input[data-indeterminate='true']
156-
~ .eds-checkbox__icon
157-
.eds-checkbox__icon-path--indeterminate {
142+
~ .eds-checkbox__icon--indeterminate {
158143
display: inline;
159144
}
160145

146+
.eds-checkbox__input[data-indeterminate='true'] ~ .eds-checkbox__icon--checked,
161147
.eds-checkbox__input[data-indeterminate='true']
162-
~ .eds-checkbox__icon
163-
.eds-checkbox__icon-path--checked,
164-
.eds-checkbox__input[data-indeterminate='true']
165-
~ .eds-checkbox__icon
166-
.eds-checkbox__icon-path--unchecked {
148+
~ .eds-checkbox__icon--unchecked {
167149
display: none;
168150
}
169151

0 commit comments

Comments
 (0)