playbook_ui 11.16.0.pre.alpha.pagination.rails1 → 11.16.0

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 +0 -2
  3. data/app/pb_kits/playbook/data/menu.yml +0 -1
  4. data/app/pb_kits/playbook/index.js +1 -3
  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_treemap_chart/_treemap_chart.tsx +111 -0
  22. data/app/pb_kits/playbook/pb_treemap_chart/docs/_treemap_chart_tooltip.jsx +1 -1
  23. data/app/pb_kits/playbook/playbook-doc.js +0 -2
  24. data/app/pb_kits/playbook/playbook-rails-react-bindings.js +4 -0
  25. data/app/pb_kits/playbook/playbook-rails.js +0 -4
  26. data/lib/playbook/kit_base.rb +0 -2
  27. data/lib/playbook/version.rb +1 -1
  28. data/lib/playbook.rb +0 -1
  29. metadata +14 -36
  30. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.jsx +0 -111
  31. data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.jsx +0 -151
  32. data/app/pb_kits/playbook/pb_gauge/_gauge.jsx +0 -112
  33. data/app/pb_kits/playbook/pb_line_graph/_line_graph.jsx +0 -113
  34. data/app/pb_kits/playbook/pb_pagination/_pagination.scss +0 -68
  35. data/app/pb_kits/playbook/pb_pagination/_pagination.tsx +0 -41
  36. data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.html.erb +0 -28
  37. data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.jsx +0 -12
  38. data/app/pb_kits/playbook/pb_pagination/docs/example.yml +0 -9
  39. data/app/pb_kits/playbook/pb_pagination/docs/index.js +0 -1
  40. data/app/pb_kits/playbook/pb_pagination/pagination.html.erb +0 -7
  41. data/app/pb_kits/playbook/pb_pagination/pagination.rb +0 -14
  42. data/app/pb_kits/playbook/pb_pagination/pagination.test.jsx +0 -17
  43. data/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.jsx +0 -79
  44. data/app/pb_kits/playbook/plugins/pb_chart.js +0 -322
  45. data/lib/playbook/pagination_renderer.rb +0 -43
@@ -1,41 +0,0 @@
1
-
2
-
3
- /* @flow */
4
-
5
- import React from 'react'
6
- import classnames from 'classnames'
7
- import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
8
- import { globalProps } from '../utilities/globalProps'
9
-
10
- type PaginationProps = {
11
- aria?: { [key: string]: string },
12
- className?: string,
13
- data?: { [key: string]: string },
14
- id?: string,
15
- }
16
-
17
- const Pagination = (props: PaginationProps) => {
18
- const {
19
- aria = {},
20
- className,
21
- data = {},
22
- id,
23
- } = props
24
-
25
- const ariaProps = buildAriaProps(aria)
26
- const dataProps = buildDataProps(data)
27
- const classes = classnames(buildCss('pb_pagination'), globalProps(props), className)
28
-
29
- return (
30
- <div
31
- {...ariaProps}
32
- {...dataProps}
33
- className={classes}
34
- id={id}
35
- >
36
- {className}
37
- </div>
38
- )
39
- }
40
-
41
- export default Pagination
@@ -1,28 +0,0 @@
1
- <% @data = [{
2
- first_name: 'Jon',
3
- last_name: 'Ron',
4
- email: "jon@mail.com",
5
- id: 1,
6
- }, {
7
- first_name: 'Sam',
8
- last_name: 'Bob',
9
- email: "sam@mail.com",
10
- id: 2,
11
- }, {
12
- first_name: 'Nick',
13
- last_name: 'Jack',
14
- email: "nick@mail.com",
15
- id: 3,
16
- }, {
17
- first_name: 'Jake',
18
- last_name: 'Wade',
19
- email: "jon@mail.com",
20
- id: 4,
21
- }, {
22
- first_name: 'Blake',
23
- last_name: 'Chad',
24
- email: "jon@mail.com",
25
- id: 5,
26
- }] %>
27
-
28
- <%= pb_rails("pagination", props: { data: @data}) %>
@@ -1,12 +0,0 @@
1
- import React from 'react'
2
- import Pagination from '../_pagination'
3
-
4
- const PaginationDefault = (props) => (
5
- <div>
6
- <Pagination
7
- {...props}
8
- />
9
- </div>
10
- )
11
-
12
- export default PaginationDefault
@@ -1,9 +0,0 @@
1
- examples:
2
-
3
- rails:
4
- - pagination_default: Default
5
-
6
-
7
- # react:
8
- # - pagination_default: Default
9
-
@@ -1 +0,0 @@
1
- export { default as PaginationDefault } from './_pagination_default.jsx'
@@ -1,7 +0,0 @@
1
- <%= content_tag(:div,
2
- aria: object.aria,
3
- class: object.classname,
4
- data: object.data,
5
- id: object.id) do %>
6
- <%= will_paginate object.page_data, renderer: Playbook::Pagination::Rails %>
7
- <% end %>
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "will_paginate/array"
4
- module Playbook
5
- module PbPagination
6
- class Pagination < ::Playbook::KitBase
7
- prop :data, type: Playbook::Props::Array,
8
- default: []
9
- def page_data
10
- data.paginate(page: params[:page], per_page: 1)
11
- end
12
- end
13
- end
14
- end
@@ -1,17 +0,0 @@
1
- import { renderKit } from '../utilities/test-utils'
2
-
3
- import { Pagination } from '../'
4
-
5
- /* See these resources for more testing info:
6
- - https://github.com/testing-library/jest-dom#usage for useage and examples
7
- - https://jestjs.io/docs/en/using-matchers
8
- */
9
-
10
- test('generated scaffold test - update me', () => {
11
- const props = {
12
- data: { testid: 'default' }
13
- }
14
-
15
- const kit = renderKit(Pagination , props)
16
- expect(kit).toBeInTheDocument()
17
- })
@@ -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
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "will_paginate/view_helpers/action_view"
4
-
5
- module Playbook
6
- module Pagination
7
- class Rails < WillPaginate::ActionView::LinkRenderer
8
- def container_attributes
9
- { class: "pb_pagination pagination" }
10
- end
11
-
12
- def page_number(page)
13
- if page == current_page
14
- tag("li", tag("span", page), class: "active")
15
- else
16
- tag("li", link(page, page, rel: rel_value(page)))
17
- end
18
- end
19
-
20
- def previous_or_next_page(page, text, classname)
21
- if page
22
- tag("li", link(text, page), class: classname)
23
- else
24
- tag("li", tag("span", text), class: "%s disabled")
25
- end
26
- end
27
-
28
- def gap
29
- tag("li", tag("span", "&hellip;"), class: "disabled")
30
- end
31
-
32
- def previous_page
33
- num = @collection.current_page > 1 && @collection.current_page - 1
34
- previous_or_next_page(num, "<i class='far fa-chevron-left fa-xs'></i>", "prev")
35
- end
36
-
37
- def next_page
38
- num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
39
- previous_or_next_page(num, "<i class='far fa-chevron-right fa-xs'></i>", "next")
40
- end
41
- end
42
- end
43
- end