@react-native-reusables/cli 0.0.18 → 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 (136) hide show
  1. package/README.md +2 -37
  2. package/__generated/components/ui/accordion.tsx +1 -1
  3. package/__generated/components/ui/alert-dialog.tsx +2 -3
  4. package/__generated/components/ui/aspect-ratio.tsx +1 -1
  5. package/__generated/components/ui/avatar.tsx +17 -13
  6. package/__generated/components/ui/badge.tsx +2 -2
  7. package/__generated/components/ui/card.tsx +1 -1
  8. package/__generated/components/ui/checkbox.tsx +2 -3
  9. package/__generated/components/ui/collapsible.tsx +1 -1
  10. package/__generated/components/ui/context-menu.tsx +3 -11
  11. package/__generated/components/ui/dialog.tsx +2 -3
  12. package/__generated/components/ui/dropdown-menu.tsx +1 -1
  13. package/__generated/components/ui/hover-card.tsx +1 -1
  14. package/__generated/components/ui/label.tsx +1 -1
  15. package/__generated/components/ui/menubar.tsx +1 -1
  16. package/__generated/components/ui/navigation-menu.tsx +6 -4
  17. package/__generated/components/ui/popover.tsx +1 -1
  18. package/__generated/components/ui/progress.tsx +14 -10
  19. package/__generated/components/ui/radio-group.tsx +1 -1
  20. package/__generated/components/ui/select.tsx +13 -12
  21. package/__generated/components/ui/separator.tsx +1 -1
  22. package/__generated/components/ui/switch.tsx +1 -2
  23. package/__generated/components/ui/table.tsx +1 -1
  24. package/__generated/components/ui/tabs.tsx +1 -1
  25. package/__generated/components/ui/text.tsx +2 -2
  26. package/__generated/components/ui/toggle-group.tsx +1 -1
  27. package/__generated/components/ui/toggle.tsx +1 -1
  28. package/__generated/components/ui/tooltip.tsx +1 -2
  29. package/__generated/components/ui/typography.tsx +2 -2
  30. package/dist/index.js +3 -3
  31. package/dist/index.js.map +1 -1
  32. package/package.json +2 -34
  33. package/__generated/components/primitives/accordion/accordion.tsx +0 -216
  34. package/__generated/components/primitives/accordion/accordion.web.tsx +0 -295
  35. package/__generated/components/primitives/accordion/index.ts +0 -1
  36. package/__generated/components/primitives/accordion/types.ts +0 -45
  37. package/__generated/components/primitives/alert-dialog/alert-dialog.tsx +0 -237
  38. package/__generated/components/primitives/alert-dialog/alert-dialog.web.tsx +0 -256
  39. package/__generated/components/primitives/alert-dialog/index.ts +0 -1
  40. package/__generated/components/primitives/alert-dialog/types.ts +0 -48
  41. package/__generated/components/primitives/aspect-ratio.tsx +0 -23
  42. package/__generated/components/primitives/avatar/index.tsx +0 -95
  43. package/__generated/components/primitives/avatar/types.ts +0 -10
  44. package/__generated/components/primitives/checkbox/checkbox.tsx +0 -101
  45. package/__generated/components/primitives/checkbox/checkbox.web.tsx +0 -114
  46. package/__generated/components/primitives/checkbox/index.ts +0 -1
  47. package/__generated/components/primitives/checkbox/types.ts +0 -11
  48. package/__generated/components/primitives/collapsible/collapsible.tsx +0 -119
  49. package/__generated/components/primitives/collapsible/collapsible.web.tsx +0 -157
  50. package/__generated/components/primitives/collapsible/index.ts +0 -1
  51. package/__generated/components/primitives/collapsible/types.ts +0 -18
  52. package/__generated/components/primitives/context-menu/context-menu.tsx +0 -648
  53. package/__generated/components/primitives/context-menu/context-menu.web.tsx +0 -533
  54. package/__generated/components/primitives/context-menu/index.ts +0 -1
  55. package/__generated/components/primitives/context-menu/types.ts +0 -90
  56. package/__generated/components/primitives/dialog/dialog.tsx +0 -211
  57. package/__generated/components/primitives/dialog/dialog.web.tsx +0 -197
  58. package/__generated/components/primitives/dialog/index.ts +0 -1
  59. package/__generated/components/primitives/dialog/types.ts +0 -60
  60. package/__generated/components/primitives/dropdown-menu/dropdown-menu.tsx +0 -608
  61. package/__generated/components/primitives/dropdown-menu/dropdown-menu.web.tsx +0 -550
  62. package/__generated/components/primitives/dropdown-menu/index.ts +0 -1
  63. package/__generated/components/primitives/dropdown-menu/types.ts +0 -72
  64. package/__generated/components/primitives/hooks/index.ts +0 -3
  65. package/__generated/components/primitives/hooks/useAugmentedRef.tsx +0 -29
  66. package/__generated/components/primitives/hooks/useControllableState.tsx +0 -75
  67. package/__generated/components/primitives/hooks/useRelativePosition.tsx +0 -227
  68. package/__generated/components/primitives/hover-card/hover-card.tsx +0 -279
  69. package/__generated/components/primitives/hover-card/hover-card.web.tsx +0 -150
  70. package/__generated/components/primitives/hover-card/index.ts +0 -1
  71. package/__generated/components/primitives/hover-card/types.ts +0 -51
  72. package/__generated/components/primitives/label/index.ts +0 -1
  73. package/__generated/components/primitives/label/label.tsx +0 -31
  74. package/__generated/components/primitives/label/label.web.tsx +0 -36
  75. package/__generated/components/primitives/label/types.ts +0 -15
  76. package/__generated/components/primitives/menubar/index.ts +0 -1
  77. package/__generated/components/primitives/menubar/menubar.tsx +0 -622
  78. package/__generated/components/primitives/menubar/menubar.web.tsx +0 -548
  79. package/__generated/components/primitives/menubar/types.ts +0 -77
  80. package/__generated/components/primitives/navigation-menu/index.ts +0 -1
  81. package/__generated/components/primitives/navigation-menu/navigation-menu.tsx +0 -315
  82. package/__generated/components/primitives/navigation-menu/navigation-menu.web.tsx +0 -264
  83. package/__generated/components/primitives/navigation-menu/types.ts +0 -49
  84. package/__generated/components/primitives/popover/index.ts +0 -1
  85. package/__generated/components/primitives/popover/popover.tsx +0 -290
  86. package/__generated/components/primitives/popover/popover.web.tsx +0 -191
  87. package/__generated/components/primitives/popover/types.ts +0 -24
  88. package/__generated/components/primitives/portal.tsx +0 -82
  89. package/__generated/components/primitives/progress/index.ts +0 -1
  90. package/__generated/components/primitives/progress/progress.tsx +0 -59
  91. package/__generated/components/primitives/progress/progress.web.tsx +0 -36
  92. package/__generated/components/primitives/progress/types.ts +0 -7
  93. package/__generated/components/primitives/radio-group/index.ts +0 -1
  94. package/__generated/components/primitives/radio-group/radio-group.tsx +0 -116
  95. package/__generated/components/primitives/radio-group/radio-group.web.tsx +0 -78
  96. package/__generated/components/primitives/radio-group/types.ts +0 -15
  97. package/__generated/components/primitives/select/index.ts +0 -1
  98. package/__generated/components/primitives/select/select.tsx +0 -466
  99. package/__generated/components/primitives/select/select.web.tsx +0 -332
  100. package/__generated/components/primitives/select/types.ts +0 -89
  101. package/__generated/components/primitives/separator/index.tsx +0 -23
  102. package/__generated/components/primitives/separator/types.ts +0 -6
  103. package/__generated/components/primitives/slider/index.ts +0 -1
  104. package/__generated/components/primitives/slider/slider.tsx +0 -89
  105. package/__generated/components/primitives/slider/slider.web.tsx +0 -67
  106. package/__generated/components/primitives/slider/types.ts +0 -24
  107. package/__generated/components/primitives/slot.tsx +0 -187
  108. package/__generated/components/primitives/switch/index.ts +0 -1
  109. package/__generated/components/primitives/switch/switch.tsx +0 -65
  110. package/__generated/components/primitives/switch/switch.web.tsx +0 -67
  111. package/__generated/components/primitives/switch/types.ts +0 -11
  112. package/__generated/components/primitives/table.tsx +0 -55
  113. package/__generated/components/primitives/tabs/index.ts +0 -1
  114. package/__generated/components/primitives/tabs/tabs.tsx +0 -133
  115. package/__generated/components/primitives/tabs/tabs.web.tsx +0 -97
  116. package/__generated/components/primitives/tabs/types.ts +0 -24
  117. package/__generated/components/primitives/toast/index.tsx +0 -128
  118. package/__generated/components/primitives/toast/types.ts +0 -7
  119. package/__generated/components/primitives/toggle/index.ts +0 -1
  120. package/__generated/components/primitives/toggle/toggle.tsx +0 -37
  121. package/__generated/components/primitives/toggle/toggle.web.tsx +0 -26
  122. package/__generated/components/primitives/toggle/types.ts +0 -7
  123. package/__generated/components/primitives/toggle-group/index.ts +0 -1
  124. package/__generated/components/primitives/toggle-group/toggle-group.tsx +0 -125
  125. package/__generated/components/primitives/toggle-group/toggle-group.web.tsx +0 -124
  126. package/__generated/components/primitives/toggle-group/types.ts +0 -37
  127. package/__generated/components/primitives/toolbar/index.ts +0 -1
  128. package/__generated/components/primitives/toolbar/toolbar.tsx +0 -125
  129. package/__generated/components/primitives/toolbar/toolbar.web.tsx +0 -129
  130. package/__generated/components/primitives/toolbar/types.ts +0 -39
  131. package/__generated/components/primitives/tooltip/index.ts +0 -1
  132. package/__generated/components/primitives/tooltip/tooltip.tsx +0 -277
  133. package/__generated/components/primitives/tooltip/tooltip.web.tsx +0 -181
  134. package/__generated/components/primitives/tooltip/types.ts +0 -42
  135. package/__generated/components/primitives/types.ts +0 -105
  136. package/__generated/components/primitives/utils.ts +0 -61
