@scality/core-ui 0.161.0 → 0.162.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 (136) hide show
  1. package/README.md +15 -15
  2. package/dist/components/accordion/Accordion.component.d.ts +0 -1
  3. package/dist/components/accordion/Accordion.component.d.ts.map +1 -1
  4. package/dist/components/barchartv2/Barchart.component.d.ts +55 -0
  5. package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -0
  6. package/dist/components/barchartv2/Barchart.component.js +76 -0
  7. package/dist/components/barchartv2/utils.d.ts +95 -0
  8. package/dist/components/barchartv2/utils.d.ts.map +1 -0
  9. package/dist/components/barchartv2/utils.js +305 -0
  10. package/dist/components/buttonv2/Buttonv2.component.d.ts +1 -1
  11. package/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -1
  12. package/dist/components/constrainedtext/Constrainedtext.component.d.ts +2 -1
  13. package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -1
  14. package/dist/components/constrainedtext/Constrainedtext.component.js +5 -4
  15. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts +0 -1
  16. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts.map +1 -1
  17. package/dist/components/date/FormattedDateTime.d.ts +1 -0
  18. package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
  19. package/dist/components/date/FormattedDateTime.js +5 -0
  20. package/dist/components/emptytable/Emptytable.component.d.ts +0 -1
  21. package/dist/components/emptytable/Emptytable.component.d.ts.map +1 -1
  22. package/dist/components/emptytable/Emptytable.component.js +1 -0
  23. package/dist/components/error-pages/ErrorPage401.component.d.ts +0 -1
  24. package/dist/components/error-pages/ErrorPage401.component.d.ts.map +1 -1
  25. package/dist/components/error-pages/ErrorPage404.component.d.ts +0 -1
  26. package/dist/components/error-pages/ErrorPage404.component.d.ts.map +1 -1
  27. package/dist/components/error-pages/ErrorPage500.component.d.ts +0 -1
  28. package/dist/components/error-pages/ErrorPage500.component.d.ts.map +1 -1
  29. package/dist/components/error-pages/ErrorPageAuth.component.d.ts.map +1 -1
  30. package/dist/components/form/Form.component.d.ts +2 -2
  31. package/dist/components/form/Form.component.d.ts.map +1 -1
  32. package/dist/components/infomessage/InfoMessage.component.d.ts +0 -1
  33. package/dist/components/infomessage/InfoMessage.component.d.ts.map +1 -1
  34. package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts.map +1 -1
  35. package/dist/components/layout/Layout.component.d.ts.map +1 -1
  36. package/dist/components/layout/v2/panels.d.ts.map +1 -1
  37. package/dist/components/modal/Modal.component.js +2 -2
  38. package/dist/components/navbar/Navbar.component.js +2 -2
  39. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts +0 -1
  40. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts.map +1 -1
  41. package/dist/components/searchinput/SearchInput.component.d.ts +1 -2
  42. package/dist/components/searchinput/SearchInput.component.d.ts.map +1 -1
  43. package/dist/components/selectv2/Selectv2.component.d.ts +5 -5
  44. package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -1
  45. package/dist/components/statuswrapper/Statuswrapper.component.d.ts +0 -1
  46. package/dist/components/statuswrapper/Statuswrapper.component.d.ts.map +1 -1
  47. package/dist/components/tablev2/Search.js +2 -2
  48. package/dist/components/tablev2/SingleSelectableContent.d.ts +1 -2
  49. package/dist/components/tablev2/SingleSelectableContent.d.ts.map +1 -1
  50. package/dist/components/tablev2/TableCommon.d.ts +2 -2
  51. package/dist/components/tablev2/TableCommon.d.ts.map +1 -1
  52. package/dist/components/tablev2/TableSync.d.ts +8 -0
  53. package/dist/components/tablev2/TableSync.d.ts.map +1 -0
  54. package/dist/components/tablev2/TableSync.js +11 -0
  55. package/dist/components/tablev2/Tablev2.component.d.ts +2 -1
  56. package/dist/components/tablev2/Tablev2.component.d.ts.map +1 -1
  57. package/dist/components/tablev2/Tablev2.component.js +10 -9
  58. package/dist/components/tabsv2/ScrollButton.d.ts +1 -2
  59. package/dist/components/tabsv2/ScrollButton.d.ts.map +1 -1
  60. package/dist/components/tabsv2/ScrollButton.js +2 -2
  61. package/dist/components/tabsv2/Tabsv2.component.d.ts +2 -2
  62. package/dist/components/tabsv2/Tabsv2.component.d.ts.map +1 -1
  63. package/dist/components/tabsv2/Tabsv2.component.js +2 -2
  64. package/dist/components/text/Text.component.d.ts +0 -1
  65. package/dist/components/text/Text.component.d.ts.map +1 -1
  66. package/dist/components/textarea/TextArea.component.d.ts +3 -3
  67. package/dist/components/textarea/TextArea.component.d.ts.map +1 -1
  68. package/dist/components/textbadge/TextBadge.component.d.ts +0 -1
  69. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  70. package/dist/components/toast/Toast.component.d.ts +1 -1
  71. package/dist/components/toast/Toast.component.d.ts.map +1 -1
  72. package/dist/components/toast/ToastProvider.d.ts.map +1 -1
  73. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +1 -2
  74. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -1
  75. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +1 -2
  76. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +1 -1
  77. package/dist/components/vegachartv2/VegaChartV2.component.js +2 -2
  78. package/dist/icons/branding.d.ts.map +1 -1
  79. package/dist/icons/scality-loading.d.ts.map +1 -1
  80. package/dist/next.d.ts +1 -0
  81. package/dist/next.d.ts.map +1 -1
  82. package/dist/next.js +1 -0
  83. package/dist/style/theme.d.ts +19 -0
  84. package/dist/style/theme.d.ts.map +1 -1
  85. package/dist/style/theme.js +18 -1
  86. package/package.json +6 -3
  87. package/setupTests.js +6 -0
  88. package/src/lib/components/accordion/Accordion.component.tsx +1 -1
  89. package/src/lib/components/barchartv2/Barchart.component.test.tsx +383 -0
  90. package/src/lib/components/barchartv2/Barchart.component.tsx +309 -0
  91. package/src/lib/components/barchartv2/utils.test.ts +782 -0
  92. package/src/lib/components/barchartv2/utils.ts +486 -0
  93. package/src/lib/components/buttonv2/Buttonv2.component.tsx +1 -1
  94. package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +22 -3
  95. package/src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx +0 -1
  96. package/src/lib/components/date/FormattedDateTime.tsx +6 -0
  97. package/src/lib/components/emptytable/Emptytable.component.tsx +1 -1
  98. package/src/lib/components/error-pages/ErrorPage401.component.tsx +0 -1
  99. package/src/lib/components/error-pages/ErrorPage404.component.tsx +0 -1
  100. package/src/lib/components/error-pages/ErrorPage500.component.tsx +0 -1
  101. package/src/lib/components/error-pages/ErrorPageAuth.component.tsx +0 -1
  102. package/src/lib/components/form/Form.component.tsx +1 -1
  103. package/src/lib/components/infomessage/InfoMessage.component.tsx +0 -1
  104. package/src/lib/components/lateralnavbarlayout/LateralNavbarLayout.component.tsx +0 -1
  105. package/src/lib/components/layout/Layout.component.tsx +0 -1
  106. package/src/lib/components/layout/v2/panels.tsx +1 -1
  107. package/src/lib/components/modal/Modal.component.tsx +2 -2
  108. package/src/lib/components/navbar/Navbar.component.tsx +2 -2
  109. package/src/lib/components/scrollbarwrapper/ScrollbarWrapper.component.tsx +0 -1
  110. package/src/lib/components/searchinput/SearchInput.component.tsx +0 -1
  111. package/src/lib/components/selectv2/Selectv2.component.tsx +11 -9
  112. package/src/lib/components/sidebar/Sidebar.component.tsx +1 -1
  113. package/src/lib/components/statuswrapper/Statuswrapper.component.tsx +0 -1
  114. package/src/lib/components/tablev2/Search.tsx +2 -2
  115. package/src/lib/components/tablev2/SingleSelectableContent.tsx +2 -2
  116. package/src/lib/components/tablev2/TableCommon.tsx +1 -1
  117. package/src/lib/components/tablev2/TableSync.test.tsx +31 -0
  118. package/src/lib/components/tablev2/TableSync.tsx +36 -0
  119. package/src/lib/components/tablev2/Tablev2.component.tsx +11 -9
  120. package/src/lib/components/tabsv2/ScrollButton.tsx +2 -2
  121. package/src/lib/components/tabsv2/Tabsv2.component.tsx +6 -6
  122. package/src/lib/components/text/Text.component.tsx +4 -5
  123. package/src/lib/components/textarea/TextArea.component.tsx +3 -2
  124. package/src/lib/components/textbadge/TextBadge.component.tsx +0 -1
  125. package/src/lib/components/toast/Toast.component.tsx +1 -1
  126. package/src/lib/components/toast/ToastProvider.tsx +3 -1
  127. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +1 -1
  128. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +2 -2
  129. package/src/lib/icons/branding.tsx +0 -2
  130. package/src/lib/icons/scality-loading.tsx +0 -2
  131. package/src/lib/next.ts +5 -0
  132. package/src/lib/style/theme.ts +24 -1
  133. package/stories/BarChart/barchart.stories.tsx +655 -0
  134. package/stories/areachart.stories.tsx +0 -1
  135. package/stories/tablev2.stories.tsx +41 -0
  136. package/tsconfig.json +5 -2
