panelui-native 0.112.0 → 0.113.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 (69) hide show
  1. package/README.md +2 -2
  2. package/lib/module/components/area-chart/index.js +3 -1
  3. package/lib/module/components/area-chart/index.js.map +1 -1
  4. package/lib/module/components/bar-chart/index.js +3 -1
  5. package/lib/module/components/bar-chart/index.js.map +1 -1
  6. package/lib/module/components/bubble-chart/index.js +5 -1
  7. package/lib/module/components/bubble-chart/index.js.map +1 -1
  8. package/lib/module/components/bump-chart/index.js +3 -1
  9. package/lib/module/components/bump-chart/index.js.map +1 -1
  10. package/lib/module/components/button/index.js.map +1 -1
  11. package/lib/module/components/candlestick-chart/index.js +3 -1
  12. package/lib/module/components/candlestick-chart/index.js.map +1 -1
  13. package/lib/module/components/heatmap-chart/index.js +32 -7
  14. package/lib/module/components/heatmap-chart/index.js.map +1 -1
  15. package/lib/module/components/line-chart/index.js +3 -1
  16. package/lib/module/components/line-chart/index.js.map +1 -1
  17. package/lib/module/components/live-line-chart/index.js +3 -0
  18. package/lib/module/components/live-line-chart/index.js.map +1 -1
  19. package/lib/module/components/mirror-area-chart/index.js +3 -1
  20. package/lib/module/components/mirror-area-chart/index.js.map +1 -1
  21. package/lib/module/components/plot/index.js +3 -1
  22. package/lib/module/components/plot/index.js.map +1 -1
  23. package/lib/module/components/pyramid-chart/index.js +4 -1
  24. package/lib/module/components/pyramid-chart/index.js.map +1 -1
  25. package/lib/module/components/scatter-chart/index.js +3 -1
  26. package/lib/module/components/scatter-chart/index.js.map +1 -1
  27. package/lib/module/components/waterfall-chart/index.js +3 -1
  28. package/lib/module/components/waterfall-chart/index.js.map +1 -1
  29. package/lib/module/primitives/animated-pressable.js +31 -6
  30. package/lib/module/primitives/animated-pressable.js.map +1 -1
  31. package/lib/module/primitives/chart-accessibility.js +8 -0
  32. package/lib/module/primitives/chart-accessibility.js.map +1 -1
  33. package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
  34. package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -1
  35. package/lib/typescript/src/components/bubble-chart/index.d.ts.map +1 -1
  36. package/lib/typescript/src/components/bump-chart/index.d.ts.map +1 -1
  37. package/lib/typescript/src/components/button/index.d.ts +7 -0
  38. package/lib/typescript/src/components/button/index.d.ts.map +1 -1
  39. package/lib/typescript/src/components/candlestick-chart/index.d.ts.map +1 -1
  40. package/lib/typescript/src/components/heatmap-chart/index.d.ts +5 -2
  41. package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
  42. package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
  43. package/lib/typescript/src/components/live-line-chart/index.d.ts.map +1 -1
  44. package/lib/typescript/src/components/mirror-area-chart/index.d.ts.map +1 -1
  45. package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
  46. package/lib/typescript/src/components/pyramid-chart/index.d.ts.map +1 -1
  47. package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
  48. package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
  49. package/lib/typescript/src/primitives/animated-pressable.d.ts +15 -1
  50. package/lib/typescript/src/primitives/animated-pressable.d.ts.map +1 -1
  51. package/lib/typescript/src/primitives/chart-accessibility.d.ts +7 -0
  52. package/lib/typescript/src/primitives/chart-accessibility.d.ts.map +1 -1
  53. package/package.json +11 -1
  54. package/src/components/area-chart/index.tsx +13 -2
  55. package/src/components/bar-chart/index.tsx +7 -2
  56. package/src/components/bubble-chart/index.tsx +17 -2
  57. package/src/components/bump-chart/index.tsx +13 -2
  58. package/src/components/button/index.tsx +7 -0
  59. package/src/components/candlestick-chart/index.tsx +14 -2
  60. package/src/components/heatmap-chart/index.tsx +46 -7
  61. package/src/components/line-chart/index.tsx +13 -2
  62. package/src/components/live-line-chart/index.tsx +13 -2
  63. package/src/components/mirror-area-chart/index.tsx +7 -1
  64. package/src/components/plot/index.tsx +13 -2
  65. package/src/components/pyramid-chart/index.tsx +10 -2
  66. package/src/components/scatter-chart/index.tsx +13 -2
  67. package/src/components/waterfall-chart/index.tsx +7 -2
  68. package/src/primitives/animated-pressable.tsx +44 -6
  69. package/src/primitives/chart-accessibility.ts +8 -0
