playbook_ui 13.29.0.pre.alpha.testingcollapsibleissue3052 → 13.30.0.pre.alpha.PBNTR353draggablev53136

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +1 -0
  3. data/app/pb_kits/playbook/index.js +1 -0
  4. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.html.erb +58 -0
  5. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.jsx +68 -0
  6. data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +2 -0
  7. data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +1 -0
  8. data/app/pb_kits/playbook/pb_card/_card.scss +5 -0
  9. data/app/pb_kits/playbook/pb_card/_card.tsx +57 -9
  10. data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +9 -5
  11. data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +2 -3
  12. data/app/pb_kits/playbook/pb_draggable/_draggable.scss +2 -4
  13. data/app/pb_kits/playbook/pb_draggable/context/index.tsx +70 -50
  14. data/app/pb_kits/playbook/pb_draggable/context/types.ts +26 -0
  15. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.jsx +3 -2
  16. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +2 -2
  17. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +13 -8
  18. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.md +1 -0
  19. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +23 -35
  20. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +5 -0
  21. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +7 -7
  22. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.md +7 -1
  23. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.jsx +11 -9
  24. data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.md +7 -0
  25. data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +143 -18
  26. data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +6 -5
  27. data/app/pb_kits/playbook/pb_list/_list.tsx +4 -4
  28. data/app/pb_kits/playbook/pb_list/_list_item.tsx +7 -3
  29. data/app/pb_kits/playbook/pb_overlay/_overlay.scss +72 -0
  30. data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +78 -0
  31. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.html.erb +24 -0
  32. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.jsx +40 -0
  33. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.md +7 -0
  34. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +11 -0
  35. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.jsx +36 -0
  36. data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.md +5 -0
  37. data/app/pb_kits/playbook/pb_overlay/docs/example.yml +8 -0
  38. data/app/pb_kits/playbook/pb_overlay/docs/index.js +2 -0
  39. data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +27 -0
  40. data/app/pb_kits/playbook/pb_overlay/overlay.rb +110 -0
  41. data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +66 -0
  42. data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_percentage.tsx +57 -0
  43. data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_token.tsx +48 -0
  44. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.scss +43 -25
  45. data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +7 -3
  46. data/app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx +3 -3
  47. data/app/pb_kits/playbook/pb_table/docs/_table_alignment_column_rails.html.erb +32 -33
  48. data/app/pb_kits/playbook/pb_table/table_header.html.erb +0 -2
  49. data/app/pb_kits/playbook/pb_timeline/_item.tsx +11 -10
  50. data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +8 -6
  51. data/app/pb_kits/playbook/playbook-doc.js +2 -0
  52. data/app/pb_kits/playbook/utilities/globalProps.ts +1 -0
  53. data/dist/menu.yml +5 -1
  54. data/dist/playbook-rails.js +6 -6
  55. data/lib/playbook/kit_base.rb +19 -0
  56. data/lib/playbook/version.rb +2 -2
  57. metadata +23 -2
