playbook_ui 14.3.2 → 14.4.0.pre.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_collapsible/_helper_functions.ts +0 -4
  3. data/app/pb_kits/playbook/pb_radio/_radio.tsx +100 -50
  4. data/app/pb_kits/playbook/pb_radio/docs/_radio_children.jsx +59 -0
  5. data/app/pb_kits/playbook/pb_radio/docs/example.yml +1 -0
  6. data/app/pb_kits/playbook/pb_radio/docs/index.js +1 -0
  7. data/app/pb_kits/playbook/pb_text_input/_text_input.scss +0 -1
  8. data/app/pb_kits/playbook/pb_textarea/_textarea.tsx +1 -0
  9. data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +1 -0
  10. data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +13 -0
  11. data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +8 -1
  12. data/app/pb_kits/playbook/pb_typeahead/components/Control.tsx +23 -16
  13. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_margin_bottom.html.erb +88 -0
  14. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_margin_bottom.jsx +60 -0
  15. data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +2 -0
  16. data/app/pb_kits/playbook/pb_typeahead/docs/index.js +1 -0
  17. data/app/pb_kits/playbook/pb_typeahead/typeahead.html.erb +2 -1
  18. data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +6 -1
  19. data/dist/chunks/{_typeahead-DbAz2Okr.js → _typeahead-es44Ih6G.js} +3 -3
  20. data/dist/chunks/{_weekday_stacked-CZ5S17_d.js → _weekday_stacked-DWJJPUPQ.js} +2 -2
  21. data/dist/chunks/vendor.js +1 -1
  22. data/dist/playbook-doc.js +1 -1
  23. data/dist/playbook-rails-react-bindings.js +1 -1
  24. data/dist/playbook-rails.js +1 -1
  25. data/dist/playbook.css +1 -1
  26. data/lib/playbook/version.rb +2 -2
  27. metadata +10 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a71ebec22a46e5a072dae9a4ecfbc2582b8778b65f5b3ff612ad60f0c0ede4a1
4
- data.tar.gz: c21a5e48cd1d2436fc3d2bd3bb5845fa9b5f8095ec79ef865fbc550e9e55a1c0
3
+ metadata.gz: c48ab9d1f77a86bcff96b7d0c83dbe51ddd8cfc8c93ecd4731882cb510e6548a
4
+ data.tar.gz: 7d2d42ecac45e98e9246c483b493af1495a8e1e3931b87b4367f2c55afaa4285
5
5
  SHA512:
6
- metadata.gz: 80e2f4a56c6ea0ed1decd054d326c129676e2183e5cf574cffd059e1009bf3e05b733f5b99c0753d449c2a3affc806db45b64684d5c109eb42ea8ff2330ad284
7
- data.tar.gz: 0e22dea5792988151e1f06850a14373a710635169a092bdf4cacc9e05a23dfce61bd34c23334b42ab919c2085c9a32efe9af44a295acdbdf0301827ac85e3850
6
+ metadata.gz: 17c4db04ead953c8f19138f208ec11d0a7496fc69515587d9ff64b04c0de556373cc8d5de7ff6b1bf6ae72fb7e0926700b28fc741a582679c8e8c7f466176290
7
+ data.tar.gz: f4eeb6eb7c9b4771747492651ae6281f6f4afd2831a11f06b7c4d7c4ef19c04bb3caf2dc9cb463da80219cc0363ffb9c6da9f07cd8e9314b995be13d7c54dd63
@@ -6,10 +6,6 @@ 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
- }
13
9
  elem.style.height = '';
14
10
  elem.style.overflow = "visible"
15
11
  }, 300);