@@ -0,0 +1,655 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import React, { useState } from 'react';
3
+ import { useTheme } from 'styled-components';
4
+ import {
5
+ Barchart,
6
+ BarchartProps,
7
+ BarchartSortFn,
8
+ BarchartTooltipFn,
9
+ } from '../../src/lib/components/barchartv2/Barchart.component';
10
+ import { Button } from '../../src/lib/components/buttonv2/Buttonv2.component';
11
+ import { Text } from '../../src/lib/components/text/Text.component';
12
+ import { spacing, Stack, Wrap } from '../../src/lib/spacing';
13
+ import {
14
+ CoreUITheme,
15
+ lineColor1,
16
+ lineColor2,
17
+ lineColor3,
18
+ } from '../../src/lib/style/theme';
19
+ import { Wrapper } from '../common';
20
+
21
+ type Story = StoryObj<typeof Barchart>;
22
+
23
+ const meta: Meta<typeof Barchart> = {
24
+ title: 'Components/Data Display/Charts/Barchartv2',
25
+ component: Barchart,
26
+ decorators: [
27
+ (story) => (
28
+ <Wrapper style={{ height: '100vh', width: '100vw' }}>{story()}</Wrapper>
29
+ ),
30
+ ],
31
+ parameters: {
32
+ layout: 'centered',
33
+ },
34
+ };
35
+
36
+ export default meta;
37
+
38
+ export const Playground: Story = {
39
+ render: () => {
40
+ const theme = useTheme() as CoreUITheme;
41
+ const exampleData = [
42
+ {
43
+ label: 'Success',
44
+ data: [
45
+ ['category1', 2],
46
+ ['category2', 4],
47
+ ['category3', 6],
48
+ ],
49
+ },
50
+ {
51
+ label: 'Failed',
52
+ data: [
53
+ ['category1', 8],
54
+ ['category2', 10],
55
+ ['category3', 12],
56
+ ],
57
+ },
58
+ ] as const;
59
+ return (
60
+ <Barchart
61
+ type="category"
62
+ bars={exampleData}
63
+ colorSet={{
64
+ Success: theme.statusHealthy,
65
+ Failed: theme.statusCritical,
66
+ }}
67
+ />
68
+ );
69
+ },
70
+ };
71
+
72
+ const timeData7Days = [
73
+ {
74
+ label: 'Success',
75
+ data: [
76
+ // 7 days ago - aligned to the exact timestamp that generateTimestamps will create
77
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), 15],
78
+ // 6 days ago
79
+ [new Date(Date.now() - 6 * 24 * 60 * 60 * 1000), 12],
80
+ // 5 days ago
81
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 30],
82
+ // 4 days ago
83
+ [new Date(Date.now() - 4 * 24 * 60 * 60 * 1000), 20],
84
+ // 3 days ago
85
+ [new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), 25],
86
+ // 2 days ago
87
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 18],
88
+ // 1 day ago
89
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 32],
90
+ ],
91
+ },
92
+ {
93
+ label: 'Failed',
94
+ data: [
95
+ // 7 days ago
96
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), 5],
97
+ // 6 days ago
98
+ [new Date(Date.now() - 6 * 24 * 60 * 60 * 1000), 8],
99
+ // 5 days ago
100
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 2],
101
+ // 4 days ago
102
+ [new Date(Date.now() - 4 * 24 * 60 * 60 * 1000), 12],
103
+ // 3 days ago
104
+ [new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), 6],
105
+ // 2 days ago
106
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 9],
107
+ // 1 day ago
108
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 7],
109
+ ],
110
+ },
111
+ ] as const;
112
+
113
+ export const Time7Days: Story = {
114
+ render: () => {
115
+ const theme = useTheme() as CoreUITheme;
116
+ return (
117
+ <Barchart
118
+ type={{
119
+ type: 'time',
120
+ timeRange: {
121
+ startDate: new Date(
122
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
123
+ 7 * 24 * 60 * 60 * 1000,
124
+ ),
125
+ endDate: new Date(
126
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
127
+ 1 * 24 * 60 * 60 * 1000,
128
+ ),
129
+ interval: 24 * 60 * 60 * 1000,
130
+ },
131
+ }}
132
+ bars={timeData7Days}
133
+ colorSet={{
134
+ Success: theme.statusHealthy,
135
+ Failed: theme.statusCritical,
136
+ }}
137
+ />
138
+ );
139
+ },
140
+ };
141
+
142
+ const timeData7DaysWithMissingData = [
143
+ {
144
+ label: 'Success',
145
+ data: [
146
+ // 7 days ago
147
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000 + 12), 15],
148
+ // 5 days ago
149
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 30],
150
+ // 4 days ago
151
+ [new Date(Date.now() - 4 * 24 * 60 * 60 * 1000), 20],
152
+ // 3 days ago
153
+ // 2 days ago
154
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 18],
155
+ // 1 day ago
156
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 32],
157
+ ],
158
+ },
159
+ {
160
+ label: 'Failed',
161
+ data: [
162
+ // 7 days ago
163
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), 5],
164
+ // 6 days ago
165
+ // 5 days ago
166
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 1],
167
+ // 4 days ago
168
+ // 3 days ago
169
+ [new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), 6],
170
+ // 2 days ago
171
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 9],
172
+ // 1 day ago
173
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 7],
174
+ ],
175
+ },
176
+ ] as const;
177
+
178
+ export const Time7DaysWithMissingData: Story = {
179
+ render: () => {
180
+ const theme = useTheme() as CoreUITheme;
181
+ return (
182
+ <Barchart
183
+ type={{
184
+ type: 'time',
185
+ timeRange: {
186
+ startDate: new Date(
187
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
188
+ 7 * 24 * 60 * 60 * 1000,
189
+ ),
190
+ endDate: new Date(
191
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
192
+ 1 * 24 * 60 * 60 * 1000,
193
+ ),
194
+ interval: 24 * 60 * 60 * 1000,
195
+ },
196
+ }}
197
+ bars={timeData7DaysWithMissingData}
198
+ colorSet={{
199
+ Success: theme.statusHealthy,
200
+ Failed: theme.statusCritical,
201
+ }}
202
+ />
203
+ );
204
+ },
205
+ };
206
+
207
+ const timeDataLast24Hours = [
208
+ {
209
+ label: 'Success',
210
+ data: [
211
+ [new Date(Date.now() - 24 * 60 * 60 * 1000), 15],
212
+ [new Date(Date.now() - 23 * 60 * 60 * 1000), 12],
213
+ [new Date(Date.now() - 22 * 60 * 60 * 1000), 30],
214
+ [new Date(Date.now() - 21 * 60 * 60 * 1000), 20],
215
+ [new Date(Date.now() - 20 * 60 * 60 * 1000), 25],
216
+ [new Date(Date.now() - 19 * 60 * 60 * 1000), 18],
217
+ [new Date(Date.now() - 18 * 60 * 60 * 1000), 32],
218
+ [new Date(Date.now() - 17 * 60 * 60 * 1000), 19],
219
+ [new Date(Date.now() - 16 * 60 * 60 * 1000), 10],
220
+ [new Date(Date.now() - 15 * 60 * 60 * 1000), 11],
221
+ [new Date(Date.now() - 14 * 60 * 60 * 1000), 12],
222
+ [new Date(Date.now() - 13 * 60 * 60 * 1000), 13],
223
+ [new Date(Date.now() - 12 * 60 * 60 * 1000), 11],
224
+ [new Date(Date.now() - 11 * 60 * 60 * 1000), 17],
225
+ [new Date(Date.now() - 10 * 60 * 60 * 1000), 16],
226
+ [new Date(Date.now() - 9 * 60 * 60 * 1000), 13],
227
+ [new Date(Date.now() - 8 * 60 * 60 * 1000), 15],
228
+ [new Date(Date.now() - 7 * 60 * 60 * 1000), 16],
229
+ [new Date(Date.now() - 6 * 60 * 60 * 1000), 17],
230
+ [new Date(Date.now() - 5 * 60 * 60 * 1000), 18],
231
+ [new Date(Date.now() - 4 * 60 * 60 * 1000), 19],
232
+ [new Date(Date.now() - 3 * 60 * 60 * 1000), 20],
233
+ [new Date(Date.now() - 2 * 60 * 60 * 1000), 21],
234
+ [new Date(Date.now() - 1 * 60 * 60 * 1000), 22],
235
+ ],
236
+ },
237
+ {
238
+ label: 'Failed',
239
+ data: [
240
+ [new Date(Date.now() - 24 * 60 * 60 * 1000), 5],
241
+ [new Date(Date.now() - 23 * 60 * 60 * 1000), 8],
242
+ [new Date(Date.now() - 22 * 60 * 60 * 1000), 2],
243
+ [new Date(Date.now() - 21 * 60 * 60 * 1000), 12],
244
+ [new Date(Date.now() - 20 * 60 * 60 * 1000), 6],
245
+ [new Date(Date.now() - 19 * 60 * 60 * 1000), 9],
246
+ [new Date(Date.now() - 18 * 60 * 60 * 1000), 7],
247
+ [new Date(Date.now() - 17 * 60 * 60 * 1000), 1],
248
+ [new Date(Date.now() - 16 * 60 * 60 * 1000), 1],
249
+ [new Date(Date.now() - 15 * 60 * 60 * 1000), 2],
250
+ [new Date(Date.now() - 14 * 60 * 60 * 1000), 4],
251
+ [new Date(Date.now() - 13 * 60 * 60 * 1000), 2],
252
+ [new Date(Date.now() - 12 * 60 * 60 * 1000), 3],
253
+ [new Date(Date.now() - 11 * 60 * 60 * 1000), 1],
254
+ [new Date(Date.now() - 10 * 60 * 60 * 1000), 1],
255
+ [new Date(Date.now() - 9 * 60 * 60 * 1000), 1],
256
+ [new Date(Date.now() - 8 * 60 * 60 * 1000), 1],
257
+ [new Date(Date.now() - 7 * 60 * 60 * 1000), 1],
258
+ [new Date(Date.now() - 6 * 60 * 60 * 1000), 1],
259
+ [new Date(Date.now() - 5 * 60 * 60 * 1000), 1],
260
+ [new Date(Date.now() - 4 * 60 * 60 * 1000), 5],
261
+ [new Date(Date.now() - 3 * 60 * 60 * 1000), 3],
262
+ [new Date(Date.now() - 2 * 60 * 60 * 1000), 2],
263
+ [new Date(Date.now() - 1 * 60 * 60 * 1000), 1],
264
+ ],
265
+ },
266
+ ] as const;
267
+
268
+ export const TimeLast24Hours: Story = {
269
+ render: () => {
270
+ const theme = useTheme() as CoreUITheme;
271
+ return (
272
+ <Barchart
273
+ type={{
274
+ type: 'time',
275
+ timeRange: {
276
+ startDate: new Date(
277
+ new Date(Date.now()).setMinutes(0, 0, 0) - 24 * 60 * 60 * 1000,
278
+ ),
279
+ endDate: new Date(new Date(Date.now()).setMinutes(0, 0, 0)),
280
+ interval: 60 * 60 * 1000,
281
+ },
282
+ }}
283
+ bars={timeDataLast24Hours}
284
+ colorSet={{
285
+ Success: theme.statusHealthy,
286
+ Failed: theme.statusCritical,
287
+ }}
288
+ />
289
+ );
290
+ },
291
+ };
292
+
293
+ const capacityDataWithUnitRange = [
294
+ {
295
+ label: 'Free',
296
+ data: [
297
+ ['category1', 2000000],
298
+ ['category2', 4000000],
299
+ ['category3', 6000000],
300
+ ],
301
+ },
302
+ {
303
+ label: 'Used',
304
+ data: [
305
+ ['category1', 8000000],
306
+ ['category2', 10000000],
307
+ ['category3', 12000000],
308
+ ],
309
+ },
310
+ ] as const;
311
+
312
+ export const CapacityWithUnitRange: Story = {
313
+ render: () => {
314
+ const theme = useTheme() as CoreUITheme;
315
+ return (
316
+ <Barchart
317
+ type="category"
318
+ bars={capacityDataWithUnitRange}
319
+ unitRange={[
320
+ {
321
+ threshold: 0,
322
+ label: 'B',
323
+ },
324
+ {
325
+ threshold: 1024,
326
+ label: 'KiB',
327
+ },
328
+ {
329
+ threshold: 1024 * 1024,
330
+ label: 'MiB',
331
+ },
332
+ {
333
+ threshold: 1024 * 1024 * 1024,
334
+ label: 'GiB',
335
+ },
336
+ ]}
337
+ colorSet={{
338
+ Free: theme.selectedActive,
339
+ Used: theme.infoSecondary,
340
+ }}
341
+ />
342
+ );
343
+ },
344
+ };
345
+
346
+ const stackedData: BarchartProps<
347
+ {
348
+ label: 'Success' | 'Failed';
349
+ data: [string, number][];
350
+ }[]
351
+ >['bars'] = [
352
+ {
353
+ label: 'Success',
354
+ data: [
355
+ ['category1', 25],
356
+ ['category2', 72],
357
+ ['category3', 52],
358
+ ],
359
+ },
360
+ {
361
+ label: 'Failed',
362
+ data: [
363
+ ['category1', 8],
364
+ ['category2', 10],
365
+ ['category3', 25],
366
+ ],
367
+ },
368
+ ];
369
+
370
+ export const Stacked: Story = {
371
+ render: () => {
372
+ const theme = useTheme() as CoreUITheme;
373
+ return (
374
+ <Barchart
375
+ type="category"
376
+ bars={stackedData}
377
+ stacked
378
+ colorSet={{
379
+ Success: theme.statusHealthy,
380
+ Failed: theme.statusCritical,
381
+ }}
382
+ />
383
+ );
384
+ },
385
+ };
386
+
387
+ export const DefaultSort: Story = {
388
+ render: () => {
389
+ const theme = useTheme() as CoreUITheme;
390
+ const defaultSortData = [
391
+ {
392
+ label: 'Success',
393
+ data: [
394
+ ['AZ', 15],
395
+ ['BB', 10],
396
+ ['CC', 25],
397
+ ['DD', 18],
398
+ ['AA', 22],
399
+ ['EE', 15],
400
+ ],
401
+ },
402
+ {
403
+ label: 'Failed',
404
+ data: [
405
+ ['AZ', 8],
406
+ ['BB', 1],
407
+ ['CC', 3],
408
+ ['DD', 1],
409
+ ['AA', 5],
410
+ ['EE', 5],
411
+ ],
412
+ },
413
+ ] as const;
414
+ const customSort: BarchartSortFn<typeof defaultSortData> = (
415
+ pointA,
416
+ pointB,
417
+ ) => {
418
+ const totalA = pointA.Success + pointA.Failed;
419
+ const totalB = pointB.Success + pointB.Failed;
420
+ return totalA - totalB > 0 ? -1 : totalA - totalB < 0 ? 1 : 0; // Descending order
421
+ };
422
+ return (
423
+ <Barchart
424
+ type="category"
425
+ stacked
426
+ bars={defaultSortData}
427
+ defaultSort={customSort}
428
+ colorSet={{
429
+ Success: theme.statusHealthy,
430
+ Failed: theme.statusCritical,
431
+ }}
432
+ />
433
+ );
434
+ },
435
+ };
436
+
437
+ export const WithCustomTooltip: Story = {
438
+ render: () => {
439
+ const theme = useTheme() as CoreUITheme;
440
+ const exampleData = [
441
+ {
442
+ label: 'Success',
443
+ data: [
444
+ ['category1', 2],
445
+ ['category2', 4],
446
+ ['category3', 6],
447
+ ],
448
+ },
449
+ {
450
+ label: 'Failed',
451
+ data: [
452
+ ['category1', 8],
453
+ ['category2', 10],
454
+ ['category3', 12],
455
+ ],
456
+ },
457
+ ] as const;
458
+ const customTooltip: BarchartTooltipFn<typeof exampleData> = (pointA) => {
459
+ return (
460
+ <Stack
461
+ direction="vertical"
462
+ gap="r4"
463
+ style={{
464
+ width: '150px',
465
+ backgroundColor: 'black',
466
+ padding: '10px',
467
+ borderRadius: '10px',
468
+ color: 'white',
469
+ }}
470
+ >
471
+ <Text style={{ textAlign: 'center', color: 'white' }}>
472
+ {pointA.category}
473
+ </Text>
474
+ {pointA.values.map((point) => (
475
+ <Text
476
+ key={point.label}
477
+ isEmphazed={point.isHovered}
478
+ style={{
479
+ color: point.isHovered ? 'yellow' : 'white',
480
+ }}
481
+ >
482
+ <Wrap>
483
+ <span>{point.label}:</span>
484
+ <span>{point.value}</span>
485
+ </Wrap>
486
+ </Text>
487
+ ))}
488
+ </Stack>
489
+ );
490
+ };
491
+ return (
492
+ <Stack direction="vertical" gap="r16">
493
+ <Text variant="Large">External Tooltip & Sort Functions</Text>
494
+ <Text variant="Basic" color="textSecondary">
495
+ Tooltip and sort functions defined outside with full type safety
496
+ </Text>
497
+ <Barchart
498
+ type="category"
499
+ bars={exampleData}
500
+ tooltip={customTooltip}
501
+ height={300}
502
+ colorSet={{
503
+ Success: theme.statusHealthy,
504
+ Failed: theme.statusCritical,
505
+ }}
506
+ />
507
+ </Stack>
508
+ );
509
+ },
510
+ };
511
+
512
+ const exampleData = [
513
+ {
514
+ label: 'Success',
515
+ data: [
516
+ ['category1', 1000000],
517
+ ['category2', 2000000],
518
+ ['category3', 3000000],
519
+ ],
520
+ },
521
+ {
522
+ label: 'Failed',
523
+ data: [
524
+ ['category1', 1000000],
525
+ ['category2', 2000000],
526
+ ['category3', 3000000],
527
+ ],
528
+ },
529
+ ] as const;
530
+
531
+ export const StatusColors: Story = {
532
+ render: () => {
533
+ const theme = useTheme() as CoreUITheme;
534
+ const statusData = [
535
+ {
536
+ label: 'Success Rate',
537
+ data: [
538
+ ['API', 95],
539
+ ['Database', 87],
540
+ ['Queue', 92],
541
+ ],
542
+ },
543
+ {
544
+ label: 'Failed Requests',
545
+ data: [
546
+ ['API', 5],
547
+ ['Database', 13],
548
+ ['Queue', 8],
549
+ ],
550
+ },
551
+ {
552
+ label: 'Warning Events',
553
+ data: [
554
+ ['API', 2],
555
+ ['Database', 4],
556
+ ['Queue', 1],
557
+ ],
558
+ },
559
+ ] as const;
560
+ return (
561
+ <Barchart
562
+ type="category"
563
+ bars={statusData}
564
+ stacked
565
+ colorSet={{
566
+ 'Success Rate': theme.statusHealthy,
567
+ 'Failed Requests': theme.statusCritical,
568
+ 'Warning Events': theme.statusWarning,
569
+ }}
570
+ title="System Health Metrics"
571
+ />
572
+ );
573
+ },
574
+ };
575
+
576
+ export const CompleteExample: Story = {
577
+ render: () => {
578
+ const theme = useTheme() as CoreUITheme;
579
+ const [isLoading, setIsLoading] = useState(true);
580
+ const [data, setData] = useState<
581
+ BarchartProps<typeof data>['bars'] | undefined
582
+ >(undefined);
583
+ const customTooltip: BarchartTooltipFn<typeof data> = (pointA) => {
584
+ return (
585
+ <Stack
586
+ direction="vertical"
587
+ gap="r4"
588
+ style={{
589
+ width: '150px',
590
+ backgroundColor: 'black',
591
+ padding: '10px',
592
+ borderRadius: '10px',
593
+ color: 'white',
594
+ }}
595
+ >
596
+ <Text style={{ textAlign: 'center', color: 'white' }}>
597
+ {pointA.category}
598
+ </Text>
599
+ {pointA.values.map((point) => (
600
+ <Text
601
+ key={point.label}
602
+ isEmphazed={point.isHovered}
603
+ style={{
604
+ fontWeight: point.isHovered ? 'bold' : 'normal',
605
+ }}
606
+ >
607
+ <Wrap>
608
+ <span>{point.label}:</span>
609
+ <span>{point.value}</span>
610
+ </Wrap>
611
+ </Text>
612
+ ))}
613
+ </Stack>
614
+ );
615
+ };
616
+ return (
617
+ <div
618
+ style={{
619
+ width: '50%',
620
+ padding: spacing.r16,
621
+ borderRadius: spacing.r8,
622
+ backgroundColor: theme.backgroundLevel2,
623
+ }}
624
+ >
625
+ <Barchart
626
+ type="category"
627
+ title="Loading BarChart"
628
+ helpTooltip="Click on the button to load or unload data"
629
+ secondaryTitle={isLoading ? 'Loading...' : 'Loaded data'}
630
+ rightTitle={
631
+ <Button
632
+ label={isLoading ? 'Load data' : 'Fake loading data'}
633
+ onClick={() => {
634
+ setIsLoading(!isLoading);
635
+ if (isLoading) {
636
+ setData(exampleData);
637
+ } else {
638
+ setData(undefined);
639
+ }
640
+ }}
641
+ />
642
+ }
643
+ bars={data || []}
644
+ tooltip={customTooltip}
645
+ isLoading={isLoading}
646
+ height={200}
647
+ colorSet={{
648
+ Success: 'lineColor1',
649
+ Failed: 'lineColor2',
650
+ }}
651
+ />
652
+ </div>
653
+ );
654
+ },
655
+ };
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { AreaChart } from '../src/lib/components/areachart/AreaChart.component';
3
2
  import { area_charts } from './data/areachart';