@@ -13,15 +13,15 @@ import {
13
13
  // Initial items to be dragged
14
14
  const data = [
15
15
  {
16
- id: "1",
16
+ id: "21",
17
17
  text: "Joe Black",
18
18
  },
19
19
  {
20
- id: "2",
20
+ id: "22",
21
21
  text: "Nancy White",
22
22
  },
23
23
  {
24
- id: "3",
24
+ id: "23",
25
25
  text: "Bill Green",
26
26
  },
27
27
  ];
@@ -32,58 +32,44 @@ const DraggableWithCards = (props) => {
32
32
  return (
33
33
  <DraggableProvider
34
34
  initialItems={data}
35
- onChange={(items) => setInitialState(items)}
35
+ onReorder={(items) => setInitialState(items)}
36
36
  >
37
37
  <Draggable.Container {...props}>
38
38
  {initialState.map(({ id, text }) => (
39
- <Draggable.Item id={id}
40
- key={id}
41
- >
42
- <Card
43
- highlight={{ position: "side", color: "primary" }}
39
+ <Card dragId={id}
40
+ draggableItem
41
+ highlight={{ color: "primary", position: "side" }}
42
+ key={id}
44
43
  marginBottom="xs"
44
+ padding="xs"
45
+ {...props}
45
46
  >
46
47
  <Flex alignItems="stretch"
47
48
  flexDirection="column"
48
- >
49
+ >
49
50
  <Flex gap="xs">
50
51
  <Title size={4}
51
- text={text}
52
- />
52
+ text={text}
53
+ {...props}
54
+ />
53
55
  <Badge
54
56
  text="35-12345"
55
57
  variant="primary"
56
- />
58
+ {...props}
59
+ />
57
60
  </Flex>
58
-
59
- <Flex
60
- gap="sm"
61
- spacing="between"
62
- >
63
- <Caption
64
- size="xs"
65
- text="8:00A"
66
- />
67
- <Flex gap="xxs">
68
61
  <Caption
69
62
  size="xs"
70
- text="Township Name"
71
- />
72
- <Caption size="xs"
73
- text="•"
63
+ text="8:00A • Township Name • 90210"
64
+ {...props}
74
65
  />
75
- <Caption size="xs"
76
- text="90210"
77
- />
78
- </Flex>
79
- </Flex>
80
-
81
66
  <Flex gap="xxs"
82
67
  spacing="between"
83
68
  >
84
69
  <Flex gap="xxs">
85
70
  <Caption color="error"
86
71
  size="xs"
72
+ {...props}
87
73
  >
88
74
  <Icon icon="house-circle-exclamation" />
89
75
  </Caption>
@@ -96,20 +82,22 @@ const DraggableWithCards = (props) => {
96
82
  <Badge rounded
97
83
  text="Schedule QA"
98
84
  variant="warning"
85
+ {...props}
99
86
  />
100
87
  <Badge rounded
101
88
  text="Flex"
102
- variant="primary"
89
+ variant="primary"
90
+ {...props}
103
91
  />
104
92
  <Badge rounded
105
93
  text="R99"
106
94
  variant="primary"
95
+ {...props}
107
96
  />
108
97
  </Flex>
109
98
  </Flex>
110
99
  </Flex>
111
100
  </Card>
112
- </Draggable.Item>
113
101
  ))}
114
102
  </Draggable.Container>
115
103
  </DraggableProvider>
@@ -0,0 +1,5 @@
1
+ For a simplified version of the Draggable API for the Card kit, You can use the Card kit as the Draggable Item by using the `draggableItem` prop. The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the Card kit.
2
+
3
+ In addition to the above, `dragId` is a REQUIRED prop to be passed to the Card kit when implementing dragging.
4
+
5
+ The dev must manage state as shown.
@@ -4,19 +4,19 @@ import { DraggableProvider, List, ListItem } from "../../";
4
4
  // Initial items to be dragged
5
5
  const data = [
6
6
  {
7
- id: "1",
7
+ id: "31",
8
8
  text: "Philadelphia",
9
9
  },
10
10
  {
11
- id: "2",
11
+ id: "32",
12
12
  text: "New Jersey",
13
13
  },
14
14
  {
15
- id: "3",
15
+ id: "33",
16
16
  text: "Maryland",
17
17
  },
18
18
  {
19
- id: "4",
19
+ id: "34",
20
20
  text: "Connecticut",
21
21
  },
22
22
  ];
@@ -28,13 +28,13 @@ const DraggableWithList = (props) => {
28
28
  return (
29
29
  <>
30
30
  <DraggableProvider initialItems={data}
31
- onChange={(items) => setInitialState(items)}
31
+ onReorder={(items) => setInitialState(items)}
32
32
  >
33
- <List draggable
33
+ <List enableDrag
34
34
  {...props}
35
35
  >
36
36
  {initialState.map(({ id, text }) => (
37
- <ListItem id={id}
37
+ <ListItem dragId={id}
38
38
  key={id}
39
39
  >
40
40
  {text}
@@ -1 +1,7 @@
1
- For a simplified version of the Draggable API fro the List kit, use the DraggableProvider to wrap the List use the `draggable` prop on List. The dev must manage state as shown and pass in id to the ListItem.
1
+ For a simplified version of the Draggable API for the List kit, use the DraggableProvider to wrap the List kit and use the `enableDrag` prop.
2
+
3
+ In addition to the above, `dragId` is a REQUIRED prop to be passed to the List kit when implementing dragging.
4
+
5
+ The dev must manage state as shown.
6
+
7
+ The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the List kit.
@@ -4,19 +4,19 @@ import { SelectableList, DraggableProvider } from "../../";
4
4
  // Initial items to be dragged
5
5
  const data = [
6
6
  {
7
- id: "1",
7
+ id: "41",
8
8
  text: "Task 1",
9
9
  },
10
10
  {
11
- id: "2",
11
+ id: "42",
12
12
  text: "Task 2",
13
13
  },
14
14
  {
15
- id: "3",
15
+ id: "43",
16
16
  text: "Task 3",
17
17
  },
18
18
  {
19
- id: "4",
19
+ id: "44",
20
20
  text: "Task 4",
21
21
  },
22
22
  ];
@@ -27,18 +27,20 @@ const DraggableWithSelectableList = (props) => {
27
27
  return (
28
28
  <>
29
29
  <DraggableProvider initialItems={data}
30
- onChange={(items) => setInitialState(items)}
30
+ onReorder={(items) => setInitialState(items)}
31
31
  >
32
- <SelectableList draggable
33
- variant="checkbox"
32
+ <SelectableList enableDrag
33
+ variant="radio"
34
34
  {...props}
35
35
  >
36
36
  {initialState.map(({ id, text }) => (
37
- <SelectableList.Item id={id}
37
+ <SelectableList.Item
38
+ dragId={id}
38
39
  key={id}
39
40
  label={text}
40
- name={id}
41
+ name="radio-test"
41
42
  value={id}
43
+ {...props}
42
44
  />
43
45
  ))}
44
46
  </SelectableList>
@@ -0,0 +1,7 @@
1
+ For a simplified version of the Draggable API for the SelectableList kit, use the DraggableProvider to wrap the SelectableList kit and use the `enableDrag` prop.
2
+
3
+ In addition to the above, `dragId` is a REQUIRED prop to be passed to the SelectableList kit when implementing dragging.
4
+
5
+ The dev must manage state as shown.
6
+
7
+ The dragHandle is added by default but this can be opted out of by setting `dragHandle` to false on the SelectableList kit.
@@ -1,9 +1,16 @@
1
- import React, {useState} from "react"
2
- import { render, screen } from "../utilities/test-utils"
1
+ import React, { useState } from "react";
2
+ import { render, screen } from "../utilities/test-utils";
3
3
 
4
- import { Draggable, DraggableProvider, SelectableList } from '../'
4
+ import {
5
+ Draggable,
6
+ DraggableProvider,
7
+ SelectableList,
8
+ List,
9
+ ListItem,
10
+ Card,
11
+ } from "../";
5
12
 
6
- const testId = 'draggable'
13
+ const testId = "draggable";
7
14
 
8
15
  const data = [
9
16
  {
@@ -24,24 +31,19 @@ const data = [
24
31
  },
25
32
  ];
26
33
 
27
-
28
34
  const DefaultDraggableKit = () => {
29
35
  const [initialState, setInitialState] = useState(data);
30
36
 
31
37
  return (
32
38
  <DraggableProvider
33
39
  initialItems={data}
34
- onChange={(items) => setInitialState(items)}
40
+ onReorder={(items) => setInitialState(items)}
35
41
  >
36
- <Draggable
37
- data={{ testid: testId }}
38
- draggableItems={data}
39
- onDragChange={(items) => setInitialItems(items)}
40
- >
42
+ <Draggable data={{ testid: testId }}>
41
43
  <Draggable.Container>
42
44
  <SelectableList variant="checkbox">
43
45
  {initialState.map(({ id, text }) => (
44
- <Draggable.Item id={id}
46
+ <Draggable.Item dragId={id}
45
47
  key={id}
46
48
  >
47
49
  <SelectableList.Item label={text}
@@ -57,9 +59,132 @@ const DefaultDraggableKit = () => {
57
59
  );
58
60
  };
59
61
 
60
- test('generated default kit and classname', () => {
61
- render(<DefaultDraggableKit/>)
62
- const kit = screen.getByTestId(testId)
63
- expect(kit).toBeInTheDocument()
64
- expect(kit).toHaveClass('pb_draggable')
65
- })
62
+ const DraggableKitWithList = () => {
63
+ const [initialState, setInitialState] = useState(data);
64
+ return (
65
+ <div data-testid="draggable">
66
+ <DraggableProvider
67
+ initialItems={data}
68
+ onReorder={(items) => setInitialState(items)}
69
+ >
70
+ <List enableDrag>
71
+ {initialState.map(({ id, text }) => (
72
+ <ListItem dragId={id}
73
+ key={id}
74
+ >
75
+ {text}
76
+ </ListItem>
77
+ ))}
78
+ </List>
79
+ </DraggableProvider>
80
+ </div>
81
+ );
82
+ };
83
+
84
+ const DraggableKitWithSelectableList = () => {
85
+ const [initialState, setInitialState] = useState(data);
86
+ return (
87
+ <div data-testid="draggable">
88
+ <DraggableProvider
89
+ initialItems={data}
90
+ onReorder={(items) => setInitialState(items)}
91
+ >
92
+ <SelectableList enableDrag>
93
+ {initialState.map(({ id, text }) => (
94
+ <SelectableList.Item
95
+ dragId={id}
96
+ key={id}
97
+ label={text}
98
+ name={id}
99
+ value={id}
100
+ />
101
+ ))}
102
+ </SelectableList>
103
+ </DraggableProvider>
104
+ </div>
105
+ );
106
+ };
107
+
108
+ const DraggableKitWithCard = () => {
109
+ const [initialState, setInitialState] = useState(data);
110
+ return (
111
+ <div data-testid="draggable">
112
+ <DraggableProvider
113
+ initialItems={data}
114
+ onReorder={(items) => setInitialState(items)}
115
+ >
116
+ <Draggable.Container>
117
+ {initialState.map(({ id, text }) => (
118
+ <Card dragId={id}
119
+ draggableItem
120
+ key={id}
121
+ >
122
+ {text}
123
+ </Card>
124
+ ))}
125
+ </Draggable.Container>
126
+ </DraggableProvider>
127
+ </div>
128
+ );
129
+ };
130
+
131
+ test("generated default kit and classname", () => {
132
+ render(<DefaultDraggableKit />);
133
+ const kit = screen.getByTestId(testId);
134
+ expect(kit).toBeInTheDocument();
135
+ expect(kit).toHaveClass("pb_draggable");
136
+ });
137
+
138
+ test("generated Draggable Container", () => {
139
+ render(<DefaultDraggableKit />);
140
+ const kit = screen.getByTestId(testId);
141
+
142
+ const container = kit.querySelector(".pb_draggable_container");
143
+ expect(container).toBeInTheDocument();
144
+ });
145
+
146
+ test("generated Draggable Item", () => {
147
+ render(<DefaultDraggableKit />);
148
+ const kit = screen.getByTestId(testId);
149
+
150
+ const item = kit.querySelector(".pb_draggable_item");
151
+ expect(item).toBeInTheDocument();
152
+ });
153
+
154
+ test("Attached draggable HTML attributes", () => {
155
+ render(<DefaultDraggableKit />);
156
+ const kit = screen.getByTestId(testId);
157
+
158
+ const item = kit.querySelector(".pb_draggable_item");
159
+ expect(item).toHaveAttribute("draggable");
160
+ });
161
+
162
+ test("generated dragHandle with List", () => {
163
+ render(<DraggableKitWithList />);
164
+ const kit = screen.getByTestId(testId);
165
+
166
+ const list = kit.querySelector(".pb_list_kit");
167
+ expect(list).toBeInTheDocument();
168
+ const dragHandle = list.querySelector(".fa-grip-dots-vertical");
169
+ expect(dragHandle).toBeInTheDocument();
170
+ });
171
+
172
+ test("generated dragHandle with SelectableList", () => {
173
+ render(<DraggableKitWithSelectableList />);
174
+ const kit = screen.getByTestId(testId);
175
+
176
+ const selectabellist = kit.querySelector(".pb_selectable_list_kit");
177
+ expect(selectabellist).toBeInTheDocument();
178
+ const dragHandle = selectabellist.querySelector(".fa-grip-dots-vertical");
179
+ expect(dragHandle).toBeInTheDocument();
180
+ });
181
+
182
+ test("generated dragHandle with Card", () => {
183
+ render(<DraggableKitWithCard />);
184
+ const kit = screen.getByTestId(testId);
185
+
186
+ const card = kit.querySelector(".pb_card_kit_deselected_border_radius_md");
187
+ expect(card).toBeInTheDocument();
188
+ const dragHandle = card.querySelector(".fa-grip-dots-vertical");
189
+ expect(dragHandle).toBeInTheDocument();
190
+ });
@@ -17,10 +17,11 @@ type DraggableItemProps = {
17
17
  data?: { [key: string]: string };
18
18
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
19
19
  id?: string;
20
+ dragId?: string;
20
21
  };
21
22
 
22
23
  const DraggableItem = (props: DraggableItemProps) => {
23
- const { aria = {}, children, className, container, data = {}, htmlOptions = {}, id } = props;
24
+ const { aria = {}, children, className, container, data = {}, htmlOptions = {}, id, dragId } = props;
24
25
 
25
26
  const { isDragging, handleDragStart, handleDragEnter, handleDragEnd } =
26
27
  DraggableContext();
@@ -31,7 +32,7 @@ const DraggableItem = (props: DraggableItemProps) => {
31
32
 
32
33
  const classes = classnames(
33
34
  buildCss("pb_draggable_item"),
34
- `${isDragging === id ? "is_dragging" : ""}`,
35
+ `${isDragging === dragId ? "is_dragging" : ""}`,
35
36
  globalProps(props),
36
37
  className
37
38
  );
@@ -44,10 +45,10 @@ const DraggableItem = (props: DraggableItemProps) => {
44
45
  className={classes}
45
46
  draggable
46
47
  id={id}
47
- key={id}
48
+ key={dragId}
48
49
  onDragEnd={() => handleDragEnd()}
49
- onDragEnter={() => handleDragEnter(id, container)}
50
- onDragStart={() => handleDragStart(id, container)}
50
+ onDragEnter={() => handleDragEnter(dragId, container)}
51
+ onDragStart={() => handleDragStart(dragId, container)}
51
52
  >
52
53
  {children}
53
54
  </div>
@@ -10,7 +10,7 @@ type ListProps = {
10
10
  className?: string;
11
11
  children: React.ReactNode[] | React.ReactNode;
12
12
  dark?: boolean;
13
- draggable?: boolean;
13
+ enableDrag?: boolean;
14
14
  data?: Record<string, unknown>;
15
15
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
16
16
  id?: string;
@@ -32,7 +32,7 @@ const List = (props: ListProps) => {
32
32
  className,
33
33
  dark = false,
34
34
  data = {},
35
- draggable = false,
35
+ enableDrag = false,
36
36
  htmlOptions = {},
37
37
  id,
38
38
  layout = "",
@@ -54,7 +54,7 @@ const List = (props: ListProps) => {
54
54
  const childrenWithProps = React.Children.map(
55
55
  children,
56
56
  (child: React.ReactElement) => {
57
- return React.cloneElement(child, { text, variant, draggable });
57
+ return React.cloneElement(child, { text, variant, enableDrag });
58
58
  }
59
59
  );
60
60
  const ariaProps = buildAriaProps(aria);
@@ -74,7 +74,7 @@ const List = (props: ListProps) => {
74
74
  return (
75
75
  <>
76
76
  {
77
- draggable ? (
77
+ enableDrag ? (
78
78
  <Draggable.Container>
79
79
  <div className={classes}>
80
80
  {ordered ? (
@@ -11,6 +11,7 @@ type ListItemProps = {
11
11
  children: React.ReactNode[] | React.ReactNode,
12
12
  className?: string,
13
13
  data?: Record<string, unknown>,
14
+ dragId?: string,
14
15
  dragHandle?: boolean,
15
16
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
16
17
  id?: string,
@@ -23,7 +24,8 @@ const ListItem = (props: ListItemProps) => {
23
24
  children,
24
25
  className,
25
26
  data = {},
26
- draggable = false,
27
+ enableDrag,
28
+ dragId,
27
29
  dragHandle = true,
28
30
  htmlOptions = {},
29
31
  id,
@@ -42,8 +44,10 @@ const ListItem = (props: ListItemProps) => {
42
44
  return (
43
45
  <>
44
46
  {
45
- draggable ? (
46
- <Draggable.Item id={id}>
47
+ enableDrag ? (
48
+ <Draggable.Item
49
+ dragId={dragId}
50
+ >
47
51
  <li
48
52
  {...ariaProps}
49
53
  {...dataProps}
@@ -0,0 +1,72 @@
1
+ @import "../tokens/colors";
2
+ @import "../tokens/spacing";
3
+
4
+ $overlay_sizes: (
5
+ full: 100%,
6
+ xxs: $space_xxs,
7
+ xs: $space_xs,
8
+ sm: $space_sm,
9
+ md: $space_md,
10
+ lg: $space_lg,
11
+ xl: $space_xl,
12
+ );
13
+
14
+ $overlay_positions: left, right, top, bottom, x, y;
15
+
16
+ $overlay_colors: (
17
+ card_light: $card_light,
18
+ card_dark: $card_dark,
19
+ bg_dark: $bg_dark,
20
+ bg_light: $bg_light,
21
+ );
22
+
23
+ @mixin overlay($direction, $size, $color) {
24
+ display: block;
25
+ position: absolute;
26
+ pointer-events: none;
27
+ z-index: 1;
28
+ content: "";
29
+
30
+ @if $direction == "left" {
31
+ inset: 0 auto 0 0;
32
+ background: linear-gradient(to right, $color 0%, transparent 100%);
33
+ width: $size;
34
+ }
35
+ @if $direction == "right" {
36
+ inset: 0 0 0 auto;
37
+ background: linear-gradient(to left, $color 0%, transparent 100%);
38
+ width: $size;
39
+ }
40
+ @if $direction == "top" {
41
+ inset: 0 0 auto 0;
42
+ background: linear-gradient(to bottom, $color 0%, transparent 100%);
43
+ height: $size;
44
+ }
45
+ @if $direction == "bottom" {
46
+ inset: auto 0 0 0;
47
+ background: linear-gradient(to top, $color 0%, transparent 100%);
48
+ height: $size;
49
+ }
50
+ }
51
+
52
+ [class^=pb_overlay] {
53
+ position: relative;
54
+ @each $color_name, $color in $overlay_colors {
55
+ .overlay_#{$color_name} {
56
+ @each $name, $size in $overlay_sizes {
57
+ @each $position in $overlay_positions {
58
+ &_#{$position}_#{$name} {
59
+ @include overlay($position, $size, $color);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ .overlay_linear_gradient {
67
+ inset: 0;
68
+ position: absolute;
69
+ pointer-events: none;
70
+ z-index: 1;
71
+ }
72
+ }
@@ -0,0 +1,78 @@
1
+ import React from 'react'
2
+ import classnames from 'classnames'
3
+ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
4
+ import { globalProps } from '../utilities/globalProps'
5
+ import OverlayPercentage from './subcomponents/_overlay_percentage'
6
+ import OverlayToken from './subcomponents/_overlay_token'
7
+
8
+ export type OverlayChildrenProps = {
9
+ children: React.ReactNode[] | React.ReactNode,
10
+ color: "card_light" | "bg_light" | "card_dark" | "bg_dark",
11
+ position: string,
12
+ size: string,
13
+ }
14
+
15
+ type OverlayProps = {
16
+ aria?: { [key: string]: string },
17
+ className?: string,
18
+ children: React.ReactNode[] | React.ReactNode,
19
+ color: "card_light" | "bg_light" | "card_dark" | "bg_dark",
20
+ data?: { [key: string]: string },
21
+ htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
22
+ id?: string,
23
+ layout: { [key: string]: string },
24
+ }
25
+
26
+ const Overlay = (props: OverlayProps) => {
27
+ const {
28
+ aria = {},
29
+ className,
30
+ children,
31
+ color = "card_light",
32
+ data = {},
33
+ htmlOptions = {},
34
+ id,
35
+ layout = { "bottom": "full" },
36
+ } = props
37
+
38
+ const ariaProps = buildAriaProps(aria)
39
+ const dataProps = buildDataProps(data)
40
+ const classes = classnames(buildCss('pb_overlay'), globalProps(props), className)
41
+ const htmlProps = buildHtmlProps(htmlOptions)
42
+
43
+ const getPosition = () => {
44
+ return Object.keys(layout)[0]
45
+ }
46
+
47
+ const getSize = () => {
48
+ return Object.values(layout)[0]
49
+ }
50
+
51
+ const isSizePercentage = getSize().includes("%")
52
+
53
+ return (
54
+ <div
55
+ {...ariaProps}
56
+ {...dataProps}
57
+ {...htmlProps}
58
+ className={classes}
59
+ id={id}
60
+ >
61
+ {isSizePercentage ?
62
+ OverlayPercentage({
63
+ children,
64
+ color,
65
+ position: getPosition(),
66
+ size: getSize()
67
+ }) : OverlayToken({
68
+ children,
69
+ color,
70
+ position: getPosition(),
71
+ size: getSize()
72
+ })
73
+ }
74
+ </div>
75
+ )
76
+ }
77
+
78
+ export default Overlay