@@ -70,7 +70,11 @@ import Animated, {
70
70
  import Svg, { G, Line as SvgLine, Path } from 'react-native-svg';
71
71
  import { useCSSVariable } from 'uniwind';
72
72
  import { Text } from '../../primitives/text';
73
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
73
+ import {
74
+ CHART_AXIS_MAX_FONT_SCALE,
75
+ ChartAccessibilityData,
76
+ type ChartAccessibilityProps,
77
+ } from '../../primitives/chart-accessibility';
74
78
  import { bandOf, compactNumber, yOf, type Plot } from '../../utils/chart';
75
79
  import { cn } from '../../utils/cn';
76
80
 
@@ -1009,6 +1013,7 @@ function CandlestickChartXAxis({
1009
1013
  width: LABEL_BOX,
1010
1014
  textAlign: 'center',
1011
1015
  }}
1016
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1012
1017
  >
1013
1018
  {label.text}
1014
1019
  </Text>
@@ -1067,7 +1072,14 @@ function CandlestickChartYAxis({
1067
1072
  className={cn(className)}
1068
1073
  >
1069
1074
  {labels.map((label) => (
1070
- <Text key={label.key} size="xs" muted numberOfLines={1} className="text-right">
1075
+ <Text
1076
+ key={label.key}
1077
+ size="xs"
1078
+ muted
1079
+ numberOfLines={1}
1080
+ className="text-right"
1081
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1082
+ >
1071
1083
  {label.text}
1072
1084
  </Text>
1073
1085
  ))}
@@ -48,7 +48,13 @@ import {
48
48
  useState,
49
49
  type ReactNode,
50
50
  } from 'react';
51
- import { StyleSheet, View, type LayoutChangeEvent, type ViewProps } from 'react-native';
51
+ import {
52
+ StyleSheet,
53
+ useWindowDimensions,
54
+ View,
55
+ type LayoutChangeEvent,
56
+ type ViewProps,
57
+ } from 'react-native';
52
58
  import { Gesture, GestureDetector } from 'react-native-gesture-handler';
53
59
  import Animated, {
54
60
  Easing,
@@ -62,7 +68,11 @@ import Animated, {
62
68
  import Svg, { G, Line as SvgLine, Rect } from 'react-native-svg';
63
69
  import { useCSSVariable } from 'uniwind';
64
70
  import { Text } from '../../primitives/text';
65
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
71
+ import {
72
+ CHART_AXIS_MAX_FONT_SCALE,
73
+ ChartAccessibilityData,
74
+ type ChartAccessibilityProps,
75
+ } from '../../primitives/chart-accessibility';
66
76
  import { cn } from '../../utils/cn';
67
77
  import { normalizeWeekStart, startOfDay } from '../../utils/date';
68
78
 
@@ -89,6 +99,20 @@ function isToken(value: string | undefined): value is string {
89
99
  /** Room left for the weekday labels when the y-axis does not ask for its own. */
90
100
  const DEFAULT_AXIS_WIDTH = 26;
91
101
 
102
+ /** Height of the month row at the default text size: one line of `xs` text. */
103
+ const X_AXIS_HEIGHT = 16;
104
+
105
+ /**
106
+ * How much larger than default the axis labels are drawn, from 1 up to the
107
+ * axis cap. The heatmap's gutters are only just wide enough for a weekday at
108
+ * the default size, so they grow by the same factor or a larger label wraps
109
+ * and runs into the cells. Below the default size they stay put.
110
+ */
111
+ function useAxisLabelScale() {
112
+ const { fontScale } = useWindowDimensions();
113
+ return Math.min(Math.max(fontScale, 1), CHART_AXIS_MAX_FONT_SCALE);
114
+ }
115
+
92
116
  /**
93
117
  * Height assumed for the readout when placing it above a cell. It is a single
94
118
  * line of `xs` text in a padded box, so it does not vary — and measuring it
@@ -432,9 +456,12 @@ const HeatmapChartRoot = forwardRef<View, HeatmapChartProps>(function HeatmapCha
432
456
  (typeof emptyToken === 'string' ? emptyToken : 'rgba(128,128,128,0.16)');
433
457
 
434
458
  const parts = useMemo(() => splitParts(children), [children]);
459
+ const labelScale = useAxisLabelScale();
435
460
  // The y-axis is laid out beside the grid rather than over it, so its width
436
461
  // has to come out of the grid's before the cells are sized.
437
- const axisWidth = parts.y ? (parts.y.props.width ?? DEFAULT_AXIS_WIDTH) : 0;
462
+ const axisWidth = parts.y
463
+ ? (parts.y.props.width ?? Math.ceil(DEFAULT_AXIS_WIDTH * labelScale))
464
+ : 0;
438
465
 
439
466
  const grid = useMemo<Grid>(() => {
440
467
  const count = data.length;
@@ -836,6 +863,7 @@ export interface HeatmapXAxisProps {
836
863
  function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisProps) {
837
864
  const { data, grid } = useHeatmap('HeatmapChart.XAxis');
838
865
  const step = grid.size + grid.gap;
866
+ const scale = useAxisLabelScale();
839
867
 
840
868
  const labels = useMemo(() => {
841
869
  if (given) {
@@ -865,7 +893,10 @@ function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisPro
865
893
  }, [data, formatLabel, given]);
866
894
 
867
895
  return (
868
- <View className={cn('h-4', className)} style={{ width: grid.width }}>
896
+ <View
897
+ className={cn('h-4', className)}
898
+ style={[{ width: grid.width }, scale > 1 && { height: Math.ceil(X_AXIS_HEIGHT * scale) }]}
899
+ >
869
900
  {labels.map(({ column, label }) => (
870
901
  <Text
871
902
  key={`${column}-${label}`}
@@ -873,6 +904,7 @@ function HeatmapXAxis({ className, formatLabel, labels: given }: HeatmapXAxisPro
873
904
  muted
874
905
  className="absolute"
875
906
  style={{ left: column * step }}
907
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
876
908
  >
877
909
  {label}
878
910
  </Text>
@@ -884,7 +916,10 @@ HeatmapXAxis.slot = 'x-axis' as Slot;
884
916
 
885
917
  export interface HeatmapYAxisProps {
886
918
  className?: string;
887
- /** Width reserved for the labels. The grid is sized around it. */
919
+ /**
920
+ * Width reserved for the labels. The grid is sized around it. Defaults to 26,
921
+ * and widens with the system text size so a larger weekday does not wrap.
922
+ */
888
923
  width?: number;
889
924
  /** Which rows get a label. Every other row is the usual choice. */
890
925
  tickFilter?: 'all' | 'odd' | 'even';
@@ -900,13 +935,15 @@ export interface HeatmapYAxisProps {
900
935
  /** Weekday labels down the left of the grid. */
901
936
  function HeatmapYAxis({
902
937
  className,
903
- width = DEFAULT_AXIS_WIDTH,
938
+ width: widthProp,
904
939
  tickFilter = 'odd',
905
940
  labelFormat = 'full',
906
941
  labels,
907
942
  }: HeatmapYAxisProps) {
908
943
  const { grid, weekStartDay } = useHeatmap('HeatmapChart.YAxis');
909
944
  const step = grid.size + grid.gap;
945
+ const scale = useAxisLabelScale();
946
+ const width = widthProp ?? Math.ceil(DEFAULT_AXIS_WIDTH * scale);
910
947
 
911
948
  return (
912
949
  <View className={className} style={{ width, height: grid.height }}>
@@ -922,10 +959,12 @@ function HeatmapYAxis({
922
959
  key={row}
923
960
  size="xs"
924
961
  muted
962
+ numberOfLines={1}
925
963
  className="absolute"
926
964
  // Centred on the cell rather than aligned to its top edge, so a
927
965
  // label reads as belonging to the row it sits beside.
928
- style={{ top: row * step + grid.size / 2 - 7 }}
966
+ style={{ top: row * step + grid.size / 2 - 7 * scale }}
967
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
929
968
  >
930
969
  {labels
931
970
  ? name
@@ -80,7 +80,11 @@ import Svg, {
80
80
  } from 'react-native-svg';
81
81
  import { useCSSVariable } from 'uniwind';
82
82
  import { Text } from '../../primitives/text';
83
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
83
+ import {
84
+ CHART_AXIS_MAX_FONT_SCALE,
85
+ ChartAccessibilityData,
86
+ type ChartAccessibilityProps,
87
+ } from '../../primitives/chart-accessibility';
84
88
  import {
85
89
  areaPath,
86
90
  columnValues,
@@ -870,6 +874,7 @@ function LineChartXAxis({ ticks = 4, format, className }: LineChartXAxisProps) {
870
874
  width: POINT_LABEL_WIDTH,
871
875
  textAlign: 'center',
872
876
  }}
877
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
873
878
  >
874
879
  {label.text}
875
880
  </Text>
@@ -930,7 +935,13 @@ function LineChartYAxis({ ticks = 4, format, className }: LineChartYAxisProps) {
930
935
  className={cn('items-end justify-between', className)}
931
936
  >
932
937
  {labels.map((label) => (
933
- <Text key={label.key} size="xs" muted numberOfLines={1}>
938
+ <Text
939
+ key={label.key}
940
+ size="xs"
941
+ muted
942
+ numberOfLines={1}
943
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
944
+ >
934
945
  {label.text}
935
946
  </Text>
936
947
  ))}
@@ -93,6 +93,7 @@ import Svg, {
93
93
  Line as SvgLine,
94
94
  } from 'react-native-svg';
95
95
  import { useCSSVariable } from 'uniwind';
96
+ import { CHART_AXIS_MAX_FONT_SCALE } from '../../primitives/chart-accessibility';
96
97
  import { Text } from '../../primitives/text';
97
98
  import {
98
99
  compactNumber,
@@ -1027,7 +1028,12 @@ function LiveLineChartXAxis({ ticks = 4, formatTick, className }: LiveLineChartX
1027
1028
  }}
1028
1029
  className={cn('items-center', className)}
1029
1030
  >
1030
- <Text size="xs" muted numberOfLines={1}>
1031
+ <Text
1032
+ size="xs"
1033
+ muted
1034
+ numberOfLines={1}
1035
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1036
+ >
1031
1037
  {format(seconds * (1 - fraction))}
1032
1038
  </Text>
1033
1039
  </View>
@@ -1082,7 +1088,12 @@ function LiveLineChartYAxis({ ticks = 4, formatValue, className }: LiveLineChart
1082
1088
  }}
1083
1089
  className={cn('items-end', className)}
1084
1090
  >
1085
- <Text size="xs" muted numberOfLines={1}>
1091
+ <Text
1092
+ size="xs"
1093
+ muted
1094
+ numberOfLines={1}
1095
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1096
+ >
1086
1097
  {format(max - (max - min) * fraction)}
1087
1098
  </Text>
1088
1099
  </View>
@@ -64,7 +64,11 @@ import Svg, {
64
64
  } from 'react-native-svg';
65
65
  import { useCSSVariable } from 'uniwind';
66
66
  import { Text } from '../../primitives/text';
67
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
67
+ import {
68
+ CHART_AXIS_MAX_FONT_SCALE,
69
+ ChartAccessibilityData,
70
+ type ChartAccessibilityProps,
71
+ } from '../../primitives/chart-accessibility';
68
72
  import { finiteChartDomain } from '../../primitives/finite-chart';
69
73
  import {
70
74
  colorStop,
@@ -934,6 +938,7 @@ function MirrorAreaChartXAxis({ ticks = 4, format, className }: MirrorAreaChartX
934
938
  width: POINT_LABEL_WIDTH,
935
939
  textAlign: 'center',
936
940
  }}
941
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
937
942
  >
938
943
  {label.text}
939
944
  </Text>
@@ -984,6 +989,7 @@ function MirrorAreaChartYAxis({ formatTop, formatBottom, className }: MirrorArea
984
989
  width,
985
990
  textAlign: 'right',
986
991
  }}
992
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
987
993
  >
988
994
  {label.text}
989
995
  </Text>
@@ -96,7 +96,11 @@ import Svg, {
96
96
  Rect,
97
97
  } from 'react-native-svg';
98
98
  import { useCSSVariable } from 'uniwind';
99
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
99
+ import {
100
+ CHART_AXIS_MAX_FONT_SCALE,
101
+ ChartAccessibilityData,
102
+ type ChartAccessibilityProps,
103
+ } from '../../primitives/chart-accessibility';
100
104
  import { Text } from '../../primitives/text';
101
105
  import { finiteChartNumber } from '../../primitives/finite-chart';
102
106
  import {
@@ -1371,6 +1375,7 @@ function PlotXAxis({ ticks = 4, format, className }: PlotXAxisProps) {
1371
1375
  width: POINT_LABEL_WIDTH,
1372
1376
  textAlign: 'center',
1373
1377
  }}
1378
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1374
1379
  >
1375
1380
  {label.text}
1376
1381
  </Text>
@@ -1429,7 +1434,13 @@ function PlotYAxis({ ticks = 4, format, className }: PlotYAxisProps) {
1429
1434
  className={cn('items-end justify-between', className)}
1430
1435
  >
1431
1436
  {labels.map((label) => (
1432
- <Text key={label.key} size="xs" muted numberOfLines={1}>
1437
+ <Text
1438
+ key={label.key}
1439
+ size="xs"
1440
+ muted
1441
+ numberOfLines={1}
1442
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1443
+ >
1433
1444
  {label.text}
1434
1445
  </Text>
1435
1446
  ))}
@@ -80,6 +80,7 @@ import Animated, {
80
80
  import Svg, { Defs, G, Line as SvgLine, LinearGradient, Path, Stop } from 'react-native-svg';
81
81
  import { useCSSVariable } from 'uniwind';
82
82
  import {
83
+ CHART_AXIS_MAX_FONT_SCALE,
83
84
  ChartAccessibilityData,
84
85
  type ChartAccessibilityProps,
85
86
  } from '../../primitives/chart-accessibility';
@@ -956,6 +957,7 @@ function PyramidChartXAxis({ ticks = 2, format, className }: PyramidChartXAxisPr
956
957
  width: AXIS_LABEL_WIDTH,
957
958
  textAlign: 'center',
958
959
  }}
960
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
959
961
  >
960
962
  {label.text}
961
963
  </Text>
@@ -1013,7 +1015,13 @@ function PyramidChartYAxis({ format, className }: PyramidChartYAxisProps) {
1013
1015
  }}
1014
1016
  className="justify-center"
1015
1017
  >
1016
- <Text size="xs" muted numberOfLines={1} style={{ textAlign: 'center' }}>
1018
+ <Text
1019
+ size="xs"
1020
+ muted
1021
+ numberOfLines={1}
1022
+ style={{ textAlign: 'center' }}
1023
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1024
+ >
1017
1025
  {label(datum, index)}
1018
1026
  </Text>
1019
1027
  </View>
@@ -1037,7 +1045,7 @@ function PyramidChartYAxis({ format, className }: PyramidChartYAxisProps) {
1037
1045
  >
1038
1046
  {data.map((datum, index) => (
1039
1047
  <View key={index} className="flex-1 justify-center">
1040
- <Text size="xs" muted numberOfLines={1}>
1048
+ <Text size="xs" muted numberOfLines={1} maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}>
1041
1049
  {label(datum, index)}
1042
1050
  </Text>
1043
1051
  </View>
@@ -67,7 +67,11 @@ import Animated, {
67
67
  import Svg, { Circle, G, Line as SvgLine } from 'react-native-svg';
68
68
  import { useCSSVariable } from 'uniwind';
69
69
  import { Text } from '../../primitives/text';
70
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
70
+ import {
71
+ CHART_AXIS_MAX_FONT_SCALE,
72
+ ChartAccessibilityData,
73
+ type ChartAccessibilityProps,
74
+ } from '../../primitives/chart-accessibility';
71
75
  import { compactNumber, useSeriesColor, xAt, yOf, type Plot } from '../../utils/chart';
72
76
  import { cn } from '../../utils/cn';
73
77
  import { useSkeletonHandoff } from '../../hooks/use-skeleton-handoff';
@@ -957,6 +961,7 @@ function ScatterChartXAxis({ ticks = 4, format, className }: ScatterChartXAxisPr
957
961
  width: POINT_LABEL_WIDTH,
958
962
  textAlign: 'center',
959
963
  }}
964
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
960
965
  >
961
966
  {label.text}
962
967
  </Text>
@@ -1004,7 +1009,13 @@ function ScatterChartYAxis({ ticks = 4, format, className }: ScatterChartYAxisPr
1004
1009
  className={cn('items-end justify-between', className)}
1005
1010
  >
1006
1011
  {labels.map((label) => (
1007
- <Text key={label.key} size="xs" muted numberOfLines={1}>
1012
+ <Text
1013
+ key={label.key}
1014
+ size="xs"
1015
+ muted
1016
+ numberOfLines={1}
1017
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1018
+ >
1008
1019
  {label.text}
1009
1020
  </Text>
1010
1021
  ))}
@@ -66,7 +66,11 @@ import Animated, {
66
66
  } from 'react-native-reanimated';
67
67
  import Svg, { Defs, G, Line as SvgLine, LinearGradient, Path, Stop } from 'react-native-svg';
68
68
  import { useCSSVariable } from 'uniwind';
69
- import { ChartAccessibilityData, type ChartAccessibilityProps } from '../../primitives/chart-accessibility';
69
+ import {
70
+ CHART_AXIS_MAX_FONT_SCALE,
71
+ ChartAccessibilityData,
72
+ type ChartAccessibilityProps,
73
+ } from '../../primitives/chart-accessibility';
70
74
  import { Text } from '../../primitives/text';
71
75
  import {
72
76
  finiteChartDomain,
@@ -1142,6 +1146,7 @@ function WaterfallChartXAxis({ ticks, format, className }: WaterfallChartXAxisPr
1142
1146
  width: bandWidth,
1143
1147
  textAlign: 'center',
1144
1148
  }}
1149
+ maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}
1145
1150
  >
1146
1151
  {label.text}
1147
1152
  </Text>
@@ -1209,7 +1214,7 @@ function WaterfallChartYAxis({ ticks = 4, format, className }: WaterfallChartYAx
1209
1214
  >
1210
1215
  {labels.map((label) => (
1211
1216
  <View key={label.key} className={horizontal ? 'flex-1 justify-center' : undefined}>
1212
- <Text size="xs" muted numberOfLines={1}>
1217
+ <Text size="xs" muted numberOfLines={1} maxFontSizeMultiplier={CHART_AXIS_MAX_FONT_SCALE}>
1213
1218
  {label.text}
1214
1219
  </Text>
1215
1220
  </View>
@@ -1,6 +1,7 @@
1
1
  import { forwardRef, useCallback } from 'react';
2
2
  import {
3
3
  Pressable,
4
+ StyleSheet,
4
5
  type GestureResponderEvent,
5
6
  type PressableProps,
6
7
  type View,
@@ -11,6 +12,7 @@ import Animated, {
11
12
  withSpring,
12
13
  withTiming,
13
14
  } from 'react-native-reanimated';
15
+ import { useResolveClassNames } from 'uniwind';
14
16
 
15
17
  const AnimatedPressableBase = Animated.createAnimatedComponent(Pressable);
16
18
 
@@ -20,20 +22,53 @@ export interface AnimatedPressableProps extends PressableProps {
20
22
  className?: string;
21
23
  /** Scale applied while pressed. Set to 1 to disable. Default 0.97. */
22
24
  pressScale?: number;
23
- /** Opacity applied while pressed. Set to 1 to disable. Default 1. */
25
+ /**
26
+ * Opacity applied while pressed, as a fraction of the resting opacity. Set
27
+ * to 1 to disable. Default 1.
28
+ */
24
29
  pressOpacity?: number;
25
30
  }
26
31
 
27
32
  /**
28
33
  * Pressable with UI-thread press feedback (scale/opacity via Reanimated).
29
34
  * The shared base for every interactive PanelUI component.
35
+ *
36
+ * The animated style is applied after the `className` styles, so any key it
37
+ * writes beats the same key from a class. That is why it writes `opacity` only
38
+ * when the press actually fades: a component that dims itself when disabled
39
+ * (`opacity-[0.64]`, or a caller's `disabled:opacity-50`) does it through the
40
+ * class, and an animated `opacity: 1` at rest would undo it on every render.
41
+ *
42
+ * A pressable that does fade owns its opacity outright, so it reads the
43
+ * resting value from `style` or `className` and fades from there rather than
44
+ * from 1. Keep `pressOpacity` either 1 or not for the life of a component:
45
+ * the style's keys follow it.
30
46
  */
31
47
  export const AnimatedPressable = forwardRef<View, AnimatedPressableProps>(
32
48
  (
33
- { pressScale = 0.97, pressOpacity = 1, onPressIn, onPressOut, style, ...props },
49
+ {
50
+ pressScale = 0.97,
51
+ pressOpacity = 1,
52
+ onPressIn,
53
+ onPressOut,
54
+ style,
55
+ className,
56
+ ...props
57
+ },
34
58
  ref
35
59
  ) => {
36
60
  const pressed = useSharedValue(0);
61
+ const fades = pressOpacity !== 1;
62
+
63
+ // Only resolved when the press fades; an empty class resolves to nothing.
64
+ const classStyle = useResolveClassNames(fades ? (className ?? '') : '');
65
+ const ownStyle = typeof style === 'function' ? undefined : StyleSheet.flatten(style);
66
+ const restingOpacity =
67
+ typeof ownStyle?.opacity === 'number'
68
+ ? ownStyle.opacity
69
+ : typeof classStyle.opacity === 'number'
70
+ ? classStyle.opacity
71
+ : 1;
37
72
 
38
73
  const handlePressIn = useCallback(
39
74
  (event: GestureResponderEvent) => {
@@ -51,14 +86,17 @@ export const AnimatedPressable = forwardRef<View, AnimatedPressableProps>(
51
86
  [onPressOut, pressed]
52
87
  );
53
88
 
54
- const animatedStyle = useAnimatedStyle(() => ({
55
- transform: [{ scale: 1 + pressed.value * (pressScale - 1) }],
56
- opacity: 1 + pressed.value * (pressOpacity - 1),
57
- }));
89
+ const animatedStyle = useAnimatedStyle(() => {
90
+ const transform = [{ scale: 1 + pressed.value * (pressScale - 1) }];
91
+ return fades
92
+ ? { transform, opacity: restingOpacity * (1 + pressed.value * (pressOpacity - 1)) }
93
+ : { transform };
94
+ });
58
95
 
59
96
  return (
60
97
  <AnimatedPressableBase
61
98
  ref={ref}
99
+ className={className}
62
100
  style={[animatedStyle, style as never]}
63
101
  onPressIn={handlePressIn}
64
102
  onPressOut={handlePressOut}
@@ -1,5 +1,13 @@
1
1
  import { createElement } from 'react';
2
2
 
3
+ /**
4
+ * The largest text scale a chart's axis labels follow: iOS's biggest size before
5
+ * the accessibility range. Axis labels sit in fixed-width gutters at fixed
6
+ * steps, so past this they overlap each other or clip. Screen readers still get
7
+ * every value through the chart's accessibility data.
8
+ */
9
+ export const CHART_AXIS_MAX_FONT_SCALE = 1.353;
10
+
3
11
  export interface ChartAccessibilityProps<Datum> {
4
12
  /** Spoken summary. Defaults to the chart family and number of data entries. */
5
13
  accessibilityLabel?: string;