@brand-map/primitives 0.0.0-broken.1 → 0.0.0-broken.2
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/package.json +2 -9
- package/src/accordion/accordion.tsx +17 -17
- package/src/accordion/accordion.web.tsx +13 -13
- package/src/alert-dialog/alert-dialog.tsx +28 -28
- package/src/alert-dialog/alert-dialog.web.tsx +18 -18
- package/src/alert-dialog/types.ts +3 -3
- package/src/aspect-ratio/aspect-ratio.tsx +3 -3
- package/src/avatar/avatar.tsx +10 -10
- package/src/avatar/types.ts +2 -2
- package/src/checkbox/checkbox.tsx +9 -9
- package/src/checkbox/checkbox.web.tsx +8 -8
- package/src/collapsible/collapsible.tsx +33 -35
- package/src/collapsible/collapsible.web.tsx +9 -9
- package/src/context-menu/context-menu.tsx +45 -45
- package/src/context-menu/context-menu.web.tsx +44 -44
- package/src/dialog/dialog.tsx +11 -11
- package/src/dialog/dialog.web.tsx +15 -15
- package/src/dialog/types.ts +5 -5
- package/src/dropdown-menu/dropdown-menu.tsx +43 -43
- package/src/dropdown-menu/dropdown-menu.web.tsx +45 -45
- package/src/hooks/use-Isomorphic-layout-effect.tsx +1 -2
- package/src/hooks/use-relative-position.tsx +2 -2
- package/src/hover-card/hover-card.tsx +40 -42
- package/src/hover-card/hover-card.web.tsx +9 -9
- package/src/label/label.tsx +3 -4
- package/src/label/label.web.tsx +5 -5
- package/src/menubar/menubar.tsx +45 -45
- package/src/menubar/menubar.web.tsx +47 -47
- package/src/navigation-menu/navigation-menu.tsx +23 -23
- package/src/navigation-menu/navigation-menu.web.tsx +26 -26
- package/src/popover/popover.tsx +20 -20
- package/src/popover/popover.web.tsx +14 -14
- package/src/progress/progress.tsx +4 -4
- package/src/progress/progress.web.tsx +5 -5
- package/src/radio-group/radio-group.tsx +11 -11
- package/src/radio-group/radio-group.web.tsx +9 -9
- package/src/render/index.ts +1 -0
- package/src/{slot/slot.tsx → render/render.tsx} +26 -27
- package/src/select/select.tsx +28 -28
- package/src/select/select.web.tsx +22 -22
- package/src/separator/separator.tsx +3 -3
- package/src/slider/slider.tsx +8 -8
- package/src/slider/slider.web.tsx +6 -6
- package/src/switch/switch.context.ts +16 -0
- package/src/switch/switch.tsx +68 -38
- package/src/switch/switch.web.tsx +9 -9
- package/src/switch/types.ts +27 -6
- package/src/table/table.tsx +9 -9
- package/src/tabs/tabs.tsx +13 -13
- package/src/tabs/tabs.web.tsx +10 -10
- package/src/toast/toast.tsx +14 -14
- package/src/toggle/toggle.tsx +5 -5
- package/src/toggle/toggle.web.tsx +5 -5
- package/src/toggle-group/toggle-group.tsx +11 -11
- package/src/toggle-group/toggle-group.web.tsx +10 -10
- package/src/toolbar/toolbar.tsx +12 -12
- package/src/toolbar/toolbar.web.tsx +12 -12
- package/src/tooltip/tooltip.tsx +17 -17
- package/src/tooltip/tooltip.web.tsx +11 -11
- package/src/types/index.ts +5 -15
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.oxfmtrc.json +0 -35
- package/.oxlintrc.json +0 -166
- package/README.md +0 -78
- package/bun.lock +0 -904
- package/mise.toml +0 -3
- package/src/slot/index.ts +0 -1
package/src/select/select.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useId, useState, useContext, useEffect } from "react";
|
|
2
2
|
import { BackHandler, Pressable, Text, View, type GestureResponderEvent, type LayoutChangeEvent, type LayoutRectangle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { useAugmentedRef, useControllableState, useRelativePosition, type LayoutPosition } from "../hooks";
|
|
5
5
|
import { Portal as RNPPortal } from "../portal";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Render from "../render";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
ContentProps,
|
|
@@ -45,19 +45,19 @@ interface RootContextInterface extends SharedRootContext {
|
|
|
45
45
|
nativeID: string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const RootContext =
|
|
48
|
+
const RootContext = createContext<RootContextInterface | null>(null);
|
|
49
49
|
|
|
50
|
-
const Root =
|
|
50
|
+
const Root = forwardRef<RootRef, RootProps>(
|
|
51
51
|
({ render, value: valueProp, defaultValue, onValueChange: onValueChangeProp, onOpenChange: onOpenChangeProp, disabled, ...viewProps }, ref) => {
|
|
52
|
-
const nativeID =
|
|
52
|
+
const nativeID = useId();
|
|
53
53
|
const [value, onValueChange] = useControllableState({
|
|
54
54
|
prop: valueProp,
|
|
55
55
|
defaultProp: defaultValue,
|
|
56
56
|
onChange: onValueChangeProp,
|
|
57
57
|
});
|
|
58
|
-
const [triggerPosition, setTriggerPosition] =
|
|
59
|
-
const [contentLayout, setContentLayout] =
|
|
60
|
-
const [open, setOpen] =
|
|
58
|
+
const [triggerPosition, setTriggerPosition] = useState<LayoutPosition | null>(null);
|
|
59
|
+
const [contentLayout, setContentLayout] = useState<LayoutRectangle | null>(null);
|
|
60
|
+
const [open, setOpen] = useState(false);
|
|
61
61
|
|
|
62
62
|
function onOpenChange(value: boolean) {
|
|
63
63
|
setOpen(value);
|
|
@@ -91,14 +91,14 @@ const Root = React.forwardRef<RootRef, RootProps>(
|
|
|
91
91
|
Root.displayName = "RootNativeSelect";
|
|
92
92
|
|
|
93
93
|
function useRootContext() {
|
|
94
|
-
const context =
|
|
94
|
+
const context = useContext(RootContext);
|
|
95
95
|
if (!context) {
|
|
96
96
|
throw new Error("Select compound components cannot be rendered outside the Select component");
|
|
97
97
|
}
|
|
98
98
|
return context;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const Trigger =
|
|
101
|
+
const Trigger = forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
102
102
|
const { open, onOpenChange, disabled: disabledRoot, setTriggerPosition } = useRootContext();
|
|
103
103
|
|
|
104
104
|
const augmentedRef = useAugmentedRef({
|
|
@@ -117,13 +117,13 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressPr
|
|
|
117
117
|
},
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
function onPress(
|
|
120
|
+
function onPress(event: GestureResponderEvent) {
|
|
121
121
|
if (disabled) return;
|
|
122
122
|
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
123
123
|
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
124
124
|
});
|
|
125
125
|
onOpenChange(!open);
|
|
126
|
-
onPressProp?.(
|
|
126
|
+
onPressProp?.(event);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
return (
|
|
@@ -141,7 +141,7 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressPr
|
|
|
141
141
|
|
|
142
142
|
Trigger.displayName = "TriggerNativeSelect";
|
|
143
143
|
|
|
144
|
-
const Value =
|
|
144
|
+
const Value = forwardRef<ValueRef, ValueProps>(({ placeholder, ...props }, ref) => {
|
|
145
145
|
const { value } = useRootContext();
|
|
146
146
|
|
|
147
147
|
return (
|
|
@@ -182,16 +182,16 @@ function Portal({ keepMounted, hostName, children }: PortalProps) {
|
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const Backdrop =
|
|
185
|
+
const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ keepMounted, onPress: onPressProp, closeOnPress = true, ...props }, ref) => {
|
|
186
186
|
const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
187
187
|
|
|
188
|
-
function onPress(
|
|
188
|
+
function onPress(event: GestureResponderEvent) {
|
|
189
189
|
if (closeOnPress) {
|
|
190
190
|
setTriggerPosition(null);
|
|
191
191
|
setContentLayout(null);
|
|
192
192
|
onOpenChange(false);
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
onPressProp?.(event);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
if (!keepMounted) {
|
|
@@ -214,7 +214,7 @@ Backdrop.displayName = "BackdropNativeSelect";
|
|
|
214
214
|
/**
|
|
215
215
|
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
216
216
|
*/
|
|
217
|
-
const Content =
|
|
217
|
+
const Content = forwardRef<ContentRef, ContentProps>(
|
|
218
218
|
(
|
|
219
219
|
{
|
|
220
220
|
render = false,
|
|
@@ -235,7 +235,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
|
235
235
|
) => {
|
|
236
236
|
const { open, onOpenChange, contentLayout, nativeID, triggerPosition, setContentLayout, setTriggerPosition } = useRootContext();
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
useEffect(() => {
|
|
239
239
|
const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
240
240
|
setTriggerPosition(null);
|
|
241
241
|
setContentLayout(null);
|
|
@@ -289,15 +289,15 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
|
289
289
|
|
|
290
290
|
Content.displayName = "ContentNativeSelect";
|
|
291
291
|
|
|
292
|
-
const ItemContext =
|
|
292
|
+
const ItemContext = createContext<{
|
|
293
293
|
itemValue: string;
|
|
294
294
|
label: string;
|
|
295
295
|
} | null>(null);
|
|
296
296
|
|
|
297
|
-
const Item =
|
|
297
|
+
const Item = forwardRef<ItemRef, ItemProps>(
|
|
298
298
|
({ render, value: itemValue, label, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, ref) => {
|
|
299
299
|
const { onOpenChange, value, onValueChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
300
|
-
function onPress(
|
|
300
|
+
function onPress(event: GestureResponderEvent) {
|
|
301
301
|
if (closeOnPress) {
|
|
302
302
|
setTriggerPosition(null);
|
|
303
303
|
setContentLayout(null);
|
|
@@ -305,7 +305,7 @@ const Item = React.forwardRef<ItemRef, ItemProps>(
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
onValueChange({ value: itemValue, label });
|
|
308
|
-
onPressProp?.(
|
|
308
|
+
onPressProp?.(event);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
return (
|
|
@@ -332,14 +332,14 @@ const Item = React.forwardRef<ItemRef, ItemProps>(
|
|
|
332
332
|
Item.displayName = "ItemNativeSelect";
|
|
333
333
|
|
|
334
334
|
function useItemContext() {
|
|
335
|
-
const context =
|
|
335
|
+
const context = useContext(ItemContext);
|
|
336
336
|
if (!context) {
|
|
337
337
|
throw new Error("Item compound components cannot be rendered outside of an Item component");
|
|
338
338
|
}
|
|
339
339
|
return context;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
const ItemText =
|
|
342
|
+
const ItemText = forwardRef<ItemTextRef, ItemTextProps>(({ ...props }, ref) => {
|
|
343
343
|
const { label } = useItemContext();
|
|
344
344
|
|
|
345
345
|
return (
|
|
@@ -354,7 +354,7 @@ const ItemText = React.forwardRef<ItemTextRef, ItemTextProps>(({ ...props }, ref
|
|
|
354
354
|
|
|
355
355
|
ItemText.displayName = "ItemTextNativeSelect";
|
|
356
356
|
|
|
357
|
-
const ItemIndicator =
|
|
357
|
+
const ItemIndicator = forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({ keepMounted, ...props }, ref) => {
|
|
358
358
|
const { itemValue } = useItemContext();
|
|
359
359
|
const { value } = useRootContext();
|
|
360
360
|
|
|
@@ -375,7 +375,7 @@ const ItemIndicator = React.forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({
|
|
|
375
375
|
|
|
376
376
|
ItemIndicator.displayName = "ItemIndicatorNativeSelect";
|
|
377
377
|
|
|
378
|
-
const Group =
|
|
378
|
+
const Group = forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
379
379
|
return (
|
|
380
380
|
<Component
|
|
381
381
|
ref={ref}
|
|
@@ -387,7 +387,7 @@ const Group = React.forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
|
387
387
|
|
|
388
388
|
Group.displayName = "GroupNativeSelect";
|
|
389
389
|
|
|
390
|
-
const Label =
|
|
390
|
+
const Label = forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
|
|
391
391
|
return (
|
|
392
392
|
<Component
|
|
393
393
|
ref={ref}
|
|
@@ -398,7 +398,7 @@ const Label = React.forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
|
|
|
398
398
|
|
|
399
399
|
Label.displayName = "LabelNativeSelect";
|
|
400
400
|
|
|
401
|
-
const Separator =
|
|
401
|
+
const Separator = forwardRef<SeparatorRef, SeparatorProps>(({ decorative, ...props }, ref) => {
|
|
402
402
|
return (
|
|
403
403
|
<Component
|
|
404
404
|
role={decorative ? "presentation" : "separator"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// import * as Select from "@radix-ui/react-select";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, Text, View } from "react-native";
|
|
4
4
|
|
|
5
5
|
// import { useAugmentedRef, useControllableState, useIsomorphicLayoutEffect } from "../hooks";
|
|
6
|
-
// import * as
|
|
6
|
+
// import * as Render from "../render";
|
|
7
7
|
|
|
8
8
|
// import type {
|
|
9
9
|
// ContentProps,
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// ViewportProps,
|
|
36
36
|
// } from "./types";
|
|
37
37
|
|
|
38
|
-
// const SelectContext =
|
|
38
|
+
// const SelectContext = createContext<
|
|
39
39
|
// | (SharedRootContext & {
|
|
40
40
|
// open: boolean;
|
|
41
41
|
// onOpenChange: (open: boolean) => void;
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
// * @web Parameter of `onValueChange` has the value of `value` for the `value` and the `label` of the selected Option
|
|
48
48
|
// * @ex When an Option with a label of Green Apple, the parameter passed to `onValueChange` is { value: 'green-apple', label: 'green-apple' }
|
|
49
49
|
// */
|
|
50
|
-
// const Root =
|
|
50
|
+
// const Root = forwardRef<RootRef, RootProps>(
|
|
51
51
|
// ({ render, value: valueProp, defaultValue, onValueChange: onValueChangeProp, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
52
52
|
// const [value, onValueChange] = useControllableState({
|
|
53
53
|
// prop: valueProp,
|
|
54
54
|
// defaultProp: defaultValue,
|
|
55
55
|
// onChange: onValueChangeProp,
|
|
56
56
|
// });
|
|
57
|
-
// const [open, setOpen] =
|
|
57
|
+
// const [open, setOpen] = useState(false);
|
|
58
58
|
|
|
59
59
|
// function onOpenChange(value: boolean) {
|
|
60
60
|
// setOpen(value);
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
// Root.displayName = "RootWebSelect";
|
|
96
96
|
|
|
97
97
|
// function useRootContext() {
|
|
98
|
-
// const context =
|
|
98
|
+
// const context = useContext(SelectContext);
|
|
99
99
|
// if (!context) {
|
|
100
100
|
// throw new Error("Select compound components cannot be rendered outside the Select component");
|
|
101
101
|
// }
|
|
102
102
|
// return context;
|
|
103
103
|
// }
|
|
104
104
|
|
|
105
|
-
// const Trigger =
|
|
105
|
+
// const Trigger = forwardRef<TriggerRef, TriggerProps>(({ role: _role, disabled, ...props }, ref) => {
|
|
106
106
|
// const { open, onOpenChange } = useRootContext();
|
|
107
107
|
// const augmentedRef = useAugmentedRef({
|
|
108
108
|
// ref,
|
|
@@ -142,14 +142,14 @@
|
|
|
142
142
|
|
|
143
143
|
// Trigger.displayName = "TriggerWebSelect";
|
|
144
144
|
|
|
145
|
-
// const Value =
|
|
145
|
+
// const Value = forwardRef<ValueRef, ValueProps>(({ placeholder, children, ...props }, ref) => {
|
|
146
146
|
// return (
|
|
147
|
-
// <
|
|
147
|
+
// <Render.Text
|
|
148
148
|
// ref={ref}
|
|
149
149
|
// {...props}
|
|
150
150
|
// >
|
|
151
151
|
// <Select.Value placeholder={placeholder}>{children}</Select.Value>
|
|
152
|
-
// </
|
|
152
|
+
// </Render.Text>
|
|
153
153
|
// );
|
|
154
154
|
// });
|
|
155
155
|
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
// );
|
|
165
165
|
// }
|
|
166
166
|
|
|
167
|
-
// const Backdrop =
|
|
167
|
+
// const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ keepMounted, children, ...props }, ref) => {
|
|
168
168
|
// const { open } = useRootContext();
|
|
169
169
|
|
|
170
170
|
//
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
|
|
184
184
|
// Backdrop.displayName = "BackdropWebSelect";
|
|
185
185
|
|
|
186
|
-
// const Content =
|
|
186
|
+
// const Content = forwardRef<ContentRef, ContentProps>(
|
|
187
187
|
// (
|
|
188
188
|
// {
|
|
189
189
|
// render = false,
|
|
@@ -227,15 +227,15 @@
|
|
|
227
227
|
|
|
228
228
|
// Content.displayName = "ContentWebSelect";
|
|
229
229
|
|
|
230
|
-
// const ItemContext =
|
|
230
|
+
// const ItemContext = createContext<{
|
|
231
231
|
// itemValue: string;
|
|
232
232
|
// label: string;
|
|
233
233
|
// } | null>(null);
|
|
234
234
|
|
|
235
|
-
// const Item =
|
|
235
|
+
// const Item = forwardRef<ItemRef, ItemProps>(({ closeOnPress = true, label, value, children, ...props }, ref) => {
|
|
236
236
|
// return (
|
|
237
237
|
// <ItemContext.Provider value={{ itemValue: value, label: label }}>
|
|
238
|
-
// <
|
|
238
|
+
// <Render.Pressable
|
|
239
239
|
// ref={ref}
|
|
240
240
|
// {...props}
|
|
241
241
|
// >
|
|
@@ -246,7 +246,7 @@
|
|
|
246
246
|
// >
|
|
247
247
|
// <>{children as React.ReactNode}</>
|
|
248
248
|
// </Select.Item>
|
|
249
|
-
// </
|
|
249
|
+
// </Render.Pressable>
|
|
250
250
|
// </ItemContext.Provider>
|
|
251
251
|
// );
|
|
252
252
|
// });
|
|
@@ -254,14 +254,14 @@
|
|
|
254
254
|
// Item.displayName = "ItemWebSelect";
|
|
255
255
|
|
|
256
256
|
// function useItemContext() {
|
|
257
|
-
// const context =
|
|
257
|
+
// const context = useContext(ItemContext);
|
|
258
258
|
// if (!context) {
|
|
259
259
|
// throw new Error("Item compound components cannot be rendered outside of an Item component");
|
|
260
260
|
// }
|
|
261
261
|
// return context;
|
|
262
262
|
// }
|
|
263
263
|
|
|
264
|
-
// const ItemText =
|
|
264
|
+
// const ItemText = forwardRef<ItemTextRef, Omit<ItemTextProps, "children">>(({ ...props }, ref) => {
|
|
265
265
|
// const { label } = useItemContext();
|
|
266
266
|
|
|
267
267
|
//
|
|
@@ -279,7 +279,7 @@
|
|
|
279
279
|
|
|
280
280
|
// ItemText.displayName = "ItemTextWebSelect";
|
|
281
281
|
|
|
282
|
-
// const ItemIndicator =
|
|
282
|
+
// const ItemIndicator = forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({ keepMounted: _forceMount, ...props }, ref) => {
|
|
283
283
|
//
|
|
284
284
|
// return (
|
|
285
285
|
// <Select.ItemIndicator render>
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
|
|
294
294
|
// ItemIndicator.displayName = "ItemIndicatorWebSelect";
|
|
295
295
|
|
|
296
|
-
// const Group =
|
|
296
|
+
// const Group = forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
297
297
|
//
|
|
298
298
|
// return (
|
|
299
299
|
// <Select.Group render>
|
|
@@ -307,7 +307,7 @@
|
|
|
307
307
|
|
|
308
308
|
// Group.displayName = "GroupWebSelect";
|
|
309
309
|
|
|
310
|
-
// const Label =
|
|
310
|
+
// const Label = forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
|
|
311
311
|
//
|
|
312
312
|
// return (
|
|
313
313
|
// <Select.Label render>
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
|
|
322
322
|
// Label.displayName = "LabelWebSelect";
|
|
323
323
|
|
|
324
|
-
// const Separator =
|
|
324
|
+
// const Separator = forwardRef<SeparatorRef, SeparatorProps>(({ decorative, ...props }, ref) => {
|
|
325
325
|
//
|
|
326
326
|
// return (
|
|
327
327
|
// <Select.Separator render>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
6
|
import type { RootProps, RootRef } from "./types";
|
|
7
7
|
|
|
8
|
-
const Root =
|
|
8
|
+
const Root = forwardRef<RootRef, RootProps>(({ decorative, orientation = "horizontal", ...props }, ref) => {
|
|
9
9
|
return (
|
|
10
10
|
<Component
|
|
11
11
|
role={decorative ? "presentation" : "separator"}
|
package/src/slider/slider.tsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useContext } from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
6
|
import type { RangeProps, RangeRef, RootProps, RootRef, ThumbProps, ThumbRef, TrackProps, TrackRef } from "./types";
|
|
7
7
|
|
|
8
|
-
const RootContext =
|
|
8
|
+
const RootContext = createContext<RootProps | null>(null);
|
|
9
9
|
|
|
10
|
-
const Root =
|
|
10
|
+
const Root = forwardRef<RootRef, RootProps>(
|
|
11
11
|
({ render, value, disabled, min, max, dir: _dir, inverted: _inverted, step: _step, onValueChange: _onValueChange, ...props }, ref) => {
|
|
12
12
|
return (
|
|
13
13
|
<RootContext.Provider value={{ value, disabled, min, max }}>
|
|
@@ -24,14 +24,14 @@ const Root = React.forwardRef<RootRef, RootProps>(
|
|
|
24
24
|
Root.displayName = "RootNativeSlider";
|
|
25
25
|
|
|
26
26
|
function useSliderContext() {
|
|
27
|
-
const context =
|
|
27
|
+
const context = useContext(RootContext);
|
|
28
28
|
if (context === null) {
|
|
29
29
|
throw new Error("Slider compound components cannot be rendered outside the Slider component");
|
|
30
30
|
}
|
|
31
31
|
return context;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const Track =
|
|
34
|
+
const Track = forwardRef<TrackRef, TrackProps>(({ ...props }, ref) => {
|
|
35
35
|
const { value, min, max, disabled } = useSliderContext();
|
|
36
36
|
|
|
37
37
|
return (
|
|
@@ -50,7 +50,7 @@ const Track = React.forwardRef<TrackRef, TrackProps>(({ ...props }, ref) => {
|
|
|
50
50
|
|
|
51
51
|
Track.displayName = "TrackNativeSlider";
|
|
52
52
|
|
|
53
|
-
const Range =
|
|
53
|
+
const Range = forwardRef<RangeRef, RangeProps>(({ ...props }, ref) => {
|
|
54
54
|
return (
|
|
55
55
|
<Component
|
|
56
56
|
ref={ref}
|
|
@@ -62,7 +62,7 @@ const Range = React.forwardRef<RangeRef, RangeProps>(({ ...props }, ref) => {
|
|
|
62
62
|
|
|
63
63
|
Range.displayName = "RangeNativeSlider";
|
|
64
64
|
|
|
65
|
-
const Thumb =
|
|
65
|
+
const Thumb = forwardRef<ThumbRef, ThumbProps>(({ ...props }, ref) => {
|
|
66
66
|
return (
|
|
67
67
|
<Component
|
|
68
68
|
accessibilityRole="adjustable"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// import * as Slider from "@radix-ui/react-slider";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { View } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
|
|
7
7
|
// import type { RangeProps, RangeRef, RootProps, RootRef, ThumbProps, ThumbRef, TrackProps, TrackRef } from "./types";
|
|
8
8
|
|
|
9
|
-
// const Root =
|
|
9
|
+
// const Root = forwardRef<RootRef, RootProps>(({ value, disabled, min, max, dir, inverted, step = 1, onValueChange, ...props }, ref) => {
|
|
10
10
|
//
|
|
11
11
|
// return (
|
|
12
12
|
// <Slider.Root
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
// Root.displayName = "RootWebSlider";
|
|
32
32
|
|
|
33
|
-
// const Track =
|
|
33
|
+
// const Track = forwardRef<TrackRef, TrackProps>(({ ...props }, ref) => {
|
|
34
34
|
//
|
|
35
35
|
// return (
|
|
36
36
|
// <Slider.Track render>
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
// Track.displayName = "TrackWebSlider";
|
|
46
46
|
|
|
47
|
-
// const Range =
|
|
47
|
+
// const Range = forwardRef<RangeRef, RangeProps>(({ ...props }, ref) => {
|
|
48
48
|
//
|
|
49
49
|
// return (
|
|
50
50
|
// <Slider.Range render>
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
|
|
59
59
|
// Range.displayName = "RangeWebSlider";
|
|
60
60
|
|
|
61
|
-
// const Thumb =
|
|
61
|
+
// const Thumb = forwardRef<ThumbRef, ThumbProps>(({ ...props }, ref) => {
|
|
62
62
|
//
|
|
63
63
|
// return (
|
|
64
64
|
// <Slider.Thumb render>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { SwitchRootState } from "./types";
|
|
4
|
+
|
|
5
|
+
export type SwitchRootContext = SwitchRootState;
|
|
6
|
+
|
|
7
|
+
export const SwitchRootContext = React.createContext<SwitchRootContext | undefined>(undefined);
|
|
8
|
+
|
|
9
|
+
export function useSwitchRootContext() {
|
|
10
|
+
const context = React.useContext(SwitchRootContext);
|
|
11
|
+
if (context === undefined) {
|
|
12
|
+
throw new Error("Base UI: SwitchRootContext is missing. Switch parts must be placed within <Switch.Root>.");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return context;
|
|
16
|
+
}
|
package/src/switch/switch.tsx
CHANGED
|
@@ -1,49 +1,79 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { forwardRef, useMemo } from "react";
|
|
2
|
+
import { type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { SwitchRootContext, useSwitchRootContext } from "./switch.context";
|
|
7
|
+
import { SwitchRootRef, SwitchRootProps, SwitchRootState, SwitchThumbRef, SwitchThumbProps } from "./types";
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export const SwitchRoot = forwardRef(function SwitchRoot(componentProps: SwitchRootProps, forwardedRef: React.ForwardedRef<SwitchRootRef>) {
|
|
10
|
+
const {
|
|
11
|
+
render,
|
|
12
|
+
checked,
|
|
13
|
+
onCheckedChange,
|
|
14
|
+
disabled = false,
|
|
15
|
+
readOnly = false,
|
|
16
|
+
required = false,
|
|
17
|
+
onPress: onPressProp,
|
|
18
|
+
"aria-valuetext": ariaValueText,
|
|
19
|
+
...rest
|
|
20
|
+
} = componentProps;
|
|
21
|
+
|
|
22
|
+
const state: SwitchRootState = useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
checked,
|
|
25
|
+
disabled,
|
|
26
|
+
readOnly,
|
|
27
|
+
required,
|
|
28
|
+
}),
|
|
29
|
+
[checked, disabled, readOnly, required],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const onPress = (event: GestureResponderEvent) => {
|
|
33
|
+
if (disabled) {
|
|
34
|
+
return;
|
|
14
35
|
}
|
|
36
|
+
onCheckedChange(!checked);
|
|
37
|
+
onPressProp?.(event);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const props = {
|
|
41
|
+
"ref": forwardedRef,
|
|
42
|
+
"role": "switch" as const,
|
|
43
|
+
"aria-disabled": disabled,
|
|
44
|
+
"aria-checked": checked,
|
|
45
|
+
"aria-valuetext": (ariaValueText ?? checked) ? "on" : "off",
|
|
46
|
+
"onPress": onPress,
|
|
47
|
+
"accessibilityState": { checked, disabled },
|
|
48
|
+
"disabled": disabled,
|
|
49
|
+
...rest,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (typeof render === "function") {
|
|
53
|
+
return <SwitchRootContext.Provider value={state}>{render(props, state)}</SwitchRootContext.Provider>;
|
|
54
|
+
}
|
|
15
55
|
|
|
16
|
-
return (
|
|
17
|
-
<Component
|
|
18
|
-
ref={ref}
|
|
19
|
-
aria-disabled={disabled}
|
|
20
|
-
role="switch"
|
|
21
|
-
aria-checked={checked}
|
|
22
|
-
aria-valuetext={(ariaValueText ?? checked) ? "on" : "off"}
|
|
23
|
-
onPress={onPress}
|
|
24
|
-
accessibilityState={{
|
|
25
|
-
checked,
|
|
26
|
-
disabled,
|
|
27
|
-
}}
|
|
28
|
-
disabled={disabled}
|
|
29
|
-
{...props}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
Root.displayName = "RootNativeSwitch";
|
|
36
|
-
|
|
37
|
-
const Thumb = React.forwardRef<ThumbRef, ThumbProps>(({ ...props }, ref) => {
|
|
38
56
|
return (
|
|
39
|
-
<
|
|
40
|
-
|
|
57
|
+
<SwitchRootContext.Provider value={state}>
|
|
58
|
+
<Render.Pressable {...props} />
|
|
59
|
+
</SwitchRootContext.Provider>
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
SwitchRoot.displayName = "SwitchRoot";
|
|
63
|
+
|
|
64
|
+
const SwitchThumb = forwardRef(function SwitchThumb({ render, ...props }: SwitchThumbProps, forwardedRef: React.ForwardedRef<SwitchThumbRef>) {
|
|
65
|
+
const state = useSwitchRootContext();
|
|
66
|
+
|
|
67
|
+
if (typeof render === "function") {
|
|
68
|
+
return render(props, state);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Render.View
|
|
73
|
+
ref={forwardedRef}
|
|
41
74
|
role="presentation"
|
|
42
75
|
{...props}
|
|
43
76
|
/>
|
|
44
77
|
);
|
|
45
78
|
});
|
|
46
|
-
|
|
47
|
-
Thumb.displayName = "ThumbNativeSwitch";
|
|
48
|
-
|
|
49
|
-
export { Root, Thumb };
|
|
79
|
+
SwitchThumb.displayName = "ThumbNativeSwitch";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// import * as Switch from "@radix-ui/react-switch";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
|
|
7
7
|
// import type { RootProps, RootRef, ThumbProps, ThumbRef } from "./types";
|
|
8
8
|
|
|
9
|
-
// const Root =
|
|
9
|
+
// const Root = forwardRef<RootRef, RootProps>(
|
|
10
10
|
// ({ render, checked, onCheckedChange, disabled, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }, ref) => {
|
|
11
|
-
// function onPress(
|
|
11
|
+
// function onPress(event: GestureResponderEvent) {
|
|
12
12
|
// onCheckedChange(!checked);
|
|
13
|
-
// onPressProp?.(
|
|
13
|
+
// onPressProp?.(event);
|
|
14
14
|
// }
|
|
15
15
|
|
|
16
|
-
// function onKeyDown(
|
|
17
|
-
// onKeyDownProp?.(
|
|
18
|
-
// if (
|
|
16
|
+
// function onKeyDown(event: React.KeyboardEvent) {
|
|
17
|
+
// onKeyDownProp?.(event);
|
|
18
|
+
// if (event.key === " ") {
|
|
19
19
|
// onCheckedChange(!checked);
|
|
20
20
|
// }
|
|
21
21
|
// }
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
// Root.displayName = "RootWebSwitch";
|
|
45
45
|
|
|
46
|
-
// const Thumb =
|
|
46
|
+
// const Thumb = forwardRef<ThumbRef, ThumbProps>(({ ...props }, ref) => {
|
|
47
47
|
//
|
|
48
48
|
// return (
|
|
49
49
|
// <Switch.Thumb render>
|