playbook_ui 11.15.0 → 11.16.0.pre.alpha.paginationrails1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +2 -0
  3. data/app/pb_kits/playbook/data/menu.yml +1 -0
  4. data/app/pb_kits/playbook/index.js +2 -2
  5. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +145 -0
  6. data/app/pb_kits/playbook/pb_circle_chart/ChartsTypes.ts +2 -0
  7. data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.tsx +207 -0
  8. data/app/pb_kits/playbook/pb_circle_chart/circle_chart.html.erb +9 -21
  9. data/app/pb_kits/playbook/pb_circle_chart/circle_chart.rb +7 -47
  10. data/app/pb_kits/playbook/pb_dashboard/pbChartsColorsHelper.ts +16 -0
  11. data/app/pb_kits/playbook/pb_dashboard/{pbChartsDarkTheme.js → pbChartsDarkTheme.ts} +6 -21
  12. data/app/pb_kits/playbook/pb_dashboard/{pbChartsLightTheme.js → pbChartsLightTheme.ts} +6 -21
  13. data/app/pb_kits/playbook/pb_dashboard/themeTypes.ts +16 -0
  14. data/app/pb_kits/playbook/pb_gauge/_gauge.scss +4 -0
  15. data/app/pb_kits/playbook/pb_gauge/_gauge.tsx +202 -0
  16. data/app/pb_kits/playbook/pb_gauge/docs/_gauge_complex.html.erb +1 -1
  17. data/app/pb_kits/playbook/pb_gauge/docs/_gauge_complex.jsx +8 -8
  18. data/app/pb_kits/playbook/pb_gauge/gauge.html.erb +1 -11
  19. data/app/pb_kits/playbook/pb_gauge/gauge.rb +3 -8
  20. data/app/pb_kits/playbook/pb_line_graph/_line_graph.tsx +148 -0
  21. data/app/pb_kits/playbook/pb_pagination/_pagination.scss +68 -0
  22. data/app/pb_kits/playbook/pb_pagination/_pagination.tsx +41 -0
  23. data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.html.erb +28 -0
  24. data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.jsx +12 -0
  25. data/app/pb_kits/playbook/pb_pagination/docs/example.yml +9 -0
  26. data/app/pb_kits/playbook/pb_pagination/docs/index.js +1 -0
  27. data/app/pb_kits/playbook/pb_pagination/pagination.html.erb +7 -0
  28. data/app/pb_kits/playbook/pb_pagination/pagination.rb +18 -0
  29. data/app/pb_kits/playbook/pb_pagination/pagination.test.jsx +17 -0
  30. data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.tsx +111 -0
  31. data/app/pb_kits/playbook/pb_treemap_chart/docs/_treemap_chart_tooltip.jsx +1 -1
  32. data/app/pb_kits/playbook/playbook-doc.js +2 -0
  33. data/app/pb_kits/playbook/playbook-rails-react-bindings.js +4 -0
  34. data/app/pb_kits/playbook/playbook-rails.js +0 -4
  35. data/lib/playbook/kit_base.rb +2 -0
  36. data/lib/playbook/pagination_renderer.rb +41 -0
  37. data/lib/playbook/version.rb +2 -2
  38. data/lib/playbook.rb +1 -0
  39. metadata +38 -12
  40. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.jsx +0 -111
  41. data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.jsx +0 -151
  42. data/app/pb_kits/playbook/pb_gauge/_gauge.jsx +0 -112
  43. data/app/pb_kits/playbook/pb_line_graph/_line_graph.jsx +0 -113
  44. data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.jsx +0 -79
  45. data/app/pb_kits/playbook/plugins/pb_chart.js +0 -322
