@scality/core-ui 0.166.0 → 0.167.0

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.
Files changed (104) hide show
  1. package/.storybook/preview.js +6 -4
  2. package/README.md +27 -80
  3. package/dist/components/barchart/BarChart.component.d.ts +5 -0
  4. package/dist/components/barchart/BarChart.component.d.ts.map +1 -1
  5. package/dist/components/barchart/BarChart.component.js +5 -0
  6. package/dist/components/button/Button.component.d.ts +2 -1
  7. package/dist/components/button/Button.component.d.ts.map +1 -1
  8. package/dist/components/button/Button.component.js +2 -1
  9. package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -1
  10. package/dist/components/chartlegend/ChartLegend.js +7 -13
  11. package/dist/components/chartlegend/ChartLegendWrapper.d.ts +1 -2
  12. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -1
  13. package/dist/components/chartlegend/ChartLegendWrapper.js +4 -9
  14. package/dist/components/icon/Icon.component.d.ts +9 -11
  15. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  16. package/dist/components/icon/Icon.component.js +2 -0
  17. package/dist/components/linetemporalchart/ChartUtil.d.ts +3 -2
  18. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +1 -1
  19. package/dist/components/linetemporalchart/ChartUtil.js +24 -20
  20. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +4 -0
  21. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +1 -1
  22. package/dist/components/linetemporalchart/LineTemporalChart.component.js +4 -0
  23. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +1 -1
  24. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
  25. package/dist/index.d.ts +1 -11
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +0 -11
  28. package/dist/next.d.ts +1 -0
  29. package/dist/next.d.ts.map +1 -1
  30. package/jest.config.js +1 -0
  31. package/package.json +16 -37
  32. package/src/lib/components/barchart/BarChart.component.tsx +5 -0
  33. package/src/lib/components/button/Button.component.tsx +2 -1
  34. package/src/lib/components/chartlegend/ChartLegend.test.tsx +17 -0
  35. package/src/lib/components/chartlegend/ChartLegend.tsx +6 -12
  36. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +5 -13
  37. package/src/lib/components/icon/Icon.component.tsx +12 -1
  38. package/src/lib/components/linetemporalchart/ChartUtil.test.ts +23 -35
  39. package/src/lib/components/linetemporalchart/ChartUtil.ts +32 -26
  40. package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +19 -15
  41. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +5 -5
  42. package/src/lib/components/selectv2/selectv2.test.tsx +1 -1
  43. package/src/lib/components/toast/useMutationsHandler.test.tsx +22 -32
  44. package/src/lib/index.ts +6 -11
  45. package/src/lib/next.ts +1 -0
  46. package/stories/barchart.stories.tsx +1 -1
  47. package/stories/card.stories.tsx +7 -5
  48. package/stories/controls.ts +19 -20
  49. package/stories/linecharttemporal.stories.tsx +1 -1
  50. package/stories/linetimeseriechart.stories.tsx +49 -0
  51. package/stories/navbar.stories.tsx +103 -0
  52. package/stories/tabsv2.stories.tsx +51 -56
  53. package/dist/components/areachart/AreaChart.component.d.ts +0 -13
  54. package/dist/components/areachart/AreaChart.component.d.ts.map +0 -1
  55. package/dist/components/areachart/AreaChart.component.js +0 -27
  56. package/dist/components/chips/Chips.component.d.ts +0 -21
  57. package/dist/components/chips/Chips.component.d.ts.map +0 -1
  58. package/dist/components/chips/Chips.component.js +0 -105
  59. package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts +0 -10
  60. package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts.map +0 -1
  61. package/dist/components/cloudprogressbar/CloudProgressBar.component.js +0 -38
  62. package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts +0 -9
  63. package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts.map +0 -1
  64. package/dist/components/collapsiblepanel/CollapsiblePanel.component.js +0 -44
  65. package/dist/components/linechart/LineChart.component.d.ts +0 -21
  66. package/dist/components/linechart/LineChart.component.d.ts.map +0 -1
  67. package/dist/components/linechart/LineChart.component.js +0 -109
  68. package/dist/components/multiselect/MultiSelect.component.d.ts +0 -28
  69. package/dist/components/multiselect/MultiSelect.component.d.ts.map +0 -1
  70. package/dist/components/multiselect/MultiSelect.component.js +0 -73
  71. package/dist/components/select/Select.component.d.ts +0 -14
  72. package/dist/components/select/Select.component.d.ts.map +0 -1
  73. package/dist/components/select/Select.component.js +0 -71
  74. package/dist/components/spacedbox/SpacedBox.d.ts +0 -34
  75. package/dist/components/spacedbox/SpacedBox.d.ts.map +0 -1
  76. package/dist/components/spacedbox/SpacedBox.js +0 -64
  77. package/dist/components/sparkline/SparkLine.component.d.ts +0 -18
  78. package/dist/components/sparkline/SparkLine.component.d.ts.map +0 -1
  79. package/dist/components/sparkline/SparkLine.component.js +0 -148
  80. package/dist/components/vegachart/VegaChart.component.d.ts +0 -13
  81. package/dist/components/vegachart/VegaChart.component.d.ts.map +0 -1
  82. package/dist/components/vegachart/VegaChart.component.js +0 -120
  83. package/plopfile.js +0 -38
  84. package/src/lib/components/areachart/AreaChart.component.tsx +0 -49
  85. package/src/lib/components/chips/Chips.component.tsx +0 -169
  86. package/src/lib/components/cloudprogressbar/CloudProgressBar.component.tsx +0 -105
  87. package/src/lib/components/collapsiblepanel/CollapsiblePanel.component.tsx +0 -77
  88. package/src/lib/components/linechart/LineChart.component.tsx +0 -152
  89. package/src/lib/components/multiselect/MultiSelect.component.tsx +0 -158
  90. package/src/lib/components/select/Select.component.tsx +0 -98
  91. package/src/lib/components/spacedbox/SpacedBox.ts +0 -116
  92. package/src/lib/components/sparkline/SparkLine.component.tsx +0 -176
  93. package/src/lib/components/vegachart/VegaChart.component.tsx +0 -146
  94. package/stories/areachart.stories.tsx +0 -120
  95. package/stories/chips.stories.tsx +0 -107
  96. package/stories/cloudprogressbar.stories.tsx +0 -93
  97. package/stories/collapsiblepanel.stories.tsx +0 -57
  98. package/stories/data/areachart.ts +0 -122
  99. package/stories/data/sparklinechart.ts +0 -164
  100. package/stories/linechart.stories.tsx +0 -319
  101. package/stories/multiselect.stories.tsx +0 -126
  102. package/stories/select.stories.tsx +0 -52
  103. package/stories/sparkline.stories.tsx +0 -85
  104. package/stories/vegachart.stories.tsx +0 -98
