playbook_ui 14.14.0.pre.alpha.play1755pbcontenttag6327 → 14.14.0.pre.alpha.play1852reacthookformsupportradio6318
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_radio/_radio.tsx +85 -74
- data/app/pb_kits/playbook/pb_radio/docs/_radio_react_hook.jsx +60 -0
- data/app/pb_kits/playbook/pb_radio/docs/_radio_react_hook.md +1 -0
- data/app/pb_kits/playbook/pb_radio/docs/example.yml +2 -1
- data/app/pb_kits/playbook/pb_radio/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_radio/radio.test.js +16 -0
- data/app/pb_kits/playbook/pb_select/select.html.erb +5 -1
- data/app/pb_kits/playbook/pb_selectable_card/selectable_card.html.erb +5 -1
- data/app/pb_kits/playbook/pb_selectable_card_icon/selectable_card_icon.html.erb +4 -1
- data/app/pb_kits/playbook/pb_selectable_icon/selectable_icon.html.erb +5 -1
- data/dist/chunks/{_typeahead-PqkcDf1H.js → _typeahead-8okiJBmN.js} +1 -1
- data/dist/chunks/{_weekday_stacked-C3in3hCo.js → _weekday_stacked-DrKLZrfR.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08169588154946fcdb034524b646de6a050c504884a381f360f3a5470ea4917d'
|
4
|
+
data.tar.gz: d2794398a68601eeac259328439846e39816d671489e70cf35c9e9cc3669b76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca7b5000b148f3a0e8beac0926d11b05e36b9cc32cef3ccd72b8c53e04a4bdb6822e957ac82c85d50910dd4240d165c912e2b4eeb09566c8dbae3b70b28320de
|
7
|
+
data.tar.gz: fa1e9d28c2a166f674ac45c0c662262fb86fb69815409769be724bdba9a36b31bf24fe484053f17f97c691f9083759827b054f5a2a6652c7aab72bd8dc1c06f3
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import React, { forwardRef, useRef } from 'react'
|
1
|
+
import React, { useRef, forwardRef } from 'react'
|
4
2
|
import Body from '../pb_body/_body'
|
5
3
|
import Flex from '../pb_flex/_flex'
|
6
4
|
import classnames from 'classnames'
|
@@ -10,7 +8,7 @@ import { globalProps, GlobalProps } from '../utilities/globalProps'
|
|
10
8
|
type RadioProps = {
|
11
9
|
aria?: { [key: string]: string },
|
12
10
|
alignment?: string,
|
13
|
-
checked?: boolean,
|
11
|
+
checked?: boolean, // removed default assignment here
|
14
12
|
children?: React.ReactChild[] | React.ReactChild,
|
15
13
|
customChildren?: boolean,
|
16
14
|
className?: string,
|
@@ -24,10 +22,10 @@ type RadioProps = {
|
|
24
22
|
name?: string,
|
25
23
|
value?: string,
|
26
24
|
text?: string,
|
27
|
-
onChange
|
25
|
+
onChange?: (event: React.FormEvent<HTMLInputElement> | null) => void,
|
28
26
|
} & GlobalProps
|
29
27
|
|
30
|
-
const Radio = ({
|
28
|
+
const Radio = forwardRef<HTMLInputElement, RadioProps>(({
|
31
29
|
aria = {},
|
32
30
|
alignment,
|
33
31
|
children,
|
@@ -43,110 +41,123 @@ const Radio = ({
|
|
43
41
|
name = 'radio_name',
|
44
42
|
text = 'Radio Text',
|
45
43
|
value = 'radio_text',
|
44
|
+
checked,
|
46
45
|
onChange = () => { void 0 },
|
47
46
|
...props
|
48
|
-
}
|
49
|
-
const
|
47
|
+
}, ref) => {
|
48
|
+
const internalRef = useRef<HTMLInputElement>(null)
|
49
|
+
const setRefs = (el: HTMLInputElement) => {
|
50
|
+
internalRef.current = el
|
51
|
+
if (typeof ref === 'function') {
|
52
|
+
ref(el)
|
53
|
+
} else if (ref) {
|
54
|
+
(ref as React.MutableRefObject<HTMLInputElement | null>).current = el
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
const ariaProps = buildAriaProps(aria)
|
59
|
+
const dataProps = buildDataProps(data)
|
60
|
+
const htmlProps = buildHtmlProps(htmlOptions)
|
50
61
|
|
51
|
-
const ariaProps = buildAriaProps(aria);
|
52
|
-
const dataProps = buildDataProps(data);
|
53
|
-
const htmlProps = buildHtmlProps(htmlOptions);
|
54
62
|
const classes = classnames(
|
55
63
|
buildCss('pb_radio_kit', alignment),
|
56
64
|
dark ? 'dark' : null,
|
57
65
|
error ? 'error' : null,
|
58
66
|
globalProps(props),
|
59
67
|
className
|
60
|
-
)
|
68
|
+
)
|
61
69
|
|
62
70
|
const classesCustom = classnames(
|
63
71
|
dark ? 'dark' : null,
|
64
72
|
error ? 'error' : null,
|
65
73
|
globalProps(props),
|
66
74
|
className
|
67
|
-
)
|
75
|
+
)
|
76
|
+
|
77
|
+
const checkedProps = checked !== undefined ? { checked } : {}
|
68
78
|
|
69
|
-
const displayRadio = (
|
70
|
-
if (children && customChildren
|
71
|
-
return
|
79
|
+
const displayRadio = (inputProps: any) => {
|
80
|
+
if (children && customChildren === false)
|
81
|
+
return children
|
72
82
|
else
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
return (
|
84
|
+
<input
|
85
|
+
{...checkedProps}
|
86
|
+
disabled={disabled}
|
87
|
+
id={id}
|
88
|
+
name={name}
|
89
|
+
onChange={onChange}
|
90
|
+
ref={setRefs}
|
91
|
+
type="radio"
|
92
|
+
value={value}
|
93
|
+
{...inputProps}
|
94
|
+
/>
|
95
|
+
)
|
96
|
+
}
|
86
97
|
|
87
98
|
const handleContainerClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent> | undefined) => {
|
88
99
|
if (event) {
|
89
|
-
const target = event.target as HTMLElement
|
100
|
+
const target = event.target as HTMLElement
|
90
101
|
if (
|
91
102
|
target.id === 'pb-radio-children-wrapper' ||
|
92
103
|
target.closest('#pb-radio-children-wrapper')
|
93
104
|
) {
|
94
|
-
|
105
|
+
internalRef.current?.click()
|
95
106
|
}
|
96
107
|
}
|
97
|
-
}
|
108
|
+
}
|
98
109
|
|
99
|
-
return (
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
>
|
116
|
-
<label className={buildCss('pb_radio_kit', alignment)}>
|
110
|
+
return customChildren ? (
|
111
|
+
<Flex
|
112
|
+
{...ariaProps}
|
113
|
+
{...dataProps}
|
114
|
+
{...htmlProps}
|
115
|
+
align="center"
|
116
|
+
className={classesCustom}
|
117
|
+
cursor="pointer"
|
118
|
+
htmlFor={id}
|
119
|
+
htmlOptions={{
|
120
|
+
onClick: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
121
|
+
handleContainerClick(event)
|
122
|
+
}) as unknown as () => void
|
123
|
+
}}
|
124
|
+
id="radio-container"
|
125
|
+
>
|
126
|
+
<label className={buildCss('pb_radio_kit', alignment)}>
|
117
127
|
<input
|
128
|
+
{...checkedProps}
|
118
129
|
disabled={disabled}
|
119
130
|
id={id}
|
120
131
|
name={name}
|
121
132
|
onChange={onChange}
|
122
|
-
ref={
|
133
|
+
ref={setRefs}
|
123
134
|
type="radio"
|
124
135
|
value={value}
|
125
136
|
{...props}
|
126
137
|
/>
|
127
|
-
<span className="pb_radio_button" />
|
128
|
-
</label>
|
129
|
-
<div id="pb-radio-children-wrapper"> {children} </div>
|
130
|
-
</Flex>
|
131
|
-
) : (
|
132
|
-
<label
|
133
|
-
{...ariaProps}
|
134
|
-
{...dataProps}
|
135
|
-
{...htmlProps}
|
136
|
-
className={classes}
|
137
|
-
htmlFor={id}
|
138
|
-
>
|
139
|
-
<>{displayRadio(props)}</>
|
140
138
|
<span className="pb_radio_button" />
|
141
|
-
<Body
|
142
|
-
dark={dark}
|
143
|
-
status={error ? 'negative' : null}
|
144
|
-
text={label}
|
145
|
-
variant={null}
|
146
|
-
/>
|
147
139
|
</label>
|
148
|
-
|
149
|
-
|
150
|
-
|
140
|
+
<div id="pb-radio-children-wrapper"> {children} </div>
|
141
|
+
</Flex>
|
142
|
+
) : (
|
143
|
+
<label
|
144
|
+
{...ariaProps}
|
145
|
+
{...dataProps}
|
146
|
+
{...htmlProps}
|
147
|
+
className={classes}
|
148
|
+
htmlFor={id}
|
149
|
+
>
|
150
|
+
{displayRadio(props)}
|
151
|
+
<span className="pb_radio_button" />
|
152
|
+
<Body
|
153
|
+
dark={dark}
|
154
|
+
status={error ? 'negative' : null}
|
155
|
+
text={label}
|
156
|
+
variant={null}
|
157
|
+
/>
|
158
|
+
</label>
|
159
|
+
)
|
160
|
+
})
|
151
161
|
|
152
|
-
|
162
|
+
Radio.displayName = "Radio"
|
163
|
+
export default Radio
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import { useForm } from "react-hook-form"
|
3
|
+
import { Radio, Flex, Body } from "playbook-ui"
|
4
|
+
|
5
|
+
const RadioReactHook = () => {
|
6
|
+
const { register, watch } = useForm({
|
7
|
+
defaultValues: {
|
8
|
+
size: "Small",
|
9
|
+
},
|
10
|
+
})
|
11
|
+
|
12
|
+
const selectedSize = watch("size", "Small")
|
13
|
+
|
14
|
+
return (
|
15
|
+
<Flex orientation="row">
|
16
|
+
<Flex
|
17
|
+
align="start"
|
18
|
+
orientation="column"
|
19
|
+
paddingRight="lg"
|
20
|
+
>
|
21
|
+
<Radio
|
22
|
+
alignment="left"
|
23
|
+
label="Small"
|
24
|
+
marginBottom='sm'
|
25
|
+
name="size"
|
26
|
+
value="Small"
|
27
|
+
{...register("size")}
|
28
|
+
/>
|
29
|
+
<br />
|
30
|
+
<Radio
|
31
|
+
alignment="left"
|
32
|
+
label="Medium"
|
33
|
+
marginBottom='sm'
|
34
|
+
name="size"
|
35
|
+
value="Medium"
|
36
|
+
{...register("size")}
|
37
|
+
/>
|
38
|
+
<br />
|
39
|
+
<Radio
|
40
|
+
alignment="left"
|
41
|
+
label="Large"
|
42
|
+
marginBottom='sm'
|
43
|
+
name="size"
|
44
|
+
value="Large"
|
45
|
+
{...register("size")}
|
46
|
+
/>
|
47
|
+
</Flex>
|
48
|
+
<Flex
|
49
|
+
align="start"
|
50
|
+
orientation="column"
|
51
|
+
>
|
52
|
+
<Body
|
53
|
+
text={`Selected Size: ${selectedSize}`}
|
54
|
+
/>
|
55
|
+
</Flex>
|
56
|
+
</Flex>
|
57
|
+
)
|
58
|
+
}
|
59
|
+
|
60
|
+
export default RadioReactHook
|
@@ -0,0 +1 @@
|
|
1
|
+
You can pass react hook props to the radio kit.
|
@@ -16,6 +16,7 @@ examples:
|
|
16
16
|
- radio_alignment: Alignment
|
17
17
|
- radio_disabled: Disabled
|
18
18
|
- radio_custom_children: Custom Children
|
19
|
+
- radio_react_hook: React Hook Form
|
19
20
|
|
20
21
|
swift:
|
21
22
|
- radio_default_swift: Default
|
@@ -26,4 +27,4 @@ examples:
|
|
26
27
|
- radio_spacing_swift: Spacing
|
27
28
|
- radio_padding_swift: Padding
|
28
29
|
- radio_subtitle_swift: Subtitle
|
29
|
-
- radio_props_swift: ""
|
30
|
+
- radio_props_swift: ""
|
@@ -4,3 +4,4 @@ export { default as RadioError } from './_radio_error.jsx'
|
|
4
4
|
export { default as RadioAlignment } from './_radio_alignment.jsx'
|
5
5
|
export { default as RadioDisabled } from './_radio_disabled.jsx'
|
6
6
|
export { default as RadioCustomChildren } from './_radio_custom_children.jsx'
|
7
|
+
export { default as RadioReactHook } from './_radio_react_hook.jsx'
|
@@ -86,3 +86,19 @@ test('has disabled attribute', () => {
|
|
86
86
|
expect(input).toHaveAttribute('disabled')
|
87
87
|
})
|
88
88
|
|
89
|
+
|
90
|
+
test('has ref in the input element', () => {
|
91
|
+
const ref = React.createRef()
|
92
|
+
render(
|
93
|
+
<Radio
|
94
|
+
data={{ testid: testId }}
|
95
|
+
name="Radio-name"
|
96
|
+
ref={ref}
|
97
|
+
text="Radio"
|
98
|
+
value="radio value"
|
99
|
+
/>
|
100
|
+
)
|
101
|
+
|
102
|
+
expect(ref.current).not.toBeNull()
|
103
|
+
expect(ref.current?.tagName).toBe('INPUT')
|
104
|
+
})
|
@@ -1,4 +1,8 @@
|
|
1
|
-
<%=
|
1
|
+
<%= content_tag(:div,
|
2
|
+
aria: object.aria,
|
3
|
+
data: object.data,
|
4
|
+
class: object.classnames,
|
5
|
+
**combined_html_options) do %>
|
2
6
|
<% if object.label %>
|
3
7
|
<label class="pb_select_kit_label" for="<%= object.name %>">
|
4
8
|
<%= pb_rails("caption", props: { text: object.label, dark: object.dark }) %>
|
@@ -1,4 +1,8 @@
|
|
1
|
-
<%=
|
1
|
+
<%= content_tag(:div,
|
2
|
+
id: object.id,
|
3
|
+
data: object.data,
|
4
|
+
class: object.classname,
|
5
|
+
**combined_html_options) do %>
|
2
6
|
|
3
7
|
<% if object.multi %>
|
4
8
|
<%= check_box_tag(object.name, object.value, object.checked, object.additional_input_options) %>
|