playbook_ui 14.3.1 → 14.3.2.pre.alpha.PBNTR480radiocustomchildrenprop3759

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: 223cdf028c8ae365aea864aba370c644cb017cd3501f5516a6194b262e645247
4
- data.tar.gz: 28bba121bbd8c768afb2b19ba5b1de90590369d0b8221baac9c4f72b7fd94cd5
3
+ metadata.gz: cdd1dded7ae1ba871ee3d9c6301c8157a59069e5b30bd4192aa3923cda2f470f
4
+ data.tar.gz: f9a6884a3c4fbc00c1cacb9706fcfa02c166c5bcd81c394e37489a953f29b099
5
5
  SHA512:
6
- metadata.gz: ccc0daa6fc9ae5b8da363a8f27ca0d4eba016801cf10fa494fc342e3ec6b27a1ed9f7a868f4308201afb638044ffc9a7e26de4069cff1fd3db0b25fb1755de1e
7
- data.tar.gz: '082044ed8cf58f4ea10b85cbcbf2bda70e24084d272df992596251a495e8fac5376f0d28c4367885ac85f9a86227c52c45e42ed8ebbab319ad057251b3404caf'
6
+ metadata.gz: cb419c98c99095e28a2b17fef5e5f9a5dd258a2d75b26d46a34182af3c56396f3ac60de61e40f9fec9afc6dd38ef00341e54f02bc762f9d4eae31d5d5b783550
7
+ data.tar.gz: ad8e3e17e90704d2f8ee7f4ff4665e0a195cfc83c0a4908ae19f8cbf3edfbd79930a221d23ba714b9272053c1514e95753dfad4b56722ce1bbbfcb44ac2d07a2
@@ -6,6 +6,10 @@ export const showElement = (elem: HTMLElement) => {
6
6
  elem.style.overflow = "hidden"
7
7
  // Once the transition is complete, remove the inline max-height so the content can scale responsively
8
8
  window.setTimeout(() => {
9
+ // If a user toggles multiple times quickly in a row, 'is-visible' can be removed by hideElement's timeout
10
+ if (!elem.classList.contains('is-visible')) {
11
+ elem.classList.add('is-visible')
12
+ }
9
13
  elem.style.height = '';
10
14
  elem.style.overflow = "visible"
11
15
  }, 300);
@@ -1,27 +1,28 @@
1
- import React, { forwardRef, isValidElement, useRef } from 'react'
1
+ /*eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */
2
+
3
+ import React, { forwardRef } from 'react'
2
4
  import Body from '../pb_body/_body'
3
- import Flex from '../pb_flex/_flex'
4
5
  import classnames from 'classnames'
5
6
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
6
7
  import { globalProps, GlobalProps } from '../utilities/globalProps'
7
8
 
8
9
  type RadioProps = {
9
- aria?: { [key: string]: string },
10
+ aria?: {[key: string]: string},
10
11
  alignment?: string,
11
12
  checked?: boolean,
12
13
  children?: React.ReactChild[] | React.ReactChild,
13
14
  className?: string,
14
15
  dark?: boolean,
15
- data?: { [key: string]: string },
16
+ data?: {[key: string]: string},
16
17
  disabled?: boolean,
17
18
  error?: boolean,
18
- htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
19
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
19
20
  id?: string,
20
21
  label: string,
21
22
  name?: string,
22
23
  value?: string,
23
24
  text?: string,
24
- onChange: (event: React.FormEvent<HTMLInputElement> | null) => void,
25
+ onChange: (event: React.FormEvent<HTMLInputElement> | null)=>void,
25
26
  } & GlobalProps
26
27
 
27
28
  const Radio = ({
@@ -30,9 +31,9 @@ const Radio = ({
30
31
  children,
31
32
  className,
32
33
  dark = false,
34
+ data = {},
33
35
  disabled = false,
34
36
  error = false,
35
- data = {},
36
37
  htmlOptions = {},
37
38
  id,
38
39
  label,
@@ -41,103 +42,52 @@ const Radio = ({
41
42
  value = 'radio_text',
42
43
  onChange = () => { void 0 },
43
44
  ...props
44
- }: RadioProps ) => {
45
- const radioRef = useRef(null);
46
-
47
- const ariaProps = buildAriaProps(aria);
48
- const dataProps = buildDataProps(data);
49
- const htmlProps = buildHtmlProps(htmlOptions);
45
+ }: RadioProps, ref: any) => {
46
+ const ariaProps = buildAriaProps(aria)
47
+ const dataProps = buildDataProps(data)
48
+ const htmlProps = buildHtmlProps(htmlOptions)
50
49
  const classes = classnames(
51
- buildCss('pb_radio_kit', alignment),
52
- dark ? 'dark' : null,
53
- error ? 'error' : null,
50
+ buildCss('pb_radio_kit', alignment ),
51
+ dark ? 'dark': null, error ? 'error': null,
54
52
  globalProps(props),
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';
53
+ className)
66
54
 
67
55
  const displayRadio = (props: RadioProps & any) => {
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
- };
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
+ )}
98
72
 
99
73
  return (
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
- };
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
+ }
142
92
 
143
- export default forwardRef(Radio);
93
+ export default forwardRef(Radio)
@@ -0,0 +1,48 @@
1
+ <%
2
+ options = [
3
+ { label: "Orange", value: "Orange" },
4
+ { label: "Red", value: "Red" },
5
+ { label: "Green", value: "Green" },
6
+ { label: "Blue", value: "Blue" },
7
+ ]
8
+ %>
9
+
10
+ <%= pb_rails("radio", props: {
11
+ custom_children: true,
12
+ label: "Select",
13
+ name: "Group1",
14
+ value: "Select",
15
+ }) do %>
16
+ <%= pb_rails("select", props: {
17
+ min_width: "xs",
18
+ options: options,
19
+ }) %>
20
+ <% end %>
21
+
22
+ <%= pb_rails("radio", props: {
23
+ custom_children: true,
24
+ label: "Typeahead",
25
+ name: "Group1",
26
+ value: "Typeahead",
27
+ }) do %>
28
+ <%= pb_rails("typeahead", props: {
29
+ id: "typeahead-radio",
30
+ is_multi: false,
31
+ min_width: "xs",
32
+ options: options,
33
+ placeholder: "Select...",
34
+ })
35
+ %>
36
+ <% end %>
37
+
38
+ <%= pb_rails("radio", props: {
39
+ custom_children: true,
40
+ label: "Typography",
41
+ name: "Group1",
42
+ value: "Typography",
43
+ }) do %>
44
+ <%= pb_rails("title", props: {
45
+ text: "Custom Typography",
46
+ })
47
+ %>
48
+ <% end %>
@@ -0,0 +1 @@
1
+ Use the `custom_children` prop to enable the use of kits instead of text labels.
@@ -7,6 +7,7 @@ examples:
7
7
  - radio_options: With Options
8
8
  - radio_alignment: Alignment
9
9
  - radio_disabled: Disabled
10
+ - radio_custom_children: Custom Children
10
11
 
11
12
  react:
12
13
  - radio_default: Default
@@ -14,7 +15,6 @@ examples:
14
15
  - radio_error: With Error
15
16
  - radio_alignment: Alignment
16
17
  - radio_disabled: Disabled
17
- - radio_children: Children
18
18
 
19
19
  swift:
20
20
  - radio_default_swift: Default
@@ -3,4 +3,3 @@ 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'
@@ -0,0 +1,17 @@
1
+ import PbEnhancedElement from "../pb_enhanced_element"
2
+
3
+ const RADIO_SELECTOR = "[data-pb-radio-children]"
4
+ const RADIO_WRAPPER_SELECTOR = "[data-pb-radio-children-wrapper]"
5
+
6
+ export default class PbRadio extends PbEnhancedElement {
7
+ static get selector() {
8
+ return RADIO_SELECTOR
9
+ }
10
+
11
+ connect() {
12
+ const radioWrapperElement = this.element.querySelector(RADIO_WRAPPER_SELECTOR)
13
+ radioWrapperElement.addEventListener("click", () => {
14
+ this.element.querySelector("input[type='radio']").click()
15
+ })
16
+ }
17
+ }
@@ -1,18 +1,42 @@
1
- <%= content_tag(:label,
2
- aria: object.aria,
3
- checked: object.checked,
4
- class: object.classname,
5
- data: object.data,
6
- id: object.id,
7
- value: object.value,
8
- **combined_html_options) do %>
9
-
10
- <% if content.present? %>
11
- <%= content %>
12
- <% else %>
13
- <%= radio_button_tag object.name, object.value, object.selected, object.input_options %>
1
+ <% if object.custom_children %>
2
+ <div data-pb-radio-children="true">
3
+ <%= pb_rails("flex", props: {
4
+ aria: object.aria,
5
+ align: "center",
6
+ class: object.classname,
7
+ cursor: "pointer",
8
+ **combined_html_options
9
+ }) do %>
10
+ <%= content_tag(:label,
11
+ checked: object.checked,
12
+ class: object.classname,
13
+ data: object.data,
14
+ id: object.id,
15
+ value: object.value,
16
+ **combined_html_options) do %>
17
+ <%= input %>
18
+ <span class="pb_radio_button"></span>
19
+ <% end %>
20
+ <div data-pb-radio-children-wrapper="true"> <%= content %> </div>
14
21
  <% end %>
22
+ </div>
23
+ <% else %>
24
+ <%= content_tag(:label,
25
+ aria: object.aria,
26
+ checked: object.checked,
27
+ class: object.classname,
28
+ data: object.data,
29
+ id: object.id,
30
+ value: object.value,
31
+ **combined_html_options) do %>
32
+
33
+ <% if content.present? %>
34
+ <%= content %>
35
+ <% else %>
36
+ <%= radio_button_tag object.name, object.value, object.selected, object.input_options %>
37
+ <% end %>
15
38
 
16
- <span class="pb_radio_button"></span>
17
- <%= pb_rails("body", props: { status: object.body_status, text: object.text, dark: object.dark }) %>
18
- <% end %>
39
+ <span class="pb_radio_button"></span>
40
+ <%= pb_rails("body", props: { status: object.body_status, text: object.text, dark: object.dark }) %>
41
+ <% end %>
42
+ <% end %>
@@ -20,6 +20,8 @@ module Playbook
20
20
  default: "Radio Text"
21
21
  prop :value, type: Playbook::Props::String,
22
22
  default: "radio_text"
23
+ prop :custom_children, type: Playbook::Props::Boolean,
24
+ default: false
23
25
 
24
26
  def classname
25
27
  generate_classname("pb_radio_kit") + error_class + alignment_class
@@ -34,7 +36,7 @@ module Playbook
34
36
  end
35
37
 
36
38
  def input
37
- radio_button_tag(name, value, checked, input_options.merge(disabled: disabled))
39
+ radio_button_tag(name, value, checked, input_options.merge(disabled: disabled || input_options[:disabled]))
38
40
  end
39
41
 
40
42
  private
@@ -92,7 +92,6 @@ const Textarea = ({
92
92
  <Caption text={label} />
93
93
  {children || (
94
94
  <textarea
95
- className="pb_textarea_kit"
96
95
  disabled={disabled}
97
96
  name={name}
98
97
  onChange={onChange}
@@ -15,7 +15,6 @@
15
15
  <%= text_area(
16
16
  :object,
17
17
  :method,
18
- :class => "#{object.classname}",
19
18
  :max_characters => object.max_characters,
20
19
  :name => object.name,
21
20
  :onkeyup => object.onkeyup,