@takaro/lib-components 0.4.9 → 0.4.11

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 (58) hide show
  1. package/package.json +13 -6
  2. package/src/components/actions/Button/__snapshots__/Button.test.tsx.snap +1 -1
  3. package/src/components/actions/IconButton/__snapshots__/IconButton.test.tsx.snap +1 -1
  4. package/src/components/charts/AreaChart/AreaChart.stories.tsx +11 -7
  5. package/src/components/charts/AreaChart/index.tsx +114 -63
  6. package/src/components/charts/BarChart/BarChart.stories.tsx +33 -10
  7. package/src/components/charts/BarChart/index.tsx +280 -147
  8. package/src/components/charts/EmptyChart.tsx +45 -0
  9. package/src/components/charts/GeoMercator/GeoMercator.stories.tsx +15 -9
  10. package/src/components/charts/GeoMercator/index.tsx +15 -172
  11. package/src/components/charts/Heatmap/Heatmap.stories.tsx +167 -33
  12. package/src/components/charts/Heatmap/index.tsx +427 -193
  13. package/src/components/charts/LineChart/LineChart.stories.tsx +77 -3
  14. package/src/components/charts/LineChart/index.tsx +200 -79
  15. package/src/components/charts/PieChart/PieChart.stories.tsx +128 -20
  16. package/src/components/charts/PieChart/index.tsx +353 -59
  17. package/src/components/charts/PointHighlight.tsx +2 -2
  18. package/src/components/charts/RadarChart/RadarChart.stories.tsx +14 -5
  19. package/src/components/charts/RadarChart/index.tsx +94 -45
  20. package/src/components/charts/RadialBarChart/RadialBarChart.stories.tsx +26 -1
  21. package/src/components/charts/RadialBarChart/index.tsx +100 -34
  22. package/src/components/charts/RadialLineChart/RadialLineChart.stories.tsx +19 -2
  23. package/src/components/charts/RadialLineChart/index.tsx +116 -26
  24. package/src/components/charts/index.tsx +0 -26
  25. package/src/components/charts/util.ts +50 -12
  26. package/src/components/data/CountryList/index.tsx +146 -0
  27. package/src/components/data/Stats/Sparkline.tsx +48 -0
  28. package/src/components/data/Stats/Stat.tsx +15 -4
  29. package/src/components/data/Stats/context.tsx +1 -1
  30. package/src/components/data/Stats/index.tsx +8 -3
  31. package/src/components/data/index.ts +3 -0
  32. package/src/components/feedback/IconTooltip/index.tsx +9 -6
  33. package/src/components/feedback/ProgressBar/ProgressBar.stories.tsx +13 -14
  34. package/src/components/feedback/ProgressBar/index.tsx +1 -1
  35. package/src/components/inputs/DurationField/__tests__/Generic.test.tsx +12 -0
  36. package/src/components/visual/Card/CardTitle.tsx +7 -1
  37. package/src/components/visual/Card/index.tsx +0 -4
  38. package/src/helpers/formatNumber.ts +6 -0
  39. package/src/helpers/index.ts +1 -0
  40. package/vite.config.mts +4 -0
  41. package/src/components/charts/echarts/EChartsArea.stories.tsx +0 -139
  42. package/src/components/charts/echarts/EChartsArea.tsx +0 -139
  43. package/src/components/charts/echarts/EChartsBar.stories.tsx +0 -141
  44. package/src/components/charts/echarts/EChartsBar.tsx +0 -133
  45. package/src/components/charts/echarts/EChartsBase.tsx +0 -264
  46. package/src/components/charts/echarts/EChartsFunnel.stories.tsx +0 -164
  47. package/src/components/charts/echarts/EChartsFunnel.tsx +0 -114
  48. package/src/components/charts/echarts/EChartsHeatmap.stories.tsx +0 -168
  49. package/src/components/charts/echarts/EChartsHeatmap.tsx +0 -141
  50. package/src/components/charts/echarts/EChartsLine.stories.tsx +0 -132
  51. package/src/components/charts/echarts/EChartsLine.tsx +0 -111
  52. package/src/components/charts/echarts/EChartsPie.stories.tsx +0 -131
  53. package/src/components/charts/echarts/EChartsPie.tsx +0 -124
  54. package/src/components/charts/echarts/EChartsRadialBar.stories.tsx +0 -124
  55. package/src/components/charts/echarts/EChartsRadialBar.tsx +0 -118
  56. package/src/components/charts/echarts/EChartsScatter.stories.tsx +0 -166
  57. package/src/components/charts/echarts/EChartsScatter.tsx +0 -135
  58. package/src/components/charts/echarts/index.ts +0 -26
