panelui-native 0.108.0 → 0.109.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 (75) hide show
  1. package/lib/module/components/badge/index.js +85 -4
  2. package/lib/module/components/badge/index.js.map +1 -1
  3. package/lib/module/components/button/index.js +12 -0
  4. package/lib/module/components/button/index.js.map +1 -1
  5. package/lib/module/components/button-group/index.js +3 -0
  6. package/lib/module/components/button-group/index.js.map +1 -1
  7. package/lib/module/components/checkbox/index.js +54 -4
  8. package/lib/module/components/checkbox/index.js.map +1 -1
  9. package/lib/module/components/chip/index.js +23 -1
  10. package/lib/module/components/chip/index.js.map +1 -1
  11. package/lib/module/components/input/index.js +14 -0
  12. package/lib/module/components/input/index.js.map +1 -1
  13. package/lib/module/components/map/index.js +157 -5
  14. package/lib/module/components/map/index.js.map +1 -1
  15. package/lib/module/components/map/map-insets.js +174 -0
  16. package/lib/module/components/map/map-insets.js.map +1 -0
  17. package/lib/module/components/radio-group/index.js +49 -3
  18. package/lib/module/components/radio-group/index.js.map +1 -1
  19. package/lib/module/components/select/index.js +54 -2
  20. package/lib/module/components/select/index.js.map +1 -1
  21. package/lib/module/components/switch/index.js +42 -3
  22. package/lib/module/components/switch/index.js.map +1 -1
  23. package/lib/module/components/tabs/index.js +147 -1
  24. package/lib/module/components/tabs/index.js.map +1 -1
  25. package/lib/module/components/textarea/index.js +18 -0
  26. package/lib/module/components/textarea/index.js.map +1 -1
  27. package/lib/module/components/toggle-button/index.js +34 -2
  28. package/lib/module/components/toggle-button/index.js.map +1 -1
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/typescript/src/components/badge/index.d.ts +68 -0
  31. package/lib/typescript/src/components/badge/index.d.ts.map +1 -1
  32. package/lib/typescript/src/components/button/index.d.ts +12 -0
  33. package/lib/typescript/src/components/button/index.d.ts.map +1 -1
  34. package/lib/typescript/src/components/button-group/index.d.ts +9 -0
  35. package/lib/typescript/src/components/button-group/index.d.ts.map +1 -1
  36. package/lib/typescript/src/components/checkbox/index.d.ts +89 -0
  37. package/lib/typescript/src/components/checkbox/index.d.ts.map +1 -1
  38. package/lib/typescript/src/components/chip/index.d.ts +24 -0
  39. package/lib/typescript/src/components/chip/index.d.ts.map +1 -1
  40. package/lib/typescript/src/components/input/index.d.ts +30 -0
  41. package/lib/typescript/src/components/input/index.d.ts.map +1 -1
  42. package/lib/typescript/src/components/map/index.d.ts +67 -1
  43. package/lib/typescript/src/components/map/index.d.ts.map +1 -1
  44. package/lib/typescript/src/components/map/map-insets.d.ts +80 -0
  45. package/lib/typescript/src/components/map/map-insets.d.ts.map +1 -0
  46. package/lib/typescript/src/components/radio-group/index.d.ts +188 -1
  47. package/lib/typescript/src/components/radio-group/index.d.ts.map +1 -1
  48. package/lib/typescript/src/components/select/index.d.ts +9 -1
  49. package/lib/typescript/src/components/select/index.d.ts.map +1 -1
  50. package/lib/typescript/src/components/switch/index.d.ts +38 -0
  51. package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
  52. package/lib/typescript/src/components/tabs/index.d.ts +10 -1
  53. package/lib/typescript/src/components/tabs/index.d.ts.map +1 -1
  54. package/lib/typescript/src/components/textarea/index.d.ts +18 -0
  55. package/lib/typescript/src/components/textarea/index.d.ts.map +1 -1
  56. package/lib/typescript/src/components/toggle-button/index.d.ts +24 -0
  57. package/lib/typescript/src/components/toggle-button/index.d.ts.map +1 -1
  58. package/lib/typescript/src/index.d.ts +7 -7
  59. package/lib/typescript/src/index.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/components/badge/index.tsx +30 -4
  62. package/src/components/button/index.tsx +9 -2
  63. package/src/components/button-group/index.tsx +1 -0
  64. package/src/components/checkbox/index.tsx +47 -3
  65. package/src/components/chip/index.tsx +5 -1
  66. package/src/components/input/index.tsx +6 -0
  67. package/src/components/map/index.tsx +215 -5
  68. package/src/components/map/map-insets.ts +169 -0
  69. package/src/components/radio-group/index.tsx +56 -4
  70. package/src/components/select/index.tsx +50 -1
  71. package/src/components/switch/index.tsx +16 -4
  72. package/src/components/tabs/index.tsx +61 -0
  73. package/src/components/textarea/index.tsx +6 -0
  74. package/src/components/toggle-button/index.tsx +16 -1
  75. package/src/index.ts +8 -3
