@charcoal-ui/react 4.0.0-beta.4 → 4.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_lib/useClassNames.d.ts +2 -2
- package/dist/_lib/useClassNames.d.ts.map +1 -1
- package/dist/components/Checkbox/CheckboxInput/index.d.ts +11 -0
- package/dist/components/Checkbox/CheckboxInput/index.d.ts.map +1 -0
- package/dist/components/Checkbox/CheckboxWithLabel.d.ts +9 -0
- package/dist/components/Checkbox/CheckboxWithLabel.d.ts.map +1 -0
- package/dist/components/Checkbox/index.d.ts +9 -7
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Clickable/index.d.ts +10 -13
- package/dist/components/Clickable/index.d.ts.map +1 -1
- package/dist/components/DropdownSelector/index.d.ts.map +1 -1
- package/dist/components/FieldLabel/index.d.ts +1 -0
- package/dist/components/FieldLabel/index.d.ts.map +1 -1
- package/dist/components/IconButton/index.d.ts +7 -5
- package/dist/components/IconButton/index.d.ts.map +1 -1
- package/dist/components/LoadingSpinner/index.d.ts +1 -0
- package/dist/components/LoadingSpinner/index.d.ts.map +1 -1
- package/dist/components/Modal/Dialog/index.d.ts +6 -24
- package/dist/components/Modal/Dialog/index.d.ts.map +1 -1
- package/dist/components/Modal/ModalPlumbing.d.ts +10 -3
- package/dist/components/Modal/ModalPlumbing.d.ts.map +1 -1
- package/dist/components/Modal/index.d.ts +1 -1
- package/dist/components/Modal/index.d.ts.map +1 -1
- package/dist/components/Radio/index.d.ts +3 -5
- package/dist/components/Radio/index.d.ts.map +1 -1
- package/dist/components/SegmentedControl/index.d.ts +1 -0
- package/dist/components/SegmentedControl/index.d.ts.map +1 -1
- package/dist/components/Switch/SwitchInput/index.d.ts +9 -0
- package/dist/components/Switch/SwitchInput/index.d.ts.map +1 -0
- package/dist/components/Switch/SwitchWithLabel.d.ts +9 -0
- package/dist/components/Switch/SwitchWithLabel.d.ts.map +1 -0
- package/dist/components/Switch/index.d.ts +4 -15
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/TagItem/index.d.ts +14 -15
- package/dist/components/TagItem/index.d.ts.map +1 -1
- package/dist/components/TextArea/index.d.ts +28 -18
- package/dist/components/TextArea/index.d.ts.map +1 -1
- package/dist/components/TextField/index.d.ts +32 -19
- package/dist/components/TextField/index.d.ts.map +1 -1
- package/dist/index.cjs.js +390 -776
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +732 -28
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +415 -799
- package/dist/index.esm.js.map +1 -1
- package/dist/styled.d.ts +4 -4
- package/package.json +11 -10
- package/src/_lib/useClassNames.ts +3 -9
- package/src/components/Checkbox/CheckboxInput/__snapshots__/index.story.storyshot +77 -0
- package/src/components/Checkbox/CheckboxInput/index.css +111 -0
- package/src/components/{CheckboxInput → Checkbox/CheckboxInput}/index.story.tsx +16 -0
- package/src/components/Checkbox/CheckboxInput/index.tsx +47 -0
- package/src/components/Checkbox/CheckboxWithLabel.tsx +24 -0
- package/src/components/Checkbox/__snapshots__/index.story.storyshot +53 -134
- package/src/components/Checkbox/index.css +2 -2
- package/src/components/Checkbox/index.story.tsx +16 -11
- package/src/components/Checkbox/index.tsx +23 -15
- package/src/components/Clickable/__snapshots__/index.story.storyshot +2 -78
- package/src/components/Clickable/index.css +41 -0
- package/src/components/Clickable/index.story.tsx +1 -1
- package/src/components/Clickable/index.tsx +25 -85
- package/src/components/DropdownSelector/ListItem/__snapshots__/index.story.storyshot +10 -135
- package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +308 -1014
- package/src/components/DropdownSelector/index.tsx +9 -38
- package/src/components/FieldLabel/index.css +35 -0
- package/src/components/FieldLabel/index.tsx +15 -105
- package/src/components/IconButton/__snapshots__/index.story.storyshot +12 -288
- package/src/components/IconButton/index.css +118 -0
- package/src/components/IconButton/index.story.tsx +2 -2
- package/src/components/IconButton/index.tsx +41 -118
- package/src/components/LoadingSpinner/__snapshots__/LoadingSpinnerIcon.story.storyshot +2 -17
- package/src/components/LoadingSpinner/__snapshots__/index.story.storyshot +40 -128
- package/src/components/LoadingSpinner/index.css +42 -0
- package/src/components/LoadingSpinner/index.tsx +26 -52
- package/src/components/Modal/Dialog/index.css +44 -0
- package/src/components/Modal/Dialog/index.tsx +13 -57
- package/src/components/Modal/ModalPlumbing.css +40 -0
- package/src/components/Modal/ModalPlumbing.tsx +22 -61
- package/src/components/Modal/__snapshots__/index.story.storyshot +459 -1881
- package/src/components/Modal/index.css +36 -0
- package/src/components/Modal/index.tsx +26 -73
- package/src/components/Radio/__snapshots__/index.story.storyshot +50 -775
- package/src/components/Radio/index.css +97 -0
- package/src/components/Radio/index.story.tsx +1 -10
- package/src/components/Radio/index.test.tsx +0 -1
- package/src/components/Radio/index.tsx +50 -161
- package/src/components/SegmentedControl/__snapshots__/index.story.storyshot +30 -260
- package/src/components/SegmentedControl/index.css +50 -0
- package/src/components/SegmentedControl/index.tsx +20 -89
- package/src/components/Switch/SwitchInput/index.css +82 -0
- package/src/components/Switch/SwitchInput/index.tsx +40 -0
- package/src/components/Switch/SwitchWithLabel.tsx +24 -0
- package/src/components/Switch/__snapshots__/index.story.storyshot +29 -532
- package/src/components/Switch/index.css +23 -0
- package/src/components/Switch/index.story.tsx +5 -0
- package/src/components/Switch/index.tsx +43 -140
- package/src/components/TagItem/__snapshots__/index.story.storyshot +153 -1130
- package/src/components/TagItem/index.css +140 -0
- package/src/components/TagItem/index.story.tsx +1 -1
- package/src/components/TagItem/index.tsx +76 -220
- package/src/components/TextArea/__snapshots__/TextArea.story.storyshot +203 -1357
- package/src/components/TextArea/index.tsx +68 -91
- package/src/components/TextField/__snapshots__/TextField.story.storyshot +274 -1614
- package/src/components/TextField/index.tsx +77 -105
- package/src/index.ts +0 -7
- package/src/type.d.ts +6 -0
- package/dist/components/CheckboxInput/index.d.ts +0 -9
- package/dist/components/CheckboxInput/index.d.ts.map +0 -1
- package/dist/components/MultiSelect/context.d.ts +0 -14
- package/dist/components/MultiSelect/context.d.ts.map +0 -1
- package/dist/components/MultiSelect/index.d.ts +0 -36
- package/dist/components/MultiSelect/index.d.ts.map +0 -1
- package/src/components/CheckboxInput/__snapshots__/index.story.storyshot +0 -109
- package/src/components/CheckboxInput/index.css +0 -77
- package/src/components/CheckboxInput/index.tsx +0 -53
- package/src/components/MultiSelect/__snapshots__/index.story.storyshot +0 -1054
- package/src/components/MultiSelect/context.ts +0 -23
- package/src/components/MultiSelect/index.story.tsx +0 -112
- package/src/components/MultiSelect/index.test.tsx +0 -263
- package/src/components/MultiSelect/index.tsx +0 -282
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
.charcoal-radio__label {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: auto 1fr;
|
|
4
|
+
grid-gap: 4px;
|
|
5
|
+
align-items: center;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
}
|
|
8
|
+
.charcoal-radio[aria-disabled]:not([aria-disabled='false']) {
|
|
9
|
+
opacity: 0.32;
|
|
10
|
+
cursor: default;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.charcoal-radio__input {
|
|
14
|
+
appearance: none;
|
|
15
|
+
display: block;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 6px;
|
|
20
|
+
|
|
21
|
+
width: 20px;
|
|
22
|
+
height: 20px;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
border-radius: 999999px;
|
|
25
|
+
background-color: var(--charcoal-surface1);
|
|
26
|
+
transition: 0.2s background-color, 0.2s box-shadow;
|
|
27
|
+
}
|
|
28
|
+
.charcoal-radio__input:checked {
|
|
29
|
+
background-color: var(--charcoal-brand);
|
|
30
|
+
}
|
|
31
|
+
.charcoal-radio__input:checked::after {
|
|
32
|
+
content: '';
|
|
33
|
+
display: block;
|
|
34
|
+
width: 8px;
|
|
35
|
+
height: 8px;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
background-color: var(--charcoal-text5);
|
|
38
|
+
border-radius: 999999px;
|
|
39
|
+
transition: 0.2s background-color, 0.2s box-shadow;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.charcoal-radio__input:not(:checked) {
|
|
43
|
+
border-width: 2px;
|
|
44
|
+
border-style: solid;
|
|
45
|
+
border-color: var(--charcoal-text3);
|
|
46
|
+
}
|
|
47
|
+
.charcoal-radio__input:disabled {
|
|
48
|
+
cursor: default;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.charcoal-radio__input:not(:disabled):hover {
|
|
52
|
+
background-color: var(--charcoal-surface1-hover);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.charcoal-radio__input:not(:disabled):active {
|
|
56
|
+
background-color: var(--charcoal-surface1-press);
|
|
57
|
+
}
|
|
58
|
+
.charcoal-radio__input:not(:disabled):focus {
|
|
59
|
+
outline: none;
|
|
60
|
+
box-shadow: 0 0 0 4px rgba(0, 150, 250, 0.32);
|
|
61
|
+
}
|
|
62
|
+
.charcoal-radio__input:not(:disabled):focus-visible {
|
|
63
|
+
box-shadow: 0 0 0 4px rgba(0, 150, 250, 0.32);
|
|
64
|
+
}
|
|
65
|
+
.charcoal-radio__input:not(:disabled):focus:not(:focus-visible) {
|
|
66
|
+
box-shadow: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.charcoal-radio__input:not(:disabled)[aria-invalid='true'],
|
|
70
|
+
.charcoal-radio__input:not(:disabled)[aria-invalid='true']:focus {
|
|
71
|
+
box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.charcoal-radio__input:checked:not(:disabled):hover {
|
|
75
|
+
background-color: var(--charcoal-brand-hover);
|
|
76
|
+
}
|
|
77
|
+
.charcoal-radio__input:checked:not(:disabled):hover::after {
|
|
78
|
+
background-color: var(--charcoal-text5-hover);
|
|
79
|
+
}
|
|
80
|
+
.charcoal-radio__input:checked:not(:disabled):active {
|
|
81
|
+
background-color: var(--charcoal-brand-press);
|
|
82
|
+
}
|
|
83
|
+
.charcoal-radio__input:checked:not(:disabled):active::after {
|
|
84
|
+
background-color: var(--charcoal-text5-press);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.charcoal-radio__label_div {
|
|
88
|
+
font-size: 14px;
|
|
89
|
+
line-height: 22px;
|
|
90
|
+
color: var(--charcoal-text2);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.charcoal-radio-group {
|
|
94
|
+
display: grid;
|
|
95
|
+
grid-template-columns: 1fr;
|
|
96
|
+
grid-gap: 8px;
|
|
97
|
+
}
|
|
@@ -27,7 +27,6 @@ export const Default: StoryObj<typeof Radio> = {
|
|
|
27
27
|
return (
|
|
28
28
|
<LayoutDiv>
|
|
29
29
|
<RadioGroup<Option>
|
|
30
|
-
label={'label'}
|
|
31
30
|
name={'name'}
|
|
32
31
|
{...args}
|
|
33
32
|
value={value}
|
|
@@ -51,7 +50,6 @@ export const Disabled: StoryObj<typeof Radio> = {
|
|
|
51
50
|
return (
|
|
52
51
|
<LayoutDiv>
|
|
53
52
|
<RadioGroup<Option>
|
|
54
|
-
label={'label'}
|
|
55
53
|
name={'name'}
|
|
56
54
|
value={value}
|
|
57
55
|
onChange={setValue}
|
|
@@ -74,12 +72,7 @@ export const PartialDisabled: StoryObj<typeof Radio> = {
|
|
|
74
72
|
|
|
75
73
|
return (
|
|
76
74
|
<LayoutDiv>
|
|
77
|
-
<RadioGroup<Option>
|
|
78
|
-
label={'label'}
|
|
79
|
-
name={'name'}
|
|
80
|
-
value={value}
|
|
81
|
-
onChange={setValue}
|
|
82
|
-
>
|
|
75
|
+
<RadioGroup<Option> name={'name'} value={value} onChange={setValue}>
|
|
83
76
|
{options.map((option) => (
|
|
84
77
|
<Radio key={option} value={option} disabled={option === '2'}>
|
|
85
78
|
Value {option}
|
|
@@ -98,7 +91,6 @@ export const Readonly: StoryObj<typeof Radio> = {
|
|
|
98
91
|
return (
|
|
99
92
|
<LayoutDiv>
|
|
100
93
|
<RadioGroup<Option>
|
|
101
|
-
label={'label'}
|
|
102
94
|
name={'name'}
|
|
103
95
|
value={value}
|
|
104
96
|
onChange={setValue}
|
|
@@ -122,7 +114,6 @@ export const Invalid: StoryObj<typeof Radio> = {
|
|
|
122
114
|
return (
|
|
123
115
|
<LayoutDiv>
|
|
124
116
|
<RadioGroup<Option>
|
|
125
|
-
label={'label'}
|
|
126
117
|
name={'name'}
|
|
127
118
|
value={value}
|
|
128
119
|
onChange={setValue}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { memo, forwardRef, useCallback, useContext } from 'react'
|
|
1
|
+
import { memo, forwardRef, useCallback, useContext, useMemo } from 'react'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import styled from 'styled-components'
|
|
4
3
|
import warning from 'warning'
|
|
5
|
-
import {
|
|
4
|
+
import { useClassNames } from '../../_lib/useClassNames'
|
|
5
|
+
|
|
6
|
+
import './index.css'
|
|
6
7
|
|
|
7
8
|
export type RadioProps = React.PropsWithChildren<{
|
|
8
9
|
value: string
|
|
@@ -11,7 +12,7 @@ export type RadioProps = React.PropsWithChildren<{
|
|
|
11
12
|
}>
|
|
12
13
|
|
|
13
14
|
const Radio = forwardRef<HTMLInputElement, RadioProps>(function RadioInner(
|
|
14
|
-
{ value, disabled = false, children,
|
|
15
|
+
{ value, disabled = false, children, ...props },
|
|
15
16
|
ref
|
|
16
17
|
) {
|
|
17
18
|
const {
|
|
@@ -23,6 +24,8 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(function RadioInner(
|
|
|
23
24
|
onChange,
|
|
24
25
|
} = useContext(RadioGroupContext)
|
|
25
26
|
|
|
27
|
+
const classNames = useClassNames('charcoal-radio__label', props.className)
|
|
28
|
+
|
|
26
29
|
warning(
|
|
27
30
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
28
31
|
name !== undefined,
|
|
@@ -41,8 +44,10 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(function RadioInner(
|
|
|
41
44
|
)
|
|
42
45
|
|
|
43
46
|
return (
|
|
44
|
-
<
|
|
45
|
-
<
|
|
47
|
+
<label aria-disabled={isDisabled || isReadonly} className={classNames}>
|
|
48
|
+
<input
|
|
49
|
+
type="radio"
|
|
50
|
+
className="charcoal-radio__input"
|
|
46
51
|
name={name}
|
|
47
52
|
value={value}
|
|
48
53
|
checked={isSelected}
|
|
@@ -51,143 +56,27 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(function RadioInner(
|
|
|
51
56
|
disabled={isDisabled || isReadonly}
|
|
52
57
|
ref={ref}
|
|
53
58
|
/>
|
|
54
|
-
{children != null &&
|
|
55
|
-
|
|
59
|
+
{children != null && (
|
|
60
|
+
<div className="charcoal-radio__label_div">{children}</div>
|
|
61
|
+
)}
|
|
62
|
+
</label>
|
|
56
63
|
)
|
|
57
64
|
})
|
|
58
65
|
|
|
59
66
|
export default memo(Radio)
|
|
60
67
|
|
|
61
|
-
const RadioRoot = styled.label`
|
|
62
|
-
display: grid;
|
|
63
|
-
grid-template-columns: auto 1fr;
|
|
64
|
-
grid-gap: 4px;
|
|
65
|
-
align-items: center;
|
|
66
|
-
cursor: pointer;
|
|
67
|
-
|
|
68
|
-
&[aria-disabled]:not([aria-disabled='false']) {
|
|
69
|
-
opacity: 0.32;
|
|
70
|
-
cursor: default;
|
|
71
|
-
}
|
|
72
|
-
`
|
|
73
|
-
|
|
74
|
-
export const RadioInput = styled.input.attrs({ type: 'radio' })`
|
|
75
|
-
/** Make prior to browser default style */
|
|
76
|
-
&[type='radio'] {
|
|
77
|
-
appearance: none;
|
|
78
|
-
display: block;
|
|
79
|
-
box-sizing: border-box;
|
|
80
|
-
|
|
81
|
-
margin: 0;
|
|
82
|
-
padding: 6px;
|
|
83
|
-
|
|
84
|
-
width: 20px;
|
|
85
|
-
height: 20px;
|
|
86
|
-
cursor: pointer;
|
|
87
|
-
border-radius: 999999px;
|
|
88
|
-
background-color: var(--charcoal-surface1);
|
|
89
|
-
transition: 0.2s background-color, 0.2s box-shadow;
|
|
90
|
-
|
|
91
|
-
:disabled {
|
|
92
|
-
cursor: default;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
&:not(:disabled):not([aria-disabled]),
|
|
96
|
-
&[aria-disabled='false'] {
|
|
97
|
-
&:hover {
|
|
98
|
-
background-color: var(--charcoal-surface1-hover);
|
|
99
|
-
}
|
|
100
|
-
&:active {
|
|
101
|
-
background-color: var(--charcoal-surface1-press);
|
|
102
|
-
}
|
|
103
|
-
${focusVisibleFocusRingCss}
|
|
104
|
-
&[aria-invalid='true'] {
|
|
105
|
-
box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
|
|
106
|
-
&:focus {
|
|
107
|
-
box-shadow: 0 0 0 4px rgba(255, 43, 0, 0.32);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
&:not(:checked) {
|
|
113
|
-
border-width: 2px;
|
|
114
|
-
border-style: solid;
|
|
115
|
-
border-color: var(--charcoal-text3);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
&:checked {
|
|
119
|
-
background-color: var(--charcoal-brand);
|
|
120
|
-
&::after {
|
|
121
|
-
content: '';
|
|
122
|
-
display: block;
|
|
123
|
-
width: 8px;
|
|
124
|
-
height: 8px;
|
|
125
|
-
pointer-events: none;
|
|
126
|
-
background-color: var(--charcoal-text5);
|
|
127
|
-
border-radius: 999999px;
|
|
128
|
-
transition: 0.2s background-color, 0.2s box-shadow;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
&:not(:disabled):not([aria-disabled]),
|
|
132
|
-
&[aria-disabled='false'] {
|
|
133
|
-
&:hover {
|
|
134
|
-
background-color: var(--charcoal-brand-hover);
|
|
135
|
-
&::after {
|
|
136
|
-
background-color: var(--charcoal-text5-hover);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
&:active {
|
|
140
|
-
background-color: var(--charcoal-brand-press);
|
|
141
|
-
&::after {
|
|
142
|
-
background-color: var(--charcoal-text5-press);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
`
|
|
149
|
-
|
|
150
|
-
const RadioLabel = styled.div`
|
|
151
|
-
font-size: 14px;
|
|
152
|
-
line-height: 22px;
|
|
153
|
-
display: flow-root;
|
|
154
|
-
color: var(--charcoal-text2);
|
|
155
|
-
|
|
156
|
-
&::before {
|
|
157
|
-
display: block;
|
|
158
|
-
width: 0;
|
|
159
|
-
height: 0;
|
|
160
|
-
content: '';
|
|
161
|
-
margin-top: -4px;
|
|
162
|
-
}
|
|
163
|
-
&::after {
|
|
164
|
-
display: block;
|
|
165
|
-
width: 0;
|
|
166
|
-
height: 0;
|
|
167
|
-
content: '';
|
|
168
|
-
margin-bottom: -4px;
|
|
169
|
-
}
|
|
170
|
-
`
|
|
171
|
-
|
|
172
68
|
export type RadioGroupProps<Value extends string = string> =
|
|
173
69
|
React.PropsWithChildren<{
|
|
174
70
|
className?: string
|
|
175
71
|
value?: Value
|
|
176
|
-
label: string
|
|
177
72
|
name: string
|
|
178
73
|
onChange(next: Value): void
|
|
179
74
|
disabled?: boolean
|
|
180
75
|
readonly?: boolean
|
|
181
76
|
invalid?: boolean
|
|
77
|
+
ref?: React.Ref<HTMLDivElement>
|
|
182
78
|
}>
|
|
183
79
|
|
|
184
|
-
// TODO: use (or polyfill) flex gap
|
|
185
|
-
const StyledRadioGroup = styled.div`
|
|
186
|
-
display: grid;
|
|
187
|
-
grid-template-columns: 1fr;
|
|
188
|
-
grid-gap: 8px;
|
|
189
|
-
`
|
|
190
|
-
|
|
191
80
|
interface RadioGroupContext {
|
|
192
81
|
name: string
|
|
193
82
|
selected?: string
|
|
@@ -210,44 +99,44 @@ const RadioGroupContext = React.createContext<RadioGroupContext>({
|
|
|
210
99
|
},
|
|
211
100
|
})
|
|
212
101
|
|
|
213
|
-
export
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
onChange(next as Value)
|
|
227
|
-
},
|
|
228
|
-
[onChange]
|
|
229
|
-
)
|
|
102
|
+
export const RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps<string>>(
|
|
103
|
+
function RadioGroupInner(
|
|
104
|
+
{ value, name, onChange, disabled, readonly, invalid, children, ...props },
|
|
105
|
+
ref
|
|
106
|
+
) {
|
|
107
|
+
const classNames = useClassNames('charcoal-radio-group', props.className)
|
|
108
|
+
|
|
109
|
+
const handleChange = useCallback(
|
|
110
|
+
(next: string) => {
|
|
111
|
+
onChange(next)
|
|
112
|
+
},
|
|
113
|
+
[onChange]
|
|
114
|
+
)
|
|
230
115
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
value={{
|
|
116
|
+
const contextValue = useMemo(
|
|
117
|
+
() => ({
|
|
234
118
|
name,
|
|
235
119
|
selected: value,
|
|
236
120
|
disabled: disabled ?? false,
|
|
237
121
|
readonly: readonly ?? false,
|
|
238
122
|
invalid: invalid ?? false,
|
|
239
123
|
onChange: handleChange,
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
124
|
+
}),
|
|
125
|
+
[disabled, handleChange, invalid, name, readonly, value]
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<RadioGroupContext.Provider value={contextValue}>
|
|
130
|
+
<div
|
|
131
|
+
role="radiogroup"
|
|
132
|
+
aria-orientation="vertical"
|
|
133
|
+
aria-invalid={invalid}
|
|
134
|
+
className={classNames}
|
|
135
|
+
ref={ref}
|
|
136
|
+
>
|
|
137
|
+
{children}
|
|
138
|
+
</div>
|
|
139
|
+
</RadioGroupContext.Provider>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
) as <Value extends string>(props: RadioGroupProps<Value>) => JSX.Element
|