@tamagui/select 1.0.1-beta.149 → 1.0.1-beta.152
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.js +24 -19
- package/dist/cjs/BubbleSelect.js.map +1 -1
- package/dist/cjs/Select.js +342 -301
- package/dist/cjs/Select.js.map +3 -3
- package/dist/cjs/SelectContent.js +18 -15
- package/dist/cjs/SelectContent.js.map +1 -1
- package/dist/cjs/SelectContent.native.js.map +1 -1
- package/dist/cjs/SelectImpl.js +9 -4
- package/dist/cjs/SelectImpl.js.map +2 -2
- package/dist/cjs/SelectScrollButton.js +109 -95
- package/dist/cjs/SelectScrollButton.js.map +2 -2
- package/dist/cjs/SelectViewport.js +49 -35
- package/dist/cjs/SelectViewport.js.map +2 -2
- package/dist/cjs/SelectViewport.native.js +5 -7
- package/dist/cjs/SelectViewport.native.js.map +1 -1
- package/dist/cjs/context.js.map +1 -1
- package/dist/esm/BubbleSelect.js +20 -18
- package/dist/esm/BubbleSelect.js.map +1 -1
- package/dist/esm/Select.js +338 -300
- package/dist/esm/Select.js.map +3 -3
- package/dist/esm/SelectContent.js +18 -12
- package/dist/esm/SelectContent.js.map +1 -1
- package/dist/esm/SelectContent.native.js.map +1 -1
- package/dist/esm/SelectImpl.js +5 -3
- package/dist/esm/SelectImpl.js.map +2 -2
- package/dist/esm/SelectScrollButton.js +105 -94
- package/dist/esm/SelectScrollButton.js.map +2 -2
- package/dist/esm/SelectViewport.js +45 -34
- package/dist/esm/SelectViewport.js.map +1 -1
- package/dist/esm/SelectViewport.native.js +5 -4
- package/dist/esm/SelectViewport.native.js.map +1 -1
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/BubbleSelect.js +20 -18
- package/dist/jsx/BubbleSelect.js.map +1 -1
- package/dist/jsx/Select.js +217 -196
- package/dist/jsx/Select.js.map +3 -3
- package/dist/jsx/SelectContent.js.map +1 -1
- package/dist/jsx/SelectContent.native.js.map +1 -1
- package/dist/jsx/SelectImpl.js.map +2 -2
- package/dist/jsx/SelectScrollButton.js +79 -69
- package/dist/jsx/SelectScrollButton.js.map +1 -1
- package/dist/jsx/SelectViewport.js +25 -23
- package/dist/jsx/SelectViewport.js.map +1 -1
- package/dist/jsx/SelectViewport.native.js.map +1 -1
- package/dist/jsx/context.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/package.json +12 -12
- package/src/Select.tsx +1 -1
package/dist/esm/Select.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
3
|
import { isWeb, useMedia } from "@tamagui/core";
|
|
3
4
|
import { styled, useGet, useIsomorphicLayoutEffect, withStaticProperties } from "@tamagui/core";
|
|
@@ -18,211 +19,232 @@ import { SelectInlineImpl } from "./SelectImpl";
|
|
|
18
19
|
import { SelectScrollDownButton, SelectScrollUpButton } from "./SelectScrollButton";
|
|
19
20
|
import { SelectViewport } from "./SelectViewport";
|
|
20
21
|
const TRIGGER_NAME = "SelectTrigger";
|
|
21
|
-
const SelectTrigger = React.forwardRef(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
const SelectTrigger = React.forwardRef(
|
|
23
|
+
(props, forwardedRef) => {
|
|
24
|
+
const {
|
|
25
|
+
__scopeSelect,
|
|
26
|
+
disabled = false,
|
|
27
|
+
"aria-labelledby": ariaLabelledby,
|
|
28
|
+
...triggerProps
|
|
29
|
+
} = props;
|
|
30
|
+
const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
|
|
31
|
+
const labelledBy = ariaLabelledby;
|
|
32
|
+
return /* @__PURE__ */ jsx(ListItem, {
|
|
33
|
+
componentName: TRIGGER_NAME,
|
|
34
|
+
backgrounded: true,
|
|
35
|
+
radiused: true,
|
|
36
|
+
hoverTheme: true,
|
|
37
|
+
pressTheme: true,
|
|
38
|
+
focusTheme: true,
|
|
39
|
+
focusable: true,
|
|
40
|
+
borderWidth: 1,
|
|
41
|
+
size: context.size,
|
|
42
|
+
"aria-expanded": context.open,
|
|
43
|
+
"aria-autocomplete": "none",
|
|
44
|
+
"aria-labelledby": labelledBy,
|
|
45
|
+
dir: context.dir,
|
|
46
|
+
disabled,
|
|
47
|
+
"data-disabled": disabled ? "" : void 0,
|
|
48
|
+
...triggerProps,
|
|
49
|
+
ref: forwardedRef,
|
|
50
|
+
...process.env.TAMAGUI_TARGET === "web" && context.interactions ? context.interactions.getReferenceProps() : {
|
|
51
|
+
onPress() {
|
|
52
|
+
context.setOpen(!context.open);
|
|
53
|
+
}
|
|
51
54
|
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
);
|
|
55
58
|
SelectTrigger.displayName = TRIGGER_NAME;
|
|
56
59
|
const VALUE_NAME = "SelectValue";
|
|
57
60
|
const SelectValueFrame = styled(Paragraph, {
|
|
58
61
|
name: VALUE_NAME,
|
|
59
62
|
selectable: false
|
|
60
63
|
});
|
|
61
|
-
const SelectValue = SelectValueFrame.extractable(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
const SelectValue = SelectValueFrame.extractable(
|
|
65
|
+
React.forwardRef(
|
|
66
|
+
({ __scopeSelect, children: childrenProp, placeholder }, forwardedRef) => {
|
|
67
|
+
const context = useSelectContext(VALUE_NAME, __scopeSelect);
|
|
68
|
+
const { onValueNodeHasChildrenChange } = context;
|
|
69
|
+
const hasChildren = childrenProp !== void 0;
|
|
70
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
|
|
71
|
+
useIsomorphicLayoutEffect(() => {
|
|
72
|
+
onValueNodeHasChildrenChange(hasChildren);
|
|
73
|
+
}, [onValueNodeHasChildrenChange, hasChildren]);
|
|
74
|
+
const children = childrenProp ?? context.selectedItem;
|
|
75
|
+
return /* @__PURE__ */ jsx(SelectValueFrame, {
|
|
76
|
+
size: context.size,
|
|
77
|
+
ref: composedRefs,
|
|
78
|
+
pointerEvents: "none",
|
|
79
|
+
children: context.value === void 0 && placeholder !== void 0 ? placeholder : children
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
);
|
|
76
84
|
SelectValue.displayName = VALUE_NAME;
|
|
77
85
|
const SelectIcon = styled(XStack, {
|
|
78
86
|
name: "SelectIcon",
|
|
79
87
|
"aria-hidden": true,
|
|
80
|
-
children: /* @__PURE__ */
|
|
88
|
+
children: /* @__PURE__ */ jsx(Paragraph, {
|
|
89
|
+
children: "\u25BC"
|
|
90
|
+
})
|
|
81
91
|
});
|
|
82
92
|
const ITEM_NAME = "SelectItem";
|
|
83
93
|
const [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
|
|
84
|
-
const SelectItem = React.forwardRef(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
listRef
|
|
94
|
+
const SelectItem = React.forwardRef(
|
|
95
|
+
(props, forwardedRef) => {
|
|
96
|
+
const {
|
|
97
|
+
__scopeSelect,
|
|
98
|
+
value,
|
|
99
|
+
disabled = false,
|
|
100
|
+
textValue: textValueProp,
|
|
101
|
+
index,
|
|
102
|
+
...itemProps
|
|
103
|
+
} = props;
|
|
104
|
+
const context = useSelectContext(ITEM_NAME, __scopeSelect);
|
|
105
|
+
const isSelected = context.value === value;
|
|
106
|
+
const textId = useId();
|
|
107
|
+
const {
|
|
108
|
+
selectedIndex,
|
|
109
|
+
setSelectedIndex,
|
|
110
|
+
listRef,
|
|
111
|
+
open,
|
|
112
|
+
setOpen,
|
|
113
|
+
onChange,
|
|
114
|
+
setActiveIndex,
|
|
115
|
+
allowMouseUpRef,
|
|
116
|
+
allowSelectRef,
|
|
117
|
+
setValueAtIndex,
|
|
118
|
+
selectTimeoutRef,
|
|
119
|
+
dataRef
|
|
120
|
+
} = context;
|
|
121
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => {
|
|
122
|
+
if (!isWeb)
|
|
123
|
+
return;
|
|
124
|
+
if (node instanceof HTMLElement) {
|
|
125
|
+
if (listRef) {
|
|
126
|
+
listRef.current[index] = node;
|
|
127
|
+
}
|
|
116
128
|
}
|
|
129
|
+
});
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
setValueAtIndex(index, value);
|
|
132
|
+
}, [index, setValueAtIndex, value]);
|
|
133
|
+
function handleSelect() {
|
|
134
|
+
setSelectedIndex(index);
|
|
135
|
+
onChange(value);
|
|
136
|
+
setOpen(false);
|
|
117
137
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
setValueAtIndex(index, value);
|
|
121
|
-
}, [index, setValueAtIndex, value]);
|
|
122
|
-
function handleSelect() {
|
|
123
|
-
setSelectedIndex(index);
|
|
124
|
-
onChange(value);
|
|
125
|
-
setOpen(false);
|
|
126
|
-
}
|
|
127
|
-
const selectItemProps = context.interactions ? context.interactions.getItemProps({
|
|
128
|
-
onTouchStart() {
|
|
129
|
-
allowSelectRef.current = true;
|
|
130
|
-
allowMouseUpRef.current = false;
|
|
131
|
-
},
|
|
132
|
-
onKeyDown(event) {
|
|
133
|
-
if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
handleSelect();
|
|
136
|
-
} else {
|
|
138
|
+
const selectItemProps = context.interactions ? context.interactions.getItemProps({
|
|
139
|
+
onTouchStart() {
|
|
137
140
|
allowSelectRef.current = true;
|
|
141
|
+
allowMouseUpRef.current = false;
|
|
142
|
+
},
|
|
143
|
+
onKeyDown(event) {
|
|
144
|
+
if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
handleSelect();
|
|
147
|
+
} else {
|
|
148
|
+
allowSelectRef.current = true;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
onClick() {
|
|
152
|
+
if (allowSelectRef.current) {
|
|
153
|
+
setSelectedIndex(index);
|
|
154
|
+
setOpen(false);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
onMouseUp() {
|
|
158
|
+
if (!allowMouseUpRef.current) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (allowSelectRef.current) {
|
|
162
|
+
handleSelect();
|
|
163
|
+
}
|
|
164
|
+
clearTimeout(selectTimeoutRef.current);
|
|
165
|
+
selectTimeoutRef.current = setTimeout(() => {
|
|
166
|
+
allowSelectRef.current = true;
|
|
167
|
+
});
|
|
138
168
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}, /* @__PURE__ */ React.createElement(ListItem, {
|
|
167
|
-
backgrounded: true,
|
|
168
|
-
pressTheme: true,
|
|
169
|
-
focusTheme: true,
|
|
170
|
-
componentName: ITEM_NAME,
|
|
171
|
-
ref: composedRefs,
|
|
172
|
-
"aria-labelledby": textId,
|
|
173
|
-
"aria-selected": isSelected,
|
|
174
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
175
|
-
"aria-disabled": disabled || void 0,
|
|
176
|
-
"data-disabled": disabled ? "" : void 0,
|
|
177
|
-
tabIndex: disabled ? void 0 : -1,
|
|
178
|
-
size: context.size,
|
|
179
|
-
...itemProps,
|
|
180
|
-
...selectItemProps
|
|
181
|
-
}));
|
|
182
|
-
});
|
|
169
|
+
}) : {
|
|
170
|
+
onPress: handleSelect
|
|
171
|
+
};
|
|
172
|
+
return /* @__PURE__ */ jsx(SelectItemContextProvider, {
|
|
173
|
+
scope: __scopeSelect,
|
|
174
|
+
value,
|
|
175
|
+
textId: textId || "",
|
|
176
|
+
isSelected,
|
|
177
|
+
children: /* @__PURE__ */ jsx(ListItem, {
|
|
178
|
+
backgrounded: true,
|
|
179
|
+
pressTheme: true,
|
|
180
|
+
focusTheme: true,
|
|
181
|
+
componentName: ITEM_NAME,
|
|
182
|
+
ref: composedRefs,
|
|
183
|
+
"aria-labelledby": textId,
|
|
184
|
+
"aria-selected": isSelected,
|
|
185
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
186
|
+
"aria-disabled": disabled || void 0,
|
|
187
|
+
"data-disabled": disabled ? "" : void 0,
|
|
188
|
+
tabIndex: disabled ? void 0 : -1,
|
|
189
|
+
size: context.size,
|
|
190
|
+
...itemProps,
|
|
191
|
+
...selectItemProps
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
);
|
|
183
196
|
SelectItem.displayName = ITEM_NAME;
|
|
184
197
|
const ITEM_TEXT_NAME = "SelectItemText";
|
|
185
198
|
const SelectItemTextFrame = styled(Paragraph, {
|
|
186
199
|
name: ITEM_TEXT_NAME,
|
|
187
200
|
selectable: false
|
|
188
201
|
});
|
|
189
|
-
const SelectItemText = React.forwardRef(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
const SelectItemText = React.forwardRef(
|
|
203
|
+
(props, forwardedRef) => {
|
|
204
|
+
const { __scopeSelect, className, ...itemTextProps } = props;
|
|
205
|
+
const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
206
|
+
const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
207
|
+
const ref = React.useRef(null);
|
|
208
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
209
|
+
const isSelected = itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren;
|
|
210
|
+
const contents = /* @__PURE__ */ jsx(SelectItemTextFrame, {
|
|
211
|
+
className,
|
|
212
|
+
size: context.size,
|
|
213
|
+
id: itemContext.textId,
|
|
214
|
+
...itemTextProps,
|
|
215
|
+
ref: composedRefs
|
|
216
|
+
});
|
|
217
|
+
if (!isWeb) {
|
|
218
|
+
React.useEffect(() => {
|
|
219
|
+
if (isSelected) {
|
|
220
|
+
context.setSelectedItem(contents);
|
|
221
|
+
}
|
|
222
|
+
}, [isSelected]);
|
|
223
|
+
}
|
|
224
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
225
|
+
children: [
|
|
226
|
+
contents,
|
|
227
|
+
isWeb && isSelected ? ReactDOM.createPortal(itemTextProps.children, context.valueNode) : null
|
|
228
|
+
]
|
|
229
|
+
});
|
|
209
230
|
}
|
|
210
|
-
|
|
211
|
-
});
|
|
231
|
+
);
|
|
212
232
|
SelectItemText.displayName = ITEM_TEXT_NAME;
|
|
213
233
|
const ITEM_INDICATOR_NAME = "SelectItemIndicator";
|
|
214
234
|
const SelectItemIndicatorFrame = styled(XStack, {
|
|
215
235
|
name: ITEM_TEXT_NAME
|
|
216
236
|
});
|
|
217
|
-
const SelectItemIndicator = React.forwardRef(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
237
|
+
const SelectItemIndicator = React.forwardRef(
|
|
238
|
+
(props, forwardedRef) => {
|
|
239
|
+
const { __scopeSelect, ...itemIndicatorProps } = props;
|
|
240
|
+
const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
|
|
241
|
+
return itemContext.isSelected ? /* @__PURE__ */ jsx(SelectItemIndicatorFrame, {
|
|
242
|
+
"aria-hidden": true,
|
|
243
|
+
...itemIndicatorProps,
|
|
244
|
+
ref: forwardedRef
|
|
245
|
+
}) : null;
|
|
246
|
+
}
|
|
247
|
+
);
|
|
226
248
|
SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
|
|
227
249
|
const GROUP_NAME = "SelectGroup";
|
|
228
250
|
const [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
|
|
@@ -230,34 +252,39 @@ const SelectGroupFrame = styled(YStack, {
|
|
|
230
252
|
name: GROUP_NAME,
|
|
231
253
|
width: "100%"
|
|
232
254
|
});
|
|
233
|
-
const SelectGroup = React.forwardRef(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
})
|
|
255
|
+
const SelectGroup = React.forwardRef(
|
|
256
|
+
(props, forwardedRef) => {
|
|
257
|
+
const { __scopeSelect, ...groupProps } = props;
|
|
258
|
+
const groupId = useId();
|
|
259
|
+
return /* @__PURE__ */ jsx(SelectGroupContextProvider, {
|
|
260
|
+
scope: __scopeSelect,
|
|
261
|
+
id: groupId || "",
|
|
262
|
+
children: /* @__PURE__ */ jsx(SelectGroupFrame, {
|
|
263
|
+
role: "group",
|
|
264
|
+
"aria-labelledby": groupId,
|
|
265
|
+
...groupProps,
|
|
266
|
+
ref: forwardedRef
|
|
267
|
+
})
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
);
|
|
246
271
|
SelectGroup.displayName = GROUP_NAME;
|
|
247
272
|
const LABEL_NAME = "SelectLabel";
|
|
248
|
-
const SelectLabel = React.forwardRef(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
273
|
+
const SelectLabel = React.forwardRef(
|
|
274
|
+
(props, forwardedRef) => {
|
|
275
|
+
const { __scopeSelect, ...labelProps } = props;
|
|
276
|
+
const context = useSelectContext(LABEL_NAME, __scopeSelect);
|
|
277
|
+
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
278
|
+
return /* @__PURE__ */ jsx(ListItem, {
|
|
279
|
+
componentName: LABEL_NAME,
|
|
280
|
+
fontWeight: "800",
|
|
281
|
+
id: groupContext.id,
|
|
282
|
+
size: context.size,
|
|
283
|
+
...labelProps,
|
|
284
|
+
ref: forwardedRef
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
);
|
|
261
288
|
SelectLabel.displayName = LABEL_NAME;
|
|
262
289
|
const SelectSeparator = styled(Separator, {
|
|
263
290
|
name: "SelectSeparator"
|
|
@@ -275,121 +302,132 @@ const SelectSheetController = (props) => {
|
|
|
275
302
|
const showSheet = useShowSelectSheet(context);
|
|
276
303
|
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
|
|
277
304
|
const getShowSheet = useGet(showSheet);
|
|
278
|
-
return /* @__PURE__ */
|
|
305
|
+
return /* @__PURE__ */ jsx(SheetController, {
|
|
279
306
|
onChangeOpen: (val) => {
|
|
280
307
|
if (getShowSheet()) {
|
|
281
308
|
props.onChangeOpen(val);
|
|
282
309
|
}
|
|
283
310
|
},
|
|
284
311
|
open: context.open,
|
|
285
|
-
hidden: breakpointActive === false
|
|
286
|
-
|
|
312
|
+
hidden: breakpointActive === false,
|
|
313
|
+
children: props.children
|
|
314
|
+
});
|
|
287
315
|
};
|
|
288
316
|
const SHEET_CONTENTS_NAME = "SelectSheetContents";
|
|
289
317
|
const SelectSheetContents = ({ __scopeSelect }) => {
|
|
290
318
|
const context = useSelectContext(SHEET_CONTENTS_NAME, __scopeSelect);
|
|
291
|
-
return /* @__PURE__ */
|
|
319
|
+
return /* @__PURE__ */ jsx(PortalHost, {
|
|
292
320
|
name: `${context.scopeKey}SheetContents`
|
|
293
321
|
});
|
|
294
322
|
};
|
|
295
323
|
SelectSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
296
324
|
const SelectSheetImpl = (props) => {
|
|
297
|
-
return /* @__PURE__ */
|
|
298
|
-
|
|
299
|
-
const Select = withStaticProperties((props) => {
|
|
300
|
-
const {
|
|
301
|
-
__scopeSelect,
|
|
302
|
-
children,
|
|
303
|
-
open: openProp,
|
|
304
|
-
defaultOpen,
|
|
305
|
-
onOpenChange,
|
|
306
|
-
value: valueProp,
|
|
307
|
-
defaultValue,
|
|
308
|
-
onValueChange,
|
|
309
|
-
size: sizeProp = "$4",
|
|
310
|
-
sheetBreakpoint = false,
|
|
311
|
-
dir
|
|
312
|
-
} = props;
|
|
313
|
-
const isSheet = useSelectBreakpointActive(sheetBreakpoint);
|
|
314
|
-
const SelectImpl = isSheet ? SelectSheetImpl : SelectInlineImpl;
|
|
315
|
-
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
316
|
-
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
317
|
-
const [open, setOpen] = useControllableState({
|
|
318
|
-
prop: openProp,
|
|
319
|
-
defaultProp: defaultOpen || false,
|
|
320
|
-
onChange: onOpenChange,
|
|
321
|
-
strategy: "most-recent-wins"
|
|
322
|
-
});
|
|
323
|
-
const [value, setValue] = useControllableState({
|
|
324
|
-
prop: valueProp,
|
|
325
|
-
defaultProp: defaultValue || "",
|
|
326
|
-
onChange: onValueChange,
|
|
327
|
-
strategy: "most-recent-wins"
|
|
325
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
326
|
+
children: props.children
|
|
328
327
|
});
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
forceUpdate,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
setActiveIndex
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
328
|
+
};
|
|
329
|
+
const Select = withStaticProperties(
|
|
330
|
+
(props) => {
|
|
331
|
+
const {
|
|
332
|
+
__scopeSelect,
|
|
333
|
+
children,
|
|
334
|
+
open: openProp,
|
|
335
|
+
defaultOpen,
|
|
336
|
+
onOpenChange,
|
|
337
|
+
value: valueProp,
|
|
338
|
+
defaultValue,
|
|
339
|
+
onValueChange,
|
|
340
|
+
size: sizeProp = "$4",
|
|
341
|
+
sheetBreakpoint = false,
|
|
342
|
+
dir
|
|
343
|
+
} = props;
|
|
344
|
+
const isSheet = useSelectBreakpointActive(sheetBreakpoint);
|
|
345
|
+
const SelectImpl = isSheet ? SelectSheetImpl : SelectInlineImpl;
|
|
346
|
+
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
347
|
+
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
348
|
+
const [open, setOpen] = useControllableState({
|
|
349
|
+
prop: openProp,
|
|
350
|
+
defaultProp: defaultOpen || false,
|
|
351
|
+
onChange: onOpenChange,
|
|
352
|
+
strategy: "most-recent-wins"
|
|
353
|
+
});
|
|
354
|
+
const [value, setValue] = useControllableState({
|
|
355
|
+
prop: valueProp,
|
|
356
|
+
defaultProp: defaultValue || "",
|
|
357
|
+
onChange: onValueChange,
|
|
358
|
+
strategy: "most-recent-wins"
|
|
359
|
+
});
|
|
360
|
+
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
361
|
+
const selectedIndexRef = React.useRef(null);
|
|
362
|
+
const activeIndexRef = React.useRef(null);
|
|
363
|
+
const listContentRef = React.useRef([]);
|
|
364
|
+
const [selectedIndex, setSelectedIndex] = React.useState(
|
|
365
|
+
Math.max(0, listContentRef.current.indexOf(value))
|
|
366
|
+
);
|
|
367
|
+
const [valueNode, setValueNode] = React.useState(null);
|
|
368
|
+
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
|
|
369
|
+
useIsomorphicLayoutEffect(() => {
|
|
370
|
+
selectedIndexRef.current = selectedIndex;
|
|
371
|
+
activeIndexRef.current = activeIndex;
|
|
372
|
+
});
|
|
373
|
+
return /* @__PURE__ */ jsx(SelectProvider, {
|
|
374
|
+
dir,
|
|
375
|
+
blockSelection: false,
|
|
376
|
+
size: sizeProp,
|
|
377
|
+
fallback: false,
|
|
378
|
+
selectedItem,
|
|
379
|
+
setSelectedItem,
|
|
380
|
+
forceUpdate,
|
|
381
|
+
valueNode,
|
|
382
|
+
onValueNodeChange: setValueNode,
|
|
383
|
+
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
384
|
+
valueNodeHasChildren,
|
|
385
|
+
scopeKey: __scopeSelect ? Object.keys(__scopeSelect)[0] : "",
|
|
386
|
+
sheetBreakpoint,
|
|
387
|
+
scope: __scopeSelect,
|
|
388
|
+
setValueAtIndex: (index, value2) => {
|
|
389
|
+
listContentRef.current[index] = value2;
|
|
390
|
+
},
|
|
391
|
+
activeIndex,
|
|
392
|
+
onChange: setValue,
|
|
393
|
+
selectedIndex,
|
|
394
|
+
setActiveIndex,
|
|
395
|
+
setOpen,
|
|
396
|
+
setSelectedIndex,
|
|
397
|
+
value,
|
|
398
|
+
open,
|
|
399
|
+
children: /* @__PURE__ */ jsx(SelectSheetController, {
|
|
400
|
+
onChangeOpen: setOpen,
|
|
401
|
+
__scopeSelect,
|
|
402
|
+
children: /* @__PURE__ */ jsx(SelectImpl, {
|
|
403
|
+
activeIndexRef,
|
|
404
|
+
listContentRef,
|
|
405
|
+
selectedIndexRef,
|
|
406
|
+
...props,
|
|
407
|
+
open,
|
|
408
|
+
value,
|
|
409
|
+
children
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
});
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
Content: SelectContent,
|
|
416
|
+
Group: SelectGroup,
|
|
417
|
+
Icon: SelectIcon,
|
|
418
|
+
Item: SelectItem,
|
|
419
|
+
ItemIndicator: SelectItemIndicator,
|
|
420
|
+
ItemText: SelectItemText,
|
|
421
|
+
Label: SelectLabel,
|
|
422
|
+
ScrollDownButton: SelectScrollDownButton,
|
|
423
|
+
ScrollUpButton: SelectScrollUpButton,
|
|
424
|
+
Trigger: SelectTrigger,
|
|
425
|
+
Value: SelectValue,
|
|
426
|
+
Viewport: SelectViewport,
|
|
427
|
+
SheetContents: SelectSheetContents,
|
|
428
|
+
Sheet
|
|
429
|
+
}
|
|
430
|
+
);
|
|
393
431
|
Select.displayName = SELECT_NAME;
|
|
394
432
|
export {
|
|
395
433
|
Select,
|