@@ -18,6 +18,19 @@
18
18
  * </Map>
19
19
  * ```
20
20
  *
21
+ * Anything else drawn over the map goes in a `Map.Overlay`. It is pinned to an
22
+ * edge or a corner and tells the map how much room it takes, so a control
23
+ * stack in the same corner sits past it rather than underneath:
24
+ *
25
+ * ```tsx
26
+ * <Map center={[-0.12, 51.5]} zoom={11}>
27
+ * <Map.Overlay position="bottom" safeArea>
28
+ * <Card>…</Card>
29
+ * </Map.Overlay>
30
+ * <Map.Controls position="bottom-right" />
31
+ * </Map>
32
+ * ```
33
+ *
21
34
  * The renderer is native and optional, so `Map` has a state no other component
22
35
  * here does: it may be unable to draw at all. It says so in place rather than
23
36
  * throwing, because the usual way to reach that state is running in a client
@@ -37,13 +50,22 @@ import {
37
50
  useCallback,
38
51
  useContext,
39
52
  useEffect,
53
+ useId,
40
54
  useImperativeHandle,
41
55
  useMemo,
42
56
  useRef,
43
57
  useState,
44
58
  type ReactNode,
45
59
  } from 'react';
46
- import { Pressable, StyleSheet, View, type PressableProps, type ViewProps } from 'react-native';
60
+ import {
61
+ Pressable,
62
+ StyleSheet,
63
+ View,
64
+ type LayoutChangeEvent,
65
+ type PressableProps,
66
+ type ViewProps,
67
+ } from 'react-native';
68
+ import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
47
69
  import { useCSSVariable } from 'uniwind';
48
70
  import { tv } from 'tailwind-variants';
49
71
  import {
@@ -80,6 +102,16 @@ import {
80
102
  type MapFeatureAccessibilityDescription,
81
103
  } from './map-accessibility';
82
104
  import { asMapLayer, partitionMapChildren } from './map-children';
105
+ import {
106
+ controlsOffsets,
107
+ overlayOffsets,
108
+ overlayReservation,
109
+ reservedAt,
110
+ resolveMapInsets,
111
+ type MapOffsets,
112
+ type MapOverlayPosition,
113
+ type MapReservation,
114
+ } from './map-insets';
83
115
  import { useNativeStyle } from './native-style';
84
116
 
85
117
  export { hasMapLibre, CARTO_SOURCE };
@@ -93,11 +125,16 @@ export type {
93
125
  ViewState,
94
126
  };
95
127
  export type { MapFeatureAccessibility } from './map-accessibility';
128
+ export type { MapOverlayPosition } from './map-insets';
129
+
130
+ /** The room `Map.Controls` and `Map.Overlay` leave between themselves and an edge. */
131
+ const EDGE_GAP = 12;
96
132
 
97
133
  const mapVariants = tv({
98
134
  slots: {
99
135
  root: 'flex-1 overflow-hidden',
100
136
  controls: 'absolute gap-2',
137
+ overlay: 'absolute',
101
138
  // A control group is one surface split by hairlines rather than separate
102
139
  // buttons: at 36pt a gap between them reads as damage, not as spacing.
103
140
  group: 'overflow-hidden rounded-xl border border-border bg-card shadow-sm',
@@ -211,6 +248,33 @@ interface InternalMapContextValue extends MapContextValue {
211
248
 
212
249
  const MapContext = createContext<InternalMapContextValue | null>(null);
213
250
 
251
+ /**
252
+ * What the overlays have claimed, and how one claims it.
253
+ *
254
+ * Two contexts rather than a field on `MapContext`, because they change at
255
+ * different times. A claim changes whenever an overlay is laid out, and only
256
+ * the controls care; everything that reads `useMap()` for the camera would
257
+ * otherwise re-render each time a card above the map changed height.
258
+ */
259
+ const MapReservationsContext = createContext<readonly MapReservation[]>([]);
260
+ const MapReserveContext = createContext<
261
+ ((id: string, reservation: MapReservation | null) => void) | null
262
+ >(null);
263
+
264
+ const NO_SAFE_AREA = { top: 0, right: 0, bottom: 0, left: 0 };
265
+
266
+ /**
267
+ * The device's safe-area insets, or zeros when nothing provides them.
268
+ *
269
+ * Read from the context rather than through the package's hook, which throws
270
+ * outside a provider. A map does not need one to draw, so asking for one would
271
+ * turn a prop most maps never set into a requirement for all of them.
272
+ */
273
+ function useSafeArea(enabled: boolean) {
274
+ const insets = useContext(SafeAreaInsetsContext);
275
+ return enabled && insets ? insets : NO_SAFE_AREA;
276
+ }
277
+
214
278
  /**
215
279
  * The map's camera and view state, from inside it.
216
280
  *
@@ -386,6 +450,32 @@ const MapRoot = forwardRef<MapHandle, MapProps>(function MapRoot(
386
450
  []
387
451
  );
388
452
 
453
+ const [reservations, setReservations] = useState<
454
+ ReadonlyMap<string, MapReservation>
455
+ >(() => new globalThis.Map());
456
+
457
+ const reserve = useCallback((id: string, reservation: MapReservation | null) => {
458
+ setReservations((current) => {
459
+ const held = current.get(id);
460
+ // An overlay reports again whenever its insets are recomputed, usually
461
+ // with the figure it already gave. Keeping the old map when nothing
462
+ // moved is what stops that from re-rendering the controls.
463
+ if (
464
+ reservation
465
+ ? held?.position === reservation.position && held.extent === reservation.extent
466
+ : held === undefined
467
+ ) {
468
+ return current;
469
+ }
470
+ const next = new globalThis.Map(current);
471
+ if (reservation) next.set(id, reservation);
472
+ else next.delete(id);
473
+ return next;
474
+ });
475
+ }, []);
476
+
477
+ const reserved = useMemo(() => [...reservations.values()], [reservations]);
478
+
389
479
  // Every colour the style needs, resolved from the active theme. Hooks run
390
480
  // unconditionally, so they sit above the renderer check rather than inside it.
391
481
  const tokens: BasemapTokens = {
@@ -548,9 +638,13 @@ const MapRoot = forwardRef<MapHandle, MapProps>(function MapRoot(
548
638
  </MapLibreMap>
549
639
  ) : null}
550
640
  {overlay.length > 0 ? (
551
- <View style={StyleSheet.absoluteFill} pointerEvents="box-none">
552
- {textChildren(overlay)}
553
- </View>
641
+ <MapReserveContext.Provider value={reserve}>
642
+ <MapReservationsContext.Provider value={reserved}>
643
+ <View style={StyleSheet.absoluteFill} pointerEvents="box-none">
644
+ {textChildren(overlay)}
645
+ </View>
646
+ </MapReservationsContext.Provider>
647
+ </MapReserveContext.Provider>
554
648
  ) : null}
555
649
  <View
556
650
  accessibilityRole="list"
@@ -814,6 +908,19 @@ asMapLayer(MapPopup);
814
908
  export interface MapControlsProps {
815
909
  /** Which corner the stack sits in. */
816
910
  position?: MapControlsPosition;
911
+ /**
912
+ * How far the stack sits from the map's edges, in points: one number for
913
+ * every side, or only the sides that need one. Defaults to 12. For chrome
914
+ * that floats over the map without being inside it, such as a translucent
915
+ * tab bar or a header.
916
+ */
917
+ inset?: number | ViewPadding;
918
+ /**
919
+ * Keep clear of the status bar and the home indicator, for a map that runs
920
+ * underneath them. Reads the insets from the nearest `SafeAreaProvider` and
921
+ * does nothing without one.
922
+ */
923
+ safeArea?: boolean;
817
924
  /** Zoom in and out. On by default — it is the one control a map always needs. */
818
925
  zoom?: boolean;
819
926
  /** Recentre on the device's location. Needs a location permission. */
@@ -862,6 +969,8 @@ function ControlButton({
862
969
  */
863
970
  function MapControls({
864
971
  position = 'bottom-right',
972
+ inset,
973
+ safeArea = false,
865
974
  zoom = true,
866
975
  locate = false,
867
976
  compass = false,
@@ -871,6 +980,24 @@ function MapControls({
871
980
  }: MapControlsProps) {
872
981
  const slots = mapVariants({ position });
873
982
  const { mapRef, cameraRef, recenter: returnToStart } = useMap();
983
+ const safeAreaInsets = useSafeArea(safeArea);
984
+ const reservations = useContext(MapReservationsContext);
985
+ const offsets = controlsOffsets(position, {
986
+ gap: EDGE_GAP,
987
+ inset: resolveMapInsets(inset, EDGE_GAP, safeAreaInsets),
988
+ reserved: reservedAt(position, reservations),
989
+ });
990
+ /*
991
+ * Only the sides that have actually moved are set here. The corner itself
992
+ * comes from the classes, so a stack that nothing has pushed is styled
993
+ * exactly as it was before any of this existed, and a `className` that
994
+ * repositions it still wins.
995
+ */
996
+ const moved: MapOffsets = {};
997
+ for (const side of ['top', 'right', 'bottom', 'left'] as const) {
998
+ const value = offsets[side];
999
+ if (value !== undefined && value !== EDGE_GAP) moved[side] = value;
1000
+ }
874
1001
  // Every glyph takes the theme's icon colour from here rather than from its
875
1002
  // own default, which was chosen for wherever that icon first appeared — the
876
1003
  // minus sign's is white, for a checked checkbox, and vanished on the card.
@@ -925,7 +1052,7 @@ function MapControls({
925
1052
 
926
1053
  return (
927
1054
  <IconColorProvider color={iconTint}>
928
- <View className={slots.controls({ className })}>
1055
+ <View className={slots.controls({ className })} style={moved}>
929
1056
  {zoom ? (
930
1057
  <View className={slots.group()}>
931
1058
  <ControlButton label="Zoom in" onPress={() => nudgeZoom(1)}>
@@ -964,6 +1091,88 @@ function MapControls({
964
1091
  }
965
1092
  MapControls.displayName = 'Map.Controls';
966
1093
 
1094
+ export interface MapOverlayProps extends Omit<ViewProps, 'children'> {
1095
+ children?: ReactNode;
1096
+ /**
1097
+ * Where it is pinned: `top` or `bottom` for a band across the map between
1098
+ * its insets, or a corner (`top-left`, `top-right`, `bottom-left`,
1099
+ * `bottom-right`), which is as wide as what is inside it.
1100
+ */
1101
+ position?: MapOverlayPosition;
1102
+ /**
1103
+ * How far it sits from the map's edges, in points: one number for every
1104
+ * side, or only the sides that need one. Defaults to 12. Pass `0` for a card
1105
+ * that runs edge to edge.
1106
+ */
1107
+ inset?: number | ViewPadding;
1108
+ /**
1109
+ * Keep clear of the status bar and the home indicator, for a map that runs
1110
+ * underneath them. Reads the insets from the nearest `SafeAreaProvider` and
1111
+ * does nothing without one.
1112
+ */
1113
+ safeArea?: boolean;
1114
+ className?: string;
1115
+ }
1116
+
1117
+ /**
1118
+ * A place for your own views over the map.
1119
+ *
1120
+ * Any view can already be a child of `Map` and positioned by hand. What this
1121
+ * adds is that the map knows about it: it is measured, and a `Map.Controls`
1122
+ * in the same corner moves past it. Without that each is positioned without
1123
+ * knowing where the other is, and the card lands on the zoom buttons.
1124
+ *
1125
+ * The container itself takes no touches, so the map underneath still pans in
1126
+ * the gaps around whatever is inside it.
1127
+ */
1128
+ function MapOverlay({
1129
+ position = 'bottom',
1130
+ inset,
1131
+ safeArea = false,
1132
+ className,
1133
+ style,
1134
+ onLayout,
1135
+ children,
1136
+ ...props
1137
+ }: MapOverlayProps) {
1138
+ const slots = mapVariants();
1139
+ const id = useId();
1140
+ const reserve = useContext(MapReserveContext);
1141
+ const safeAreaInsets = useSafeArea(safeArea);
1142
+ const insets = resolveMapInsets(inset, EDGE_GAP, safeAreaInsets);
1143
+ const { top, right, bottom, left } = insets;
1144
+ const [height, setHeight] = useState(0);
1145
+
1146
+ useEffect(() => {
1147
+ reserve?.(id, overlayReservation(position, { top, right, bottom, left }, height));
1148
+ }, [reserve, id, position, top, right, bottom, left, height]);
1149
+
1150
+ // Its own effect, so the claim is given up once on unmount rather than
1151
+ // dropped and re-made every time the card changes height.
1152
+ useEffect(() => () => reserve?.(id, null), [reserve, id]);
1153
+
1154
+ const handleLayout = useCallback(
1155
+ (event: LayoutChangeEvent) => {
1156
+ setHeight(event.nativeEvent.layout.height);
1157
+ onLayout?.(event);
1158
+ },
1159
+ [onLayout]
1160
+ );
1161
+
1162
+ return (
1163
+ <View
1164
+ pointerEvents="box-none"
1165
+ className={slots.overlay({ className })}
1166
+ style={[overlayOffsets(position, insets), style]}
1167
+ onLayout={handleLayout}
1168
+ {...props}
1169
+ >
1170
+ {textChildren(children)}
1171
+ </View>
1172
+ );
1173
+ }
1174
+ MapOverlay.displayName = 'Map.Overlay';
1175
+
967
1176
  /** Turns a token into a colour a style layer can use. */
968
1177
  function useLineColor(color?: string) {
969
1178
  const fallback = useToken('--color-primary', '#262626');
@@ -1547,6 +1756,7 @@ export const Map = Object.assign(MapRoot, {
1547
1756
  Label: MapLabel,
1548
1757
  Popup: MapPopup,
1549
1758
  Controls: MapControls,
1759
+ Overlay: MapOverlay,
1550
1760
  Route: MapRoute,
1551
1761
  Arc: MapArc,
1552
1762
  GeoJSON: MapGeoJSON,
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Where things sit once something else is drawn over the map.
3
+ *
4
+ * A map that fills the screen usually has chrome on top of it: a card of
5
+ * figures along the top, a summary along the bottom, the status bar, a
6
+ * floating tab bar. The controls belong in a corner, and a corner is exactly
7
+ * where that chrome goes, so left alone they end up underneath it.
8
+ *
9
+ * Everything drawn over the map therefore says how far in from its edge it
10
+ * reaches, and the controls take the largest claim on their corner and sit
11
+ * past it. This file is that arithmetic and nothing else, kept apart from the
12
+ * views so it can be checked without a device.
13
+ */
14
+
15
+ export type MapCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
16
+
17
+ /** A band across the whole of one edge, or a single corner. */
18
+ export type MapOverlayPosition = 'top' | 'bottom' | MapCorner;
19
+
20
+ /** A distance from each edge of the map, in points. */
21
+ export interface MapInsets {
22
+ top: number;
23
+ right: number;
24
+ bottom: number;
25
+ left: number;
26
+ }
27
+
28
+ /** One number for every side, or only the sides that need one. */
29
+ export type MapInsetsInput = number | Partial<MapInsets>;
30
+
31
+ /** What one overlay takes: where it is, and how far in from that edge it reaches. */
32
+ export interface MapReservation {
33
+ position: MapOverlayPosition;
34
+ /** Points from the map's top or bottom edge to the overlay's far side. */
35
+ extent: number;
36
+ }
37
+
38
+ /** The style offsets that pin a view: one vertical side and, for a corner, one horizontal. */
39
+ export type MapOffsets = Partial<MapInsets>;
40
+
41
+ /** A negative or missing inset is no inset. A view pushed off the map helps nobody. */
42
+ function clean(value: number | undefined): number {
43
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
44
+ }
45
+
46
+ /** Expands the `inset` shorthand to four sides. */
47
+ export function toMapInsets(inset: MapInsetsInput | undefined): MapInsets {
48
+ if (typeof inset === 'number') {
49
+ const value = clean(inset);
50
+ return { top: value, right: value, bottom: value, left: value };
51
+ }
52
+ return {
53
+ top: clean(inset?.top),
54
+ right: clean(inset?.right),
55
+ bottom: clean(inset?.bottom),
56
+ left: clean(inset?.left),
57
+ };
58
+ }
59
+
60
+ /** Two sets of insets, side by side. */
61
+ export function addMapInsets(a: MapInsets, b: MapInsets): MapInsets {
62
+ return {
63
+ top: a.top + b.top,
64
+ right: a.right + b.right,
65
+ bottom: a.bottom + b.bottom,
66
+ left: a.left + b.left,
67
+ };
68
+ }
69
+
70
+ /** The corners a position covers. A band covers both corners of its edge. */
71
+ export function cornersOf(position: MapOverlayPosition): MapCorner[] {
72
+ if (position === 'top') return ['top-left', 'top-right'];
73
+ if (position === 'bottom') return ['bottom-left', 'bottom-right'];
74
+ return [position];
75
+ }
76
+
77
+ /** The furthest any overlay reaches into a corner. 0 when nothing is there. */
78
+ export function reservedAt(
79
+ corner: MapCorner,
80
+ reservations: Iterable<MapReservation>
81
+ ): number {
82
+ let reserved = 0;
83
+ for (const { position, extent } of reservations) {
84
+ if (extent > reserved && cornersOf(position).includes(corner)) reserved = extent;
85
+ }
86
+ return reserved;
87
+ }
88
+
89
+ /**
90
+ * Where an overlay is pinned, and how far it reaches once it has a height.
91
+ *
92
+ * A band is pinned on three sides so it spans the map between its insets. A
93
+ * corner is pinned on two and is as wide as what is inside it.
94
+ */
95
+ export function overlayOffsets(position: MapOverlayPosition, inset: MapInsets): MapOffsets {
96
+ const vertical = position.startsWith('top') ? { top: inset.top } : { bottom: inset.bottom };
97
+ if (position === 'top' || position === 'bottom') {
98
+ return { ...vertical, left: inset.left, right: inset.right };
99
+ }
100
+ return position.endsWith('left')
101
+ ? { ...vertical, left: inset.left }
102
+ : { ...vertical, right: inset.right };
103
+ }
104
+
105
+ /**
106
+ * The reservation an overlay makes once it has been measured.
107
+ *
108
+ * Nothing until it has a height. An overlay that is empty, or has not been
109
+ * laid out yet, would otherwise claim its inset alone and nudge the controls
110
+ * by a gap for a frame before moving them to where they belong.
111
+ */
112
+ export function overlayReservation(
113
+ position: MapOverlayPosition,
114
+ inset: MapInsets,
115
+ height: number
116
+ ): MapReservation | null {
117
+ if (clean(height) === 0) return null;
118
+ const edge = position.startsWith('top') ? inset.top : inset.bottom;
119
+ return { position, extent: edge + height };
120
+ }
121
+
122
+ /**
123
+ * The distance a part keeps from each edge of the map.
124
+ *
125
+ * `inset` means the same thing on `Map.Controls` and `Map.Overlay`: how far
126
+ * from the edge, with the standard gap on any side it leaves out. The safe
127
+ * area is added on top, because a card 12 points from the edge of the screen
128
+ * and a card 12 points below the status bar are both "12 points in" to the
129
+ * person looking at them.
130
+ */
131
+ export function resolveMapInsets(
132
+ inset: MapInsetsInput | undefined,
133
+ gap: number,
134
+ safeArea: MapInsets
135
+ ): MapInsets {
136
+ const own =
137
+ typeof inset === 'number'
138
+ ? toMapInsets(inset)
139
+ : toMapInsets({
140
+ top: inset?.top ?? gap,
141
+ right: inset?.right ?? gap,
142
+ bottom: inset?.bottom ?? gap,
143
+ left: inset?.left ?? gap,
144
+ });
145
+ return addMapInsets(own, toMapInsets(safeArea));
146
+ }
147
+
148
+ /**
149
+ * Where a control stack in `corner` goes.
150
+ *
151
+ * `inset` is the stack's own distance from the map's edges. `reserved` is what
152
+ * an overlay has taken from the same edge, and the stack sits one `gap` past
153
+ * it. The two are not added: an overlay that already clears the status bar has
154
+ * cleared it for the controls too, so whichever reaches further decides.
155
+ */
156
+ export function controlsOffsets(
157
+ corner: MapCorner,
158
+ { gap, inset, reserved }: { gap: number; inset: MapInsets; reserved: number }
159
+ ): MapOffsets {
160
+ const top = corner.startsWith('top');
161
+ const left = corner.endsWith('left');
162
+ const past = clean(reserved) > 0 ? clean(reserved) + gap : 0;
163
+ const vertical = Math.max(top ? inset.top : inset.bottom, past);
164
+ const horizontal = left ? inset.left : inset.right;
165
+ return {
166
+ ...(top ? { top: vertical } : { bottom: vertical }),
167
+ ...(left ? { left: horizontal } : { right: horizontal }),
168
+ };
169
+ }
@@ -49,10 +49,49 @@ const itemVariants = tv({
49
49
  row: 'min-h-12 min-w-12 flex-row items-center gap-2.5 self-start',
50
50
  indicator:
51
51
  'h-5 w-5 items-center justify-center rounded-full border border-input bg-background',
52
+ // Half the disc it sits in, at every size.
53
+ dot: 'h-2.5 w-2.5 rounded-full bg-primary',
52
54
  label: 'text-sm text-foreground',
53
55
  description: 'text-xs text-muted-foreground',
54
56
  },
55
57
  variants: {
58
+ /*
59
+ * The disc, its dot and the text beside it move together, on the same
60
+ * steps as Checkbox so the two line up in one form. The row stays 48
61
+ * points tall at every size, because that is the touch target.
62
+ *
63
+ * Listed before `variant` so the card keeps the label weight it sets.
64
+ */
65
+ size: {
66
+ xs: {
67
+ row: 'gap-2',
68
+ indicator: 'h-3.5 w-3.5',
69
+ dot: 'h-1.5 w-1.5',
70
+ label: 'text-xs',
71
+ description: 'text-[11px]',
72
+ },
73
+ sm: {
74
+ row: 'gap-2',
75
+ indicator: 'h-4 w-4',
76
+ dot: 'h-2 w-2',
77
+ label: 'text-[13px]',
78
+ },
79
+ md: {},
80
+ lg: {
81
+ row: 'gap-3',
82
+ indicator: 'h-6 w-6',
83
+ dot: 'h-3 w-3',
84
+ label: 'text-base',
85
+ description: 'text-sm',
86
+ },
87
+ xl: {
88
+ row: 'gap-3',
89
+ indicator: 'h-7 w-7',
90
+ dot: 'h-3.5 w-3.5',
91
+ label: 'text-lg',
92
+ description: 'text-sm',
93
+ },
94
+ },
56
95
  variant: {
57
96
  dot: {},
58
97
  card: {
@@ -85,14 +124,19 @@ const itemVariants = tv({
85
124
  ],
86
125
  defaultVariants: {
87
126
  variant: 'dot',
127
+ size: 'md',
88
128
  },
89
129
  });
90
130
 
131
+ /** How big a group's discs and labels are. */
132
+ type RadioSize = NonNullable<VariantProps<typeof itemVariants>['size']>;
133
+
91
134
  interface RadioGroupContextValue {
92
135
  value: string | undefined;
93
136
  onValueChange: (value: string) => void;
94
137
  disabled?: boolean;
95
138
  variant: RadioVariant;
139
+ size: RadioSize;
96
140
  orientation: RadioOrientation;
97
141
  }
98
142
 
@@ -109,6 +153,12 @@ export interface RadioGroupProps extends ViewProps {
109
153
  * settings choice where each option carries a description.
110
154
  */
111
155
  variant?: RadioVariant;
156
+ /**
157
+ * How big every option's disc and label are. Set on the group rather than
158
+ * per option, because options of different sizes read as though one of them
159
+ * matters more. The row keeps a 48-point target at every size.
160
+ */
161
+ size?: RadioSize;
112
162
  /**
113
163
  * `horizontal` lays the options out along a row that wraps — for two or
114
164
  * three short choices, where a stacked list wastes the width and reads as
@@ -126,6 +176,7 @@ const RadioGroupRoot = forwardRef<View, RadioGroupProps>(
126
176
  onValueChange,
127
177
  disabled,
128
178
  variant = 'dot',
179
+ size = 'md',
129
180
  orientation = 'vertical',
130
181
  children,
131
182
  ...props
@@ -133,8 +184,8 @@ const RadioGroupRoot = forwardRef<View, RadioGroupProps>(
133
184
  ref
134
185
  ) => {
135
186
  const context = useMemo(
136
- () => ({ value, onValueChange, disabled, variant, orientation }),
137
- [value, onValueChange, disabled, variant, orientation]
187
+ () => ({ value, onValueChange, disabled, variant, size, orientation }),
188
+ [value, onValueChange, disabled, variant, size, orientation]
138
189
  );
139
190
 
140
191
  return (
@@ -220,6 +271,7 @@ const RadioGroupItem = forwardRef<View, RadioGroupItemProps>(
220
271
 
221
272
  const slots = itemVariants({
222
273
  variant,
274
+ size: context.size,
223
275
  selected,
224
276
  disabled: !!disabled,
225
277
  horizontal: context.orientation === 'horizontal',
@@ -227,7 +279,7 @@ const RadioGroupItem = forwardRef<View, RadioGroupItemProps>(
227
279
 
228
280
  const indicator = hideIndicator ? null : (
229
281
  <View className={slots.indicator()}>
230
- <Animated.View style={dotStyle} className="h-2.5 w-2.5 rounded-full bg-primary" />
282
+ <Animated.View style={dotStyle} className={slots.dot()} />
231
283
  </View>
232
284
  );
233
285
 
@@ -287,4 +339,4 @@ export const RadioGroup = Object.assign(RadioGroupRoot, {
287
339
  Item: RadioGroupItem,
288
340
  });
289
341
 
290
- export type { RadioVariant };
342
+ export type { RadioVariant, RadioSize };