@@ -1,216 +0,0 @@
1
- import * as React from 'react';
2
- import { Pressable, View, type GestureResponderEvent } from 'react-native';
3
- import * as Slot from '@rnr/slot';
4
- import type {
5
- PressableRef,
6
- SlottablePressableProps,
7
- SlottableViewProps,
8
- ViewRef,
9
- } from '@rnr/types';
10
- import type {
11
- AccordionContentProps,
12
- AccordionItemProps,
13
- AccordionRootProps,
14
- RootContext,
15
- } from './types';
16
- import { useControllableState } from '@rnr/hooks';
17
-
18
- const AccordionContext = React.createContext<RootContext | null>(null);
19
-
20
- const Root = React.forwardRef<ViewRef, SlottableViewProps & AccordionRootProps>(
21
- (
22
- {
23
- asChild,
24
- type,
25
- disabled,
26
- collapsible = true,
27
- value: valueProp,
28
- onValueChange: onValueChangeProps,
29
- defaultValue,
30
- ...viewProps
31
- },
32
- ref
33
- ) => {
34
- const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState<
35
- (string | undefined) | string[]
36
- >({
37
- prop: valueProp,
38
- defaultProp: defaultValue,
39
- onChange: onValueChangeProps as (state: string | string[] | undefined) => void,
40
- });
41
-
42
- const Component = asChild ? Slot.View : View;
43
- return (
44
- <AccordionContext.Provider
45
- value={{
46
- type,
47
- disabled,
48
- collapsible,
49
- value,
50
- onValueChange,
51
- }}
52
- >
53
- <Component ref={ref} {...viewProps} />
54
- </AccordionContext.Provider>
55
- );
56
- }
57
- );
58
-
59
- Root.displayName = 'RootNativeAccordion';
60
-
61
- function useRootContext() {
62
- const context = React.useContext(AccordionContext);
63
- if (!context) {
64
- throw new Error(
65
- 'Accordion compound components cannot be rendered outside the Accordion component'
66
- );
67
- }
68
- return context;
69
- }
70
-
71
- type AccordionItemContext = AccordionItemProps & {
72
- nativeID: string;
73
- isExpanded: boolean;
74
- };
75
-
76
- const AccordionItemContext = React.createContext<AccordionItemContext | null>(null);
77
-
78
- const Item = React.forwardRef<ViewRef, SlottableViewProps & AccordionItemProps>(
79
- ({ asChild, value, disabled, ...viewProps }, ref) => {
80
- const { value: rootValue } = useRootContext();
81
- const nativeID = React.useId();
82
-
83
- const Component = asChild ? Slot.View : View;
84
- return (
85
- <AccordionItemContext.Provider
86
- value={{
87
- value,
88
- disabled,
89
- nativeID,
90
- isExpanded: isItemExpanded(rootValue, value),
91
- }}
92
- >
93
- <Component ref={ref} {...viewProps} />
94
- </AccordionItemContext.Provider>
95
- );
96
- }
97
- );
98
-
99
- Item.displayName = 'ItemNativeAccordion';
100
-
101
- function useItemContext() {
102
- const context = React.useContext(AccordionItemContext);
103
- if (!context) {
104
- throw new Error(
105
- 'AccordionItem compound components cannot be rendered outside the AccordionItem component'
106
- );
107
- }
108
- return context;
109
- }
110
-
111
- const Header = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
112
- const { disabled: rootDisabled } = useRootContext();
113
- const { disabled: itemDisabled, isExpanded } = useItemContext();
114
-
115
- const Component = asChild ? Slot.View : View;
116
- return (
117
- <Component
118
- ref={ref}
119
- role='heading'
120
- aria-expanded={isExpanded}
121
- aria-disabled={rootDisabled ?? itemDisabled}
122
- {...props}
123
- />
124
- );
125
- });
126
-
127
- Header.displayName = 'HeaderNativeAccordion';
128
-
129
- const Trigger = React.forwardRef<PressableRef, SlottablePressableProps>(
130
- ({ asChild, onPress: onPressProp, disabled: disabledProp, ...props }, ref) => {
131
- const {
132
- disabled: rootDisabled,
133
- type,
134
- onValueChange,
135
- value: rootValue,
136
- collapsible,
137
- } = useRootContext();
138
- const { nativeID, disabled: itemDisabled, value, isExpanded } = useItemContext();
139
-
140
- function onPress(ev: GestureResponderEvent) {
141
- if (rootDisabled || itemDisabled) return;
142
- if (type === 'single') {
143
- const newValue = collapsible ? (value === rootValue ? undefined : value) : value;
144
- onValueChange(newValue);
145
- }
146
- if (type === 'multiple') {
147
- const rootToArray = toStringArray(rootValue);
148
- const newValue = collapsible
149
- ? rootToArray.includes(value)
150
- ? rootToArray.filter((val) => val !== value)
151
- : rootToArray.concat(value)
152
- : [...new Set(rootToArray.concat(value))];
153
- // @ts-ignore - `newValue` is of type `string[]` which is OK
154
- onValueChange(newValue);
155
- }
156
- onPressProp?.(ev);
157
- }
158
-
159
- const isDisabled = disabledProp || rootDisabled || itemDisabled;
160
- const Component = asChild ? Slot.Pressable : Pressable;
161
- return (
162
- <Component
163
- ref={ref}
164
- key={`${nativeID}-${JSON.stringify(rootValue)}-${isDisabled}-${collapsible}-${type}`}
165
- nativeID={nativeID}
166
- aria-disabled={isDisabled}
167
- role='button'
168
- onPress={onPress}
169
- accessibilityState={{
170
- expanded: isExpanded,
171
- disabled: isDisabled,
172
- }}
173
- disabled={isDisabled}
174
- {...props}
175
- />
176
- );
177
- }
178
- );
179
-
180
- Trigger.displayName = 'TriggerNativeAccordion';
181
-
182
- const Content = React.forwardRef<ViewRef, SlottableViewProps & AccordionContentProps>(
183
- ({ asChild, forceMount, ...props }, ref) => {
184
- const { type } = useRootContext();
185
- const { nativeID, isExpanded } = useItemContext();
186
-
187
- if (!forceMount) {
188
- if (!isExpanded) {
189
- return null;
190
- }
191
- }
192
-
193
- const Component = asChild ? Slot.View : View;
194
- return (
195
- <Component
196
- ref={ref}
197
- aria-hidden={!(forceMount || isExpanded)}
198
- aria-labelledby={nativeID}
199
- role={type === 'single' ? 'region' : 'summary'}
200
- {...props}
201
- />
202
- );
203
- }
204
- );
205
-
206
- Content.displayName = 'ContentNativeAccordion';
207
-
208
- export { Content, Header, Item, Root, Trigger, useRootContext, useItemContext };
209
-
210
- function toStringArray(value?: string | string[]) {
211
- return Array.isArray(value) ? value : value ? [value] : [];
212
- }
213
-
214
- function isItemExpanded(rootValue: string | string[] | undefined, value: string) {
215
- return Array.isArray(rootValue) ? rootValue.includes(value) : rootValue === value;
216
- }
@@ -1,295 +0,0 @@
1
- import * as Accordion from '@radix-ui/react-accordion';
2
- import { useAugmentedRef, useControllableState } from '@rnr/hooks';
3
- import * as Slot from '@rnr/slot';
4
- import type {
5
- PressableRef,
6
- SlottablePressableProps,
7
- SlottableViewProps,
8
- ViewRef,
9
- } from '@rnr/types';
10
- import * as React from 'react';
11
- import { Pressable, View } from 'react-native';
12
- import type { AccordionContentProps, AccordionItemProps, AccordionRootProps } from './types';
13
-
14
- function useIsomorphicLayoutEffect(
15
- effect: React.EffectCallback,
16
- dependencies?: React.DependencyList
17
- ) {
18
- if (typeof window === 'undefined') {
19
- React.useEffect(effect, dependencies);
20
- } else {
21
- React.useLayoutEffect(effect, dependencies);
22
- }
23
- }
24
-
25
- const AccordionContext = React.createContext<AccordionRootProps | null>(null);
26
-
27
- const Root = React.forwardRef<ViewRef, SlottableViewProps & AccordionRootProps>(
28
- (
29
- {
30
- asChild,
31
- value: valueProp,
32
- onValueChange: onValueChangeProps,
33
- defaultValue,
34
- type,
35
- disabled,
36
- dir,
37
- orientation = 'vertical',
38
- collapsible,
39
- ...props
40
- },
41
- ref
42
- ) => {
43
- const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState<
44
- (string | undefined) | string[]
45
- >({
46
- prop: valueProp,
47
- defaultProp: defaultValue,
48
- onChange: onValueChangeProps as (state: string | string[] | undefined) => void,
49
- });
50
-
51
- const Component = asChild ? Slot.View : View;
52
- return (
53
- <AccordionContext.Provider
54
- value={
55
- {
56
- value,
57
- onValueChange,
58
- type,
59
- disabled,
60
- dir,
61
- orientation,
62
- } as AccordionRootProps
63
- }
64
- >
65
- <Accordion.Root
66
- asChild
67
- value={value as any}
68
- onValueChange={onValueChange as any}
69
- type={type as any}
70
- disabled={disabled}
71
- dir={dir}
72
- orientation={orientation}
73
- collapsible={collapsible}
74
- >
75
- <Component ref={ref} {...props} />
76
- </Accordion.Root>
77
- </AccordionContext.Provider>
78
- );
79
- }
80
- );
81
-
82
- Root.displayName = 'RootWebAccordion';
83
-
84
- function useRootContext() {
85
- const context = React.useContext(AccordionContext);
86
- if (!context) {
87
- throw new Error(
88
- 'Accordion compound components cannot be rendered outside the Accordion component'
89
- );
90
- }
91
- return context;
92
- }
93
-
94
- const AccordionItemContext = React.createContext<
95
- (AccordionItemProps & { isExpanded: boolean }) | null
96
- >(null);
97
-
98
- const Item = React.forwardRef<ViewRef, AccordionItemProps & SlottableViewProps>(
99
- ({ asChild, value: itemValue, disabled, ...props }, ref) => {
100
- const augmentedRef = useAugmentedRef({ ref });
101
- const { value, orientation, disabled: disabledRoot } = useRootContext();
102
-
103
- useIsomorphicLayoutEffect(() => {
104
- if (augmentedRef.current) {
105
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
106
- const isExpanded = Array.isArray(value) ? value.includes(itemValue) : value === itemValue;
107
- augRef.dataset.state = isExpanded ? 'open' : 'closed';
108
- }
109
- }, [value, itemValue]);
110
-
111
- useIsomorphicLayoutEffect(() => {
112
- if (augmentedRef.current) {
113
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
114
- augRef.dataset.orientation = orientation;
115
- if (disabled || disabledRoot) {
116
- augRef.dataset.disabled = 'true';
117
- } else {
118
- augRef.dataset.disabled = undefined;
119
- }
120
- }
121
- }, [orientation, disabled, disabledRoot]);
122
-
123
- const Component = asChild ? Slot.View : View;
124
- return (
125
- <AccordionItemContext.Provider
126
- value={{
127
- value: itemValue,
128
- disabled,
129
- isExpanded: isItemExpanded(value, itemValue),
130
- }}
131
- >
132
- <Accordion.Item value={itemValue} disabled={disabled} asChild>
133
- <Component ref={augmentedRef} {...props} />
134
- </Accordion.Item>
135
- </AccordionItemContext.Provider>
136
- );
137
- }
138
- );
139
-
140
- Item.displayName = 'ItemWebAccordion';
141
-
142
- function useItemContext() {
143
- const context = React.useContext(AccordionItemContext);
144
- if (!context) {
145
- throw new Error(
146
- 'AccordionItem compound components cannot be rendered outside the AccordionItem component'
147
- );
148
- }
149
- return context;
150
- }
151
-
152
- const Header = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
153
- const augmentedRef = useAugmentedRef({ ref });
154
- const { disabled, isExpanded } = useItemContext();
155
- const { orientation, disabled: disabledRoot } = useRootContext();
156
-
157
- useIsomorphicLayoutEffect(() => {
158
- if (augmentedRef.current) {
159
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
160
- augRef.dataset.state = isExpanded ? 'open' : 'closed';
161
- }
162
- }, [isExpanded]);
163
-
164
- useIsomorphicLayoutEffect(() => {
165
- if (augmentedRef.current) {
166
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
167
- augRef.dataset.orientation = orientation;
168
- if (disabled || disabledRoot) {
169
- augRef.dataset.disabled = 'true';
170
- } else {
171
- augRef.dataset.disabled = undefined;
172
- }
173
- }
174
- }, [orientation, disabled, disabledRoot]);
175
-
176
- const Component = asChild ? Slot.View : View;
177
- return (
178
- <Accordion.Header asChild>
179
- <Component ref={augmentedRef} {...props} />
180
- </Accordion.Header>
181
- );
182
- });
183
-
184
- Header.displayName = 'HeaderWebAccordion';
185
-
186
- const HIDDEN_STYLE: React.CSSProperties = {
187
- position: 'absolute',
188
- top: 0,
189
- left: 0,
190
- zIndex: -999999,
191
- opacity: 0,
192
- };
193
-
194
- const Trigger = React.forwardRef<PressableRef, SlottablePressableProps>(
195
- ({ asChild, disabled: disabledProp, ...props }, ref) => {
196
- const { disabled: disabledRoot } = useRootContext();
197
- const { disabled, isExpanded } = useItemContext();
198
- const triggerRef = React.useRef<HTMLButtonElement>(null);
199
- const augmentedRef = useAugmentedRef({ ref });
200
-
201
- useIsomorphicLayoutEffect(() => {
202
- if (augmentedRef.current) {
203
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
204
-
205
- augRef.dataset.state = isExpanded ? 'expanded' : 'closed';
206
- }
207
- }, [isExpanded]);
208
-
209
- useIsomorphicLayoutEffect(() => {
210
- if (augmentedRef.current) {
211
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
212
-
213
- if (disabled || disabledRoot || disabledProp) {
214
- augRef.dataset.disabled = 'true';
215
- } else {
216
- augRef.dataset.disabled = undefined;
217
- }
218
- }
219
- }, [disabled, disabledRoot, disabledProp]);
220
-
221
- useIsomorphicLayoutEffect(() => {
222
- if (triggerRef.current) {
223
- triggerRef.current.disabled = true;
224
- }
225
- }, []);
226
-
227
- const isDisabled = disabledProp ?? disabledRoot ?? disabled;
228
- const Component = asChild ? Slot.Pressable : Pressable;
229
- return (
230
- <>
231
- <Accordion.Trigger ref={triggerRef} aria-hidden tabIndex={-1} style={HIDDEN_STYLE} />
232
- <Accordion.Trigger disabled={isDisabled} asChild>
233
- <Component
234
- ref={augmentedRef}
235
- role='button'
236
- disabled={isDisabled}
237
- {...props}
238
- onPress={() => {
239
- if (triggerRef.current && !isDisabled) {
240
- triggerRef.current.disabled = false;
241
- triggerRef.current.click();
242
- triggerRef.current.disabled = true;
243
- }
244
- }}
245
- />
246
- </Accordion.Trigger>
247
- </>
248
- );
249
- }
250
- );
251
-
252
- Trigger.displayName = 'TriggerWebAccordion';
253
-
254
- const Content = React.forwardRef<ViewRef, AccordionContentProps & SlottableViewProps>(
255
- ({ asChild, forceMount, ...props }, ref) => {
256
- const augmentedRef = useAugmentedRef({ ref });
257
-
258
- const { orientation, disabled: disabledRoot } = useRootContext();
259
- const { disabled, isExpanded } = useItemContext();
260
- useIsomorphicLayoutEffect(() => {
261
- if (augmentedRef.current) {
262
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
263
- augRef.dataset.state = isExpanded ? 'expanded' : 'closed';
264
- }
265
- }, [isExpanded]);
266
-
267
- useIsomorphicLayoutEffect(() => {
268
- if (augmentedRef.current) {
269
- const augRef = augmentedRef.current as unknown as HTMLDivElement;
270
- augRef.dataset.orientation = orientation;
271
-
272
- if (disabled || disabledRoot) {
273
- augRef.dataset.disabled = 'true';
274
- } else {
275
- augRef.dataset.disabled = undefined;
276
- }
277
- }
278
- }, [orientation, disabled, disabledRoot]);
279
-
280
- const Component = asChild ? Slot.View : View;
281
- return (
282
- <Accordion.Content forceMount={forceMount} asChild>
283
- <Component ref={augmentedRef} {...props} />
284
- </Accordion.Content>
285
- );
286
- }
287
- );
288
-
289
- Content.displayName = 'ContentWebAccordion';
290
-
291
- export { Content, Header, Item, Root, Trigger, useItemContext, useRootContext };
292
-
293
- function isItemExpanded(rootValue: string | string[] | undefined, value: string) {
294
- return Array.isArray(rootValue) ? rootValue.includes(value) : rootValue === value;
295
- }
@@ -1 +0,0 @@
1
- export * from './accordion';
@@ -1,45 +0,0 @@
1
- import { ForceMountable } from '@rnr/types';
2
-
3
- type RootContext = {
4
- type: 'single' | 'multiple';
5
- value: (string | undefined) | string[];
6
- onValueChange: (value: string | undefined) => void | ((value: string[]) => void);
7
- collapsible: boolean;
8
- disabled?: boolean;
9
- };
10
-
11
- type SingleRootProps = {
12
- type: 'single';
13
- defaultValue?: string | undefined;
14
- value?: string | undefined;
15
- onValueChange?: (value: string | undefined) => void;
16
- };
17
-
18
- type MultipleRootProps = {
19
- type: 'multiple';
20
- defaultValue?: string[];
21
- value?: string[];
22
- onValueChange?: (value: string[]) => void;
23
- };
24
-
25
- type AccordionRootProps = (SingleRootProps | MultipleRootProps) & {
26
- defaultValue?: string | string[];
27
- disabled?: boolean;
28
- collapsible?: boolean;
29
- /**
30
- * Platform: WEB ONLY
31
- */
32
- dir?: 'ltr' | 'rtl';
33
- /**
34
- * Platform: WEB ONLY
35
- */
36
- orientation?: 'vertical' | 'horizontal';
37
- };
38
-
39
- type AccordionItemProps = {
40
- value: string;
41
- disabled?: boolean;
42
- };
43
- type AccordionContentProps = ForceMountable;
44
-
45
- export type { AccordionContentProps, AccordionItemProps, AccordionRootProps, RootContext };