@react-native-reusables/cli 0.0.8 → 0.0.10
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.
- package/dist/generated/components/primitives/accordion/accordion.tsx +216 -0
- package/dist/generated/components/primitives/accordion/accordion.web.tsx +295 -0
- package/dist/generated/components/primitives/accordion/index.ts +1 -0
- package/dist/generated/components/primitives/accordion/types.ts +45 -0
- package/dist/generated/components/primitives/alert-dialog/alert-dialog.tsx +237 -0
- package/dist/generated/components/primitives/alert-dialog/alert-dialog.web.tsx +256 -0
- package/dist/generated/components/primitives/alert-dialog/index.ts +1 -0
- package/dist/generated/components/primitives/alert-dialog/types.ts +48 -0
- package/dist/generated/components/primitives/aspect-ratio.tsx +23 -0
- package/dist/generated/components/primitives/avatar/ types.ts +10 -0
- package/dist/generated/components/primitives/avatar/index.tsx +95 -0
- package/dist/generated/components/primitives/checkbox/checkbox.tsx +101 -0
- package/dist/generated/components/primitives/checkbox/checkbox.web.tsx +114 -0
- package/dist/generated/components/primitives/checkbox/index.ts +1 -0
- package/dist/generated/components/primitives/checkbox/types.ts +11 -0
- package/dist/generated/components/primitives/collapsible/collapsible.tsx +119 -0
- package/dist/generated/components/primitives/collapsible/collapsible.web.tsx +157 -0
- package/dist/generated/components/primitives/collapsible/index.ts +1 -0
- package/dist/generated/components/primitives/collapsible/types.ts +18 -0
- package/dist/generated/components/primitives/context-menu/context-menu.tsx +626 -0
- package/dist/generated/components/primitives/context-menu/context-menu.web.tsx +504 -0
- package/dist/generated/components/primitives/context-menu/index.ts +1 -0
- package/dist/generated/components/primitives/context-menu/types.ts +82 -0
- package/dist/generated/components/primitives/dialog/dialog.tsx +211 -0
- package/dist/generated/components/primitives/dialog/dialog.web.tsx +197 -0
- package/dist/generated/components/primitives/dialog/index.ts +1 -0
- package/dist/generated/components/primitives/dialog/types.ts +60 -0
- package/dist/generated/components/primitives/dropdown-menu/dropdown-menu.tsx +584 -0
- package/dist/generated/components/primitives/dropdown-menu/dropdown-menu.web.tsx +521 -0
- package/dist/generated/components/primitives/dropdown-menu/index.ts +1 -0
- package/dist/generated/components/primitives/dropdown-menu/types.ts +71 -0
- package/dist/generated/components/primitives/hooks/index.ts +3 -0
- package/dist/generated/components/primitives/hooks/useAugmentedRef.tsx +29 -0
- package/dist/generated/components/primitives/hooks/useControllableState.tsx +75 -0
- package/dist/generated/components/primitives/hooks/useRelativePosition.tsx +227 -0
- package/dist/generated/components/primitives/hover-card/hover-card.tsx +271 -0
- package/dist/generated/components/primitives/hover-card/hover-card.web.tsx +145 -0
- package/dist/generated/components/primitives/hover-card/index.ts +1 -0
- package/dist/generated/components/primitives/hover-card/types.ts +42 -0
- package/dist/generated/components/primitives/label/index.ts +1 -0
- package/dist/generated/components/primitives/label/label.tsx +31 -0
- package/dist/generated/components/primitives/label/label.web.tsx +36 -0
- package/dist/generated/components/primitives/label/types.ts +15 -0
- package/dist/generated/components/primitives/menubar/index.ts +1 -0
- package/dist/generated/components/primitives/menubar/menubar.tsx +624 -0
- package/dist/generated/components/primitives/menubar/menubar.web.tsx +543 -0
- package/dist/generated/components/primitives/menubar/types.ts +76 -0
- package/dist/generated/components/primitives/navigation-menu/index.ts +1 -0
- package/dist/generated/components/primitives/navigation-menu/navigation-menu.tsx +315 -0
- package/dist/generated/components/primitives/navigation-menu/navigation-menu.web.tsx +264 -0
- package/dist/generated/components/primitives/navigation-menu/types.ts +49 -0
- package/dist/generated/components/primitives/popover/index.ts +1 -0
- package/dist/generated/components/primitives/popover/popover.tsx +286 -0
- package/dist/generated/components/primitives/popover/popover.web.tsx +179 -0
- package/dist/generated/components/primitives/popover/types.ts +30 -0
- package/dist/generated/components/primitives/portal.tsx +67 -0
- package/dist/generated/components/primitives/progress/index.ts +1 -0
- package/dist/generated/components/primitives/progress/progress.tsx +59 -0
- package/dist/generated/components/primitives/progress/progress.web.tsx +36 -0
- package/dist/generated/components/primitives/progress/types.ts +7 -0
- package/dist/generated/components/primitives/radio-group/index.ts +1 -0
- package/dist/generated/components/primitives/radio-group/radio-group.tsx +116 -0
- package/dist/generated/components/primitives/radio-group/radio-group.web.tsx +78 -0
- package/dist/generated/components/primitives/radio-group/types.ts +15 -0
- package/dist/generated/components/primitives/select/index.ts +1 -0
- package/dist/generated/components/primitives/select/select.tsx +455 -0
- package/dist/generated/components/primitives/select/select.web.tsx +319 -0
- package/dist/generated/components/primitives/select/types.ts +87 -0
- package/dist/generated/components/primitives/separator/ types.ts +6 -0
- package/dist/generated/components/primitives/separator/index.tsx +23 -0
- package/dist/generated/components/primitives/slider/index.ts +1 -0
- package/dist/generated/components/primitives/slider/slider.tsx +89 -0
- package/dist/generated/components/primitives/slider/slider.web.tsx +67 -0
- package/dist/generated/components/primitives/slider/types.ts +24 -0
- package/dist/generated/components/primitives/slot.tsx +187 -0
- package/dist/generated/components/primitives/switch/index.ts +1 -0
- package/dist/generated/components/primitives/switch/switch.tsx +65 -0
- package/dist/generated/components/primitives/switch/switch.web.tsx +67 -0
- package/dist/generated/components/primitives/switch/types.ts +11 -0
- package/dist/generated/components/primitives/table.tsx +55 -0
- package/dist/generated/components/primitives/tabs/index.ts +1 -0
- package/dist/generated/components/primitives/tabs/tabs.tsx +133 -0
- package/dist/generated/components/primitives/tabs/tabs.web.tsx +97 -0
- package/dist/generated/components/primitives/tabs/types.ts +24 -0
- package/dist/generated/components/primitives/toast/ types.ts +7 -0
- package/dist/generated/components/primitives/toast/index.tsx +128 -0
- package/dist/generated/components/primitives/toggle/index.ts +1 -0
- package/dist/generated/components/primitives/toggle/toggle.tsx +37 -0
- package/dist/generated/components/primitives/toggle/toggle.web.tsx +26 -0
- package/dist/generated/components/primitives/toggle/types.ts +7 -0
- package/dist/generated/components/primitives/toggle-group/index.ts +1 -0
- package/dist/generated/components/primitives/toggle-group/toggle-group.tsx +125 -0
- package/dist/generated/components/primitives/toggle-group/toggle-group.web.tsx +124 -0
- package/dist/generated/components/primitives/toggle-group/types.ts +37 -0
- package/dist/generated/components/primitives/toolbar/index.ts +1 -0
- package/dist/generated/components/primitives/toolbar/toolbar.tsx +125 -0
- package/dist/generated/components/primitives/toolbar/toolbar.web.tsx +129 -0
- package/dist/generated/components/primitives/toolbar/types.ts +39 -0
- package/dist/generated/components/primitives/tooltip/index.ts +1 -0
- package/dist/generated/components/primitives/tooltip/tooltip.tsx +271 -0
- package/dist/generated/components/primitives/tooltip/tooltip.web.tsx +167 -0
- package/dist/generated/components/primitives/tooltip/types.ts +44 -0
- package/dist/generated/components/primitives/types.ts +105 -0
- package/dist/generated/components/primitives/utils.ts +61 -0
- package/dist/generated/components/ui/accordion.tsx +127 -0
- package/dist/generated/components/ui/alert-dialog.tsx +167 -0
- package/dist/generated/components/ui/aspect-ratio.tsx +5 -0
- package/dist/generated/components/ui/avatar.tsx +44 -0
- package/dist/generated/components/ui/badge.tsx +51 -0
- package/dist/generated/components/ui/button.tsx +88 -0
- package/dist/generated/components/ui/card.tsx +67 -0
- package/dist/generated/components/ui/checkbox.tsx +34 -0
- package/dist/generated/components/ui/collapsible.tsx +9 -0
- package/dist/generated/components/ui/context-menu.tsx +244 -0
- package/dist/generated/components/ui/dialog.tsx +150 -0
- package/dist/generated/components/ui/dropdown-menu.tsx +244 -0
- package/dist/generated/components/ui/hover-card.tsx +45 -0
- package/dist/generated/components/ui/input.tsx +26 -0
- package/dist/generated/components/ui/label.tsx +28 -0
- package/dist/generated/components/ui/menubar.tsx +260 -0
- package/dist/generated/components/ui/navigation-menu.tsx +177 -0
- package/dist/generated/components/ui/popover.tsx +39 -0
- package/dist/generated/components/ui/radio-group.tsx +38 -0
- package/dist/generated/components/ui/select.tsx +181 -0
- package/dist/generated/components/ui/separator.tsx +23 -0
- package/dist/generated/components/ui/skeleton.tsx +39 -0
- package/dist/generated/components/ui/switch.tsx +97 -0
- package/dist/generated/components/ui/table.tsx +99 -0
- package/dist/generated/components/ui/tabs.tsx +65 -0
- package/dist/generated/components/ui/text.tsx +24 -0
- package/dist/generated/components/ui/textarea.tsx +28 -0
- package/dist/generated/components/ui/toggle-group.tsx +86 -0
- package/dist/generated/components/ui/toggle.tsx +85 -0
- package/dist/generated/components/ui/tooltip.tsx +36 -0
- package/dist/generated/components/ui/typography.tsx +204 -0
- package/package.json +8 -8
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import * as Select from '@radix-ui/react-select';
|
|
2
|
+
import { useAugmentedRef, useControllableState } from '@rnr/hooks';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type {
|
|
5
|
+
ForceMountable,
|
|
6
|
+
PositionedContentProps,
|
|
7
|
+
PressableRef,
|
|
8
|
+
SlottablePressableProps,
|
|
9
|
+
SlottableTextProps,
|
|
10
|
+
SlottableViewProps,
|
|
11
|
+
TextRef,
|
|
12
|
+
ViewRef,
|
|
13
|
+
} from '@rnr/types';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { Pressable, Text, View } from 'react-native';
|
|
16
|
+
import type {
|
|
17
|
+
RootContext,
|
|
18
|
+
SelectContentProps,
|
|
19
|
+
SelectItemProps,
|
|
20
|
+
SelectOverlayProps,
|
|
21
|
+
SelectPortalProps,
|
|
22
|
+
SelectRootProps,
|
|
23
|
+
SelectSeparatorProps,
|
|
24
|
+
SelectValueProps,
|
|
25
|
+
} from './types';
|
|
26
|
+
|
|
27
|
+
const SelectContext = React.createContext<RootContext | null>(null);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @web Parameter of `onValueChange` has the value of `value` for the `value` and the `label` of the selected Option
|
|
31
|
+
* @ex When an Option with a label of Green Apple, the parameter passed to `onValueChange` is { value: 'green-apple', label: 'green-apple' }
|
|
32
|
+
*/
|
|
33
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & SelectRootProps>(
|
|
34
|
+
(
|
|
35
|
+
{
|
|
36
|
+
asChild,
|
|
37
|
+
value: valueProp,
|
|
38
|
+
defaultValue,
|
|
39
|
+
onValueChange: onValueChangeProp,
|
|
40
|
+
open: openProp,
|
|
41
|
+
defaultOpen,
|
|
42
|
+
onOpenChange: onOpenChangeProp,
|
|
43
|
+
...viewProps
|
|
44
|
+
},
|
|
45
|
+
ref
|
|
46
|
+
) => {
|
|
47
|
+
const [open = false, onOpenChange] = useControllableState({
|
|
48
|
+
prop: openProp,
|
|
49
|
+
defaultProp: defaultOpen,
|
|
50
|
+
onChange: onOpenChangeProp,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const [value, onValueChange] = useControllableState({
|
|
54
|
+
prop: valueProp,
|
|
55
|
+
defaultProp: defaultValue,
|
|
56
|
+
onChange: onValueChangeProp,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function onStrValueChange(val: string) {
|
|
60
|
+
onValueChange({ value: val, label: val });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const Component = asChild ? Slot.View : View;
|
|
64
|
+
return (
|
|
65
|
+
<SelectContext.Provider
|
|
66
|
+
value={{
|
|
67
|
+
value,
|
|
68
|
+
onValueChange,
|
|
69
|
+
open,
|
|
70
|
+
onOpenChange,
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<Select.Root
|
|
74
|
+
value={value?.value}
|
|
75
|
+
defaultValue={defaultValue?.value}
|
|
76
|
+
onValueChange={onStrValueChange}
|
|
77
|
+
open={open}
|
|
78
|
+
defaultOpen={defaultOpen}
|
|
79
|
+
onOpenChange={onOpenChange}
|
|
80
|
+
>
|
|
81
|
+
<Component ref={ref} {...viewProps} />
|
|
82
|
+
</Select.Root>
|
|
83
|
+
</SelectContext.Provider>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
Root.displayName = 'RootWebSelect';
|
|
89
|
+
|
|
90
|
+
function useRootContext() {
|
|
91
|
+
const context = React.useContext(SelectContext);
|
|
92
|
+
if (!context) {
|
|
93
|
+
throw new Error('Select compound components cannot be rendered outside the Select component');
|
|
94
|
+
}
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const Trigger = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
99
|
+
({ asChild, role: _role, disabled, ...props }, ref) => {
|
|
100
|
+
const augmentedRef = useAugmentedRef({ ref });
|
|
101
|
+
const { open } = useRootContext();
|
|
102
|
+
|
|
103
|
+
React.useLayoutEffect(() => {
|
|
104
|
+
if (augmentedRef.current) {
|
|
105
|
+
const augRef = augmentedRef.current as unknown as HTMLButtonElement;
|
|
106
|
+
augRef.dataset.state = open ? 'open' : 'closed';
|
|
107
|
+
augRef.type = 'button';
|
|
108
|
+
}
|
|
109
|
+
}, [open]);
|
|
110
|
+
|
|
111
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
112
|
+
return (
|
|
113
|
+
<Select.Trigger disabled={disabled ?? undefined} asChild>
|
|
114
|
+
<Component ref={augmentedRef} role='button' disabled={disabled} {...props} />
|
|
115
|
+
</Select.Trigger>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
Trigger.displayName = 'TriggerWebSelect';
|
|
121
|
+
|
|
122
|
+
const Value = React.forwardRef<TextRef, SlottableTextProps & SelectValueProps>(
|
|
123
|
+
({ asChild, placeholder, children, ...props }, ref) => {
|
|
124
|
+
return (
|
|
125
|
+
<Slot.Text ref={ref} {...props}>
|
|
126
|
+
<Select.Value placeholder={placeholder}>{children}</Select.Value>
|
|
127
|
+
</Slot.Text>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
Value.displayName = 'ValueWebSelect';
|
|
133
|
+
|
|
134
|
+
function Portal({ container, children }: SelectPortalProps) {
|
|
135
|
+
return <Select.Portal children={children} container={container} />;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const Overlay = React.forwardRef<PressableRef, SlottablePressableProps & SelectOverlayProps>(
|
|
139
|
+
({ asChild, forceMount, ...props }, ref) => {
|
|
140
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
141
|
+
return <Component ref={ref} {...props} />;
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
Overlay.displayName = 'OverlayWebSelect';
|
|
146
|
+
|
|
147
|
+
const Content = React.forwardRef<
|
|
148
|
+
ViewRef,
|
|
149
|
+
SlottableViewProps & PositionedContentProps & SelectContentProps
|
|
150
|
+
>(
|
|
151
|
+
(
|
|
152
|
+
{
|
|
153
|
+
asChild = false,
|
|
154
|
+
forceMount: _forceMount,
|
|
155
|
+
align = 'start',
|
|
156
|
+
side = 'bottom',
|
|
157
|
+
position = 'popper',
|
|
158
|
+
sideOffset = 0,
|
|
159
|
+
alignOffset = 0,
|
|
160
|
+
avoidCollisions = true,
|
|
161
|
+
disablePositioningStyle: _disablePositioningStyle,
|
|
162
|
+
onCloseAutoFocus,
|
|
163
|
+
onEscapeKeyDown,
|
|
164
|
+
onInteractOutside: _onInteractOutside,
|
|
165
|
+
onPointerDownOutside,
|
|
166
|
+
...props
|
|
167
|
+
},
|
|
168
|
+
ref
|
|
169
|
+
) => {
|
|
170
|
+
const Component = asChild ? Slot.View : View;
|
|
171
|
+
return (
|
|
172
|
+
<Select.Content
|
|
173
|
+
onCloseAutoFocus={onCloseAutoFocus}
|
|
174
|
+
onEscapeKeyDown={onEscapeKeyDown}
|
|
175
|
+
onPointerDownOutside={onPointerDownOutside}
|
|
176
|
+
align={align}
|
|
177
|
+
side={side}
|
|
178
|
+
sideOffset={sideOffset}
|
|
179
|
+
alignOffset={alignOffset}
|
|
180
|
+
avoidCollisions={avoidCollisions}
|
|
181
|
+
position={position}
|
|
182
|
+
>
|
|
183
|
+
<Component ref={ref} {...props} />
|
|
184
|
+
</Select.Content>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
Content.displayName = 'ContentWebSelect';
|
|
190
|
+
|
|
191
|
+
const ItemContext = React.createContext<{
|
|
192
|
+
itemValue: string;
|
|
193
|
+
label: string;
|
|
194
|
+
} | null>(null);
|
|
195
|
+
|
|
196
|
+
const Item = React.forwardRef<PressableRef, SlottablePressableProps & SelectItemProps>(
|
|
197
|
+
({ asChild, closeOnPress = true, label, value, children, ...props }, ref) => {
|
|
198
|
+
return (
|
|
199
|
+
<ItemContext.Provider value={{ itemValue: value, label: label }}>
|
|
200
|
+
<Slot.Pressable ref={ref} {...props}>
|
|
201
|
+
<Select.Item textValue={label} value={value} disabled={props.disabled ?? undefined}>
|
|
202
|
+
<>{children}</>
|
|
203
|
+
</Select.Item>
|
|
204
|
+
</Slot.Pressable>
|
|
205
|
+
</ItemContext.Provider>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
Item.displayName = 'ItemWebSelect';
|
|
211
|
+
|
|
212
|
+
function useItemContext() {
|
|
213
|
+
const context = React.useContext(ItemContext);
|
|
214
|
+
if (!context) {
|
|
215
|
+
throw new Error('Item compound components cannot be rendered outside of an Item component');
|
|
216
|
+
}
|
|
217
|
+
return context;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const ItemText = React.forwardRef<TextRef, Omit<SlottableTextProps, 'children'>>(
|
|
221
|
+
({ asChild, ...props }, ref) => {
|
|
222
|
+
const { label } = useItemContext();
|
|
223
|
+
|
|
224
|
+
const Component = asChild ? Slot.Text : Text;
|
|
225
|
+
return (
|
|
226
|
+
<Select.ItemText asChild>
|
|
227
|
+
<Component ref={ref} {...props}>
|
|
228
|
+
{label}
|
|
229
|
+
</Component>
|
|
230
|
+
</Select.ItemText>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
ItemText.displayName = 'ItemTextWebSelect';
|
|
236
|
+
|
|
237
|
+
const ItemIndicator = React.forwardRef<ViewRef, SlottableViewProps & ForceMountable>(
|
|
238
|
+
({ asChild, forceMount: _forceMount, ...props }, ref) => {
|
|
239
|
+
const Component = asChild ? Slot.View : View;
|
|
240
|
+
return (
|
|
241
|
+
<Select.ItemIndicator asChild>
|
|
242
|
+
<Component ref={ref} {...props} />
|
|
243
|
+
</Select.ItemIndicator>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
ItemIndicator.displayName = 'ItemIndicatorWebSelect';
|
|
249
|
+
|
|
250
|
+
const Group = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
251
|
+
const Component = asChild ? Slot.View : View;
|
|
252
|
+
return (
|
|
253
|
+
<Select.Group asChild>
|
|
254
|
+
<Component ref={ref} {...props} />
|
|
255
|
+
</Select.Group>
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
Group.displayName = 'GroupWebSelect';
|
|
260
|
+
|
|
261
|
+
const Label = React.forwardRef<TextRef, SlottableTextProps>(({ asChild, ...props }, ref) => {
|
|
262
|
+
const Component = asChild ? Slot.Text : Text;
|
|
263
|
+
return (
|
|
264
|
+
<Select.Label asChild>
|
|
265
|
+
<Component ref={ref} {...props} />
|
|
266
|
+
</Select.Label>
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
Label.displayName = 'LabelWebSelect';
|
|
271
|
+
|
|
272
|
+
const Separator = React.forwardRef<ViewRef, SlottableViewProps & SelectSeparatorProps>(
|
|
273
|
+
({ asChild, decorative, ...props }, ref) => {
|
|
274
|
+
const Component = asChild ? Slot.View : View;
|
|
275
|
+
return (
|
|
276
|
+
<Select.Separator asChild>
|
|
277
|
+
<Component ref={ref} {...props} />
|
|
278
|
+
</Select.Separator>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
Separator.displayName = 'SeparatorWebSelect';
|
|
284
|
+
|
|
285
|
+
const ScrollUpButton = (props: React.ComponentPropsWithoutRef<typeof Select.ScrollUpButton>) => {
|
|
286
|
+
return <Select.ScrollUpButton {...props} />;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const ScrollDownButton = (
|
|
290
|
+
props: React.ComponentPropsWithoutRef<typeof Select.ScrollDownButton>
|
|
291
|
+
) => {
|
|
292
|
+
return <Select.ScrollDownButton {...props} />;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const Viewport = (props: React.ComponentPropsWithoutRef<typeof Select.Viewport>) => {
|
|
296
|
+
return <Select.Viewport {...props} />;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export {
|
|
300
|
+
Content,
|
|
301
|
+
Group,
|
|
302
|
+
Item,
|
|
303
|
+
ItemIndicator,
|
|
304
|
+
ItemText,
|
|
305
|
+
Label,
|
|
306
|
+
Overlay,
|
|
307
|
+
Portal,
|
|
308
|
+
Root,
|
|
309
|
+
ScrollDownButton,
|
|
310
|
+
ScrollUpButton,
|
|
311
|
+
Separator,
|
|
312
|
+
Trigger,
|
|
313
|
+
Value,
|
|
314
|
+
Viewport,
|
|
315
|
+
useItemContext,
|
|
316
|
+
useRootContext,
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export type { Option } from './types';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ForceMountable } from '@rnr/types';
|
|
2
|
+
|
|
3
|
+
type Option =
|
|
4
|
+
| {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
| undefined;
|
|
9
|
+
|
|
10
|
+
interface RootContext {
|
|
11
|
+
value: Option;
|
|
12
|
+
onValueChange: (option: Option) => void;
|
|
13
|
+
open: boolean;
|
|
14
|
+
onOpenChange: (value: boolean) => void;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SelectRootProps {
|
|
19
|
+
value?: Option;
|
|
20
|
+
defaultValue?: Option;
|
|
21
|
+
onValueChange?: (option: Option) => void;
|
|
22
|
+
open?: boolean;
|
|
23
|
+
defaultOpen?: boolean;
|
|
24
|
+
onOpenChange?: (value: boolean) => void;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Platform: WEB ONLY
|
|
28
|
+
*/
|
|
29
|
+
dir?: 'ltr' | 'rtl';
|
|
30
|
+
/**
|
|
31
|
+
* Platform: WEB ONLY
|
|
32
|
+
*/
|
|
33
|
+
name?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Platform: WEB ONLY
|
|
36
|
+
*/
|
|
37
|
+
required?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface SelectValueProps {
|
|
41
|
+
placeholder: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface SelectPortalProps extends ForceMountable {
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
/**
|
|
47
|
+
* Platform: NATIVE ONLY
|
|
48
|
+
*/
|
|
49
|
+
hostName?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Platform: WEB ONLY
|
|
52
|
+
*/
|
|
53
|
+
container?: HTMLElement | null | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface SelectOverlayProps extends ForceMountable {
|
|
57
|
+
closeOnPress?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface SelectContentProps {
|
|
61
|
+
/**
|
|
62
|
+
* Platform: WEB ONLY
|
|
63
|
+
*/
|
|
64
|
+
position?: 'popper' | 'item-aligned' | undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface SelectItemProps {
|
|
68
|
+
value: string;
|
|
69
|
+
label: string;
|
|
70
|
+
closeOnPress?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface SelectSeparatorProps {
|
|
74
|
+
decorative?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type {
|
|
78
|
+
Option,
|
|
79
|
+
RootContext,
|
|
80
|
+
SelectContentProps,
|
|
81
|
+
SelectItemProps,
|
|
82
|
+
SelectOverlayProps,
|
|
83
|
+
SelectPortalProps,
|
|
84
|
+
SelectRootProps,
|
|
85
|
+
SelectSeparatorProps,
|
|
86
|
+
SelectValueProps,
|
|
87
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type { SlottableViewProps, ViewRef } from '@rnr/types';
|
|
5
|
+
import type { SeparatorRootProps } from './types';
|
|
6
|
+
|
|
7
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & SeparatorRootProps>(
|
|
8
|
+
({ asChild, decorative, orientation = 'horizontal', ...props }, ref) => {
|
|
9
|
+
const Component = asChild ? Slot.View : View;
|
|
10
|
+
return (
|
|
11
|
+
<Component
|
|
12
|
+
role={decorative ? 'presentation' : 'separator'}
|
|
13
|
+
aria-orientation={orientation}
|
|
14
|
+
ref={ref}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
Root.displayName = 'RootSeparator';
|
|
22
|
+
|
|
23
|
+
export { Root };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slider';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type {
|
|
5
|
+
SlottableViewProps,
|
|
6
|
+
ViewRef,
|
|
7
|
+
} from '@rnr/types';
|
|
8
|
+
import type { SliderRootProps } from './types';
|
|
9
|
+
|
|
10
|
+
const RootContext = React.createContext<SliderRootProps | null>(null);
|
|
11
|
+
|
|
12
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & SliderRootProps>(
|
|
13
|
+
(
|
|
14
|
+
{
|
|
15
|
+
asChild,
|
|
16
|
+
value,
|
|
17
|
+
disabled,
|
|
18
|
+
min,
|
|
19
|
+
max,
|
|
20
|
+
dir: _dir,
|
|
21
|
+
inverted: _inverted,
|
|
22
|
+
step: _step,
|
|
23
|
+
onValueChange: _onValueChange,
|
|
24
|
+
...props
|
|
25
|
+
},
|
|
26
|
+
ref
|
|
27
|
+
) => {
|
|
28
|
+
const Component = asChild ? Slot.View : View;
|
|
29
|
+
return (
|
|
30
|
+
<RootContext.Provider value={{ value, disabled, min, max }}>
|
|
31
|
+
<Component ref={ref} role='group' {...props} />
|
|
32
|
+
</RootContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
Root.displayName = 'RootNativeSlider';
|
|
38
|
+
|
|
39
|
+
function useSliderContext() {
|
|
40
|
+
const context = React.useContext(RootContext);
|
|
41
|
+
if (context === null) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'Slider compound components cannot be rendered outside the Slider component'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const Track = React.forwardRef<ViewRef, SlottableViewProps>(
|
|
50
|
+
({ asChild, ...props }, ref) => {
|
|
51
|
+
const { value, min, max, disabled } = useSliderContext();
|
|
52
|
+
|
|
53
|
+
const Component = asChild ? Slot.View : View;
|
|
54
|
+
return (
|
|
55
|
+
<Component
|
|
56
|
+
ref={ref}
|
|
57
|
+
aria-disabled={disabled}
|
|
58
|
+
role='slider'
|
|
59
|
+
aria-valuemin={min}
|
|
60
|
+
aria-valuemax={max}
|
|
61
|
+
aria-valuenow={value}
|
|
62
|
+
accessibilityValue={{ max, min, now: value }}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
Track.displayName = 'TrackNativeSlider';
|
|
70
|
+
|
|
71
|
+
const Range = React.forwardRef<ViewRef, SlottableViewProps>(
|
|
72
|
+
({ asChild, ...props }, ref) => {
|
|
73
|
+
const Component = asChild ? Slot.View : View;
|
|
74
|
+
return <Component ref={ref} role='presentation' {...props} />;
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
Range.displayName = 'RangeNativeSlider';
|
|
79
|
+
|
|
80
|
+
const Thumb = React.forwardRef<ViewRef, SlottableViewProps>(
|
|
81
|
+
({ asChild, ...props }, ref) => {
|
|
82
|
+
const Component = asChild ? Slot.View : View;
|
|
83
|
+
return <Component accessibilityRole='adjustable' ref={ref} {...props} />;
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
Thumb.displayName = 'ThumbNativeSlider';
|
|
88
|
+
|
|
89
|
+
export { Range, Root, Thumb, Track };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as Slider from '@radix-ui/react-slider';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import * as Slot from '@rnr/slot';
|
|
5
|
+
import type { SlottableViewProps, ViewRef } from '@rnr/types';
|
|
6
|
+
import type { SliderRootProps } from './types';
|
|
7
|
+
|
|
8
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & SliderRootProps>(
|
|
9
|
+
(
|
|
10
|
+
{ asChild, value, disabled, min, max, dir, inverted, step = 1, onValueChange, ...props },
|
|
11
|
+
ref
|
|
12
|
+
) => {
|
|
13
|
+
const Component = asChild ? Slot.View : View;
|
|
14
|
+
return (
|
|
15
|
+
<Slider.Root
|
|
16
|
+
dir={dir}
|
|
17
|
+
inverted={inverted}
|
|
18
|
+
value={[value]}
|
|
19
|
+
disabled={disabled}
|
|
20
|
+
min={min}
|
|
21
|
+
max={max}
|
|
22
|
+
step={step}
|
|
23
|
+
onValueChange={onValueChange}
|
|
24
|
+
asChild
|
|
25
|
+
>
|
|
26
|
+
<Component ref={ref} {...props} />
|
|
27
|
+
</Slider.Root>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
Root.displayName = 'RootWebSlider';
|
|
33
|
+
|
|
34
|
+
const Track = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
35
|
+
const Component = asChild ? Slot.View : View;
|
|
36
|
+
return (
|
|
37
|
+
<Slider.Track asChild>
|
|
38
|
+
<Component ref={ref} {...props} />
|
|
39
|
+
</Slider.Track>
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
Track.displayName = 'TrackWebSlider';
|
|
44
|
+
|
|
45
|
+
const Range = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
46
|
+
const Component = asChild ? Slot.View : View;
|
|
47
|
+
return (
|
|
48
|
+
<Slider.Range asChild>
|
|
49
|
+
<Component ref={ref} {...props} />
|
|
50
|
+
</Slider.Range>
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
Range.displayName = 'RangeWebSlider';
|
|
55
|
+
|
|
56
|
+
const Thumb = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
57
|
+
const Component = asChild ? Slot.View : View;
|
|
58
|
+
return (
|
|
59
|
+
<Slider.Thumb asChild>
|
|
60
|
+
<Component ref={ref} {...props} />
|
|
61
|
+
</Slider.Thumb>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
Thumb.displayName = 'ThumbWebSlider';
|
|
66
|
+
|
|
67
|
+
export { Range, Root, Thumb, Track };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface SliderRootProps {
|
|
2
|
+
value: number;
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Platform: WEB ONLY
|
|
8
|
+
*/
|
|
9
|
+
dir?: 'ltr' | 'rtl';
|
|
10
|
+
/**
|
|
11
|
+
* Platform: WEB ONLY
|
|
12
|
+
*/
|
|
13
|
+
inverted?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Platform: WEB ONLY
|
|
16
|
+
*/
|
|
17
|
+
step?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Platform: WEB ONLY
|
|
20
|
+
*/
|
|
21
|
+
onValueChange?: (value: number[]) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type { SliderRootProps };
|