playbook_ui 12.12.0 → 12.13.0.pre.alpha.addingProductTokens439

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_card/_card.scss +2 -3
  3. data/app/pb_kits/playbook/pb_card/card.rb +1 -1
  4. data/app/pb_kits/playbook/pb_card/docs/_card_background.html.erb +22 -35
  5. data/app/pb_kits/playbook/pb_card/docs/_card_background.jsx +34 -37
  6. data/app/pb_kits/playbook/pb_card/docs/_card_header.html.erb +27 -44
  7. data/app/pb_kits/playbook/pb_card/docs/_card_header.jsx +21 -33
  8. data/app/pb_kits/playbook/pb_card/docs/_card_highlight.html.erb +7 -7
  9. data/app/pb_kits/playbook/pb_card/docs/_card_highlight.jsx +6 -8
  10. data/app/pb_kits/playbook/pb_flex/_flex.scss +1 -0
  11. data/app/pb_kits/playbook/pb_flex/_flex.tsx +4 -3
  12. data/app/pb_kits/playbook/pb_flex/docs/_flex_gap.html.erb +1 -1
  13. data/app/pb_kits/playbook/pb_flex/docs/_flex_gap.jsx +1 -1
  14. data/app/pb_kits/playbook/pb_flex/docs/_flex_gap.md +1 -1
  15. data/app/pb_kits/playbook/pb_flex/flex.rb +3 -3
  16. data/app/pb_kits/playbook/pb_legend/docs/_legend_colors.html.erb +4 -4
  17. data/app/pb_kits/playbook/pb_legend/docs/_legend_colors.jsx +5 -5
  18. data/app/pb_kits/playbook/pb_legend/docs/_legend_custom_colors.html.erb +3 -3
  19. data/app/pb_kits/playbook/pb_legend/docs/_legend_custom_colors.jsx +3 -3
  20. data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +107 -0
  21. data/app/pb_kits/playbook/pb_selectable_list/{_selectable_list.jsx → _selectable_list.tsx} +11 -9
  22. data/app/pb_kits/playbook/pb_selectable_list/selectable_list.test.js +68 -0
  23. data/app/pb_kits/playbook/pb_table/docs/_table_side_highlight.html.erb +6 -6
  24. data/app/pb_kits/playbook/pb_table/docs/_table_side_highlight.jsx +6 -6
  25. data/app/pb_kits/playbook/tokens/_colors.scss +55 -15
  26. data/app/pb_kits/playbook/utilities/_colors.scss +7 -13
  27. data/lib/playbook/version.rb +2 -2
  28. metadata +10 -9
  29. data/app/pb_kits/playbook/pb_selectable_list/_item.jsx +0 -106