@@ -1,64 +0,0 @@
1
- import styled from 'styled-components';
2
- import { spacing } from '../../style/theme';
3
- const validValue = [0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32];
4
- const createSpacingFn = (propsName, spacingFields) => (props) => {
5
- if (!props[propsName] && props[propsName] !== 0) {
6
- return null;
7
- }
8
- //@ts-ignore -- this is ensured below
9
- let value = props[propsName];
10
- if (!validValue.includes(value)) {
11
- console.warn(`'${propsName}' props should be a number in this list: ` +
12
- '0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32');
13
- return null;
14
- }
15
- const result = spacingFields
16
- .map((param) => `${param}: ${spacing[`sp${value}`]}`)
17
- .join(';');
18
- return result;
19
- };
20
- const m = createSpacingFn('m', ['margin']);
21
- const mt = createSpacingFn('mt', ['margin-top']);
22
- const mr = createSpacingFn('mr', ['margin-right']);
23
- const mb = createSpacingFn('mb', ['margin-bottom']);
24
- const ml = createSpacingFn('ml', ['margin-left']);
25
- const mx = createSpacingFn('mx', ['margin-left', 'margin-right']);
26
- const my = createSpacingFn('my', ['margin-top', 'margin-bottom']);
27
- const p = createSpacingFn('p', ['padding']);
28
- const pt = createSpacingFn('pt', ['padding-top']);
29
- const pr = createSpacingFn('pr', ['padding-right']);
30
- const pb = createSpacingFn('pb', ['padding-bottom']);
31
- const pl = createSpacingFn('pl', ['padding-left']);
32
- const px = createSpacingFn('px', ['padding-left', 'padding-right']);
33
- const py = createSpacingFn('py', ['padding-top', 'padding-bottom']);
34
- /**
35
- * @deprecated
36
- * Please use Box with import { Box } from '@scality/core-ui/dist/next';
37
- *
38
- * Most common use cases:
39
- *
40
- * `<SpacedBox m={14}><Component /></SpacedBox>`
41
- *
42
- * `<SpacedBox as={SpanComponent}><Component /></SpacedBox>`
43
- *
44
- * Props : m, mt, mr, mb, ml, mx, my, p, pt, pr, pb, pl, px, py
45
- *
46
- * Values: 0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32
47
- */
48
- const SpacedBox = styled.div `
49
- ${m};
50
- ${mt};
51
- ${mr};
52
- ${mb};
53
- ${ml};
54
- ${mx};
55
- ${my};
56
- ${p};
57
- ${pt};
58
- ${pr};
59
- ${pb};
60
- ${pl};
61
- ${px};
62
- ${py};
63
- `;
64
- export { SpacedBox };
@@ -1,18 +0,0 @@
1
- type Props = {
2
- id: string;
3
- title?: string;
4
- width?: number;
5
- height?: number;
6
- data: Array<Record<string, any>>;
7
- xAxis: Record<string, any>;
8
- yAxis: Record<string, any>;
9
- row: Record<string, any>;
10
- lineConfig?: Record<string, any>;
11
- sparkLineColor?: string;
12
- upTrendColor?: string;
13
- bottomTrendColor?: string;
14
- };
15
- declare function SparkLine({ id, title, width, height, data, xAxis, yAxis, row, lineConfig, sparkLineColor, upTrendColor, bottomTrendColor, }: Props): import("react/jsx-runtime").JSX.Element;
16
- export declare const Sparkline: typeof SparkLine;
17
- export {};
18
- //# sourceMappingURL=SparkLine.component.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SparkLine.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/sparkline/SparkLine.component.tsx"],"names":[],"mappings":"AAEA,KAAK,KAAK,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,iBAAS,SAAS,CAAC,EACjB,EAAE,EACF,KAAK,EACL,KAAW,EACX,MAAW,EACX,IAAI,EACJ,KAAK,EACL,KAAK,EACL,GAAG,EACH,UAAU,EACV,cAAc,EACd,YAA2B,EAC3B,gBAAwB,GACzB,EAAE,KAAK,2CA+IP;AAED,eAAO,MAAM,SAAS,kBAAY,CAAC"}
@@ -1,148 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { VegaChart } from '../vegachart/VegaChart.component';
3
- import { yellowOrange, green } from '../../style/theme';
4
- function SparkLine({ id, title, width = 300, height = 80, data, xAxis, yAxis, row, lineConfig, sparkLineColor, upTrendColor = yellowOrange, bottomTrendColor = green, }) {
5
- const spec = {
6
- title: {
7
- text: title,
8
- },
9
- data: {
10
- values: data,
11
- },
12
- facet: {
13
- row,
14
- },
15
- spec: {
16
- width,
17
- height,
18
- layer: [
19
- // display the sparkline chart
20
- {
21
- mark: {
22
- type: 'line',
23
- ...lineConfig,
24
- },
25
- encoding: {
26
- x: xAxis,
27
- y: yAxis,
28
- color: {
29
- value: sparkLineColor,
30
- },
31
- },
32
- }, // display the label to specify the max/min data
33
- {
34
- mark: {
35
- type: 'text',
36
- style: 'labelMin',
37
- align: 'bottom',
38
- dy: height / 2,
39
- dx: width / 2 + 10,
40
- },
41
- encoding: {
42
- text: {
43
- aggregate: 'min',
44
- field: 'y',
45
- type: 'quantitative',
46
- },
47
- },
48
- },
49
- {
50
- mark: {
51
- type: 'text',
52
- style: 'labelMax',
53
- align: 'top',
54
- dy: -(height / 2),
55
- dx: width / 2 + 10,
56
- },
57
- encoding: {
58
- text: {
59
- aggregate: 'max',
60
- field: 'y',
61
- type: 'quantitative',
62
- },
63
- },
64
- }, // display the up and bottom trend line
65
- {
66
- mark: {
67
- type: 'rule',
68
- style: 'ruleMaxEnd',
69
- color: upTrendColor,
70
- },
71
- encoding: {
72
- y: {
73
- aggregate: 'max',
74
- field: 'y',
75
- type: 'quantitative',
76
- },
77
- x: {
78
- value: width - 15,
79
- },
80
- x2: {
81
- value: width,
82
- },
83
- },
84
- },
85
- {
86
- mark: {
87
- type: 'rule',
88
- style: 'ruleMaxStart',
89
- color: upTrendColor,
90
- opacity: 0.1,
91
- },
92
- encoding: {
93
- y: {
94
- aggregate: 'max',
95
- field: 'y',
96
- type: 'quantitative',
97
- },
98
- x: {
99
- value: 0,
100
- },
101
- x2: {
102
- value: width - 15,
103
- },
104
- },
105
- },
106
- {
107
- mark: {
108
- type: 'rule',
109
- style: 'ruleMinEnd',
110
- color: bottomTrendColor,
111
- },
112
- encoding: {
113
- y: {
114
- value: height,
115
- },
116
- x: {
117
- value: width - 15,
118
- },
119
- x2: {
120
- value: width,
121
- },
122
- },
123
- },
124
- {
125
- mark: {
126
- type: 'rule',
127
- style: 'ruleMinStart',
128
- color: bottomTrendColor,
129
- opacity: 0.1,
130
- },
131
- encoding: {
132
- y: {
133
- value: height,
134
- },
135
- x: {
136
- value: 0,
137
- },
138
- x2: {
139
- value: width - 15,
140
- },
141
- },
142
- },
143
- ],
144
- },
145
- };
146
- return _jsx(VegaChart, { className: "sc-sparkline", id: id, spec: spec });
147
- }
148
- export const Sparkline = SparkLine;
@@ -1,13 +0,0 @@
1
- export declare const TOP = "top";
2
- export declare const BOTTOM = "bottom";
3
- type Position = typeof TOP | typeof BOTTOM;
4
- type Props = {
5
- id: string;
6
- spec: Record<string, any>;
7
- tooltipPosition?: Position;
8
- theme?: 'light' | 'dark' | 'custom';
9
- className?: string;
10
- };
11
- declare function VegaChart({ id, spec, tooltipPosition, theme, }: Props): import("react/jsx-runtime").JSX.Element;
12
- export { VegaChart };
13
- //# sourceMappingURL=VegaChart.component.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VegaChart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/vegachart/VegaChart.component.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,KAAK,QAAQ,GAAG,OAAO,GAAG,GAAG,OAAO,MAAM,CAAC;AAC3C,KAAK,KAAK,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA0BF,iBAAS,SAAS,CAAC,EACjB,EAAE,EACF,IAAI,EACJ,eAAwB,EACxB,KAAgB,GACjB,EAAE,KAAK,2CAkGP;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,120 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- // @ts-nocheck
3
- import { useEffect, useContext, useRef } from 'react';
4
- import vegaEmbed from 'vega-embed';
5
- import { ThemeContext, createGlobalStyle } from 'styled-components';
6
- import { getThemePropSelector } from '../../utils';
7
- export const TOP = 'top';
8
- export const BOTTOM = 'bottom';
9
- /* How to theme tooltip:
10
- https://github.com/vega/vega-tooltip/blob/master/docs/customizing_your_tooltip.md
11
- */
12
- const VegaTooltipTheme = createGlobalStyle `
13
- #vg-tooltip-element.vg-tooltip.custom-theme {
14
- padding: 8px;
15
- position: fixed;
16
- z-index: 1000;
17
- font-family: 'Lato';
18
- font-size: 12px;
19
- border-radius: 3px;
20
- box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
21
- color: ${getThemePropSelector('textPrimary')};
22
- background-color: ${getThemePropSelector('backgroundLevel1')};
23
- border: 1px solid ${getThemePropSelector('border')};
24
- // customize the title
25
- h2 {
26
- color: ${getThemePropSelector('textSecondary')};
27
- margin-bottom: 10px;
28
- font-size: 12px;
29
- }
30
- }
31
- `;
32
- function VegaChart({ id, spec, tooltipPosition = BOTTOM, theme = 'custom', }) {
33
- const themeContext = useContext(ThemeContext);
34
- const currentBackgroundColor = themeContext && themeContext.brand
35
- ? themeContext.brand.backgroundLevel4
36
- : themeContext.backgroundLevel4;
37
- // the background color of the view
38
- const currentBackgroundColor2 = themeContext && themeContext.brand
39
- ? themeContext.brand.backgroundLevel1
40
- : themeContext.backgroundLevel1;
41
- const brandText = themeContext && themeContext.brand
42
- ? themeContext.brand.textPrimary
43
- : themeContext.textPrimary;
44
- const themeConfig = {
45
- config: {
46
- background: currentBackgroundColor,
47
- axis: {
48
- labelColor: brandText,
49
- titleColor: brandText,
50
- grid: false,
51
- domainColor: currentBackgroundColor2,
52
- },
53
- title: {
54
- color: brandText,
55
- font: 'Lato',
56
- },
57
- view: {
58
- stroke: 'transparent',
59
- fill: currentBackgroundColor2,
60
- },
61
- // the headers provide a title and labels for faceted plots.
62
- header: {
63
- labelColor: brandText,
64
- },
65
- // the label of max/min
66
- text: {
67
- color: brandText,
68
- font: 'Lato',
69
- },
70
- // the up, bottom trend line and verticle line when hover
71
- rule: {
72
- color: brandText,
73
- },
74
- legend: {
75
- labelColor: brandText,
76
- titleColor: brandText,
77
- },
78
- },
79
- };
80
- const themedSpec = { ...spec, ...themeConfig };
81
- const vegaInstance = useRef();
82
- let tooltipOptions = {
83
- theme: theme,
84
- };
85
- if (tooltipPosition === TOP) {
86
- tooltipOptions = {
87
- theme: theme,
88
- offsetX: -85,
89
- offsetY: -140,
90
- };
91
- }
92
- useEffect(() => {
93
- let isMounted = true;
94
- vegaEmbed(`#${id}`, themedSpec, {
95
- renderer: 'svg',
96
- // Override the DEFAULT_OPTIONS https://github.com/vega/vega-tooltip/blob/master/src/defaults.ts
97
- tooltip: tooltipOptions,
98
- /* Determines if action links
99
- ("Export as PNG/SVG", "View Source", "View Vega" (only for Vega-Lite), "Open in Vega Editor") are included with the embedded view.
100
- If the value is true, all action links will be shown and none if the value is false. */
101
- actions: false,
102
- })
103
- .then((result) => {
104
- vegaInstance.current = result; // result.view contains the Vega view
105
- })
106
- .catch((...args) => {
107
- if (isMounted) {
108
- console.error(...args); // TODO: we should handle this with a retry or an error state of the component
109
- }
110
- });
111
- return () => {
112
- isMounted = false;
113
- if (vegaInstance.current) {
114
- vegaInstance.current.view.finalize();
115
- }
116
- };
117
- }, [id, themedSpec, tooltipOptions, vegaInstance]);
118
- return (_jsx("div", { id: id, className: "sc-vegachart", children: _jsx(VegaTooltipTheme, {}) }));
119
- }
120
- export { VegaChart };
package/plopfile.js DELETED
@@ -1,38 +0,0 @@
1
- module.exports = function (plop) {
2
- plop.addHelper('lowerCase', (text) => text.toLowerCase());
3
- plop.addHelper('properCase', (text) =>
4
- text.replace(/\w\S*/g, function (txt) {
5
- return txt.charAt(0).toUpperCase() + txt.substr(1);
6
- }),
7
- );
8
-
9
- plop.setGenerator('component', {
10
- description: 'Add a react component',
11
- prompts: [
12
- {
13
- type: 'input',
14
- name: 'name',
15
- message: 'Component name please (ex: layout, breadcrumbs, menuItem)!',
16
- },
17
- ],
18
- actions: [
19
- {
20
- type: 'add',
21
- path:
22
- 'src/lib/components/{{lowerCase name}}/{{properCase name}}.component.js',
23
- templateFile: 'plop-templates/component.hbs',
24
- },
25
- {
26
- type: 'add',
27
- path:
28
- 'src/lib/components/{{lowerCase name}}/{{properCase name}}.component.test.js',
29
- templateFile: 'plop-templates/component.test.hbs',
30
- },
31
- {
32
- type: 'add',
33
- path: 'stories/{{lowerCase name}}.stories.js',
34
- templateFile: 'plop-templates/stories.hbs',
35
- },
36
- ],
37
- });
38
- };
@@ -1,49 +0,0 @@
1
- import { VegaChart } from '../vegachart/VegaChart.component';
2
-
3
- type Props = {
4
- id: string;
5
- data: Array<Record<string, any>>;
6
- xAxis: Record<string, any>;
7
- yAxis: Array<Record<string, any>>;
8
- color?: Record<string, any>;
9
- areas: Array<Record<string, any>>;
10
- width?: number;
11
- height?: number;
12
- };
13
-
14
- function AreaChart({
15
- id,
16
- data,
17
- xAxis,
18
- yAxis,
19
- color,
20
- height = 300,
21
- width = 1000,
22
- areas = [],
23
- ...rest
24
- }: Props) {
25
- const lines = yAxis.map((y) => ({
26
- mark: {
27
- type: 'line',
28
- },
29
- encoding: {
30
- y,
31
- },
32
- }));
33
- const spec = {
34
- data: {
35
- values: data,
36
- },
37
- encoding: {
38
- x: xAxis,
39
- color,
40
- },
41
- layer: [...lines, ...areas],
42
- height,
43
- width,
44
- ...rest,
45
- };
46
- return <VegaChart className="sc-areachart" id={id} spec={spec}></VegaChart>;
47
- }
48
-
49
- export { AreaChart };
@@ -1,169 +0,0 @@
1
- import { lighten } from 'polished';
2
- import styled, { css } from 'styled-components';
3
- import { fontSize, grayLight, white } from '../../style/theme';
4
- import { Button } from '../button/Button.component';
5
- import { Size } from '../constants';
6
-
7
- import { Icon } from '../icon/Icon.component';
8
- type Props = {
9
- text: string;
10
- variant?:
11
- | 'statusHealthy'
12
- | 'statusWarning'
13
- | 'statusCritical'
14
- | 'infoPrimary'
15
- | 'infoSecondary';
16
- icon?: JSX.Element;
17
- onClick?: (arg0: any) => void;
18
- onRemove?: (arg0: any) => void;
19
- size?: Size;
20
- };
21
- const ChipsContainer = styled.div<{
22
- size?: string;
23
- variant?: any;
24
- icon?: JSX.Element;
25
- }>`
26
- display: inline-flex;
27
- .sc-chips-remove {
28
- padding-right: 10px;
29
- color: ${white};
30
- &:hover {
31
- color: ${grayLight};
32
- }
33
- }
34
- ${(props) => {
35
- switch (props.size) {
36
- case 'smaller':
37
- return css`
38
- border-radius: 10px;
39
- .sc-chips-icon {
40
- border-radius: 10px;
41
- padding: 5px;
42
- }
43
- `;
44
-
45
- case 'small':
46
- return css`
47
- border-radius: 12px;
48
- .sc-chips-icon {
49
- border-radius: 12px;
50
- padding: 6px;
51
- }
52
- `;
53
-
54
- case 'large':
55
- return css`
56
- border-radius: 14px;
57
- .sc-chips-icon {
58
- border-radius: 14px;
59
- padding: 6px;
60
- }
61
- `;
62
-
63
- case 'larger':
64
- return css`
65
- border-radius: 17px;
66
- .sc-chips-icon {
67
- border-radius: 17px;
68
- padding: 7px;
69
- }
70
- `;
71
-
72
- default:
73
- return css`
74
- border-radius: 12px;
75
- .sc-chips-icon {
76
- border-radius: 12px;
77
- padding: 6px;
78
- }
79
- `;
80
- }
81
- }}
82
- ${(props) => {
83
- const brand = props.theme;
84
- return css`
85
- color: ${brand.textReverse};
86
- `;
87
- }}
88
-
89
- ${(props) => {
90
- const brand = props.theme;
91
- const brandLight = lighten(0.1, brand[props.variant]).toString();
92
- return props.onClick
93
- ? css`
94
- background-color: ${brand[props.variant]};
95
- font-size: ${fontSize[props.size || 'base']};
96
- &:hover {
97
- cursor: pointer;
98
- background-color: ${brandLight};
99
- }
100
- &:active {
101
- background-color: ${brand[props.variant]};
102
- }
103
- `
104
- : css`
105
- background-color: ${brand[props.variant]};
106
- font-size: ${fontSize[props.size || 'base']};
107
- `;
108
- }}
109
- `;
110
- export const ChipsIcon = styled.span<{
111
- variant: any;
112
- text: string;
113
- size: Size;
114
- }>`
115
- display: inline-flex;
116
- justify-content: center;
117
- align-items: center;
118
- background-color: ${(props) =>
119
- lighten(0.15, props.theme[props.variant]).toString()};
120
- `;
121
- export const ChipsText = styled.span<{ icon: any; isRemovable: boolean }>`
122
- display: inline-flex;
123
- justify-content: center;
124
- align-items: center;
125
- padding: ${(props) => (props.icon || props.isRemovable ? '5px' : '5px 10px')};
126
- `;
127
-
128
- const Chips = ({
129
- text = '',
130
- variant = 'infoPrimary',
131
- icon = undefined,
132
- onClick,
133
- onRemove,
134
- size = 'base',
135
- }: Props) => (
136
- <ChipsContainer
137
- className="sc-chips"
138
- onClick={onClick}
139
- variant={variant}
140
- icon={icon}
141
- size={size}
142
- >
143
- {icon && (
144
- <ChipsIcon
145
- className="sc-chips-icon"
146
- text={text}
147
- variant={variant}
148
- size={size}
149
- >
150
- {icon}
151
- </ChipsIcon>
152
- )}
153
- <ChipsText className="sc-chips-text" icon={icon} isRemovable={!!onRemove}>
154
- {text}
155
- </ChipsText>
156
- {onRemove && (
157
- <Button
158
- // @ts-ignore
159
- className="sc-chips-remove"
160
- size={size}
161
- inverted={true}
162
- icon={<Icon name="Close" />}
163
- onClick={onRemove}
164
- />
165
- )}
166
- </ChipsContainer>
167
- );
168
-
169
- export { Chips };