@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,321 @@
1
+ import { useState } from 'react';
2
+ import {
3
+ Bar,
4
+ BarChart,
5
+ CartesianGrid,
6
+ ReferenceLine,
7
+ ResponsiveContainer,
8
+ Tooltip,
9
+ TooltipContentProps,
10
+ XAxis,
11
+ YAxis,
12
+ } from 'recharts';
13
+ import styled, { useTheme } from 'styled-components';
14
+ import { spacing, Stack, Wrap } from '../../spacing';
15
+ import { chartColors, ChartColors, fontSize } from '../../style/theme';
16
+ import { Box } from '../box/Box';
17
+ import { ConstrainedText } from '../constrainedtext/Constrainedtext.component';
18
+ import { IconHelp } from '../iconhelper/IconHelper';
19
+ import { Loader } from '../loader/Loader.component';
20
+ import { Text } from '../text/Text.component';
21
+ import { renderTooltipContent, UnitRange, useChartData } from './utils';
22
+ import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
23
+
24
+ const CHART_CONSTANTS = {
25
+ TICK_WIDTH_OFFSET: 5,
26
+ BAR_SIZE: 12,
27
+ MIN_POINT_SIZE: 1,
28
+ DEFAULT_HEIGHT: 200,
29
+ CHART_MARGIN: {
30
+ left: 0,
31
+ right: 0,
32
+ top: 0,
33
+ bottom: 0,
34
+ },
35
+ } as const;
36
+
37
+ /* ---------------------------------- TYPE ---------------------------------- */
38
+
39
+ export type TimeType = {
40
+ type: 'time';
41
+ timeRange: {
42
+ startDate: Date;
43
+ endDate: Date;
44
+ interval: number;
45
+ };
46
+ };
47
+ export type Point = {
48
+ key: string | number;
49
+ values: { label: string; value: number }[];
50
+ };
51
+
52
+ export type BarchartBars = readonly {
53
+ readonly label: string;
54
+ /**
55
+ * When using a time type, the data should be an array of [Date, value]
56
+ * so use Date instead of timestamp for transformation data in format fn
57
+ */
58
+ readonly data: readonly (readonly [string | Date, number | string])[];
59
+ }[];
60
+
61
+ export type BarchartTooltipFn<T extends BarchartBars> = (currentPoint: {
62
+ category: string | number;
63
+ values: { label: T[number]['label']; value: number; isHovered: boolean }[];
64
+ }) => React.ReactNode;
65
+
66
+ export type BarchartSortFn<T extends BarchartBars> = (
67
+ pointA: Record<T[number]['label'], number> & { category: string | number },
68
+ pointB: Record<T[number]['label'], number> & { category: string | number },
69
+ ) => 1 | -1 | 0;
70
+
71
+ export type BarchartProps<T extends BarchartBars> = {
72
+ type: 'category' | TimeType;
73
+ bars: T;
74
+ tooltip?: BarchartTooltipFn<T>;
75
+ defaultSort?: BarchartSortFn<T>;
76
+ unitRange?: UnitRange;
77
+ helpTooltip?: string;
78
+ stacked?: boolean;
79
+ title?: string;
80
+ secondaryTitle?: string;
81
+ rightTitle?: React.ReactNode;
82
+ height?: number;
83
+ isLoading?: boolean;
84
+ };
85
+
86
+ interface CustomTickProps {
87
+ x: number;
88
+ y: number;
89
+ payload: {
90
+ value: string | number;
91
+ };
92
+ visibleTicksCount: number;
93
+ width: number;
94
+ }
95
+
96
+ /* ---------------------------------- COMPONENTS ---------------------------------- */
97
+
98
+ const CustomTick = ({
99
+ x,
100
+ y,
101
+ payload,
102
+ visibleTicksCount,
103
+ width,
104
+ }: CustomTickProps) => {
105
+ const theme = useTheme();
106
+ const tickWidth =
107
+ width / visibleTicksCount - CHART_CONSTANTS.TICK_WIDTH_OFFSET;
108
+ const centerX = x - tickWidth / 2;
109
+
110
+ return (
111
+ <foreignObject
112
+ x={centerX}
113
+ y={y}
114
+ width={tickWidth}
115
+ color={theme.textSecondary}
116
+ overflow="visible"
117
+ >
118
+ <ConstrainedText
119
+ text={
120
+ <Text variant="Smaller" color="textSecondary">
121
+ {String(payload.value)}
122
+ </Text>
123
+ }
124
+ centered
125
+ tooltipStyle={{
126
+ backgroundColor: theme.backgroundLevel1,
127
+ padding: spacing.r10,
128
+ borderRadius: spacing.r8,
129
+ border: `1px solid ${theme.border}`,
130
+ position: 'absolute',
131
+ }}
132
+ />
133
+ </foreignObject>
134
+ );
135
+ };
136
+
137
+ const StyledResponsiveContainer = styled(ResponsiveContainer)`
138
+ // Avoid tooltip over constrained text to be cut off
139
+ & .recharts-surface {
140
+ overflow: visible;
141
+ }
142
+ `;
143
+
144
+ const ChartHeader = ({
145
+ title,
146
+ secondaryTitle,
147
+ helpTooltip,
148
+ rightTitle,
149
+ }: {
150
+ title?: string;
151
+ secondaryTitle?: string;
152
+ helpTooltip?: string;
153
+ rightTitle?: React.ReactNode;
154
+ }) => {
155
+ return (
156
+ <Wrap>
157
+ <Stack gap="r4">
158
+ <Text variant="ChartTitle">{title}</Text>
159
+ {helpTooltip && (
160
+ <IconHelp tooltipMessage={helpTooltip} title={helpTooltip} />
161
+ )}
162
+
163
+ {secondaryTitle && (
164
+ <Text
165
+ color="textSecondary"
166
+ style={{
167
+ marginLeft: spacing.r8,
168
+ }}
169
+ >
170
+ {secondaryTitle}
171
+ </Text>
172
+ )}
173
+ </Stack>
174
+
175
+ {rightTitle && <Text>{rightTitle}</Text>}
176
+ </Wrap>
177
+ );
178
+ };
179
+
180
+ const Loading = ({ height }: { height: number }) => {
181
+ return (
182
+ <Box
183
+ height={height}
184
+ style={{
185
+ alignItems: 'center',
186
+ justifyContent: 'center',
187
+ display: 'flex',
188
+ }}
189
+ >
190
+ <Loader size="larger" children={<Text>Loading Chart Data...</Text>} />
191
+ </Box>
192
+ );
193
+ };
194
+
195
+ /* ---------------------------------- MAIN COMPONENT ---------------------------------- */
196
+
197
+ export const Barchart = <T extends BarchartBars>(props: BarchartProps<T>) => {
198
+ const theme = useTheme();
199
+ const { getColor } = useChartLegend();
200
+ const [hoveredValue, setHoveredValue] = useState<string | undefined>();
201
+
202
+ const {
203
+ height = CHART_CONSTANTS.DEFAULT_HEIGHT,
204
+ bars,
205
+ type = 'category',
206
+ unitRange,
207
+ stacked,
208
+ defaultSort,
209
+ tooltip,
210
+ title,
211
+ secondaryTitle,
212
+ helpTooltip,
213
+ rightTitle,
214
+ isLoading,
215
+ } = props;
216
+
217
+ // Create colorSet from ChartLegendWrapper
218
+ const colorSet = bars.reduce(
219
+ (acc, bar) => {
220
+ const color = getColor(bar.label);
221
+ if (color) {
222
+ acc[bar.label] = color;
223
+ }
224
+ return acc;
225
+ },
226
+ {} as Record<string, ChartColors | string>,
227
+ );
228
+
229
+ const { rechartsBars, unitLabel, roundReferenceValue, rechartsData } =
230
+ useChartData(bars, type, colorSet, stacked, defaultSort, unitRange);
231
+
232
+ return (
233
+ <Stack direction="vertical" gap="r8">
234
+ <ChartHeader
235
+ title={title}
236
+ secondaryTitle={secondaryTitle}
237
+ helpTooltip={helpTooltip}
238
+ rightTitle={rightTitle}
239
+ />
240
+ {isLoading ? (
241
+ <Loading height={height} />
242
+ ) : (
243
+ <StyledResponsiveContainer width="100%" height={height}>
244
+ <BarChart
245
+ data={rechartsData}
246
+ accessibilityLayer
247
+ barSize={CHART_CONSTANTS.BAR_SIZE}
248
+ height={height}
249
+ margin={CHART_CONSTANTS.CHART_MARGIN}
250
+ >
251
+ <CartesianGrid
252
+ vertical={false}
253
+ horizontal={false}
254
+ fill={theme.backgroundLevel1}
255
+ />
256
+ {rechartsBars.map((bar) => {
257
+ const { fill, dataKey, stackId } = bar;
258
+ return (
259
+ <Bar
260
+ key={dataKey}
261
+ dataKey={dataKey}
262
+ fill={chartColors[fill] || fill}
263
+ minPointSize={CHART_CONSTANTS.MIN_POINT_SIZE}
264
+ stackId={stackId}
265
+ onMouseOver={() => setHoveredValue(dataKey)}
266
+ onMouseLeave={() => setHoveredValue(undefined)}
267
+ />
268
+ );
269
+ })}
270
+
271
+ <YAxis
272
+ tickCount={1}
273
+ unit={` ${unitLabel}`}
274
+ domain={[0, roundReferenceValue]}
275
+ tickFormatter={
276
+ (value) =>
277
+ new Intl.NumberFormat('fr-FR').format(value.toFixed(0)) // Add a space as thousand separator
278
+ }
279
+ axisLine={false}
280
+ tick={{
281
+ fill: theme.textSecondary,
282
+ fontSize: fontSize.smaller,
283
+ }}
284
+ tickLine={false}
285
+ label={{
286
+ fill: theme.textSecondary,
287
+ }}
288
+ orientation="right"
289
+ />
290
+
291
+ <ReferenceLine
292
+ y={roundReferenceValue}
293
+ fill={theme.border}
294
+ strokeWidth={0.5} // Reduce stroke width to make it less visible
295
+ />
296
+ <XAxis
297
+ dataKey="category"
298
+ tick={(props) => <CustomTick {...props} />}
299
+ type="category"
300
+ interval={0}
301
+ allowDataOverflow={true}
302
+ tickLine={{
303
+ stroke: theme.textSecondary,
304
+ }}
305
+ axisLine={{
306
+ stroke: theme.textSecondary,
307
+ }}
308
+ />
309
+
310
+ <Tooltip
311
+ content={(props: TooltipContentProps<number, string>) =>
312
+ renderTooltipContent(props, tooltip, hoveredValue)
313
+ }
314
+ cursor={false}
315
+ />
316
+ </BarChart>
317
+ </StyledResponsiveContainer>
318
+ )}
319
+ </Stack>
320
+ );
321
+ };