package/package.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "name": "@takaro/lib-components",
3
- "version": "0.4.9",
4
- "private": false,
5
3
  "description": "Takaro UI is a simple and customizable component library to build React apps faster within the Takaro eco system",
4
+ "version": "0.4.11",
5
+ "dependencies": {
6
+ "dnd-core": "16.0.1"
7
+ },
8
+ "devDependencies": {
9
+ "@storybook/react": "10.0.6",
10
+ "vitest": "4.0.8"
11
+ },
6
12
  "license": "AGPL-3.0-or-later",
7
13
  "main": "src/index.ts",
8
- "types": "src/index.ts",
14
+ "private": false,
9
15
  "scripts": {
10
16
  "build": "storybook build -c ../../.storybook",
11
17
  "start:dev": "storybook dev --no-open -c ../../.storybook -p 13002",
12
- "test:unit": "CI=true vitest",
13
- "test:snapshot": "vitest -u"
14
- }
18
+ "test:snapshot": "vitest -u",
19
+ "test:unit": "CI=true vitest"
20
+ },
21
+ "types": "src/index.ts"
15
22
  }
@@ -3,7 +3,7 @@
3
3
  exports[`Should render <Button/> 1`] = `
4
4
  <div>
5
5
  <button
6
- class="sc-pKqro cGkgJf"
6
+ class="sc-ggqIjW dRTgIR"
7
7
  color="primary"
8
8
  tabindex="0"
9
9
  type="button"
@@ -4,7 +4,7 @@ exports[`Should render <IconButton /> 1`] = `
4
4
  <div>
5
5
  <button
6
6
  aria-label="test"
7
- class="sc-dBFDNq bubVam"
7
+ class="sc-epRvzc floJoN"
8
8
  color="primary"
9
9
  type="button"
10
10
  >
@@ -12,9 +12,10 @@ export default {
12
12
  component: AreaChart,
13
13
  args: {
14
14
  showBrush: true,
15
- showGrid: true,
16
15
  axisXLabel: '',
17
16
  axisYLabel: 'Close Price',
17
+ grid: 'none',
18
+ animate: true,
18
19
  },
19
20
  } as Meta<AreaChartProps<AppleStock>>;
20
21
 
@@ -33,10 +34,12 @@ export const Default: StoryFn<AreaChartProps<AppleStock>> = (args) => {
33
34
  xAccessor={getDate}
34
35
  yAccessor={getStockValue}
35
36
  data={appleStock}
36
- showBrush={args.showBrush}
37
- showGrid={args.showGrid}
38
- axisXLabel={args.axisXLabel}
39
- axisYLabel={args.axisYLabel}
37
+ axis={{
38
+ labelX: args.axis?.labelX,
39
+ labelY: args.axis?.labelY,
40
+ }}
41
+ grid={args.grid}
42
+ animate={args.animate}
40
43
  />
41
44
  </Wrapper>
42
45
  );
@@ -87,9 +90,10 @@ export const PingExample: StoryFn = () => {
87
90
  name="Ping"
88
91
  xAccessor={getDate}
89
92
  yAccessor={getLatency}
90
- tooltipAccessor={tooltipAccessor}
93
+ tooltip={{
94
+ accessor: tooltipAccessor,
95
+ }}
91
96
  data={generateData()}
92
- showBrush={false}
93
97
  />
94
98
  </div>
95
99
  </Card.Body>
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useMemo, useRef, useState } from 'react';
2
2
 
3
3
  import { ParentSize } from '@visx/responsive';
4
- import { GridColumns } from '@visx/grid';
4
+ import { GridColumns, GridRows } from '@visx/grid';
5
5
  import { Group } from '@visx/group';
