@tamagui/select 1.0.1-beta.99 → 1.0.1-rc.0

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.
Files changed (114) hide show
  1. package/dist/cjs/BubbleSelect.js +25 -33
  2. package/dist/cjs/BubbleSelect.js.map +1 -1
  3. package/dist/cjs/Select.js +391 -789
  4. package/dist/cjs/Select.js.map +3 -3
  5. package/dist/cjs/SelectContent.js +72 -0
  6. package/dist/cjs/SelectContent.js.map +7 -0
  7. package/dist/cjs/SelectContent.native.js +31 -0
  8. package/dist/cjs/SelectContent.native.js.map +7 -0
  9. package/dist/cjs/SelectImpl.js +288 -0
  10. package/dist/cjs/SelectImpl.js.map +7 -0
  11. package/dist/cjs/SelectScrollButton.js +157 -0
  12. package/dist/cjs/SelectScrollButton.js.map +7 -0
  13. package/dist/cjs/SelectScrollButton.native.js +32 -0
  14. package/dist/cjs/SelectScrollButton.native.js.map +7 -0
  15. package/dist/cjs/SelectViewport.js +125 -0
  16. package/dist/cjs/SelectViewport.js.map +7 -0
  17. package/dist/cjs/SelectViewport.native.js +41 -0
  18. package/dist/cjs/SelectViewport.native.js.map +7 -0
  19. package/dist/cjs/constants.js +47 -0
  20. package/dist/cjs/constants.js.map +7 -0
  21. package/dist/cjs/context.js +49 -0
  22. package/dist/cjs/context.js.map +7 -0
  23. package/dist/cjs/index.js +2 -0
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/types.js +17 -0
  26. package/dist/cjs/types.js.map +7 -0
  27. package/dist/cjs/useSelectBreakpointActive.js +39 -0
  28. package/dist/cjs/useSelectBreakpointActive.js.map +7 -0
  29. package/dist/esm/BubbleSelect.js +20 -33
  30. package/dist/esm/BubbleSelect.js.map +1 -1
  31. package/dist/esm/Select.js +379 -803
  32. package/dist/esm/Select.js.map +3 -3
  33. package/dist/esm/SelectContent.js +48 -0
  34. package/dist/esm/SelectContent.js.map +7 -0
  35. package/dist/esm/SelectContent.native.js +7 -0
  36. package/dist/esm/SelectContent.native.js.map +7 -0
  37. package/dist/esm/SelectImpl.js +273 -0
  38. package/dist/esm/SelectImpl.js.map +7 -0
  39. package/dist/esm/SelectScrollButton.js +126 -0
  40. package/dist/esm/SelectScrollButton.js.map +7 -0
  41. package/dist/esm/SelectScrollButton.native.js +7 -0
  42. package/dist/esm/SelectScrollButton.native.js.map +7 -0
  43. package/dist/esm/SelectViewport.js +94 -0
  44. package/dist/esm/SelectViewport.js.map +7 -0
  45. package/dist/esm/SelectViewport.native.js +17 -0
  46. package/dist/esm/SelectViewport.native.js.map +7 -0
  47. package/dist/esm/constants.js +17 -0
  48. package/dist/esm/constants.js.map +7 -0
  49. package/dist/esm/context.js +21 -0
  50. package/dist/esm/context.js.map +7 -0
  51. package/dist/esm/index.js +1 -0
  52. package/dist/esm/index.js.map +2 -2
  53. package/dist/esm/types.js +1 -0
  54. package/dist/esm/types.js.map +7 -0
  55. package/dist/esm/useSelectBreakpointActive.js +14 -0
  56. package/dist/esm/useSelectBreakpointActive.js.map +7 -0
  57. package/dist/jsx/BubbleSelect.js +20 -18
  58. package/dist/jsx/BubbleSelect.js.map +1 -1
  59. package/dist/jsx/Select.js +259 -656
  60. package/dist/jsx/Select.js.map +3 -3
  61. package/dist/jsx/SelectContent.js +27 -0
  62. package/dist/jsx/SelectContent.js.map +7 -0
  63. package/dist/jsx/SelectContent.native.js +7 -0
  64. package/dist/jsx/SelectContent.native.js.map +7 -0
  65. package/dist/jsx/SelectImpl.js +246 -0
  66. package/dist/jsx/SelectImpl.js.map +7 -0
  67. package/dist/jsx/SelectScrollButton.js +99 -0
  68. package/dist/jsx/SelectScrollButton.js.map +7 -0
  69. package/dist/jsx/SelectScrollButton.native.js +7 -0
  70. package/dist/jsx/SelectScrollButton.native.js.map +7 -0
  71. package/dist/jsx/SelectViewport.js +72 -0
  72. package/dist/jsx/SelectViewport.js.map +7 -0
  73. package/dist/jsx/SelectViewport.native.js +13 -0
  74. package/dist/jsx/SelectViewport.native.js.map +7 -0
  75. package/dist/jsx/constants.js +17 -0
  76. package/dist/jsx/constants.js.map +7 -0
  77. package/dist/jsx/context.js +15 -0
  78. package/dist/jsx/context.js.map +7 -0
  79. package/dist/jsx/index.js +1 -0
  80. package/dist/jsx/index.js.map +2 -2
  81. package/dist/jsx/types.js +1 -0
  82. package/dist/jsx/types.js.map +7 -0
  83. package/dist/jsx/useSelectBreakpointActive.js +14 -0
  84. package/dist/jsx/useSelectBreakpointActive.js.map +7 -0
  85. package/package.json +26 -20
  86. package/src/Select.tsx +210 -906
  87. package/src/SelectContent.native.tsx +5 -0
  88. package/src/SelectContent.tsx +45 -0
  89. package/src/SelectImpl.tsx +344 -0
  90. package/src/SelectScrollButton.native.tsx +7 -0
  91. package/src/SelectScrollButton.tsx +168 -0
  92. package/src/SelectViewport.native.tsx +14 -0
  93. package/src/SelectViewport.tsx +104 -0
  94. package/src/constants.tsx +7 -0
  95. package/src/context.tsx +19 -0
  96. package/src/index.tsx +7 -0
  97. package/src/types.tsx +91 -0
  98. package/src/useSelectBreakpointActive.tsx +15 -0
  99. package/types/BubbleSelect.d.ts +2 -0
  100. package/types/Select.d.ts +449 -599
  101. package/types/SelectContent.d.ts +5 -0
  102. package/types/SelectContent.native.d.ts +4 -0
  103. package/types/SelectImpl.d.ts +9 -0
  104. package/types/SelectScrollButton.d.ts +6 -0
  105. package/types/SelectScrollButton.native.d.ts +4 -0
  106. package/types/SelectViewport.d.ts +127 -0
  107. package/types/SelectViewport.native.d.ts +7 -0
  108. package/types/constants.d.ts +8 -0
  109. package/types/context.d.ts +21 -0
  110. package/types/index.d.ts +2 -0
  111. package/types/types.d.ts +81 -0
  112. package/types/useSelectBreakpointActive.d.ts +4 -0
  113. package/types/Select.d.ts.map +0 -1
  114. package/types/index.d.ts.map +0 -1
