@brand-map/primitives 0.0.0-broken.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/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.oxfmtrc.json +35 -0
  4. package/.oxlintrc.json +166 -0
  5. package/README.md +78 -0
  6. package/bun.lock +904 -0
  7. package/mise.toml +3 -0
  8. package/package.json +61 -0
  9. package/src/accordion/accordion.tsx +189 -0
  10. package/src/accordion/accordion.web.tsx +282 -0
  11. package/src/accordion/index.ts +2 -0
  12. package/src/accordion/types.ts +44 -0
  13. package/src/alert-dialog/alert-dialog.tsx +238 -0
  14. package/src/alert-dialog/alert-dialog.web.tsx +260 -0
  15. package/src/alert-dialog/index.ts +2 -0
  16. package/src/alert-dialog/types.ts +81 -0
  17. package/src/aspect-ratio/aspect-ratio.tsx +27 -0
  18. package/src/aspect-ratio/index.ts +1 -0
  19. package/src/avatar/avatar.tsx +122 -0
  20. package/src/avatar/index.ts +2 -0
  21. package/src/avatar/types.ts +20 -0
  22. package/src/checkbox/checkbox.tsx +95 -0
  23. package/src/checkbox/checkbox.web.tsx +111 -0
  24. package/src/checkbox/index.ts +2 -0
  25. package/src/checkbox/types.ts +14 -0
  26. package/src/collapsible/collapsible.tsx +98 -0
  27. package/src/collapsible/collapsible.web.tsx +149 -0
  28. package/src/collapsible/index.ts +2 -0
  29. package/src/collapsible/types.ts +23 -0
  30. package/src/context-menu/context-menu.tsx +616 -0
  31. package/src/context-menu/context-menu.web.tsx +560 -0
  32. package/src/context-menu/index.ts +2 -0
  33. package/src/context-menu/types.ts +136 -0
  34. package/src/dialog/dialog.tsx +286 -0
  35. package/src/dialog/dialog.web.tsx +215 -0
  36. package/src/dialog/index.ts +2 -0
  37. package/src/dialog/types.ts +92 -0
  38. package/src/dropdown-menu/dropdown-menu.tsx +575 -0
  39. package/src/dropdown-menu/dropdown-menu.web.tsx +565 -0
  40. package/src/dropdown-menu/index.ts +2 -0
  41. package/src/dropdown-menu/types.ts +121 -0
  42. package/src/hooks/index.ts +4 -0
  43. package/src/hooks/use-Isomorphic-layout-effect.tsx +12 -0
  44. package/src/hooks/use-augmented-ref.tsx +25 -0
  45. package/src/hooks/use-controllable-state.tsx +70 -0
  46. package/src/hooks/use-relative-position.tsx +175 -0
  47. package/src/hover-card/hover-card.tsx +255 -0
  48. package/src/hover-card/hover-card.web.tsx +161 -0
  49. package/src/hover-card/index.ts +2 -0
  50. package/src/hover-card/types.ts +56 -0
  51. package/src/label/index.ts +2 -0
  52. package/src/label/label.tsx +36 -0
  53. package/src/label/label.web.tsx +38 -0
  54. package/src/label/types.ts +24 -0
  55. package/src/menubar/index.ts +2 -0
  56. package/src/menubar/menubar.tsx +602 -0
  57. package/src/menubar/menubar.web.tsx +575 -0
  58. package/src/menubar/types.ts +126 -0
  59. package/src/navigation-menu/index.ts +2 -0
  60. package/src/navigation-menu/navigation-menu.tsx +302 -0
  61. package/src/navigation-menu/navigation-menu.web.tsx +259 -0
  62. package/src/navigation-menu/types.ts +85 -0
  63. package/src/popover/index.ts +2 -0
  64. package/src/popover/popover.tsx +279 -0
  65. package/src/popover/popover.web.tsx +217 -0
  66. package/src/popover/types.ts +44 -0
  67. package/src/portal/index.ts +1 -0
  68. package/src/portal/portal.tsx +56 -0
  69. package/src/progress/index.ts +2 -0
  70. package/src/progress/progress.tsx +59 -0
  71. package/src/progress/progress.web.tsx +46 -0
  72. package/src/progress/types.ts +14 -0
  73. package/src/radio-group/index.ts +2 -0
  74. package/src/radio-group/radio-group.tsx +106 -0
  75. package/src/radio-group/radio-group.web.tsx +85 -0
  76. package/src/radio-group/types.ts +24 -0
  77. package/src/select/index.ts +2 -0
  78. package/src/select/select.tsx +447 -0
  79. package/src/select/select.web.tsx +368 -0
  80. package/src/select/types.ts +145 -0
  81. package/src/separator/index.ts +2 -0
  82. package/src/separator/separator.tsx +21 -0
  83. package/src/separator/types.ts +10 -0
  84. package/src/slider/index.ts +2 -0
  85. package/src/slider/slider.tsx +77 -0
  86. package/src/slider/slider.web.tsx +75 -0
  87. package/src/slider/types.ts +39 -0
  88. package/src/slot/index.ts +1 -0
  89. package/src/slot/slot.tsx +224 -0
  90. package/src/switch/index.ts +2 -0
  91. package/src/switch/switch.tsx +49 -0
  92. package/src/switch/switch.web.tsx +60 -0
  93. package/src/switch/types.ts +19 -0
  94. package/src/table/index.ts +1 -0
  95. package/src/table/table.tsx +121 -0
  96. package/src/tabs/index.ts +2 -0
  97. package/src/tabs/tabs.tsx +120 -0
  98. package/src/tabs/tabs.web.tsx +106 -0
  99. package/src/tabs/types.ts +37 -0
  100. package/src/toast/index.ts +2 -0
  101. package/src/toast/toast.tsx +124 -0
  102. package/src/toast/types.ts +20 -0
  103. package/src/toggle/index.ts +2 -0
  104. package/src/toggle/toggle.tsx +35 -0
  105. package/src/toggle/toggle.web.tsx +36 -0
  106. package/src/toggle/types.ts +11 -0
  107. package/src/toggle-group/index.ts +2 -0
  108. package/src/toggle-group/toggle-group.tsx +100 -0
  109. package/src/toggle-group/toggle-group.web.tsx +103 -0
  110. package/src/toggle-group/types.ts +46 -0
  111. package/src/toolbar/index.ts +2 -0
  112. package/src/toolbar/toolbar.tsx +141 -0
  113. package/src/toolbar/toolbar.web.tsx +158 -0
  114. package/src/toolbar/types.ts +64 -0
  115. package/src/tooltip/index.ts +2 -0
  116. package/src/tooltip/tooltip.tsx +261 -0
  117. package/src/tooltip/tooltip.web.tsx +175 -0
  118. package/src/tooltip/types.ts +61 -0
  119. package/src/types/index.ts +141 -0
  120. package/src/utils/index.ts +69 -0
  121. package/tsconfig.json +23 -0
