playbook_ui 13.29.0 → 13.30.0.pre.alpha.PBNTR353draggablev53136
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/_playbook.scss +1 -0
- data/app/pb_kits/playbook/index.js +1 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.html.erb +58 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_horizontal.jsx +68 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_card/_card.scss +5 -0
- data/app/pb_kits/playbook/pb_card/_card.tsx +57 -9
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +9 -5
- data/app/pb_kits/playbook/pb_collapsible/_collapsible.tsx +2 -6
- data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +2 -3
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +2 -4
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +70 -50
- data/app/pb_kits/playbook/pb_draggable/context/types.ts +26 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.jsx +3 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_default.md +2 -2
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.jsx +13 -8
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_multiple_containers.md +1 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.jsx +23 -35
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_cards.md +5 -0
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.jsx +7 -7
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_list.md +7 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.jsx +11 -9
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_selectable_list.md +7 -0
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +143 -18
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableItem.tsx +6 -5
- data/app/pb_kits/playbook/pb_list/_list.tsx +4 -4
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +7 -3
- data/app/pb_kits/playbook/pb_overlay/_overlay.scss +72 -0
- data/app/pb_kits/playbook/pb_overlay/_overlay.tsx +78 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.html.erb +24 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.jsx +40 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_default.md +7 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.html.erb +11 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.jsx +36 -0
- data/app/pb_kits/playbook/pb_overlay/docs/_overlay_multi_directional.md +5 -0
- data/app/pb_kits/playbook/pb_overlay/docs/example.yml +8 -0
- data/app/pb_kits/playbook/pb_overlay/docs/index.js +2 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.html.erb +27 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.rb +110 -0
- data/app/pb_kits/playbook/pb_overlay/overlay.test.jsx +66 -0
- data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_percentage.tsx +57 -0
- data/app/pb_kits/playbook/pb_overlay/subcomponents/_overlay_token.tsx +48 -0
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.scss +43 -25
- data/app/pb_kits/playbook/pb_selectable_list/_item.tsx +7 -3
- data/app/pb_kits/playbook/pb_selectable_list/_selectable_list.tsx +3 -3
- data/app/pb_kits/playbook/pb_table/docs/_table_alignment_column_rails.html.erb +32 -33
- data/app/pb_kits/playbook/pb_table/table_header.html.erb +0 -2
- data/app/pb_kits/playbook/pb_timeline/_item.tsx +11 -10
- data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +8 -6
- data/app/pb_kits/playbook/playbook-doc.js +2 -0
- data/app/pb_kits/playbook/utilities/globalProps.ts +1 -0
- data/dist/menu.yml +5 -1
- data/dist/playbook-rails.js +6 -6
- data/lib/playbook/kit_base.rb +19 -0
- data/lib/playbook/version.rb +2 -2
- metadata +26 -5
@@ -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
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%= pb_rails("overlay") do %>
|
2
|
+
<%= pb_rails("table", props: { size: "sm" }) do %>
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<th>Column 1</th>
|
6
|
+
<th>Column 2</th>
|
7
|
+
<th>Column 3</th>
|
8
|
+
<th>Column 4</th>
|
9
|
+
<th>Column 5</th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
<tbody>
|
13
|
+
<% 7.times do %>
|
14
|
+
<tr>
|
15
|
+
<td>Value 1</td>
|
16
|
+
<td>Value 2</td>
|
17
|
+
<td>Value 3</td>
|
18
|
+
<td>Value 4</td>
|
19
|
+
<td>Value 5</td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
<% end %>
|
24
|
+
<% end %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import {
|
3
|
+
Overlay,
|
4
|
+
Table,
|
5
|
+
} from '../..'
|
6
|
+
|
7
|
+
const TableExample = () => {
|
8
|
+
return (
|
9
|
+
<Table size="sm">
|
10
|
+
<thead>
|
11
|
+
<tr>
|
12
|
+
<th>{'Column 1'}</th>
|
13
|
+
<th>{'Column 2'}</th>
|
14
|
+
<th>{'Column 3'}</th>
|
15
|
+
<th>{'Column 4'}</th>
|
16
|
+
<th>{'Column 5'}</th>
|
17
|
+
</tr>
|
18
|
+
</thead>
|
19
|
+
<tbody>
|
20
|
+
{Array.from({ length: 7 }, (_, index) => (
|
21
|
+
<tr key={index}>
|
22
|
+
{Array.from({ length: 5 }, (_, columnIndex) => (
|
23
|
+
<td key={columnIndex}>{`Value ${columnIndex + 1}`}</td>
|
24
|
+
))}
|
25
|
+
</tr>
|
26
|
+
))}
|
27
|
+
</tbody>
|
28
|
+
</Table>
|
29
|
+
)
|
30
|
+
}
|
31
|
+
|
32
|
+
const OverlayDefault = () => (
|
33
|
+
<>
|
34
|
+
<Overlay>
|
35
|
+
<TableExample />
|
36
|
+
</Overlay>
|
37
|
+
</>
|
38
|
+
)
|
39
|
+
|
40
|
+
export default OverlayDefault
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Overlays optionally accept a `color`, which sets the "start" (opaque) color of a gradient mask. Because this overlay is intended to reveal underlying content, the "end" color is fixed to transparent.
|
2
|
+
|
3
|
+
The optional `layout` prop accepts the `position` and `size` of the overlay as a key:value pair.
|
4
|
+
|
5
|
+
The `position` key accepts `bottom` (default), `top`, `y` (for both top and bottom) `right`, `left`, or `x` (for both left and right), which sets the side(s) where the `color` overlay starts. The direction of the overlay is always toward the opposite side of the position. For example, the default position of `bottom` starts the overlay on the bottom edge of your container and extends it toward the opposite side: the top.
|
6
|
+
|
7
|
+
The `size` value is `full` (100%) by default, but accepts our [spacing tokens](https://playbook.powerapp.cloud/visual_guidelines/spacing) or a percentage value as a string, and literally translates to how much of the container is covered by the overlay(s).
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= pb_rails("overlay", props: { layout: { "x": "xl" }, color: "card_light" }) do %>
|
2
|
+
<%= pb_rails("flex", props: { column_gap: "lg", orientation: "row", overflow_x: "auto" }) do %>
|
3
|
+
<% 15.times do %>
|
4
|
+
<%= pb_rails("flex/flex_item") do %>
|
5
|
+
<%= pb_rails("card") do %>
|
6
|
+
Card content
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import {
|
3
|
+
Overlay,
|
4
|
+
Card,
|
5
|
+
Flex,
|
6
|
+
FlexItem,
|
7
|
+
} from '../..'
|
8
|
+
|
9
|
+
const InlineCardsExample = () => {
|
10
|
+
return (
|
11
|
+
<Flex
|
12
|
+
columnGap="lg"
|
13
|
+
orientation="row"
|
14
|
+
overflowX="auto"
|
15
|
+
>
|
16
|
+
{Array.from({ length: 15 }, (_, index) => (
|
17
|
+
<FlexItem key={index}>
|
18
|
+
<Card>{"Card Content"}</Card>
|
19
|
+
</FlexItem>
|
20
|
+
))}
|
21
|
+
</Flex>
|
22
|
+
)
|
23
|
+
}
|
24
|
+
|
25
|
+
const OverlayMultiDirectional = () => (
|
26
|
+
<>
|
27
|
+
<Overlay
|
28
|
+
color="card_light"
|
29
|
+
layout={{"x": "xl"}}
|
30
|
+
>
|
31
|
+
<InlineCardsExample />
|
32
|
+
</Overlay>
|
33
|
+
</>
|
34
|
+
)
|
35
|
+
|
36
|
+
export default OverlayMultiDirectional
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Optionally, you can pass multi-directional options (`x` or `y`) to the `position` key, which creates multiple overlays.
|
2
|
+
|
3
|
+
Your `color` is still applied as the starting edge to both overlays, and each mask will fade to transparent moving toward its opposite edge, ending at the `size` value you set.
|
4
|
+
|
5
|
+
NOTE: Multi-directional overlays share the available container space, so passing `full` or a percentage string greater than 50% to a multi-directional overlay will cause your masks to overlap at the midline of your container. As a best practice, we do not recommend exceeding a percentage size of 25% when using multi-directional overlays.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%= pb_content_tag(:div,
|
2
|
+
aria: object.aria,
|
3
|
+
class: object.classname,
|
4
|
+
data: object.data,
|
5
|
+
id: object.id,
|
6
|
+
**combined_html_options) do %>
|
7
|
+
<% if is_size_percentage %>
|
8
|
+
<div class="overlay_linear_gradient"
|
9
|
+
style="background: <%= previous_overlay %>"></div>
|
10
|
+
|
11
|
+
<%= content.presence %>
|
12
|
+
|
13
|
+
<% if has_subsequent_overlay %>
|
14
|
+
<div class="overlay_linear_gradient"
|
15
|
+
style="background: <%= subsequent_overlay %>"></div>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<% else %>
|
19
|
+
<div class="<%= previous_overlay_class_name %>"></div>
|
20
|
+
|
21
|
+
<%= content.presence %>
|
22
|
+
|
23
|
+
<% if has_subsequent_overlay %>
|
24
|
+
<div class="<%= subsequent_overlay_class_name %>"></div>
|
25
|
+
<% end %>
|
26
|
+
<% end %>
|
27
|
+
<% end %>
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Playbook
|
4
|
+
module PbOverlay
|
5
|
+
class Overlay < Playbook::KitBase
|
6
|
+
prop :color, type: Playbook::Props::Enum,
|
7
|
+
values: %w[card_light bg_light card_dark bg_dark],
|
8
|
+
default: "card_light"
|
9
|
+
prop :layout, type: Playbook::Props::HashProp,
|
10
|
+
default: { "bottom": "full" }
|
11
|
+
|
12
|
+
def classname
|
13
|
+
generate_classname("pb_overlay")
|
14
|
+
end
|
15
|
+
|
16
|
+
def position
|
17
|
+
layout.keys[0]
|
18
|
+
end
|
19
|
+
|
20
|
+
def size
|
21
|
+
layout.values[0]
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_size_percentage
|
25
|
+
size.include?("%")
|
26
|
+
end
|
27
|
+
|
28
|
+
def previous_overlay
|
29
|
+
"linear-gradient(#{previous_overlay_direction}, #{color_map[color.to_sym]} 0%, transparent #{size})"
|
30
|
+
end
|
31
|
+
|
32
|
+
def subsequent_overlay
|
33
|
+
"linear-gradient(#{subsequent_overlay_direction}, #{color_map[color.to_sym]} 0%, transparent #{size})"
|
34
|
+
end
|
35
|
+
|
36
|
+
def previous_overlay_class_name
|
37
|
+
"overlay_#{color}_#{previous_overlay_direction_token}_#{size}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def subsequent_overlay_class_name
|
41
|
+
"overlay_#{color}_#{subsequent_overlay_direction_token}_#{size}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def previous_overlay_direction
|
45
|
+
previous_overlay_direction_map[position.to_sym]
|
46
|
+
end
|
47
|
+
|
48
|
+
def subsequent_overlay_direction
|
49
|
+
subsequent_overlay_direction_map[position.to_sym]
|
50
|
+
end
|
51
|
+
|
52
|
+
def previous_overlay_direction_token
|
53
|
+
has_subsequent_overlay ? previous_overlay_direction_map_token[position.to_sym] : position
|
54
|
+
end
|
55
|
+
|
56
|
+
def subsequent_overlay_direction_token
|
57
|
+
has_subsequent_overlay ? subsequent_overlay_direction_map_token[position.to_sym] : position
|
58
|
+
end
|
59
|
+
|
60
|
+
def previous_overlay_direction_map
|
61
|
+
{
|
62
|
+
"bottom": "to top",
|
63
|
+
"top": "to bottom",
|
64
|
+
"left": "to right",
|
65
|
+
"right": "to left",
|
66
|
+
"x": "to right",
|
67
|
+
"y": "to top",
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def subsequent_overlay_direction_map
|
72
|
+
{
|
73
|
+
"bottom": "to top",
|
74
|
+
"top": "to bottom",
|
75
|
+
"left": "to right",
|
76
|
+
"right": "to left",
|
77
|
+
"x": "to left",
|
78
|
+
"y": "to bottom",
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def previous_overlay_direction_map_token
|
83
|
+
{
|
84
|
+
"x": "left",
|
85
|
+
"y": "top",
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def subsequent_overlay_direction_map_token
|
90
|
+
{
|
91
|
+
"x": "right",
|
92
|
+
"y": "bottom",
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def has_subsequent_overlay
|
97
|
+
position == "x".to_sym || position == "y".to_sym
|
98
|
+
end
|
99
|
+
|
100
|
+
def color_map
|
101
|
+
{
|
102
|
+
"card_light": "#fff",
|
103
|
+
"bg_light": "#F3F7FB",
|
104
|
+
"card_dark": "#231E3D",
|
105
|
+
"bg_dark": "#0a0527",
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
|
3
|
+
import { render, screen } from '../utilities/test-utils'
|
4
|
+
import { Overlay } from '..'
|
5
|
+
|
6
|
+
const testId = "overlay"
|
7
|
+
const children = "This is the Overlay children"
|
8
|
+
|
9
|
+
test('should pass data prop', () => {
|
10
|
+
const props = {
|
11
|
+
children,
|
12
|
+
data: { testid: testId }
|
13
|
+
}
|
14
|
+
|
15
|
+
render(<Overlay {...props} />)
|
16
|
+
const kit = screen.getByTestId(testId)
|
17
|
+
expect(kit).toBeInTheDocument()
|
18
|
+
})
|
19
|
+
|
20
|
+
test("should pass className prop", () => {
|
21
|
+
const className = "custom-class-name"
|
22
|
+
const props = {
|
23
|
+
className,
|
24
|
+
children,
|
25
|
+
data: { testid: testId },
|
26
|
+
}
|
27
|
+
|
28
|
+
render(<Overlay {...props} />)
|
29
|
+
const kit = screen.getByTestId(testId)
|
30
|
+
expect(kit).toHaveClass(className)
|
31
|
+
})
|
32
|
+
|
33
|
+
test('should pass aria prop', () => {
|
34
|
+
const props = {
|
35
|
+
aria: { label: testId },
|
36
|
+
children,
|
37
|
+
data: { testid: testId },
|
38
|
+
}
|
39
|
+
|
40
|
+
render(<Overlay {...props} />)
|
41
|
+
const kit = screen.getByTestId(testId)
|
42
|
+
expect(kit).toHaveAttribute('aria-label', testId)
|
43
|
+
})
|
44
|
+
|
45
|
+
test('should pass id prop', () => {
|
46
|
+
const props = {
|
47
|
+
children,
|
48
|
+
data: { testid: testId },
|
49
|
+
id: testId
|
50
|
+
}
|
51
|
+
|
52
|
+
render(<Overlay {...props} />)
|
53
|
+
const kit = screen.getByTestId(testId)
|
54
|
+
expect(kit).toHaveAttribute('id', testId)
|
55
|
+
})
|
56
|
+
|
57
|
+
test('should render children', () => {
|
58
|
+
const props = {
|
59
|
+
children,
|
60
|
+
data: { testid: testId }
|
61
|
+
}
|
62
|
+
|
63
|
+
render(<Overlay {...props} />)
|
64
|
+
const kit = screen.getByTestId(testId)
|
65
|
+
expect(kit).toHaveTextContent(props.children)
|
66
|
+
})
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import defaultColors from "../../tokens/exports/_colors.scss";
|
3
|
+
import { OverlayChildrenProps } from '../_overlay';
|
4
|
+
|
5
|
+
|
6
|
+
const previousOverlayDirectionMap: { [key: string]: string } = {
|
7
|
+
"bottom": "to top",
|
8
|
+
"top": "to bottom",
|
9
|
+
"left": "to right",
|
10
|
+
"right": "to left",
|
11
|
+
"x": "to right",
|
12
|
+
"y": "to top",
|
13
|
+
}
|
14
|
+
|
15
|
+
const subsequentOverlayDirectionMap: { [key: string]: string } = {
|
16
|
+
...previousOverlayDirectionMap,
|
17
|
+
"x": "to left",
|
18
|
+
"y": "to bottom",
|
19
|
+
}
|
20
|
+
|
21
|
+
const OverlayPercentage = (props: OverlayChildrenProps) => {
|
22
|
+
const {
|
23
|
+
children,
|
24
|
+
color,
|
25
|
+
position,
|
26
|
+
size,
|
27
|
+
} = props
|
28
|
+
|
29
|
+
const getPreviousOverlayDirection = () => {
|
30
|
+
return previousOverlayDirectionMap[position]
|
31
|
+
}
|
32
|
+
|
33
|
+
const getSubsequentOverlayDirection = () => {
|
34
|
+
return subsequentOverlayDirectionMap[position]
|
35
|
+
}
|
36
|
+
|
37
|
+
const hasSubsequentOverlay = position === "x" || position === "y"
|
38
|
+
|
39
|
+
const previousOverlay = `linear-gradient(${getPreviousOverlayDirection()}, ${defaultColors[color]} 0%, transparent ${size})`
|
40
|
+
const subsequentOverlay = `linear-gradient(${getSubsequentOverlayDirection()}, ${defaultColors[color]} 0%, transparent ${size})`
|
41
|
+
|
42
|
+
return (
|
43
|
+
<>
|
44
|
+
<div className="overlay_linear_gradient"
|
45
|
+
style={{ background: previousOverlay }} />
|
46
|
+
|
47
|
+
{children}
|
48
|
+
|
49
|
+
{ hasSubsequentOverlay &&
|
50
|
+
<div className="overlay_linear_gradient"
|
51
|
+
style={{ background: subsequentOverlay }} />
|
52
|
+
}
|
53
|
+
</>
|
54
|
+
)
|
55
|
+
}
|
56
|
+
|
57
|
+
export default OverlayPercentage
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { OverlayChildrenProps } from '../_overlay'
|
3
|
+
|
4
|
+
const previousOverlayDirectionMap: { [key: string]: string } = {
|
5
|
+
"x": "left",
|
6
|
+
"y": "top",
|
7
|
+
}
|
8
|
+
|
9
|
+
const subsequentOverlayDirectionMap: { [key: string]: string } = {
|
10
|
+
"x": "right",
|
11
|
+
"y": "bottom",
|
12
|
+
}
|
13
|
+
|
14
|
+
const OverlayToken = (props: OverlayChildrenProps) => {
|
15
|
+
const {
|
16
|
+
children,
|
17
|
+
color,
|
18
|
+
position,
|
19
|
+
size,
|
20
|
+
} = props
|
21
|
+
|
22
|
+
const hasSubsequentOverlay = position === "x" || position === "y"
|
23
|
+
|
24
|
+
const getPreviousOverlayDirection = () => {
|
25
|
+
return hasSubsequentOverlay ? previousOverlayDirectionMap[position] : position
|
26
|
+
}
|
27
|
+
|
28
|
+
const getSubsequentOverlayDirection = () => {
|
29
|
+
return hasSubsequentOverlay ? subsequentOverlayDirectionMap[position] : position
|
30
|
+
}
|
31
|
+
|
32
|
+
const previousOverlayClassName = `overlay_${color}_${getPreviousOverlayDirection()}_${size}`
|
33
|
+
const subsequentOverlayClassName = `overlay_${color}_${getSubsequentOverlayDirection()}_${size}`
|
34
|
+
|
35
|
+
return (
|
36
|
+
<>
|
37
|
+
<div className={previousOverlayClassName} />
|
38
|
+
|
39
|
+
{children}
|
40
|
+
|
41
|
+
{ hasSubsequentOverlay &&
|
42
|
+
<div className={subsequentOverlayClassName} />
|
43
|
+
}
|
44
|
+
</>
|
45
|
+
)
|
46
|
+
}
|
47
|
+
|
48
|
+
export default OverlayToken
|