playbook_ui 15.2.0.pre.alpha.PLAY2428advancedtablerailscellpadding11387 → 15.2.0.pre.alpha.PLAY236711413
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/_playbook.scss +4 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_styling_rails.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_rails.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_row_styling_react.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +0 -3
- data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +1 -2
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +0 -44
- data/app/pb_kits/playbook/pb_pb_bar_graph/_pb_bar_graph.tsx +8 -6
- data/app/pb_kits/playbook/pb_pb_bar_graph/pb_bar_graph.rb +7 -10
- data/app/pb_kits/playbook/pb_pb_bar_graph/pbbargraph.test.jsx +73 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/_pb_circle_chart.tsx +1 -1
- data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.rb +7 -10
- data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.test.jsx +47 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.scss +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/_pb_line_graph.tsx +61 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_description.md +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.html.erb +34 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.jsx +52 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_colors.md +5 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.html.erb +34 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_default.jsx +45 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.html.erb +47 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.jsx +64 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_height.md +3 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.html.erb +24 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend.jsx +37 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.html.erb +39 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_nonclickable.jsx +45 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.html.erb +86 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.jsx +116 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/_pb_line_graph_legend_position.md +11 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/example.yml +20 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/docs/index.js +6 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pbLineGraphTheme.ts +125 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.html.erb +1 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.rb +25 -0
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.test.jsx +110 -0
- data/dist/chunks/{_line_graph-DY4PK6AH.js → _line_graph-AKTV-rqw.js} +1 -1
- data/dist/chunks/{_typeahead-fQDb_yVO.js → _typeahead-DCInCM2E.js} +1 -1
- data/dist/chunks/{_weekday_stacked-D_bGbWtk.js → _weekday_stacked-ByJl1kOQ.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +6 -0
- data/dist/playbook-doc.js +2 -2
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +29 -11
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.html.erb +0 -113
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_background_control_rails.md +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.html.erb +0 -51
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row_rails.md +0 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.html.erb +0 -40
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_rails.md +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cc2c7f12836c0b0cfd328cd4da352d15742389255cad6ebb58c7ce81950b8c1
|
4
|
+
data.tar.gz: ea405e40cdff68ce02f3601dd8b2980ad4f0dd2ef9e2f41604cb07cee0b5a110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06c40f5eceac33d198cfb4fead060cd6ec83a89015ed203918803c986f2681ffcea85aa20195a4169a97dc7795c1d8c157104ae6d577a5146d9e64e7603ae811
|
7
|
+
data.tar.gz: 8dc8b586a3f229d87db253fabfae256d43799df4c8ba1d17df525d5502a8b885cd0954c032b7dac7ad7304f2cdf1a18a860368500f1dd775a386635a9743fe20
|
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
1
|
@import 'pb_advanced_table/advanced_table';
|
5
2
|
@import 'pb_avatar/avatar';
|
6
3
|
@import 'pb_background/background';
|
@@ -33,6 +30,7 @@
|
|
33
30
|
@import 'pb_distribution_bar/distribution_bar';
|
34
31
|
@import 'pb_draggable/draggable';
|
35
32
|
@import 'pb_dropdown/dropdown';
|
33
|
+
@import 'pb_empty_state/empty_state';
|
36
34
|
@import 'pb_file_upload/file_upload';
|
37
35
|
@import 'pb_filter/filter';
|
38
36
|
@import 'pb_fixed_confirmation_toast/fixed_confirmation_toast';
|
@@ -70,6 +68,9 @@
|
|
70
68
|
@import 'pb_overlay/overlay';
|
71
69
|
@import 'pb_pagination/pagination';
|
72
70
|
@import 'pb_passphrase/passphrase';
|
71
|
+
@import 'pb_pb_bar_graph/pb_bar_graph';
|
72
|
+
@import 'pb_pb_circle_chart/pb_circle_chart';
|
73
|
+
@import 'pb_pb_line_graph/pb_line_graph';
|
73
74
|
@import 'pb_person/person';
|
74
75
|
@import 'pb_person_contact/person_contact';
|
75
76
|
@import 'pb_phone_number_input/phone_number_input';
|
@@ -108,9 +109,6 @@
|
|
108
109
|
@import 'pb_user/user';
|
109
110
|
@import 'pb_user_badge/user_badge';
|
110
111
|
@import 'pb_weekday_stacked/weekday_stacked';
|
111
|
-
@import 'pb_empty_state/empty_state';
|
112
|
-
@import 'pb_pb_bar_graph/pb_bar_graph';
|
113
|
-
@import 'pb_pb_circle_chart/pb_circle_chart';
|
114
112
|
@import 'utilities/mixins';
|
115
113
|
@import 'utilities/spacing';
|
116
114
|
@import 'utilities/cursor';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
The `columnStyling` prop is an optional item that can be used within `columnDefinitions` as shown in the code snippet below. It is an object that has
|
1
|
+
The `columnStyling` prop is an optional item that can be used within `columnDefinitions` as shown in the code snippet below. It is an object that has 2 optional key/value pairs:
|
2
2
|
|
3
3
|
1) `headerAlignment`: This will allow you to control alignment of header content which is set to right aligned by default. you can set this to `left`, `right` or `center`.
|
4
4
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
The `column_styling` prop is an optional item that can be used within `column_definitions` as shown in the code snippet below.
|
1
|
+
The `column_styling` prop is an optional item that can be used within `column_definitions` as shown in the code snippet below. It is an object that has 2 optional key/value pairs:
|
2
2
|
|
3
3
|
1) `header_alignment`: This will allow you to control alignment of header content which is set to right aligned by default. you can set this to `left`, `right` or `center`.
|
4
4
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
The `row_styling` prop can be used in conjunction with row ids to control certain styling options on individual rows.
|
1
|
+
The `row_styling` prop can be used in conjunction with row ids to control certain styling options on individual rows. Currently, `row_styling` gives you 3 optional controls:
|
2
2
|
|
3
3
|
- `background_color` : use this to control the background color of the row
|
4
4
|
- `font_color`: use this to control font color for each row if needed, for example if using a darker background color.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
The `rowStyling` prop can be used in conjunction with row ids to control certain styling options on individual rows.
|
1
|
+
The `rowStyling` prop can be used in conjunction with row ids to control certain styling options on individual rows. Currently, `rowStyling` gives you 3 optional controls:
|
2
2
|
|
3
3
|
- `backgroundColor` : use this to control the background color of the row
|
4
4
|
- `fontColor`: use this to control font color for each row if needed, for example if using a darker background color.
|
@@ -21,11 +21,8 @@ examples:
|
|
21
21
|
- advanced_table_selectable_rows_header_rails: Selectable Rows (No Actions Bar)
|
22
22
|
- advanced_table_scrollbar_none: Advanced Table Scrollbar None
|
23
23
|
- advanced_table_row_styling: Row Styling
|
24
|
-
- advanced_table_padding_control_per_row_rails: Padding Control using Row Styling
|
25
24
|
- advanced_table_column_styling_rails: Column Styling
|
26
25
|
- advanced_table_column_styling_column_headers_rails: Column Styling with Multiple Headers
|
27
|
-
- advanced_table_padding_control_rails: Padding Control using Column Styling
|
28
|
-
- advanced_table_background_control_rails: Background Control using Column Styling
|
29
26
|
- advanced_table_column_border_color_rails: Column Group Border Color
|
30
27
|
|
31
28
|
|
@@ -12,8 +12,7 @@
|
|
12
12
|
<% end %>
|
13
13
|
<% object.column_definitions.each_with_index do |column, index| %>
|
14
14
|
<% next unless column[:accessor].present? %>
|
15
|
-
|
16
|
-
<%= pb_rails(component_info[:name], props: component_info[:props]) do %>
|
15
|
+
<%= pb_rails("table/table_cell", props: { html_options: { style: { "background-color": bg_color, color: font_color } }, classname:object.td_classname(column, index)}) do %>
|
17
16
|
<%= pb_rails("flex", props:{ align: "center", justify: object.justify_for(column, index), classname: object.loading ? "loading-cell" : "" }) do %>
|
18
17
|
<% if collapsible_trail && index.zero? %>
|
19
18
|
<% (1..depth).each do |i| %>
|
@@ -46,53 +46,9 @@ module Playbook
|
|
46
46
|
classes = %w[id-cell]
|
47
47
|
classes << "last-cell" if column[:is_last_in_group]
|
48
48
|
classes << "pinned-left" if index.zero? && is_pinned_left && responsive == "scroll"
|
49
|
-
|
50
|
-
row_style = row_styling.find { |style| style[:row_id].to_s == row_id.to_s }
|
51
|
-
row_padding = row_style&.[](:cell_padding)
|
52
|
-
|
53
|
-
if column[:accessor].present?
|
54
|
-
orig_def = find_column_def_by_accessor(column_definitions, column[:accessor])
|
55
|
-
column_padding = orig_def[:column_styling][:cell_padding] if orig_def && orig_def[:column_styling].is_a?(Hash) && orig_def[:column_styling][:cell_padding].present?
|
56
|
-
end
|
57
|
-
|
58
|
-
classes << "p_#{row_padding}" if row_padding.present?
|
59
|
-
classes << "p_#{column_padding}" if column_padding.present?
|
60
|
-
|
61
49
|
classes.join(" ")
|
62
50
|
end
|
63
51
|
|
64
|
-
def cell_background_color(column)
|
65
|
-
return nil unless column[:accessor].present?
|
66
|
-
|
67
|
-
orig_def = find_column_def_by_accessor(column_definitions, column[:accessor])
|
68
|
-
if orig_def && orig_def[:column_styling].is_a?(Hash) && orig_def[:column_styling][:cell_background_color].present?
|
69
|
-
bg_color = orig_def[:column_styling][:cell_background_color]
|
70
|
-
if bg_color.respond_to?(:call)
|
71
|
-
bg_color.call(row)
|
72
|
-
else
|
73
|
-
bg_color
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def has_custom_background_color?(column)
|
79
|
-
cell_background_color(column).present?
|
80
|
-
end
|
81
|
-
|
82
|
-
# Uses a regular table/table_cell component if there is no custom background color; if there is a cell_background_color uses a background component with tag "td"
|
83
|
-
def cell_component_info(column, index, bg_color, font_color)
|
84
|
-
if has_custom_background_color?(column)
|
85
|
-
custom_bg_color = cell_background_color(column)
|
86
|
-
component_name = "background"
|
87
|
-
component_props = { background_color: custom_bg_color, tag: "td", classname: td_classname(column, index) }
|
88
|
-
else
|
89
|
-
component_name = "table/table_cell"
|
90
|
-
component_props = { html_options: { style: { "background-color": bg_color, color: font_color } }, classname: td_classname(column, index) }
|
91
|
-
end
|
92
|
-
|
93
|
-
{ name: component_name, props: component_props }
|
94
|
-
end
|
95
|
-
|
96
52
|
def depth_accessors
|
97
53
|
column_definitions.flat_map do |column|
|
98
54
|
column[:cellAccessors] if column.key?(:cellAccessors)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { useMemo } from "react"
|
2
2
|
import { globalProps } from "../utilities/globalProps";
|
3
|
-
import { buildAriaProps, buildDataProps, buildHtmlProps } from "../utilities/props";
|
3
|
+
import { buildAriaProps, buildDataProps, buildCss, buildHtmlProps } from "../utilities/props";
|
4
4
|
import Highcharts from "highcharts"
|
5
5
|
import HighchartsReact from "highcharts-react-official"
|
6
6
|
|
@@ -18,23 +18,25 @@ type PbBarGraphProps = {
|
|
18
18
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)};
|
19
19
|
}
|
20
20
|
|
21
|
-
const PbBarGraph = ({
|
21
|
+
const PbBarGraph = ( props: PbBarGraphProps): React.ReactElement => {
|
22
|
+
const {
|
22
23
|
aria = {},
|
23
24
|
data = {},
|
24
25
|
id,
|
25
26
|
htmlOptions = {},
|
26
27
|
options,
|
27
|
-
className
|
28
|
-
}
|
28
|
+
className,
|
29
|
+
} = props
|
29
30
|
|
30
31
|
const ariaProps = buildAriaProps(aria);
|
31
32
|
const dataProps = buildDataProps(data)
|
32
33
|
const htmlProps = buildHtmlProps(htmlOptions);
|
34
|
+
const classes = classnames(buildCss('pb_pb_bar_graph'), globalProps(props), className)
|
33
35
|
|
34
36
|
const mergedOptions = useMemo(() => {
|
35
37
|
if (!options || typeof options !== "object") {
|
36
38
|
// eslint-disable-next-line no-console
|
37
|
-
console.error("❌ Invalid options passed to <
|
39
|
+
console.error("❌ Invalid options passed to <PbBarGraph />", options)
|
38
40
|
return {}
|
39
41
|
}
|
40
42
|
|
@@ -46,7 +48,7 @@ const PbBarGraph = ({
|
|
46
48
|
<div>
|
47
49
|
<HighchartsReact
|
48
50
|
containerProps={{
|
49
|
-
className: classnames(
|
51
|
+
className: classnames(classes),
|
50
52
|
id: id,
|
51
53
|
...ariaProps,
|
52
54
|
...dataProps,
|
@@ -4,24 +4,21 @@ module Playbook
|
|
4
4
|
module PbPbBarGraph
|
5
5
|
class PbBarGraph < ::Playbook::KitBase
|
6
6
|
prop :options, default: {}
|
7
|
-
prop :container_props, default: {}
|
8
7
|
|
9
8
|
def react_props
|
10
9
|
{
|
10
|
+
className: classname,
|
11
|
+
data: data,
|
11
12
|
options: options,
|
12
|
-
|
13
|
+
id: id,
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
16
|
-
def container_props_hash
|
17
|
-
container_props.merge({
|
18
|
-
id: id,
|
19
|
-
className: classname,
|
20
|
-
}).compact
|
21
|
-
end
|
22
|
-
|
23
17
|
def classname
|
24
|
-
|
18
|
+
# Highcharts react needs classname attached to the container div,
|
19
|
+
# we pass an empty string here to avoid conflicts, classname is built in the TSX
|
20
|
+
# We still need generate_classnames to retain ability to pass in custom classnames or global props
|
21
|
+
generate_classname("")
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -15,6 +15,41 @@ afterEach(() => {
|
|
15
15
|
console.warn.mockRestore();
|
16
16
|
});
|
17
17
|
|
18
|
+
const chartData = [{
|
19
|
+
name: 'Installation',
|
20
|
+
data: [1475, 200, 3000, 654, 656],
|
21
|
+
}, {
|
22
|
+
name: 'Manufacturing',
|
23
|
+
data: [4434, 524, 2320, 440, 500],
|
24
|
+
}, {
|
25
|
+
name: 'Sales & Distribution',
|
26
|
+
data: [3387, 743, 1344, 434, 440],
|
27
|
+
}, {
|
28
|
+
name: 'Project Development',
|
29
|
+
data: [3227, 878, 999, 780, 1000],
|
30
|
+
}, {
|
31
|
+
name: 'Other',
|
32
|
+
data: [1111, 677, 3245, 500, 200],
|
33
|
+
}]
|
34
|
+
|
35
|
+
const chartOptions = {
|
36
|
+
series: chartData,
|
37
|
+
title: {
|
38
|
+
text: 'Solar Employment Growth by Sector, 2010-2016',
|
39
|
+
},
|
40
|
+
subtitle: {
|
41
|
+
text: 'Source: thesolarfoundation.com',
|
42
|
+
},
|
43
|
+
xAxis: {
|
44
|
+
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
|
45
|
+
},
|
46
|
+
yAxis: {
|
47
|
+
title: {
|
48
|
+
text: 'Number of Employees',
|
49
|
+
},
|
50
|
+
},
|
51
|
+
}
|
52
|
+
|
18
53
|
const testId = 'bargraph1';
|
19
54
|
|
20
55
|
test('bargraph uses exact classname', () => {
|
@@ -23,9 +58,46 @@ test('bargraph uses exact classname', () => {
|
|
23
58
|
className='super_important_class'
|
24
59
|
data={{ testid: testId }}
|
25
60
|
id='bar-default'
|
61
|
+
options={chartOptions}
|
26
62
|
/>
|
27
63
|
);
|
28
64
|
|
29
65
|
const kit = screen.getByTestId(testId);
|
30
66
|
expect(kit).toHaveClass('super_important_class');
|
31
|
-
});
|
67
|
+
});
|
68
|
+
|
69
|
+
test('Kit to apply base classname', () => {
|
70
|
+
render(
|
71
|
+
<PbBarGraph
|
72
|
+
data={{testid: testId}}
|
73
|
+
options={chartOptions}
|
74
|
+
/>
|
75
|
+
)
|
76
|
+
|
77
|
+
expect(screen.getByTestId(testId)).toHaveClass('pb_pb_bar_graph')
|
78
|
+
})
|
79
|
+
|
80
|
+
|
81
|
+
test('Kit to apply global props', () => {
|
82
|
+
render(
|
83
|
+
<PbBarGraph
|
84
|
+
data={{testid: testId}}
|
85
|
+
margin="lg"
|
86
|
+
options={chartOptions}
|
87
|
+
/>
|
88
|
+
)
|
89
|
+
|
90
|
+
expect(screen.getByTestId(testId)).toHaveClass('m_lg')
|
91
|
+
})
|
92
|
+
|
93
|
+
test('kit to apply id', () => {
|
94
|
+
render(
|
95
|
+
<PbBarGraph
|
96
|
+
data={{testid: testId}}
|
97
|
+
id='bar-graph-id'
|
98
|
+
options={chartOptions}
|
99
|
+
/>
|
100
|
+
)
|
101
|
+
|
102
|
+
expect(screen.getByTestId(testId)).toHaveAttribute('id', 'bar-graph-id')
|
103
|
+
})
|
@@ -4,24 +4,21 @@ module Playbook
|
|
4
4
|
module PbPbCircleChart
|
5
5
|
class PbCircleChart < ::Playbook::KitBase
|
6
6
|
prop :options, default: {}
|
7
|
-
prop :container_props, default: {}
|
8
7
|
|
9
8
|
def react_props
|
10
9
|
{
|
10
|
+
className: classname,
|
11
|
+
data: data,
|
11
12
|
options: options,
|
12
|
-
|
13
|
+
id: id,
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
16
|
-
def container_props_hash
|
17
|
-
container_props.merge({
|
18
|
-
id: id,
|
19
|
-
className: classname,
|
20
|
-
}).compact
|
21
|
-
end
|
22
|
-
|
23
17
|
def classname
|
24
|
-
|
18
|
+
# Highcharts react needs classname attached to the container div,
|
19
|
+
# we pass an empty string here to avoid conflicts, classname is built in the TSX
|
20
|
+
# We still need generate_classnames to retain ability to pass in custom classnames or global props
|
21
|
+
generate_classname("")
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -49,3 +49,50 @@ test('Kit to exist', () => {
|
|
49
49
|
expect(screen.getByTestId(testId)).toBeInTheDocument()
|
50
50
|
})
|
51
51
|
|
52
|
+
test('Kit to apply base classname', () => {
|
53
|
+
render(
|
54
|
+
<PbCircleChart
|
55
|
+
data={{testid: testId}}
|
56
|
+
options={chartOptions}
|
57
|
+
/>
|
58
|
+
)
|
59
|
+
|
60
|
+
expect(screen.getByTestId(testId)).toHaveClass('pb_pb_circle_chart')
|
61
|
+
})
|
62
|
+
|
63
|
+
test('Kit to have custom class', () => {
|
64
|
+
render(
|
65
|
+
<PbCircleChart
|
66
|
+
className='custom-class'
|
67
|
+
data={{testid: testId}}
|
68
|
+
options={chartOptions}
|
69
|
+
/>
|
70
|
+
)
|
71
|
+
|
72
|
+
expect(screen.getByTestId(testId)).toHaveClass('custom-class')
|
73
|
+
})
|
74
|
+
|
75
|
+
test('Kit to apply global props', () => {
|
76
|
+
render(
|
77
|
+
<PbCircleChart
|
78
|
+
data={{testid: testId}}
|
79
|
+
margin="lg"
|
80
|
+
options={chartOptions}
|
81
|
+
/>
|
82
|
+
)
|
83
|
+
|
84
|
+
expect(screen.getByTestId(testId)).toHaveClass('m_lg')
|
85
|
+
})
|
86
|
+
|
87
|
+
test('kit to apply id', () => {
|
88
|
+
render(
|
89
|
+
<PbCircleChart
|
90
|
+
data={{testid: testId}}
|
91
|
+
id='circle-chart-id'
|
92
|
+
options={chartOptions}
|
93
|
+
/>
|
94
|
+
)
|
95
|
+
|
96
|
+
expect(screen.getByTestId(testId)).toHaveAttribute('id', 'circle-chart-id')
|
97
|
+
})
|
98
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
import React, { useMemo } from 'react'
|
3
|
+
import classnames from 'classnames'
|
4
|
+
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
|
5
|
+
import Highcharts from "highcharts"
|
6
|
+
import HighchartsReact from "highcharts-react-official"
|
7
|
+
import pbLineGraphTheme from './pbLineGraphTheme'
|
8
|
+
import { globalProps } from '../utilities/globalProps'
|
9
|
+
|
10
|
+
|
11
|
+
type PbLineGraphProps = {
|
12
|
+
aria?: { [key: string]: string },
|
13
|
+
className?: string,
|
14
|
+
data?: { [key: string]: string },
|
15
|
+
id?: string,
|
16
|
+
htmlOptions?: { [key: string]: string | number | boolean | (() => void) };
|
17
|
+
options: Record<string, unknown>
|
18
|
+
}
|
19
|
+
|
20
|
+
const PbLineGraph = (props: PbLineGraphProps) => {
|
21
|
+
const {
|
22
|
+
aria = {},
|
23
|
+
className,
|
24
|
+
data = {},
|
25
|
+
id,
|
26
|
+
htmlOptions = {},
|
27
|
+
options
|
28
|
+
} = props
|
29
|
+
|
30
|
+
const ariaProps = buildAriaProps(aria)
|
31
|
+
const dataProps = buildDataProps(data)
|
32
|
+
const htmlProps = buildHtmlProps(htmlOptions);
|
33
|
+
const classes = classnames(buildCss('pb_pb_line_graph'), globalProps(props), className)
|
34
|
+
|
35
|
+
const mergedOptions = useMemo(() => {
|
36
|
+
if (!options || typeof options !== "object") {
|
37
|
+
// eslint-disable-next-line no-console
|
38
|
+
console.error("❌ Invalid options passed to <PbLineGraph />", options)
|
39
|
+
return {}
|
40
|
+
}
|
41
|
+
|
42
|
+
return Highcharts.merge({}, pbLineGraphTheme, options)
|
43
|
+
}, [options])
|
44
|
+
return (
|
45
|
+
<div>
|
46
|
+
<HighchartsReact
|
47
|
+
containerProps={{
|
48
|
+
className: classnames(classes),
|
49
|
+
id: id,
|
50
|
+
...ariaProps,
|
51
|
+
...dataProps,
|
52
|
+
...htmlProps
|
53
|
+
}}
|
54
|
+
highcharts={Highcharts}
|
55
|
+
options={mergedOptions}
|
56
|
+
/>
|
57
|
+
</div>
|
58
|
+
)
|
59
|
+
}
|
60
|
+
|
61
|
+
export default PbLineGraph
|
@@ -0,0 +1,3 @@
|
|
1
|
+
This kit is a wrapper around the Highcharts library. It applies styling and default settings but does NOT ship Highcharts. In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo. Once done, any prop or functionality provided by Highcharts can be used with this kit without requiring specifc props from Playbook. The doc examples below showcase a few common usecases but are not a comprehensive list of all the functionalities possible.
|
2
|
+
|
3
|
+
See the [highcharts API docs](https://api.highcharts.com/highcharts/) for a comprehensive look at what is possible.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% data = [{
|
2
|
+
name: 'Installation',
|
3
|
+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
|
4
|
+
}, {
|
5
|
+
name: 'Manufacturing',
|
6
|
+
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
|
7
|
+
}, {
|
8
|
+
name: 'Sales & Distribution',
|
9
|
+
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
|
10
|
+
}, {
|
11
|
+
name: 'Project Development',
|
12
|
+
data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227],
|
13
|
+
}, {
|
14
|
+
name: 'Other',
|
15
|
+
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
|
16
|
+
}] %>
|
17
|
+
|
18
|
+
<% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] %>
|
19
|
+
|
20
|
+
<% chart_options = {
|
21
|
+
series: data,
|
22
|
+
colors: ['#1CA05C', '#FD804C', '#144075', '#00C4D7', '#DA0014'],
|
23
|
+
title: { text: "Line Graph with Custom Data Colors" },
|
24
|
+
xAxis: {
|
25
|
+
categories: categories,
|
26
|
+
},
|
27
|
+
yAxis: {
|
28
|
+
title: {
|
29
|
+
text: "Number of Employees",
|
30
|
+
},
|
31
|
+
},
|
32
|
+
} %>
|
33
|
+
|
34
|
+
<%= pb_rails("pb_line_graph", props: {options: chart_options}) %>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import PbLineGraph from '../../pb_pb_line_graph/_pb_line_graph'
|
3
|
+
import { colors } from 'playbook-ui'
|
4
|
+
|
5
|
+
const data = [{
|
6
|
+
name: 'Installation',
|
7
|
+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
|
8
|
+
}, {
|
9
|
+
name: 'Manufacturing',
|
10
|
+
data: [24916, 28064, 29742, 40851, 50590, 65282, 70121, 85434],
|
11
|
+
}, {
|
12
|
+
name: 'Sales & Distribution',
|
13
|
+
data: [11744, 17722, 16005, 19771, 25185, 28377, 36147, 43387],
|
14
|
+
}, {
|
15
|
+
name: 'Project Development',
|
16
|
+
data: [5332, 6344, 7988, 12169, 15112, 14452, 22400, 30227],
|
17
|
+
}, {
|
18
|
+
name: 'Other',
|
19
|
+
data: [null, null, null, 3112, 4989, 5816, 15274, 18111],
|
20
|
+
}]
|
21
|
+
|
22
|
+
const categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
23
|
+
|
24
|
+
const chartOptions = {
|
25
|
+
title: {
|
26
|
+
text: 'Line Graph with Custom Data Colors',
|
27
|
+
},
|
28
|
+
xAxis: {
|
29
|
+
categories: categories,
|
30
|
+
},
|
31
|
+
yAxis: {
|
32
|
+
min: 0,
|
33
|
+
title: {
|
34
|
+
text: 'Number of Employees',
|
35
|
+
},
|
36
|
+
},
|
37
|
+
series: data,
|
38
|
+
colors: [colors.data_4, colors.data_5, "#144075", colors.data_7, colors.data_8]
|
39
|
+
}
|
40
|
+
|
41
|
+
const PbLineGraphColors = (props) => {
|
42
|
+
return (
|
43
|
+
<div>
|
44
|
+
<PbLineGraph
|
45
|
+
options={chartOptions}
|
46
|
+
{...props}
|
47
|
+
/>
|
48
|
+
</div>
|
49
|
+
)
|
50
|
+
}
|
51
|
+
|
52
|
+
export default PbLineGraphColors
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Custom data colors allow for color customization to match the needs of business requirements.
|
2
|
+
|
3
|
+
For React, import 'colors' from Playbook, then set custom colors in the colors array using the desired color variables. Hex colors are also available.
|
4
|
+
|
5
|
+
For Rails, HEX values are required.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% data = [{
|
2
|
+
name: 'Installation',
|
3
|
+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
|
4
|
+
}, {
|
5
|
+
name: 'Manufacturing',
|
6
|
+
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
|
7
|
+
}, {
|
8
|
+
name: 'Sales & Distribution',
|
9
|
+
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
|
10
|
+
}, {
|
11
|
+
name: 'Project Development',
|
12
|
+
data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227],
|
13
|
+
}, {
|
14
|
+
name: 'Other',
|
15
|
+
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
|
16
|
+
}] %>
|
17
|
+
|
18
|
+
<% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] %>
|
19
|
+
|
20
|
+
<% chart_options = {
|
21
|
+
series: data,
|
22
|
+
title: { text: "Solar Employment Growth by Sector, 2010-2016" },
|
23
|
+
subtitle: { text: "Source: thesolarfoundation.com" },
|
24
|
+
xAxis: {
|
25
|
+
categories: categories,
|
26
|
+
},
|
27
|
+
yAxis: {
|
28
|
+
title: {
|
29
|
+
text: "Number of Employees",
|
30
|
+
},
|
31
|
+
},
|
32
|
+
} %>
|
33
|
+
|
34
|
+
<%= pb_rails("pb_line_graph", props: {options: chart_options}) %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import PbLineGraph from '../../pb_pb_line_graph/_pb_line_graph'
|
3
|
+
|
4
|
+
const data = [{
|
5
|
+
name: 'Installation',
|
6
|
+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
|
7
|
+
}, {
|
8
|
+
name: 'Manufacturing',
|
9
|
+
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
|
10
|
+
}, {
|
11
|
+
name: 'Sales & Distribution',
|
12
|
+
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387],
|
13
|
+
}, {
|
14
|
+
name: 'Project Development',
|
15
|
+
data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227],
|
16
|
+
}, {
|
17
|
+
name: 'Other',
|
18
|
+
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111],
|
19
|
+
}]
|
20
|
+
|
21
|
+
const categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
22
|
+
|
23
|
+
const chartOptions = {
|
24
|
+
series: data,
|
25
|
+
title: { text: "Solar Employment Growth by Sector, 2010-2016" },
|
26
|
+
subtitle: { text: "Source: thesolarfoundation.com" },
|
27
|
+
xAxis: {
|
28
|
+
categories: categories,
|
29
|
+
},
|
30
|
+
yAxis: {
|
31
|
+
title: {
|
32
|
+
text: "Number of Employees",
|
33
|
+
},
|
34
|
+
},
|
35
|
+
}
|
36
|
+
const PbLineGraphDefault = (props) => (
|
37
|
+
<div>
|
38
|
+
<PbLineGraph
|
39
|
+
options={chartOptions}
|
40
|
+
{...props}
|
41
|
+
/>
|
42
|
+
</div>
|
43
|
+
)
|
44
|
+
|
45
|
+
export default PbLineGraphDefault
|