@scality/core-ui 0.161.0 → 0.163.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 (173) 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 +53 -0
  5. package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -0
  6. package/dist/components/barchartv2/Barchart.component.js +86 -0
  7. package/dist/components/barchartv2/utils.d.ts +118 -0
  8. package/dist/components/barchartv2/utils.d.ts.map +1 -0
  9. package/dist/components/barchartv2/utils.js +337 -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/chartlegend/ChartLegend.d.ts +8 -0
  13. package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -0
  14. package/dist/components/chartlegend/ChartLegend.js +65 -0
  15. package/dist/components/chartlegend/ChartLegendWrapper.d.ts +17 -0
  16. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -0
  17. package/dist/components/chartlegend/ChartLegendWrapper.js +50 -0
  18. package/dist/components/constrainedtext/Constrainedtext.component.d.ts +2 -1
  19. package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -1
  20. package/dist/components/constrainedtext/Constrainedtext.component.js +5 -4
  21. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts +0 -1
  22. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts.map +1 -1
  23. package/dist/components/date/FormattedDateTime.d.ts +4 -1
  24. package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
  25. package/dist/components/date/FormattedDateTime.js +24 -1
  26. package/dist/components/date/FormattedDateTime.spec.js +12 -0
  27. package/dist/components/emptytable/Emptytable.component.d.ts +0 -1
  28. package/dist/components/emptytable/Emptytable.component.d.ts.map +1 -1
  29. package/dist/components/emptytable/Emptytable.component.js +1 -0
  30. package/dist/components/error-pages/ErrorPage401.component.d.ts +0 -1
  31. package/dist/components/error-pages/ErrorPage401.component.d.ts.map +1 -1
  32. package/dist/components/error-pages/ErrorPage404.component.d.ts +0 -1
  33. package/dist/components/error-pages/ErrorPage404.component.d.ts.map +1 -1
  34. package/dist/components/error-pages/ErrorPage500.component.d.ts +0 -1
  35. package/dist/components/error-pages/ErrorPage500.component.d.ts.map +1 -1
  36. package/dist/components/error-pages/ErrorPageAuth.component.d.ts.map +1 -1
  37. package/dist/components/form/Form.component.d.ts +2 -2
  38. package/dist/components/form/Form.component.d.ts.map +1 -1
  39. package/dist/components/icon/Icon.component.d.ts +5 -5
  40. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  41. package/dist/components/icon/Icon.component.js +33 -31
  42. package/dist/components/infomessage/InfoMessage.component.d.ts +0 -1
  43. package/dist/components/infomessage/InfoMessage.component.d.ts.map +1 -1
  44. package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts.map +1 -1
  45. package/dist/components/layout/Layout.component.d.ts.map +1 -1
  46. package/dist/components/layout/v2/panels.d.ts.map +1 -1
  47. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +33 -0
  48. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -0
  49. package/dist/components/linetimeseriechart/linetimeseriechart.component.js +249 -0
  50. package/dist/components/modal/Modal.component.js +2 -2
  51. package/dist/components/navbar/Navbar.component.js +2 -2
  52. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts +0 -1
  53. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts.map +1 -1
  54. package/dist/components/searchinput/SearchInput.component.d.ts +1 -2
  55. package/dist/components/searchinput/SearchInput.component.d.ts.map +1 -1
  56. package/dist/components/selectv2/Selectv2.component.d.ts +5 -5
  57. package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -1
  58. package/dist/components/selectv2/Selectv2.component.js +11 -6
  59. package/dist/components/statuswrapper/Statuswrapper.component.d.ts +0 -1
  60. package/dist/components/statuswrapper/Statuswrapper.component.d.ts.map +1 -1
  61. package/dist/components/steppers/Stepper.component.d.ts.map +1 -1
  62. package/dist/components/steppers/Stepper.component.js +9 -8
  63. package/dist/components/tablev2/Search.js +2 -2
  64. package/dist/components/tablev2/SingleSelectableContent.d.ts +1 -2
  65. package/dist/components/tablev2/SingleSelectableContent.d.ts.map +1 -1
  66. package/dist/components/tablev2/TableCommon.d.ts +2 -2
  67. package/dist/components/tablev2/TableCommon.d.ts.map +1 -1
  68. package/dist/components/tablev2/TableSync.d.ts +8 -0
  69. package/dist/components/tablev2/TableSync.d.ts.map +1 -0
  70. package/dist/components/tablev2/TableSync.js +11 -0
  71. package/dist/components/tablev2/Tablev2.component.d.ts +2 -1
  72. package/dist/components/tablev2/Tablev2.component.d.ts.map +1 -1
  73. package/dist/components/tablev2/Tablev2.component.js +10 -9
  74. package/dist/components/tabsv2/ScrollButton.d.ts +1 -2
  75. package/dist/components/tabsv2/ScrollButton.d.ts.map +1 -1
  76. package/dist/components/tabsv2/ScrollButton.js +2 -2
  77. package/dist/components/tabsv2/Tabsv2.component.d.ts +2 -2
  78. package/dist/components/tabsv2/Tabsv2.component.d.ts.map +1 -1
  79. package/dist/components/tabsv2/Tabsv2.component.js +2 -2
  80. package/dist/components/text/Text.component.d.ts +0 -1
  81. package/dist/components/text/Text.component.d.ts.map +1 -1
  82. package/dist/components/textarea/TextArea.component.d.ts +3 -3
  83. package/dist/components/textarea/TextArea.component.d.ts.map +1 -1
  84. package/dist/components/textbadge/TextBadge.component.d.ts +0 -1
  85. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  86. package/dist/components/toast/Toast.component.d.ts +1 -1
  87. package/dist/components/toast/Toast.component.d.ts.map +1 -1
  88. package/dist/components/toast/ToastProvider.d.ts.map +1 -1
  89. package/dist/components/toast/ToastProvider.js +4 -5
  90. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +1 -2
  91. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -1
  92. package/dist/components/vegachartv2/SyncedCursorCharts.js +3 -5
  93. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +1 -2
  94. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +1 -1
  95. package/dist/components/vegachartv2/VegaChartV2.component.js +2 -2
  96. package/dist/icons/branding.d.ts.map +1 -1
  97. package/dist/icons/scality-loading.d.ts.map +1 -1
  98. package/dist/index.d.ts +1 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +1 -0
  101. package/dist/next.d.ts +2 -0
  102. package/dist/next.d.ts.map +1 -1
  103. package/dist/next.js +2 -0
  104. package/dist/style/theme.d.ts +20 -0
  105. package/dist/style/theme.d.ts.map +1 -1
  106. package/dist/style/theme.js +46 -1
  107. package/package.json +7 -4
  108. package/setupTests.js +6 -0
  109. package/src/lib/components/accordion/Accordion.component.tsx +1 -1
  110. package/src/lib/components/accordion/Accordion.test.tsx +7 -15
  111. package/src/lib/components/barchartv2/Barchart.component.test.tsx +364 -0
  112. package/src/lib/components/barchartv2/Barchart.component.tsx +321 -0
  113. package/src/lib/components/barchartv2/utils.test.ts +899 -0
  114. package/src/lib/components/barchartv2/utils.ts +534 -0
  115. package/src/lib/components/buttonv2/Buttonv2.component.tsx +1 -1
  116. package/src/lib/components/chartlegend/ChartLegend.tsx +113 -0
  117. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +85 -0
  118. package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +22 -3
  119. package/src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx +0 -1
  120. package/src/lib/components/date/FormattedDateTime.spec.tsx +24 -0
  121. package/src/lib/components/date/FormattedDateTime.tsx +42 -2
  122. package/src/lib/components/emptytable/Emptytable.component.tsx +1 -1
  123. package/src/lib/components/error-pages/ErrorPage401.component.tsx +0 -1
  124. package/src/lib/components/error-pages/ErrorPage404.component.tsx +0 -1
  125. package/src/lib/components/error-pages/ErrorPage500.component.tsx +0 -1
  126. package/src/lib/components/error-pages/ErrorPageAuth.component.tsx +0 -1
  127. package/src/lib/components/form/Form.component.tsx +1 -1
  128. package/src/lib/components/healthselectorv2/HealthSelector.component.test.tsx +3 -3
  129. package/src/lib/components/icon/Icon.component.tsx +48 -60
  130. package/src/lib/components/infomessage/InfoMessage.component.tsx +0 -1
  131. package/src/lib/components/inlineinput/InlineInput.test.tsx +22 -19
  132. package/src/lib/components/inputlist/InputList.test.tsx +21 -19
  133. package/src/lib/components/lateralnavbarlayout/LateralNavbarLayout.component.tsx +0 -1
  134. package/src/lib/components/layout/Layout.component.tsx +0 -1
  135. package/src/lib/components/layout/v2/panels.tsx +1 -1
  136. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +502 -0
  137. package/src/lib/components/modal/Modal.component.tsx +2 -2
  138. package/src/lib/components/navbar/Navbar.component.tsx +2 -2
  139. package/src/lib/components/scrollbarwrapper/ScrollbarWrapper.component.tsx +0 -1
  140. package/src/lib/components/searchinput/SearchInput.component.tsx +0 -1
  141. package/src/lib/components/searchinput/SearchInput.test.tsx +3 -7
  142. package/src/lib/components/selectv2/Selectv2.component.tsx +24 -14
  143. package/src/lib/components/selectv2/selectv2.test.tsx +62 -57
  144. package/src/lib/components/sidebar/Sidebar.component.tsx +1 -1
  145. package/src/lib/components/statuswrapper/Statuswrapper.component.tsx +0 -1
  146. package/src/lib/components/steppers/Stepper.component.tsx +10 -8
  147. package/src/lib/components/tablev2/Search.tsx +2 -2
  148. package/src/lib/components/tablev2/SingleSelectableContent.tsx +2 -2
  149. package/src/lib/components/tablev2/TableCommon.tsx +1 -1
  150. package/src/lib/components/tablev2/TableSync.test.tsx +28 -0
  151. package/src/lib/components/tablev2/TableSync.tsx +36 -0
  152. package/src/lib/components/tablev2/Tablev2.component.tsx +11 -9
  153. package/src/lib/components/tablev2/Tablev2.test.tsx +36 -37
  154. package/src/lib/components/tabsv2/ScrollButton.tsx +2 -2
  155. package/src/lib/components/tabsv2/Tabsv2.component.tsx +6 -6
  156. package/src/lib/components/text/Text.component.tsx +4 -5
  157. package/src/lib/components/textarea/TextArea.component.tsx +3 -2
  158. package/src/lib/components/textbadge/TextBadge.component.tsx +0 -1
  159. package/src/lib/components/toast/Toast.component.tsx +1 -1
  160. package/src/lib/components/toast/ToastProvider.tsx +17 -7
  161. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +5 -7
  162. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +2 -2
  163. package/src/lib/icons/branding.tsx +0 -2
  164. package/src/lib/icons/scality-loading.tsx +0 -2
  165. package/src/lib/index.ts +1 -0
  166. package/src/lib/next.ts +6 -0
  167. package/src/lib/style/theme.ts +53 -1
  168. package/stories/BarChart/barchart.stories.tsx +822 -0
  169. package/stories/areachart.stories.tsx +0 -1
  170. package/stories/format.mdx +4 -2
  171. package/stories/linetimeseriechart.stories.tsx +485 -0
  172. package/stories/tablev2.stories.tsx +41 -0
  173. package/tsconfig.json +5 -2