@@ -1,112 +0,0 @@
1
- /* @flow */
2
-
3
- import React, { useEffect, useRef } from 'react'
4
- import classnames from 'classnames'
5
- import Highcharts from 'highcharts'
6
-
7
- import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
8
- import { globalProps } from '../utilities/globalProps'
9
- import pbChart from '../plugins/pb_chart'
10
-
11
- type GaugeProps = {
12
- aria: Object,
13
- className?: string,
14
- chartData?: array,
15
- dark?: Boolean,
16
- data?: Object,
17
- disableAnimation: boolean,
18
- fullCircle: boolean,
19
- height: string,
20
- id?: string,
21
- max: number,
22
- min: number,
23
- prefix: string,
24
- showLabels: boolean,
25
- style: string,
26
- suffix: string,
27
- title: string,
28
- tooltipHtml: string,
29
- colors: array,
30
- }
31
-
32
- const Gauge = (props: GaugeProps) => {
33
- const {
34
- aria = {},
35
- className,
36
- chartData = [{ name: 'Name', value: 0 }],
37
- dark = false,
38
- data = {},
39
- disableAnimation = false,
40
- fullCircle = false,
41
- height = null,
42
- id,
43
- max = 100,
44
- min = 0,
45
- prefix = '',
46
- showLabels = false,
47
- style = 'solidgauge',
48
- suffix = '',
49
- title = '',
50
- tooltipHtml = '<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: ' + '<b>{point.y}</b>',
51
- colors = [],
52
- } = props
53
-
54
- const ariaProps = buildAriaProps(aria)
55
- const dataProps = buildDataProps(data)
56
-
57
- const css = buildCss({
58
- 'pb_gauge_kit': true,
59
- })
60
- // Runs first time component Renders
61
- useEffect(() => {
62
- const formattedChartData = chartData.map((obj) => {
63
- obj.y = obj.value
64
- delete obj.value
65
- return obj
66
- })
67
-
68
- new pbChart('.selector', {
69
- id: id,
70
- chartData: formattedChartData,
71
- circumference: fullCircle ? [0, 360] : [-100, 100],
72
- dark,
73
- disableAnimation: disableAnimation,
74
- height: height,
75
- min: min,
76
- max: max,
77
- prefix: prefix,
78
- title: title,
79
- suffix: suffix,
80
- showLabels: showLabels,
81
- style: style,
82
- tooltipHtml: tooltipHtml,
83
- type: 'gauge',
84
- colors: colors,
85
- })
86
- }, [])
87
-
88
- const componentDidMount = useRef(false)
89
- // Doesn't run the first time but runs every subsequent render
90
- useEffect(() => {
91
- if (componentDidMount.current) {
92
- Highcharts.charts.forEach((chart) => {
93
- if (chart && chart.renderTo.id === id) {
94
- chart.series[0].setData([chartData[0].value])
95
- chart.series[0].data[0].name = chartData[0].name
96
- }
97
- })
98
- } else {
99
- componentDidMount.current = true
100
- }
101
- }, [chartData])
102
- return (
103
- <div
104
- {...ariaProps}
105
- {...dataProps}
106
- className={classnames(css, globalProps(props), className)}
107
- id={id}
108
- />
109
- )
110
- }
111
-
112
- export default Gauge
@@ -1,113 +0,0 @@
1
- /* @flow */
2
-
3
- import React from 'react'
4
- import classnames from 'classnames'
5
-
6
- import { globalProps } from '../utilities/globalProps'
7
- import pbChart from '../plugins/pb_chart'
8
-
9
- type LineGraphProps = {
10
- align?: "left" | "right" | "center",
11
- axisTitle?: string,
12
- dark?: Boolean,
13
- xAxisCategories: array,
14
- yAxisMin: number,
15
- yAxisMax: number,
16
- className?: string,
17
- chartData: array<{
18
- name: string,
19
- data: array<number>,
20
- }>,
21
- gradient?: boolean,
22
- id: string,
23
- pointStart: number,
24
- subTitle?: string,
25
- title: string,
26
- type?: string,
27
- legend?: boolean,
28
- toggleLegendClick?: boolean,
29
- height?: string,
30
- colors: array,
31
- layout?: "horizontal" | "vertical" | "proximate",
32
- verticalAlign?: "top" | "middle" | "bottom",
33
- x?: number,
34
- y?: number,
35
- }
36
-
37
- export default class LineGraph extends React.Component<LineGraphProps> {
38
- static defaultProps = {
39
- align: "center",
40
- className: 'pb_bar_graph',
41
- dark: false,
42
- gradient: false,
43
- type: 'line',
44
- legend: false,
45
- toggleLegendClick: true,
46
- layout: "horizontal",
47
- verticalAlign: "bottom",
48
- x: 0,
49
- y: 0,
50
- }
51
-
52
- componentDidMount() {
53
- const {
54
- align,
55
- axisTitle,
56
- dark,
57
- xAxisCategories,
58
- yAxisMin,
59
- yAxisMax,
60
- className,
61
- chartData,
62
- id,
63
- pointStart,
64
- subTitle,
65
- title,
66
- type,
67
- legend,
68
- toggleLegendClick,
69
- height,
70
- colors = [],
71
- layout,
72
- verticalAlign,
73
- x,
74
- y,
75
- } = this.props
76
-
77
- new pbChart(`.${className}`, {
78
- align,
79
- axisTitle: axisTitle,
80
- chartData: chartData,
81
- colors: colors,
82
- dark,
83
- id: id,
84
- pointStart: pointStart,
85
- subtitle: subTitle,
86
- type,
87
- title: title,
88
- xAxisCategories: xAxisCategories,
89
- yAxisMin: yAxisMin,
90
- yAxisMax: yAxisMax,
91
- legend: legend,
92
- toggleLegendClick: toggleLegendClick,
93
- height: height,
94
- layout,
95
- verticalAlign,
96
- x,
97
- y,
98
- })
99
- }
100
-
101
- props: LineGraphProps
102
-
103
- render() {
104
- const { className, id } = this.props
105
-
106
- return (
107
- <div
108
- className={classnames(globalProps(this.props), className)}
109
- id={id}
110
- />
111
- )
112
- }
113
- }
@@ -1,79 +0,0 @@
1
- /* @flow */
2
-
3
- import React from 'react'
4
- import classnames from 'classnames'
5
-
6
- import { globalProps } from '../utilities/globalProps'
7
- import pbChart from '../plugins/pb_chart'
8
-
9
- type TreemapChartProps = {
10
- chartData: array<{
11
- name: string,
12
- parent?: string | number,
13
- value: number,
14
- color?: string,
15
- id?: string | number,
16
- }>,
17
- className?: string,
18
- colors: array,
19
- dark?: boolean,
20
- drillable: boolean,
21
- grouped: boolean,
22
- height?: string,
23
- id: number,
24
- title: string,
25
- tooltipHtml: string,
26
- type?: string,
27
- }
28
-
29
- export default class TreemapChart extends React.Component<TreemapChartProps> {
30
- static defaultProps = {
31
- className: 'pb_treemap_chart',
32
- dark: false,
33
- drillable: false,
34
- grouped: false,
35
- type: 'treemap',
36
- }
37
-
38
- componentDidMount() {
39
- const {
40
- chartData,
41
- className,
42
- colors = [],
43
- dark,
44
- drillable,
45
- grouped,
46
- height,
47
- id,
48
- title = "",
49
- tooltipHtml = '<span style="font-weight: bold; color:{point.color};">&#9679; </span>{point.name}: <b>{point.value}</b>',
50
- type,
51
- } = this.props
52
-
53
- new pbChart(`.${className}`, {
54
- chartData: chartData,
55
- colors: colors,
56
- dark,
57
- drillable,
58
- grouped,
59
- height: height,
60
- id: id,
61
- title: title,
62
- tooltipHtml,
63
- type,
64
- })
65
- }
66
-
67
- props: TreemapChartProps
68
-
69
- render() {
70
- const { className, id } = this.props
71
-
72
- return (
73
- <div
74
- className={classnames(globalProps(this.props), className)}
75
- id={id}
76
- />
77
- )
78
- }
79
- }
@@ -1,322 +0,0 @@
1
- import Highcharts from 'highcharts'
2
-
3
- import { highchartsTheme } from '../pb_dashboard/pbChartsLightTheme'
4
- import { highchartsDarkTheme } from '../pb_dashboard/pbChartsDarkTheme'
5
- import colors from '../tokens/exports/_colors.scss'
6
-
7
- import pie from 'highcharts/modules/variable-pie'
8
- import highchartsMore from 'highcharts/highcharts-more'
9
- import solidGauge from 'highcharts/modules/solid-gauge'
10
- import treemap from 'highcharts/modules/treemap'
11
-
12
- pie(Highcharts)
13
-
14
- // Map Data Color String Props to our SCSS Variables
15
-
16
- const mapColors = (array) => {
17
- const regex = /(data)\-[1-8]/ //eslint-disable-line
18
-
19
- const newArray = array.map((item) => {
20
- return regex.test(item)
21
- ? `${colors[`data_${item[item.length - 1]}`]}`
22
- : item
23
- })
24
- return newArray
25
- }
26
-
27
- // Adjust Circle Chart Block Kit Dimensions to Match the Chart for Centering
28
- const alignBlockElement = (event) => {
29
- const itemToMove = document.querySelector(`#wrapper-circle-chart-${event.target.renderTo.id} .pb-circle-chart-block`)
30
- const chartContainer = document.querySelector(`#${event.target.renderTo.id}`)
31
- if (itemToMove !== null) {
32
- itemToMove.style.height = `${event.target.chartHeight}px`
33
- itemToMove.style.width = `${event.target.chartWidth}px`;
34
- (chartContainer.firstChild).before(itemToMove)
35
- }
36
- }
37
-
38
- class pbChart {
39
- defaults = {
40
- callbackInitializeBefore: () => {},
41
- callbackInitializeAfter: () => {},
42
- callbackRefreshBefore: () => {},
43
- callbackRefreshAfter: () => {},
44
- callbackDestroyBefore: () => {},
45
- callbackDestroyAfter: () => {},
46
- property: 'Value',
47
- }
48
-
49
- extendDefaults(defaults, options) {
50
- for (const property in options) {
51
- if (Object.prototype.hasOwnProperty.call(options, property)) {
52
- defaults[property] = options[property]
53
- }
54
- }
55
- return defaults
56
- }
57
-
58
- constructor(element, options) {
59
- this.element = element
60
- this.options = options
61
- this.settings = this.extendDefaults(this.defaults, options)
62
-
63
- if (this.options.type == 'variablepie' || this.options.type == 'pie'){
64
- this.setupPieChart(options)
65
- } else if (this.options.type == 'gauge') {
66
- this.setupGauge(options)
67
- } else if (this.options.type == 'treemap') {
68
- this.setupTreemap(options)
69
- } else {
70
- this.setupChart(options)
71
- }
72
- }
73
-
74
- setupTheme() {
75
- this.options.dark ? Highcharts.setOptions(highchartsDarkTheme) : Highcharts.setOptions(highchartsTheme)
76
- }
77
-
78
- setupGauge(options) {
79
- highchartsMore(Highcharts)
80
- solidGauge(Highcharts)
81
- this.setupTheme()
82
-
83
- Highcharts.chart(this.defaults.id, {
84
- chart: {
85
- events: {
86
- load() {
87
- setTimeout(this.reflow.bind(this), 0)
88
- },
89
- },
90
- type: this.defaults.style,
91
- height: this.defaults.height,
92
- },
93
- title: {
94
- text: this.defaults.title,
95
- },
96
- yAxis: {
97
- min: this.defaults.min,
98
- max: this.defaults.max,
99
- lineWidth: 0,
100
- tickWidth: 0,
101
- minorTickInterval: null,
102
- tickAmount: 2,
103
- tickPositions: [this.defaults.min, this.defaults.max],
104
- labels: {
105
- y: 26,
106
- enabled: this.defaults.showLabels,
107
- },
108
- },
109
- credits: false,
110
- series: [
111
- {
112
- data: this.defaults.chartData,
113
- },
114
- ],
115
- pane: {
116
- center: ['50%', '50%'],
117
- size: '90%',
118
- startAngle: this.defaults.circumference[0],
119
- endAngle: this.defaults.circumference[1],
120
- background: {
121
- borderWidth: 20,
122
- innerRadius: '90%',
123
- outerRadius: '90%',
124
- shape: 'arc',
125
- className: 'gauge-pane',
126
- },
127
- },
128
- tooltip: {
129
- headerFormat: '',
130
- pointFormat: this.defaults.tooltipHtml,
131
- followPointer: true,
132
- },
133
- colors: options.colors !== undefined && options.colors.length > 0 ? mapColors(options.colors) : highchartsTheme.colors,
134
- plotOptions: {
135
- series: {
136
- animation: !this.defaults.disableAnimation,
137
- },
138
- solidgauge: {
139
- borderColor: options.colors !== undefined && options.colors.length === 1 ? mapColors(options.colors).join() : highchartsTheme.colors[0],
140
- dataLabels: {
141
- format: `<span class="prefix">${this.defaults.prefix}</span>` +
142
- '<span class="fix">{y:,f}</span>' +
143
- `<span class="suffix">${this.defaults.suffix}</span>`,
144
- } },
145
- },
146
- },
147
- )
148
- document.querySelectorAll('.gauge-pane').forEach((pane) => pane.setAttribute('stroke-linejoin', 'round'))
149
- if (document.querySelector('.prefix')) {
150
- document.querySelectorAll('.prefix').forEach((prefix) => prefix.setAttribute('y', '28'))
151
- document.querySelectorAll('.fix').forEach((fix) => fix.setAttribute('y', '38'))
152
- }
153
- }
154
-
155
- setupPieChart(options) {
156
- this.setupTheme()
157
- Highcharts.chart(this.defaults.id, {
158
- title: {
159
- text: this.defaults.title,
160
- },
161
- chart: {
162
- height: this.defaults.height,
163
- type: this.defaults.type,
164
- events: {
165
- render: (event) => alignBlockElement(event),
166
- redraw: (event) => alignBlockElement(event),
167
- },
168
- },
169
-
170
- legend: {
171
- align: this.defaults.align,
172
- verticalAlign: this.defaults.verticalAlign,
173
- layout: this.defaults.layout,
174
- x: this.defaults.x,
175
- y: this.defaults.y,
176
- },
177
-
178
- plotOptions: {
179
- pie: {
180
- colors: options.colors.length > 0 ? mapColors(options.colors) : highchartsTheme.colors,
181
- dataLabels: {
182
- enabled: this.defaults.dataLabels,
183
- connectorShape: 'straight',
184
- connectorWidth: 3,
185
- format: this.defaults.dataLabelHtml,
186
- },
187
- showInLegend: this.defaults.showInLegend,
188
- },
189
- },
190
-
191
- tooltip: {
192
- headerFormat: this.defaults.headerFormat,
193
- pointFormat: this.defaults.tooltipHtml,
194
- useHTML: this.defaults.useHTML,
195
- },
196
- series: [{
197
- minPointSize: this.defaults.minPointSize,
198
- maxPointSize: this.defaults.maxPointSize,
199
- innerSize: options.borderWidth == 20 ? '100%' : this.defaults.innerSize,
200
- data: this.defaults.chartData,
201
- zMin: this.defaults.zMin,
202
- startAngle: this.defaults.startAngle,
203
- borderWidth: this.defaults.borderWidth,
204
- borderColor: options.borderWidth == 20 ? null : this.defaults.innerSize,
205
- }],
206
- credits: false,
207
- })
208
- }
209
-
210
- setupTreemap(options) {
211
- treemap(Highcharts)
212
- this.setupTheme()
213
- options.dark ? Highcharts.setOptions(highchartsDarkTheme) : Highcharts.setOptions(highchartsTheme)
214
-
215
- Highcharts.chart(this.defaults.id, {
216
- title: {
217
- text: this.defaults.title,
218
- },
219
- chart: {
220
- height: this.defaults.height,
221
- type: this.defaults.type,
222
- },
223
- credits: false,
224
- series: [{
225
- data: this.defaults.chartData,
226
- }],
227
- plotOptions: {
228
- treemap: {
229
- allowTraversingTree: this.defaults.drillable,
230
- colorByPoint: !this.defaults.grouped,
231
- colors: options.colors !== undefined && options.colors.length > 0 ? mapColors(options.colors) : highchartsTheme.colors,
232
- },
233
- },
234
- tooltip: {
235
- pointFormat: this.defaults.tooltipHtml,
236
- useHTML: true,
237
- },
238
- })
239
- }
240
-
241
- setupChart(options) {
242
- this.setupTheme()
243
- const configOptions = {
244
- title: {
245
- text: this.defaults.title,
246
- },
247
- chart: {
248
- height: this.defaults.height,
249
- type: this.defaults.type,
250
- },
251
- subtitle: {
252
- text: this.defaults.subtitle,
253
- },
254
- yAxis: {
255
- min: this.defaults.yAxisMin,
256
- max: this.defaults.yAxisMax,
257
- title: {
258
- text: this.defaults.axisTitle,
259
- },
260
- },
261
- xAxis: {
262
- categories: this.defaults.xAxisCategories,
263
- },
264
- legend: {
265
- enabled: this.defaults.legend,
266
- align: this.defaults.align,
267
- verticalAlign: this.defaults.verticalAlign,
268
- layout: this.defaults.layout,
269
- x: this.defaults.x,
270
- y: this.defaults.y,
271
- },
272
- colors: options.colors !== undefined && options.colors.length > 0 ? mapColors(options.colors) : highchartsTheme.colors,
273
- plotOptions: {
274
- series: {
275
- pointStart: this.defaults.pointStart,
276
- dataLabels: {
277
- enabled: false,
278
- },
279
- },
280
- },
281
- series: this.defaults.chartData,
282
- credits: false,
283
- }
284
-
285
- if (!this.defaults.toggleLegendClick) {
286
- configOptions.plotOptions.series.events = { legendItemClick: () => false }
287
- }
288
-
289
- Highcharts.chart(this.defaults.id, configOptions)
290
- }
291
-
292
- refresh(silent = false) {
293
- if (!silent) {
294
- this.settings.callbackRefreshBefore.call()
295
- }
296
-
297
- this.this.destroy(silent)
298
- this.this.initialize(silent)
299
- if (!silent) {
300
- this.settings.callbackRefreshAfter.call()
301
- }
302
- }
303
-
304
- destroy(silent = false) {
305
- if (!silent) {
306
- this.settings.callbackDestroyBefore.call()
307
- }
308
- if (!silent) {
309
- this.settings.callbackDestroyAfter.call()
310
- }
311
- }
312
-
313
- refreshSilently() {
314
- this.this.refresh(true)
315
- }
316
-
317
- destroySilently() {
318
- this.this.destroy(true)
319
- }
320
- }
321
-
322
- export default pbChart