6
6
  import { AreaClosed, Bar } from '@visx/shape';
7
7
  import { max, extent, bisector } from '@visx/vendor/d3-array';
@@ -14,21 +14,23 @@ import { timeFormat } from '@visx/vendor/d3-time-format';
14
14
  import { PatternLines } from '@visx/pattern';
15
15
  import { Brush } from '@visx/brush';
16
16
  import { Bounds } from '@visx/brush/lib/types';
17
+ import { motion } from 'framer-motion';
17
18
 
18
19
  import { useTheme } from '../../../hooks';
19
20
  import { useGradients } from '../useGradients';
20
- import { Margin, ChartProps, InnerChartProps, getDefaultTooltipStyles } from '../util';
21
+ import { ChartProps, InnerChartProps, getDefaultTooltipStyles, TooltipConfig, BrushConfig } from '../util';
21
22
  import { BrushHandle } from '../BrushHandle';
22
23
  import { PointHighlight } from '../PointHighlight';
24
+ import { EmptyChart } from '../EmptyChart';
23
25
 
24
26
  export interface AreaChartProps<T> extends ChartProps {
25
27
  data: T[];
26
28
  xAccessor: (d: T) => Date;
27
29
  yAccessor: (d: T) => number;
28
- tooltipAccessor?: (d: T) => string;
29
- margin?: Margin;
30
- showBrush?: boolean;
31
- brushMargin?: Margin;
30
+ /** Tooltip configuration */
31
+ tooltip?: TooltipConfig<T>;
32
+ /** Brush/zoom configuration */
33
+ brush?: BrushConfig;
32
34
  }
33
35
 
34
36
  const formatDate = timeFormat("%b %d, '%y");
@@ -37,48 +39,41 @@ const defaultMargin = { top: 20, left: 50, bottom: 20, right: 5 };
37
39
  const defaultBrushMargin = { top: 10, bottom: 15, left: 50, right: 5 };
38
40
  const defaultShowAxisX = true;
39
41
  const defaultShowAxisY = true;
40
- const defaultShowGrid = true;
41
42
 
42
43
  export const AreaChart = <T,>({
43
44
  data,
44
45
  xAccessor,
45
46
  yAccessor,
46
- tooltipAccessor,
47
- margin = defaultMargin,
48
- showGrid = defaultShowGrid,
49
- showBrush = false,
50
- brushMargin = defaultBrushMargin,
51
47
  name,
52
- showAxisX = defaultShowAxisX,
53
- showAxisY = defaultShowAxisY,
54
- axisXLabel,
55
- axisYLabel,
48
+ grid = 'none',
49
+ axis,
50
+ tooltip,
51
+ brush,
52
+ animate = true,
53
+ margin = defaultMargin,
56
54
  }: AreaChartProps<T>) => {
57
- // TODO: handle empty data
58
- if (!data || data.length === 0) return null;
55
+ const hasData = data && data.length > 0;
59
56
 
60
- // TODO: handle loading state
61
57
  return (
62
58
  <ParentSize>
63
- {(parent) => (
64
- <Chart<T>
65
- name={name}
66
- xAccessor={xAccessor}
67
- yAccessor={yAccessor}
68
- tooltipAccessor={tooltipAccessor}
69
- data={data}
70
- width={parent.width}
71
- height={parent.height}
72
- brushMargin={brushMargin}
73
- showBrush={showBrush}
74
- showGrid={showGrid}
75
- margin={margin}
76
- axisYLabel={axisYLabel}
77
- axisXLabel={axisXLabel}
78
- showAxisX={showAxisX}
79
- showAxisY={showAxisY}
80
- />
81
- )}
59
+ {hasData
60
+ ? (parent) => (
61
+ <Chart<T>
62
+ name={name}
63
+ xAccessor={xAccessor}
64
+ yAccessor={yAccessor}
65
+ data={data}
66
+ width={parent.width}
67
+ height={parent.height}
68
+ grid={grid}
69
+ axis={axis}
70
+ tooltip={tooltip}
71
+ brush={brush}
72
+ animate={animate}
73
+ margin={margin}
74
+ />
75
+ )
76
+ : () => <EmptyChart />}
82
77
  </ParentSize>
83
78
  );
84
79
  };