@@ -0,0 +1,822 @@
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 { CoreUITheme } from '../../src/lib/style/theme';
14
+ import { Wrapper } from '../common';
15
+ import { ChartLegendWrapper } from '../../src/lib/components/chartlegend/ChartLegendWrapper';
16
+ import { ChartLegend } from '../../src/lib/components/chartlegend/ChartLegend';
17
+
18
+ type Story = StoryObj<typeof Barchart>;
19
+
20
+ const meta: Meta<typeof Barchart> = {
21
+ title: 'Components/Data Display/Charts/Barchartv2',
22
+ component: Barchart,
23
+ decorators: [
24
+ (story) => (
25
+ <Wrapper style={{ height: '100vh', width: '100vw' }}>{story()}</Wrapper>
26
+ ),
27
+ ],
28
+ parameters: {
29
+ layout: 'centered',
30
+ },
31
+ };
32
+
33
+ export default meta;
34
+
35
+ export const Playground: Story = {
36
+ render: () => {
37
+ const theme = useTheme() as CoreUITheme;
38
+ const exampleData = [
39
+ {
40
+ label: 'Success',
41
+ data: [
42
+ ['category1', 2],
43
+ ['category2', 4],
44
+ ['category3', 6],
45
+ ],
46
+ },
47
+ {
48
+ label: 'Failed',
49
+ data: [
50
+ ['category1', 8],
51
+ ['category2', 10],
52
+ ['category3', 12],
53
+ ],
54
+ },
55
+ ] as const;
56
+ return (
57
+ <ChartLegendWrapper
58
+ colorSet={{
59
+ Success: theme.statusHealthy,
60
+ Failed: theme.statusCritical,
61
+ }}
62
+ >
63
+ <Stack direction="vertical" gap="r16">
64
+ <Barchart type="category" bars={exampleData} />
65
+ <ChartLegend shape="rectangle" direction="horizontal" />
66
+ </Stack>
67
+ </ChartLegendWrapper>
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
+ <ChartLegendWrapper
118
+ colorSet={{
119
+ Success: theme.statusHealthy,
120
+ Failed: theme.statusCritical,
121
+ }}
122
+ >
123
+ <Stack direction="vertical" gap="r16">
124
+ <Barchart
125
+ type={{
126
+ type: 'time',
127
+ timeRange: {
128
+ startDate: new Date(
129
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
130
+ 7 * 24 * 60 * 60 * 1000,
131
+ ),
132
+ endDate: new Date(
133
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
134
+ 1 * 24 * 60 * 60 * 1000,
135
+ ),
136
+ interval: 24 * 60 * 60 * 1000,
137
+ },
138
+ }}
139
+ bars={timeData7Days}
140
+ />
141
+ <ChartLegend shape="line" />
142
+ </Stack>
143
+ </ChartLegendWrapper>
144
+ );
145
+ },
146
+ };
147
+
148
+ const timeData7DaysWithMissingData = [
149
+ {
150
+ label: 'Success',
151
+ data: [
152
+ // 7 days ago
153
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000 + 12), 15],
154
+ // 5 days ago
155
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 30],
156
+ // 4 days ago
157
+ [new Date(Date.now() - 4 * 24 * 60 * 60 * 1000), 20],
158
+ // 3 days ago
159
+ // 2 days ago
160
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 18],
161
+ // 1 day ago
162
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 32],
163
+ ],
164
+ },
165
+ {
166
+ label: 'Failed',
167
+ data: [
168
+ // 7 days ago
169
+ [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), 5],
170
+ // 6 days ago
171
+ // 5 days ago
172
+ [new Date(Date.now() - 5 * 24 * 60 * 60 * 1000), 1],
173
+ // 4 days ago
174
+ // 3 days ago
175
+ [new Date(Date.now() - 3 * 24 * 60 * 60 * 1000), 6],
176
+ // 2 days ago
177
+ [new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), 9],
178
+ // 1 day ago
179
+ [new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), 7],
180
+ ],
181
+ },
182
+ ] as const;
183
+
184
+ export const Time7DaysWithMissingData: Story = {
185
+ render: () => {
186
+ const theme = useTheme() as CoreUITheme;
187
+ return (
188
+ <ChartLegendWrapper
189
+ colorSet={{
190
+ Success: theme.statusHealthy,
191
+ Failed: theme.statusCritical,
192
+ }}
193
+ >
194
+ <Barchart
195
+ type={{
196
+ type: 'time',
197
+ timeRange: {
198
+ startDate: new Date(
199
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
200
+ 7 * 24 * 60 * 60 * 1000,
201
+ ),
202
+ endDate: new Date(
203
+ new Date(Date.now()).setHours(0, 0, 0, 0) -
204
+ 1 * 24 * 60 * 60 * 1000,
205
+ ),
206
+ interval: 24 * 60 * 60 * 1000,
207
+ },
208
+ }}
209
+ bars={timeData7DaysWithMissingData}
210
+ />
211
+ </ChartLegendWrapper>
212
+ );
213
+ },
214
+ };
215
+
216
+ const timeDataLast24Hours = [
217
+ {
218
+ label: 'Success',
219
+ data: [
220
+ [new Date(Date.now() - 24 * 60 * 60 * 1000), 15],
221
+ [new Date(Date.now() - 23 * 60 * 60 * 1000), 12],
222
+ [new Date(Date.now() - 22 * 60 * 60 * 1000), 30],
223
+ [new Date(Date.now() - 21 * 60 * 60 * 1000), 20],
224
+ [new Date(Date.now() - 20 * 60 * 60 * 1000), 25],
225
+ [new Date(Date.now() - 19 * 60 * 60 * 1000), 18],
226
+ [new Date(Date.now() - 18 * 60 * 60 * 1000), 32],
227
+ [new Date(Date.now() - 17 * 60 * 60 * 1000), 19],
228
+ [new Date(Date.now() - 16 * 60 * 60 * 1000), 10],
229
+ [new Date(Date.now() - 15 * 60 * 60 * 1000), 11],
230
+ [new Date(Date.now() - 14 * 60 * 60 * 1000), 12],
231
+ [new Date(Date.now() - 13 * 60 * 60 * 1000), 13],
232
+ [new Date(Date.now() - 12 * 60 * 60 * 1000), 11],
233
+ [new Date(Date.now() - 11 * 60 * 60 * 1000), 17],
234
+ [new Date(Date.now() - 10 * 60 * 60 * 1000), 16],
235
+ [new Date(Date.now() - 9 * 60 * 60 * 1000), 13],
236
+ [new Date(Date.now() - 8 * 60 * 60 * 1000), 15],
237
+ [new Date(Date.now() - 7 * 60 * 60 * 1000), 16],
238
+ [new Date(Date.now() - 6 * 60 * 60 * 1000), 17],
239
+ [new Date(Date.now() - 5 * 60 * 60 * 1000), 18],
240
+ [new Date(Date.now() - 4 * 60 * 60 * 1000), 19],
241
+ [new Date(Date.now() - 3 * 60 * 60 * 1000), 20],
242
+ [new Date(Date.now() - 2 * 60 * 60 * 1000), 21],
243
+ [new Date(Date.now() - 1 * 60 * 60 * 1000), 22],
244
+ ],
245
+ },
246
+ {
247
+ label: 'Failed',
248
+ data: [
249
+ [new Date(Date.now() - 24 * 60 * 60 * 1000), 5],
250
+ [new Date(Date.now() - 23 * 60 * 60 * 1000), 8],
251
+ [new Date(Date.now() - 22 * 60 * 60 * 1000), 2],
252
+ [new Date(Date.now() - 21 * 60 * 60 * 1000), 12],
253
+ [new Date(Date.now() - 20 * 60 * 60 * 1000), 6],
254
+ [new Date(Date.now() - 19 * 60 * 60 * 1000), 9],
255
+ [new Date(Date.now() - 18 * 60 * 60 * 1000), 7],
256
+ [new Date(Date.now() - 17 * 60 * 60 * 1000), 1],
257
+ [new Date(Date.now() - 16 * 60 * 60 * 1000), 1],
258
+ [new Date(Date.now() - 15 * 60 * 60 * 1000), 2],
259
+ [new Date(Date.now() - 14 * 60 * 60 * 1000), 4],
260
+ [new Date(Date.now() - 13 * 60 * 60 * 1000), 2],
261
+ [new Date(Date.now() - 12 * 60 * 60 * 1000), 3],
262
+ [new Date(Date.now() - 11 * 60 * 60 * 1000), 1],
263
+ [new Date(Date.now() - 10 * 60 * 60 * 1000), 1],
264
+ [new Date(Date.now() - 9 * 60 * 60 * 1000), 1],
265
+ [new Date(Date.now() - 8 * 60 * 60 * 1000), 1],
266
+ [new Date(Date.now() - 7 * 60 * 60 * 1000), 1],
267
+ [new Date(Date.now() - 6 * 60 * 60 * 1000), 1],
268
+ [new Date(Date.now() - 5 * 60 * 60 * 1000), 1],
269
+ [new Date(Date.now() - 4 * 60 * 60 * 1000), 5],
270
+ [new Date(Date.now() - 3 * 60 * 60 * 1000), 3],
271
+ [new Date(Date.now() - 2 * 60 * 60 * 1000), 2],
272
+ [new Date(Date.now() - 1 * 60 * 60 * 1000), 1],
273
+ ],
274
+ },
275
+ ] as const;
276
+
277
+ export const TimeLast24Hours: Story = {
278
+ render: () => {
279
+ const theme = useTheme() as CoreUITheme;
280
+ return (
281
+ <ChartLegendWrapper
282
+ colorSet={{
283
+ Success: theme.statusHealthy,
284
+ Failed: theme.statusCritical,
285
+ }}
286
+ >
287
+ <Barchart
288
+ type={{
289
+ type: 'time',
290
+ timeRange: {
291
+ startDate: new Date(
292
+ new Date(Date.now()).setMinutes(0, 0, 0) - 24 * 60 * 60 * 1000,
293
+ ),
294
+ endDate: new Date(new Date(Date.now()).setMinutes(0, 0, 0)),
295
+ interval: 60 * 60 * 1000,
296
+ },
297
+ }}
298
+ bars={timeDataLast24Hours}
299
+ />
300
+ </ChartLegendWrapper>
301
+ );
302
+ },
303
+ };
304
+
305
+ const capacityDataWithUnitRange = [
306
+ {
307
+ label: 'Free',
308
+ data: [
309
+ ['category1', 2000000],
310
+ ['category2', 4000000],
311
+ ['category3', 6000000],
312
+ ],
313
+ },
314
+ {
315
+ label: 'Used',
316
+ data: [
317
+ ['category1', 8000000],
318
+ ['category2', 10000000],
319
+ ['category3', 12000000],
320
+ ],
321
+ },
322
+ ] as const;
323
+
324
+ export const CapacityWithUnitRange: Story = {
325
+ render: () => {
326
+ const theme = useTheme() as CoreUITheme;
327
+ return (
328
+ <ChartLegendWrapper
329
+ colorSet={{
330
+ Free: theme.selectedActive,
331
+ Used: theme.infoSecondary,
332
+ }}
333
+ >
334
+ <Barchart
335
+ type="category"
336
+ bars={capacityDataWithUnitRange}
337
+ unitRange={[
338
+ {
339
+ threshold: 0,
340
+ label: 'B',
341
+ },
342
+ {
343
+ threshold: 1024,
344
+ label: 'KiB',
345
+ },
346
+ {
347
+ threshold: 1024 * 1024,
348
+ label: 'MiB',
349
+ },
350
+ {
351
+ threshold: 1024 * 1024 * 1024,
352
+ label: 'GiB',
353
+ },
354
+ ]}
355
+ />
356
+ </ChartLegendWrapper>
357
+ );
358
+ },
359
+ };
360
+
361
+ const stackedData: BarchartProps<
362
+ {
363
+ label: 'Success' | 'Failed';
364
+ data: [string, number][];
365
+ }[]
366
+ >['bars'] = [
367
+ {
368
+ label: 'Success',
369
+ data: [
370
+ ['category1', 25],
371
+ ['category2', 72],
372
+ ['category3', 52],
373
+ ],
374
+ },
375
+ {
376
+ label: 'Failed',
377
+ data: [
378
+ ['category1', 8],
379
+ ['category2', 10],
380
+ ['category3', 25],
381
+ ],
382
+ },
383
+ ];
384
+
385
+ export const Stacked: Story = {
386
+ render: () => {
387
+ const theme = useTheme() as CoreUITheme;
388
+ return (
389
+ <ChartLegendWrapper
390
+ colorSet={{
391
+ Success: theme.statusHealthy,
392
+ Failed: theme.statusCritical,
393
+ }}
394
+ >
395
+ <Stack direction="vertical" gap="r16">
396
+ <Barchart type="category" bars={stackedData} stacked />
397
+ <ChartLegend shape="rectangle" />
398
+ </Stack>
399
+ </ChartLegendWrapper>
400
+ );
401
+ },
402
+ };
403
+
404
+ export const DefaultSort: Story = {
405
+ render: () => {
406
+ const theme = useTheme() as CoreUITheme;
407
+ const defaultSortData = [
408
+ {
409
+ label: 'Success',
410
+ data: [
411
+ ['AZ', 15],
412
+ ['BB', 10],
413
+ ['CC', 25],
414
+ ['DD', 18],
415
+ ['AA', 22],
416
+ ['EE', 15],
417
+ ],
418
+ },
419
+ {
420
+ label: 'Failed',
421
+ data: [
422
+ ['AZ', 8],
423
+ ['BB', 1],
424
+ ['CC', 3],
425
+ ['DD', 1],
426
+ ['AA', 5],
427
+ ['EE', 5],
428
+ ],
429
+ },
430
+ ] as const;
431
+ const customSort: BarchartSortFn<typeof defaultSortData> = (
432
+ pointA,
433
+ pointB,
434
+ ) => {
435
+ const totalA = pointA.Success + pointA.Failed;
436
+ const totalB = pointB.Success + pointB.Failed;
437
+ return totalA - totalB > 0 ? -1 : totalA - totalB < 0 ? 1 : 0; // Descending order
438
+ };
439
+ return (
440
+ <ChartLegendWrapper
441
+ colorSet={{
442
+ Success: theme.statusHealthy,
443
+ Failed: theme.statusCritical,
444
+ }}
445
+ >
446
+ <Barchart
447
+ type="category"
448
+ stacked
449
+ bars={defaultSortData}
450
+ defaultSort={customSort}
451
+ />
452
+ </ChartLegendWrapper>
453
+ );
454
+ },
455
+ };
456
+
457
+ export const WithCustomTooltip: Story = {
458
+ render: () => {
459
+ const theme = useTheme() as CoreUITheme;
460
+ const exampleData = [
461
+ {
462
+ label: 'Success',
463
+ data: [
464
+ ['category1', 2],
465
+ ['category2', 4],
466
+ ['category3', 6],
467
+ ],
468
+ },
469
+ {
470
+ label: 'Failed',
471
+ data: [
472
+ ['category1', 8],
473
+ ['category2', 10],
474
+ ['category3', 12],
475
+ ],
476
+ },
477
+ ] as const;
478
+ const customTooltip: BarchartTooltipFn<typeof exampleData> = (pointA) => {
479
+ return (
480
+ <Stack
481
+ direction="vertical"
482
+ gap="r4"
483
+ style={{
484
+ width: '150px',
485
+ backgroundColor: 'black',
486
+ padding: '10px',
487
+ borderRadius: '10px',
488
+ color: 'white',
489
+ }}
490
+ >
491
+ <Text style={{ textAlign: 'center', color: 'white' }}>
492
+ {pointA.category}
493
+ </Text>
494
+ {pointA.values.map((point) => (
495
+ <Text
496
+ key={point.label}
497
+ isEmphazed={point.isHovered}
498
+ style={{
499
+ color: point.isHovered ? 'yellow' : 'white',
500
+ }}
501
+ >
502
+ <Wrap>
503
+ <span>{point.label}:</span>
504
+ <span>{point.value}</span>
505
+ </Wrap>
506
+ </Text>
507
+ ))}
508
+ </Stack>
509
+ );
510
+ };
511
+ return (
512
+ <Stack direction="vertical" gap="r16">
513
+ <Text variant="Large">External Tooltip & Sort Functions</Text>
514
+ <Text variant="Basic" color="textSecondary">
515
+ Tooltip and sort functions defined outside with full type safety
516
+ </Text>
517
+ <ChartLegendWrapper
518
+ colorSet={{
519
+ Success: theme.statusHealthy,
520
+ Failed: theme.statusCritical,
521
+ }}
522
+ >
523
+ <Stack direction="vertical" gap="r16">
524
+ <Barchart
525
+ type="category"
526
+ bars={exampleData}
527
+ tooltip={customTooltip}
528
+ height={300}
529
+ />
530
+ <ChartLegend shape="line" />
531
+ </Stack>
532
+ </ChartLegendWrapper>
533
+ </Stack>
534
+ );
535
+ },
536
+ };
537
+
538
+ const exampleData = [
539
+ {
540
+ label: 'Success',
541
+ data: [
542
+ ['category1', 1000000],
543
+ ['category2', 2000000],
544
+ ['category3', 3000000],
545
+ ],
546
+ },
547
+ {
548
+ label: 'Failed',
549
+ data: [
550
+ ['category1', 1000000],
551
+ ['category2', 2000000],
552
+ ['category3', 3000000],
553
+ ],
554
+ },
555
+ ] as const;
556
+
557
+ export const StatusColors: Story = {
558
+ render: () => {
559
+ const theme = useTheme() as CoreUITheme;
560
+ const statusData = [
561
+ {
562
+ label: 'Success Rate',
563
+ data: [
564
+ ['API', 95],
565
+ ['Database', 87],
566
+ ['Queue', 92],
567
+ ],
568
+ },
569
+ {
570
+ label: 'Failed Requests',
571
+ data: [
572
+ ['API', 5],
573
+ ['Database', 13],
574
+ ['Queue', 8],
575
+ ],
576
+ },
577
+ {
578
+ label: 'Warning Events',
579
+ data: [
580
+ ['API', 2],
581
+ ['Database', 4],
582
+ ['Queue', 1],
583
+ ],
584
+ },
585
+ ] as const;
586
+ return (
587
+ <ChartLegendWrapper
588
+ colorSet={{
589
+ 'Success Rate': theme.statusHealthy,
590
+ 'Failed Requests': theme.statusCritical,
591
+ 'Warning Events': theme.statusWarning,
592
+ }}
593
+ >
594
+ <Stack direction="vertical" gap="r16">
595
+ <Barchart
596
+ type="category"
597
+ bars={statusData}
598
+ stacked
599
+ title="System Health Metrics"
600
+ />
601
+ <ChartLegend shape="rectangle" />
602
+ </Stack>
603
+ </ChartLegendWrapper>
604
+ );
605
+ },
606
+ };
607
+
608
+ export const LegendShapes: Story = {
609
+ render: () => {
610
+ const theme = useTheme() as CoreUITheme;
611
+ const exampleData = [
612
+ {
613
+ label: 'Success',
614
+ data: [
615
+ ['category1', 25],
616
+ ['category2', 40],
617
+ ['category3', 35],
618
+ ],
619
+ },
620
+ {
621
+ label: 'Failed',
622
+ data: [
623
+ ['category1', 15],
624
+ ['category2', 20],
625
+ ['category3', 18],
626
+ ],
627
+ },
628
+ {
629
+ label: 'Warning',
630
+ data: [
631
+ ['category1', 8],
632
+ ['category2', 12],
633
+ ['category3', 10],
634
+ ],
635
+ },
636
+ ] as const;
637
+ return (
638
+ <Stack direction="vertical" gap="r24">
639
+ <Text variant="Large">Legend Shapes</Text>
640
+
641
+ <ChartLegendWrapper
642
+ colorSet={{
643
+ Success: theme.statusHealthy,
644
+ Failed: theme.statusCritical,
645
+ Warning: theme.statusWarning,
646
+ }}
647
+ >
648
+ <Stack direction="vertical" gap="r16">
649
+ <Barchart
650
+ type="category"
651
+ bars={exampleData}
652
+ height={200}
653
+ title="Horizontal Rectangle Legend"
654
+ />
655
+ <ChartLegend shape="rectangle" />
656
+ </Stack>
657
+ </ChartLegendWrapper>
658
+ <ChartLegendWrapper
659
+ colorSet={{
660
+ Success: theme.statusHealthy,
661
+ Failed: theme.statusCritical,
662
+ Warning: theme.statusWarning,
663
+ }}
664
+ >
665
+ <Stack direction="vertical" gap="r16">
666
+ <Barchart
667
+ type="category"
668
+ bars={exampleData}
669
+ height={200}
670
+ title="Vertical Line Legend"
671
+ />
672
+ <ChartLegend shape="line" direction="vertical" />
673
+ </Stack>
674
+ </ChartLegendWrapper>
675
+ </Stack>
676
+ );
677
+ },
678
+ };
679
+
680
+ export const BarchartsWithSingleLegend: Story = {
681
+ render: () => {
682
+ const theme = useTheme() as CoreUITheme;
683
+ const exampleData = [
684
+ {
685
+ label: 'Success',
686
+ data: [
687
+ ['category1', 25],
688
+ ['category2', 40],
689
+ ['category3', 35],
690
+ ],
691
+ },
692
+ {
693
+ label: 'Failed',
694
+ data: [
695
+ ['category1', 15],
696
+ ['category2', 20],
697
+ ['category3', 18],
698
+ ],
699
+ },
700
+ {
701
+ label: 'Warning',
702
+ data: [
703
+ ['category1', 8],
704
+ ['category2', 12],
705
+ ['category3', 10],
706
+ ],
707
+ },
708
+ ] as const;
709
+ return (
710
+ <Stack direction="vertical" gap="r24">
711
+ <Text variant="Large">Barcharts with Single Shared Legend</Text>
712
+
713
+ <ChartLegendWrapper
714
+ colorSet={{
715
+ Success: theme.statusHealthy,
716
+ Failed: theme.statusCritical,
717
+ Warning: theme.statusWarning,
718
+ }}
719
+ >
720
+ <Barchart
721
+ type="category"
722
+ bars={exampleData}
723
+ height={200}
724
+ title="Barchart 1"
725
+ />
726
+
727
+ <Barchart
728
+ type="category"
729
+ bars={exampleData}
730
+ height={200}
731
+ title="Barchart 2"
732
+ />
733
+ <ChartLegend shape="rectangle" />
734
+ </ChartLegendWrapper>
735
+ </Stack>
736
+ );
737
+ },
738
+ };
739
+ export const CompleteExample: Story = {
740
+ render: () => {
741
+ const theme = useTheme() as CoreUITheme;
742
+ const [isLoading, setIsLoading] = useState(true);
743
+ const [data, setData] = useState<
744
+ BarchartProps<typeof data>['bars'] | undefined
745
+ >(undefined);
746
+ const customTooltip: BarchartTooltipFn<typeof data> = (pointA) => {
747
+ return (
748
+ <Stack
749
+ direction="vertical"
750
+ gap="r4"
751
+ style={{
752
+ width: '150px',
753
+ backgroundColor: 'black',
754
+ padding: '10px',
755
+ borderRadius: '10px',
756
+ color: 'white',
757
+ }}
758
+ >
759
+ <Text style={{ textAlign: 'center', color: 'white' }}>
760
+ {pointA.category}
761
+ </Text>
762
+ {pointA.values.map((point) => (
763
+ <Text
764
+ key={point.label}
765
+ isEmphazed={point.isHovered}
766
+ style={{
767
+ fontWeight: point.isHovered ? 'bold' : 'normal',
768
+ }}
769
+ >
770
+ <Wrap>
771
+ <span>{point.label}:</span>
772
+ <span>{point.value}</span>
773
+ </Wrap>
774
+ </Text>
775
+ ))}
776
+ </Stack>
777
+ );
778
+ };
779
+ return (
780
+ <div
781
+ style={{
782
+ width: '50%',
783
+ padding: spacing.r16,
784
+ borderRadius: spacing.r8,
785
+ backgroundColor: theme.backgroundLevel2,
786
+ }}
787
+ >
788
+ <ChartLegendWrapper
789
+ colorSet={{
790
+ Success: 'lineColor1',
791
+ Failed: 'lineColor2',
792
+ }}
793
+ >
794
+ <Barchart
795
+ type="category"
796
+ title="Loading BarChart"
797
+ helpTooltip="Click on the button to load or unload data"
798
+ secondaryTitle={isLoading ? 'Loading...' : 'Loaded data'}
799
+ rightTitle={
800
+ <Button
801
+ label={isLoading ? 'Load data' : 'Fake loading data'}
802
+ onClick={() => {
803
+ setIsLoading(!isLoading);
804
+ if (isLoading) {
805
+ setData(exampleData);
806
+ } else {
807
+ setData(undefined);
808
+ }
809
+ }}
810
+ />
811
+ }
812
+ bars={data || []}
813
+ tooltip={customTooltip}
814
+ isLoading={isLoading}
815
+ height={200}
816
+ />
817
+ <ChartLegend shape="rectangle" direction="horizontal" />
818
+ </ChartLegendWrapper>
819
+ </div>
820
+ );
821
+ },
822
+ };