@@ -5,22 +5,22 @@ const LegendColors = (props) => (
5
5
  <div>
6
6
  <Legend
7
7
  color="data_8"
8
- text="Windows"
8
+ text="Data 8"
9
9
  {...props}
10
10
  />
11
11
  <Legend
12
12
  color="warning"
13
- text="Windows"
13
+ text="Warning"
14
14
  {...props}
15
15
  />
16
16
  <Legend
17
- color="windows"
18
- text="Windows"
17
+ color="product_6_highlight"
18
+ text="Product 6 (highlight)"
19
19
  {...props}
20
20
  />
21
21
  <Legend
22
22
  color="category_7"
23
- text="Windows"
23
+ text="Category 7"
24
24
  {...props}
25
25
  />
26
26
  </div>
@@ -1,3 +1,3 @@
1
- <%= pb_rails("legend", props: { color: "#dc418a", text: "Windows" }) %>
2
- <%= pb_rails("legend", props: { color: "#3ef0b8", text: "Windows" }) %>
3
- <%= pb_rails("legend", props: { color: "#ab8b04", text: "Windows" }) %>
1
+ <%= pb_rails("legend", props: { color: "#dc418a", text: "Custom Legend Color 1" }) %>
2
+ <%= pb_rails("legend", props: { color: "#3ef0b8", text: "Custom Legend Color 2" }) %>
3
+ <%= pb_rails("legend", props: { color: "#ab8b04", text: "Custom Legend Color 3" }) %>
@@ -5,17 +5,17 @@ const LegendCustomColors = (props) => (
5
5
  <div>
6
6
  <Legend
7
7
  color="#dc418a"
8
- text="Windows"
8
+ text="Custom Legend Color 1"
9
9
  {...props}
10
10
  />
11
11
  <Legend
12
12
  color="#3ef0b8"
13
- text="Windows"
13
+ text="Custom Legend Color 2"
14
14
  {...props}
15
15
  />
16
16
  <Legend
17
17
  color="#ab8b04"
18
- text="Windows"
18
+ text="Custom Legend Color 3"
19
19
  {...props}
20
20
  />
21
21
  </div>
@@ -0,0 +1,107 @@
1
+ import React, { useState } from "react";
2
+ import classnames from "classnames";
3
+
4
+ import { buildAriaProps, buildCss, buildDataProps } from "../utilities/props";
5
+ import { globalProps } from "../utilities/globalProps";
6
+
7
+ import Checkbox from "../pb_checkbox/_checkbox";
8
+ import ListItem from "../pb_list/_list_item";
9
+ import Radio from "../pb_radio/_radio";
10
+
11
+ export type SelectableListItemProps = {
12
+ aria?: { [key: string]: string };
13
+ children: React.ReactNode[] | React.ReactNode;
14
+ checked?: boolean;
15
+ className?: string;
16
+ data?: object;
17
+ defaultChecked?: boolean;
18
+ id?: string;
19
+ label?: string;
20
+ text?: string;
21
+ name?: string;
22
+ value?: string;
23
+ variant?: string;
24
+ onChange: (arg: React.ChangeEvent<HTMLInputElement> | null) => void;
25
+ };
26
+
27
+ const SelectableListItem = ({
28
+ aria = {},
29
+ checked = false,
30
+ children,
31
+ className,
32
+ data = {},
33
+ defaultChecked,
34
+ id,
35
+ label,
36
+ text = "",
37
+ name = "",
38
+ value = "",
39
+ variant = "checkbox",
40
+ onChange = () => {},
41
+ ...props
42
+ }: SelectableListItemProps) => {
43
+ const ariaProps = buildAriaProps(aria);
44
+ const dataProps = buildDataProps(data);
45
+ const classes = classnames(
46
+ buildCss("pb_selectable_list_item_kit"),
47
+ globalProps(props),
48
+ className
49
+ );
50
+
51
+ const initialCheckedState = checked;
52
+ const [checkedState, setCheckedState] = useState(initialCheckedState);
53
+
54
+ const handleChecked = (event: React.ChangeEvent<HTMLInputElement>) => {
55
+ onChange(event);
56
+ setCheckedState(event.target.checked);
57
+ };
58
+
59
+ return (
60
+ <ListItem
61
+ {...props}
62
+ className={classnames(checkedState ? "checked_item" : "", className)}
63
+ >
64
+ <div {...ariaProps} {...dataProps} className={classes}>
65
+ {variant == "checkbox" && (
66
+ <>
67
+ <Checkbox
68
+ checked={checkedState}
69
+ id={id}
70
+ name={name}
71
+ onChange={handleChecked}
72
+ // eslint suppressor, text is needed to display on screen
73
+ //@ts-ignore
74
+ text={label || (text && false)}
75
+ type="checkbox"
76
+ value={value}
77
+ {...props}
78
+ />
79
+ {children}
80
+ </>
81
+ )}
82
+ {variant == "radio" && (
83
+ <>
84
+ <Radio
85
+ defaultChecked={defaultChecked}
86
+ id={id}
87
+ label={label}
88
+ name={name}
89
+ onChange={onChange}
90
+ //@ts-ignore
91
+ text={label}
92
+ type="radio"
93
+ value={value}
94
+ {...props}
95
+ />
96
+ {children}
97
+ </>
98
+ )}
99
+ {variant !== "checkbox" && variant !== "radio" && (
100
+ { children }
101
+ )}
102
+ </div>
103
+ </ListItem>
104
+ );
105
+ };
106
+
107
+ export default SelectableListItem;
@@ -1,16 +1,16 @@
1
- /* @flow */
2
1
  import React, { useState } from 'react'
3
2
  import classnames from 'classnames'
4
3
 
5
4
  import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
6
5
  import { globalProps } from '../utilities/globalProps'
6
+ import { SelectableListItemProps } from './_item.js'
7
7
 
8
8
  import List from '../pb_list/_list'
9
- import SelectableListItem from './_item.jsx'
9
+ import SelectableListItem from './_item'
10
10
 
11
11
  type SelectableListProps = {
12
- aria?: object,
13
- children?: Node,
12
+ aria?: {[key: string]: string },
13
+ children?: React.ReactElement[],
14
14
  className?: string,
15
15
  data?: object,
16
16
  id?: string,
@@ -30,17 +30,18 @@ const SelectableList = (props: SelectableListProps) => {
30
30
  const classes = classnames(buildCss('pb_selectable_list_kit'), globalProps(props), className)
31
31
  const dataProps = buildDataProps(data)
32
32
  const isRadio = props.variant === "radio"
33
- const defaultCheckedRadioValue = children.filter(item => item.props.defaultChecked)[0]?.props?.value
33
+ const defaultCheckedRadioValue = children.filter((item: {props:SelectableListItemProps} ) => item.props.defaultChecked)[0]?.props?.value
34
+
34
35
  const [selectedRadioValue, setSelectedRadioValue] = useState(defaultCheckedRadioValue)
35
36
 
36
- const onChangeRadioValue = ({ target }) => {
37
+ const onChangeRadioValue = ({ target }: React.ChangeEvent<HTMLInputElement>) => {
37
38
  setSelectedRadioValue(target.value)
38
39
  }
39
40
 
40
41
  let selectableListItems = children
41
42
 
42
43
  if (isRadio) {
43
- selectableListItems = children.map(({ props }) => {
44
+ selectableListItems = children.map(( {props}: {props:SelectableListItemProps} ) => {
44
45
  return (
45
46
  <SelectableListItem
46
47
  {...props}
@@ -51,6 +52,7 @@ const SelectableList = (props: SelectableListProps) => {
51
52
  )
52
53
  })
53
54
  }
55
+
54
56
 
55
57
  return (
56
58
  <div
@@ -59,13 +61,13 @@ const SelectableList = (props: SelectableListProps) => {
59
61
  className={classes}
60
62
  id={id}
61
63
  >
62
- <List {...props}>
64
+ <List variant={props.variant}>
63
65
  {selectableListItems}
64
66
  </List>
65
67
  </div>
66
68
  )
67
69
  }
68
-
70
+
69
71
  SelectableList.Item = SelectableListItem
70
72
 
71
73
  export default SelectableList
@@ -0,0 +1,68 @@
1
+ import React from 'react'
2
+ import { render, screen } from '../utilities/test-utils'
3
+ import SelectableList from './_selectable_list'
4
+
5
+ const testId = "selectable-list-test"
6
+
7
+ const SelectableListCheckbox = () => {
8
+ return (
9
+ <SelectableList
10
+ data={{ testid: testId }}
11
+ variant="checkbox">
12
+ <SelectableList.Item
13
+ label="Mild"
14
+ name="checkbox-name-1"
15
+ value="1"
16
+ />
17
+ <SelectableList.Item
18
+ checked
19
+ label="Medium"
20
+ name="checkbox-name-2"
21
+ value="2"
22
+ />
23
+ </SelectableList>
24
+ )
25
+ }
26
+
27
+ const SelectableListRadio = () => {
28
+ return (
29
+ <SelectableList
30
+ data={{ testid: testId }}
31
+ variant="radio">
32
+ <SelectableList.Item
33
+ label="Small"
34
+ name="radio"
35
+ value="1"
36
+ />
37
+ <SelectableList.Item
38
+ defaultChecked
39
+ label="Medium"
40
+ name="radio"
41
+ value="2"
42
+ />
43
+ </SelectableList>
44
+ )
45
+ }
46
+
47
+
48
+ test("classname renders as expected", () => {
49
+ render(<SelectableListCheckbox />)
50
+
51
+ const kit = screen.getByTestId("selectable-list-test")
52
+ expect(kit).toHaveClass("pb_selectable_list_kit")
53
+ })
54
+
55
+ test("renders variant checkbox", () => {
56
+ render(<SelectableListCheckbox />)
57
+ const kit = screen.getByTestId("selectable-list-test")
58
+ const checkbox = kit.querySelector(".pb_checkbox_kit")
59
+ expect(checkbox).toBeInTheDocument()
60
+ })
61
+
62
+ test("renders variant radio", () => {
63
+ render(<SelectableListRadio />)
64
+ const kit = screen.getByTestId("selectable-list-test")
65
+ const checkbox = kit.querySelector(".pb_radio_kit")
66
+ expect(checkbox).toBeInTheDocument()
67
+
68
+ })
@@ -9,22 +9,22 @@
9
9
  </tr>
10
10
  </thead>
11
11
  <tbody>
12
- <%= pb_rails("table/table_row", props: { side_highlight_color: "solar" }) do %>
13
- <td>Solar</td>
12
+ <%= pb_rails("table/table_row", props: { side_highlight_color: "product_1_highlight" }) do %>
13
+ <td>Product 1</td>
14
14
  <td>Value 2</td>
15
15
  <td>Value 3</td>
16
16
  <td>Value 4</td>
17
17
  <td>Value 5</td>
18
18
  <% end %>
19
- <%= pb_rails("table/table_row", props: { side_highlight_color: "roofing" }) do %>
20
- <td>Roofing</td>
19
+ <%= pb_rails("table/table_row", props: { side_highlight_color: "product_2_highlight" }) do %>
20
+ <td>Product 2</td>
21
21
  <td>Value 2</td>
22
22
  <td>Value 3</td>
23
23
  <td>Value 4</td>
24
24
  <td>Value 5</td>
25
25
  <% end %>
26
- <%= pb_rails("table/table_row", props: { side_highlight_color: "gutters" }) do %>
27
- <td>Gutters</td>
26
+ <%= pb_rails("table/table_row", props: { side_highlight_color: "product_3_highlight" }) do %>
27
+ <td>Product 3</td>
28
28
  <td>Value 2</td>
29
29
  <td>Value 3</td>
30
30
  <td>Value 4</td>
@@ -21,30 +21,30 @@ const TableSideHighlight = (props) => {
21
21
  </thead>
22
22
  <tbody>
23
23
  <TableRow
24
- sideHighlightColor="solar"
24
+ sideHighlightColor="product_1_highlight"
25
25
  {...props}
26
26
  >
27
- <td>{'Solar'}</td>
27
+ <td>{'Product 1'}</td>
28
28
  <td>{'Value 2'}</td>
29
29
  <td>{'Value 3'}</td>
30
30
  <td>{'Value 4'}</td>
31
31
  <td>{'Value 5'}</td>
32
32
  </TableRow>
33
33
  <TableRow
34
- sideHighlightColor="roofing"
34
+ sideHighlightColor="product_2_highlight"
35
35
  {...props}
36
36
  >
37
- <td>{'Roofing'}</td>
37
+ <td>{'Product 2'}</td>
38
38
  <td>{'Value 2'}</td>
39
39
  <td>{'Value 3'}</td>
40
40
  <td>{'Value 4'}</td>
41
41
  <td>{'Value 5'}</td>
42
42
  </TableRow>
43
43
  <TableRow
44
- sideHighlightColor="gutters"
44
+ sideHighlightColor="product_3_highlight"
45
45
  {...props}
46
46
  >
47
- <td>{'Gutters'}</td>
47
+ <td>{'Product 3'}</td>
48
48
  <td>{'Value 2'}</td>
49
49
  <td>{'Value 3'}</td>
50
50
  <td>{'Value 4'}</td>
@@ -213,22 +213,62 @@ $status_color_text: (
213
213
  $primary_action: $primary !default;
214
214
 
215
215
  /* Product colors ---------------------*/
216
- $windows: $royal !default;
217
- $siding: $yellow !default;
218
- $doors: $teal !default;
219
- $solar: $green !default;
220
- $roofing: $slate !default;
221
- $gutters: $purple !default;
222
- $insulation: $red !default;
216
+ $product_1_background: #003DB2 !default;
217
+ $product_1_highlight: #0057FF !default;
218
+ $product_2_background: #6000AC !default;
219
+ $product_2_highlight: #8200E9 !default;
220
+ $product_3_background: #B85C00 !default;
221
+ $product_3_highlight: #CE7500 !default;
222
+ $product_4_background: #007E8F !default;
223
+ $product_4_highlight: #00B9D2 !default;
224
+ $product_5_background: #760B24 !default;
225
+ $product_5_highlight: #B8032E !default;
226
+ $product_6_background: #008540 !default;
227
+ $product_6_highlight: #00A851 !default;
228
+ $product_7_background: #96006C !default;
229
+ $product_7_highlight: #CD0094 !default;
230
+ $product_8_background: #144075 !default;
231
+ $product_8_highlight: #1A569E !default;
232
+ $product_9_background: #fcc419 !default;
233
+ $product_9_highlight: #ffd43b !default;
234
+ $product_10_background: #20c997 !default;
235
+ $product_10_highlight: #38d9a9 !default;
236
+ $windows: $product_1_background !default; // deprecated
237
+ $siding: $product_2_background !default; // deprecated
238
+ $doors: $product_3_background !default; // deprecated
239
+ $solar: $product_4_background !default; // deprecated
240
+ $roofing: $product_5_background !default; // deprecated
241
+ $gutters: $product_6_background !default; // deprecated
242
+ $insulation: $product_7_background !default; // deprecated
223
243
  $product_colors: (
224
- windows: $windows,
225
- siding: $siding,
226
- doors: $doors,
227
- solar: $solar,
228
- roofing: $roofing,
229
- gutters: $gutters,
230
- insulation: $insulation
231
- );
244
+ windows: $windows,
245
+ siding: $siding,
246
+ doors: $doors,
247
+ solar: $solar,
248
+ roofing: $roofing,
249
+ gutters: $gutters,
250
+ insulation: $insulation,
251
+ product_1_background: $product_1_background,
252
+ product_1_highlight: $product_1_highlight,
253
+ product_2_background: $product_2_background,
254
+ product_2_highlight: $product_2_highlight,
255
+ product_3_background: $product_3_background,
256
+ product_3_highlight: $product_3_highlight,
257
+ product_4_background: $product_4_background,
258
+ product_4_highlight: $product_4_highlight,
259
+ product_5_background: $product_5_background,
260
+ product_5_highlight: $product_5_highlight,
261
+ product_6_background: $product_6_background,
262
+ product_6_highlight: $product_6_highlight,
263
+ product_7_background: $product_7_background,
264
+ product_7_highlight: $product_7_highlight,
265
+ product_8_background: $product_8_background,
266
+ product_8_highlight: $product_8_highlight,
267
+ product_9_background: $product_9_background,
268
+ product_9_highlight: $product_9_highlight,
269
+ product_10_background: $product_10_background,
270
+ product_10_highlight: $product_10_highlight
271
+ ) !default;
232
272
 
233
273
  /* Category colors ---------------------*/
234
274
  $category_1: $royal !default;
@@ -1,3 +1,5 @@
1
+ // Color Helper Utilities
2
+
1
3
  @function shade($color, $percentage) {
2
4
  @return mix($charcoal, $color, $percentage);
3
5
  }
@@ -14,9 +16,12 @@
14
16
  @return $text_color;
15
17
  }
16
18
 
19
+
20
+ // Generate Color Helper Classes
21
+
17
22
  @mixin background-color($colors-list) {
18
23
  @each $name, $color in $colors-list {
19
- .#{$name} {
24
+ .pb_web_#{$name} {
20
25
  background-color: $color !important;
21
26
  }
22
27
  }
@@ -28,15 +33,4 @@
28
33
  color: $color !important;
29
34
  }
30
35
  }
31
- }
32
-
33
- .bg_gradient {
34
- background: $gradient_start;
35
- background: -moz-linear-gradient(-45deg, $gradient_start 0%, $gradient_end 100%);
36
- background: -webkit-linear-gradient(-45deg, $gradient_start 0%, $gradient_end 100%);
37
- background: linear-gradient(135deg, $gradient_start 0%, $gradient_end 100%);
38
- filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{$gradient_start}', endColorstr='#{$gradient_end}',GradientType=1 );
39
- }
40
-
41
- @include text-color($text_colors);
42
- @include background-color($background_colors);
36
+ }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playbook
4
- PREVIOUS_VERSION = "12.11.0"
5
- VERSION = "12.12.0"
4
+ PREVIOUS_VERSION = "12.13.0"
5
+ VERSION = "12.13.0.pre.alpha.addingProductTokens439"
6
6
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playbook_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.12.0
4
+ version: 12.13.0.pre.alpha.addingProductTokens439
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
8
8
  - Power Devs
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-30 00:00:00.000000000 Z
12
+ date: 2023-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -1843,9 +1843,9 @@ files:
1843
1843
  - app/pb_kits/playbook/pb_selectable_icon/selectable_icon.html.erb
1844
1844
  - app/pb_kits/playbook/pb_selectable_icon/selectable_icon.rb
1845
1845
  - app/pb_kits/playbook/pb_selectable_icon/selectable_icon.test.js
1846
- - app/pb_kits/playbook/pb_selectable_list/_item.jsx
1847
- - app/pb_kits/playbook/pb_selectable_list/_selectable_list.jsx
1846
+ - app/pb_kits/playbook/pb_selectable_list/_item.tsx
1848
1847
  - app/pb_kits/playbook/pb_selectable_list/_selectable_list.scss
1848
+ - app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx
1849
1849
  - app/pb_kits/playbook/pb_selectable_list/docs/_selectable_list_checkbox.html.erb
1850
1850
  - app/pb_kits/playbook/pb_selectable_list/docs/_selectable_list_checkbox.jsx
1851
1851
  - app/pb_kits/playbook/pb_selectable_list/docs/_selectable_list_radio.html.erb
@@ -1854,6 +1854,7 @@ files:
1854
1854
  - app/pb_kits/playbook/pb_selectable_list/docs/index.js
1855
1855
  - app/pb_kits/playbook/pb_selectable_list/selectable_list.html.erb
1856
1856
  - app/pb_kits/playbook/pb_selectable_list/selectable_list.rb
1857
+ - app/pb_kits/playbook/pb_selectable_list/selectable_list.test.js
1857
1858
  - app/pb_kits/playbook/pb_selectable_list/selectable_list_item.html.erb
1858
1859
  - app/pb_kits/playbook/pb_selectable_list/selectable_list_item.rb
1859
1860
  - app/pb_kits/playbook/pb_source/_source.scss
@@ -2461,7 +2462,7 @@ homepage: http://playbook.powerapp.cloud
2461
2462
  licenses:
2462
2463
  - ISC
2463
2464
  metadata: {}
2464
- post_install_message:
2465
+ post_install_message:
2465
2466
  rdoc_options: []
2466
2467
  require_paths:
2467
2468
  - lib
@@ -2472,12 +2473,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
2472
2473
  version: '0'
2473
2474
  required_rubygems_version: !ruby/object:Gem::Requirement
2474
2475
  requirements:
2475
- - - ">="
2476
+ - - ">"
2476
2477
  - !ruby/object:Gem::Version
2477
- version: '0'
2478
+ version: 1.3.1
2478
2479
  requirements: []
2479
2480
  rubygems_version: 3.3.7
2480
- signing_key:
2481
+ signing_key:
2481
2482
  specification_version: 4
2482
2483
  summary: Playbook Design System
2483
2484
  test_files: []
@@ -1,106 +0,0 @@
1
- /* @flow */
2
-
3
- import React, { Node, useState } from 'react'
4
- import classnames from 'classnames'
5
-
6
- import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
7
- import { globalProps } from '../utilities/globalProps'
8
-
9
- import Checkbox from '../pb_checkbox/_checkbox'
10
- import ListItem from '../pb_list/_list_item'
11
- import Radio from '../pb_radio/_radio'
12
-
13
- type SelectableListItemProps = {
14
- aria?: object,
15
- children: array<Node> | Node,
16
- checked?: boolean,
17
- className?: string,
18
- data?: object,
19
- defaultChecked?: boolean,
20
- id?: string,
21
- label?: string,
22
- text?: string,
23
- name?: string,
24
- value?: string,
25
- variant?: string,
26
- onChange: (boolean)=>void,
27
- }
28
-
29
- const SelectableListItem = ({
30
- aria = {},
31
- checked = false,
32
- children,
33
- className,
34
- data = {},
35
- defaultChecked,
36
- id,
37
- label,
38
- text = '',
39
- name = '',
40
- value = '',
41
- variant = 'checkbox',
42
- onChange = () => {},
43
- ...props
44
- }: SelectableListItemProps) => {
45
- const ariaProps = buildAriaProps(aria)
46
- const dataProps = buildDataProps(data)
47
- const classes = classnames(
48
- buildCss('pb_selectable_list_item_kit'),
49
- globalProps(props),
50
- className
51
- )
52
-
53
- const initialCheckedState = checked
54
- const [checkedState, setCheckedState] = useState(initialCheckedState)
55
-
56
- const handleChecked = (event) => {
57
- onChange(event)
58
- setCheckedState(event.target.checked)
59
- }
60
-
61
- return (
62
- <ListItem
63
- {...props}
64
- className={classnames(checkedState ? "checked_item" : "", className)}
65
- >
66
- <div
67
- {...ariaProps}
68
- {...dataProps}
69
- className={classes}
70
- >
71
- <Choose>
72
- <When condition={variant == 'checkbox'}>
73
- <Checkbox
74
- checked={checkedState}
75
- id={id}
76
- name={name}
77
- onChange={handleChecked}
78
- // eslint suppressor, text is needed to display on screen
79
- text={label || (text && false)}
80
- type="checkbox"
81
- value={value}
82
- {...props}
83
- />
84
- {children}
85
- </When>
86
- <When condition={variant == 'radio'}>
87
- <Radio
88
- defaultChecked={defaultChecked}
89
- id={id}
90
- label={label}
91
- name={name}
92
- onChange={onChange}
93
- type="radio"
94
- value={value}
95
- {...props}
96
- />
97
- {children}
98
- </When>
99
- <Otherwise>{children}</Otherwise>
100
- </Choose>
101
- </div>
102
- </ListItem>
103
- )
104
- }
105
-
106
- export default SelectableListItem