@tallyui/primitives 0.1.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 (128) hide show
  1. package/dist/index.d.ts +1370 -0
  2. package/dist/index.js +3954 -0
  3. package/package.json +47 -0
  4. package/src/__tests__/accordion.test.tsx +370 -0
  5. package/src/__tests__/alert-dialog.test.tsx +127 -0
  6. package/src/__tests__/animated.test.tsx +184 -0
  7. package/src/__tests__/checkbox.test.tsx +90 -0
  8. package/src/__tests__/collapsible.test.tsx +149 -0
  9. package/src/__tests__/combobox.test.tsx +292 -0
  10. package/src/__tests__/context-menu.test.tsx +226 -0
  11. package/src/__tests__/dialog.test.tsx +81 -0
  12. package/src/__tests__/dropdown-menu.test.tsx +119 -0
  13. package/src/__tests__/hooks.test.tsx +46 -0
  14. package/src/__tests__/hover-card.test.tsx +77 -0
  15. package/src/__tests__/image.test.tsx +53 -0
  16. package/src/__tests__/label.test.tsx +50 -0
  17. package/src/__tests__/list.test.tsx +63 -0
  18. package/src/__tests__/popover.test.tsx +63 -0
  19. package/src/__tests__/portal.test.tsx +66 -0
  20. package/src/__tests__/progress.test.tsx +70 -0
  21. package/src/__tests__/radio-group.test.tsx +164 -0
  22. package/src/__tests__/select.test.tsx +76 -0
  23. package/src/__tests__/separator.test.tsx +37 -0
  24. package/src/__tests__/slider.test.tsx +124 -0
  25. package/src/__tests__/slot.test.tsx +56 -0
  26. package/src/__tests__/switch.test.tsx +70 -0
  27. package/src/__tests__/table.test.tsx +172 -0
  28. package/src/__tests__/tabs.test.tsx +67 -0
  29. package/src/__tests__/text.test.tsx +59 -0
  30. package/src/__tests__/toast.test.tsx +137 -0
  31. package/src/__tests__/toggle-group.test.tsx +167 -0
  32. package/src/__tests__/toggle.test.tsx +60 -0
  33. package/src/__tests__/tooltip.test.tsx +77 -0
  34. package/src/__tests__/types.test-d.ts +106 -0
  35. package/src/__tests__/utils.test.ts +47 -0
  36. package/src/accordion/accordion.tsx +232 -0
  37. package/src/accordion/index.ts +12 -0
  38. package/src/accordion/types.ts +56 -0
  39. package/src/alert-dialog/alert-dialog.tsx +296 -0
  40. package/src/alert-dialog/index.ts +25 -0
  41. package/src/alert-dialog/types.ts +50 -0
  42. package/src/animated/index.ts +3 -0
  43. package/src/animated/presence.tsx +27 -0
  44. package/src/animated/types.ts +36 -0
  45. package/src/animated/use-presence.ts +44 -0
  46. package/src/checkbox/checkbox.tsx +106 -0
  47. package/src/checkbox/index.ts +2 -0
  48. package/src/checkbox/types.ts +19 -0
  49. package/src/collapsible/collapsible.tsx +135 -0
  50. package/src/collapsible/index.ts +2 -0
  51. package/src/collapsible/types.ts +25 -0
  52. package/src/combobox/combobox.tsx +325 -0
  53. package/src/combobox/index.ts +24 -0
  54. package/src/combobox/types.ts +84 -0
  55. package/src/context-menu/context-menu.tsx +654 -0
  56. package/src/context-menu/index.ts +40 -0
  57. package/src/context-menu/types.ts +117 -0
  58. package/src/dialog/dialog.tsx +260 -0
  59. package/src/dialog/index.ts +23 -0
  60. package/src/dialog/types.ts +47 -0
  61. package/src/dropdown-menu/dropdown-menu.tsx +654 -0
  62. package/src/dropdown-menu/index.ts +40 -0
  63. package/src/dropdown-menu/types.ts +117 -0
  64. package/src/hooks/index.ts +6 -0
  65. package/src/hooks/use-augmented-ref.ts +32 -0
  66. package/src/hooks/use-controllable-state.ts +87 -0
  67. package/src/hooks/use-relative-position.ts +253 -0
  68. package/src/hooks/use-relative-position.web.ts +9 -0
  69. package/src/hover-card/hover-card.tsx +271 -0
  70. package/src/hover-card/index.ts +17 -0
  71. package/src/hover-card/types.ts +50 -0
  72. package/src/image/image.tsx +29 -0
  73. package/src/image/index.ts +2 -0
  74. package/src/image/types.ts +10 -0
  75. package/src/index.ts +38 -0
  76. package/src/label/index.ts +2 -0
  77. package/src/label/label.tsx +45 -0
  78. package/src/label/types.ts +11 -0
  79. package/src/list/index.ts +2 -0
  80. package/src/list/list.tsx +54 -0
  81. package/src/list/types.ts +14 -0
  82. package/src/popover/index.ts +19 -0
  83. package/src/popover/popover.tsx +314 -0
  84. package/src/popover/types.ts +51 -0
  85. package/src/portal.tsx +60 -0
  86. package/src/progress/index.ts +2 -0
  87. package/src/progress/progress.tsx +92 -0
  88. package/src/progress/types.ts +16 -0
  89. package/src/radio-group/index.ts +2 -0
  90. package/src/radio-group/radio-group.tsx +160 -0
  91. package/src/radio-group/types.ts +31 -0
  92. package/src/select/index.ts +34 -0
  93. package/src/select/select.tsx +465 -0
  94. package/src/select/types.ts +112 -0
  95. package/src/separator/index.ts +2 -0
  96. package/src/separator/separator.tsx +32 -0
  97. package/src/separator/types.ts +8 -0
  98. package/src/slider/index.ts +2 -0
  99. package/src/slider/slider.tsx +139 -0
  100. package/src/slider/types.ts +35 -0
  101. package/src/slot.tsx +160 -0
  102. package/src/switch/index.ts +2 -0
  103. package/src/switch/switch.tsx +92 -0
  104. package/src/switch/types.ts +18 -0
  105. package/src/table/index.ts +12 -0
  106. package/src/table/table.tsx +160 -0
  107. package/src/table/types.ts +30 -0
  108. package/src/tabs/index.ts +15 -0
  109. package/src/tabs/tabs.tsx +140 -0
  110. package/src/tabs/types.ts +36 -0
  111. package/src/text/index.ts +2 -0
  112. package/src/text/text.tsx +40 -0
  113. package/src/text/types.ts +5 -0
  114. package/src/toast/index.ts +2 -0
  115. package/src/toast/toast.tsx +189 -0
  116. package/src/toast/types.ts +35 -0
  117. package/src/toggle/index.ts +2 -0
  118. package/src/toggle/toggle.tsx +59 -0
  119. package/src/toggle/types.ts +11 -0
  120. package/src/toggle-group/index.ts +2 -0
  121. package/src/toggle-group/toggle-group.tsx +123 -0
  122. package/src/toggle-group/types.ts +36 -0
  123. package/src/tooltip/index.ts +17 -0
  124. package/src/tooltip/tooltip.tsx +272 -0
  125. package/src/tooltip/types.ts +49 -0
  126. package/src/types.ts +129 -0
  127. package/src/uniwind-env.d.ts +31 -0
  128. package/src/utils.ts +67 -0