@@ -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 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,59 @@
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
+ marginBottom="sm"
22
+ name="Group1"
23
+ tabIndex={0}
24
+ value="Select"
25
+ {...props}
26
+ >
27
+ <Select
28
+ marginBottom="none"
29
+ minWidth="xs"
30
+ options={options}
31
+ />
32
+ </Radio>
33
+ <Radio
34
+ label="Typeahead"
35
+ marginBottom="sm"
36
+ name="Group1"
37
+ tabIndex={0}
38
+ value="Typeahead"
39
+ {...props}
40
+ >
41
+ <Typeahead
42
+ marginBottom="none"
43
+ minWidth="xs"
44
+ options={options}
45
+ />
46
+ </Radio>
47
+ <Radio
48
+ defaultChecked={false}
49
+ label="Typography"
50
+ name="Group1"
51
+ value="Typography"
52
+ {...props}
53
+ >
54
+ <Title text="Custom Typography" />
55
+ </Radio>
56
+ </div>
57
+ )
58
+ }
59
+ 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'
@@ -45,7 +45,6 @@
45
45
  }
46
46
  }
47
47
  .text_input_wrapper {
48
- margin-bottom: 1rem;
49
48
  input::placeholder,
50
49
  .text_input .placeholder {
51
50
  @include pb_body_light_dark;
@@ -92,6 +92,7 @@ const Textarea = ({
92
92
  <Caption text={label} />
93
93
  {children || (
94
94
  <textarea
95
+ className="pb_textarea_kit"
95
96
  disabled={disabled}
96
97
  name={name}
97
98
  onChange={onChange}
@@ -15,6 +15,7 @@
15
15
  <%= text_area(
16
16
  :object,
17
17
  :method,
18
+ :class => "#{object.classname}",
18
19
  :max_characters => object.max_characters,
19
20
  :name => object.name,
20
21
  :onkeyup => object.onkeyup,
@@ -107,4 +107,17 @@ test('should pass className prop', () => {
107
107
 
108
108
  const kit = screen.getByTestId('typeahead-test')
109
109
  expect(kit).toHaveClass(className)
110
+ })
111
+
112
+ test('typeahead textinput has mb_sm class by default', () => {
113
+ render(
114
+ <Typeahead
115
+ data={{ testid: 'default-mb-test' }}
116
+ options={options}
117
+ />
118
+ )
119
+
120
+ const kit = screen.getByTestId('default-mb-test')
121
+ const textInput = kit.querySelector(".pb_text_input_kit")
122
+ expect(textInput).toHaveClass("mb_sm")
110
123
  })
@@ -45,6 +45,7 @@ type TypeaheadProps = {
45
45
  getOptionLabel?: string | (() => any),
46
46
  getOptionValue?: string | (() => any),
47
47
  name?: string,
48
+ marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
48
49
  } & GlobalProps
49
50
 
50
51
  export type SelectValueType = {
@@ -76,12 +77,18 @@ const Typeahead = ({
76
77
  htmlOptions = {},
77
78
  id,
78
79
  loadOptions = noop,
80
+ marginBottom = "sm",
79
81
  ...props
80
82
  }: TypeaheadProps) => {
81
83
  const selectProps = {
82
84
  cacheOptions: true,
83
85
  components: {
84
- Control,
86
+ Control: (controlProps: any) => (
87
+ <Control
88
+ {...controlProps}
89
+ marginBottom={marginBottom}
90
+ />
91
+ ),
85
92
  ClearIndicator,
86
93
  IndicatorsContainer,
87
94
  IndicatorSeparator: null as null,
@@ -6,23 +6,30 @@ import TextInput from '../../pb_text_input/_text_input'
6
6
 
7
7
  type Props = {
8
8
  selectProps: any,
9
+ marginBottom?: string,
9
10
  }
10
11
 
11
- const TypeaheadControl = (props: Props) => (
12
- <div className="pb_typeahead_wrapper">
13
- <TextInput
14
- dark={props.selectProps.dark}
15
- error={props.selectProps.error}
16
- label={props.selectProps.label}
17
- >
18
- <Flex>
19
- <components.Control
20
- className="text_input"
21
- {...props}
22
- />
23
- </Flex>
24
- </TextInput>
25
- </div>
26
- )
12
+ const TypeaheadControl = (props: Props) => {
13
+ const { selectProps, marginBottom } = props
14
+ const { dark, error, label } = selectProps
15
+
16
+ return (
17
+ <div className="pb_typeahead_wrapper">
18
+ <TextInput
19
+ dark={dark}
20
+ error={error}
21
+ label={label}
22
+ marginBottom={marginBottom}
23
+ >
24
+ <Flex>
25
+ <components.Control
26
+ className="text_input"
27
+ {...props}
28
+ />
29
+ </Flex>
30
+ </TextInput>
31
+ </div>
32
+ )
33
+ }
27
34
 
28
35
  export default TypeaheadControl
@@ -0,0 +1,88 @@
1
+ <%
2
+ options = [
3
+ { label: 'Orange', value: '#FFA500' },
4
+ { label: 'Red', value: '#FF0000' },
5
+ { label: 'Green', value: '#00FF00' },
6
+ { label: 'Blue', value: '#0000FF' },
7
+ ]
8
+ %>
9
+
10
+ <%= pb_rails("typeahead", props: {
11
+ id: "typeahead-default",
12
+ placeholder: "All Colors",
13
+ options: options,
14
+ label: "None",
15
+ name: :foo,
16
+ is_multi: false,
17
+ margin_bottom: "none",
18
+ })
19
+ %>
20
+ <%= pb_rails("typeahead", props: {
21
+ id: "typeahead-default",
22
+ placeholder: "All Colors",
23
+ options: options,
24
+ label: "XXS",
25
+ name: :foo,
26
+ is_multi: false,
27
+ margin_bottom: "xxs",
28
+ })
29
+ %>
30
+ <%= pb_rails("typeahead", props: {
31
+ id: "typeahead-default",
32
+ placeholder: "All Colors",
33
+ options: options,
34
+ label: "XS",
35
+ name: :foo,
36
+ is_multi: false,
37
+ margin_bottom: "xs",
38
+ })
39
+ %>
40
+ <%= pb_rails("typeahead", props: {
41
+ id: "typeahead-default",
42
+ placeholder: "All Colors",
43
+ options: options,
44
+ label: "Default - SM",
45
+ name: :foo,
46
+ is_multi: false,
47
+ })
48
+ %>
49
+ <%= pb_rails("typeahead", props: {
50
+ id: "typeahead-default",
51
+ placeholder: "All Colors",
52
+ options: options,
53
+ label: "MD",
54
+ name: :foo,
55
+ is_multi: false,
56
+ margin_bottom: "md",
57
+ })
58
+ %>
59
+ <%= pb_rails("typeahead", props: {
60
+ id: "typeahead-default",
61
+ placeholder: "All Colors",
62
+ options: options,
63
+ label: "LG",
64
+ name: :foo,
65
+ is_multi: false,
66
+ margin_bottom: "lg",
67
+ })
68
+ %>
69
+ <%= pb_rails("typeahead", props: {
70
+ id: "typeahead-default",
71
+ placeholder: "All Colors",
72
+ options: options,
73
+ label: "XL",
74
+ name: :foo,
75
+ is_multi: false,
76
+ margin_bottom: "xl",
77
+ })
78
+ %>
79
+
80
+ <%= javascript_tag defer: "defer" do %>
81
+ document.addEventListener("pb-typeahead-kit-typeahead-default-result-option-select", function(event) {
82
+ console.log('Single Option selected')
83
+ console.dir(event.detail)
84
+ })
85
+ document.addEventListener("pb-typeahead-kit-typeahead-default-result-clear", function() {
86
+ console.log('All options cleared')
87
+ })
88
+ <% end %>
@@ -0,0 +1,60 @@
1
+ import React from 'react'
2
+
3
+ import Typeahead from '../_typeahead'
4
+
5
+ const options = [
6
+ { label: 'Orange', value: '#FFA500' },
7
+ { label: 'Red', value: '#FF0000' },
8
+ { label: 'Green', value: '#00FF00' },
9
+ { label: 'Blue', value: '#0000FF' },
10
+ ]
11
+
12
+ const TypeaheadMarginBottom = (props) => {
13
+ return (
14
+ <>
15
+ <Typeahead
16
+ label="None"
17
+ marginBottom="none"
18
+ options={options}
19
+ {...props}
20
+ />
21
+ <Typeahead
22
+ label="XXS"
23
+ marginBottom="xxs"
24
+ options={options}
25
+ {...props}
26
+ />
27
+ <Typeahead
28
+ label="XS"
29
+ marginBottom="xs"
30
+ options={options}
31
+ {...props}
32
+ />
33
+ <Typeahead
34
+ label="Default - SM"
35
+ options={options}
36
+ {...props}
37
+ />
38
+ <Typeahead
39
+ label="MD"
40
+ marginBottom="md"
41
+ options={options}
42
+ {...props}
43
+ />
44
+ <Typeahead
45
+ label="LG"
46
+ marginBottom="lg"
47
+ options={options}
48
+ {...props}
49
+ />
50
+ <Typeahead
51
+ label="XL"
52
+ marginBottom="xl"
53
+ options={options}
54
+ {...props}
55
+ />
56
+ </>
57
+ )
58
+ }
59
+
60
+ export default TypeaheadMarginBottom
@@ -9,6 +9,7 @@ examples:
9
9
  - typeahead_inline: Inline
10
10
  - typeahead_multi_kit: Multi Kit Options
11
11
  - typeahead_error_state: Error State
12
+ - typeahead_margin_bottom: Margin Bottom
12
13
 
13
14
  react:
14
15
  - typeahead_default: Default
@@ -23,3 +24,4 @@ examples:
23
24
  - typeahead_async_createable: Createable (+ Async Data)
24
25
  - typeahead_error_state: Error State
25
26
  - typeahead_custom_menu_list: Custom MenuList
27
+ - typeahead_margin_bottom: Margin Bottom
@@ -10,3 +10,4 @@ export { default as TypeaheadCreateable } from './_typeahead_createable.jsx'
10
10
  export { default as TypeaheadAsyncCreateable } from './_typeahead_async_createable.jsx'
11
11
  export { default as TypeaheadErrorState } from './_typeahead_error_state.jsx'
12
12
  export { default as TypeaheadCustomMenuList } from './_typeahead_custom_menu_list.jsx'
13
+ export { default as TypeaheadMarginBottom } from './_typeahead_margin_bottom.jsx'
@@ -20,7 +20,8 @@
20
20
  label: object.label,
21
21
  name: object.name,
22
22
  value: object.value,
23
- placeholder: object.placeholder
23
+ placeholder: object.placeholder,
24
+ margin_bottom: "none",
24
25
  }) %>
25
26
  <%= pb_rails("list", props: { ordered: false, borderless: false, xpadding: true, role: "status", aria: { live: "polite" }, data: { pb_typeahead_kit_results: true } }) do %>
26
27
  <% end %>
@@ -14,6 +14,9 @@ module Playbook
14
14
  default: false
15
15
  prop :label
16
16
  prop :load_options
17
+ prop :margin_bottom, type: Playbook::Props::Enum,
18
+ values: %w[none xxs xs sm md lg xl],
19
+ default: "sm"
17
20
  prop :multi_kit, type: Playbook::Props::String,
18
21
  default: ""
19
22
  prop :name
@@ -36,7 +39,8 @@ module Playbook
36
39
  prop :value
37
40
 
38
41
  def classname
39
- generate_classname("pb_typeahead_kit")
42
+ default_margin_bottom = margin_bottom.present? ? "" : " mb_sm"
43
+ generate_classname("pb_typeahead_kit") + default_margin_bottom
40
44
  end
41
45
 
42
46
  def inline_class
@@ -65,6 +69,7 @@ module Playbook
65
69
  inline: inline,
66
70
  isMulti: is_multi,
67
71
  label: label,
72
+ marginBottom: margin_bottom,
68
73
  multiKit: multi_kit,
69
74
  name: name,
70
75
  options: options,