@instructure/ui-radio-input 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +45 -299
- package/es/RadioInput/{index.js → v1/index.js} +1 -1
- package/es/RadioInput/v2/index.js +189 -0
- package/{src/index.ts → es/RadioInput/v2/props.js} +2 -4
- package/es/RadioInput/v2/styles.js +268 -0
- package/es/RadioInputGroup/{index.js → v1/index.js} +3 -3
- package/es/RadioInputGroup/v2/index.js +146 -0
- package/es/RadioInputGroup/v2/props.js +26 -0
- package/es/{index.js → exports/a.js} +2 -2
- package/es/exports/b.js +25 -0
- package/lib/RadioInput/{index.js → v1/index.js} +1 -1
- package/lib/RadioInput/v2/index.js +195 -0
- package/lib/RadioInput/v2/props.js +31 -0
- package/lib/RadioInput/v2/styles.js +274 -0
- package/lib/RadioInputGroup/{index.js → v1/index.js} +6 -6
- package/lib/RadioInputGroup/v2/index.js +154 -0
- package/lib/RadioInputGroup/v2/props.js +31 -0
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +19 -0
- package/package.json +40 -18
- package/src/RadioInput/{index.tsx → v1/index.tsx} +1 -1
- package/src/RadioInput/v2/README.md +110 -0
- package/src/RadioInput/v2/index.tsx +223 -0
- package/src/RadioInput/v2/props.ts +126 -0
- package/src/RadioInput/v2/styles.ts +304 -0
- package/src/RadioInputGroup/{index.tsx → v1/index.tsx} +4 -4
- package/src/RadioInputGroup/{props.ts → v1/props.ts} +1 -1
- package/src/RadioInputGroup/{styles.ts → v1/styles.ts} +3 -1
- package/src/RadioInputGroup/v2/README.md +241 -0
- package/src/RadioInputGroup/v2/index.tsx +178 -0
- package/src/RadioInputGroup/v2/props.ts +122 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/RadioInput/v1/index.d.ts.map +1 -0
- package/types/RadioInput/v1/props.d.ts.map +1 -0
- package/types/RadioInput/v1/styles.d.ts.map +1 -0
- package/types/RadioInput/v1/theme.d.ts.map +1 -0
- package/types/RadioInput/v2/index.d.ts +64 -0
- package/types/RadioInput/v2/index.d.ts.map +1 -0
- package/types/RadioInput/v2/props.d.ts +77 -0
- package/types/RadioInput/v2/props.d.ts.map +1 -0
- package/types/RadioInput/v2/styles.d.ts +24 -0
- package/types/RadioInput/v2/styles.d.ts.map +1 -0
- package/types/RadioInputGroup/{index.d.ts → v1/index.d.ts} +3 -3
- package/types/RadioInputGroup/v1/index.d.ts.map +1 -0
- package/types/RadioInputGroup/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/RadioInputGroup/v1/props.d.ts.map +1 -0
- package/types/RadioInputGroup/v1/styles.d.ts.map +1 -0
- package/types/RadioInputGroup/v1/theme.d.ts.map +1 -0
- package/types/RadioInputGroup/v2/index.d.ts +47 -0
- package/types/RadioInputGroup/v2/index.d.ts.map +1 -0
- package/types/RadioInputGroup/v2/props.d.ts +63 -0
- package/types/RadioInputGroup/v2/props.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/RadioInput/index.d.ts.map +0 -1
- package/types/RadioInput/props.d.ts.map +0 -1
- package/types/RadioInput/styles.d.ts.map +0 -1
- package/types/RadioInput/theme.d.ts.map +0 -1
- package/types/RadioInputGroup/index.d.ts.map +0 -1
- package/types/RadioInputGroup/props.d.ts.map +0 -1
- package/types/RadioInputGroup/styles.d.ts.map +0 -1
- package/types/RadioInputGroup/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/RadioInput/{props.js → v1/props.js} +0 -0
- /package/es/RadioInput/{styles.js → v1/styles.js} +0 -0
- /package/es/RadioInput/{theme.js → v1/theme.js} +0 -0
- /package/es/RadioInputGroup/{props.js → v1/props.js} +0 -0
- /package/es/RadioInputGroup/{styles.js → v1/styles.js} +0 -0
- /package/es/RadioInputGroup/{theme.js → v1/theme.js} +0 -0
- /package/lib/RadioInput/{props.js → v1/props.js} +0 -0
- /package/lib/RadioInput/{styles.js → v1/styles.js} +0 -0
- /package/lib/RadioInput/{theme.js → v1/theme.js} +0 -0
- /package/lib/RadioInputGroup/{props.js → v1/props.js} +0 -0
- /package/lib/RadioInputGroup/{styles.js → v1/styles.js} +0 -0
- /package/lib/RadioInputGroup/{theme.js → v1/theme.js} +0 -0
- /package/src/RadioInput/{README.md → v1/README.md} +0 -0
- /package/src/RadioInput/{props.ts → v1/props.ts} +0 -0
- /package/src/RadioInput/{styles.ts → v1/styles.ts} +0 -0
- /package/src/RadioInput/{theme.ts → v1/theme.ts} +0 -0
- /package/src/RadioInputGroup/{README.md → v1/README.md} +0 -0
- /package/src/RadioInputGroup/{theme.ts → v1/theme.ts} +0 -0
- /package/types/RadioInput/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/RadioInput/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/RadioInput/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/RadioInput/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/RadioInputGroup/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/RadioInputGroup/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: RadioInputGroup
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A RadioInputGroup is a group of RadioInput components. It will handle setting
|
|
6
|
+
the name property on the RadioInput components for you and will set the selected item
|
|
7
|
+
based on the `value` property.
|
|
8
|
+
|
|
9
|
+
The `name` prop sets the [same low level HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#defining_a_radio_group) which **must be unique across the DOM** otherwise groups with the same name will interfere with each other.
|
|
10
|
+
|
|
11
|
+
Adjust the size of the radio button and label text via the `size` prop. The default size is
|
|
12
|
+
`medium`.
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
---
|
|
16
|
+
type: example
|
|
17
|
+
---
|
|
18
|
+
function Example () {
|
|
19
|
+
const inputs = [
|
|
20
|
+
{value: 'foo', label: 'Radio option one' },
|
|
21
|
+
{value: 'bar', label: 'Radio option two' },
|
|
22
|
+
{value: 'baz', label: 'Radio option three' }
|
|
23
|
+
]
|
|
24
|
+
const handleChange = function (event, value) {
|
|
25
|
+
console.log(value)
|
|
26
|
+
}
|
|
27
|
+
return (
|
|
28
|
+
<RadioInputGroup onChange={handleChange} name="example1" defaultValue="foo" description="Select something">
|
|
29
|
+
{inputs.map(input => <RadioInput key={input.value} value={input.value} label={input.label} />)}
|
|
30
|
+
</RadioInputGroup>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
render(<Example />)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
With the `layout` prop set to `inline` to render the description in its own column at screens `medium` size
|
|
37
|
+
and up.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
---
|
|
41
|
+
type: example
|
|
42
|
+
---
|
|
43
|
+
function Example () {
|
|
44
|
+
const inputs = [
|
|
45
|
+
{value: 'foo', label: 'Classical' },
|
|
46
|
+
{value: 'bar', label: 'Electronic' },
|
|
47
|
+
{value: 'baz', label: 'Country' }
|
|
48
|
+
]
|
|
49
|
+
return (
|
|
50
|
+
<RadioInputGroup
|
|
51
|
+
name="example2"
|
|
52
|
+
defaultValue="foo"
|
|
53
|
+
description="Select something"
|
|
54
|
+
layout="inline">
|
|
55
|
+
{inputs.map(input => <RadioInput key={input.value} value={input.value} label={input.label} />)}
|
|
56
|
+
</RadioInputGroup>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
render(<Example />)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
With the `layout` property set to `columns` the inputs will render horizontally at screens `medium` size
|
|
63
|
+
and up.
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
---
|
|
67
|
+
type: example
|
|
68
|
+
---
|
|
69
|
+
function Example () {
|
|
70
|
+
const inputs = [
|
|
71
|
+
{value: 'foo', label: 'Extremely happy' },
|
|
72
|
+
{value: 'bar', label: 'Very annoyed' },
|
|
73
|
+
{value: 'baz', label: 'Somewhat apathetic' }
|
|
74
|
+
]
|
|
75
|
+
return (
|
|
76
|
+
<RadioInputGroup
|
|
77
|
+
layout="columns"
|
|
78
|
+
name="example3"
|
|
79
|
+
defaultValue="foo"
|
|
80
|
+
description="Select something"
|
|
81
|
+
>
|
|
82
|
+
{inputs.map(input =>
|
|
83
|
+
<RadioInput
|
|
84
|
+
key={input.value}
|
|
85
|
+
value={input.value}
|
|
86
|
+
label={input.label}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
</RadioInputGroup>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
render(<Example />)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Set the `variant` prop to `toggle` to have the RadioInputGroup display as a toggle switch. The `context` prop can be set to switch the background color of the toggle switch. Default is `success` options are 'success', 'warning', 'danger', and 'off'.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
---
|
|
100
|
+
type: example
|
|
101
|
+
---
|
|
102
|
+
<FormFieldGroup description={<ScreenReaderContent>Toggle examples</ScreenReaderContent>}>
|
|
103
|
+
<RadioInputGroup
|
|
104
|
+
name="featuresm"
|
|
105
|
+
defaultValue="off"
|
|
106
|
+
description="Small-size"
|
|
107
|
+
variant="toggle"
|
|
108
|
+
size="small">
|
|
109
|
+
<RadioInput label="Off" value="off" context="off" />
|
|
110
|
+
<RadioInput label="Allow" value="allow" />
|
|
111
|
+
<RadioInput label="On" value="on" />
|
|
112
|
+
</RadioInputGroup>
|
|
113
|
+
<RadioInputGroup
|
|
114
|
+
name="featuremed"
|
|
115
|
+
defaultValue="allow"
|
|
116
|
+
description="Medium-size (default)"
|
|
117
|
+
variant="toggle">
|
|
118
|
+
<RadioInput label="Off" value="off" context="off" />
|
|
119
|
+
<RadioInput label="Allow" value="allow" />
|
|
120
|
+
<RadioInput label="On" value="on" />
|
|
121
|
+
</RadioInputGroup>
|
|
122
|
+
<RadioInputGroup
|
|
123
|
+
name="context"
|
|
124
|
+
defaultValue="off"
|
|
125
|
+
description="Context (background changes based on context set)"
|
|
126
|
+
variant="toggle">
|
|
127
|
+
<RadioInput label="Off" value="off" context="danger" />
|
|
128
|
+
<RadioInput label="Allow" value="allow" context="warning" />
|
|
129
|
+
<RadioInput label="On" value="on" />
|
|
130
|
+
</RadioInputGroup>
|
|
131
|
+
<RadioInputGroup
|
|
132
|
+
name="featurelg"
|
|
133
|
+
defaultValue="on"
|
|
134
|
+
description="Large-size"
|
|
135
|
+
variant="toggle"
|
|
136
|
+
size="large">
|
|
137
|
+
<RadioInput label="Off" value="off" />
|
|
138
|
+
<RadioInput label="Allow" value="allow" />
|
|
139
|
+
<RadioInput label="On" value="on" />
|
|
140
|
+
</RadioInputGroup>
|
|
141
|
+
</FormFieldGroup>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Setting the `disabled` prop to `true` will disable the entire RadioInputGroup.
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
---
|
|
148
|
+
type: example
|
|
149
|
+
---
|
|
150
|
+
<RadioInputGroup
|
|
151
|
+
name="fruits1"
|
|
152
|
+
description="Fruits"
|
|
153
|
+
defaultValue="orange"
|
|
154
|
+
disabled
|
|
155
|
+
>
|
|
156
|
+
<RadioInput label="Apple" value="apple" />
|
|
157
|
+
<RadioInput label="Orange" value="orange" />
|
|
158
|
+
<RadioInput label="Banana" value="banana" />
|
|
159
|
+
</RadioInputGroup>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
---
|
|
164
|
+
type: example
|
|
165
|
+
---
|
|
166
|
+
<RadioInputGroup name="feature1" defaultValue="off" description="Super-awesome feature" variant="toggle" disabled>
|
|
167
|
+
<RadioInput label="Off" value="off" context="off" />
|
|
168
|
+
<RadioInput label="Allow" value="allow" />
|
|
169
|
+
<RadioInput label="On" value="on" />
|
|
170
|
+
</RadioInputGroup>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Or disable an individual RadioInput component via its `disabled` prop.
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
---
|
|
177
|
+
type: example
|
|
178
|
+
---
|
|
179
|
+
<RadioInputGroup
|
|
180
|
+
name="fruits2"
|
|
181
|
+
defaultValue="banana"
|
|
182
|
+
description="Fruits"
|
|
183
|
+
layout="columns"
|
|
184
|
+
>
|
|
185
|
+
<RadioInput label="Apple" value="apple" />
|
|
186
|
+
<RadioInput label="Orange" value="orange" disabled />
|
|
187
|
+
<RadioInput label="Banana" value="banana" />
|
|
188
|
+
</RadioInputGroup>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
---
|
|
193
|
+
type: example
|
|
194
|
+
---
|
|
195
|
+
<RadioInputGroup name="feature2" defaultValue="none" description="Super-awesome feature" variant="toggle">
|
|
196
|
+
<RadioInput label="None" value="none" context="off" />
|
|
197
|
+
<RadioInput label="Some" value="some" />
|
|
198
|
+
<RadioInput label="All" value="all" disabled />
|
|
199
|
+
</RadioInputGroup>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
If you would like to make the description visible only to screen readers you can use the
|
|
203
|
+
[ScreenReaderContent](ScreenReaderContent) component.
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
---
|
|
207
|
+
type: example
|
|
208
|
+
---
|
|
209
|
+
<RadioInputGroup
|
|
210
|
+
name="fruit3"
|
|
211
|
+
defaultValue="banana"
|
|
212
|
+
description={
|
|
213
|
+
<ScreenReaderContent>Select a fruit</ScreenReaderContent>
|
|
214
|
+
}
|
|
215
|
+
messages={[{ text: 'Invalid choice', type: 'error' }]}
|
|
216
|
+
>
|
|
217
|
+
<RadioInput label="Apple" value="apple" />
|
|
218
|
+
<RadioInput label="Orange" value="orange" />
|
|
219
|
+
<RadioInput label="Banana" value="banana" />
|
|
220
|
+
</RadioInputGroup>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Guidelines
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
---
|
|
227
|
+
type: embed
|
|
228
|
+
---
|
|
229
|
+
<Guidelines>
|
|
230
|
+
<Figure recommendation="yes" title="Do">
|
|
231
|
+
<Figure.Item>Use sentence-style capitalization</Figure.Item>
|
|
232
|
+
<Figure.Item>Use a clear and concise label for RadioInput</Figure.Item>
|
|
233
|
+
<Figure.Item>Optionally include a heading to provide further clarity</Figure.Item>
|
|
234
|
+
</Figure>
|
|
235
|
+
<Figure recommendation="no" title="Don't">
|
|
236
|
+
<Figure.Item>Have a single RadioInput</Figure.Item>
|
|
237
|
+
<Figure.Item>Use long labels for RadioInput</Figure.Item>
|
|
238
|
+
<Figure.Item>Display more than two radio inputs horizontally</Figure.Item>
|
|
239
|
+
</Figure>
|
|
240
|
+
</Guidelines>
|
|
241
|
+
```
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { ComponentElement, Children, Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { FormFieldGroup } from '@instructure/ui-form-field/latest'
|
|
28
|
+
import {
|
|
29
|
+
matchComponentTypes,
|
|
30
|
+
safeCloneElement,
|
|
31
|
+
omitProps,
|
|
32
|
+
pickProps,
|
|
33
|
+
withDeterministicId
|
|
34
|
+
} from '@instructure/ui-react-utils'
|
|
35
|
+
|
|
36
|
+
import { RadioInput } from '../../RadioInput/v2'
|
|
37
|
+
import type { RadioInputProps } from '../../RadioInput/v2/props'
|
|
38
|
+
|
|
39
|
+
import type { RadioInputGroupProps, RadioInputGroupState } from './props'
|
|
40
|
+
import { allowedProps } from './props'
|
|
41
|
+
|
|
42
|
+
type RadioInputChild = ComponentElement<RadioInputProps, any>
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
category: components
|
|
47
|
+
---
|
|
48
|
+
**/
|
|
49
|
+
@withDeterministicId()
|
|
50
|
+
class RadioInputGroup extends Component<
|
|
51
|
+
RadioInputGroupProps,
|
|
52
|
+
RadioInputGroupState
|
|
53
|
+
> {
|
|
54
|
+
static readonly componentId = 'RadioInputGroup'
|
|
55
|
+
|
|
56
|
+
static allowedProps = allowedProps
|
|
57
|
+
|
|
58
|
+
static defaultProps = {
|
|
59
|
+
disabled: false,
|
|
60
|
+
variant: 'simple',
|
|
61
|
+
size: 'medium',
|
|
62
|
+
layout: 'stacked',
|
|
63
|
+
readOnly: false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ref: Element | null = null
|
|
67
|
+
|
|
68
|
+
private readonly _messagesId: string
|
|
69
|
+
|
|
70
|
+
handleRef = (el: Element | null) => {
|
|
71
|
+
this.ref = el
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
constructor(props: RadioInputGroupProps) {
|
|
75
|
+
super(props)
|
|
76
|
+
|
|
77
|
+
if (typeof props.value === 'undefined') {
|
|
78
|
+
this.state = {
|
|
79
|
+
value: props.defaultValue
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._messagesId = props.deterministicId!('RadioInputGroup-messages')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get hasMessages() {
|
|
87
|
+
return !!this.props.messages && this.props.messages.length > 0
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get invalid() {
|
|
91
|
+
return !!this.props.messages?.find(
|
|
92
|
+
(m) => m.type === 'newError' || m.type === 'error'
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
handleChange: RadioInputProps['onChange'] = (e) => {
|
|
97
|
+
const value = e.target.value
|
|
98
|
+
|
|
99
|
+
if (this.props.disabled || this.props.readOnly) {
|
|
100
|
+
e.preventDefault()
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof this.props.value === 'undefined') {
|
|
105
|
+
this.setState({ value })
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeof this.props.onChange === 'function') {
|
|
109
|
+
this.props.onChange(e, value)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get value() {
|
|
114
|
+
return typeof this.props.value === 'undefined'
|
|
115
|
+
? this.state.value
|
|
116
|
+
: this.props.value
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
renderChildren() {
|
|
120
|
+
const { children, name, variant, size, disabled, readOnly } = this.props
|
|
121
|
+
|
|
122
|
+
// This adds the passed in name property to each RadioInput component
|
|
123
|
+
// and checks the input whose value matches the value property
|
|
124
|
+
return Children.map(children, (child, index) => {
|
|
125
|
+
if (matchComponentTypes<RadioInputChild>(child, [RadioInput])) {
|
|
126
|
+
const isChecked = this.value === child.props.value
|
|
127
|
+
const defaultFocus = !this.value && index === 0
|
|
128
|
+
return safeCloneElement(child, {
|
|
129
|
+
name,
|
|
130
|
+
disabled: disabled || child.props.disabled,
|
|
131
|
+
variant,
|
|
132
|
+
size,
|
|
133
|
+
checked: isChecked,
|
|
134
|
+
onChange: this.handleChange,
|
|
135
|
+
readOnly: readOnly || child.props.readOnly,
|
|
136
|
+
width: child.props.width || 'auto',
|
|
137
|
+
'aria-describedby': this.hasMessages ? this._messagesId : undefined,
|
|
138
|
+
// only one radio in a group should be considered tabbable
|
|
139
|
+
// if a radio is checked, it should be the input to receive focus when tabbed to
|
|
140
|
+
// if none of the inputs are checked, the first should receive the focus
|
|
141
|
+
tabIndex: isChecked || defaultFocus ? 0 : -1,
|
|
142
|
+
label: child.props.label
|
|
143
|
+
})
|
|
144
|
+
} else {
|
|
145
|
+
return child // ignore (but preserve) children that aren't RadioInput
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
render() {
|
|
151
|
+
const { variant, layout, description, isRequired } = this.props
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<FormFieldGroup
|
|
155
|
+
{...omitProps(this.props, RadioInputGroup.allowedProps)}
|
|
156
|
+
{...pickProps(this.props, FormFieldGroup.allowedProps)}
|
|
157
|
+
description={description}
|
|
158
|
+
layout={
|
|
159
|
+
layout === 'columns' && variant === 'toggle' ? 'stacked' : layout
|
|
160
|
+
} // toggles already display in cols
|
|
161
|
+
vAlign={variant === 'toggle' ? 'middle' : 'top'}
|
|
162
|
+
rowSpacing="small"
|
|
163
|
+
colSpacing={variant === 'toggle' ? 'none' : 'small'} // keep toggles close together
|
|
164
|
+
startAt={variant === 'toggle' ? 'small' : undefined}
|
|
165
|
+
messagesId={this._messagesId}
|
|
166
|
+
elementRef={this.handleRef}
|
|
167
|
+
role="radiogroup"
|
|
168
|
+
isRequired={isRequired}
|
|
169
|
+
data-cid="RadioInputGroup"
|
|
170
|
+
>
|
|
171
|
+
{this.renderChildren()}
|
|
172
|
+
</FormFieldGroup>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export default RadioInputGroup
|
|
178
|
+
export { RadioInputGroup }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
|
|
27
|
+
import type { FormMessage } from '@instructure/ui-form-field/latest'
|
|
28
|
+
import type { OtherHTMLAttributes } from '@instructure/shared-types'
|
|
29
|
+
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
30
|
+
|
|
31
|
+
type RadioInputGroupOwnProps = {
|
|
32
|
+
/**
|
|
33
|
+
* This prop sets the
|
|
34
|
+
* [same low level HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#defining_a_radio_group)
|
|
35
|
+
*
|
|
36
|
+
* **Must be unique across the DOM** otherwise groups will interfere with
|
|
37
|
+
* each other
|
|
38
|
+
*/
|
|
39
|
+
name: string
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The text above the radio group. Use `ScreenReaderContent` if you don't want it to be visible.
|
|
43
|
+
*/
|
|
44
|
+
description: React.ReactNode
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* value to set on initial render
|
|
48
|
+
*/
|
|
49
|
+
defaultValue?: string | number
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* the selected value (must be accompanied by an `onChange` prop)
|
|
53
|
+
*/
|
|
54
|
+
value?: string | number
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* when used with the `value` prop, the component will not control its own state
|
|
58
|
+
*/
|
|
59
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void
|
|
60
|
+
|
|
61
|
+
disabled?: boolean
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* works just like disabled but keeps the same styles as if it were active
|
|
65
|
+
*/
|
|
66
|
+
readOnly?: boolean
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Array of objects with shape: `{
|
|
70
|
+
* text: ReactNode,
|
|
71
|
+
* type: One of: ['error', 'newError', 'hint', 'success', 'screenreader-only']
|
|
72
|
+
* }`
|
|
73
|
+
*/
|
|
74
|
+
messages?: FormMessage[]
|
|
75
|
+
|
|
76
|
+
variant?: 'simple' | 'toggle'
|
|
77
|
+
|
|
78
|
+
size?: 'small' | 'medium' | 'large'
|
|
79
|
+
|
|
80
|
+
layout?: 'stacked' | 'columns' | 'inline'
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* any children (ones that aren't `RadioInput` are passed through)
|
|
84
|
+
*/
|
|
85
|
+
children?: React.ReactNode
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Setting this to `true` adds and asterisk after the description (group label). It does not cause any behavioural change.
|
|
89
|
+
*/
|
|
90
|
+
isRequired?: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type PropKeys = keyof RadioInputGroupOwnProps
|
|
94
|
+
|
|
95
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
96
|
+
|
|
97
|
+
type RadioInputGroupProps = RadioInputGroupOwnProps &
|
|
98
|
+
OtherHTMLAttributes<RadioInputGroupOwnProps> &
|
|
99
|
+
WithDeterministicIdProps
|
|
100
|
+
|
|
101
|
+
type RadioInputGroupState = {
|
|
102
|
+
value?: string | number
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const allowedProps: AllowedPropKeys = [
|
|
106
|
+
'name',
|
|
107
|
+
'description',
|
|
108
|
+
'defaultValue',
|
|
109
|
+
'value',
|
|
110
|
+
'onChange',
|
|
111
|
+
'disabled',
|
|
112
|
+
'readOnly',
|
|
113
|
+
'messages',
|
|
114
|
+
'children',
|
|
115
|
+
'variant',
|
|
116
|
+
'size',
|
|
117
|
+
'layout',
|
|
118
|
+
'isRequired'
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
export type { RadioInputGroupProps, RadioInputGroupState }
|
|
122
|
+
export { allowedProps }
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
export { RadioInput } from '../RadioInput/v1'
|
|
25
|
+
export { RadioInputGroup } from '../RadioInputGroup/v1'
|
|
26
|
+
|
|
27
|
+
export type { RadioInputProps } from '../RadioInput/v1/props'
|
|
28
|
+
export type { RadioInputGroupProps } from '../RadioInputGroup/v1/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
export { RadioInput } from '../RadioInput/v2'
|
|
25
|
+
export { RadioInputGroup } from '../RadioInputGroup/v2'
|
|
26
|
+
|
|
27
|
+
export type { RadioInputProps } from '../RadioInput/v2/props'
|
|
28
|
+
export type { RadioInputGroupProps } from '../RadioInputGroup/v2/props'
|