playbook_ui 14.2.1.pre.alpha.pbntr373enablekitsforradio3665 → 14.2.1.pre.alpha.20240828cikubedbump3702

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: fa5747ca042dba51edc844b07e00549101cae2c3829c5c96c3aa9f73aea7491e
4
- data.tar.gz: 18bf10c5deb6626ad335955cceac2e6d5474efc880fb75e6958ed670e5e620d7
3
+ metadata.gz: 2d3e9d0cf8c716ccb0fc1b35d9280d785d203bc04efc76c5f2ed07b10db00fdb
4
+ data.tar.gz: 0553a09a6f688a341b9eefbebcb738644b1cf94f7a0fb14183afd2878ef8df0f
5
5
  SHA512:
6
- metadata.gz: bfecc78791b9be7bea37131e83dc9711af181361113412768e32d4a050db5dc960201dec5cada82968ae55afe5b1105301fdc563931bf9658a52894ab87cb989
7
- data.tar.gz: 10f25895d117d306052e76a930177996a074b34aa04cb810edcf62a20ab1eae9534879f4d8c78a51286b18bd20434094ff6e9b5fcfb6dc3fa983630529e2e7c0
6
+ metadata.gz: 5f6d08a59cb3eb52fff129ab86c45cd39c0a76c2386568987c3d9fd26e46701081dc451dfb4cfdf300a7133f5275e30d2043bcd5a8d37eef897b257de87274a8
7
+ data.tar.gz: 7f86b1c123956136832a9d4e46792db68853700cd5ac66d94e9de6331b4588981cc06b4ae2c8cfc2a8dd278b578717c6b4a2498067e78a6bfaa96659e24a423f
@@ -16,6 +16,7 @@ type CircleIconButtonProps = {
16
16
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
17
17
  id?: string,
18
18
  link?: string,
19
+ loading?: boolean,
19
20
  onClick?: React.MouseEventHandler<HTMLElement>,
20
21
  newWindow?: boolean,
21
22
  type?: 'button' | 'submit' | 'reset' | undefined,
@@ -32,6 +33,7 @@ const CircleIconButton = (props: CircleIconButtonProps): React.ReactElement => {
32
33
  htmlOptions = {},
33
34
  icon,
34
35
  id,
36
+ loading = false,
35
37
  onClick = noop,
36
38
  type,
37
39
  link,
@@ -61,6 +63,7 @@ const CircleIconButton = (props: CircleIconButtonProps): React.ReactElement => {
61
63
  disabled={disabled}
62
64
  htmlType={type}
63
65
  link={link}
66
+ loading={loading}
64
67
  newWindow={newWindow}
65
68
  onClick={onClick}
66
69
  text={null}
@@ -1,5 +1,5 @@
1
1
  <%= pb_content_tag do %>
2
- <%= pb_rails("button", props: {type: object.type, link: object.link, new_window:object.new_window, variant: object.variant, disabled: object.disabled, dark: object.dark}) do %>
2
+ <%= pb_rails("button", props: {type: object.type, loading: object.loading, link: object.link, new_window:object.new_window, variant: object.variant, disabled: object.disabled, dark: object.dark}) do %>
3
3
  <%= pb_rails("icon", props: {icon: object.icon, fixed_width: true, dark: object.dark}) %>
4
4
  <% end %>
5
5
  <% end %>
@@ -12,6 +12,8 @@ module Playbook
12
12
  prop :disabled, type: Playbook::Props::Boolean,
13
13
  default: false
14
14
  prop :icon, required: true
15
+ prop :loading, type: Playbook::Props::Boolean,
16
+ default: false
15
17
  prop :link
16
18
  prop :new_window, type: Playbook::Props::Boolean,
17
19
  default: false
@@ -15,3 +15,18 @@ test('default test', () => {
15
15
 
16
16
  expect(kit).toHaveClass('pb_circle_icon_button_kit')
17
17
  })
18
+
19
+ test('passes loading prop to button', () => {
20
+ render(
21
+ <CircleIconButton
22
+ data={{ testid: 'loading-test' }}
23
+ icon="plus"
24
+ loading
25
+ />
26
+ )
27
+
28
+ const kit = screen.getByTestId('loading-test')
29
+ const button = kit.querySelector('.pb_button_kit_primary_inline_enabled_loading')
30
+
31
+ expect(button).toBeInTheDocument()
32
+ })
@@ -0,0 +1,29 @@
1
+ <%= pb_rails("circle_icon_button", props: {
2
+ variant: "primary",
3
+ icon: "plus",
4
+ loading: true
5
+ }) %>
6
+
7
+ <br/>
8
+
9
+ <%= pb_rails("circle_icon_button", props: {
10
+ variant: "secondary",
11
+ icon: "pen",
12
+ loading: true
13
+ }) %>
14
+
15
+ <br/>
16
+
17
+ <%= pb_rails("circle_icon_button", props: {
18
+ disabled: true,
19
+ icon: "times",
20
+ loading: true
21
+ }) %>
22
+
23
+ <br/>
24
+
25
+ <%= pb_rails("circle_icon_button", props: {
26
+ variant: "link",
27
+ icon: "user",
28
+ loading: true
29
+ }) %>
@@ -0,0 +1,43 @@
1
+ import React from 'react'
2
+
3
+ import CircleIconButton from '../_circle_icon_button'
4
+
5
+ const CircleIconButtonLoading = (props) => (
6
+ <div>
7
+ <CircleIconButton
8
+ icon="plus"
9
+ loading
10
+ variant="primary"
11
+ {...props}
12
+ />
13
+
14
+ <br />
15
+
16
+ <CircleIconButton
17
+ icon="pen"
18
+ loading
19
+ variant="secondary"
20
+ {...props}
21
+ />
22
+
23
+ <br />
24
+
25
+ <CircleIconButton
26
+ disabled
27
+ icon="times"
28
+ loading
29
+ {...props}
30
+ />
31
+
32
+ <br />
33
+
34
+ <CircleIconButton
35
+ icon="user"
36
+ loading
37
+ variant="link"
38
+ {...props}
39
+ />
40
+ </div>
41
+ )
42
+
43
+ export default CircleIconButtonLoading
@@ -3,8 +3,10 @@ examples:
3
3
  rails:
4
4
  - circle_icon_button_default: Default
5
5
  - circle_icon_button_link: Link
6
+ - circle_icon_button_loading: Loading
6
7
 
7
8
  react:
8
9
  - circle_icon_button_default: Default
9
10
  - circle_icon_button_click: Click Handler
10
11
  - circle_icon_button_link: Link
12
+ - circle_icon_button_loading: Loading
@@ -1,3 +1,4 @@
1
1
  export { default as CircleIconButtonDefault } from './_circle_icon_button_default.jsx'
2
2
  export { default as CircleIconButtonClick } from './_circle_icon_button_click.jsx'
3
3
  export { default as CircleIconButtonLink } from './_circle_icon_button_link.jsx'
4
+ export { default as CircleIconButtonLoading } from './_circle_icon_button_loading.jsx'
@@ -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, ref: any ) => {
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)
@@ -14,7 +14,6 @@ examples:
14
14
  - radio_error: With Error
15
15
  - radio_alignment: Alignment
16
16
  - radio_disabled: Disabled
17
- - radio_children: Children
18
17
 
19
18
  swift:
20
19
  - 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'