@@ -1,326 +1,251 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- import {
33
- FloatingFocusManager,
34
- FloatingOverlay,
35
- FloatingPortal,
36
- autoUpdate,
37
- detectOverflow,
38
- flip,
39
- offset,
40
- size,
41
- useClick,
42
- useDismiss,
43
- useFloating,
44
- useInteractions,
45
- useListNavigation,
46
- useRole,
47
- useTypeahead
48
- } from "@floating-ui/react-dom-interactions";
49
- import { usePrevious } from "@radix-ui/react-use-previous";
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { Adapt, useAdaptParent } from "@tamagui/adapt";
50
3
  import { useComposedRefs } from "@tamagui/compose-refs";
51
- import {
52
- Theme,
53
- styled,
54
- useIsomorphicLayoutEffect,
55
- useThemeName,
56
- withStaticProperties
57
- } from "@tamagui/core";
4
+ import { isWeb } from "@tamagui/core";
5
+ import { styled, useGet, useIsomorphicLayoutEffect, withStaticProperties } from "@tamagui/core";
58
6
  import { useId } from "@tamagui/core";
59
- import { createContextScope } from "@tamagui/create-context";
60
7
  import { ListItem } from "@tamagui/list-item";
8
+ import { PortalHost } from "@tamagui/portal";
61
9
  import { Separator } from "@tamagui/separator";
62
- import { ThemeableStack, XStack, YStack } from "@tamagui/stacks";
63
- import { Paragraph } from "@tamagui/text";
10
+ import { ControlledSheet, SheetController } from "@tamagui/sheet";
11
+ import { XStack, YStack } from "@tamagui/stacks";
12
+ import { Paragraph, SizableText } from "@tamagui/text";
64
13
  import { useControllableState } from "@tamagui/use-controllable-state";
65
14
  import * as React from "react";
66
- import * as ReactDOM from "react-dom";
67
- const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
68
- const isFirefox = userAgent.toLowerCase().includes("firefox");
69
- if (isFirefox) {
70
- document.body.classList.add("firefox");
71
- }
72
- function getVisualOffsetTop() {
73
- return !/^((?!chrome|android).)*safari/i.test(userAgent) ? (visualViewport == null ? void 0 : visualViewport.offsetTop) ?? 0 : 0;
74
- }
75
- const SELECT_NAME = "Select";
76
- const WINDOW_PADDING = 8;
77
- const SCROLL_ARROW_VELOCITY = 8;
78
- const SCROLL_ARROW_THRESHOLD = 8;
79
- const MIN_HEIGHT = 80;
80
- const FALLBACK_THRESHOLD = 16;
81
- const [createSelectContext, createSelectScope] = createContextScope(SELECT_NAME);
82
- const [SelectProvider, useSelectContext] = createSelectContext(SELECT_NAME);
15
+ import { SELECT_NAME } from "./constants";
16
+ import { SelectProvider, createSelectContext, useSelectContext } from "./context";
17
+ import { SelectContent } from "./SelectContent";
18
+ import { SelectInlineImpl } from "./SelectImpl";
19
+ import { SelectScrollDownButton, SelectScrollUpButton } from "./SelectScrollButton";
20
+ import { SelectViewport } from "./SelectViewport";
21
+ import { useSelectBreakpointActive, useShowSelectSheet } from "./useSelectBreakpointActive";
83
22
  const TRIGGER_NAME = "SelectTrigger";
84
- const SelectTrigger = React.forwardRef((props, forwardedRef) => {
85
- const _a = props, {
86
- __scopeSelect,
87
- disabled = false,
88
- "aria-labelledby": ariaLabelledby
89
- } = _a, triggerProps = __objRest(_a, [
90
- "__scopeSelect",
91
- "disabled",
92
- "aria-labelledby"
93
- ]);
94
- const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
95
- return /* @__PURE__ */ React.createElement(ListItem, __spreadValues(__spreadProps(__spreadValues({
96
- backgrounded: true,
97
- radiused: true,
98
- hoverTheme: true,
99
- pressTheme: true,
100
- focusTheme: true,
101
- focusable: false,
102
- borderWidth: 1,
103
- componentName: TRIGGER_NAME,
104
- size: context.size,
105
- "aria-expanded": context.open,
106
- "aria-autocomplete": "none",
107
- disabled,
108
- "data-disabled": disabled ? "" : void 0
109
- }, triggerProps), {
110
- ref: forwardedRef
111
- }), context.interactions.getReferenceProps()));
112
- });
23
+ const SelectTrigger = React.forwardRef(
24
+ (props, forwardedRef) => {
25
+ const {
26
+ __scopeSelect,
27
+ disabled = false,
28
+ "aria-labelledby": ariaLabelledby,
29
+ ...triggerProps
30
+ } = props;
31
+ const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
32
+ const labelledBy = ariaLabelledby;
33
+ return /* @__PURE__ */ jsx(ListItem, {
34
+ componentName: TRIGGER_NAME,
35
+ backgrounded: true,
36
+ radiused: true,
37
+ hoverTheme: true,
38
+ pressTheme: true,
39
+ focusTheme: true,
40
+ focusable: true,
41
+ borderWidth: 1,
42
+ size: context.size,
43
+ "aria-expanded": context.open,
44
+ "aria-autocomplete": "none",
45
+ "aria-labelledby": labelledBy,
46
+ dir: context.dir,
47
+ disabled,
48
+ "data-disabled": disabled ? "" : void 0,
49
+ ...triggerProps,
50
+ ref: forwardedRef,
51
+ ...process.env.TAMAGUI_TARGET === "web" && context.interactions ? context.interactions.getReferenceProps() : {
52
+ onPress() {
53
+ context.setOpen(!context.open);
54
+ }
55
+ }
56
+ });
57
+ }
58
+ );
113
59
  SelectTrigger.displayName = TRIGGER_NAME;
114
60
  const VALUE_NAME = "SelectValue";
115
61
  const SelectValueFrame = styled(Paragraph, {
116
62
  name: VALUE_NAME,
117
63
  selectable: false
118
64
  });
119
- const SelectValue = SelectValueFrame.extractable(React.forwardRef(({ __scopeSelect, children, placeholder }, forwardedRef) => {
120
- const context = useSelectContext(VALUE_NAME, __scopeSelect);
121
- const { onValueNodeHasChildrenChange } = context;
122
- const hasChildren = children !== void 0;
123
- const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
124
- React.useLayoutEffect(() => {
125
- onValueNodeHasChildrenChange(hasChildren);
126
- }, [onValueNodeHasChildrenChange, hasChildren]);
127
- return /* @__PURE__ */ React.createElement(SelectValueFrame, {
128
- size: context.size,
129
- ref: composedRefs,
130
- pointerEvents: "none"
131
- }, context.value === void 0 && placeholder !== void 0 ? placeholder : children);
132
- }));
65
+ const SelectValue = SelectValueFrame.extractable(
66
+ React.forwardRef(
67
+ ({ __scopeSelect, children: childrenProp, placeholder }, forwardedRef) => {
68
+ const context = useSelectContext(VALUE_NAME, __scopeSelect);
69
+ const { onValueNodeHasChildrenChange } = context;
70
+ const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
71
+ const children = childrenProp ?? context.selectedItem;
72
+ const hasChildren = !!children;
73
+ const selectValueChildren = context.value === void 0 && placeholder !== void 0 ? placeholder : children;
74
+ useIsomorphicLayoutEffect(() => {
75
+ onValueNodeHasChildrenChange(hasChildren);
76
+ }, [onValueNodeHasChildrenChange, hasChildren]);
77
+ return /* @__PURE__ */ jsx(SelectValueFrame, {
78
+ size: context.size,
79
+ ref: composedRefs,
80
+ pointerEvents: "none",
81
+ children: selectValueChildren
82
+ });
83
+ }
84
+ )
85
+ );
133
86
  SelectValue.displayName = VALUE_NAME;