4
3
  import { Wrapper } from './common';
@@ -635,3 +635,44 @@ export const ErrorTable = {
635
635
  );
636
636
  },
637
637
  };
638
+
639
+ export const TableWithSyncButton = {
640
+ render: ({}) => {
641
+ const [isLoading, setIsLoading] = React.useState(false);
642
+
643
+ const handleSync = () => {
644
+ action('Sync button clicked')();
645
+ setIsLoading(true);
646
+
647
+ // Simulate loading for 2 seconds
648
+ setTimeout(() => {
649
+ setIsLoading(false);
650
+ }, 2000);
651
+ };
652
+
653
+ return (
654
+ <Box>
655
+ <Title>Table with Sync Button</Title>
656
+ <Box
657
+ display="flex"
658
+ justifyContent="space-between"
659
+ alignItems="center"
660
+ mb={2}
661
+ >
662
+ <Box>Total: {data.length} items</Box>
663
+ <Table.Sync
664
+ onSync={handleSync}
665
+ loading={isLoading}
666
+ tooltipOverlay="Synchronize table data"
667
+ />
668
+ </Box>
669
+ <Table columns={columns} data={data}>
670
+ <Table.SingleSelectableContent
671
+ rowHeight="h40"
672
+ separationLineVariant="backgroundLevel3"
673
+ />
674
+ </Table>
675
+ </Box>
676
+ );
677
+ },
678
+ };
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "exclude": ["src/**/*.test.*","stories/*", "dist/**/*"],
2
+ "exclude": ["src/**/*.test.*", "stories/*", "dist/**/*"],
3
3
  "compilerOptions": {
4
4
  "module": "esnext",
5
5
  "declaration": true, // Generate d.ts files
@@ -13,6 +13,9 @@
13
13
  "moduleResolution": "node",
14
14
  "strict": true,
15
15
  "strictFunctionTypes": true,
16
- "noImplicitAny": false //For now it is too costly to enable this one
16
+ "noImplicitAny": false, //For now it is too costly to enable this one
17
+ "esModuleInterop": true,
18
+ "allowSyntheticDefaultImports": true,
19
+ "forceConsistentCasingInFileNames": true
17
20
  }
18
21
  }