@hero-design/rn 8.99.4 → 8.100.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 (121) hide show
  1. package/.turbo/turbo-build.log +8 -3
  2. package/CHANGELOG.md +17 -0
  3. package/es/index.js +5621 -690
  4. package/jest.config.js +1 -1
  5. package/lib/index.js +5545 -613
  6. package/package.json +4 -2
  7. package/src/components/Avatar/AvatarStack/utils.ts +6 -4
  8. package/src/components/Badge/Status.tsx +1 -1
  9. package/src/components/Badge/__tests__/Status.spec.tsx +20 -0
  10. package/src/components/Badge/__tests__/__snapshots__/Status.spec.tsx.snap +2 -0
  11. package/src/components/Chart/ChartSelect/StyledChartSelect.tsx +9 -0
  12. package/src/components/Chart/ChartSelect/__tests__/StyledChartSelect.spec.tsx +15 -0
  13. package/src/components/Chart/ChartSelect/__tests__/__snapshots__/StyledChartSelect.spec.tsx.snap +20 -0
  14. package/src/components/Chart/ChartSelect/__tests__/index.spec.tsx +111 -0
  15. package/src/components/Chart/ChartSelect/index.tsx +137 -0
  16. package/src/components/Chart/ColumnChart/ColumnChartContent.tsx +84 -0
  17. package/src/components/Chart/ColumnChart/Segment.tsx +66 -0
  18. package/src/components/Chart/ColumnChart/StackedSegment.tsx +99 -0
  19. package/src/components/Chart/ColumnChart/StyledColumnChart.tsx +9 -0
  20. package/src/components/Chart/ColumnChart/__tests__/ColumnChartContent.spec.tsx +68 -0
  21. package/src/components/Chart/ColumnChart/__tests__/Segment.spec.tsx +99 -0
  22. package/src/components/Chart/ColumnChart/__tests__/StackedSegment.spec.tsx +115 -0
  23. package/src/components/Chart/ColumnChart/__tests__/__snapshots__/StackedSegment.spec.tsx.snap +120 -0
  24. package/src/components/Chart/ColumnChart/__tests__/__snapshots__/index.spec.tsx.snap +1405 -0
  25. package/src/components/Chart/ColumnChart/__tests__/index.spec.tsx +134 -0
  26. package/src/components/Chart/ColumnChart/index.tsx +216 -0
  27. package/src/components/Chart/Line/Line.tsx +81 -0
  28. package/src/components/Chart/Line/__tests__/Line.spec.tsx +148 -0
  29. package/src/components/Chart/Line/__tests__/__snapshots__/Line.spec.tsx.snap +56 -0
  30. package/src/components/Chart/Line/__tests__/__snapshots__/index.spec.tsx.snap +1461 -0
  31. package/src/components/Chart/Line/__tests__/index.spec.tsx +112 -0
  32. package/src/components/Chart/Line/index.tsx +143 -0
  33. package/src/components/Chart/StyledChart.tsx +16 -0
  34. package/src/components/Chart/index.tsx +13 -0
  35. package/src/components/Chart/shared/AxisLabel.tsx +25 -0
  36. package/src/components/Chart/shared/ChartFrame.tsx +131 -0
  37. package/src/components/Chart/shared/ChartHeader.tsx +19 -0
  38. package/src/components/Chart/shared/EmptyState.tsx +83 -0
  39. package/src/components/Chart/shared/XAxis.tsx +69 -0
  40. package/src/components/Chart/shared/XAxisGrid.tsx +42 -0
  41. package/src/components/Chart/shared/YAxis.tsx +104 -0
  42. package/src/components/Chart/shared/YAxisGrid.tsx +58 -0
  43. package/src/components/Chart/shared/__tests__/ChartFrame.spec.tsx +125 -0
  44. package/src/components/Chart/shared/__tests__/ChartHeader.spec.tsx +22 -0
  45. package/src/components/Chart/shared/__tests__/EmptyState.spec.tsx +29 -0
  46. package/src/components/Chart/shared/__tests__/XAXisGrid.spec.tsx +30 -0
  47. package/src/components/Chart/shared/__tests__/XAxis.spec.tsx +42 -0
  48. package/src/components/Chart/shared/__tests__/YAxis.spec.tsx +72 -0
  49. package/src/components/Chart/shared/__tests__/YAxisGrid.spec.tsx +35 -0
  50. package/src/components/Chart/shared/__tests__/__snapshots__/ChartFrame.spec.tsx.snap +3058 -0
  51. package/src/components/Chart/shared/__tests__/__snapshots__/ChartHeader.spec.tsx.snap +160 -0
  52. package/src/components/Chart/shared/__tests__/__snapshots__/EmptyState.spec.tsx.snap +155 -0
  53. package/src/components/Chart/shared/__tests__/__snapshots__/XAXisGrid.spec.tsx.snap +197 -0
  54. package/src/components/Chart/shared/__tests__/__snapshots__/XAxis.spec.tsx.snap +369 -0
  55. package/src/components/Chart/shared/__tests__/__snapshots__/YAxis.spec.tsx.snap +1013 -0
  56. package/src/components/Chart/shared/__tests__/__snapshots__/YAxisGrid.spec.tsx.snap +228 -0
  57. package/src/components/Chart/shared/__tests__/niceNumbers.spec.tsx +127 -0
  58. package/src/components/Chart/shared/constants.ts +2 -0
  59. package/src/components/Chart/shared/hooks/useColorScale.ts +25 -0
  60. package/src/components/Chart/shared/hooks/useGenerateTicks.ts +27 -0
  61. package/src/components/Chart/shared/hooks/useScaleBandX.ts +17 -0
  62. package/src/components/Chart/shared/hooks/useScaleLinearY.ts +30 -0
  63. package/src/components/Chart/shared/niceNumbers.ts +68 -0
  64. package/src/components/Chart/types.ts +100 -0
  65. package/src/components/Select/MultiSelect/OptionList.tsx +1 -1
  66. package/src/components/Select/MultiSelect/index.tsx +2 -6
  67. package/src/components/Select/MultiSelect/utils.ts +1 -1
  68. package/src/components/Select/SingleSelect/OptionList.tsx +1 -1
  69. package/src/components/Select/SingleSelect/index.tsx +2 -7
  70. package/src/components/Select/__tests__/helpers.spec.tsx +0 -36
  71. package/src/components/Select/helpers.tsx +0 -75
  72. package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/Option.spec.tsx.snap +3 -0
  73. package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/index.spec.tsx.snap +1 -0
  74. package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +3 -0
  75. package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabsHeader.spec.tsx.snap +2 -0
  76. package/src/components/Tabs/__tests__/__snapshots__/TabWithBadge.spec.tsx.snap +1 -0
  77. package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +3 -0
  78. package/src/index.ts +2 -0
  79. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +28 -0
  80. package/src/theme/components/chart.ts +28 -0
  81. package/src/theme/components/columnChart.ts +15 -0
  82. package/src/theme/getTheme.ts +6 -0
  83. package/src/types.ts +4 -0
  84. package/src/utils/__tests__/helpers.spec.ts +36 -1
  85. package/src/utils/helpers.ts +76 -1
  86. package/stats/8.100.0/rn-stats.html +4842 -0
  87. package/stats/8.99.4/rn-stats.html +1 -1
  88. package/types/components/Badge/Status.d.ts +0 -1
  89. package/types/components/Chart/ChartSelect/StyledChartSelect.d.ts +8 -0
  90. package/types/components/Chart/ChartSelect/index.d.ts +63 -0
  91. package/types/components/Chart/ColumnChart/ColumnChartContent.d.ts +25 -0
  92. package/types/components/Chart/ColumnChart/Segment.d.ts +14 -0
  93. package/types/components/Chart/ColumnChart/StackedSegment.d.ts +28 -0
  94. package/types/components/Chart/ColumnChart/StyledColumnChart.d.ts +8 -0
  95. package/types/components/Chart/ColumnChart/index.d.ts +80 -0
  96. package/types/components/Chart/Line/Line.d.ts +21 -0
  97. package/types/components/Chart/Line/index.d.ts +35 -0
  98. package/types/components/Chart/StyledChart.d.ts +9 -0
  99. package/types/components/Chart/index.d.ts +9 -0
  100. package/types/components/Chart/shared/AxisLabel.d.ts +7 -0
  101. package/types/components/Chart/shared/ChartFrame.d.ts +30 -0
  102. package/types/components/Chart/shared/ChartHeader.d.ts +8 -0
  103. package/types/components/Chart/shared/EmptyState.d.ts +8 -0
  104. package/types/components/Chart/shared/XAxis.d.ts +8 -0
  105. package/types/components/Chart/shared/XAxisGrid.d.ts +8 -0
  106. package/types/components/Chart/shared/YAxis.d.ts +10 -0
  107. package/types/components/Chart/shared/YAxisGrid.d.ts +10 -0
  108. package/types/components/Chart/shared/constants.d.ts +2 -0
  109. package/types/components/Chart/shared/hooks/useColorScale.d.ts +7 -0
  110. package/types/components/Chart/shared/hooks/useGenerateTicks.d.ts +6 -0
  111. package/types/components/Chart/shared/hooks/useScaleBandX.d.ts +8 -0
  112. package/types/components/Chart/shared/hooks/useScaleLinearY.d.ts +9 -0
  113. package/types/components/Chart/shared/niceNumbers.d.ts +12 -0
  114. package/types/components/Chart/types.d.ts +84 -0
  115. package/types/components/Select/helpers.d.ts +0 -5
  116. package/types/index.d.ts +2 -1
  117. package/types/theme/components/chart.d.ts +22 -0
  118. package/types/theme/components/columnChart.d.ts +10 -0
  119. package/types/theme/getTheme.d.ts +4 -0
  120. package/types/types.d.ts +3 -1
  121. package/types/utils/helpers.d.ts +5 -0
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react-native';
3
+ import Svg from 'react-native-svg';
4
+ import ColumnChartContent from '../ColumnChartContent';
5
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
6
+
7
+ const baseData = [
8
+ {
9
+ label: 'Series 1',
10
+ data: [10, 20, 30],
11
+ },
12
+ {
13
+ label: 'Series 2',
14
+ data: [5, 15, 25],
15
+ },
16
+ ];
17
+
18
+ const xAxisConfig = {
19
+ labels: ['A', 'B', 'C'],
20
+ };
21
+
22
+ const yAxisConfig = {
23
+ maxValue: 55,
24
+ minValue: 0,
25
+ step: 5,
26
+ tick: { interval: 5 },
27
+ };
28
+
29
+ const coordinates = { xStart: 0, xEnd: 100, yStart: 0, yEnd: 200 };
30
+
31
+ describe('ColumnChartContent', () => {
32
+ it('renders segments with correct accessibilityLabel and testID', () => {
33
+ const { getByTestId } = renderWithTheme(
34
+ <Svg>
35
+ <ColumnChartContent
36
+ coordinates={coordinates}
37
+ data={baseData}
38
+ xAxisConfig={xAxisConfig}
39
+ yAxisConfig={yAxisConfig}
40
+ />
41
+ </Svg>
42
+ );
43
+ // Check a few segments
44
+ const segmentA1 = getByTestId('column-segment-A-Series 1');
45
+ expect(segmentA1.props.accessibilityLabel).toContain('value 10');
46
+ expect(segmentA1.props.accessibilityLabel).toContain('x-label A');
47
+ expect(segmentA1.props.accessibilityLabel).toContain('series Series 1');
48
+
49
+ const segmentB2 = getByTestId('column-segment-B-Series 2');
50
+ expect(segmentB2.props.accessibilityLabel).toContain('value 15');
51
+ expect(segmentB2.props.accessibilityLabel).toContain('x-label B');
52
+ expect(segmentB2.props.accessibilityLabel).toContain('series Series 2');
53
+ });
54
+
55
+ it('renders nothing if data is empty', () => {
56
+ const { queryByTestId } = render(
57
+ <Svg>
58
+ <ColumnChartContent
59
+ coordinates={coordinates}
60
+ data={[]}
61
+ xAxisConfig={xAxisConfig}
62
+ yAxisConfig={yAxisConfig}
63
+ />
64
+ </Svg>
65
+ );
66
+ expect(queryByTestId('column-segment-A-Series 1')).toBeNull();
67
+ });
68
+ });
@@ -0,0 +1,99 @@
1
+ import React from 'react';
2
+ import { Svg } from 'react-native-svg';
3
+ import { fireEvent } from '@testing-library/react-native';
4
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
5
+ import Segment from '../Segment';
6
+
7
+ describe('Segment', () => {
8
+ const defaultProps = {
9
+ xCenter: 50,
10
+ y: 100,
11
+ height: 50,
12
+ color: '#000000',
13
+ value: 10,
14
+ xLabel: 'A',
15
+ seriesLabel: 'Series 1',
16
+ testID: 'test-segment',
17
+ };
18
+
19
+ it('renders with correct accessibility props', () => {
20
+ const { getByTestId } = renderWithTheme(
21
+ <Svg>
22
+ <Segment {...defaultProps} />
23
+ </Svg>
24
+ );
25
+
26
+ const segment = getByTestId('test-segment');
27
+ expect(segment.props.accessibilityLabel).toBe(
28
+ 'Column segment: value 10, x-label A, series Series 1'
29
+ );
30
+ });
31
+
32
+ it('applies segment gap from theme', () => {
33
+ const { getByTestId } = renderWithTheme(
34
+ <Svg>
35
+ <Segment {...defaultProps} height={100} y={50} />
36
+ </Svg>
37
+ );
38
+
39
+ const segment = getByTestId('test-segment');
40
+ // Height should be adjusted by the segment gap
41
+ expect(segment.props.height).toBeLessThan(100);
42
+ // Y position should be adjusted by half the segment gap
43
+ expect(segment.props.y).toBeGreaterThan(50);
44
+ });
45
+
46
+ it('centers segment horizontally based on xCenter', () => {
47
+ const { getByTestId } = renderWithTheme(
48
+ <Svg>
49
+ <Segment {...defaultProps} xCenter={100} />
50
+ </Svg>
51
+ );
52
+
53
+ const segment = getByTestId('test-segment');
54
+ const { width } = segment.props;
55
+ // X position should be centered around xCenter
56
+ expect(segment.props.x).toBe(100 - width / 2);
57
+ });
58
+
59
+ it('enforces a minimum bar height if height > 0 but height - segmentGap < minBarHeight', () => {
60
+ // segmentGap from theme is 2 (default), so height = 11 should result in adjustedHeight = 10
61
+ const { getByTestId } = renderWithTheme(
62
+ <Svg>
63
+ <Segment {...defaultProps} height={11} />
64
+ </Svg>
65
+ );
66
+ const segment = getByTestId('test-segment');
67
+ expect(segment.props.height).toBe(10);
68
+ });
69
+
70
+ it('does not support negative values: negative height results in height 0', () => {
71
+ const { getByTestId } = renderWithTheme(
72
+ <Svg>
73
+ <Segment {...defaultProps} height={-20} />
74
+ </Svg>
75
+ );
76
+ const segment = getByTestId('test-segment');
77
+ expect(segment.props.height).toBe(0);
78
+ });
79
+
80
+ it('calls onPress when the segment is pressed', () => {
81
+ const onPress = jest.fn();
82
+ const { getByTestId } = renderWithTheme(
83
+ <Svg>
84
+ <Segment {...defaultProps} onPress={onPress} />
85
+ </Svg>
86
+ );
87
+ const segment = getByTestId('test-segment');
88
+ // fireEvent.press works for react-native-svg Rect
89
+ // but if not, use fireEvent(segment, 'press')
90
+ // (depends on test setup)
91
+ // Try both for robustness
92
+ try {
93
+ fireEvent.press(segment);
94
+ } catch {
95
+ fireEvent(segment, 'press');
96
+ }
97
+ expect(onPress).toHaveBeenCalled();
98
+ });
99
+ });
@@ -0,0 +1,115 @@
1
+ import React from 'react';
2
+ import { Svg } from 'react-native-svg';
3
+ import { fireEvent } from '@testing-library/react-native';
4
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
5
+ import StackedSegment from '../StackedSegment';
6
+
7
+ describe('StackedSegment', () => {
8
+ const stackedData = [10, 20, 30];
9
+ const seriesLabels = ['Series 1', 'Series 2', 'Series 3'];
10
+ const xLabel = 'A';
11
+ const yAxisConfig = {
12
+ maxValue: 60,
13
+ minValue: 0,
14
+ step: 10,
15
+ tick: { interval: 10 },
16
+ };
17
+ const coordinates = { xStart: 0, xEnd: 100, yStart: 0, yEnd: 200 };
18
+ const xCenter = 50;
19
+
20
+ it('renders segments with correct accessibilityLabel and testID', () => {
21
+ const { getByTestId, toJSON } = renderWithTheme(
22
+ <Svg>
23
+ <StackedSegment
24
+ stackedData={stackedData}
25
+ seriesLabels={seriesLabels}
26
+ xLabel={xLabel}
27
+ yAxisConfig={yAxisConfig}
28
+ coordinates={coordinates}
29
+ xCenter={xCenter}
30
+ xIndex={0}
31
+ />
32
+ </Svg>
33
+ );
34
+
35
+ expect(toJSON()).toMatchSnapshot();
36
+ // Check a few segments
37
+ const segment1 = getByTestId('column-segment-A-Series 1');
38
+ expect(segment1.props.accessibilityLabel).toContain('value 10');
39
+ expect(segment1.props.accessibilityLabel).toContain('x-label A');
40
+ expect(segment1.props.accessibilityLabel).toContain('series Series 1');
41
+
42
+ const segment2 = getByTestId('column-segment-A-Series 2');
43
+ expect(segment2.props.accessibilityLabel).toContain('value 20');
44
+ expect(segment2.props.accessibilityLabel).toContain('series Series 2');
45
+ });
46
+
47
+ it('handles undefined data value', () => {
48
+ const stackedDataWithUndefined = [undefined, 15, 25];
49
+ const { getByTestId, queryByTestId } = renderWithTheme(
50
+ <Svg>
51
+ <StackedSegment
52
+ stackedData={stackedDataWithUndefined}
53
+ seriesLabels={seriesLabels}
54
+ xLabel={xLabel}
55
+ yAxisConfig={yAxisConfig}
56
+ coordinates={coordinates}
57
+ xCenter={xCenter}
58
+ xIndex={0}
59
+ />
60
+ </Svg>
61
+ );
62
+ expect(queryByTestId('column-segment-A-Series 1')).toBeNull();
63
+ const segment2 = getByTestId('column-segment-A-Series 2');
64
+ expect(segment2.props.accessibilityLabel).toContain('value 15');
65
+ });
66
+
67
+ it('renders nothing if stackedData is empty', () => {
68
+ const { queryByTestId } = renderWithTheme(
69
+ <Svg>
70
+ <StackedSegment
71
+ stackedData={[]}
72
+ seriesLabels={[]}
73
+ xLabel={xLabel}
74
+ yAxisConfig={yAxisConfig}
75
+ coordinates={coordinates}
76
+ xCenter={xCenter}
77
+ xIndex={0}
78
+ />
79
+ </Svg>
80
+ );
81
+ expect(queryByTestId('column-segment-A-Series 1')).toBeNull();
82
+ });
83
+
84
+ it('calls onBarPress with correct info when a segment is pressed', () => {
85
+ const onBarPress = jest.fn();
86
+ const { getByTestId } = renderWithTheme(
87
+ <Svg>
88
+ <StackedSegment
89
+ stackedData={stackedData}
90
+ seriesLabels={seriesLabels}
91
+ xLabel={xLabel}
92
+ yAxisConfig={yAxisConfig}
93
+ coordinates={coordinates}
94
+ xCenter={xCenter}
95
+ xIndex={0}
96
+ onBarPress={onBarPress}
97
+ />
98
+ </Svg>
99
+ );
100
+ // Press the first segment (A, Series 1)
101
+ const segment = getByTestId('column-segment-A-Series 1');
102
+ try {
103
+ fireEvent.press(segment);
104
+ } catch {
105
+ fireEvent(segment, 'press');
106
+ }
107
+ expect(onBarPress).toHaveBeenCalledWith({
108
+ value: 10,
109
+ xLabel: 'A',
110
+ seriesLabel: 'Series 1',
111
+ seriesIndex: 0,
112
+ xIndex: 0,
113
+ });
114
+ });
115
+ });
@@ -0,0 +1,120 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`StackedSegment renders segments with correct accessibilityLabel and testID 1`] = `
4
+ <View
5
+ style={
6
+ {
7
+ "flex": 1,
8
+ }
9
+ }
10
+ >
11
+ <RNSVGSvgView
12
+ bbHeight="100%"
13
+ bbWidth="100%"
14
+ focusable={false}
15
+ style={
16
+ [
17
+ {
18
+ "backgroundColor": "transparent",
19
+ "borderWidth": 0,
20
+ },
21
+ {
22
+ "flex": 0,
23
+ "height": "100%",
24
+ "width": "100%",
25
+ },
26
+ ]
27
+ }
28
+ >
29
+ <RNSVGGroup
30
+ fill={
31
+ {
32
+ "payload": 4278190080,
33
+ "type": 0,
34
+ }
35
+ }
36
+ >
37
+ <RNSVGRect
38
+ accessibilityLabel="Column segment: value 10, x-label A, series Series 1"
39
+ fill={
40
+ {
41
+ "payload": 4291005678,
42
+ "type": 0,
43
+ }
44
+ }
45
+ height={31.333333333333314}
46
+ propList={
47
+ [
48
+ "fill",
49
+ ]
50
+ }
51
+ rx={8}
52
+ testID="column-segment-A-Series 1"
53
+ width={16}
54
+ x={42}
55
+ y={167.66666666666669}
56
+ />
57
+ <RNSVGRect
58
+ accessibilityLabel="Column segment: value 20, x-label A, series Series 2"
59
+ fill={
60
+ {
61
+ "payload": 4280139502,
62
+ "type": 0,
63
+ }
64
+ }
65
+ height={64.66666666666669}
66
+ propList={
67
+ [
68
+ "fill",
69
+ ]
70
+ }
71
+ rx={8}
72
+ testID="column-segment-A-Series 2"
73
+ width={16}
74
+ x={42}
75
+ y={101}
76
+ />
77
+ <RNSVGRect
78
+ accessibilityLabel="Column segment: value 30, x-label A, series Series 3"
79
+ fill={
80
+ {
81
+ "payload": 4284471940,
82
+ "type": 0,
83
+ }
84
+ }
85
+ height={98}
86
+ propList={
87
+ [
88
+ "fill",
89
+ ]
90
+ }
91
+ rx={8}
92
+ testID="column-segment-A-Series 3"
93
+ width={16}
94
+ x={42}
95
+ y={1}
96
+ />
97
+ </RNSVGGroup>
98
+ </RNSVGSvgView>
99
+ <View
100
+ pointerEvents="box-none"
101
+ position="bottom"
102
+ style={
103
+ [
104
+ {
105
+ "bottom": 0,
106
+ "elevation": 9999,
107
+ "flexDirection": "column-reverse",
108
+ "left": 0,
109
+ "paddingHorizontal": 24,
110
+ "paddingVertical": 16,
111
+ "position": "absolute",
112
+ "right": 0,
113
+ "top": 0,
114
+ },
115
+ undefined,
116
+ ]
117
+ }
118
+ />
119
+ </View>
120
+ `;