134
87
  const SelectIcon = styled(XStack, {
135
88
  name: "SelectIcon",
136
89
  "aria-hidden": true,
137
- children: /* @__PURE__ */ React.createElement(Paragraph, null, "\u25BC")
138
- });
139
- const CONTENT_NAME = "SelectContent";
140
- const SelectContent = ({ children, __scopeSelect }) => {
141
- const context = useSelectContext(CONTENT_NAME, __scopeSelect);
142
- const themeName = useThemeName();
143
- const contents = /* @__PURE__ */ React.createElement(Theme, {
144
- name: themeName
145
- }, children);
146
- return /* @__PURE__ */ React.createElement(FloatingPortal, null, context.open ? /* @__PURE__ */ React.createElement(FloatingOverlay, {
147
- lockScroll: true
148
- }, contents) : /* @__PURE__ */ React.createElement("div", {
149
- style: { display: "none" }
150
- }, contents));
151
- };
152
- const VIEWPORT_NAME = "SelectViewport";
153
- const SelectViewportFrame = styled(ThemeableStack, {
154
- name: VIEWPORT_NAME,
155
- backgroundColor: "$background",
156
- elevate: true,
157
- bordered: true,
158
- overflow: "scroll",
159
- userSelect: "none",
160
- variants: {
161
- size: {
162
- "...size": (val, { tokens }) => {
163
- return {
164
- borderRadius: tokens.radius[val] ?? val
165
- };
166
- }
167
- }
168
- },
169
- defaultVariants: {
170
- size: "$2"
171
- }
172
- });
173
- const SelectViewport = React.forwardRef((props, forwardedRef) => {
174
- const _a = props, { __scopeSelect, children } = _a, viewportProps = __objRest(_a, ["__scopeSelect", "children"]);
175
- const context = useSelectContext(VIEWPORT_NAME, __scopeSelect);
176
- const _b = context.interactions.getFloatingProps(), { style } = _b, floatingProps = __objRest(_b, ["style"]);
177
- delete style["scrollbarWidth"];
178
- delete style["listStyleType"];
179
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("style", {
180
- dangerouslySetInnerHTML: {
181
- __html: `[data-tamagui-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-tamagui-select-viewport]::-webkit-scrollbar{display:none}`
182
- }
183
- }), /* @__PURE__ */ React.createElement(FloatingFocusManager, {
184
- context: context.floatingContext,
185
- preventTabbing: true
186
- }, /* @__PURE__ */ React.createElement(SelectViewportFrame, __spreadValues(__spreadValues(__spreadProps(__spreadValues({
187
- size: context.size,
188
- "data-tamagui-select-viewport": "",
189
- role: "presentation"
190
- }, viewportProps), {
191
- ref: forwardedRef
192
- }), floatingProps), style), children)));
90
+ children: /* @__PURE__ */ jsx(Paragraph, {
91
+ children: "\u25BC"
92
+ })
193
93
  });
194
- SelectViewport.displayName = VIEWPORT_NAME;
195
94
  const ITEM_NAME = "SelectItem";