@@ -0,0 +1,14 @@
1
+ import { RenderViewProps, ViewRef } from "../types";
2
+
3
+ type RootProps = RenderViewProps & {
4
+ value?: number | null | undefined;
5
+ max?: number;
6
+ getValueLabel?(value: number, max: number): string;
7
+ };
8
+
9
+ type IndicatorProps = RenderViewProps;
10
+
11
+ type RootRef = ViewRef;
12
+ type IndicatorRef = ViewRef;
13
+
14
+ export type { IndicatorProps, IndicatorRef, RootProps, RootRef };
@@ -0,0 +1,2 @@
1
+ export * from "./radio-group";
2
+ export * from "./types";
@@ -0,0 +1,106 @@
1
+ import * as React from "react";
2
+ import { Pressable, View, type GestureResponderEvent } from "react-native";
3
+
4
+ import * as Slot from "../slot";
5
+
6
+ import type { IndicatorProps, IndicatorRef, ItemProps, ItemRef, RootProps, RootRef } from "./types";
7
+
8
+ const RadioGroupContext = React.createContext<RootProps | null>(null);
9
+
10
+ const Root = React.forwardRef<RootRef, RootProps>(({ value, onValueChange, disabled = false, ...viewProps }, ref) => {
11
+ return (
12
+ <RadioGroupContext.Provider
13
+ value={{
14
+ value,
15
+ disabled,
16
+ onValueChange,
17
+ }}
18
+ >
19
+ <Component
20
+ ref={ref}
21
+ role="radiogroup"
22
+ {...viewProps}
23
+ />
24
+ </RadioGroupContext.Provider>
25
+ );
26
+ });
27
+
28
+ Root.displayName = "RootRadioGroup";
29
+
30
+ function useRadioGroupContext() {
31
+ const context = React.useContext(RadioGroupContext);
32
+ if (!context) {
33
+ throw new Error("RadioGroup compound components cannot be rendered outside the RadioGroup component");
34
+ }
35
+ return context;
36
+ }
37
+
38
+ interface RadioItemContext {
39
+ itemValue: string | undefined;
40
+ }
41
+
42
+ const RadioItemContext = React.createContext<RadioItemContext | null>(null);
43
+
44
+ const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
45
+ const { disabled, value, onValueChange } = useRadioGroupContext();
46
+
47
+ function onPress(ev: GestureResponderEvent) {
48
+ if (disabled || disabledProp) return;
49
+ onValueChange(itemValue);
50
+ onPressProp?.(ev);
51
+ }
52
+
53
+ return (
54
+ <RadioItemContext.Provider
55
+ value={{
56
+ itemValue: itemValue,
57
+ }}
58
+ >
59
+ <Component
60
+ ref={ref}
61
+ role="radio"
62
+ onPress={onPress}
63
+ aria-checked={value === itemValue}
64
+ disabled={(disabled || disabledProp) ?? false}
65
+ accessibilityState={{
66
+ disabled: (disabled || disabledProp) ?? false,
67
+ checked: value === itemValue,
68
+ }}
69
+ {...props}
70
+ />
71
+ </RadioItemContext.Provider>
72
+ );
73
+ });
74
+
75
+ Item.displayName = "ItemRadioGroup";
76
+
77
+ function useRadioItemContext() {
78
+ const context = React.useContext(RadioItemContext);
79
+ if (!context) {
80
+ throw new Error("RadioItem compound components cannot be rendered outside the RadioItem component");
81
+ }
82
+ return context;
83
+ }
84
+
85
+ const Indicator = React.forwardRef<IndicatorRef, IndicatorProps>(({ keepMounted, ...props }, ref) => {
86
+ const { value } = useRadioGroupContext();
87
+ const { itemValue } = useRadioItemContext();
88
+
89
+ if (!keepMounted) {
90
+ if (value !== itemValue) {
91
+ return null;
92
+ }
93
+ }
94
+
95
+ return (
96
+ <Component
97
+ ref={ref}
98
+ role="presentation"
99
+ {...props}
100
+ />
101
+ );
102
+ });
103
+
104
+ Indicator.displayName = "IndicatorRadioGroup";
105
+
106
+ export { Indicator, Item, Root };
@@ -0,0 +1,85 @@
1
+ // import * as RadioGroup from "@radix-ui/react-radio-group";
2
+ // import * as React from "react";
3
+ // import { GestureResponderEvent, Pressable, View } from "react-native";
4
+
5
+ // import * as Slot from "../slot";
6
+
7
+ // import type { IndicatorProps, IndicatorRef, ItemProps, ItemRef, RootProps, RootRef } from "./types";
8
+
9
+ // const RadioGroupContext = React.createContext<RootProps | null>(null);
10
+
11
+ // const Root = React.forwardRef<RootRef, RootProps>(({ value, onValueChange, disabled = false, ...viewProps }, ref) => {
12
+ //
13
+ // return (
14
+ // <RadioGroupContext.Provider
15
+ // value={{
16
+ // value,
17
+ // disabled,
18
+ // onValueChange,
19
+ // }}
20
+ // >
21
+ // <RadioGroup.Root
22
+ // value={value}
23
+ // onValueChange={onValueChange}
24
+ // disabled={disabled}
25
+ // render
26
+ // >
27
+ // <Component
28
+ // ref={ref}
29
+ // {...viewProps}
30
+ // />
31
+ // </RadioGroup.Root>
32
+ // </RadioGroupContext.Provider>
33
+ // );
34
+ // });
35
+
36
+ // Root.displayName = "RootRadioGroup";
37
+ // function useRadioGroupContext() {
38
+ // const context = React.useContext(RadioGroupContext);
39
+ // if (!context) {
40
+ // throw new Error("RadioGroup compound components cannot be rendered outside the RadioGroup component");
41
+ // }
42
+ // return context;
43
+ // }
44
+ // const Item = React.forwardRef<ItemRef, ItemProps>(({ value, onPress: onPressProps, ...props }, ref) => {
45
+ // const { onValueChange } = useRadioGroupContext();
46
+
47
+ // function onPress(ev: GestureResponderEvent) {
48
+ // if (onPressProps) {
49
+ // onPressProps(ev);
50
+ // }
51
+ // onValueChange(value);
52
+ // }
53
+
54
+ //
55
+ // return (
56
+ // <RadioGroup.Item
57
+ // value={value}
58
+ // render
59
+ // >
60
+ // <Component
61
+ // ref={ref}
62
+ // onPress={onPress}
63
+ // {...props}
64
+ // />
65
+ // </RadioGroup.Item>
66
+ // );
67
+ // });
68
+
69
+ // Item.displayName = "ItemRadioGroup";
70
+
71
+ // const Indicator = React.forwardRef<IndicatorRef, IndicatorProps>(({ keepMounted, ...props }, ref) => {
72
+ //
73
+ // return (
74
+ // <RadioGroup.Indicator render>
75
+ // <Component
76
+ // ref={ref}
77
+ // {...props}
78
+ // />
79
+ // </RadioGroup.Indicator>
80
+ // );
81
+ // });
82
+
83
+ // Indicator.displayName = "IndicatorRadioGroup";
84
+
85
+ // export { Indicator, Item, Root };
@@ -0,0 +1,24 @@
1
+ import { KeepMountable, PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
2
+
3
+ type RootProps = RenderViewProps & {
4
+ value: string | undefined;
5
+ onValueChange: (val: string) => void;
6
+ disabled?: boolean;
7
+ };
8
+
9
+ type ItemProps = RenderPressableProps & {
10
+ "value": string;
11
+
12
+ /**
13
+ * nativeID of the label element that describes this radio group item
14
+ */
15
+ "aria-labelledby"?: string;
16
+ };
17
+
18
+ type IndicatorProps = RenderViewProps & KeepMountable;
19
+
20
+ type RootRef = ViewRef;
21
+ type ItemRef = PressableRef;
22
+ type IndicatorRef = ViewRef;
23
+
24
+ export type { IndicatorProps, IndicatorRef, ItemProps, ItemRef, RootProps, RootRef };
@@ -0,0 +1,2 @@
1
+ export * from "./select";
2
+ export * from "./types";
@@ -0,0 +1,447 @@
1
+ import * as React from "react";
2
+ import { BackHandler, Pressable, Text, View, type GestureResponderEvent, type LayoutChangeEvent, type LayoutRectangle } from "react-native";
3
+
4
+ import { useAugmentedRef, useControllableState, useRelativePosition, type LayoutPosition } from "../hooks";
5
+ import { Portal as RNPPortal } from "../portal";
6
+ import * as Slot from "../slot";
7
+
8
+ import type {
9
+ ContentProps,
10
+ ContentRef,
11
+ GroupProps,
12
+ GroupRef,
13
+ ItemIndicatorProps,
14
+ ItemIndicatorRef,
15
+ ItemProps,
16
+ ItemRef,
17
+ ItemTextProps,
18
+ ItemTextRef,
19
+ LabelProps,
20
+ LabelRef,
21
+ BackdropProps,
22
+ BackdropRef,
23
+ PortalProps,
24
+ RootProps,
25
+ RootRef,
26
+ ScrollDownButtonProps,
27
+ ScrollUpButtonProps,
28
+ SeparatorProps,
29
+ SeparatorRef,
30
+ SharedRootContext,
31
+ TriggerProps,
32
+ TriggerRef,
33
+ ValueProps,
34
+ ValueRef,
35
+ ViewportProps,
36
+ } from "./types";
37
+
38
+ interface RootContextInterface extends SharedRootContext {
39
+ open: boolean;
40
+ onOpenChange: (open: boolean) => void;
41
+ triggerPosition: LayoutPosition | null;
42
+ setTriggerPosition: (triggerPosition: LayoutPosition | null) => void;
43
+ contentLayout: LayoutRectangle | null;
44
+ setContentLayout: (contentLayout: LayoutRectangle | null) => void;
45
+ nativeID: string;
46
+ }
47
+
48
+ const RootContext = React.createContext<RootContextInterface | null>(null);
49
+
50
+ const Root = React.forwardRef<RootRef, RootProps>(
51
+ ({ render, value: valueProp, defaultValue, onValueChange: onValueChangeProp, onOpenChange: onOpenChangeProp, disabled, ...viewProps }, ref) => {
52
+ const nativeID = React.useId();
53
+ const [value, onValueChange] = useControllableState({
54
+ prop: valueProp,
55
+ defaultProp: defaultValue,
56
+ onChange: onValueChangeProp,
57
+ });
58
+ const [triggerPosition, setTriggerPosition] = React.useState<LayoutPosition | null>(null);
59
+ const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
60
+ const [open, setOpen] = React.useState(false);
61
+
62
+ function onOpenChange(value: boolean) {
63
+ setOpen(value);
64
+ onOpenChangeProp?.(value);
65
+ }
66
+
67
+ return (
68
+ <RootContext.Provider
69
+ value={{
70
+ value,
71
+ onValueChange,
72
+ open,
73
+ onOpenChange,
74
+ disabled,
75
+ contentLayout,
76
+ nativeID,
77
+ setContentLayout,
78
+ setTriggerPosition,
79
+ triggerPosition,
80
+ }}
81
+ >
82
+ <Component
83
+ ref={ref}
84
+ {...viewProps}
85
+ />
86
+ </RootContext.Provider>
87
+ );
88
+ },
89
+ );
90
+
91
+ Root.displayName = "RootNativeSelect";
92
+
93
+ function useRootContext() {
94
+ const context = React.useContext(RootContext);
95
+ if (!context) {
96
+ throw new Error("Select compound components cannot be rendered outside the Select component");
97
+ }
98
+ return context;
99
+ }
100
+
101
+ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
102
+ const { open, onOpenChange, disabled: disabledRoot, setTriggerPosition } = useRootContext();
103
+
104
+ const augmentedRef = useAugmentedRef({
105
+ ref,
106
+ methods: {
107
+ open: () => {
108
+ onOpenChange(true);
109
+ augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
110
+ setTriggerPosition({ width, pageX, pageY: pageY, height });
111
+ });
112
+ },
113
+ close: () => {
114
+ setTriggerPosition(null);
115
+ onOpenChange(false);
116
+ },
117
+ },
118
+ });
119
+
120
+ function onPress(ev: GestureResponderEvent) {
121
+ if (disabled) return;
122
+ augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
123
+ setTriggerPosition({ width, pageX, pageY: pageY, height });
124
+ });
125
+ onOpenChange(!open);
126
+ onPressProp?.(ev);
127
+ }
128
+
129
+ return (
130
+ <Component
131
+ ref={augmentedRef}
132
+ aria-disabled={disabled ?? undefined}
133
+ role="combobox"
134
+ onPress={onPress}
135
+ disabled={disabled ?? disabledRoot}
136
+ aria-expanded={open}
137
+ {...props}
138
+ />
139
+ );
140
+ });
141
+
142
+ Trigger.displayName = "TriggerNativeSelect";
143
+
144
+ const Value = React.forwardRef<ValueRef, ValueProps>(({ placeholder, ...props }, ref) => {
145
+ const { value } = useRootContext();
146
+
147
+ return (
148
+ <Component
149
+ ref={ref}
150
+ {...props}
151
+ >
152
+ {value?.label ?? placeholder}
153
+ </Component>
154
+ );
155
+ });
156
+
157
+ Value.displayName = "ValueNativeSelect";
158
+
159
+ /**
160
+ * @warning when using a custom `<PortalHost />`, you might have to adjust the Content's sideOffset.
161
+ */
162
+ function Portal({ keepMounted, hostName, children }: PortalProps) {
163
+ const value = useRootContext();
164
+
165
+ if (!value.triggerPosition) {
166
+ return null;
167
+ }
168
+
169
+ if (!keepMounted) {
170
+ if (!value.open) {
171
+ return null;
172
+ }
173
+ }
174
+
175
+ return (
176
+ <RNPPortal
177
+ hostName={hostName}
178
+ name={`${value.nativeID}_portal`}
179
+ >
180
+ <RootContext.Provider value={value}>{children}</RootContext.Provider>
181
+ </RNPPortal>
182
+ );
183
+ }
184
+
185
+ const Backdrop = React.forwardRef<BackdropRef, BackdropProps>(({ keepMounted, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => {
186
+ const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
187
+
188
+ function onPress(ev: GestureResponderEvent) {
189
+ if (closeOnPress) {
190
+ setTriggerPosition(null);
191
+ setContentLayout(null);
192
+ onOpenChange(false);
193
+ }
194
+ OnPressProp?.(ev);
195
+ }
196
+
197
+ if (!keepMounted) {
198
+ if (!open) {
199
+ return null;
200
+ }
201
+ }
202
+
203
+ return (
204
+ <Component
205
+ ref={ref}
206
+ onPress={onPress}
207
+ {...props}
208
+ />
209
+ );
210
+ });
211
+
212
+ Backdrop.displayName = "BackdropNativeSelect";
213
+
214
+ /**
215
+ * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
216
+ */
217
+ const Content = React.forwardRef<ContentRef, ContentProps>(
218
+ (
219
+ {
220
+ render = false,
221
+ keepMounted,
222
+ align = "start",
223
+ side = "bottom",
224
+ sideOffset = 0,
225
+ alignOffset = 0,
226
+ avoidCollisions = true,
227
+ onLayout: onLayoutProp,
228
+ insets,
229
+ style,
230
+ disablePositioningStyle,
231
+ position: _position,
232
+ ...props
233
+ },
234
+ ref,
235
+ ) => {
236
+ const { open, onOpenChange, contentLayout, nativeID, triggerPosition, setContentLayout, setTriggerPosition } = useRootContext();
237
+
238
+ React.useEffect(() => {
239
+ const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
240
+ setTriggerPosition(null);
241
+ setContentLayout(null);
242
+ onOpenChange(false);
243
+ return true;
244
+ });
245
+
246
+ return () => {
247
+ setContentLayout(null);
248
+ backHandler.remove();
249
+ };
250
+ }, []);
251
+
252
+ const positionStyle = useRelativePosition({
253
+ align,
254
+ avoidCollisions,
255
+ triggerPosition,
256
+ contentLayout,
257
+ alignOffset,
258
+ insets,
259
+ sideOffset,
260
+ side,
261
+ disablePositioningStyle,
262
+ });
263
+
264
+ function onLayout(event: LayoutChangeEvent) {
265
+ setContentLayout(event.nativeEvent.layout);
266
+ onLayoutProp?.(event);
267
+ }
268
+
269
+ if (!keepMounted) {
270
+ if (!open) {
271
+ return null;
272
+ }
273
+ }
274
+
275
+ return (
276
+ <Component
277
+ ref={ref}
278
+ role="list"
279
+ nativeID={nativeID}
280
+ aria-modal={true}
281
+ style={[positionStyle, style]}
282
+ onLayout={onLayout}
283
+ onStartShouldSetResponder={onStartShouldSetResponder}
284
+ {...props}
285
+ />
286
+ );
287
+ },
288
+ );
289
+
290
+ Content.displayName = "ContentNativeSelect";
291
+
292
+ const ItemContext = React.createContext<{
293
+ itemValue: string;
294
+ label: string;
295
+ } | null>(null);
296
+
297
+ const Item = React.forwardRef<ItemRef, ItemProps>(
298
+ ({ render, value: itemValue, label, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, ref) => {
299
+ const { onOpenChange, value, onValueChange, setTriggerPosition, setContentLayout } = useRootContext();
300
+ function onPress(ev: GestureResponderEvent) {
301
+ if (closeOnPress) {
302
+ setTriggerPosition(null);
303
+ setContentLayout(null);
304
+ onOpenChange(false);
305
+ }
306
+
307
+ onValueChange({ value: itemValue, label });
308
+ onPressProp?.(ev);
309
+ }
310
+
311
+ return (
312
+ <ItemContext.Provider value={{ itemValue, label }}>
313
+ <Component
314
+ ref={ref}
315
+ role="option"
316
+ onPress={onPress}
317
+ disabled={disabled}
318
+ aria-checked={value?.value === itemValue}
319
+ aria-valuetext={label}
320
+ aria-disabled={!!disabled}
321
+ accessibilityState={{
322
+ disabled: !!disabled,
323
+ checked: value?.value === itemValue,
324
+ }}
325
+ {...props}
326
+ />
327
+ </ItemContext.Provider>
328
+ );
329
+ },
330
+ );
331
+
332
+ Item.displayName = "ItemNativeSelect";
333
+
334
+ function useItemContext() {
335
+ const context = React.useContext(ItemContext);
336
+ if (!context) {
337
+ throw new Error("Item compound components cannot be rendered outside of an Item component");
338
+ }
339
+ return context;
340
+ }
341
+
342
+ const ItemText = React.forwardRef<ItemTextRef, ItemTextProps>(({ ...props }, ref) => {
343
+ const { label } = useItemContext();
344
+
345
+ return (
346
+ <Component
347
+ ref={ref}
348
+ {...props}
349
+ >
350
+ {label}
351
+ </Component>
352
+ );
353
+ });
354
+
355
+ ItemText.displayName = "ItemTextNativeSelect";
356
+
357
+ const ItemIndicator = React.forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({ keepMounted, ...props }, ref) => {
358
+ const { itemValue } = useItemContext();
359
+ const { value } = useRootContext();
360
+
361
+ if (!keepMounted) {
362
+ if (value?.value !== itemValue) {
363
+ return null;
364
+ }
365
+ }
366
+
367
+ return (
368
+ <Component
369
+ ref={ref}
370
+ role="presentation"
371
+ {...props}
372
+ />
373
+ );
374
+ });
375
+
376
+ ItemIndicator.displayName = "ItemIndicatorNativeSelect";
377
+
378
+ const Group = React.forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
379
+ return (
380
+ <Component
381
+ ref={ref}
382
+ role="group"
383
+ {...props}
384
+ />
385
+ );
386
+ });
387
+
388
+ Group.displayName = "GroupNativeSelect";
389
+
390
+ const Label = React.forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
391
+ return (
392
+ <Component
393
+ ref={ref}
394
+ {...props}
395
+ />
396
+ );
397
+ });
398
+
399
+ Label.displayName = "LabelNativeSelect";
400
+
401
+ const Separator = React.forwardRef<SeparatorRef, SeparatorProps>(({ decorative, ...props }, ref) => {
402
+ return (
403
+ <Component
404
+ role={decorative ? "presentation" : "separator"}
405
+ ref={ref}
406
+ {...props}
407
+ />
408
+ );
409
+ });
410
+
411
+ Separator.displayName = "SeparatorNativeSelect";
412
+
413
+ const ScrollUpButton = ({ children }: ScrollUpButtonProps) => {
414
+ return <>{children}</>;
415
+ };
416
+
417
+ const ScrollDownButton = ({ children }: ScrollDownButtonProps) => {
418
+ return <>{children}</>;
419
+ };
420
+
421
+ const Viewport = ({ children }: ViewportProps) => {
422
+ return <>{children}</>;
423
+ };
424
+
425
+ export {
426
+ Content,
427
+ Group,
428
+ Item,
429
+ ItemIndicator,
430
+ ItemText,
431
+ Label,
432
+ Backdrop,
433
+ Portal,
434
+ Root,
435
+ ScrollDownButton,
436
+ ScrollUpButton,
437
+ Separator,
438
+ Trigger,
439
+ useItemContext,
440
+ useRootContext,
441
+ Value,
442
+ Viewport,
443
+ };
444
+
445
+ function onStartShouldSetResponder() {
446
+ return true;
447
+ }