@tamagui/select 1.114.4 → 1.115.1
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/cjs/BubbleSelect.cjs +45 -0
- package/dist/cjs/Select.cjs +398 -0
- package/dist/cjs/SelectContent.cjs +82 -0
- package/dist/cjs/SelectContent.native.cjs +28 -0
- package/dist/cjs/SelectContent.native.cjs.map +6 -0
- package/dist/cjs/SelectImpl.cjs +272 -0
- package/dist/cjs/SelectImpl.native.cjs +29 -0
- package/dist/cjs/SelectImpl.native.cjs.map +6 -0
- package/dist/cjs/SelectItem.cjs +158 -0
- package/dist/cjs/SelectItemText.cjs +89 -0
- package/dist/cjs/SelectScrollButton.cjs +136 -0
- package/dist/cjs/SelectScrollButton.native.cjs +28 -0
- package/dist/cjs/SelectScrollButton.native.cjs.map +6 -0
- package/dist/cjs/SelectTrigger.cjs +99 -0
- package/dist/cjs/SelectViewport.cjs +135 -0
- package/dist/cjs/SelectViewport.native.cjs +69 -0
- package/dist/cjs/SelectViewport.native.cjs.map +6 -0
- package/dist/cjs/constants.cjs +38 -0
- package/dist/cjs/context.cjs +55 -0
- package/dist/cjs/index.cjs +19 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/useSelectBreakpointActive.cjs +35 -0
- package/package.json +25 -24
- package/dist/cjs/BubbleSelect.js +0 -34
- package/dist/cjs/Select.js +0 -328
- package/dist/cjs/SelectContent.js +0 -45
- package/dist/cjs/SelectImpl.js +0 -224
- package/dist/cjs/SelectItem.js +0 -142
- package/dist/cjs/SelectItemText.js +0 -62
- package/dist/cjs/SelectScrollButton.js +0 -105
- package/dist/cjs/SelectTrigger.js +0 -84
- package/dist/cjs/SelectViewport.js +0 -111
- package/dist/cjs/constants.js +0 -27
- package/dist/cjs/context.js +0 -35
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/types.js +0 -14
- package/dist/cjs/useSelectBreakpointActive.js +0 -29
- /package/dist/cjs/{BubbleSelect.js.map → BubbleSelect.cjs.map} +0 -0
- /package/dist/cjs/{Select.js.map → Select.cjs.map} +0 -0
- /package/dist/cjs/{SelectContent.js.map → SelectContent.cjs.map} +0 -0
- /package/dist/cjs/{SelectImpl.js.map → SelectImpl.cjs.map} +0 -0
- /package/dist/cjs/{SelectItem.js.map → SelectItem.cjs.map} +0 -0
- /package/dist/cjs/{SelectItemText.js.map → SelectItemText.cjs.map} +0 -0
- /package/dist/cjs/{SelectScrollButton.js.map → SelectScrollButton.cjs.map} +0 -0
- /package/dist/cjs/{SelectTrigger.js.map → SelectTrigger.cjs.map} +0 -0
- /package/dist/cjs/{SelectViewport.js.map → SelectViewport.cjs.map} +0 -0
- /package/dist/cjs/{constants.js.map → constants.cjs.map} +0 -0
- /package/dist/cjs/{context.js.map → context.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
- /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
- /package/dist/cjs/{useSelectBreakpointActive.js.map → useSelectBreakpointActive.cjs.map} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
15
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
16
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
17
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
18
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
19
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: !0
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
var import_compose_refs = require("@tamagui/compose-refs"),
|
|
24
|
+
import_use_previous = require("@tamagui/use-previous"),
|
|
25
|
+
React = __toESM(require("react"));
|
|
26
|
+
const BubbleSelect = React.forwardRef((props, forwardedRef) => {
|
|
27
|
+
const {
|
|
28
|
+
value,
|
|
29
|
+
...selectProps
|
|
30
|
+
} = props,
|
|
31
|
+
ref = React.useRef(null),
|
|
32
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref),
|
|
33
|
+
prevValue = (0, import_use_previous.usePrevious)(value);
|
|
34
|
+
return React.useEffect(() => {
|
|
35
|
+
const select = ref.current,
|
|
36
|
+
selectProto = window.HTMLSelectElement.prototype,
|
|
37
|
+
setValue = Object.getOwnPropertyDescriptor(selectProto, "value").set;
|
|
38
|
+
if (prevValue !== value && setValue) {
|
|
39
|
+
const event = new Event("change", {
|
|
40
|
+
bubbles: !0
|
|
41
|
+
});
|
|
42
|
+
setValue.call(select, value), select.dispatchEvent(event);
|
|
43
|
+
}
|
|
44
|
+
}, [prevValue, value]), null;
|
|
45
|
+
});
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Select_exports = {};
|
|
33
|
+
__export(Select_exports, {
|
|
34
|
+
Select: () => Select,
|
|
35
|
+
SelectGroupFrame: () => SelectGroupFrame,
|
|
36
|
+
SelectIcon: () => SelectIcon,
|
|
37
|
+
SelectSeparator: () => SelectSeparator
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(Select_exports);
|
|
40
|
+
var import_adapt = require("@tamagui/adapt"),
|
|
41
|
+
import_compose_refs = require("@tamagui/compose-refs"),
|
|
42
|
+
import_constants = require("@tamagui/constants"),
|
|
43
|
+
import_core = require("@tamagui/core"),
|
|
44
|
+
import_get_token = require("@tamagui/get-token"),
|
|
45
|
+
import_helpers = require("@tamagui/helpers"),
|
|
46
|
+
import_list_item = require("@tamagui/list-item"),
|
|
47
|
+
import_portal = require("@tamagui/portal"),
|
|
48
|
+
import_separator = require("@tamagui/separator"),
|
|
49
|
+
import_focusable = require("@tamagui/focusable"),
|
|
50
|
+
import_sheet = require("@tamagui/sheet"),
|
|
51
|
+
import_stacks = require("@tamagui/stacks"),
|
|
52
|
+
import_text = require("@tamagui/text"),
|
|
53
|
+
import_use_controllable_state = require("@tamagui/use-controllable-state"),
|
|
54
|
+
React = __toESM(require("react")),
|
|
55
|
+
import_use_debounce = require("@tamagui/use-debounce"),
|
|
56
|
+
import_constants2 = require("./constants.cjs"),
|
|
57
|
+
import_context = require("./context.cjs"),
|
|
58
|
+
import_SelectContent = require("./SelectContent.cjs"),
|
|
59
|
+
import_SelectImpl = require("./SelectImpl.cjs"),
|
|
60
|
+
import_SelectItem = require("./SelectItem.cjs"),
|
|
61
|
+
import_SelectItemText = require("./SelectItemText.cjs"),
|
|
62
|
+
import_SelectScrollButton = require("./SelectScrollButton.cjs"),
|
|
63
|
+
import_SelectTrigger = require("./SelectTrigger.cjs"),
|
|
64
|
+
import_SelectViewport = require("./SelectViewport.cjs"),
|
|
65
|
+
import_useSelectBreakpointActive = require("./useSelectBreakpointActive.cjs"),
|
|
66
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
const VALUE_NAME = "SelectValue",
|
|
68
|
+
SelectValueFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
69
|
+
name: VALUE_NAME,
|
|
70
|
+
userSelect: "none"
|
|
71
|
+
}),
|
|
72
|
+
SelectValue = SelectValueFrame.styleable(function ({
|
|
73
|
+
__scopeSelect,
|
|
74
|
+
children: childrenProp,
|
|
75
|
+
placeholder,
|
|
76
|
+
...props
|
|
77
|
+
}, forwardedRef) {
|
|
78
|
+
const context = (0, import_context.useSelectContext)(VALUE_NAME, __scopeSelect),
|
|
79
|
+
itemParentContext = (0, import_context.useSelectItemParentContext)(VALUE_NAME, __scopeSelect),
|
|
80
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.onValueNodeChange),
|
|
81
|
+
children = childrenProp ?? context.selectedItem,
|
|
82
|
+
selectValueChildren = context.value == null || context.value === "" ? placeholder ?? children : children;
|
|
83
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectValueFrame, {
|
|
84
|
+
...(!props.unstyled && {
|
|
85
|
+
size: itemParentContext.size,
|
|
86
|
+
ellipse: !0,
|
|
87
|
+
// we don't want events from the portalled `SelectValue` children to bubble
|
|
88
|
+
// through the item they came from
|
|
89
|
+
pointerEvents: "none"
|
|
90
|
+
}),
|
|
91
|
+
ref: composedRefs,
|
|
92
|
+
...props,
|
|
93
|
+
children: unwrapSelectItem(selectValueChildren)
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
function unwrapSelectItem(selectValueChildren) {
|
|
97
|
+
return React.Children.map(selectValueChildren, child => {
|
|
98
|
+
if (child) {
|
|
99
|
+
if (child.type?.staticConfig?.componentName === import_SelectItemText.ITEM_TEXT_NAME) return child.props.children;
|
|
100
|
+
if (child.props?.children) return unwrapSelectItem(child.props.children);
|
|
101
|
+
}
|
|
102
|
+
return child;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const SelectIcon = (0, import_core.styled)(import_stacks.XStack, {
|
|
106
|
+
name: "SelectIcon",
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
"aria-hidden": !0,
|
|
109
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.Paragraph, {
|
|
110
|
+
children: "\u25BC"
|
|
111
|
+
})
|
|
112
|
+
}),
|
|
113
|
+
ITEM_INDICATOR_NAME = "SelectItemIndicator",
|
|
114
|
+
SelectItemIndicatorFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
115
|
+
name: import_SelectItemText.ITEM_TEXT_NAME
|
|
116
|
+
}),
|
|
117
|
+
SelectItemIndicator = React.forwardRef((props, forwardedRef) => {
|
|
118
|
+
const {
|
|
119
|
+
__scopeSelect,
|
|
120
|
+
...itemIndicatorProps
|
|
121
|
+
} = props,
|
|
122
|
+
context = (0, import_context.useSelectItemParentContext)(ITEM_INDICATOR_NAME, __scopeSelect),
|
|
123
|
+
itemContext = (0, import_SelectItem.useSelectItemContext)(ITEM_INDICATOR_NAME, __scopeSelect);
|
|
124
|
+
return context.shouldRenderWebNative ? null : itemContext.isSelected ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectItemIndicatorFrame, {
|
|
125
|
+
"aria-hidden": !0,
|
|
126
|
+
...itemIndicatorProps,
|
|
127
|
+
ref: forwardedRef
|
|
128
|
+
}) : null;
|
|
129
|
+
});
|
|
130
|
+
SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
|
|
131
|
+
const GROUP_NAME = "SelectGroup",
|
|
132
|
+
[SelectGroupContextProvider, useSelectGroupContext] = (0, import_context.createSelectContext)(GROUP_NAME),
|
|
133
|
+
SelectGroupFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
134
|
+
name: GROUP_NAME,
|
|
135
|
+
width: "100%"
|
|
136
|
+
}),
|
|
137
|
+
NativeSelectTextFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
138
|
+
tag: "select",
|
|
139
|
+
backgroundColor: "$background",
|
|
140
|
+
borderColor: "$borderColor",
|
|
141
|
+
hoverStyle: {
|
|
142
|
+
backgroundColor: "$backgroundHover"
|
|
143
|
+
}
|
|
144
|
+
}),
|
|
145
|
+
NativeSelectFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
146
|
+
name: "NativeSelect",
|
|
147
|
+
bordered: !0,
|
|
148
|
+
userSelect: "none",
|
|
149
|
+
outlineWidth: 0,
|
|
150
|
+
paddingRight: 10,
|
|
151
|
+
variants: {
|
|
152
|
+
size: {
|
|
153
|
+
"...size": (val, extras) => {
|
|
154
|
+
const {
|
|
155
|
+
tokens
|
|
156
|
+
} = extras,
|
|
157
|
+
paddingHorizontal = (0, import_core.getVariableValue)(tokens.space[val]);
|
|
158
|
+
return {
|
|
159
|
+
borderRadius: tokens.radius[val] ?? val,
|
|
160
|
+
minHeight: tokens.size[val],
|
|
161
|
+
paddingRight: paddingHorizontal + 20,
|
|
162
|
+
paddingLeft: paddingHorizontal,
|
|
163
|
+
paddingVertical: (0, import_get_token.getSpace)(val, {
|
|
164
|
+
shift: -3
|
|
165
|
+
})
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
defaultVariants: {
|
|
171
|
+
size: "$2"
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
SelectGroup = React.forwardRef((props, forwardedRef) => {
|
|
175
|
+
const {
|
|
176
|
+
__scopeSelect,
|
|
177
|
+
...groupProps
|
|
178
|
+
} = props,
|
|
179
|
+
groupId = React.useId(),
|
|
180
|
+
context = (0, import_context.useSelectContext)(GROUP_NAME, __scopeSelect),
|
|
181
|
+
itemParentContext = (0, import_context.useSelectItemParentContext)(GROUP_NAME, __scopeSelect),
|
|
182
|
+
size = itemParentContext.size ?? "$true",
|
|
183
|
+
nativeSelectRef = React.useRef(null),
|
|
184
|
+
content = itemParentContext.shouldRenderWebNative ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeSelectFrame, {
|
|
185
|
+
asChild: !0,
|
|
186
|
+
size,
|
|
187
|
+
value: context.value,
|
|
188
|
+
id: itemParentContext.id,
|
|
189
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeSelectTextFrame, {
|
|
190
|
+
onChange: event => {
|
|
191
|
+
itemParentContext.onChange(event.currentTarget.value);
|
|
192
|
+
},
|
|
193
|
+
size,
|
|
194
|
+
ref: nativeSelectRef,
|
|
195
|
+
style: {
|
|
196
|
+
color: "var(--color)",
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
appearance: "none"
|
|
199
|
+
},
|
|
200
|
+
children: props.children
|
|
201
|
+
})
|
|
202
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectGroupFrame, {
|
|
203
|
+
role: "group",
|
|
204
|
+
"aria-labelledby": groupId,
|
|
205
|
+
...groupProps,
|
|
206
|
+
ref: forwardedRef
|
|
207
|
+
});
|
|
208
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectGroupContextProvider, {
|
|
209
|
+
scope: __scopeSelect,
|
|
210
|
+
id: groupId || "",
|
|
211
|
+
children: content
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
SelectGroup.displayName = GROUP_NAME;
|
|
215
|
+
const LABEL_NAME = "SelectLabel",
|
|
216
|
+
SelectLabel = React.forwardRef((props, forwardedRef) => {
|
|
217
|
+
const {
|
|
218
|
+
__scopeSelect,
|
|
219
|
+
...labelProps
|
|
220
|
+
} = props,
|
|
221
|
+
context = (0, import_context.useSelectItemParentContext)(LABEL_NAME, __scopeSelect),
|
|
222
|
+
groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
223
|
+
return context.shouldRenderWebNative ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_list_item.ListItem, {
|
|
224
|
+
tag: "div",
|
|
225
|
+
componentName: LABEL_NAME,
|
|
226
|
+
fontWeight: "800",
|
|
227
|
+
id: groupContext.id,
|
|
228
|
+
size: context.size,
|
|
229
|
+
...labelProps,
|
|
230
|
+
ref: forwardedRef
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
SelectLabel.displayName = LABEL_NAME;
|
|
234
|
+
const SelectSeparator = (0, import_core.styled)(import_separator.Separator, {
|
|
235
|
+
name: "SelectSeparator"
|
|
236
|
+
}),
|
|
237
|
+
SelectSheetController = props => {
|
|
238
|
+
const context = (0, import_context.useSelectContext)("SelectSheetController", props.__scopeSelect),
|
|
239
|
+
showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context),
|
|
240
|
+
breakpointActive = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(context.sheetBreakpoint),
|
|
241
|
+
getShowSheet = (0, import_core.useGet)(showSheet);
|
|
242
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_sheet.SheetController, {
|
|
243
|
+
onOpenChange: val => {
|
|
244
|
+
getShowSheet() && props.onOpenChange(val);
|
|
245
|
+
},
|
|
246
|
+
open: context.open,
|
|
247
|
+
hidden: breakpointActive === !1,
|
|
248
|
+
children: props.children
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
SelectSheetImpl = props => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
252
|
+
children: props.children
|
|
253
|
+
}),
|
|
254
|
+
Select = (0, import_helpers.withStaticProperties)(props => {
|
|
255
|
+
const {
|
|
256
|
+
__scopeSelect,
|
|
257
|
+
native,
|
|
258
|
+
children,
|
|
259
|
+
open: openProp,
|
|
260
|
+
defaultOpen,
|
|
261
|
+
onOpenChange,
|
|
262
|
+
value: valueProp,
|
|
263
|
+
defaultValue,
|
|
264
|
+
onValueChange,
|
|
265
|
+
disablePreventBodyScroll,
|
|
266
|
+
size: sizeProp = "$true",
|
|
267
|
+
onActiveChange,
|
|
268
|
+
dir,
|
|
269
|
+
id
|
|
270
|
+
} = props,
|
|
271
|
+
internalId = React.useId(),
|
|
272
|
+
scopeKey = __scopeSelect ? Object.keys(__scopeSelect)[0] ?? internalId : internalId,
|
|
273
|
+
{
|
|
274
|
+
when,
|
|
275
|
+
AdaptProvider
|
|
276
|
+
} = (0, import_adapt.useAdaptParent)({
|
|
277
|
+
Contents: React.useCallback(() => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
|
|
278
|
+
name: `${scopeKey}SheetContents`
|
|
279
|
+
}), [scopeKey])
|
|
280
|
+
}),
|
|
281
|
+
sheetBreakpoint = when,
|
|
282
|
+
SelectImpl = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(sheetBreakpoint) || !import_constants.isWeb ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl,
|
|
283
|
+
forceUpdate = React.useReducer(() => ({}), {})[1],
|
|
284
|
+
[selectedItem, setSelectedItem] = React.useState(null),
|
|
285
|
+
[open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
286
|
+
prop: openProp,
|
|
287
|
+
defaultProp: defaultOpen || !1,
|
|
288
|
+
onChange: onOpenChange
|
|
289
|
+
}),
|
|
290
|
+
[value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
291
|
+
prop: valueProp,
|
|
292
|
+
defaultProp: defaultValue || "",
|
|
293
|
+
onChange: onValueChange,
|
|
294
|
+
transition: !0
|
|
295
|
+
});
|
|
296
|
+
React.useEffect(() => {
|
|
297
|
+
open && emitValue(value);
|
|
298
|
+
}, [open]), React.useEffect(() => {
|
|
299
|
+
emitValue(value);
|
|
300
|
+
}, [value]);
|
|
301
|
+
const [activeIndex, setActiveIndex] = React.useState(0),
|
|
302
|
+
[emitValue, valueSubscribe] = useEmitter(),
|
|
303
|
+
[emitActiveIndex, activeIndexSubscribe] = useEmitter(),
|
|
304
|
+
selectedIndexRef = React.useRef(null),
|
|
305
|
+
activeIndexRef = React.useRef(null),
|
|
306
|
+
listContentRef = React.useRef([]),
|
|
307
|
+
[selectedIndex, setSelectedIndex] = React.useState(0),
|
|
308
|
+
[valueNode, setValueNode] = React.useState(null);
|
|
309
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
310
|
+
selectedIndexRef.current = selectedIndex, activeIndexRef.current = activeIndex;
|
|
311
|
+
});
|
|
312
|
+
const shouldRenderWebNative = import_constants.isWeb && (native === !0 || native === "web" || Array.isArray(native) && native.includes("web")),
|
|
313
|
+
setActiveIndexDebounced = (0, import_use_debounce.useDebounce)(index => {
|
|
314
|
+
setActiveIndex(prev => prev !== index ? (typeof index == "number" && emitActiveIndex(index), index) : prev);
|
|
315
|
+
}, 1, {}, []);
|
|
316
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AdaptProvider, {
|
|
317
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectItemParentProvider, {
|
|
318
|
+
scope: __scopeSelect,
|
|
319
|
+
initialValue: React.useMemo(() => value, [open]),
|
|
320
|
+
size: sizeProp,
|
|
321
|
+
activeIndexSubscribe,
|
|
322
|
+
valueSubscribe,
|
|
323
|
+
setOpen,
|
|
324
|
+
id,
|
|
325
|
+
onChange: React.useCallback(val => {
|
|
326
|
+
setValue(val), emitValue(val);
|
|
327
|
+
}, []),
|
|
328
|
+
onActiveChange: (0, import_core.useEvent)((...args) => {
|
|
329
|
+
onActiveChange?.(...args);
|
|
330
|
+
}),
|
|
331
|
+
setSelectedIndex,
|
|
332
|
+
setValueAtIndex: React.useCallback((index, value2) => {
|
|
333
|
+
listContentRef.current[index] = value2;
|
|
334
|
+
}, []),
|
|
335
|
+
shouldRenderWebNative,
|
|
336
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectProvider, {
|
|
337
|
+
scope: __scopeSelect,
|
|
338
|
+
disablePreventBodyScroll,
|
|
339
|
+
dir,
|
|
340
|
+
blockSelection: !1,
|
|
341
|
+
fallback: !1,
|
|
342
|
+
selectedItem,
|
|
343
|
+
setSelectedItem,
|
|
344
|
+
forceUpdate,
|
|
345
|
+
valueNode,
|
|
346
|
+
onValueNodeChange: setValueNode,
|
|
347
|
+
scopeKey,
|
|
348
|
+
sheetBreakpoint,
|
|
349
|
+
activeIndex,
|
|
350
|
+
selectedIndex,
|
|
351
|
+
setActiveIndex: setActiveIndexDebounced,
|
|
352
|
+
value,
|
|
353
|
+
open,
|
|
354
|
+
native,
|
|
355
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectSheetController, {
|
|
356
|
+
onOpenChange: setOpen,
|
|
357
|
+
__scopeSelect,
|
|
358
|
+
children: shouldRenderWebNative ? children : /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectImpl, {
|
|
359
|
+
activeIndexRef,
|
|
360
|
+
listContentRef,
|
|
361
|
+
selectedIndexRef,
|
|
362
|
+
...props,
|
|
363
|
+
open,
|
|
364
|
+
value,
|
|
365
|
+
children
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
});
|
|
371
|
+
}, {
|
|
372
|
+
Adapt: import_adapt.Adapt,
|
|
373
|
+
Content: import_SelectContent.SelectContent,
|
|
374
|
+
Group: SelectGroup,
|
|
375
|
+
Icon: SelectIcon,
|
|
376
|
+
Item: import_SelectItem.SelectItem,
|
|
377
|
+
ItemIndicator: SelectItemIndicator,
|
|
378
|
+
ItemText: import_SelectItemText.SelectItemText,
|
|
379
|
+
Label: SelectLabel,
|
|
380
|
+
ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
|
|
381
|
+
ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
|
|
382
|
+
Trigger: import_SelectTrigger.SelectTrigger,
|
|
383
|
+
Value: SelectValue,
|
|
384
|
+
Viewport: import_SelectViewport.SelectViewport,
|
|
385
|
+
Sheet: import_sheet.Sheet.Controlled
|
|
386
|
+
});
|
|
387
|
+
function useEmitter() {
|
|
388
|
+
const listeners = React.useRef();
|
|
389
|
+
listeners.current || (listeners.current = /* @__PURE__ */new Set());
|
|
390
|
+
const emit = value => {
|
|
391
|
+
listeners.current.forEach(l => l(value));
|
|
392
|
+
},
|
|
393
|
+
subscribe = React.useCallback(listener => (listeners.current.add(listener), () => {
|
|
394
|
+
listeners.current.delete(listener);
|
|
395
|
+
}), []);
|
|
396
|
+
return [emit, subscribe];
|
|
397
|
+
}
|
|
398
|
+
Select.displayName = import_constants2.SELECT_NAME;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var SelectContent_exports = {};
|
|
33
|
+
__export(SelectContent_exports, {
|
|
34
|
+
SelectContent: () => SelectContent
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(SelectContent_exports);
|
|
37
|
+
var import_react = __toESM(require("react")),
|
|
38
|
+
import_react2 = require("@floating-ui/react"),
|
|
39
|
+
import_core = require("@tamagui/core"),
|
|
40
|
+
import_focus_scope = require("@tamagui/focus-scope"),
|
|
41
|
+
import_context = require("./context.cjs"),
|
|
42
|
+
import_useSelectBreakpointActive = require("./useSelectBreakpointActive.cjs"),
|
|
43
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
const CONTENT_NAME = "SelectContent",
|
|
45
|
+
SelectContent = ({
|
|
46
|
+
children,
|
|
47
|
+
__scopeSelect,
|
|
48
|
+
zIndex = 1e3,
|
|
49
|
+
...focusScopeProps
|
|
50
|
+
}) => {
|
|
51
|
+
const context = (0, import_context.useSelectContext)(CONTENT_NAME, __scopeSelect),
|
|
52
|
+
itemParentContext = (0, import_context.useSelectItemParentContext)(CONTENT_NAME, __scopeSelect),
|
|
53
|
+
themeName = (0, import_core.useThemeName)(),
|
|
54
|
+
showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context),
|
|
55
|
+
contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
56
|
+
forceClassName: !0,
|
|
57
|
+
name: themeName,
|
|
58
|
+
children
|
|
59
|
+
}),
|
|
60
|
+
touch = (0, import_core.useIsTouchDevice)(),
|
|
61
|
+
overlayStyle = import_react.default.useMemo(() => ({
|
|
62
|
+
zIndex,
|
|
63
|
+
pointerEvents: context.open ? "auto" : "none"
|
|
64
|
+
}), [context.open]);
|
|
65
|
+
return itemParentContext.shouldRenderWebNative ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
66
|
+
children
|
|
67
|
+
}) : showSheet ? context.open ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
68
|
+
children: contents
|
|
69
|
+
}) : null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react2.FloatingPortal, {
|
|
70
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react2.FloatingOverlay, {
|
|
71
|
+
style: overlayStyle,
|
|
72
|
+
lockScroll: !context.disablePreventBodyScroll && !!context.open && !touch,
|
|
73
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
|
|
74
|
+
loop: !0,
|
|
75
|
+
enabled: !!context.open,
|
|
76
|
+
trapped: !0,
|
|
77
|
+
...focusScopeProps,
|
|
78
|
+
children: contents
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var SelectContent_native_exports = {};
|
|
22
|
+
__export(SelectContent_native_exports, {
|
|
23
|
+
SelectContent: () => SelectContent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(SelectContent_native_exports);
|
|
26
|
+
const SelectContent = ({
|
|
27
|
+
children
|
|
28
|
+
}) => children;
|