playbook_ui 11.11.0 → 11.12.1.pre.alpha.charts1
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/index.js +2 -1
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +145 -0
- data/app/pb_kits/playbook/pb_bar_graph/bar_graph.rb +17 -1
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_legend_position.html.erb +62 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_legend_position.jsx +86 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_legend_position.md +17 -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_button/_button.scss +6 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_default.html.erb +4 -4
- data/app/pb_kits/playbook/pb_button/docs/_button_default.jsx +18 -17
- data/app/pb_kits/playbook/pb_circle_chart/ChartsTypes.ts +2 -0
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +216 -0
- data/app/pb_kits/playbook/pb_circle_chart/circle_chart.html.erb +9 -21
- data/app/pb_kits/playbook/pb_circle_chart/circle_chart.rb +23 -47
- data/app/pb_kits/playbook/pb_circle_chart/docs/_circle_chart_legend_position.html.erb +86 -0
- data/app/pb_kits/playbook/pb_circle_chart/docs/_circle_chart_legend_position.jsx +114 -0
- data/app/pb_kits/playbook/pb_circle_chart/docs/_circle_chart_legend_position.md +17 -0
- data/app/pb_kits/playbook/pb_circle_chart/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_circle_chart/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_dashboard/pbChartsColorsHelper.ts +16 -0
- data/app/pb_kits/playbook/pb_dashboard/{pbChartsDarkTheme.js → pbChartsDarkTheme.ts} +6 -21
- data/app/pb_kits/playbook/pb_dashboard/{pbChartsLightTheme.js → pbChartsLightTheme.ts} +6 -21
- data/app/pb_kits/playbook/pb_dashboard/themeTypes.ts +16 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +50 -50
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_time.jsx +1 -0
- data/app/pb_kits/playbook/pb_date_picker/plugins/timeSelect.ts +89 -89
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_time_selection_styles.scss +15 -0
- data/app/pb_kits/playbook/pb_dialog/_dialog.scss +30 -1
- data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +28 -0
- data/app/pb_kits/playbook/pb_dialog/dialog.rb +7 -35
- data/app/pb_kits/playbook/pb_dialog/dialogHelper.js +21 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_body.html.erb +7 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_body.rb +13 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_footer.html.erb +13 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_footer.rb +16 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_header.html.erb +13 -0
- data/app/pb_kits/playbook/pb_dialog/dialog_header.rb +3 -20
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_compound_components.html.erb +12 -0
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_compound_components.md +3 -1
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_default.html.erb +11 -0
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_default.md +3 -0
- data/app/pb_kits/playbook/pb_dialog/docs/_dialog_sizes.html.erb +29 -0
- data/app/pb_kits/playbook/pb_dialog/docs/example.yml +3 -0
- data/app/pb_kits/playbook/pb_gauge/_gauge.scss +4 -0
- data/app/pb_kits/playbook/pb_gauge/_gauge.tsx +213 -0
- data/app/pb_kits/playbook/pb_gauge/docs/_gauge_complex.html.erb +1 -1
- data/app/pb_kits/playbook/pb_gauge/docs/_gauge_complex.jsx +8 -8
- data/app/pb_kits/playbook/pb_gauge/gauge.html.erb +1 -11
- data/app/pb_kits/playbook/pb_gauge/gauge.rb +3 -8
- data/app/pb_kits/playbook/pb_icon/_icon.tsx +3 -1
- data/app/pb_kits/playbook/pb_icon/icon.rb +8 -1
- data/app/pb_kits/playbook/pb_icon/icon.test.js +155 -0
- data/app/pb_kits/playbook/pb_legend/{_legend.jsx → _legend.tsx} +6 -6
- data/app/pb_kits/playbook/pb_legend/legend.test.js +29 -0
- data/app/pb_kits/playbook/pb_line_graph/_line_graph.tsx +148 -0
- data/app/pb_kits/playbook/pb_line_graph/docs/_line_graph_legend_position.html.erb +62 -0
- data/app/pb_kits/playbook/pb_line_graph/docs/_line_graph_legend_position.jsx +83 -0
- data/app/pb_kits/playbook/pb_line_graph/docs/_line_graph_legend_position.md +17 -0
- data/app/pb_kits/playbook/pb_line_graph/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_line_graph/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_line_graph/line_graph.rb +17 -1
- data/app/pb_kits/playbook/pb_radio/_radio.scss +1 -1
- data/app/pb_kits/playbook/pb_title/_title.scss +5 -0
- data/app/pb_kits/playbook/pb_title/_title.tsx +4 -1
- data/app/pb_kits/playbook/pb_title/docs/{_title_light.html.erb → _title_default.html.erb} +3 -3
- data/app/pb_kits/playbook/pb_title/docs/{_title_light.jsx → _title_default.jsx} +14 -14
- data/app/pb_kits/playbook/pb_title/docs/{_title_light.md → _title_default.md} +0 -0
- data/app/pb_kits/playbook/pb_title/docs/_title_light_weight.html.erb +1 -0
- data/app/pb_kits/playbook/pb_title/docs/_title_light_weight.jsx +19 -0
- data/app/pb_kits/playbook/pb_title/docs/_title_light_weight.md +4 -0
- data/app/pb_kits/playbook/pb_title/docs/example.yml +4 -2
- data/app/pb_kits/playbook/pb_title/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_title/title.rb +6 -1
- data/app/pb_kits/playbook/pb_title/title.test.js +13 -0
- data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.tsx +111 -0
- data/app/pb_kits/playbook/pb_treemap_chart/docs/_treemap_chart_tooltip.jsx +1 -1
- data/app/pb_kits/playbook/playbook-rails-react-bindings.js +4 -0
- data/app/pb_kits/playbook/playbook-rails.js +4 -4
- data/app/pb_kits/playbook/tokens/_titles.scss +10 -1
- data/app/pb_kits/playbook/tokens/_typography.scss +2 -2
- data/lib/playbook/version.rb +2 -2
- metadata +42 -17
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.jsx +0 -91
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.jsx +0 -136
- data/app/pb_kits/playbook/pb_dialog/_dialog.html.erb +0 -10
- data/app/pb_kits/playbook/pb_gauge/_gauge.jsx +0 -112
- data/app/pb_kits/playbook/pb_line_graph/_line_graph.jsx +0 -93
- data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.jsx +0 -79
- data/app/pb_kits/playbook/plugins/pb_chart.js +0 -309
@@ -1,2 +1,4 @@
|
|
1
1
|
The dialog kit also supports customizing your dialog with a [compound component](https://kentcdodds.com/blog/compound-components-with-react-hooks) structure.
|
2
|
-
This allows for greater flexibility and more complex dialogs.
|
2
|
+
This allows for greater flexibility and more complex dialogs.
|
3
|
+
|
4
|
+
For the Rails version, when using the kit as a compound component it is necessary to pass the same value as the id for the dialog, the dialog header and the dialog footer in order for the opening and closing of the dialog to function as expected.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= pb_rails("button", props: { text: "Open Dialog", data: {"open-dialog": "dialog-1"} }) %>
|
2
|
+
|
3
|
+
<%= pb_rails("dialog", props: {
|
4
|
+
id:"dialog-1",
|
5
|
+
size: "sm",
|
6
|
+
title: "This is a header",
|
7
|
+
text: "This is a dialog.",
|
8
|
+
cancel_button: "Cancel",
|
9
|
+
confirm_button: "Confirm",
|
10
|
+
confirm_button_id: "confirm-button-1"
|
11
|
+
}) %>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
For the Rails version of the dialog kit, the clickable element being used to open the dialog must be given a `open-dialog` data attribute with a value that is the same as the id being given to the dialog itself. See code example below to see this in action.
|
2
|
+
|
3
|
+
Additionally, both the cancel button and the confirm button have optional id props which can be used to pass in a custom id to allow developers to target that button with custom javascript if needed (`confirm_button_id` and `cancel_button_id`).
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= pb_rails("button", props: { text: "Small Dialog", data:{"open-dialog": "dialog-sm"} }) %>
|
2
|
+
<%= pb_rails("button", props: { text: "Medium Dialog", data:{"open-dialog": "dialog-md"} }) %>
|
3
|
+
<%= pb_rails("button", props: { text: "Large Dialog", data:{"open-dialog": "dialog-lg"} }) %>
|
4
|
+
|
5
|
+
<%= pb_rails("dialog", props: {
|
6
|
+
id:"dialog-sm",
|
7
|
+
size: "sm",
|
8
|
+
title: "This is a header",
|
9
|
+
text: "I am a small dialog",
|
10
|
+
cancel_button: "Cancel",
|
11
|
+
confirm_button: "Confirm",
|
12
|
+
}) %>
|
13
|
+
|
14
|
+
|
15
|
+
<%= pb_rails("dialog", props: {
|
16
|
+
id:"dialog-md",
|
17
|
+
size: "md",
|
18
|
+
title: "This is a header",
|
19
|
+
text: "I am a medium dialog",
|
20
|
+
cancel_button: "Cancel", confirm_button: "Confirm",
|
21
|
+
}) %>
|
22
|
+
|
23
|
+
<%= pb_rails("dialog", props: {
|
24
|
+
id:"dialog-lg", size: "lg",
|
25
|
+
title: "This is a header",
|
26
|
+
text: "I am a large dialog",
|
27
|
+
cancel_button: "Cancel",
|
28
|
+
confirm_button: "Confirm"
|
29
|
+
}) %>
|
@@ -0,0 +1,213 @@
|
|
1
|
+
import React, { useState, useEffect, useRef } from "react";
|
2
|
+
import classnames from "classnames";
|
3
|
+
import HighchartsReact from "highcharts-react-official";
|
4
|
+
import Highcharts from "highcharts";
|
5
|
+
import { highchartsTheme } from "../pb_dashboard/pbChartsLightTheme";
|
6
|
+
import { highchartsDarkTheme } from "../pb_dashboard/pbChartsDarkTheme";
|
7
|
+
import mapColors from "../pb_dashboard/pbChartsColorsHelper";
|
8
|
+
import highchartsMore from "highcharts/highcharts-more";
|
9
|
+
import solidGauge from "highcharts/modules/solid-gauge";
|
10
|
+
import defaultColors from "../tokens/exports/_colors.scss";
|
11
|
+
import typography from "../tokens/exports/_typography.scss";
|
12
|
+
|
13
|
+
import { buildAriaProps, buildCss, buildDataProps } from "../utilities/props";
|
14
|
+
import { globalProps } from "../utilities/globalProps";
|
15
|
+
|
16
|
+
type GaugeProps = {
|
17
|
+
aria: { [key: string]: string };
|
18
|
+
className?: string;
|
19
|
+
chartData?: { name: string; value: number[] | number }[];
|
20
|
+
dark?: Boolean;
|
21
|
+
data?: { [key: string]: string };
|
22
|
+
disableAnimation?: boolean;
|
23
|
+
fullCircle?: boolean;
|
24
|
+
height?: string;
|
25
|
+
id?: string;
|
26
|
+
max?: number;
|
27
|
+
min?: number;
|
28
|
+
prefix?: string;
|
29
|
+
showLabels?: boolean;
|
30
|
+
style?: string;
|
31
|
+
suffix?: string;
|
32
|
+
title?: string;
|
33
|
+
tooltipHtml?: string;
|
34
|
+
colors: string[];
|
35
|
+
minorTickInterval: any;
|
36
|
+
circumference: number[];
|
37
|
+
};
|
38
|
+
|
39
|
+
const Gauge = ({
|
40
|
+
aria = {},
|
41
|
+
className,
|
42
|
+
chartData,
|
43
|
+
dark = false,
|
44
|
+
data = {},
|
45
|
+
disableAnimation = false,
|
46
|
+
fullCircle = false,
|
47
|
+
height = null,
|
48
|
+
id,
|
49
|
+
max = 100,
|
50
|
+
min = 0,
|
51
|
+
prefix = "",
|
52
|
+
showLabels = false,
|
53
|
+
style = "solidgauge",
|
54
|
+
suffix = "",
|
55
|
+
title = "",
|
56
|
+
tooltipHtml = '<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: ' +
|
57
|
+
"<b>{point.y}</b>",
|
58
|
+
colors = [],
|
59
|
+
minorTickInterval = null,
|
60
|
+
circumference = fullCircle ? [0, 360] : [-100, 100],
|
61
|
+
...props
|
62
|
+
}: GaugeProps) => {
|
63
|
+
const ariaProps = buildAriaProps(aria);
|
64
|
+
const dataProps = buildDataProps(data);
|
65
|
+
highchartsMore(Highcharts);
|
66
|
+
solidGauge(Highcharts);
|
67
|
+
const setupTheme = () => {
|
68
|
+
dark
|
69
|
+
? Highcharts.setOptions(highchartsDarkTheme)
|
70
|
+
: Highcharts.setOptions(highchartsTheme);
|
71
|
+
};
|
72
|
+
setupTheme();
|
73
|
+
|
74
|
+
//set tooltip directly to prevent being overriden by Highcharts defaults
|
75
|
+
Highcharts.setOptions({
|
76
|
+
tooltip: {
|
77
|
+
pointFormat: tooltipHtml,
|
78
|
+
followPointer: true,
|
79
|
+
},
|
80
|
+
});
|
81
|
+
|
82
|
+
const css = buildCss({
|
83
|
+
pb_gauge_kit: true,
|
84
|
+
});
|
85
|
+
|
86
|
+
const componentDidMount = useRef(false);
|
87
|
+
const [options, setOptions] = useState({});
|
88
|
+
|
89
|
+
useEffect(() => {
|
90
|
+
const formattedChartData = chartData.map((obj: any) => {
|
91
|
+
obj.y = obj.value;
|
92
|
+
delete obj.value;
|
93
|
+
return obj;
|
94
|
+
});
|
95
|
+
|
96
|
+
const staticOptions = {
|
97
|
+
chart: {
|
98
|
+
events: {
|
99
|
+
load() {
|
100
|
+
setTimeout(this.reflow.bind(this), 0);
|
101
|
+
},
|
102
|
+
},
|
103
|
+
type: style,
|
104
|
+
height: height,
|
105
|
+
},
|
106
|
+
title: {
|
107
|
+
text: title,
|
108
|
+
},
|
109
|
+
yAxis: {
|
110
|
+
min: min,
|
111
|
+
max: max,
|
112
|
+
lineWidth: 0,
|
113
|
+
tickWidth: 0,
|
114
|
+
minorTickInterval: minorTickInterval,
|
115
|
+
tickAmount: 2,
|
116
|
+
tickPositions: [min, max],
|
117
|
+
labels: {
|
118
|
+
y: 26,
|
119
|
+
enabled: showLabels,
|
120
|
+
},
|
121
|
+
},
|
122
|
+
credits: false,
|
123
|
+
series: [
|
124
|
+
{
|
125
|
+
data: formattedChartData,
|
126
|
+
},
|
127
|
+
],
|
128
|
+
pane: {
|
129
|
+
center: ["50%", "50%"],
|
130
|
+
size: "90%",
|
131
|
+
startAngle: circumference[0],
|
132
|
+
endAngle: circumference[1],
|
133
|
+
background: {
|
134
|
+
borderWidth: 20,
|
135
|
+
innerRadius: "90%",
|
136
|
+
outerRadius: "90%",
|
137
|
+
shape: "arc",
|
138
|
+
className: "gauge-pane",
|
139
|
+
},
|
140
|
+
},
|
141
|
+
colors:
|
142
|
+
colors !== undefined && colors.length > 0
|
143
|
+
? mapColors(colors)
|
144
|
+
: highchartsTheme.colors,
|
145
|
+
plotOptions: {
|
146
|
+
series: {
|
147
|
+
animation: !disableAnimation,
|
148
|
+
},
|
149
|
+
solidgauge: {
|
150
|
+
borderColor:
|
151
|
+
colors !== undefined && colors.length === 1
|
152
|
+
? mapColors(colors).join()
|
153
|
+
: highchartsTheme.colors[0],
|
154
|
+
borderWidth: 20,
|
155
|
+
radius: 90,
|
156
|
+
innerRadius: "90%",
|
157
|
+
dataLabels: {
|
158
|
+
borderWidth: 0,
|
159
|
+
color: defaultColors.text_lt_default,
|
160
|
+
enabled: true,
|
161
|
+
format:
|
162
|
+
`<span class="prefix">${prefix}</span>` +
|
163
|
+
'<span class="fix">{y:,f}</span>' +
|
164
|
+
`<span class="suffix">${suffix}</span>`,
|
165
|
+
style: {
|
166
|
+
fontFamily: typography.font_family_base,
|
167
|
+
fontWeight: typography.regular,
|
168
|
+
fontSize: typography.heading_2,
|
169
|
+
},
|
170
|
+
y: -26,
|
171
|
+
},
|
172
|
+
},
|
173
|
+
},
|
174
|
+
};
|
175
|
+
|
176
|
+
setOptions({ ...staticOptions });
|
177
|
+
|
178
|
+
if (document.querySelector(".prefix")) {
|
179
|
+
document.querySelectorAll(".prefix").forEach((prefix) => {
|
180
|
+
prefix.setAttribute("y", "28");
|
181
|
+
});
|
182
|
+
document
|
183
|
+
.querySelectorAll(".fix")
|
184
|
+
.forEach((fix) => fix.setAttribute("y", "38"));
|
185
|
+
}
|
186
|
+
|
187
|
+
if (componentDidMount.current) {
|
188
|
+
Highcharts.charts.forEach((chart: any) => {
|
189
|
+
if (chart && chart.renderTo.id === id) {
|
190
|
+
chart.series[0].setData([chartData[0].value]);
|
191
|
+
chart.series[0].data[0].name = chartData[0].name;
|
192
|
+
}
|
193
|
+
});
|
194
|
+
} else {
|
195
|
+
componentDidMount.current = true;
|
196
|
+
}
|
197
|
+
}, [chartData]);
|
198
|
+
|
199
|
+
return (
|
200
|
+
<HighchartsReact
|
201
|
+
containerProps={{
|
202
|
+
className: classnames(css, globalProps(props)),
|
203
|
+
id: id,
|
204
|
+
...ariaProps,
|
205
|
+
...dataProps,
|
206
|
+
}}
|
207
|
+
highcharts={Highcharts}
|
208
|
+
options={options}
|
209
|
+
/>
|
210
|
+
);
|
211
|
+
};
|
212
|
+
|
213
|
+
export default Gauge;
|
@@ -71,26 +71,26 @@ const GaugeComplex = (props) => (
|
|
71
71
|
orientation="column"
|
72
72
|
wrap
|
73
73
|
>
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
<Body
|
75
|
+
color="light"
|
76
|
+
text="% Abandoned"
|
77
|
+
/>
|
78
78
|
<Flex wrap>
|
79
79
|
<FlexItem
|
80
80
|
fixedSize="150px"
|
81
81
|
overflow="hidden"
|
82
82
|
shrink
|
83
|
-
>
|
83
|
+
>
|
84
84
|
<Gauge
|
85
85
|
chartData={data}
|
86
86
|
disableAnimation
|
87
|
-
height="
|
87
|
+
height="150"
|
88
88
|
id="gauge-complex"
|
89
89
|
suffix="%"
|
90
90
|
{...props}
|
91
91
|
/>
|
92
|
-
|
93
|
-
</Flex>
|
92
|
+
</FlexItem>
|
93
|
+
</Flex>
|
94
94
|
</Flex>
|
95
95
|
</Flex>
|
96
96
|
</Card>
|
@@ -1,12 +1,2 @@
|
|
1
|
-
<%=
|
2
|
-
id: object.id,
|
3
|
-
data: object.data,
|
4
|
-
class: object.classname) %>
|
5
|
-
<% content_for :pb_js do %>
|
6
|
-
<%= javascript_tag do %>
|
7
|
-
window.addEventListener('DOMContentLoaded', function() {
|
8
|
-
new pbChart('.selector', <%= object.chart_options %>)
|
9
|
-
})
|
10
|
-
<% end %>
|
11
|
-
<% end %>
|
1
|
+
<%= react_component('Gauge', object.chart_options) %>
|
12
2
|
|
@@ -22,15 +22,10 @@ module Playbook
|
|
22
22
|
prop :max, type: Playbook::Props::Numeric, default: 100
|
23
23
|
prop :colors, type: Playbook::Props::Array, default: []
|
24
24
|
|
25
|
-
def chart_data_formatted
|
26
|
-
chart_data.map { |hash| hash[:y] = hash.delete :value }
|
27
|
-
chart_data
|
28
|
-
end
|
29
|
-
|
30
25
|
def chart_options
|
31
26
|
{
|
32
27
|
id: id,
|
33
|
-
chartData:
|
28
|
+
chartData: chart_data,
|
34
29
|
circumference: full_circle ? [0, 360] : [-100, 100],
|
35
30
|
dark: dark ? "dark" : "",
|
36
31
|
disableAnimation: disable_animation,
|
@@ -43,9 +38,9 @@ module Playbook
|
|
43
38
|
showLabels: show_labels,
|
44
39
|
style: style,
|
45
40
|
tooltipHtml: tooltip_html,
|
46
|
-
type:
|
41
|
+
type: style,
|
47
42
|
colors: colors,
|
48
|
-
}
|
43
|
+
}
|
49
44
|
end
|
50
45
|
|
51
46
|
def classname
|
@@ -34,6 +34,7 @@ type IconProps = {
|
|
34
34
|
pulse?: boolean,
|
35
35
|
rotation?: 90 | 180 | 270,
|
36
36
|
size?: IconSizes,
|
37
|
+
fontStyle?: 'far' | 'fas' | 'fab',
|
37
38
|
spin?: boolean,
|
38
39
|
} & GlobalProps
|
39
40
|
|
@@ -61,6 +62,7 @@ const Icon = (props: IconProps) => {
|
|
61
62
|
pulse = false,
|
62
63
|
rotation,
|
63
64
|
size,
|
65
|
+
fontStyle = 'far',
|
64
66
|
spin = false,
|
65
67
|
} = props
|
66
68
|
|
@@ -85,7 +87,7 @@ const Icon = (props: IconProps) => {
|
|
85
87
|
const classes = classnames(
|
86
88
|
flipMap[flip],
|
87
89
|
'pb_icon_kit',
|
88
|
-
customIcon ? '' :
|
90
|
+
customIcon ? '' : fontStyle,
|
89
91
|
faClasses,
|
90
92
|
globalProps(props),
|
91
93
|
className
|
@@ -32,13 +32,16 @@ module Playbook
|
|
32
32
|
prop :size, type: Playbook::Props::Enum,
|
33
33
|
values: ["lg", "xs", "sm", "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x", nil],
|
34
34
|
default: nil
|
35
|
+
prop :font_style, type: Playbook::Props::Enum,
|
36
|
+
values: %w[far fas fab],
|
37
|
+
default: "far"
|
35
38
|
prop :spin, type: Playbook::Props::Boolean,
|
36
39
|
default: false
|
37
40
|
|
38
41
|
def classname
|
39
42
|
generate_classname(
|
40
43
|
"pb_icon_kit",
|
41
|
-
|
44
|
+
font_style_class,
|
42
45
|
icon_class,
|
43
46
|
border_class,
|
44
47
|
fixed_width_class,
|
@@ -131,6 +134,10 @@ module Playbook
|
|
131
134
|
size ? "fa-#{size}" : nil
|
132
135
|
end
|
133
136
|
|
137
|
+
def font_style_class
|
138
|
+
font_style ? font_style.to_s : "far"
|
139
|
+
end
|
140
|
+
|
134
141
|
def spin_class
|
135
142
|
spin ? "fa-spin" : nil
|
136
143
|
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { render, screen, cleanup } from '../utilities/test-utils'
|
3
|
+
|
4
|
+
import Icon from './_icon'
|
5
|
+
|
6
|
+
const testId = "icon-kit"
|
7
|
+
|
8
|
+
describe("Icon Kit", () => {
|
9
|
+
test("renders Icon classname", () => {
|
10
|
+
render(
|
11
|
+
<Icon
|
12
|
+
data={{ testid: testId }}
|
13
|
+
fixedWidth
|
14
|
+
icon="user"
|
15
|
+
/>
|
16
|
+
)
|
17
|
+
|
18
|
+
const kit = screen.getByTestId(testId)
|
19
|
+
expect(kit).toHaveClass("fa-user pb_icon_kit fa-fw far")
|
20
|
+
})
|
21
|
+
|
22
|
+
test("renders rotate prop", () => {[
|
23
|
+
"90", "180", "270"].forEach((rotateProp)=> {
|
24
|
+
render(
|
25
|
+
<Icon
|
26
|
+
data={{ testid: testId }}
|
27
|
+
fixedWidth
|
28
|
+
icon="user"
|
29
|
+
rotation={rotateProp}
|
30
|
+
/>
|
31
|
+
)
|
32
|
+
|
33
|
+
const kit = screen.getByTestId(testId)
|
34
|
+
expect(kit).toHaveClass(`fa-user pb_icon_kit fa-fw fa-rotate-${rotateProp} far`)
|
35
|
+
|
36
|
+
cleanup()
|
37
|
+
})
|
38
|
+
})
|
39
|
+
|
40
|
+
test("renders flip prop", () => {
|
41
|
+
render(
|
42
|
+
<Icon
|
43
|
+
data={{ testid: testId }}
|
44
|
+
fixedWidth
|
45
|
+
flip="horizontal"
|
46
|
+
icon="user"
|
47
|
+
/>
|
48
|
+
)
|
49
|
+
|
50
|
+
const kit = screen.getByTestId(testId)
|
51
|
+
expect(kit).toHaveClass("fa-user pb_icon_kit fa-fw fa-flip-horizontal far")
|
52
|
+
})
|
53
|
+
|
54
|
+
|
55
|
+
test("renders spinning icon", () => {
|
56
|
+
render(
|
57
|
+
<Icon
|
58
|
+
data={{ testid: testId }}
|
59
|
+
fixedWidth
|
60
|
+
icon="spinner"
|
61
|
+
spin
|
62
|
+
/>
|
63
|
+
)
|
64
|
+
|
65
|
+
const kit = screen.getByTestId(testId)
|
66
|
+
expect(kit).toHaveClass("fa-spinner pb_icon_kit fa-fw fa-spin far")
|
67
|
+
})
|
68
|
+
|
69
|
+
test("renders pull icon", () => {
|
70
|
+
render(
|
71
|
+
<Icon
|
72
|
+
data={{ testid: testId }}
|
73
|
+
fixedWidth
|
74
|
+
icon="arrow-left"
|
75
|
+
pull="left"
|
76
|
+
/>
|
77
|
+
)
|
78
|
+
|
79
|
+
const kit = screen.getByTestId(testId)
|
80
|
+
expect(kit).toHaveClass("fa-arrow-left pb_icon_kit fa-fw fa-pull-left far")
|
81
|
+
})
|
82
|
+
|
83
|
+
test("renders pull icon", () => {
|
84
|
+
render(
|
85
|
+
<Icon
|
86
|
+
data={{ testid: testId }}
|
87
|
+
fixedWidth
|
88
|
+
icon="arrow-left"
|
89
|
+
pull="left"
|
90
|
+
/>
|
91
|
+
)
|
92
|
+
|
93
|
+
const kit = screen.getByTestId(testId)
|
94
|
+
expect(kit).toHaveClass("fa-arrow-left pb_icon_kit fa-fw fa-pull-left far")
|
95
|
+
})
|
96
|
+
|
97
|
+
test("renders border around icon", () => {
|
98
|
+
render(
|
99
|
+
<Icon
|
100
|
+
border
|
101
|
+
data={{ testid: testId }}
|
102
|
+
fixedWidth
|
103
|
+
icon="user"
|
104
|
+
/>
|
105
|
+
)
|
106
|
+
|
107
|
+
const kit = screen.getByTestId(testId)
|
108
|
+
expect(kit).toHaveClass("fa-user pb_icon_kit fa-border fa-fw far")
|
109
|
+
})
|
110
|
+
|
111
|
+
test("renders size prop", () => {
|
112
|
+
["lg",
|
113
|
+
"sm",
|
114
|
+
"xs",
|
115
|
+
"1x",
|
116
|
+
"2x",
|
117
|
+
"3x",
|
118
|
+
"4x",
|
119
|
+
"5x",
|
120
|
+
"6x",
|
121
|
+
"7x",
|
122
|
+
"8x",
|
123
|
+
"9x",
|
124
|
+
"10x"].forEach(
|
125
|
+
(sizeProp) => {
|
126
|
+
render(
|
127
|
+
<Icon
|
128
|
+
data={{ testid: testId }}
|
129
|
+
icon="user"
|
130
|
+
size={sizeProp}
|
131
|
+
/>
|
132
|
+
)
|
133
|
+
|
134
|
+
const kit = screen.getByTestId(testId)
|
135
|
+
expect(kit).toHaveClass(`pb_icon_kit fa-user fa-fw fa-${sizeProp} far`)
|
136
|
+
|
137
|
+
cleanup()
|
138
|
+
})
|
139
|
+
})
|
140
|
+
|
141
|
+
test("renders fontStyle prop", () => {
|
142
|
+
render(
|
143
|
+
<Icon
|
144
|
+
data={{ testid: testId }}
|
145
|
+
fixedWidth
|
146
|
+
fontStyle="fas"
|
147
|
+
icon="user"
|
148
|
+
/>
|
149
|
+
)
|
150
|
+
|
151
|
+
const kit = screen.getByTestId(testId)
|
152
|
+
expect(kit).toHaveClass("fa-user pb_icon_kit fa-fw fas")
|
153
|
+
})
|
154
|
+
|
155
|
+
})
|
@@ -1,5 +1,3 @@
|
|
1
|
-
/* @flow */
|
2
|
-
|
3
1
|
import React from 'react'
|
4
2
|
import classnames from 'classnames'
|
5
3
|
|
@@ -10,7 +8,7 @@ import Body from '../pb_body/_body'
|
|
10
8
|
import Title from '../pb_title/_title'
|
11
9
|
|
12
10
|
type LegendProps = {
|
13
|
-
aria?:
|
11
|
+
aria?: { [key: string]: string },
|
14
12
|
className?: string,
|
15
13
|
color?: string,
|
16
14
|
dark?: boolean,
|
@@ -59,14 +57,16 @@ const Legend = (props: LegendProps) => {
|
|
59
57
|
<span className={`${customColor ? "pb_legend_indicator_circle_custom" : "pb_legend_indicator_circle"}`}
|
60
58
|
style={customColorStyle}
|
61
59
|
/>
|
62
|
-
|
63
|
-
|
60
|
+
{
|
61
|
+
prefixText && (
|
62
|
+
<Title
|
64
63
|
dark={dark}
|
65
64
|
size={4}
|
66
65
|
tag="span"
|
67
66
|
text={` ${prefixText} `}
|
68
67
|
/>
|
69
|
-
|
68
|
+
)
|
69
|
+
}
|
70
70
|
{` ${text} `}
|
71
71
|
</Body>
|
72
72
|
</div>
|
@@ -27,3 +27,32 @@ test('color prop', () => {
|
|
27
27
|
const kit = screen.getByTestId('primary-test')
|
28
28
|
expect(kit).toHaveClass('pb_legend_kit_category_17')
|
29
29
|
})
|
30
|
+
|
31
|
+
test('prefixText prop renders', () => {
|
32
|
+
render(
|
33
|
+
<Legend
|
34
|
+
color="category_17"
|
35
|
+
data={{ testid: 'primary-test' }}
|
36
|
+
prefixText="10"
|
37
|
+
text="Test colors"
|
38
|
+
/>
|
39
|
+
)
|
40
|
+
|
41
|
+
const kit = screen.getByTestId('primary-test')
|
42
|
+
const prefix = kit.querySelector(".pb_title_kit_size_4")
|
43
|
+
expect(prefix).toBeInTheDocument()
|
44
|
+
})
|
45
|
+
|
46
|
+
test('Color prop renders with custom HEX value', () => {
|
47
|
+
render(
|
48
|
+
<Legend
|
49
|
+
color="#dc418a"
|
50
|
+
data={{ testid: 'primary-test' }}
|
51
|
+
text="Test colors"
|
52
|
+
/>
|
53
|
+
)
|
54
|
+
|
55
|
+
const kit = screen.getByTestId('primary-test')
|
56
|
+
const circle = kit.querySelector(".pb_legend_indicator_circle_custom")
|
57
|
+
expect(circle).toHaveStyle('background: rgb(220, 65, 138);')
|
58
|
+
})
|