@tamagui/select 1.88.13 → 1.89.0-1706308641099
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/LICENSE +21 -0
- package/dist/esm/BubbleSelect.mjs +23 -0
- package/dist/esm/Select.mjs +359 -0
- package/dist/esm/SelectContent.mjs +47 -0
- package/dist/esm/SelectImpl.mjs +233 -0
- package/dist/esm/SelectItem.mjs +121 -0
- package/dist/esm/SelectItemText.mjs +52 -0
- package/dist/esm/SelectScrollButton.mjs +100 -0
- package/dist/esm/SelectTrigger.mjs +53 -0
- package/dist/esm/SelectViewport.mjs +117 -0
- package/dist/esm/constants.mjs +8 -0
- package/dist/esm/context.mjs +23 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/useSelectBreakpointActive.mjs +10 -0
- package/dist/jsx/BubbleSelect.mjs +23 -0
- package/dist/jsx/Select.mjs +359 -0
- package/dist/jsx/SelectContent.mjs +47 -0
- package/dist/jsx/SelectImpl.mjs +233 -0
- package/dist/jsx/SelectItem.mjs +121 -0
- package/dist/jsx/SelectItemText.mjs +52 -0
- package/dist/jsx/SelectScrollButton.mjs +100 -0
- package/dist/jsx/SelectTrigger.mjs +53 -0
- package/dist/jsx/SelectViewport.mjs +117 -0
- package/dist/jsx/constants.mjs +8 -0
- package/dist/jsx/context.mjs +23 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/types.mjs +0 -0
- package/dist/jsx/useSelectBreakpointActive.mjs +10 -0
- package/package.json +23 -23
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
|
+
import { ListItemFrame, useListItem } from "@tamagui/list-item";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { createSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
const ITEM_NAME = "SelectItem",
|
|
8
|
+
[SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME),
|
|
9
|
+
SelectItem = ListItemFrame.styleable(function (props, forwardedRef) {
|
|
10
|
+
const {
|
|
11
|
+
__scopeSelect,
|
|
12
|
+
value,
|
|
13
|
+
disabled = !1,
|
|
14
|
+
textValue: textValueProp,
|
|
15
|
+
index,
|
|
16
|
+
...restProps
|
|
17
|
+
} = props,
|
|
18
|
+
{
|
|
19
|
+
props: listItemProps
|
|
20
|
+
} = useListItem({
|
|
21
|
+
...(!props.unstyled && {
|
|
22
|
+
ellipse: !0
|
|
23
|
+
}),
|
|
24
|
+
...restProps
|
|
25
|
+
}),
|
|
26
|
+
context = useSelectItemParentContext(ITEM_NAME, __scopeSelect),
|
|
27
|
+
{
|
|
28
|
+
setSelectedIndex,
|
|
29
|
+
listRef,
|
|
30
|
+
setOpen,
|
|
31
|
+
onChange,
|
|
32
|
+
activeIndexSubscribe,
|
|
33
|
+
valueSubscribe,
|
|
34
|
+
allowMouseUpRef,
|
|
35
|
+
allowSelectRef,
|
|
36
|
+
setValueAtIndex,
|
|
37
|
+
selectTimeoutRef,
|
|
38
|
+
dataRef,
|
|
39
|
+
interactions,
|
|
40
|
+
shouldRenderWebNative,
|
|
41
|
+
size,
|
|
42
|
+
onActiveChange,
|
|
43
|
+
initialValue
|
|
44
|
+
} = context,
|
|
45
|
+
[isSelected, setSelected] = React.useState(initialValue === value);
|
|
46
|
+
React.useEffect(() => activeIndexSubscribe(i => {
|
|
47
|
+
index === i && (onActiveChange(value, index), listRef?.current[index]?.focus());
|
|
48
|
+
}), [index]), React.useEffect(() => valueSubscribe(val => {
|
|
49
|
+
setSelected(val === value);
|
|
50
|
+
}), [value]);
|
|
51
|
+
const textId = React.useId(),
|
|
52
|
+
composedRefs = useComposedRefs(forwardedRef, node => {
|
|
53
|
+
isWeb && node instanceof HTMLElement && listRef && (listRef.current[index] = node);
|
|
54
|
+
});
|
|
55
|
+
useIsomorphicLayoutEffect(() => {
|
|
56
|
+
setValueAtIndex(index, value);
|
|
57
|
+
}, [index, setValueAtIndex, value]);
|
|
58
|
+
function handleSelect() {
|
|
59
|
+
setSelectedIndex(index), onChange(value), setOpen(!1);
|
|
60
|
+
}
|
|
61
|
+
const selectItemProps = React.useMemo(() => interactions ? interactions.getItemProps({
|
|
62
|
+
onTouchMove() {
|
|
63
|
+
allowSelectRef.current = !0, allowMouseUpRef.current = !1;
|
|
64
|
+
},
|
|
65
|
+
onTouchEnd() {
|
|
66
|
+
allowSelectRef.current = !1, allowMouseUpRef.current = !0;
|
|
67
|
+
},
|
|
68
|
+
onKeyDown(event) {
|
|
69
|
+
event.key === "Enter" || event.key === " " && !dataRef?.current.typing ? (event.preventDefault(), handleSelect()) : allowSelectRef.current = !0;
|
|
70
|
+
},
|
|
71
|
+
onClick() {
|
|
72
|
+
allowSelectRef.current && handleSelect();
|
|
73
|
+
},
|
|
74
|
+
onMouseUp() {
|
|
75
|
+
allowMouseUpRef.current && (allowSelectRef.current && handleSelect(), clearTimeout(selectTimeoutRef.current), selectTimeoutRef.current = setTimeout(() => {
|
|
76
|
+
allowSelectRef.current = !0;
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
}) : {
|
|
80
|
+
onPress: handleSelect
|
|
81
|
+
}, [handleSelect]);
|
|
82
|
+
return /* @__PURE__ */jsx(SelectItemContextProvider, {
|
|
83
|
+
scope: __scopeSelect,
|
|
84
|
+
value,
|
|
85
|
+
textId: textId || "",
|
|
86
|
+
isSelected,
|
|
87
|
+
children: shouldRenderWebNative ? /* @__PURE__ */jsx("option", {
|
|
88
|
+
value,
|
|
89
|
+
children: props.children
|
|
90
|
+
}) : /* @__PURE__ */jsx(ListItemFrame, {
|
|
91
|
+
tag: "div",
|
|
92
|
+
componentName: ITEM_NAME,
|
|
93
|
+
ref: composedRefs,
|
|
94
|
+
"aria-labelledby": textId,
|
|
95
|
+
"aria-selected": isSelected,
|
|
96
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
97
|
+
"aria-disabled": disabled || void 0,
|
|
98
|
+
"data-disabled": disabled ? "" : void 0,
|
|
99
|
+
tabIndex: disabled ? void 0 : -1,
|
|
100
|
+
...(!props.unstyled && {
|
|
101
|
+
backgrounded: !0,
|
|
102
|
+
pressTheme: !0,
|
|
103
|
+
hoverTheme: !0,
|
|
104
|
+
cursor: "default",
|
|
105
|
+
size,
|
|
106
|
+
outlineOffset: -1,
|
|
107
|
+
focusStyle: {
|
|
108
|
+
outlineColor: "$outlineColor",
|
|
109
|
+
outlineWidth: 2,
|
|
110
|
+
outlineStyle: "solid",
|
|
111
|
+
outlineOffset: -2
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
...listItemProps,
|
|
115
|
+
...selectItemProps
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
}, {
|
|
119
|
+
disableTheme: !0
|
|
120
|
+
});
|
|
121
|
+
export { SelectItem, SelectItemContextProvider, useSelectItemContext };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { styled } from "@tamagui/core";
|
|
3
|
+
import { SizableText } from "@tamagui/text";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { useSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
6
|
+
import { useSelectItemContext } from "./SelectItem.mjs";
|
|
7
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
|
+
const ITEM_TEXT_NAME = "SelectItemText",
|
|
9
|
+
SelectItemTextFrame = styled(SizableText, {
|
|
10
|
+
name: ITEM_TEXT_NAME,
|
|
11
|
+
variants: {
|
|
12
|
+
unstyled: {
|
|
13
|
+
false: {
|
|
14
|
+
userSelect: "none",
|
|
15
|
+
color: "$color",
|
|
16
|
+
ellipse: !0
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
SelectItemText = SelectItemTextFrame.styleable(function (props, forwardedRef) {
|
|
25
|
+
const {
|
|
26
|
+
__scopeSelect,
|
|
27
|
+
className,
|
|
28
|
+
...itemTextProps
|
|
29
|
+
} = props,
|
|
30
|
+
context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect),
|
|
31
|
+
itemParentContext = useSelectItemParentContext(ITEM_TEXT_NAME, __scopeSelect),
|
|
32
|
+
ref = React.useRef(null),
|
|
33
|
+
composedRefs = useComposedRefs(forwardedRef, ref),
|
|
34
|
+
itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect),
|
|
35
|
+
contents = React.useRef();
|
|
36
|
+
return contents.current = /* @__PURE__ */jsx(SelectItemTextFrame, {
|
|
37
|
+
className,
|
|
38
|
+
size: itemParentContext.size,
|
|
39
|
+
id: itemContext.textId,
|
|
40
|
+
...itemTextProps,
|
|
41
|
+
ref: composedRefs
|
|
42
|
+
}), React.useEffect(() => {
|
|
43
|
+
itemParentContext.initialValue === itemContext.value && !context.selectedIndex && context.setSelectedItem(contents.current);
|
|
44
|
+
}, []), React.useEffect(() => itemParentContext.valueSubscribe(val => {
|
|
45
|
+
val === itemContext.value && context.setSelectedItem(contents.current);
|
|
46
|
+
}), [itemContext.value]), itemParentContext.shouldRenderWebNative ? /* @__PURE__ */jsx(Fragment, {
|
|
47
|
+
children: props.children
|
|
48
|
+
}) : /* @__PURE__ */jsx(Fragment, {
|
|
49
|
+
children: contents.current
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
export { ITEM_TEXT_NAME, SelectItemText, SelectItemTextFrame };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { autoUpdate, offset, useFloating } from "@floating-ui/react";
|
|
2
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
+
import { YStack } from "@tamagui/stacks";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { flushSync } from "react-dom";
|
|
6
|
+
import { useSelectContext } from "./context.mjs";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
const SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton",
|
|
9
|
+
SelectScrollUpButton = React.forwardRef((props, forwardedRef) => /* @__PURE__ */jsx(SelectScrollButtonImpl, {
|
|
10
|
+
componentName: SCROLL_UP_BUTTON_NAME,
|
|
11
|
+
...props,
|
|
12
|
+
dir: "up",
|
|
13
|
+
ref: forwardedRef
|
|
14
|
+
}));
|
|
15
|
+
SelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;
|
|
16
|
+
const SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton",
|
|
17
|
+
SelectScrollDownButton = React.forwardRef((props, forwardedRef) => /* @__PURE__ */jsx(SelectScrollButtonImpl, {
|
|
18
|
+
componentName: SCROLL_DOWN_BUTTON_NAME,
|
|
19
|
+
...props,
|
|
20
|
+
dir: "down",
|
|
21
|
+
ref: forwardedRef
|
|
22
|
+
}));
|
|
23
|
+
SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
|
|
24
|
+
const SelectScrollButtonImpl = React.memo(React.forwardRef((props, forwardedRef) => {
|
|
25
|
+
const {
|
|
26
|
+
__scopeSelect,
|
|
27
|
+
dir,
|
|
28
|
+
componentName,
|
|
29
|
+
...scrollIndicatorProps
|
|
30
|
+
} = props,
|
|
31
|
+
{
|
|
32
|
+
forceUpdate,
|
|
33
|
+
open,
|
|
34
|
+
fallback,
|
|
35
|
+
setScrollTop,
|
|
36
|
+
setInnerOffset,
|
|
37
|
+
...context
|
|
38
|
+
} = useSelectContext(componentName, __scopeSelect),
|
|
39
|
+
floatingRef = context.floatingContext?.refs.floating,
|
|
40
|
+
statusRef = React.useRef("idle"),
|
|
41
|
+
isVisible = context[dir === "down" ? "canScrollDown" : "canScrollUp"],
|
|
42
|
+
frameRef = React.useRef(),
|
|
43
|
+
{
|
|
44
|
+
x,
|
|
45
|
+
y,
|
|
46
|
+
refs,
|
|
47
|
+
strategy
|
|
48
|
+
} = useFloating({
|
|
49
|
+
open: open && isVisible,
|
|
50
|
+
strategy: "fixed",
|
|
51
|
+
elements: {
|
|
52
|
+
reference: floatingRef?.current
|
|
53
|
+
},
|
|
54
|
+
placement: dir === "up" ? "top" : "bottom",
|
|
55
|
+
middleware: [offset(({
|
|
56
|
+
rects
|
|
57
|
+
}) => -rects.floating.height)],
|
|
58
|
+
whileElementsMounted: (...args) => autoUpdate(...args, {
|
|
59
|
+
animationFrame: !0
|
|
60
|
+
})
|
|
61
|
+
}),
|
|
62
|
+
composedRef = useComposedRefs(forwardedRef, refs.setFloating);
|
|
63
|
+
if (!isVisible) return null;
|
|
64
|
+
const onScroll = amount => {
|
|
65
|
+
const floating = floatingRef;
|
|
66
|
+
floating && (fallback ? floating.current && (floating.current.scrollTop -= amount, flushSync(() => setScrollTop(floating.current?.scrollTop ?? 0))) : flushSync(() => setInnerOffset(value => value - amount)));
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */jsx(YStack, {
|
|
69
|
+
ref: composedRef,
|
|
70
|
+
componentName,
|
|
71
|
+
"aria-hidden": !0,
|
|
72
|
+
...scrollIndicatorProps,
|
|
73
|
+
zIndex: 1e3,
|
|
74
|
+
position: strategy,
|
|
75
|
+
left: x || 0,
|
|
76
|
+
top: y || 0,
|
|
77
|
+
width: `calc(${(floatingRef?.current?.offsetWidth ?? 0) - 2}px)`,
|
|
78
|
+
onPointerEnter: () => {
|
|
79
|
+
statusRef.current = "active";
|
|
80
|
+
let prevNow = Date.now();
|
|
81
|
+
function frame() {
|
|
82
|
+
const element = floatingRef?.current;
|
|
83
|
+
if (element) {
|
|
84
|
+
const currentNow = Date.now(),
|
|
85
|
+
msElapsed = currentNow - prevNow;
|
|
86
|
+
prevNow = currentNow;
|
|
87
|
+
const pixelsToScroll = msElapsed / 2,
|
|
88
|
+
remainingPixels = dir === "up" ? element.scrollTop : element.scrollHeight - element.clientHeight - element.scrollTop,
|
|
89
|
+
scrollRemaining = dir === "up" ? element.scrollTop - pixelsToScroll > 0 : element.scrollTop + pixelsToScroll < element.scrollHeight - element.clientHeight;
|
|
90
|
+
onScroll(dir === "up" ? Math.min(pixelsToScroll, remainingPixels) : Math.max(-pixelsToScroll, -remainingPixels)), scrollRemaining && (frameRef.current = requestAnimationFrame(frame));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
cancelAnimationFrame(frameRef.current), frameRef.current = requestAnimationFrame(frame);
|
|
94
|
+
},
|
|
95
|
+
onPointerLeave: () => {
|
|
96
|
+
statusRef.current = "idle", cancelAnimationFrame(frameRef.current);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}));
|
|
100
|
+
export { SelectScrollDownButton, SelectScrollUpButton };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { ListItem } from "@tamagui/list-item";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
const TRIGGER_NAME = "SelectTrigger",
|
|
7
|
+
SelectTrigger = React.forwardRef(function (props, forwardedRef) {
|
|
8
|
+
const {
|
|
9
|
+
__scopeSelect,
|
|
10
|
+
disabled = !1,
|
|
11
|
+
unstyled = !1,
|
|
12
|
+
...triggerProps
|
|
13
|
+
} = props,
|
|
14
|
+
context = useSelectContext(TRIGGER_NAME, __scopeSelect),
|
|
15
|
+
itemParentContext = useSelectItemParentContext(TRIGGER_NAME, __scopeSelect),
|
|
16
|
+
composedRefs = useComposedRefs(forwardedRef, context.floatingContext?.refs.setReference);
|
|
17
|
+
return itemParentContext.shouldRenderWebNative ? null : /* @__PURE__ */jsx(ListItem, {
|
|
18
|
+
componentName: TRIGGER_NAME,
|
|
19
|
+
unstyled,
|
|
20
|
+
...(!unstyled && {
|
|
21
|
+
backgrounded: !0,
|
|
22
|
+
radiused: !0,
|
|
23
|
+
hoverTheme: !0,
|
|
24
|
+
pressTheme: !0,
|
|
25
|
+
focusable: !0,
|
|
26
|
+
focusStyle: {
|
|
27
|
+
outlineStyle: "solid",
|
|
28
|
+
outlineWidth: 2,
|
|
29
|
+
outlineColor: "$outlineColor"
|
|
30
|
+
},
|
|
31
|
+
borderWidth: 1
|
|
32
|
+
}),
|
|
33
|
+
size: itemParentContext.size,
|
|
34
|
+
"aria-expanded": context.open,
|
|
35
|
+
"aria-autocomplete": "none",
|
|
36
|
+
dir: context.dir,
|
|
37
|
+
disabled,
|
|
38
|
+
"data-disabled": disabled ? "" : void 0,
|
|
39
|
+
...triggerProps,
|
|
40
|
+
ref: composedRefs,
|
|
41
|
+
...(itemParentContext.interactions ? {
|
|
42
|
+
...itemParentContext.interactions.getReferenceProps(),
|
|
43
|
+
onMouseDown() {
|
|
44
|
+
context.floatingContext?.update(), itemParentContext.setOpen(!context.open);
|
|
45
|
+
}
|
|
46
|
+
} : {
|
|
47
|
+
onPress() {
|
|
48
|
+
itemParentContext.setOpen(!context.open);
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
export { SelectTrigger };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { FloatingFocusManager } from "@floating-ui/react";
|
|
2
|
+
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
3
|
+
import { composeRefs } from "@tamagui/compose-refs";
|
|
4
|
+
import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
5
|
+
import { styled } from "@tamagui/core";
|
|
6
|
+
import { PortalItem } from "@tamagui/portal";
|
|
7
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
8
|
+
import { VIEWPORT_NAME } from "./constants.mjs";
|
|
9
|
+
import { ForwardSelectContext, useSelectContext, useSelectItemParentContext } from "./context.mjs";
|
|
10
|
+
import { useSelectBreakpointActive } from "./useSelectBreakpointActive.mjs";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
const SelectViewportFrame = styled(ThemeableStack, {
|
|
13
|
+
name: VIEWPORT_NAME,
|
|
14
|
+
variants: {
|
|
15
|
+
unstyled: {
|
|
16
|
+
false: {
|
|
17
|
+
size: "$2",
|
|
18
|
+
backgroundColor: "$background",
|
|
19
|
+
elevate: !0,
|
|
20
|
+
bordered: !0,
|
|
21
|
+
userSelect: "none",
|
|
22
|
+
outlineWidth: 0
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
"...size": (val, {
|
|
27
|
+
tokens
|
|
28
|
+
}) => ({
|
|
29
|
+
borderRadius: tokens.radius[val] ?? val
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
SelectViewport = SelectViewportFrame.styleable(function (props, forwardedRef) {
|
|
38
|
+
const {
|
|
39
|
+
__scopeSelect,
|
|
40
|
+
children,
|
|
41
|
+
disableScroll,
|
|
42
|
+
...viewportProps
|
|
43
|
+
} = props,
|
|
44
|
+
context = useSelectContext(VIEWPORT_NAME, __scopeSelect),
|
|
45
|
+
itemContext = useSelectItemParentContext(VIEWPORT_NAME, __scopeSelect),
|
|
46
|
+
breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
47
|
+
if (useIsomorphicLayoutEffect(() => {
|
|
48
|
+
context.update && context.update();
|
|
49
|
+
}, [breakpointActive]), itemContext.shouldRenderWebNative) return /* @__PURE__ */jsx(Fragment, {
|
|
50
|
+
children
|
|
51
|
+
});
|
|
52
|
+
if (breakpointActive || !isWeb) return /* @__PURE__ */jsx(PortalItem, {
|
|
53
|
+
hostName: `${context.scopeKey}SheetContents`,
|
|
54
|
+
children: /* @__PURE__ */jsx(ForwardSelectContext, {
|
|
55
|
+
__scopeSelect,
|
|
56
|
+
itemContext,
|
|
57
|
+
context,
|
|
58
|
+
children
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
if (!itemContext.interactions) return process.env.NODE_ENV === "development" && console.warn("No interactions provided to Select, potentially missing Adapt"), null;
|
|
62
|
+
const {
|
|
63
|
+
style,
|
|
64
|
+
// remove this, it was set to "Select" always
|
|
65
|
+
className,
|
|
66
|
+
...floatingProps
|
|
67
|
+
} = itemContext.interactions.getFloatingProps(),
|
|
68
|
+
composedRefs = composeRefs(forwardedRef, context.floatingContext?.refs.setFloating),
|
|
69
|
+
{
|
|
70
|
+
scrollbarWidth,
|
|
71
|
+
listStyleType,
|
|
72
|
+
overflow,
|
|
73
|
+
...restStyle
|
|
74
|
+
} = style;
|
|
75
|
+
return /* @__PURE__ */jsxs(Fragment, {
|
|
76
|
+
children: [!disableScroll && !props.unstyled && /* @__PURE__ */jsx("style", {
|
|
77
|
+
dangerouslySetInnerHTML: {
|
|
78
|
+
__html: selectViewportCSS
|
|
79
|
+
}
|
|
80
|
+
}), /* @__PURE__ */jsx(AnimatePresence, {
|
|
81
|
+
children: context.open ? /* @__PURE__ */jsx(FloatingFocusManager, {
|
|
82
|
+
context: context.floatingContext,
|
|
83
|
+
modal: !1,
|
|
84
|
+
children: /* @__PURE__ */jsx(SelectViewportFrame, {
|
|
85
|
+
disableClassName: !0,
|
|
86
|
+
size: itemContext.size,
|
|
87
|
+
role: "presentation",
|
|
88
|
+
...viewportProps,
|
|
89
|
+
...floatingProps,
|
|
90
|
+
...restStyle,
|
|
91
|
+
...(!props.unstyled && {
|
|
92
|
+
overflow: disableScroll ? void 0 : overflow ?? "scroll"
|
|
93
|
+
}),
|
|
94
|
+
ref: composedRefs,
|
|
95
|
+
children
|
|
96
|
+
}, "select-viewport")
|
|
97
|
+
}) : null
|
|
98
|
+
}), !context.open && /* @__PURE__ */jsx("div", {
|
|
99
|
+
style: {
|
|
100
|
+
display: "none"
|
|
101
|
+
},
|
|
102
|
+
children: props.children
|
|
103
|
+
})]
|
|
104
|
+
});
|
|
105
|
+
}),
|
|
106
|
+
selectViewportCSS = `
|
|
107
|
+
.is_SelectViewport {
|
|
108
|
+
scrollbar-width: none;
|
|
109
|
+
-webkit-overflow-scrolling: touch;
|
|
110
|
+
overscroll-behavior: contain;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.is_SelectViewport::-webkit-scrollbar{
|
|
114
|
+
display:none
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
117
|
+
export { SelectViewport, SelectViewportFrame };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const SELECT_NAME = "Select",
|
|
2
|
+
WINDOW_PADDING = 8,
|
|
3
|
+
SCROLL_ARROW_VELOCITY = 8,
|
|
4
|
+
SCROLL_ARROW_THRESHOLD = 8,
|
|
5
|
+
MIN_HEIGHT = 80,
|
|
6
|
+
FALLBACK_THRESHOLD = 16,
|
|
7
|
+
VIEWPORT_NAME = "SelectViewport";
|
|
8
|
+
export { FALLBACK_THRESHOLD, MIN_HEIGHT, SCROLL_ARROW_THRESHOLD, SCROLL_ARROW_VELOCITY, SELECT_NAME, VIEWPORT_NAME, WINDOW_PADDING };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
2
|
+
import { SELECT_NAME } from "./constants.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
const [createSelectContext, createSelectScope] = createContextScope(SELECT_NAME),
|
|
5
|
+
[SelectProvider, useSelectContext] = createSelectContext(SELECT_NAME),
|
|
6
|
+
[createSelectItemParentContext, createSelectItemParentScope] = createContextScope(SELECT_NAME),
|
|
7
|
+
[SelectItemParentProvider, useSelectItemParentContext] = createSelectContext(SELECT_NAME),
|
|
8
|
+
ForwardSelectContext = ({
|
|
9
|
+
__scopeSelect,
|
|
10
|
+
context,
|
|
11
|
+
itemContext,
|
|
12
|
+
children
|
|
13
|
+
}) => /* @__PURE__ */jsx(SelectProvider, {
|
|
14
|
+
isInSheet: !0,
|
|
15
|
+
scope: __scopeSelect,
|
|
16
|
+
...context,
|
|
17
|
+
children: /* @__PURE__ */jsx(SelectItemParentProvider, {
|
|
18
|
+
scope: __scopeSelect,
|
|
19
|
+
...itemContext,
|
|
20
|
+
children
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
export { ForwardSelectContext, SelectItemParentProvider, SelectProvider, createSelectContext, createSelectItemParentContext, createSelectItemParentScope, createSelectScope, useSelectContext, useSelectItemParentContext };
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useMedia } from "@tamagui/core";
|
|
2
|
+
const useSelectBreakpointActive = sheetBreakpoint => {
|
|
3
|
+
const media = useMedia();
|
|
4
|
+
return sheetBreakpoint ? sheetBreakpoint === !0 ? !0 : sheetBreakpoint ? media[sheetBreakpoint] : !1 : !1;
|
|
5
|
+
},
|
|
6
|
+
useShowSelectSheet = context => {
|
|
7
|
+
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
8
|
+
return context.open === !1 ? !1 : breakpointActive;
|
|
9
|
+
};
|
|
10
|
+
export { useSelectBreakpointActive, useShowSelectSheet };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/select",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -35,27 +35,27 @@
|
|
|
35
35
|
"@floating-ui/react": "^0.26.6",
|
|
36
36
|
"@floating-ui/react-dom": "^2.0.6",
|
|
37
37
|
"@floating-ui/react-native": "^0.10.3",
|
|
38
|
-
"@tamagui/adapt": "1.
|
|
39
|
-
"@tamagui/animate-presence": "1.
|
|
40
|
-
"@tamagui/compose-refs": "1.
|
|
41
|
-
"@tamagui/constants": "1.
|
|
42
|
-
"@tamagui/core": "1.
|
|
43
|
-
"@tamagui/create-context": "1.
|
|
44
|
-
"@tamagui/dismissable": "1.
|
|
45
|
-
"@tamagui/focus-scope": "1.
|
|
46
|
-
"@tamagui/get-token": "1.
|
|
47
|
-
"@tamagui/helpers": "1.
|
|
48
|
-
"@tamagui/list-item": "1.
|
|
49
|
-
"@tamagui/portal": "1.
|
|
50
|
-
"@tamagui/remove-scroll": "1.
|
|
51
|
-
"@tamagui/separator": "1.
|
|
52
|
-
"@tamagui/sheet": "1.
|
|
53
|
-
"@tamagui/stacks": "1.
|
|
54
|
-
"@tamagui/text": "1.
|
|
55
|
-
"@tamagui/use-controllable-state": "1.
|
|
56
|
-
"@tamagui/use-debounce": "1.
|
|
57
|
-
"@tamagui/use-event": "1.
|
|
58
|
-
"@tamagui/use-previous": "1.
|
|
38
|
+
"@tamagui/adapt": "1.89.0-1706308641099",
|
|
39
|
+
"@tamagui/animate-presence": "1.89.0-1706308641099",
|
|
40
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
41
|
+
"@tamagui/constants": "1.89.0-1706308641099",
|
|
42
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
43
|
+
"@tamagui/create-context": "1.89.0-1706308641099",
|
|
44
|
+
"@tamagui/dismissable": "1.89.0-1706308641099",
|
|
45
|
+
"@tamagui/focus-scope": "1.89.0-1706308641099",
|
|
46
|
+
"@tamagui/get-token": "1.89.0-1706308641099",
|
|
47
|
+
"@tamagui/helpers": "1.89.0-1706308641099",
|
|
48
|
+
"@tamagui/list-item": "1.89.0-1706308641099",
|
|
49
|
+
"@tamagui/portal": "1.89.0-1706308641099",
|
|
50
|
+
"@tamagui/remove-scroll": "1.89.0-1706308641099",
|
|
51
|
+
"@tamagui/separator": "1.89.0-1706308641099",
|
|
52
|
+
"@tamagui/sheet": "1.89.0-1706308641099",
|
|
53
|
+
"@tamagui/stacks": "1.89.0-1706308641099",
|
|
54
|
+
"@tamagui/text": "1.89.0-1706308641099",
|
|
55
|
+
"@tamagui/use-controllable-state": "1.89.0-1706308641099",
|
|
56
|
+
"@tamagui/use-debounce": "1.89.0-1706308641099",
|
|
57
|
+
"@tamagui/use-event": "1.89.0-1706308641099",
|
|
58
|
+
"@tamagui/use-previous": "1.89.0-1706308641099",
|
|
59
59
|
"react-dom": "^18.2.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"react-native": "*"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@tamagui/build": "1.
|
|
66
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
67
67
|
"react": "^18.2.0",
|
|
68
68
|
"react-native": "^0.72.6"
|
|
69
69
|
},
|