playbook_ui 14.2.1.pre.alpha.bugfixforactionrc3663 → 14.2.1.pre.alpha.pbntr373enablekitsforradio3665

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edb541a83e28db25f69d9598522bed628cc9c1d8db58f3b398a961c9487726c0
4
- data.tar.gz: 9bd751b41aea6d0acfb08cbc540ddeb3321239277b2580e1991266e988942cd4
3
+ metadata.gz: fa5747ca042dba51edc844b07e00549101cae2c3829c5c96c3aa9f73aea7491e
4
+ data.tar.gz: 18bf10c5deb6626ad335955cceac2e6d5474efc880fb75e6958ed670e5e620d7
5
5
  SHA512:
6
- metadata.gz: 283976543a175b218e894ff4b01cd97cd9b53c53de29a822517cf703ec4618455df0fcb545f6194283a3f9f4b3c991aa91b35c30be4bc678db61aea92f922823
7
- data.tar.gz: 4311c8657fbe37ef7e808d53bc5262b3c490047bd9e03cce58d35005fb6a105102f48b3fa9a09f6d5828bd50278022cf07a00ab194f1a8ad3076e21d0772f66c
6
+ metadata.gz: bfecc78791b9be7bea37131e83dc9711af181361113412768e32d4a050db5dc960201dec5cada82968ae55afe5b1105301fdc563931bf9658a52894ab87cb989
7
+ data.tar.gz: 10f25895d117d306052e76a930177996a074b34aa04cb810edcf62a20ab1eae9534879f4d8c78a51286b18bd20434094ff6e9b5fcfb6dc3fa983630529e2e7c0
@@ -1,28 +1,27 @@
1
- /*eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */
2
-
3
- import React, { forwardRef } from 'react'
1
+ import React, { forwardRef, isValidElement, useRef } from 'react'
4
2
  import Body from '../pb_body/_body'
3
+ import Flex from '../pb_flex/_flex'
5
4
  import classnames from 'classnames'
6
5
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
7
6
  import { globalProps, GlobalProps } from '../utilities/globalProps'
8
7
 
9
8
  type RadioProps = {
10
- aria?: {[key: string]: string},
9
+ aria?: { [key: string]: string },
11
10
  alignment?: string,
12
11
  checked?: boolean,
13
12
  children?: React.ReactChild[] | React.ReactChild,
14
13
  className?: string,
15
14
  dark?: boolean,
16
- data?: {[key: string]: string},
15
+ data?: { [key: string]: string },
17
16
  disabled?: boolean,
18
17
  error?: boolean,
19
- htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
18
+ htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
20
19
  id?: string,
21
20
  label: string,
22
21
  name?: string,
23
22
  value?: string,
24
23
  text?: string,
25
- onChange: (event: React.FormEvent<HTMLInputElement> | null)=>void,
24
+ onChange: (event: React.FormEvent<HTMLInputElement> | null) => void,
26
25
  } & GlobalProps
27
26
 
