@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,139 @@
1
+ import * as React from 'react';
2
+ import { Pressable, View } from 'react-native';
3
+ import { useControllableState } from '../hooks';
4
+ import { Slot } from '../slot';
5
+ import type { RootContext as RootContextType, RootProps, TrackProps, RangeProps, ThumbProps } from './types';
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // Constants
9
+ // ---------------------------------------------------------------------------
10
+
11
+ const DEFAULT_MIN = 0;
12
+ const DEFAULT_MAX = 100;
13
+ const DEFAULT_STEP = 1;
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Context
17
+ // ---------------------------------------------------------------------------
18
+
19
+ const RootContext = React.createContext<RootContextType | null>(null);
20
+
21
+ function useRootContext(): RootContextType {
22
+ const context = React.useContext(RootContext);
23
+ if (!context) {
24
+ throw new Error(
25
+ 'Slider compound components cannot be rendered outside the Slider.Root component'
26
+ );
27
+ }
28
+ return context;
29
+ }
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // Root
33
+ // ---------------------------------------------------------------------------
34
+
35
+ const Root = React.forwardRef<View, RootProps>(function Root(
36
+ {
37
+ asChild,
38
+ value: valueProp,
39
+ defaultValue,
40
+ onValueChange: onValueChangeProp,
41
+ min = DEFAULT_MIN,
42
+ max = DEFAULT_MAX,
43
+ step = DEFAULT_STEP,
44
+ disabled = false,
45
+ ...props
46
+ },
47
+ ref
48
+ ) {
49
+ const [value = DEFAULT_MIN, setValue] = useControllableState({
50
+ prop: valueProp,
51
+ defaultProp: defaultValue,
52
+ onChange: onValueChangeProp,
53
+ });
54
+
55
+ const onValueChange = React.useCallback(
56
+ (newValue: number) => {
57
+ setValue(newValue);
58
+ },
59
+ [setValue]
60
+ );
61
+
62
+ const Component = asChild ? Slot : View;
63
+
64
+ return (
65
+ <RootContext.Provider value={{ value, min, max, step, disabled, onValueChange }}>
66
+ <Component ref={ref} role="group" {...props} />
67
+ </RootContext.Provider>
68
+ );
69
+ });
70
+
71
+ Root.displayName = 'SliderRoot';
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Track
75
+ // ---------------------------------------------------------------------------
76
+
77
+ const Track = React.forwardRef<View, TrackProps>(function Track(
78
+ { asChild, ...props },
79
+ ref
80
+ ) {
81
+ useRootContext();
82
+
83
+ const Component = asChild ? Slot : View;
84
+
85
+ return <Component ref={ref} {...props} />;
86
+ });
87
+
88
+ Track.displayName = 'SliderTrack';
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // Range
92
+ // ---------------------------------------------------------------------------
93
+
94
+ const Range = React.forwardRef<View, RangeProps>(function Range(
95
+ { asChild, ...props },
96
+ ref
97
+ ) {
98
+ useRootContext();
99
+
100
+ const Component = asChild ? Slot : View;
101
+
102
+ return <Component ref={ref} {...props} />;
103
+ });
104
+
105
+ Range.displayName = 'SliderRange';
106
+
107
+ // ---------------------------------------------------------------------------
108
+ // Thumb
109
+ // ---------------------------------------------------------------------------
110
+
111
+ const Thumb = React.forwardRef<View, ThumbProps>(function Thumb(
112
+ { asChild, ...props },
113
+ ref
114
+ ) {
115
+ const { value, min, max, disabled } = useRootContext();
116
+
117
+ const Component = asChild ? Slot : Pressable;
118
+
119
+ return (
120
+ <Component
121
+ ref={ref}
122
+ role="slider"
123
+ aria-valuemin={min}
124
+ aria-valuemax={max}
125
+ aria-valuenow={value}
126
+ disabled={disabled || undefined}
127
+ aria-disabled={disabled || undefined}
128
+ {...props}
129
+ />
130
+ );
131
+ });
132
+
133
+ Thumb.displayName = 'SliderThumb';
134
+
135
+ // ---------------------------------------------------------------------------
136
+ // Exports
137
+ // ---------------------------------------------------------------------------
138
+
139
+ export { Root, Track, Range, Thumb, useRootContext };
@@ -0,0 +1,35 @@
1
+ import type { SlottablePressableProps, SlottableViewProps, PressableRef, ViewRef } from '../types';
2
+
3
+ interface RootProps extends SlottableViewProps {
4
+ value?: number;
5
+ defaultValue?: number;
6
+ onValueChange?: (value: number) => void;
7
+ min?: number;
8
+ max?: number;
9
+ step?: number;
10
+ disabled?: boolean;
11
+ ref?: ViewRef;
12
+ }
13
+
14
+ interface TrackProps extends SlottableViewProps {
15
+ ref?: ViewRef;
16
+ }
17
+
18
+ interface RangeProps extends SlottableViewProps {
19
+ ref?: ViewRef;
20
+ }
21
+
22
+ interface ThumbProps extends SlottablePressableProps {
23
+ ref?: PressableRef;
24
+ }
25
+
26
+ interface RootContext {
27
+ value: number;
28
+ min: number;
29
+ max: number;
30
+ step: number;
31
+ disabled: boolean;
32
+ onValueChange: (value: number) => void;
33
+ }
34
+
35
+ export type { RootProps, TrackProps, RangeProps, ThumbProps, RootContext };
package/src/slot.tsx ADDED
@@ -0,0 +1,160 @@
1
+ // Forked from rn-primitives slot implementation.
2
+ // Original code licensed under MIT — https://github.com/roninoss/rn-primitives
3
+ // Includes patterns from WorkOS/Radix Primitives (MIT).
4
+
5
+ import * as React from 'react';
6
+ import {
7
+ StyleSheet,
8
+ type PressableStateCallbackType,
9
+ type PressableProps as RNPressableProps,
10
+ type ImageStyle as RNImageStyle,
11
+ type StyleProp,
12
+ } from 'react-native';
13
+
14
+ /**
15
+ * Combines multiple refs into a single callback ref that sets all of them.
16
+ */
17
+ function composeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {
18
+ return (node: T) =>
19
+ refs.forEach((ref) => {
20
+ if (typeof ref === 'function') {
21
+ ref(node);
22
+ } else if (ref != null) {
23
+ (ref as React.RefObject<T>).current = node;
24
+ }
25
+ });
26
+ }
27
+
28
+ type AnyProps = Record<string, any>;
29
+
30
+ /**
31
+ * Merges slot props with child props. Event handlers (on*) are composed so
32
+ * both fire. Styles are merged via combineStyles. className strings are joined
33
+ * with a space. Everything else: child overrides slot.
34
+ */
35
+ function mergeProps(slotProps: AnyProps, childProps: AnyProps) {
36
+ // Start with child props as the base — they take priority.
37
+ const overrideProps = { ...childProps };
38
+
39
+ for (const propName in childProps) {
40
+ const slotPropValue = slotProps[propName];
41
+ const childPropValue = childProps[propName];
42
+
43
+ const isHandler = /^on[A-Z]/.test(propName);
44
+ if (isHandler) {
45
+ // If both slot and child define the handler, compose them.
46
+ if (slotPropValue && childPropValue) {
47
+ overrideProps[propName] = (...args: unknown[]) => {
48
+ childPropValue(...args);
49
+ slotPropValue(...args);
50
+ };
51
+ }
52
+ // If only the slot has the handler, use it.
53
+ else if (slotPropValue) {
54
+ overrideProps[propName] = slotPropValue;
55
+ }
56
+ }
57
+ // Merge style objects/functions.
58
+ else if (propName === 'style') {
59
+ overrideProps[propName] = combineStyles(slotPropValue, childPropValue);
60
+ }
61
+ // Join className strings.
62
+ else if (propName === 'className') {
63
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');
64
+ }
65
+ }
66
+
67
+ return { ...slotProps, ...overrideProps };
68
+ }
69
+
70
+ type PressableStyle = RNPressableProps['style'];
71
+ type ImageStyle = StyleProp<RNImageStyle>;
72
+ type Style = PressableStyle | ImageStyle;
73
+
74
+ /**
75
+ * Merges two style values, handling the case where either or both may be
76
+ * Pressable state callback functions rather than plain style objects.
77
+ */
78
+ function combineStyles(slotStyle?: Style, childValue?: Style) {
79
+ if (typeof slotStyle === 'function' && typeof childValue === 'function') {
80
+ return (state: PressableStateCallbackType) => {
81
+ return StyleSheet.flatten([slotStyle(state), childValue(state)]);
82
+ };
83
+ }
84
+ if (typeof slotStyle === 'function') {
85
+ return (state: PressableStateCallbackType) => {
86
+ return childValue ? StyleSheet.flatten([slotStyle(state), childValue]) : slotStyle(state);
87
+ };
88
+ }
89
+ if (typeof childValue === 'function') {
90
+ return (state: PressableStateCallbackType) => {
91
+ return slotStyle ? StyleSheet.flatten([slotStyle, childValue(state)]) : childValue(state);
92
+ };
93
+ }
94
+
95
+ return StyleSheet.flatten([slotStyle, childValue].filter(Boolean));
96
+ }
97
+
98
+ /**
99
+ * Returns true when children is text-only (a string or array of strings).
100
+ */
101
+ function isTextChildren(
102
+ children: React.ReactNode | ((state: PressableStateCallbackType) => React.ReactNode)
103
+ ) {
104
+ return Array.isArray(children)
105
+ ? children.every((child) => typeof child === 'string')
106
+ : typeof children === 'string';
107
+ }
108
+
109
+ /**
110
+ * Slot implements the "asChild" composition pattern. It renders its single
111
+ * child element while merging the Slot's own props and ref onto it. This lets
112
+ * a parent component define behavior (event handlers, accessibility props, etc.)
113
+ * while the consumer controls the rendered element.
114
+ *
115
+ * Throws if the child is plain text (must be a valid React element).
116
+ */
117
+ function Slot<T extends React.ElementType>(props: React.ComponentProps<T>) {
118
+ const { children, ref: forwardedRef, ...restOfProps } = props;
119
+
120
+ if (isTextChildren(children)) {
121
+ throw new Error(
122
+ 'Slot: children must be a valid React element, not a string. ' +
123
+ 'Wrap text in a <Text> component.'
124
+ );
125
+ }
126
+
127
+ if (!React.isValidElement(children)) {
128
+ return null;
129
+ }
130
+
131
+ const childrenProps = (children.props as Record<string, any>) ?? {};
132
+
133
+ // Unwrap Fragment children — apply Slot to each child individually.
134
+ if (children.type === React.Fragment) {
135
+ return (
136
+ <>
137
+ {React.Children.toArray(childrenProps.children).map((child): any =>
138
+ React.isValidElement(child)
139
+ ? Slot({ ...restOfProps, ref: forwardedRef, children: child })
140
+ : child
141
+ )}
142
+ </>
143
+ );
144
+ }
145
+
146
+ const { ref: childRef, ...childProps } = childrenProps;
147
+
148
+ return React.cloneElement(children, {
149
+ ...mergeProps(restOfProps, childProps),
150
+ ...(children.type === 'function'
151
+ ? {}
152
+ : {
153
+ ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef,
154
+ }),
155
+ } as unknown as Partial<React.ComponentProps<T>>);
156
+ }
157
+
158
+ Slot.displayName = 'Slot';
159
+
160
+ export { Slot, composeRefs, mergeProps };
@@ -0,0 +1,2 @@
1
+ export { Root, Thumb, useRootContext } from './switch';
2
+ export type { RootProps, ThumbProps, RootContext } from './types';
@@ -0,0 +1,92 @@
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, ThumbProps } 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
+ 'Switch compound components cannot be rendered outside the Switch.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 }}>
58
+ <Component
59
+ ref={ref}
60
+ role="switch"
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 = 'SwitchRoot';
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Thumb
75
+ // ---------------------------------------------------------------------------
76
+
77
+ const Thumb = React.forwardRef<View, ThumbProps>(function Thumb(
78
+ { asChild, ...props },
79
+ ref
80
+ ) {
81
+ useRootContext(); // Ensure Thumb is used within Root
82
+ const Component = asChild ? Slot : View;
83
+ return <Component ref={ref} role="presentation" {...props} />;
84
+ });
85
+
86
+ Thumb.displayName = 'SwitchThumb';
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // Exports
90
+ // ---------------------------------------------------------------------------
91
+
92
+ export { Root, Thumb, useRootContext };
@@ -0,0 +1,18 @@
1
+ import type { 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 ThumbProps extends SlottableViewProps {}
12
+
13
+ interface RootContext {
14
+ checked: boolean;
15
+ disabled: boolean;
16
+ }
17
+
18
+ export type { RootProps, ThumbProps, RootContext };
@@ -0,0 +1,12 @@
1
+ export { Root, Header, HeaderRow, HeaderCell, Body, Row, Cell, Footer, useRootContext } from './table';
2
+ export type {
3
+ RootProps,
4
+ HeaderProps,
5
+ HeaderRowProps,
6
+ HeaderCellProps,
7
+ BodyProps,
8
+ RowProps,
9
+ CellProps,
10
+ FooterProps,
11
+ RootContext,
12
+ } from './types';
@@ -0,0 +1,160 @@
1
+ import * as React from 'react';
2
+ import { View, Text } from 'react-native';
3
+ import { Slot } from '../slot';
4
+ import type {
5
+ RootContext as RootContextType,
6
+ RootProps,
7
+ HeaderProps,
8
+ HeaderRowProps,
9
+ HeaderCellProps,
10
+ BodyProps,
11
+ RowProps,
12
+ CellProps,
13
+ FooterProps,
14
+ } from './types';
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Context
18
+ // ---------------------------------------------------------------------------
19
+
20
+ const RootContext = React.createContext<RootContextType | null>(null);
21
+
22
+ function useRootContext(): RootContextType {
23
+ const context = React.useContext(RootContext);
24
+ if (!context) {
25
+ throw new Error(
26
+ 'Table compound components cannot be rendered outside the Table.Root component'
27
+ );
28
+ }
29
+ return context;
30
+ }
31
+
32
+ // ---------------------------------------------------------------------------
33
+ // Root
34
+ // ---------------------------------------------------------------------------
35
+
36
+ const Root = React.forwardRef<View, RootProps<any>>(function Root(
37
+ { asChild, table, ...props },
38
+ ref
39
+ ) {
40
+ const Component = asChild ? Slot : View;
41
+
42
+ return (
43
+ <RootContext.Provider value={{ table }}>
44
+ <Component ref={ref} role="table" {...props} />
45
+ </RootContext.Provider>
46
+ );
47
+ });
48
+
49
+ Root.displayName = 'TableRoot';
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Header
53
+ // ---------------------------------------------------------------------------
54
+
55
+ const Header = React.forwardRef<View, HeaderProps>(function Header(
56
+ { asChild, ...props },
57
+ ref
58
+ ) {
59
+ const Component = asChild ? Slot : View;
60
+
61
+ return <Component ref={ref} role="rowgroup" {...props} />;
62
+ });
63
+
64
+ Header.displayName = 'TableHeader';
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // HeaderRow
68
+ // ---------------------------------------------------------------------------
69
+
70
+ const HeaderRow = React.forwardRef<View, HeaderRowProps>(function HeaderRow(
71
+ { asChild, ...props },
72
+ ref
73
+ ) {
74
+ const Component = asChild ? Slot : View;
75
+
76
+ return <Component ref={ref} role="row" {...props} />;
77
+ });
78
+
79
+ HeaderRow.displayName = 'TableHeaderRow';
80
+
81
+ // ---------------------------------------------------------------------------
82
+ // HeaderCell
83
+ // ---------------------------------------------------------------------------
84
+
85
+ const HeaderCell = React.forwardRef<Text, HeaderCellProps>(function HeaderCell(
86
+ { asChild, ...props },
87
+ ref
88
+ ) {
89
+ const Component = asChild ? Slot : Text;
90
+
91
+ return <Component ref={ref} role="columnheader" {...props} />;
92
+ });
93
+
94
+ HeaderCell.displayName = 'TableHeaderCell';
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Body
98
+ // ---------------------------------------------------------------------------
99
+
100
+ const Body = React.forwardRef<View, BodyProps>(function Body(
101
+ { asChild, ...props },
102
+ ref
103
+ ) {
104
+ const Component = asChild ? Slot : View;
105
+
106
+ return <Component ref={ref} role="rowgroup" {...props} />;
107
+ });
108
+
109
+ Body.displayName = 'TableBody';
110
+
111
+ // ---------------------------------------------------------------------------
112
+ // Row
113
+ // ---------------------------------------------------------------------------
114
+
115
+ const Row = React.forwardRef<View, RowProps>(function Row(
116
+ { asChild, ...props },
117
+ ref
118
+ ) {
119
+ const Component = asChild ? Slot : View;
120
+
121
+ return <Component ref={ref} role="row" {...props} />;
122
+ });
123
+
124
+ Row.displayName = 'TableRow';
125
+
126
+ // ---------------------------------------------------------------------------
127
+ // Cell
128
+ // ---------------------------------------------------------------------------
129
+
130
+ const Cell = React.forwardRef<Text, CellProps>(function Cell(
131
+ { asChild, ...props },
132
+ ref
133
+ ) {
134
+ const Component = asChild ? Slot : Text;
135
+
136
+ return <Component ref={ref} role="cell" {...props} />;
137
+ });
138
+
139
+ Cell.displayName = 'TableCell';
140
+
141
+ // ---------------------------------------------------------------------------
142
+ // Footer
143
+ // ---------------------------------------------------------------------------
144
+
145
+ const Footer = React.forwardRef<View, FooterProps>(function Footer(
146
+ { asChild, ...props },
147
+ ref
148
+ ) {
149
+ const Component = asChild ? Slot : View;
150
+
151
+ return <Component ref={ref} role="rowgroup" {...props} />;
152
+ });
153
+
154
+ Footer.displayName = 'TableFooter';
155
+
156
+ // ---------------------------------------------------------------------------
157
+ // Exports
158
+ // ---------------------------------------------------------------------------
159
+
160
+ export { Root, Header, HeaderRow, HeaderCell, Body, Row, Cell, Footer, useRootContext };
@@ -0,0 +1,30 @@
1
+ import type { Table as TanStackTable } from '@tanstack/react-table';
2
+ import type { SlottableViewProps, SlottableTextProps } from '../types';
3
+
4
+ interface RootProps<TData> extends SlottableViewProps {
5
+ table: TanStackTable<TData>;
6
+ }
7
+
8
+ interface HeaderProps extends SlottableViewProps {}
9
+ interface HeaderRowProps extends SlottableViewProps {}
10
+ interface HeaderCellProps extends SlottableTextProps {}
11
+ interface BodyProps extends SlottableViewProps {}
12
+ interface RowProps extends SlottableViewProps {}
13
+ interface CellProps extends SlottableTextProps {}
14
+ interface FooterProps extends SlottableViewProps {}
15
+
16
+ interface RootContext<TData = unknown> {
17
+ table: TanStackTable<TData>;
18
+ }
19
+
20
+ export type {
21
+ RootProps,
22
+ HeaderProps,
23
+ HeaderRowProps,
24
+ HeaderCellProps,
25
+ BodyProps,
26
+ RowProps,
27
+ CellProps,
28
+ FooterProps,
29
+ RootContext,
30
+ };
@@ -0,0 +1,15 @@
1
+ export {
2
+ Root,
3
+ List,
4
+ Trigger,
5
+ Content,
6
+ useRootContext,
7
+ } from './tabs';
8
+
9
+ export type {
10
+ RootProps,
11
+ ListProps,
12
+ TriggerProps,
13
+ ContentProps,
14
+ RootContext,
15
+ } from './types';