@@ -0,0 +1,296 @@
1
+ import * as React from 'react';
2
+ import { Pressable, Text, View, type GestureResponderEvent } from 'react-native';
3
+ import { useControllableState } from '../hooks';
4
+ import { Portal as RNPortal } from '../portal';
5
+ import { Slot } from '../slot';
6
+ import type {
7
+ ActionProps,
8
+ CancelProps,
9
+ ContentProps,
10
+ DescriptionProps,
11
+ OverlayProps,
12
+ PortalProps,
13
+ RootContext as RootContextType,
14
+ RootProps,
15
+ TitleProps,
16
+ TriggerProps,
17
+ } from './types';
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Contexts
21
+ // ---------------------------------------------------------------------------
22
+
23
+ const RootContext = React.createContext<RootContextType | null>(null);
24
+
25
+ function useRootContext(): RootContextType {
26
+ const context = React.useContext(RootContext);
27
+ if (!context) {
28
+ throw new Error(
29
+ 'AlertDialog compound components cannot be rendered outside the AlertDialog.Root component'
30
+ );
31
+ }
32
+ return context;
33
+ }
34
+
35
+ const InternalContext = React.createContext<{ nativeID: string } | null>(null);
36
+
37
+ function useInternalContext() {
38
+ const context = React.useContext(InternalContext);
39
+ if (!context) {
40
+ throw new Error(
41
+ 'AlertDialog compound components cannot be rendered outside the AlertDialog.Root component'
42
+ );
43
+ }
44
+ return context;
45
+ }
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Root
49
+ // ---------------------------------------------------------------------------
50
+
51
+ function Root({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, children }: RootProps) {
52
+ const nativeID = React.useId();
53
+ const [open = false, onOpenChange] = useControllableState({
54
+ prop: openProp,
55
+ defaultProp: defaultOpen,
56
+ onChange: onOpenChangeProp,
57
+ });
58
+
59
+ return (
60
+ <InternalContext.Provider value={{ nativeID }}>
61
+ <RootContext.Provider value={{ open, onOpenChange }}>
62
+ {children}
63
+ </RootContext.Provider>
64
+ </InternalContext.Provider>
65
+ );
66
+ }
67
+
68
+ Root.displayName = 'AlertDialogRoot';
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Trigger
72
+ // ---------------------------------------------------------------------------
73
+
74
+ const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
75
+ { asChild, onPress: onPressProp, disabled, ...props },
76
+ ref
77
+ ) {
78
+ const { open, onOpenChange } = useRootContext();
79
+
80
+ const onPress = React.useCallback(
81
+ (ev: GestureResponderEvent) => {
82
+ onOpenChange(!open);
83
+ onPressProp?.(ev);
84
+ },
85
+ [onOpenChange, onPressProp, open]
86
+ );
87
+
88
+ const Component = asChild ? Slot : Pressable;
89
+
90
+ return (
91
+ <Component
92
+ ref={ref}
93
+ role="button"
94
+ aria-disabled={disabled || undefined}
95
+ onPress={onPress}
96
+ disabled={disabled || undefined}
97
+ {...props}
98
+ />
99
+ );
100
+ });
101
+
102
+ Trigger.displayName = 'AlertDialogTrigger';
103
+
104
+ // ---------------------------------------------------------------------------
105
+ // Portal
106
+ // ---------------------------------------------------------------------------
107
+
108
+ function Portal({ forceMount, hostName, children }: PortalProps) {
109
+ const internalValue = useInternalContext();
110
+ const rootValue = useRootContext();
111
+
112
+ if (!forceMount && !rootValue.open) {
113
+ return null;
114
+ }
115
+
116
+ return (
117
+ <RNPortal hostName={hostName} name={`${internalValue.nativeID}_portal`}>
118
+ <InternalContext.Provider value={internalValue}>
119
+ <RootContext.Provider value={rootValue}>{children}</RootContext.Provider>
120
+ </InternalContext.Provider>
121
+ </RNPortal>
122
+ );
123
+ }
124
+
125
+ Portal.displayName = 'AlertDialogPortal';
126
+
127
+ // ---------------------------------------------------------------------------
128
+ // Overlay
129
+ // ---------------------------------------------------------------------------
130
+
131
+ const Overlay = React.forwardRef<View, OverlayProps>(function Overlay(
132
+ { asChild, forceMount, ...props },
133
+ ref
134
+ ) {
135
+ const { open } = useRootContext();
136
+
137
+ if (!forceMount && !open) {
138
+ return null;
139
+ }
140
+
141
+ const Component = asChild ? Slot : View;
142
+
143
+ return <Component ref={ref} aria-modal={true} {...props} />;
144
+ });
145
+
146
+ Overlay.displayName = 'AlertDialogOverlay';
147
+
148
+ // ---------------------------------------------------------------------------
149
+ // Content
150
+ // ---------------------------------------------------------------------------
151
+
152
+ const Content = React.forwardRef<View, ContentProps>(function Content(
153
+ { asChild, forceMount, ...props },
154
+ ref
155
+ ) {
156
+ const { open } = useRootContext();
157
+ const { nativeID } = useInternalContext();
158
+
159
+ if (!forceMount && !open) {
160
+ return null;
161
+ }
162
+
163
+ const Component = asChild ? Slot : View;
164
+
165
+ return (
166
+ <Component
167
+ ref={ref}
168
+ role="alertdialog"
169
+ nativeID={nativeID}
170
+ aria-labelledby={`${nativeID}_title`}
171
+ aria-describedby={`${nativeID}_description`}
172
+ {...props}
173
+ />
174
+ );
175
+ });
176
+
177
+ Content.displayName = 'AlertDialogContent';
178
+
179
+ // ---------------------------------------------------------------------------
180
+ // Title
181
+ // ---------------------------------------------------------------------------
182
+
183
+ const Title = React.forwardRef<Text, TitleProps>(function Title(
184
+ { asChild, ...props },
185
+ ref
186
+ ) {
187
+ const { nativeID } = useInternalContext();
188
+
189
+ const Component = asChild ? Slot : Text;
190
+
191
+ return <Component ref={ref} role="heading" nativeID={`${nativeID}_title`} {...props} />;
192
+ });
193
+
194
+ Title.displayName = 'AlertDialogTitle';
195
+
196
+ // ---------------------------------------------------------------------------
197
+ // Description
198
+ // ---------------------------------------------------------------------------
199
+
200
+ const Description = React.forwardRef<Text, DescriptionProps>(function Description(
201
+ { asChild, ...props },
202
+ ref
203
+ ) {
204
+ const { nativeID } = useInternalContext();
205
+
206
+ const Component = asChild ? Slot : Text;
207
+
208
+ return <Component ref={ref} nativeID={`${nativeID}_description`} {...props} />;
209
+ });
210
+
211
+ Description.displayName = 'AlertDialogDescription';
212
+
213
+ // ---------------------------------------------------------------------------
214
+ // Action
215
+ // ---------------------------------------------------------------------------
216
+
217
+ const Action = React.forwardRef<View, ActionProps>(function Action(
218
+ { asChild, onPress: onPressProp, disabled, ...props },
219
+ ref
220
+ ) {
221
+ const { onOpenChange } = useRootContext();
222
+
223
+ const onPress = React.useCallback(
224
+ (ev: GestureResponderEvent) => {
225
+ onOpenChange(false);
226
+ onPressProp?.(ev);
227
+ },
228
+ [onOpenChange, onPressProp]
229
+ );
230
+
231
+ const Component = asChild ? Slot : Pressable;
232
+
233
+ return (
234
+ <Component
235
+ ref={ref}
236
+ role="button"
237
+ aria-disabled={disabled || undefined}
238
+ onPress={onPress}
239
+ disabled={disabled || undefined}
240
+ {...props}
241
+ />
242
+ );
243
+ });
244
+
245
+ Action.displayName = 'AlertDialogAction';
246
+
247
+ // ---------------------------------------------------------------------------
248
+ // Cancel
249
+ // ---------------------------------------------------------------------------
250
+
251
+ const Cancel = React.forwardRef<View, CancelProps>(function Cancel(
252
+ { asChild, onPress: onPressProp, disabled, ...props },
253
+ ref
254
+ ) {
255
+ const { onOpenChange } = useRootContext();
256
+
257
+ const onPress = React.useCallback(
258
+ (ev: GestureResponderEvent) => {
259
+ onOpenChange(false);
260
+ onPressProp?.(ev);
261
+ },
262
+ [onOpenChange, onPressProp]
263
+ );
264
+
265
+ const Component = asChild ? Slot : Pressable;
266
+
267
+ return (
268
+ <Component
269
+ ref={ref}
270
+ role="button"
271
+ aria-disabled={disabled || undefined}
272
+ onPress={onPress}
273
+ disabled={disabled || undefined}
274
+ {...props}
275
+ />
276
+ );
277
+ });
278
+
279
+ Cancel.displayName = 'AlertDialogCancel';
280
+
281
+ // ---------------------------------------------------------------------------
282
+ // Exports
283
+ // ---------------------------------------------------------------------------
284
+
285
+ export {
286
+ Action,
287
+ Cancel,
288
+ Content,
289
+ Description,
290
+ Overlay,
291
+ Portal,
292
+ Root,
293
+ Title,
294
+ Trigger,
295
+ useRootContext,
296
+ };
@@ -0,0 +1,25 @@
1
+ export {
2
+ Root,
3
+ Trigger,
4
+ Portal,
5
+ Overlay,
6
+ Content,
7
+ Title,
8
+ Description,
9
+ Action,
10
+ Cancel,
11
+ useRootContext,
12
+ } from './alert-dialog';
13
+
14
+ export type {
15
+ RootProps,
16
+ TriggerProps,
17
+ PortalProps,
18
+ OverlayProps,
19
+ ContentProps,
20
+ TitleProps,
21
+ DescriptionProps,
22
+ ActionProps,
23
+ CancelProps,
24
+ RootContext,
25
+ } from './types';
@@ -0,0 +1,50 @@
1
+ import type {
2
+ ForceMountable,
3
+ SlottablePressableProps,
4
+ SlottableTextProps,
5
+ SlottableViewProps,
6
+ } from '../types';
7
+
8
+ interface RootProps {
9
+ open?: boolean;
10
+ defaultOpen?: boolean;
11
+ onOpenChange?: (open: boolean) => void;
12
+ children?: React.ReactNode;
13
+ }
14
+
15
+ interface TriggerProps extends SlottablePressableProps {}
16
+
17
+ interface PortalProps extends ForceMountable {
18
+ hostName?: string;
19
+ children?: React.ReactNode;
20
+ }
21
+
22
+ interface OverlayProps extends SlottableViewProps, ForceMountable {}
23
+
24
+ interface ContentProps extends SlottableViewProps, ForceMountable {}
25
+
26
+ interface TitleProps extends SlottableTextProps {}
27
+
28
+ interface DescriptionProps extends SlottableTextProps {}
29
+
30
+ interface ActionProps extends SlottablePressableProps {}
31
+
32
+ interface CancelProps extends SlottablePressableProps {}
33
+
34
+ interface RootContext {
35
+ open: boolean;
36
+ onOpenChange: (open: boolean) => void;
37
+ }
38
+
39
+ export type {
40
+ ActionProps,
41
+ CancelProps,
42
+ ContentProps,
43
+ DescriptionProps,
44
+ OverlayProps,
45
+ PortalProps,
46
+ RootContext,
47
+ RootProps,
48
+ TitleProps,
49
+ TriggerProps,
50
+ };
@@ -0,0 +1,3 @@
1
+ export { Presence } from './presence';
2
+ export { usePresence } from './use-presence';
3
+ export type { AnimationConfig, PresenceProps, PresenceState } from './types';
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { usePresence } from './use-presence';
3
+ import type { PresenceProps } from './types';
4
+
5
+ /**
6
+ * Manages mount/unmount transitions for children.
7
+ * Keeps children mounted during exit animations.
8
+ */
9
+ function Presence({ present, forceMount, children }: PresenceProps) {
10
+ const { isPresent } = usePresence(present);
11
+
12
+ const shouldRender = forceMount || isPresent;
13
+
14
+ if (!shouldRender) {
15
+ return null;
16
+ }
17
+
18
+ if (typeof children === 'function') {
19
+ return <>{children({ present })}</>;
20
+ }
21
+
22
+ return <>{children}</>;
23
+ }
24
+
25
+ Presence.displayName = 'AnimatedPresence';
26
+
27
+ export { Presence };
@@ -0,0 +1,36 @@
1
+ import type { ViewStyle } from 'react-native';
2
+
3
+ /**
4
+ * Configuration for an enter/exit animation.
5
+ */
6
+ interface AnimationConfig {
7
+ /** Style when entering (becoming visible) */
8
+ entering?: ViewStyle;
9
+ /** Style when exiting (becoming hidden) */
10
+ exiting?: ViewStyle;
11
+ /** Duration in ms */
12
+ duration?: number;
13
+ }
14
+
15
+ /**
16
+ * Props for the Presence component that manages mount/unmount transitions.
17
+ */
18
+ interface PresenceProps {
19
+ /** Whether the content should be visible */
20
+ present: boolean;
21
+ /** If true, always keep in DOM (but animate opacity/transform) */
22
+ forceMount?: boolean;
23
+ children: React.ReactNode | ((props: { present: boolean }) => React.ReactNode);
24
+ }
25
+
26
+ /**
27
+ * Return type for usePresence hook
28
+ */
29
+ interface PresenceState {
30
+ /** Whether the content is currently mounted (may lag behind `present` for exit animations) */
31
+ isPresent: boolean;
32
+ /** Ref callback to attach to the animated element */
33
+ ref: React.RefCallback<any>;
34
+ }
35
+
36
+ export type { AnimationConfig, PresenceProps, PresenceState };
@@ -0,0 +1,44 @@
1
+ import { useState, useCallback, useEffect, useRef } from 'react';
2
+ import type { PresenceState } from './types';
3
+
4
+ /**
5
+ * Manages presence state for animated mount/unmount transitions.
6
+ *
7
+ * When `present` changes from true to false, `isPresent` stays true
8
+ * for `exitDuration` ms to allow exit animations to complete.
9
+ */
10
+ function usePresence(present: boolean, exitDuration = 150): PresenceState {
11
+ const [isPresent, setIsPresent] = useState(present);
12
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
13
+ const nodeRef = useRef<any>(null);
14
+
15
+ const ref = useCallback((node: any) => {
16
+ nodeRef.current = node;
17
+ }, []);
18
+
19
+ useEffect(() => {
20
+ if (present) {
21
+ // Entering: immediately mount
22
+ if (timerRef.current) {
23
+ clearTimeout(timerRef.current);
24
+ timerRef.current = null;
25
+ }
26
+ setIsPresent(true);
27
+ } else {
28
+ // Exiting: delay unmount for exit animation
29
+ timerRef.current = setTimeout(() => {
30
+ setIsPresent(false);
31
+ }, exitDuration);
32
+ }
33
+
34
+ return () => {
35
+ if (timerRef.current) {
36
+ clearTimeout(timerRef.current);
37
+ }
38
+ };
39
+ }, [present, exitDuration]);
40
+
41
+ return { isPresent, ref };
42
+ }
43
+
44
+ export { usePresence };
@@ -0,0 +1,106 @@
1
+ import * as React from 'react';
2
+ import { Pressable, View, type GestureResponderEvent } from 'react-native';
3
+ import { useControllableState } from '../hooks';
4
+ import { Slot } from '../slot';
5
+ import type { RootContext as RootContextType, RootProps, IndicatorProps } from './types';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Context
9
+ // ---------------------------------------------------------------------------
10
+
11
+ const RootContext = React.createContext<RootContextType | null>(null);
12
+
13
+ function useRootContext(): RootContextType {
14
+ const context = React.useContext(RootContext);
15
+ if (!context) {
16
+ throw new Error(
17
+ 'Checkbox compound components cannot be rendered outside the Checkbox.Root component'
18
+ );
19
+ }
20
+ return context;
21
+ }
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Root
25
+ // ---------------------------------------------------------------------------
26
+
27
+ const Root = React.forwardRef<View, RootProps>(function Root(
28
+ {
29
+ asChild,
30
+ checked: checkedProp,
31
+ defaultChecked,
32
+ onCheckedChange: onCheckedChangeProp,
33
+ disabled = false,
34
+ onPress: onPressProp,
35
+ ...props
36
+ },
37
+ ref
38
+ ) {
39
+ const [checked = false, setChecked] = useControllableState({
40
+ prop: checkedProp,
41
+ defaultProp: defaultChecked,
42
+ onChange: onCheckedChangeProp,
43
+ });
44
+
45
+ const onPress = React.useCallback(
46
+ (ev: GestureResponderEvent) => {
47
+ if (disabled) return;
48
+ setChecked(!checked);
49
+ onPressProp?.(ev);
50
+ },
51
+ [disabled, checked, setChecked, onPressProp]
52
+ );
53
+
54
+ const Component = asChild ? Slot : Pressable;
55
+
56
+ return (
57
+ <RootContext.Provider value={{ checked, disabled, onCheckedChange: setChecked }}>
58
+ <Component
59
+ ref={ref}
60
+ role="checkbox"
61
+ aria-checked={checked}
62
+ aria-disabled={disabled || undefined}
63
+ onPress={onPress}
64
+ disabled={disabled || undefined}
65
+ {...props}
66
+ />
67
+ </RootContext.Provider>
68
+ );
69
+ });
70
+
71
+ Root.displayName = 'CheckboxRoot';
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Indicator
75
+ // ---------------------------------------------------------------------------
76
+
77
+ const Indicator = React.forwardRef<View, IndicatorProps>(function Indicator(
78
+ { asChild, forceMount, ...props },
79
+ ref
80
+ ) {
81
+ const { checked, disabled } = useRootContext();
82
+
83
+ if (!forceMount && !checked) {
84
+ return null;
85
+ }
86
+
87
+ const Component = asChild ? Slot : View;
88
+
89
+ return (
90
+ <Component
91
+ ref={ref}
92
+ role="presentation"
93
+ aria-hidden={!(forceMount || checked)}
94
+ aria-disabled={disabled || undefined}
95
+ {...props}
96
+ />
97
+ );
98
+ });
99
+
100
+ Indicator.displayName = 'CheckboxIndicator';
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // Exports
104
+ // ---------------------------------------------------------------------------
105
+
106
+ export { Root, Indicator, useRootContext };
@@ -0,0 +1,2 @@
1
+ export { Root, Indicator, useRootContext } from './checkbox';
2
+ export type { RootProps, IndicatorProps, RootContext } from './types';
@@ -0,0 +1,19 @@
1
+ import type { ForceMountable, SlottablePressableProps, SlottableViewProps, PressableRef } from '../types';
2
+
3
+ interface RootProps extends SlottablePressableProps {
4
+ checked?: boolean;
5
+ defaultChecked?: boolean;
6
+ onCheckedChange?: (checked: boolean) => void;
7
+ disabled?: boolean;
8
+ ref?: PressableRef;
9
+ }
10
+
11
+ interface IndicatorProps extends SlottableViewProps, ForceMountable {}
12
+
13
+ interface RootContext {
14
+ checked: boolean;
15
+ disabled: boolean;
16
+ onCheckedChange: (checked: boolean) => void;
17
+ }
18
+
19
+ export type { RootProps, IndicatorProps, RootContext };