playbook_ui 14.1.0.pre.alpha.PBNTR462starratingdefaultvalue3582 → 14.1.0.pre.alpha.pbntr373enablekitsforradio3593

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86c5c7a19a77669f0f9596f882885bf9755b7133dfda2003ffd1c992c2bae189
4
- data.tar.gz: 51834aabec9d4f6f0be017af72d03ef45f1a0f7bdd4990a74f0cc6f1170d6dea
3
+ metadata.gz: 3196a7c6aa5e0024e25c8581fe5f40df03e4e21cc9c56c49d0a1ca632526705a
4
+ data.tar.gz: f7c8bb1d07368d634a75ba43c233bfb38a56806f41b5233736cece0f9a7f94e4
5
5
  SHA512:
6
- metadata.gz: 3346c978f64fd9869968ddde829ce952c95d88f79e4f5402077c6852267a32327a230a50832859df450d9329c9c8250120e7c7785b23248a20d9bf0276924bfb
7
- data.tar.gz: 89c68496e6d686d31845b51181fcb2e55dc3643a9962a6778175bc4c2eb7be0aa058f3b62f17513e8da3853d2246f938d47b536c2e761f2eade0bff7674d33c9
6
+ metadata.gz: 88b1dc8797609b61c77cac834ce35550d8a42ab675575b683b266d0b543c763d1f04effee8183793c331e6e4a7d96c53eb7b9b103e1a14d96cd0c4f337767f1b
7
+ data.tar.gz: 1ea4a1fdd91607e9c6c7af6029f637a48f8b770366ce33e87eb83be9f9672898c09fcac287c1c3478f226efd7c1c3a951c03c8769ee15da4b6560cd5af70e8ed
@@ -8,17 +8,17 @@
8
8
  display: inline-flex;
9
9
  cursor: pointer;
10
10
 
11
- .pb_radio_button {
12
- width: 22px;
13
- min-width: 22px;
14
- height: 22px;
15
- box-sizing: border-box;
16
- border-radius: 1000px;
17
- border: 2px solid $border_light;
18
- margin-right: $space_xs;
19
- transition: background $transition_default ease, box-shadow $transition_default ease, border-color $transition_default ease;
20
- }
21
-
11
+ .pb_radio_button{
12
+ width: 22px;
13
+ min-width: 22px;
14
+ height: 22px;
15
+ box-sizing: border-box;
16
+ border-radius: 1000px;
17
+ border: 2px solid $border_light;
18
+ margin-right: $space_xs;
19
+ transition: background $transition_default ease, box-shadow $transition_default ease, border-color $transition_default ease;
20
+ }
21
+
22
22
  @media (hover:hover) {
23
23
  &:hover .pb_radio_button {
24
24
  background-color: $bg_light;
@@ -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 ) => {
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 React.cloneElement(children, { ...props, ref: radioRef });
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 === 'children-wrapper' ||
92
+ target.closest('#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="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,51 @@
1
+ import React from 'react'
2
+ import Radio from '../_radio'
3
+ import Typeahead from '../../pb_typeahead/_typeahead'
4
+ import Dropdown from '../../pb_dropdown/_dropdown'
5
+ import Title from '../../pb_title/_title'
6
+
7
+ const RadioChildren = (props) => {
8
+
9
+
10
+ const options = [
11
+ { label: 'Orange', value: '#FFA500' },
12
+ { label: 'Red', value: '#FF0000' },
13
+ { label: 'Green', value: '#00FF00' },
14
+ { label: 'Blue', value: '#0000FF' },
15
+ ]
16
+
17
+ return (
18
+ <div>
19
+ <Radio
20
+ label="Power"
21
+ name="Group2"
22
+ tabIndex={0}
23
+ value="Power"
24
+ {...props}
25
+ >
26
+ <Dropdown options={options}/>
27
+ </Radio>
28
+ <br />
29
+ <Radio
30
+ defaultChecked={false}
31
+ label="Nitro"
32
+ name="Group2"
33
+ value="Nitro"
34
+ {...props}
35
+ >
36
+ <Typeahead options={options} />
37
+ </Radio>
38
+ <br />
39
+ <Radio
40
+ defaultChecked={false}
41
+ label="Google"
42
+ name="Group2"
43
+ value="Google"
44
+ {...props}
45
+ >
46
+ <Title text="Custom Typography" />
47
+ </Radio>
48
+ </div>
49
+ )
50
+ }
51
+ export default RadioChildren
@@ -34,4 +34,4 @@ const RadioDefault = (props) => {
34
34
  </div>
35
35
  )
36
36
  }
37
- export default RadioDefault
37
+ export default RadioDefault
@@ -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'
@@ -12,7 +12,6 @@ export default class PbStarRating extends PbEnhancedElement {
12
12
  connect() {
13
13
  this.addEventListeners()
14
14
  this.handleFormReset()
15
- this.setDefaultValue()
16
15
  }
17
16
 
18
17
  addEventListeners() {
@@ -154,13 +153,4 @@ export default class PbStarRating extends PbEnhancedElement {
154
153
  }
155
154
  }
156
155
  }
157
-
158
- setDefaultValue() {
159
- const hiddenInput = this.element.querySelector(STAR_RATING_INPUT_DATA_SELECTOR)
160
- const defaultValue = hiddenInput.value
161
-
162
- if (defaultValue) {
163
- this.updateStarColors(defaultValue)
164
- }
165
- }
166
156
  }
@@ -34,7 +34,6 @@ module Playbook
34
34
  default: false
35
35
  prop :input_options, type: Playbook::Props::HashProp,
36
36
  default: {}
37
- prop :default_value
38
37
 
39
38
  def one_decimal_rating
40
39
  rating.to_f.round(1)
@@ -121,8 +120,7 @@ module Playbook
121
120
  data: { "pb-star-rating-input": true },
122
121
  name: name,
123
122
  required: required,
124
- style: "display: none",
125
- value: default_value || ""
123
+ style: "display: none"
126
124
  )
127
125
  end
128
126
  end