28
27
  const Radio = ({
@@ -31,9 +30,9 @@ const Radio = ({
31
30
  children,
32
31
  className,
33
32
  dark = false,
34
- data = {},
35
33
  disabled = false,
36
34
  error = false,
35
+ data = {},
37
36
  htmlOptions = {},
38
37
  id,
39
38
  label,
@@ -42,52 +41,103 @@ const Radio = ({
42
41
  value = 'radio_text',
43
42
  onChange = () => { void 0 },
44
43
  ...props
45
- }: RadioProps, ref: any) => {
46
- const ariaProps = buildAriaProps(aria)
47
- const dataProps = buildDataProps(data)
48
- const htmlProps = buildHtmlProps(htmlOptions)
44
+ }: RadioProps, ref: any ) => {
45
+ const radioRef = useRef(null);
46
+
47
+ const ariaProps = buildAriaProps(aria);
48
+ const dataProps = buildDataProps(data);
49
+ const htmlProps = buildHtmlProps(htmlOptions);
49
50
  const classes = classnames(
50
- buildCss('pb_radio_kit', alignment ),
51
- dark ? 'dark': null, error ? 'error': null,
51
+ buildCss('pb_radio_kit', alignment),
52
+ dark ? 'dark' : null,
53
+ error ? 'error' : null,
52
54
  globalProps(props),
53
- className)
55
+ className
56
+ );
57
+
58
+ const classesCustom = classnames(
59
+ dark ? 'dark' : null,
60
+ error ? 'error' : null,
61
+ globalProps(props),
62
+ className
63
+ );
64
+
65
+ const isCustomChild = children && isValidElement(children) && children.type !== 'input';
54
66
 
55
67
  const displayRadio = (props: RadioProps & any) => {
56
- if (children)
57
- return (children)
58
- else
59
- return (
60
- <input
61
- disabled={disabled}
62
- id={id}
63
- name={name}
64
- onChange={onChange}
65
- ref={ref}
66
- text={text}
67
- type="radio"
68
- value={value}
69
- {...props}
70
- />
71
- )}
68
+ if (isValidElement(children) && children.type === 'input') {
69
+ return children;
70
+ } else if (isCustomChild || !children) {
71
+ return (
72
+ <input
73
+ disabled={disabled}
74
+ id={id}
75
+ name={name}
76
+ onChange={onChange}
77
+ ref={radioRef}
78
+ text={text}
79
+ type="radio"
80
+ value={value}
81
+ {...props}
82
+ />
83
+ );
84
+ }
85
+ };
86
+
87
+ const handleContainerClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent> | undefined) => {
88
+ if (event) {
89
+ const target = event.target as HTMLElement;
90
+ if (
91
+ target.id === 'pb-radio-children-wrapper' ||
92
+ target.closest('#pb-radio-children-wrapper')
93
+ ) {
94
+ radioRef.current?.click();
95
+ }
96
+ }
97
+ };
72
98
 
73
99
  return (
74
- <label
75
- {...ariaProps}
76
- {...dataProps}
77
- {...htmlProps}
78
- className={classes}
79
- htmlFor={id}
80
- >
81
- <>{displayRadio(props)}</>
82
- <span className="pb_radio_button" />
83
- <Body
84
- dark={dark}
85
- status={error ? 'negative' : null}
86
- text={label}
87
- variant={null}
88
- />
89
- </label>
90
- )
91
- }
100
+ isCustomChild ? (
101
+ <Flex
102
+ {...ariaProps}
103
+ {...dataProps}
104
+ {...htmlProps}
105
+ align='center'
106
+ className={classesCustom}
107
+ cursor='pointer'
108
+ htmlFor={id}
109
+ htmlOptions={{
110
+ onClick: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
111
+ handleContainerClick(event);
112
+ }) as unknown as () => void
113
+ }}
114
+ id="radio-container"
115
+ >
116
+ <label className={buildCss('pb_radio_kit', alignment)}>
117
+ <>{displayRadio(props)}</>
118
+ <span className="pb_radio_button" />
119
+ </label>
120
+ <div id="pb-radio-children-wrapper"> {children} </div>
121
+ </Flex>
122
+ ) : (
123
+ <label
124
+ {...ariaProps}
125
+ {...dataProps}
126
+ {...htmlProps}
127
+ className={classes}
128
+ htmlFor={id}
129
+ >
130
+ <>{displayRadio(props)}</>
131
+ <span className="pb_radio_button" />
132
+ <Body
133
+ dark={dark}
134
+ status={error ? 'negative' : null}
135
+ text={label}
136
+ variant={null}
137
+ />
138
+ </label>
139
+ )
140
+ );
141
+ };
92
142
 
93
- export default forwardRef(Radio)
143
+ export default forwardRef(Radio);
@@ -0,0 +1,56 @@
1
+ import React from 'react'
2
+ import Radio from '../_radio'
3
+ import Select from '../../pb_select/_select'
4
+ import Typeahead from '../../pb_typeahead/_typeahead'
5
+ import Title from '../../pb_title/_title'
6
+
7
+ const RadioChildren = (props) => {
8
+
9
+
10
+ const options = [
11
+ { label: 'Orange', value: 'Orange' },
12
+ { label: 'Red', value: 'Red' },
13
+ { label: 'Green', value: 'Green' },
14
+ { label: 'Blue', value: 'Blue' },
15
+ ]
16
+
17
+ return (
18
+ <div>
19
+ <Radio
20
+ label="Select"
21
+ name="Group1"
22
+ tabIndex={0}
23
+ value="Select"
24
+ {...props}
25
+ >
26
+ <Select
27
+ minWidth="xs"
28
+ options={options}
29
+ />
30
+ </Radio>
31
+ <Radio
32
+ label="Typeahead"
33
+ name="Group1"
34
+ tabIndex={0}
35
+ value="Typeahead"
36
+ {...props}
37
+ >
38
+ <Typeahead
39
+ minWidth="xs"
40
+ options={options}
41
+ />
42
+ </Radio>
43
+ <br />
44
+ <Radio
45
+ defaultChecked={false}
46
+ label="Typography"
47
+ name="Group1"
48
+ value="Typography"
49
+ {...props}
50
+ >
51
+ <Title text="Custom Typography" />
52
+ </Radio>
53
+ </div>
54
+ )
55
+ }
56
+ export default RadioChildren
@@ -14,6 +14,7 @@ examples:
14
14
  - radio_error: With Error
15
15
  - radio_alignment: Alignment
16
16
  - radio_disabled: Disabled
17
+ - radio_children: Children
17
18
 
18
19
  swift:
19
20
  - radio_default_swift: Default
@@ -3,3 +3,4 @@ export { default as RadioCustom } from './_radio_custom.jsx'
3
3
  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
+ export { default as RadioChildren } from './_radio_children.jsx'