196
95
  const [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
197
- const SelectItem = React.forwardRef((props, forwardedRef) => {
198
- const _a = props, {
199
- __scopeSelect,
200
- value,
201
- disabled = false,
202
- textValue: textValueProp,
203
- index
204
- } = _a, itemProps = __objRest(_a, [
205
- "__scopeSelect",
206
- "value",
207
- "disabled",
208
- "textValue",
209
- "index"
210
- ]);
211
- const context = useSelectContext(ITEM_NAME, __scopeSelect);
212
- const isSelected = context.value === value;
213
- const [textValue, setTextValue] = React.useState(textValueProp ?? "");
214
- const [isFocused, setIsFocused] = React.useState(false);
215
- const textId = useId();
216
- const {
217
- selectedIndex,
218
- setSelectedIndex,
219
- listRef,
220
- open,
221
- setOpen,
222
- onChange,
223
- activeIndex,
224
- setActiveIndex,
225
- setValueAtIndex,
226
- dataRef
227
- } = context;
228
- const composedRefs = useComposedRefs(forwardedRef, (node) => {
229
- if (node instanceof HTMLElement) {
230
- listRef.current[index] = node;
231
- }
232
- });
233
- React.useEffect(() => {
234
- setValueAtIndex(index, value);
235
- }, [index]);
236
- const timeoutRef = React.useRef();
237
- const [allowMouseUp, setAllowMouseUp] = React.useState(false);
238
- function handleSelect() {
239
- setSelectedIndex(index);
240
- onChange(value);
241
- setOpen(false);
242
- }
243
- React.useLayoutEffect(() => {
244
- clearTimeout(timeoutRef.current);
245
- if (open) {
246
- if (selectedIndex !== index) {
247
- setAllowMouseUp(true);
248
- } else {
249
- timeoutRef.current = setTimeout(() => {
250
- setAllowMouseUp(true);
251
- }, 300);
96
+ const SelectItem = React.forwardRef(
97
+ (props, forwardedRef) => {
98
+ const {
99
+ __scopeSelect,
100
+ value,
101
+ disabled = false,
102
+ textValue: textValueProp,
103
+ index,
104
+ ...itemProps
105
+ } = props;
106
+ const context = useSelectContext(ITEM_NAME, __scopeSelect);
107
+ const isSelected = context.value === value;
108
+ const textId = useId();
109
+ const {
110
+ selectedIndex,
111
+ setSelectedIndex,
112
+ listRef,
113
+ open,
114
+ setOpen,
115
+ onChange,
116
+ setActiveIndex,
117
+ allowMouseUpRef,
118
+ allowSelectRef,
119
+ setValueAtIndex,
120
+ selectTimeoutRef,
121
+ dataRef
122
+ } = context;
123
+ const composedRefs = useComposedRefs(forwardedRef, (node) => {
124
+ if (!isWeb)
125
+ return;
126
+ if (node instanceof HTMLElement) {
127
+ if (listRef) {
128
+ listRef.current[index] = node;
129
+ }
252
130
  }
253
- } else {
254
- setAllowMouseUp(false);
255
- }
256
- }, [open, index, setActiveIndex, selectedIndex]);
257
- function handleKeyDown(event) {
258
- if (event.key === "Enter" || event.key === " " && !dataRef.current.typing) {
259
- event.preventDefault();
260
- handleSelect();
131
+ });
132
+ React.useEffect(() => {
133
+ setValueAtIndex(index, value);
134
+ }, [index, setValueAtIndex, value]);
135
+ function handleSelect() {
136
+ setSelectedIndex(index);
137
+ onChange(value);
138
+ setOpen(false);
261
139
  }
140
+ const selectItemProps = context.interactions ? context.interactions.getItemProps({
141
+ onTouchStart() {
142
+ allowSelectRef.current = true;
143
+ allowMouseUpRef.current = false;
144
+ },
145
+ onKeyDown(event) {
146
+ if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
147
+ event.preventDefault();
148
+ handleSelect();
149
+ } else {
150
+ allowSelectRef.current = true;
151
+ }
152
+ },
153
+ onClick() {
154
+ if (allowSelectRef.current) {
155
+ setSelectedIndex(index);
156
+ setOpen(false);
157
+ }
158
+ },
159
+ onMouseUp() {
160
+ if (!allowMouseUpRef.current) {
161
+ return;
162
+ }
163
+ if (allowSelectRef.current) {
164
+ handleSelect();
165
+ }
166
+ clearTimeout(selectTimeoutRef.current);
167
+ selectTimeoutRef.current = setTimeout(() => {
168
+ allowSelectRef.current = true;
169
+ });
170
+ }
171
+ }) : {
172
+ onPress: handleSelect
173
+ };
174
+ return /* @__PURE__ */ jsx(SelectItemContextProvider, {
175
+ scope: __scopeSelect,
176
+ value,
177
+ textId: textId || "",
178
+ isSelected,
179
+ children: /* @__PURE__ */ jsx(ListItem, {
180
+ backgrounded: true,
181
+ pressTheme: true,
182
+ cursor: "",
183
+ focusTheme: true,
184
+ componentName: ITEM_NAME,
185
+ ref: composedRefs,
186
+ "aria-labelledby": textId,
187
+ "aria-selected": isSelected,
188
+ "data-state": isSelected ? "active" : "inactive",
189
+ "aria-disabled": disabled || void 0,
190
+ "data-disabled": disabled ? "" : void 0,
191
+ tabIndex: disabled ? void 0 : -1,
192
+ size: context.size,
193
+ ...itemProps,
194
+ ...selectItemProps
195
+ })
196
+ });
262
197
  }
263
- const selectItemProps = context.interactions.getItemProps({
264
- onClick: allowMouseUp ? handleSelect : void 0,
265
- onMouseUp: allowMouseUp ? handleSelect : void 0,
266
- onKeyDown: handleKeyDown
267
- });
268
- return /* @__PURE__ */ React.createElement(SelectItemContextProvider, {
269
- scope: __scopeSelect,
270
- value,
271
- textId: textId || "",
272
- isSelected,
273
- onItemTextChange: React.useCallback((node) => {
274
- setTextValue((prevTextValue) => prevTextValue || ((node == null ? void 0 : node.textContent) ?? "").trim());
275
- }, [])
276
- }, /* @__PURE__ */ React.createElement(ListItem, __spreadValues(__spreadValues({
277
- backgrounded: true,
278
- pressTheme: true,
279
- focusTheme: true,
280
- componentName: ITEM_NAME,
281
- ref: composedRefs,
282
- "aria-labelledby": textId,
283
- "aria-selected": isSelected && isFocused,
284
- "data-state": isSelected ? "active" : "inactive",
285
- "aria-disabled": disabled || void 0,
286
- "data-disabled": disabled ? "" : void 0,
287
- tabIndex: disabled ? void 0 : -1,
288
- size: context.size
289
- }, itemProps), selectItemProps)));
290
- });
198
+ );
291
199
  SelectItem.displayName = ITEM_NAME;
292
200
  const ITEM_TEXT_NAME = "SelectItemText";
293
- const SelectItemTextFrame = styled(Paragraph, {
201
+ const SelectItemTextFrame = styled(SizableText, {
294
202
  name: ITEM_TEXT_NAME,
295
203
  selectable: false
296
204
  });
297
- const SelectItemText = React.forwardRef((props, forwardedRef) => {
298
- const _a = props, { __scopeSelect, className, style } = _a, itemTextProps = __objRest(_a, ["__scopeSelect", "className", "style"]);
299
- const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
300
- const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
301
- const ref = React.useRef(null);
302
- const composedRefs = useComposedRefs(forwardedRef, ref, itemContext.onItemTextChange);
303
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SelectItemTextFrame, __spreadProps(__spreadValues({
304
- size: context.size,
305
- id: itemContext.textId
306
- }, itemTextProps), {
307
- ref: composedRefs
308
- })), itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? ReactDOM.createPortal(itemTextProps.children, context.valueNode) : null);
309
- });
205
+ const SelectItemText = React.forwardRef(
206
+ (props, forwardedRef) => {
207
+ const { __scopeSelect, className, ...itemTextProps } = props;
208
+ const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
209
+ const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
210
+ const ref = React.useRef(null);
211
+ const composedRefs = useComposedRefs(forwardedRef, ref);
212
+ const isSelected = Boolean(itemContext.isSelected && context.valueNode);
213
+ const contents = React.useMemo(
214
+ () => /* @__PURE__ */ jsx(SelectItemTextFrame, {
215
+ className,
216
+ size: context.size,
217
+ id: itemContext.textId,
218
+ ...itemTextProps,
219
+ ref: composedRefs
220
+ }),
221
+ [props, context.size, className, itemContext.textId]
222
+ );
223
+ React.useEffect(() => {
224
+ if (isSelected) {
225
+ context.setSelectedItem(contents);
226
+ }
227
+ }, [isSelected, contents]);
228
+ return /* @__PURE__ */ jsx(Fragment, {
229
+ children: contents
230
+ });
231
+ }
232
+ );
310
233
  SelectItemText.displayName = ITEM_TEXT_NAME;
311
234
  const ITEM_INDICATOR_NAME = "SelectItemIndicator";
312
235
  const SelectItemIndicatorFrame = styled(XStack, {
313
236
  name: ITEM_TEXT_NAME
314
237
  });
315
- const SelectItemIndicator = React.forwardRef((props, forwardedRef) => {
316
- const _a = props, { __scopeSelect } = _a, itemIndicatorProps = __objRest(_a, ["__scopeSelect"]);
317
- const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
318
- return itemContext.isSelected ? /* @__PURE__ */ React.createElement(SelectItemIndicatorFrame, __spreadProps(__spreadValues({
319
- "aria-hidden": true
320
- }, itemIndicatorProps), {
321
- ref: forwardedRef
322
- })) : null;
323
- });
238
+ const SelectItemIndicator = React.forwardRef(
239
+ (props, forwardedRef) => {
240
+ const { __scopeSelect, ...itemIndicatorProps } = props;
241
+ const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
242
+ return itemContext.isSelected ? /* @__PURE__ */ jsx(SelectItemIndicatorFrame, {
243
+ "aria-hidden": true,
244
+ ...itemIndicatorProps,
245
+ ref: forwardedRef
246
+ }) : null;
247
+ }
248
+ );
324
249
  SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
325
250
  const GROUP_NAME = "SelectGroup";
326
251
  const [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
@@ -328,529 +253,182 @@ const SelectGroupFrame = styled(YStack, {
328
253
  name: GROUP_NAME,
329
254
  width: "100%"
330
255
  });
331
- const SelectGroup = React.forwardRef((props, forwardedRef) => {
332
- const _a = props, { __scopeSelect } = _a, groupProps = __objRest(_a, ["__scopeSelect"]);
333
- const groupId = useId();
334
- return /* @__PURE__ */ React.createElement(SelectGroupContextProvider, {
335
- scope: __scopeSelect,
336
- id: groupId || ""
337
- }, /* @__PURE__ */ React.createElement(SelectGroupFrame, __spreadProps(__spreadValues({
338
- role: "group",
339
- "aria-labelledby": groupId
340
- }, groupProps), {
341
- ref: forwardedRef
342
- })));
343
- });
256
+ const SelectGroup = React.forwardRef(
257
+ (props, forwardedRef) => {
258
+ const { __scopeSelect, ...groupProps } = props;
259
+ const groupId = useId();
260
+ return /* @__PURE__ */ jsx(SelectGroupContextProvider, {
261
+ scope: __scopeSelect,
262
+ id: groupId || "",
263
+ children: /* @__PURE__ */ jsx(SelectGroupFrame, {
264
+ role: "group",
265
+ "aria-labelledby": groupId,
266
+ ...groupProps,
267
+ ref: forwardedRef
268
+ })
269
+ });
270
+ }
271
+ );
344
272
  SelectGroup.displayName = GROUP_NAME;
345
273
  const LABEL_NAME = "SelectLabel";
346
- const SelectLabel = React.forwardRef((props, forwardedRef) => {
347
- const _a = props, { __scopeSelect } = _a, labelProps = __objRest(_a, ["__scopeSelect"]);
348
- const context = useSelectContext(LABEL_NAME, __scopeSelect);
349
- const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
350
- return /* @__PURE__ */ React.createElement(ListItem, __spreadProps(__spreadValues({
351
- componentName: LABEL_NAME,
352
- fontWeight: "800",
353
- id: groupContext.id,
354
- size: context.size
355
- }, labelProps), {
356
- ref: forwardedRef
357
- }));
358
- });
359
- SelectLabel.displayName = LABEL_NAME;
360
- const SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton";
361
- const SelectScrollUpButton = React.forwardRef((props, forwardedRef) => {
362
- return /* @__PURE__ */ React.createElement(SelectScrollButtonImpl, __spreadProps(__spreadValues({
363
- componentName: SCROLL_UP_BUTTON_NAME
364
- }, props), {
365
- dir: "up",
366
- ref: forwardedRef
367
- }));
368
- });
369
- SelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;
370
- const SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton";
371
- const SelectScrollDownButton = React.forwardRef((props, forwardedRef) => {
372
- return /* @__PURE__ */ React.createElement(SelectScrollButtonImpl, __spreadProps(__spreadValues({
373
- componentName: SCROLL_DOWN_BUTTON_NAME
374
- }, props), {
375
- dir: "down",
376
- ref: forwardedRef
377
- }));
378
- });
379
- SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
380
- const SelectScrollButtonImpl = React.forwardRef((props, forwardedRef) => {
381
- var _c;
382
- const _a = props, { __scopeSelect, dir, componentName } = _a, scrollIndicatorProps = __objRest(_a, ["__scopeSelect", "dir", "componentName"]);
383
- const _b = useSelectContext(componentName, __scopeSelect), { floatingRef, increaseHeight, forceUpdate } = _b, context = __objRest(_b, ["floatingRef", "increaseHeight", "forceUpdate"]);
384
- const intervalRef = React.useRef();
385
- const loopingRef = React.useRef(false);
386
- const isVisible = context[dir === "down" ? "canScrollDown" : "canScrollUp"];
387
- const { x, y, reference, floating, strategy, update, refs } = useFloating({
388
- strategy: "fixed",
389
- placement: dir === "up" ? "top" : "bottom",
390
- middleware: [offset(({ rects }) => -rects.floating.height)]
391
- });
392
- const composedRefs = useComposedRefs(forwardedRef, floating);
393
- React.useLayoutEffect(() => {
394
- reference(floatingRef.current);
395
- }, [reference, floatingRef.current]);
396
- React.useEffect(() => {
397
- if (!refs.reference.current || !refs.floating.current || !isVisible) {
398
- return;
399
- }
400
- const cleanup = autoUpdate(refs.reference.current, refs.floating.current, update, {
401
- animationFrame: true
274
+ const SelectLabel = React.forwardRef(
275
+ (props, forwardedRef) => {
276
+ const { __scopeSelect, ...labelProps } = props;
277
+ const context = useSelectContext(LABEL_NAME, __scopeSelect);
278
+ const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
279
+ return /* @__PURE__ */ jsx(ListItem, {
280
+ componentName: LABEL_NAME,
281
+ fontWeight: "800",
282
+ id: groupContext.id,
283
+ size: context.size,
284
+ ...labelProps,
285
+ ref: forwardedRef
402
286
  });
403
- return () => {
404
- clearInterval(intervalRef.current);
405
- loopingRef.current = false;
406
- cleanup();
407
- };
408
- }, [isVisible, update, refs.floating, refs.reference]);
409
- if (!isVisible) {
410
- return null;
411
287
  }
412
- const handleScrollArrowChange = () => {
413
- const floating2 = floatingRef.current;
414
- const isUp = dir === "up";
415
- if (floating2) {
416
- const value = isUp ? -SCROLL_ARROW_VELOCITY : SCROLL_ARROW_VELOCITY;
417
- const multi = isUp && floating2.scrollTop <= SCROLL_ARROW_THRESHOLD * 2 || !isUp && floating2.scrollTop >= floating2.scrollHeight - floating2.clientHeight - SCROLL_ARROW_THRESHOLD * 2 ? 2 : 1;
418
- floating2.scrollTop += multi * (isUp ? -SCROLL_ARROW_VELOCITY : SCROLL_ARROW_VELOCITY);
419
- increaseHeight(floating2, multi === 2 ? value * 2 : value);
420
- forceUpdate();
421
- }
422
- };
423
- return /* @__PURE__ */ React.createElement(YStack, __spreadProps(__spreadValues({
424
- ref: composedRefs,
425
- componentName,
426
- "aria-hidden": true
427
- }, scrollIndicatorProps), {
428
- zIndex: 1e3,
429
- position: strategy,
430
- left: x || 0,
431
- top: y || 0,
432
- width: `calc(${(((_c = floatingRef.current) == null ? void 0 : _c.offsetWidth) ?? 0) - 2}px)`,
433
- onPointerMove: () => {
434
- if (!loopingRef.current) {
435
- intervalRef.current = setInterval(handleScrollArrowChange, 1e3 / 60);
436
- loopingRef.current = true;
437
- }
438
- },
439
- onPointerLeave: () => {
440
- loopingRef.current = false;
441
- clearInterval(intervalRef.current);
442
- }
443
- }));
444
- });
288
+ );
289
+ SelectLabel.displayName = LABEL_NAME;
445
290
  const SelectSeparator = styled(Separator, {
446
291
  name: "SelectSeparator"
447
292
  });
448
- const Select = withStaticProperties((props) => {
449
- const {
450
- id,
451
- __scopeSelect,
452
- children,
453
- open: openProp,
454
- defaultOpen,
455
- onOpenChange,
456
- value: valueProp,
457
- defaultValue,
458
- onValueChange,
459
- size: sizeProp,
460
- dir,
461
- name,
462
- autoComplete
463
- } = props;
464
- const [open, setOpen] = useControllableState({
465
- prop: openProp,
466
- defaultProp: defaultOpen || false,
467
- onChange: onOpenChange
293
+ const SelectSheetController = (props) => {
294
+ const context = useSelectContext("SelectSheetController", props.__scopeSelect);
295
+ const showSheet = useShowSelectSheet(context);
296
+ const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
297
+ const getShowSheet = useGet(showSheet);
298
+ return /* @__PURE__ */ jsx(SheetController, {
299
+ onOpenChange: (val) => {
300
+ if (getShowSheet()) {
301
+ props.onOpenChange(val);
302
+ }
303
+ },
304
+ open: context.open,
305
+ hidden: breakpointActive === false,
306
+ children: props.children
468
307
  });
469
- const [value, setValue] = useControllableState({
470
- prop: valueProp,
471
- defaultProp: defaultValue || "",
472
- onChange: onValueChange
308
+ };
309
+ const SHEET_CONTENTS_NAME = "SelectSheetContents";
310
+ const SelectSheetContents = ({ __scopeSelect }) => {
311
+ const context = useSelectContext(SHEET_CONTENTS_NAME, __scopeSelect);
312
+ return /* @__PURE__ */ jsx(PortalHost, {
313
+ name: `${context.scopeKey}SheetContents`
473
314
  });
474
- const [activeIndex, setActiveIndex] = React.useState(null);
475
- const selectedIndexRef = React.useRef(null);
476
- const activeIndexRef = React.useRef(null);
477
- const prevActiveIndex = usePrevious(activeIndex);
478
- const [showArrows, setShowArrows] = React.useState(false);
479
- const [scrollTop, setScrollTop] = React.useState(0);
480
- const listItemsRef = React.useRef([]);
481
- const listContentRef = React.useRef([]);
482
- const [selectedIndex, setSelectedIndex] = React.useState(Math.max(0, listContentRef.current.indexOf(value)));
483
- const [controlledScrolling, setControlledScrolling] = React.useState(false);
484
- const [middlewareType, setMiddlewareType] = React.useState("align");
485
- useIsomorphicLayoutEffect(() => {
486
- selectedIndexRef.current = selectedIndex;
487
- activeIndexRef.current = activeIndex;
315
+ };
316
+ SelectSheetContents.displayName = SHEET_CONTENTS_NAME;
317
+ const SelectSheetImpl = (props) => {
318
+ return /* @__PURE__ */ jsx(Fragment, {
319
+ children: props.children
488
320
  });
489
- React.useEffect(() => {
490
- const frame = requestAnimationFrame(() => {
491
- setShowArrows(open);
492
- if (!open) {
493
- setScrollTop(0);
494
- setMiddlewareType("align");
495
- setActiveIndex(null);
496
- setControlledScrolling(false);
497
- }
321
+ };
322
+ const Select = withStaticProperties(
323
+ (props) => {
324
+ const {
325
+ __scopeSelect,
326
+ children,
327
+ open: openProp,
328
+ defaultOpen,
329
+ onOpenChange,
330
+ value: valueProp,
331
+ defaultValue,
332
+ onValueChange,
333
+ size: sizeProp = "$4",
334
+ dir
335
+ } = props;
336
+ const { when, AdaptProvider } = useAdaptParent({
337
+ Contents: SelectSheetContents
498
338
  });
499
- return () => {
500
- cancelAnimationFrame(frame);
501
- };
502
- }, [open]);
503
- function getFloatingPadding(floating2) {
504
- var _a;
505
- if (!floating2) {
506
- return 0;
507
- }
508
- return Number((_a = getComputedStyle(floating2).paddingLeft) == null ? void 0 : _a.replace("px", ""));
509
- }
510
- const { x, y, reference, floating, strategy, context, refs, middlewareData, update } = useFloating({
511
- open,
512
- onOpenChange: setOpen,
513
- placement: "bottom",
514
- middleware: middlewareType === "align" ? [
515
- offset(({ rects }) => {
516
- const index = activeIndexRef.current ?? selectedIndexRef.current;
517
- if (index == null) {
518
- return 0;
519
- }
520
- const item = listItemsRef.current[index];
521
- if (item == null) {
522
- return 0;
523
- }
524
- const offsetTop = item.offsetTop;
525
- const itemHeight = item.offsetHeight;
526
- const height = rects.reference.height;
527
- return -offsetTop - height - (itemHeight - height) / 2;
528
- }),
529
- {
530
- name: "size",
531
- async fn(args) {
532
- var _a;
533
- const {
534
- elements: { floating: floating2 },
535
- rects: { reference: reference2 },
536
- middlewareData: middlewareData2
537
- } = args;
538
- const overflow = await detectOverflow(args, {
539
- padding: WINDOW_PADDING
540
- });
541
- const top = Math.max(0, overflow.top);
542
- const bottom = Math.max(0, overflow.bottom);
543
- const nextY = args.y + top;
544
- if ((_a = middlewareData2.size) == null ? void 0 : _a.skip) {
545
- return {
546
- y: nextY,
547
- data: {
548
- y: middlewareData2.size.y
549
- }
550
- };
551
- }
552
- Object.assign(floating2.style, {
553
- maxHeight: `${floating2.scrollHeight - Math.abs(top + bottom)}px`,
554
- minWidth: `${reference2.width + getFloatingPadding(floating2) * 2}px`
555
- });
556
- return {
557
- y: nextY,
558
- data: {
559
- y: top,
560
- skip: true
561
- },
562
- reset: {
563
- rects: true
564
- }
565
- };
566
- }
567
- }
568
- ] : [
569
- offset(5),
570
- flip(),
571
- size({
572
- apply({ rects, availableHeight, elements }) {
573
- Object.assign(elements.floating.style, {
574
- width: `${rects.reference.width}px`,
575
- maxHeight: `${availableHeight}px`
576
- });
339
+ const sheetBreakpoint = when || false;
340
+ const isSheet = useSelectBreakpointActive(sheetBreakpoint);
341
+ const SelectImpl = isSheet ? SelectSheetImpl : SelectInlineImpl;
342
+ const forceUpdate = React.useReducer(() => ({}), {})[1];
343
+ const [selectedItem, setSelectedItem] = React.useState(null);
344
+ const [open, setOpen] = useControllableState({
345
+ prop: openProp,
346
+ defaultProp: defaultOpen || false,
347
+ onChange: onOpenChange,
348
+ strategy: "most-recent-wins"
349
+ });
350
+ const [value, setValue] = useControllableState({
351
+ prop: valueProp,
352
+ defaultProp: defaultValue || "",
353
+ onChange: onValueChange,
354
+ strategy: "most-recent-wins"
355
+ });
356
+ const [activeIndex, setActiveIndex] = React.useState(null);
357
+ const selectedIndexRef = React.useRef(null);
358
+ const activeIndexRef = React.useRef(null);
359
+ const listContentRef = React.useRef([]);
360
+ const [selectedIndex, setSelectedIndex] = React.useState(
361
+ Math.max(0, listContentRef.current.indexOf(value))
362
+ );
363
+ const [valueNode, setValueNode] = React.useState(null);
364
+ const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
365
+ useIsomorphicLayoutEffect(() => {
366
+ selectedIndexRef.current = selectedIndex;
367
+ activeIndexRef.current = activeIndex;
368
+ });
369
+ const id = useId();
370
+ const scopeKey = __scopeSelect ? Object.keys(__scopeSelect)[0] ?? id : id;
371
+ return /* @__PURE__ */ jsx(AdaptProvider, {
372
+ children: /* @__PURE__ */ jsx(SelectProvider, {
373
+ dir,
374
+ blockSelection: false,
375
+ size: sizeProp,
376
+ fallback: false,
377
+ selectedItem,
378
+ setSelectedItem,
379
+ forceUpdate,
380
+ valueNode,
381
+ onValueNodeChange: setValueNode,
382
+ onValueNodeHasChildrenChange: setValueNodeHasChildren,
383
+ valueNodeHasChildren,
384
+ scopeKey,
385
+ sheetBreakpoint,
386
+ scope: __scopeSelect,
387
+ setValueAtIndex: (index, value2) => {
388
+ listContentRef.current[index] = value2;
577
389
  },
578
- padding: WINDOW_PADDING
390
+ activeIndex,
391
+ onChange: setValue,
392
+ selectedIndex,
393
+ setActiveIndex,
394
+ setOpen,
395
+ setSelectedIndex,
396
+ value,
397
+ open,
398
+ children: /* @__PURE__ */ jsx(SelectSheetController, {
399
+ onOpenChange: setOpen,
400
+ __scopeSelect,
401
+ children: /* @__PURE__ */ jsx(SelectImpl, {
402
+ activeIndexRef,
403
+ listContentRef,
404
+ selectedIndexRef,
405
+ ...props,
406
+ open,
407
+ value,
408
+ children
409
+ })
410
+ })
579
411
  })
580
- ]
581
- });
582
- const floatingRef = refs.floating;
583
- const forceUpdate = React.useReducer(() => ({}), {})[1];
584
- const showUpArrow = showArrows && scrollTop > SCROLL_ARROW_THRESHOLD;
585
- const showDownArrow = showArrows && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD;
586
- const interactions = useInteractions([
587
- useClick(context, { pointerDown: true }),
588
- useRole(context, { role: "listbox" }),
589
- useDismiss(context),
590
- useListNavigation(context, {
591
- listRef: listItemsRef,
592
- activeIndex,
593
- selectedIndex,
594
- onNavigate: setActiveIndex
595
- }),
596
- useTypeahead(context, {
597
- listRef: listContentRef,
598
- onMatch: open ? setActiveIndex : setSelectedIndex,
599
- selectedIndex,
600
- activeIndex
601
- })
602
- ]);
603
- const increaseHeight = React.useCallback((floating2, amount = 0) => {
604
- if (middlewareType === "fallback") {
605
- return;
606
- }
607
- const currentMaxHeight = Number(floating2.style.maxHeight.replace("px", ""));
608
- const currentTop = Number(floating2.style.top.replace("px", ""));
609
- const rect = floating2.getBoundingClientRect();
610
- const rectTop = rect.top;
611
- const rectBottom = rect.bottom;
612
- const viewportHeight = (visualViewport == null ? void 0 : visualViewport.height) ?? 0;
613
- const visualMaxHeight = viewportHeight - WINDOW_PADDING * 2;
614
- if (amount < 0 && selectedIndexRef.current != null && Math.round(rectBottom) < Math.round(viewportHeight + getVisualOffsetTop() - WINDOW_PADDING)) {
615
- floating2.style.maxHeight = `${Math.min(visualMaxHeight, currentMaxHeight - amount)}px`;
616
- }
617
- if (amount > 0 && Math.round(rectTop) > Math.round(WINDOW_PADDING - getVisualOffsetTop()) && floating2.scrollHeight > floating2.offsetHeight) {
618
- const nextTop = Math.max(WINDOW_PADDING + getVisualOffsetTop(), currentTop - amount);
619
- const nextMaxHeight = Math.min(visualMaxHeight, currentMaxHeight + amount);
620
- Object.assign(floating2.style, {
621
- maxHeight: `${nextMaxHeight}px`,
622
- top: `${nextTop}px`
623
- });
624
- if (nextTop - WINDOW_PADDING > getVisualOffsetTop()) {
625
- floating2.scrollTop -= nextMaxHeight - currentMaxHeight + getFloatingPadding(floating2);
626
- }
627
- return currentTop - nextTop;
628
- }
629
- }, [middlewareType]);
630
- const touchPageYRef = React.useRef(null);
631
- const handleWheel = React.useCallback((event) => {
632
- var _a;
633
- const pinching = event.ctrlKey;
634
- const currentTarget = event.currentTarget;
635
- function isWheelEvent(event2) {
636
- return typeof event2.deltaY === "number";
637
- }
638
- function isTouchEvent(event2) {
639
- return event2.touches != null;
640
- }
641
- if (Math.abs(((currentTarget == null ? void 0 : currentTarget.offsetHeight) ?? 0) - (((visualViewport == null ? void 0 : visualViewport.height) ?? 0) - WINDOW_PADDING * 2)) > 1 && !pinching) {
642
- event.preventDefault();
643
- } else if (isWheelEvent(event) && isFirefox) {
644
- currentTarget.scrollTop += event.deltaY;
645
- }
646
- if (!pinching) {
647
- let delta = 5;
648
- if (isTouchEvent(event)) {
649
- const currentPageY = touchPageYRef.current;
650
- const pageY = (_a = event.touches[0]) == null ? void 0 : _a.pageY;
651
- if (pageY != null) {
652
- touchPageYRef.current = pageY;
653
- if (currentPageY != null) {
654
- delta = currentPageY - pageY;
655
- }
656
- }
657
- }
658
- increaseHeight(currentTarget, isWheelEvent(event) ? event.deltaY : delta);
659
- setScrollTop(currentTarget.scrollTop);
660
- forceUpdate();
661
- }
662
- }, [increaseHeight, forceUpdate]);
663
- React.useEffect(() => {
664
- function onTouchEnd() {
665
- touchPageYRef.current = null;
666
- }
667
- const floating2 = floatingRef.current;
668
- if (open && floating2 && middlewareType === "align") {
669
- floating2.addEventListener("wheel", handleWheel);
670
- floating2.addEventListener("touchmove", handleWheel);
671
- floating2.addEventListener("touchend", onTouchEnd, { passive: true });
672
- return () => {
673
- floating2.removeEventListener("wheel", handleWheel);
674
- floating2.removeEventListener("touchmove", handleWheel);
675
- floating2.removeEventListener("touchend", onTouchEnd);
676
- };
677
- }
678
- }, [open, floatingRef, handleWheel, middlewareType]);
679
- React.useEffect(() => {
680
- window.addEventListener("resize", update);
681
- return () => {
682
- window.removeEventListener("resize", update);
683
- };
684
- }, [update]);
685
- React.useLayoutEffect(() => {
686
- var _a;
687
- const floating2 = floatingRef.current;
688
- if (open && controlledScrolling && floating2) {
689
- const item = activeIndex != null ? listItemsRef.current[activeIndex] : selectedIndex != null ? listItemsRef.current[selectedIndex] : null;
690
- if (item && prevActiveIndex != null) {
691
- const itemHeight = ((_a = listItemsRef.current[prevActiveIndex]) == null ? void 0 : _a.offsetHeight) ?? 0;
692
- const floatingHeight = floating2.offsetHeight;
693
- const top = item.offsetTop;
694
- const bottom = top + itemHeight;
695
- if (top < floating2.scrollTop + 20) {
696
- const diff = floating2.scrollTop - top + 20;
697
- floating2.scrollTop -= diff;
698
- if (activeIndex != selectedIndex && activeIndex != null) {
699
- increaseHeight(floating2, -diff);
700
- }
701
- } else if (bottom > floatingHeight + floating2.scrollTop - 20) {
702
- const diff = bottom - floatingHeight - floating2.scrollTop + 20;
703
- floating2.scrollTop += diff;
704
- if (activeIndex != selectedIndex && activeIndex != null) {
705
- floating2.scrollTop -= increaseHeight(floating2, diff) ?? 0;
706
- }
707
- }
708
- }
709
- }
710
- }, [
711
- open,
712
- controlledScrolling,
713
- prevActiveIndex,
714
- activeIndex,
715
- selectedIndex,
716
- floatingRef,
717
- increaseHeight
718
- ]);
719
- React.useLayoutEffect(() => {
720
- var _a;
721
- const floating2 = refs.floating.current;
722
- const reference2 = refs.reference.current;
723
- if (open && floating2 && reference2 && floating2.offsetHeight < floating2.scrollHeight) {
724
- const referenceRect = reference2.getBoundingClientRect();
725
- if (middlewareType === "fallback") {
726
- const item = listItemsRef.current[selectedIndex];
727
- if (item) {
728
- floating2.scrollTop = item.offsetTop - floating2.clientHeight + referenceRect.height;
729
- }
730
- return;
731
- }
732
- floating2.scrollTop = (_a = middlewareData.size) == null ? void 0 : _a.y;
733
- const closeToBottom = ((visualViewport == null ? void 0 : visualViewport.height) ?? 0) + getVisualOffsetTop() - referenceRect.bottom < FALLBACK_THRESHOLD;
734
- const closeToTop = referenceRect.top < FALLBACK_THRESHOLD;
735
- if (floating2.offsetHeight < MIN_HEIGHT || closeToTop || closeToBottom) {
736
- setMiddlewareType("fallback");
737
- }
738
- }
739
- }, [
740
- open,
741
- increaseHeight,
742
- selectedIndex,
743
- middlewareType,
744
- refs.floating,
745
- refs.reference,
746
- middlewareData
747
- ]);
748
- React.useLayoutEffect(() => {
749
- if (open && selectedIndex != null) {
750
- requestAnimationFrame(() => {
751
- var _a;
752
- (_a = listItemsRef.current[selectedIndex]) == null ? void 0 : _a.focus({ preventScroll: true });
753
- });
754
- }
755
- }, [listItemsRef, selectedIndex, open]);
756
- React.useEffect(() => {
757
- const frame = requestAnimationFrame(() => {
758
- setShowArrows(open);
759
- if (!open) {
760
- setScrollTop(0);
761
- setMiddlewareType("align");
762
- setActiveIndex(null);
763
- setControlledScrolling(false);
764
- }
765
412
  });
766
- return () => cancelAnimationFrame(frame);
767
- }, [open]);
768
- const [valueNode, setValueNode] = React.useState(null);
769
- const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
770
- return /* @__PURE__ */ React.createElement(SelectProvider, {
771
- size: sizeProp,
772
- scope: __scopeSelect,
773
- increaseHeight,
774
- forceUpdate,
775
- floatingRef,
776
- valueNode,
777
- onValueNodeChange: setValueNode,
778
- valueNodeHasChildren,
779
- onValueNodeHasChildrenChange: setValueNodeHasChildren,
780
- setValueAtIndex: (index, value2) => {
781
- listContentRef.current[index] = value2;
782
- },
783
- interactions: __spreadProps(__spreadValues({}, interactions), {
784
- getReferenceProps() {
785
- return interactions.getReferenceProps({
786
- ref: reference,
787
- className: "SelectTrigger",
788
- onKeyDown(event) {
789
- if (event.key === "Enter" || event.key === " " && !context.dataRef.current.typing) {
790
- event.preventDefault();
791
- setOpen(true);
792
- }
793
- }
794
- });
795
- },
796
- getFloatingProps(props2) {
797
- return interactions.getFloatingProps(__spreadProps(__spreadValues({
798
- ref: floating,
799
- className: "Select"
800
- }, props2), {
801
- style: __spreadValues({
802
- position: strategy,
803
- top: y ?? "",
804
- left: x ?? "",
805
- outline: 0,
806
- listStyleType: "none",
807
- scrollbarWidth: "none",
808
- userSelect: "none"
809
- }, props2 == null ? void 0 : props2.style),
810
- onPointerEnter() {
811
- setControlledScrolling(false);
812
- },
813
- onPointerMove() {
814
- setControlledScrolling(false);
815
- },
816
- onKeyDown() {
817
- setControlledScrolling(true);
818
- },
819
- onScroll(event) {
820
- setScrollTop(event.currentTarget.scrollTop);
821
- }
822
- }));
823
- }
824
- }),
825
- floatingContext: context,
826
- activeIndex,
827
- canScrollDown: !!showDownArrow,
828
- canScrollUp: !!showUpArrow,
829
- controlledScrolling: true,
830
- dataRef: context.dataRef,
831
- listRef: listItemsRef,
832
- onChange: setValue,
833
- selectedIndex,
834
- setActiveIndex,
835
- setOpen,
836
- setSelectedIndex,
837
- value,
838
- open
839
- }, children);
840
- }, {
841
- Content: SelectContent,
842
- Group: SelectGroup,
843
- Icon: SelectIcon,
844
- Item: SelectItem,
845
- ItemIndicator: SelectItemIndicator,
846
- ItemText: SelectItemText,
847
- Label: SelectLabel,
848
- ScrollDownButton: SelectScrollDownButton,
849
- ScrollUpButton: SelectScrollUpButton,
850
- Trigger: SelectTrigger,
851
- Value: SelectValue,
852
- Viewport: SelectViewport
853
- });
413
+ },
414
+ {
415
+ Adapt,
416
+ Content: SelectContent,
417
+ Group: SelectGroup,
418
+ Icon: SelectIcon,
419
+ Item: SelectItem,
420
+ ItemIndicator: SelectItemIndicator,
421
+ ItemText: SelectItemText,
422
+ Label: SelectLabel,
423
+ ScrollDownButton: SelectScrollDownButton,
424
+ ScrollUpButton: SelectScrollUpButton,
425
+ Trigger: SelectTrigger,
426
+ Value: SelectValue,
427
+ Viewport: SelectViewport,
428
+ SheetContents: SelectSheetContents,
429
+ Sheet: ControlledSheet
430
+ }
431
+ );
854
432
  Select.displayName = SELECT_NAME;
855
433
  export {
856
434
  Select,
@@ -859,9 +437,7 @@ export {
859
437
  SelectItem,
860
438
  SelectItemTextFrame,
861
439
  SelectSeparator,
862
- SelectTrigger,
863
- SelectViewport,
864
- SelectViewportFrame,
865
- createSelectScope
440
+ SelectSheetContents,
441
+ SelectTrigger
866
442
  };
867
443
  //# sourceMappingURL=Select.js.map