@@ -89,19 +84,25 @@ const Chart = <T,>({
89
84
  data,
90
85
  xAccessor,
91
86
  yAccessor,
92
- tooltipAccessor,
93
87
  width,
94
88
  height,
95
89
  margin = defaultMargin,
96
- showGrid = defaultShowGrid,
97
- showBrush = false,
98
- brushMargin = defaultBrushMargin,
90
+ grid = 'none',
91
+ axis,
92
+ tooltip,
93
+ brush,
94
+ animate = true,
99
95
  name,
100
- showAxisX = defaultShowAxisX,
101
- showAxisY = defaultShowAxisY,
102
- axisYLabel,
103
- axisXLabel,
104
96
  }: InnerAreaChartProps<T>) => {
97
+ const showAxisX = axis?.showX ?? defaultShowAxisX;
98
+ const showAxisY = axis?.showY ?? defaultShowAxisY;
99
+ const axisXLabel = axis?.labelX;
100
+ const axisYLabel = axis?.labelY;
101
+ const tooltipAccessor = tooltip?.accessor;
102
+
103
+ // Extract brush configuration
104
+ const showBrush = brush?.enabled ?? false;
105
+ const brushMargin = brush?.margin ?? defaultBrushMargin;
105
106
  const PATTERN_ID = `${name}-brush_pattern`;
106
107
  const theme = useTheme();
107
108
  const gradients = useGradients(name);
@@ -219,21 +220,27 @@ const Chart = <T,>({
219
220
  <div>
220
221
  <svg width={width} height={height}>
221
222
  {gradients.chart.gradient}
222
- {gradients.background.gradient}
223
- <rect x={0} y={0} width={width} height={height} fill={`url(#${gradients.background.id})`} rx={14} />
224
- {showGrid && (
225
- <GridColumns
226
- top={margin.top}
227
- left={margin.left}
228
- scale={xScale}
229
- height={yMax}
230
- strokeDasharray="1,5"
231
- stroke={theme.colors.backgroundAccent}
232
- strokeOpacity={0.2}
233
- pointerEvents="none"
234
- />
235
- )}
236
223
  <Group id="chart" top={margin.top} left={margin.left}>
224
+ {(grid === 'y' || grid === 'xy') && (
225
+ <GridRows
226
+ scale={yScale}
227
+ width={xMax}
228
+ stroke={theme.colors.backgroundAccent}
229
+ strokeOpacity={1}
230
+ strokeDasharray="2,2"
231
+ pointerEvents="none"
232
+ />
233
+ )}
234
+ {(grid === 'x' || grid === 'xy') && (
235
+ <GridColumns
236
+ scale={xScale}
237
+ height={yMax}
238
+ stroke={theme.colors.backgroundAccent}
239
+ strokeOpacity={1}
240
+ strokeDasharray="2,2"
241
+ pointerEvents="none"
242
+ />
243
+ )}
237
244
  <AreaClosed<T>
238
245
  x={(d) => xScale(xAccessor(d)) ?? 0}
239
246
  y={(d) => yScale(yAccessor(d)) ?? 0}
@@ -243,7 +250,29 @@ const Chart = <T,>({
243
250
  stroke={theme.colors.primary}
244
251
  fill={`url(#${gradients.chart.id})`}
245
252
  curve={curveMonotoneX}
246
- />
253
+ >
254
+ {({ path }) => {
255
+ const pathData = path(filteredData) || '';
256
+ return (
257
+ <motion.path
258
+ d={pathData}
259
+ stroke={theme.colors.primary}
260
+ strokeWidth={1}
261
+ fill={`url(#${gradients.chart.id})`}
262
+ initial={animate ? { pathLength: 0, opacity: 0 } : { pathLength: 1, opacity: 1 }}
263
+ animate={{ pathLength: 1, opacity: 1 }}
264
+ transition={
265
+ animate
266
+ ? {
267
+ pathLength: { duration: 1, ease: 'easeInOut' },
268
+ opacity: { duration: 0.8, ease: 'easeInOut' },
269
+ }
270
+ : { duration: 0 }
271
+ }
272
+ />
273
+ );
274
+ }}
275
+ </AreaClosed>
247
276
  </Group>
248
277
  <Bar
249
278
  x={margin.left}
@@ -273,7 +302,29 @@ const Chart = <T,>({
273
302
  stroke={`url(#${gradients.chart.id})`}
274
303
  fill={`url(#${gradients.chart.id})`}
275
304
  curve={curveMonotoneX}
276
- />
305
+ >
306
+ {({ path }) => {
307
+ const pathData = path(data) || '';
308
+ return (
309
+ <motion.path
310
+ d={pathData}
311
+ stroke={`url(#${gradients.chart.id})`}
312
+ strokeWidth={1}
313
+ fill={`url(#${gradients.chart.id})`}
314
+ initial={animate ? { pathLength: 0, opacity: 0 } : { pathLength: 1, opacity: 1 }}
315
+ animate={{ pathLength: 1, opacity: 1 }}
316
+ transition={
317
+ animate
318
+ ? {
319
+ pathLength: { duration: 0.5, ease: 'easeInOut' },
320
+ opacity: { duration: 0.4, ease: 'easeInOut' },
321
+ }
322
+ : { duration: 0 }
323
+ }
324
+ />
325
+ );
326
+ }}
327
+ </AreaClosed>
277
328
  <PatternLines
278
329
  id={PATTERN_ID}
279
330
  height={8}
@@ -334,7 +385,7 @@ const Chart = <T,>({
334
385
  tickLabelProps={{
335
386
  fill: theme.colors.textAlt,
336
387
  fontSize: theme.fontSize.small,
337
- textAnchor: 'end',
388
+ textAnchor: 'middle',
338
389
  }}
339
390
  tickFormat={tickFormatDate}
340
391
  labelProps={{
@@ -4,28 +4,51 @@ import { BarChart, BarChartProps } from '.';
4
4
  import { styled } from '../../../styled';
5
5
  import letterFrequency, { LetterFrequency } from '@visx/mock-data/lib/mocks/letterFrequency';
6
6
 
7
- export default {
8
- title: 'Charts/BarChart',
9
- component: BarChart,
10
- } as Meta<BarChartProps<LetterFrequency>>;
11
-
12
7
  const Wrapper = styled.div`
13
8
  height: 50vh;
14
9
  width: 100%;
15
10
  `;
16
11
 
17
- export const Default: StoryFn<BarChartProps<LetterFrequency>> = () => {
18
- const getLetter = (d: LetterFrequency) => d.letter;
19
- const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
12
+ const getLetter = (d: LetterFrequency) => d.letter;
13
+ const getLetterFrequency = (d: LetterFrequency) => Number(d.frequency) * 100;
14
+
15
+ export default {
16
+ title: 'Charts/BarChart',
17
+ component: BarChart,
18
+ args: {
19
+ name: 'letterFrequency',
20
+ grid: 'xy',
21
+ barWidth: 0.6,
22
+ tooltip: {
23
+ enabled: true,
24
+ accessor: (d: LetterFrequency) => `${d.letter}: ${getLetterFrequency(d).toFixed(1)}%`,
25
+ },
26
+ brush: {
27
+ enabled: false,
28
+ },
29
+ axis: {
30
+ showX: true,
31
+ showY: true,
32
+ labelX: 'Letter',
33
+ labelY: 'Frequency (%)',
34
+ },
35
+ },
36
+ argTypes: {
37
+ barWidth: {
38
+ control: { type: 'range', min: 0.1, max: 1, step: 0.05 },
39
+ description: 'Bar width as percentage (0-1). 1.0 = bars touch (no gaps)',
40
+ },
41
+ },
42
+ } as Meta<BarChartProps<LetterFrequency>>;
20
43
 
44
+ export const Default: StoryFn<BarChartProps<LetterFrequency>> = (args) => {
21
45
  return (
22
46
  <Wrapper>
23
47
  <BarChart<LetterFrequency>
24
- name="letterFrequency"
48
+ {...args}
25
49
  xAccessor={getLetter}
26
50
  yAccessor={getLetterFrequency}
27
51
  data={letterFrequency}
28
- showBrush={true}
29
52
  />
30
53
  </Wrapper>
31
54
  );