@tamagui/select 1.14.1 → 1.14.3
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 +47 -1
- package/dist/cjs/BubbleSelect.js.map +2 -2
- package/dist/cjs/Select.js +494 -1
- package/dist/cjs/Select.js.map +2 -2
- package/dist/cjs/SelectContent.js +54 -1
- package/dist/cjs/SelectContent.js.map +2 -2
- package/dist/cjs/SelectContent.native.js +30 -1
- package/dist/cjs/SelectContent.native.js.map +2 -2
- package/dist/cjs/SelectImpl.js +308 -1
- package/dist/cjs/SelectImpl.js.map +2 -2
- package/dist/cjs/SelectImpl.native.js +34 -1
- package/dist/cjs/SelectImpl.native.js.map +2 -2
- package/dist/cjs/SelectScrollButton.js +175 -1
- package/dist/cjs/SelectScrollButton.js.map +2 -2
- package/dist/cjs/SelectScrollButton.native.js +31 -1
- package/dist/cjs/SelectScrollButton.native.js.map +2 -2
- package/dist/cjs/SelectViewport.js +115 -2
- package/dist/cjs/SelectViewport.js.map +2 -2
- package/dist/cjs/SelectViewport.native.js +52 -1
- package/dist/cjs/SelectViewport.native.js.map +2 -2
- package/dist/cjs/constants.js +46 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/context.js +43 -1
- package/dist/cjs/context.js.map +2 -2
- package/dist/cjs/index.js +19 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/useSelectBreakpointActive.js +42 -1
- package/dist/cjs/useSelectBreakpointActive.js.map +2 -2
- package/dist/esm/BubbleSelect.js +24 -1
- package/dist/esm/BubbleSelect.js.map +2 -2
- package/dist/esm/BubbleSelect.mjs +24 -1
- package/dist/esm/BubbleSelect.mjs.map +2 -2
- package/dist/esm/Select.js +464 -1
- package/dist/esm/Select.js.map +2 -2
- package/dist/esm/Select.mjs +464 -1
- package/dist/esm/Select.mjs.map +2 -2
- package/dist/esm/SelectContent.js +30 -1
- package/dist/esm/SelectContent.js.map +2 -2
- package/dist/esm/SelectContent.mjs +30 -1
- package/dist/esm/SelectContent.mjs.map +2 -2
- package/dist/esm/SelectContent.native.js +6 -1
- package/dist/esm/SelectContent.native.js.map +2 -2
- package/dist/esm/SelectContent.native.mjs +6 -1
- package/dist/esm/SelectContent.native.mjs.map +2 -2
- package/dist/esm/SelectImpl.js +294 -1
- package/dist/esm/SelectImpl.js.map +2 -2
- package/dist/esm/SelectImpl.mjs +294 -1
- package/dist/esm/SelectImpl.mjs.map +2 -2
- package/dist/esm/SelectImpl.native.js +10 -1
- package/dist/esm/SelectImpl.native.js.map +2 -2
- package/dist/esm/SelectImpl.native.mjs +10 -1
- package/dist/esm/SelectImpl.native.mjs.map +2 -2
- package/dist/esm/SelectScrollButton.js +140 -1
- package/dist/esm/SelectScrollButton.js.map +2 -2
- package/dist/esm/SelectScrollButton.mjs +140 -1
- package/dist/esm/SelectScrollButton.mjs.map +2 -2
- package/dist/esm/SelectScrollButton.native.js +6 -1
- package/dist/esm/SelectScrollButton.native.js.map +2 -2
- package/dist/esm/SelectScrollButton.native.mjs +6 -1
- package/dist/esm/SelectScrollButton.native.mjs.map +2 -2
- package/dist/esm/SelectViewport.js +80 -2
- package/dist/esm/SelectViewport.js.map +2 -2
- package/dist/esm/SelectViewport.mjs +80 -2
- package/dist/esm/SelectViewport.mjs.map +2 -2
- package/dist/esm/SelectViewport.native.js +18 -1
- package/dist/esm/SelectViewport.native.js.map +2 -2
- package/dist/esm/SelectViewport.native.mjs +18 -1
- package/dist/esm/SelectViewport.native.mjs.map +2 -2
- package/dist/esm/constants.js +16 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +16 -1
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/context.js +15 -1
- package/dist/esm/context.js.map +2 -2
- package/dist/esm/context.mjs +15 -1
- package/dist/esm/context.mjs.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/useSelectBreakpointActive.js +17 -1
- package/dist/esm/useSelectBreakpointActive.js.map +2 -2
- package/dist/esm/useSelectBreakpointActive.mjs +17 -1
- package/dist/esm/useSelectBreakpointActive.mjs.map +2 -2
- package/dist/jsx/BubbleSelect.js +24 -1
- package/dist/jsx/BubbleSelect.js.map +2 -2
- package/dist/jsx/BubbleSelect.mjs +24 -1
- package/dist/jsx/BubbleSelect.mjs.map +2 -2
- package/dist/jsx/Select.js +428 -1
- package/dist/jsx/Select.js.map +2 -2
- package/dist/jsx/Select.mjs +428 -1
- package/dist/jsx/Select.mjs.map +2 -2
- package/dist/jsx/SelectContent.js +29 -1
- package/dist/jsx/SelectContent.js.map +2 -2
- package/dist/jsx/SelectContent.mjs +29 -1
- package/dist/jsx/SelectContent.mjs.map +2 -2
- package/dist/jsx/SelectContent.native.js +6 -1
- package/dist/jsx/SelectContent.native.js.map +2 -2
- package/dist/jsx/SelectContent.native.mjs +6 -1
- package/dist/jsx/SelectContent.native.mjs.map +2 -2
- package/dist/jsx/SelectImpl.js +286 -1
- package/dist/jsx/SelectImpl.js.map +2 -2
- package/dist/jsx/SelectImpl.mjs +286 -1
- package/dist/jsx/SelectImpl.mjs.map +2 -2
- package/dist/jsx/SelectImpl.native.js +9 -1
- package/dist/jsx/SelectImpl.native.js.map +2 -2
- package/dist/jsx/SelectImpl.native.mjs +9 -1
- package/dist/jsx/SelectImpl.native.mjs.map +2 -2
- package/dist/jsx/SelectScrollButton.js +126 -1
- package/dist/jsx/SelectScrollButton.js.map +2 -2
- package/dist/jsx/SelectScrollButton.mjs +126 -1
- package/dist/jsx/SelectScrollButton.mjs.map +2 -2
- package/dist/jsx/SelectScrollButton.native.js +6 -1
- package/dist/jsx/SelectScrollButton.native.js.map +2 -2
- package/dist/jsx/SelectScrollButton.native.mjs +6 -1
- package/dist/jsx/SelectScrollButton.native.mjs.map +2 -2
- package/dist/jsx/SelectViewport.js +72 -2
- package/dist/jsx/SelectViewport.js.map +2 -2
- package/dist/jsx/SelectViewport.mjs +72 -2
- package/dist/jsx/SelectViewport.mjs.map +2 -2
- package/dist/jsx/SelectViewport.native.js +17 -1
- package/dist/jsx/SelectViewport.native.js.map +2 -2
- package/dist/jsx/SelectViewport.native.mjs +17 -1
- package/dist/jsx/SelectViewport.native.mjs.map +2 -2
- package/dist/jsx/constants.js +16 -1
- package/dist/jsx/constants.js.map +2 -2
- package/dist/jsx/constants.mjs +16 -1
- package/dist/jsx/constants.mjs.map +2 -2
- package/dist/jsx/context.js +14 -1
- package/dist/jsx/context.js.map +2 -2
- package/dist/jsx/context.mjs +14 -1
- package/dist/jsx/context.mjs.map +2 -2
- package/dist/jsx/index.js +2 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +2 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/useSelectBreakpointActive.js +17 -1
- package/dist/jsx/useSelectBreakpointActive.js.map +2 -2
- package/dist/jsx/useSelectBreakpointActive.mjs +17 -1
- package/dist/jsx/useSelectBreakpointActive.mjs.map +2 -2
- package/package.json +16 -16
package/dist/cjs/BubbleSelect.js
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_react_use_previous = require("@radix-ui/react-use-previous");
|
|
25
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
26
|
+
var React = __toESM(require("react"));
|
|
27
|
+
const BubbleSelect = React.forwardRef((props, forwardedRef) => {
|
|
28
|
+
const { value, ...selectProps } = props;
|
|
29
|
+
const ref = React.useRef(null);
|
|
30
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
31
|
+
const prevValue = (0, import_react_use_previous.usePrevious)(value);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const select = ref.current;
|
|
34
|
+
const selectProto = window.HTMLSelectElement.prototype;
|
|
35
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
36
|
+
selectProto,
|
|
37
|
+
"value"
|
|
38
|
+
);
|
|
39
|
+
const setValue = descriptor.set;
|
|
40
|
+
if (prevValue !== value && setValue) {
|
|
41
|
+
const event = new Event("change", { bubbles: true });
|
|
42
|
+
setValue.call(select, value);
|
|
43
|
+
select.dispatchEvent(event);
|
|
44
|
+
}
|
|
45
|
+
}, [prevValue, value]);
|
|
46
|
+
return null;
|
|
47
|
+
});
|
|
2
48
|
//# sourceMappingURL=BubbleSelect.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/BubbleSelect.tsx"],
|
|
4
4
|
"sourcesContent": ["import { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\n/* -----------------------------------------------------------------------------------------------*/\nconst BubbleSelect = React.forwardRef<\n HTMLSelectElement,\n React.ComponentPropsWithoutRef<'select'>\n>((props, forwardedRef) => {\n const { value, ...selectProps } = props\n const ref = React.useRef<HTMLSelectElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const prevValue = usePrevious(value)\n\n // Bubble value change to parents (e.g form change event)\n React.useEffect(() => {\n const select = ref.current!\n const selectProto = window.HTMLSelectElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(\n selectProto,\n 'value',\n ) as PropertyDescriptor\n const setValue = descriptor.set\n if (prevValue !== value && setValue) {\n const event = new Event('change', { bubbles: true })\n setValue.call(select, value)\n select.dispatchEvent(event)\n }\n }, [prevValue, value])\n\n /**\n * We purposefully use a `select` here to support form autofill as much\n * as possible.\n *\n * We purposefully do not add the `value` attribute here to allow the value\n * to be set programatically and bubble to any parent form `onChange` event.\n * Adding the `value` will cause React to consider the programatic\n * dispatch a duplicate and it will get swallowed.\n *\n * We use `VisuallyHidden` rather than `display: \"none\"` because Safari autofill\n * won't work otherwise.\n */\n // TODO\n return null\n // return (\n // <VisuallyHidden asChild>\n // <select {...selectProps} ref={composedRefs} defaultValue={value} />\n // </VisuallyHidden>\n // )\n})\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,gCAA4B;AAC5B,0BAAgC;AAChC,YAAuB;AAGvB,MAAM,eAAe,MAAM,WAGzB,CAAC,OAAO,iBAAiB;AACzB,QAAM,EAAE,OAAO,GAAG,YAAY,IAAI;AAClC,QAAM,MAAM,MAAM,OAA0B,IAAI;AAChD,QAAM,mBAAe,qCAAgB,cAAc,GAAG;AACtD,QAAM,gBAAY,uCAAY,KAAK;AAGnC,QAAM,UAAU,MAAM;AACpB,UAAM,SAAS,IAAI;AACnB,UAAM,cAAc,OAAO,kBAAkB;AAC7C,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AACA,UAAM,WAAW,WAAW;AAC5B,QAAI,cAAc,SAAS,UAAU;AACnC,YAAM,QAAQ,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC;AACnD,eAAS,KAAK,QAAQ,KAAK;AAC3B,aAAO,cAAc,KAAK;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAerB,SAAO;AAMT,CAAC;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/cjs/Select.js
CHANGED
|
@@ -1,2 +1,495 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Select_exports = {};
|
|
30
|
+
__export(Select_exports, {
|
|
31
|
+
Select: () => Select,
|
|
32
|
+
SelectGroupFrame: () => SelectGroupFrame,
|
|
33
|
+
SelectIcon: () => SelectIcon,
|
|
34
|
+
SelectItem: () => SelectItem,
|
|
35
|
+
SelectItemTextFrame: () => SelectItemTextFrame,
|
|
36
|
+
SelectSeparator: () => SelectSeparator,
|
|
37
|
+
SelectTrigger: () => SelectTrigger
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(Select_exports);
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var import_adapt = require("@tamagui/adapt");
|
|
42
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
43
|
+
var import_core = require("@tamagui/core");
|
|
44
|
+
var import_list_item = require("@tamagui/list-item");
|
|
45
|
+
var import_portal = require("@tamagui/portal");
|
|
46
|
+
var import_separator = require("@tamagui/separator");
|
|
47
|
+
var import_sheet = require("@tamagui/sheet");
|
|
48
|
+
var import_stacks = require("@tamagui/stacks");
|
|
49
|
+
var import_text = require("@tamagui/text");
|
|
50
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
51
|
+
var React = __toESM(require("react"));
|
|
52
|
+
var import_constants = require("./constants");
|
|
53
|
+
var import_context = require("./context");
|
|
54
|
+
var import_SelectContent = require("./SelectContent");
|
|
55
|
+
var import_SelectImpl = require("./SelectImpl");
|
|
56
|
+
var import_SelectScrollButton = require("./SelectScrollButton");
|
|
57
|
+
var import_SelectViewport = require("./SelectViewport");
|
|
58
|
+
var import_useSelectBreakpointActive = require("./useSelectBreakpointActive");
|
|
59
|
+
const TRIGGER_NAME = "SelectTrigger";
|
|
60
|
+
const SelectTrigger = React.forwardRef(
|
|
61
|
+
(props, forwardedRef) => {
|
|
62
|
+
const {
|
|
63
|
+
__scopeSelect,
|
|
64
|
+
disabled = false,
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
"aria-labelledby": ariaLabelledby,
|
|
67
|
+
...triggerProps
|
|
68
|
+
} = props;
|
|
69
|
+
const context = (0, import_context.useSelectContext)(TRIGGER_NAME, __scopeSelect);
|
|
70
|
+
const labelledBy = ariaLabelledby;
|
|
71
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
+
import_list_item.ListItem,
|
|
73
|
+
{
|
|
74
|
+
componentName: TRIGGER_NAME,
|
|
75
|
+
backgrounded: true,
|
|
76
|
+
radiused: true,
|
|
77
|
+
hoverTheme: true,
|
|
78
|
+
pressTheme: true,
|
|
79
|
+
focusTheme: true,
|
|
80
|
+
focusable: true,
|
|
81
|
+
borderWidth: 1,
|
|
82
|
+
size: context.size,
|
|
83
|
+
"aria-expanded": context.open,
|
|
84
|
+
"aria-autocomplete": "none",
|
|
85
|
+
"aria-labelledby": labelledBy,
|
|
86
|
+
dir: context.dir,
|
|
87
|
+
disabled,
|
|
88
|
+
"data-disabled": disabled ? "" : void 0,
|
|
89
|
+
...triggerProps,
|
|
90
|
+
ref: forwardedRef,
|
|
91
|
+
...process.env.TAMAGUI_TARGET === "web" && context.interactions ? context.interactions.getReferenceProps() : {
|
|
92
|
+
onPress() {
|
|
93
|
+
context.setOpen(!context.open);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
SelectTrigger.displayName = TRIGGER_NAME;
|
|
101
|
+
const VALUE_NAME = "SelectValue";
|
|
102
|
+
const SelectValueFrame = (0, import_core.styled)(import_text.Paragraph, {
|
|
103
|
+
name: VALUE_NAME,
|
|
104
|
+
userSelect: "none"
|
|
105
|
+
});
|
|
106
|
+
const SelectValue = SelectValueFrame.extractable(
|
|
107
|
+
React.forwardRef(
|
|
108
|
+
({
|
|
109
|
+
__scopeSelect,
|
|
110
|
+
children: childrenProp,
|
|
111
|
+
placeholder
|
|
112
|
+
}, forwardedRef) => {
|
|
113
|
+
const context = (0, import_context.useSelectContext)(VALUE_NAME, __scopeSelect);
|
|
114
|
+
const { onValueNodeHasChildrenChange } = context;
|
|
115
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.onValueNodeChange);
|
|
116
|
+
const children = childrenProp ?? context.selectedItem;
|
|
117
|
+
const hasChildren = !!children;
|
|
118
|
+
const isEmptyValue = context.value == null || context.value === "";
|
|
119
|
+
const selectValueChildren = isEmptyValue ? placeholder ?? children : children;
|
|
120
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
121
|
+
onValueNodeHasChildrenChange(hasChildren);
|
|
122
|
+
}, [onValueNodeHasChildrenChange, hasChildren]);
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
SelectValueFrame,
|
|
125
|
+
{
|
|
126
|
+
size: context.size,
|
|
127
|
+
ref: composedRefs,
|
|
128
|
+
pointerEvents: "none",
|
|
129
|
+
children: selectValueChildren
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
SelectValue.displayName = VALUE_NAME;
|
|
136
|
+
const SelectIcon = (0, import_core.styled)(import_stacks.XStack, {
|
|
137
|
+
name: "SelectIcon",
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
"aria-hidden": true,
|
|
140
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_text.Paragraph, { children: "\u25BC" })
|
|
141
|
+
});
|
|
142
|
+
const ITEM_NAME = "SelectItem";
|
|
143
|
+
const [SelectItemContextProvider, useSelectItemContext] = (0, import_context.createSelectContext)(ITEM_NAME);
|
|
144
|
+
const SelectItem = React.forwardRef(
|
|
145
|
+
(props, forwardedRef) => {
|
|
146
|
+
const {
|
|
147
|
+
__scopeSelect,
|
|
148
|
+
value,
|
|
149
|
+
disabled = false,
|
|
150
|
+
textValue: textValueProp,
|
|
151
|
+
index,
|
|
152
|
+
...itemProps
|
|
153
|
+
} = props;
|
|
154
|
+
const context = (0, import_context.useSelectContext)(ITEM_NAME, __scopeSelect);
|
|
155
|
+
const isSelected = context.value === value;
|
|
156
|
+
const textId = (0, import_core.useId)();
|
|
157
|
+
const {
|
|
158
|
+
selectedIndex,
|
|
159
|
+
setSelectedIndex,
|
|
160
|
+
listRef,
|
|
161
|
+
open,
|
|
162
|
+
setOpen,
|
|
163
|
+
onChange,
|
|
164
|
+
setActiveIndex,
|
|
165
|
+
allowMouseUpRef,
|
|
166
|
+
allowSelectRef,
|
|
167
|
+
setValueAtIndex,
|
|
168
|
+
selectTimeoutRef,
|
|
169
|
+
dataRef
|
|
170
|
+
} = context;
|
|
171
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => {
|
|
172
|
+
if (!import_core.isWeb)
|
|
173
|
+
return;
|
|
174
|
+
if (node instanceof HTMLElement) {
|
|
175
|
+
if (listRef) {
|
|
176
|
+
listRef.current[index] = node;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
React.useEffect(() => {
|
|
181
|
+
setValueAtIndex(index, value);
|
|
182
|
+
}, [index, setValueAtIndex, value]);
|
|
183
|
+
function handleSelect() {
|
|
184
|
+
setSelectedIndex(index);
|
|
185
|
+
onChange(value);
|
|
186
|
+
setOpen(false);
|
|
187
|
+
}
|
|
188
|
+
const selectItemProps = context.interactions ? context.interactions.getItemProps({
|
|
189
|
+
onTouchStart() {
|
|
190
|
+
allowSelectRef.current = true;
|
|
191
|
+
allowMouseUpRef.current = false;
|
|
192
|
+
},
|
|
193
|
+
onKeyDown(event) {
|
|
194
|
+
if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
handleSelect();
|
|
197
|
+
} else {
|
|
198
|
+
allowSelectRef.current = true;
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
onClick() {
|
|
202
|
+
if (allowSelectRef.current) {
|
|
203
|
+
setSelectedIndex(index);
|
|
204
|
+
setOpen(false);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
onMouseUp() {
|
|
208
|
+
if (!allowMouseUpRef.current) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (allowSelectRef.current) {
|
|
212
|
+
handleSelect();
|
|
213
|
+
}
|
|
214
|
+
clearTimeout(selectTimeoutRef.current);
|
|
215
|
+
selectTimeoutRef.current = setTimeout(() => {
|
|
216
|
+
allowSelectRef.current = true;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}) : {
|
|
220
|
+
onPress: handleSelect
|
|
221
|
+
};
|
|
222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
223
|
+
SelectItemContextProvider,
|
|
224
|
+
{
|
|
225
|
+
scope: __scopeSelect,
|
|
226
|
+
value,
|
|
227
|
+
textId: textId || "",
|
|
228
|
+
isSelected,
|
|
229
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
230
|
+
import_list_item.ListItem,
|
|
231
|
+
{
|
|
232
|
+
tag: "div",
|
|
233
|
+
backgrounded: true,
|
|
234
|
+
pressTheme: true,
|
|
235
|
+
hoverTheme: true,
|
|
236
|
+
cursor: "default",
|
|
237
|
+
outlineWidth: 0,
|
|
238
|
+
componentName: ITEM_NAME,
|
|
239
|
+
ref: composedRefs,
|
|
240
|
+
"aria-labelledby": textId,
|
|
241
|
+
"aria-selected": isSelected,
|
|
242
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
243
|
+
"aria-disabled": disabled || void 0,
|
|
244
|
+
"data-disabled": disabled ? "" : void 0,
|
|
245
|
+
tabIndex: disabled ? void 0 : -1,
|
|
246
|
+
size: context.size,
|
|
247
|
+
focusStyle: {
|
|
248
|
+
backgroundColor: "$backgroundHover"
|
|
249
|
+
},
|
|
250
|
+
...itemProps,
|
|
251
|
+
...selectItemProps
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
SelectItem.displayName = ITEM_NAME;
|
|
259
|
+
const ITEM_TEXT_NAME = "SelectItemText";
|
|
260
|
+
const SelectItemTextFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
261
|
+
name: ITEM_TEXT_NAME,
|
|
262
|
+
userSelect: "none"
|
|
263
|
+
});
|
|
264
|
+
const SelectItemText = React.forwardRef(
|
|
265
|
+
(props, forwardedRef) => {
|
|
266
|
+
const { __scopeSelect, className, ...itemTextProps } = props;
|
|
267
|
+
const context = (0, import_context.useSelectContext)(ITEM_TEXT_NAME, __scopeSelect);
|
|
268
|
+
const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
|
|
269
|
+
const ref = React.useRef(null);
|
|
270
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
271
|
+
const isSelected = Boolean(itemContext.isSelected && context.valueNode);
|
|
272
|
+
const contents = React.useMemo(
|
|
273
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
274
|
+
SelectItemTextFrame,
|
|
275
|
+
{
|
|
276
|
+
className,
|
|
277
|
+
size: context.size,
|
|
278
|
+
id: itemContext.textId,
|
|
279
|
+
...itemTextProps,
|
|
280
|
+
ref: composedRefs
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
284
|
+
[props, context.size, className, itemContext.textId]
|
|
285
|
+
);
|
|
286
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
287
|
+
if (isSelected) {
|
|
288
|
+
context.setSelectedItem(contents);
|
|
289
|
+
}
|
|
290
|
+
}, [isSelected, contents]);
|
|
291
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: contents });
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
SelectItemText.displayName = ITEM_TEXT_NAME;
|
|
295
|
+
const ITEM_INDICATOR_NAME = "SelectItemIndicator";
|
|
296
|
+
const SelectItemIndicatorFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
297
|
+
name: ITEM_TEXT_NAME
|
|
298
|
+
});
|
|
299
|
+
const SelectItemIndicator = React.forwardRef(
|
|
300
|
+
(props, forwardedRef) => {
|
|
301
|
+
const { __scopeSelect, ...itemIndicatorProps } = props;
|
|
302
|
+
const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
|
|
303
|
+
return itemContext.isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemIndicatorFrame, { "aria-hidden": true, ...itemIndicatorProps, ref: forwardedRef }) : null;
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
|
|
307
|
+
const GROUP_NAME = "SelectGroup";
|
|
308
|
+
const [SelectGroupContextProvider, useSelectGroupContext] = (0, import_context.createSelectContext)(GROUP_NAME);
|
|
309
|
+
const SelectGroupFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
310
|
+
name: GROUP_NAME,
|
|
311
|
+
width: "100%"
|
|
312
|
+
});
|
|
313
|
+
const SelectGroup = React.forwardRef(
|
|
314
|
+
(props, forwardedRef) => {
|
|
315
|
+
const { __scopeSelect, ...groupProps } = props;
|
|
316
|
+
const groupId = (0, import_core.useId)();
|
|
317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectGroupContextProvider, { scope: __scopeSelect, id: groupId || "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
318
|
+
SelectGroupFrame,
|
|
319
|
+
{
|
|
320
|
+
role: "group",
|
|
321
|
+
"aria-labelledby": groupId,
|
|
322
|
+
...groupProps,
|
|
323
|
+
ref: forwardedRef
|
|
324
|
+
}
|
|
325
|
+
) });
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
SelectGroup.displayName = GROUP_NAME;
|
|
329
|
+
const LABEL_NAME = "SelectLabel";
|
|
330
|
+
const SelectLabel = React.forwardRef(
|
|
331
|
+
(props, forwardedRef) => {
|
|
332
|
+
const { __scopeSelect, ...labelProps } = props;
|
|
333
|
+
const context = (0, import_context.useSelectContext)(LABEL_NAME, __scopeSelect);
|
|
334
|
+
const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
|
|
335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
336
|
+
import_list_item.ListItem,
|
|
337
|
+
{
|
|
338
|
+
tag: "div",
|
|
339
|
+
componentName: LABEL_NAME,
|
|
340
|
+
fontWeight: "800",
|
|
341
|
+
id: groupContext.id,
|
|
342
|
+
size: context.size,
|
|
343
|
+
...labelProps,
|
|
344
|
+
ref: forwardedRef
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
SelectLabel.displayName = LABEL_NAME;
|
|
350
|
+
const SelectSeparator = (0, import_core.styled)(import_separator.Separator, {
|
|
351
|
+
name: "SelectSeparator"
|
|
352
|
+
});
|
|
353
|
+
const SelectSheetController = (props) => {
|
|
354
|
+
const context = (0, import_context.useSelectContext)("SelectSheetController", props.__scopeSelect);
|
|
355
|
+
const showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context);
|
|
356
|
+
const breakpointActive = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(context.sheetBreakpoint);
|
|
357
|
+
const getShowSheet = (0, import_core.useGet)(showSheet);
|
|
358
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
359
|
+
import_sheet.SheetController,
|
|
360
|
+
{
|
|
361
|
+
onOpenChange: (val) => {
|
|
362
|
+
if (getShowSheet()) {
|
|
363
|
+
props.onOpenChange(val);
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
open: context.open,
|
|
367
|
+
hidden: breakpointActive === false,
|
|
368
|
+
children: props.children
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
};
|
|
372
|
+
const SelectSheetImpl = (props) => {
|
|
373
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children });
|
|
374
|
+
};
|
|
375
|
+
const Select = (0, import_core.withStaticProperties)(
|
|
376
|
+
(props) => {
|
|
377
|
+
const {
|
|
378
|
+
__scopeSelect,
|
|
379
|
+
children,
|
|
380
|
+
open: openProp,
|
|
381
|
+
defaultOpen,
|
|
382
|
+
onOpenChange,
|
|
383
|
+
value: valueProp,
|
|
384
|
+
defaultValue,
|
|
385
|
+
onValueChange,
|
|
386
|
+
size: sizeProp = "$true",
|
|
387
|
+
dir
|
|
388
|
+
} = props;
|
|
389
|
+
const id = (0, import_core.useId)();
|
|
390
|
+
const scopeKey = __scopeSelect ? Object.keys(__scopeSelect)[0] ?? id : id;
|
|
391
|
+
const { when, AdaptProvider } = (0, import_adapt.useAdaptParent)({
|
|
392
|
+
Contents: React.useCallback(
|
|
393
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalHost, { name: `${scopeKey}SheetContents` }),
|
|
394
|
+
[scopeKey]
|
|
395
|
+
)
|
|
396
|
+
});
|
|
397
|
+
const sheetBreakpoint = when;
|
|
398
|
+
const isSheet = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(sheetBreakpoint);
|
|
399
|
+
const SelectImpl = isSheet || !import_core.isWeb ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl;
|
|
400
|
+
const forceUpdate = React.useReducer(() => ({}), {})[1];
|
|
401
|
+
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
402
|
+
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
403
|
+
prop: openProp,
|
|
404
|
+
defaultProp: defaultOpen || false,
|
|
405
|
+
onChange: onOpenChange
|
|
406
|
+
});
|
|
407
|
+
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
408
|
+
prop: valueProp,
|
|
409
|
+
defaultProp: defaultValue || "",
|
|
410
|
+
onChange: onValueChange,
|
|
411
|
+
transition: true
|
|
412
|
+
});
|
|
413
|
+
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
414
|
+
const selectedIndexRef = React.useRef(null);
|
|
415
|
+
const activeIndexRef = React.useRef(null);
|
|
416
|
+
const listContentRef = React.useRef([]);
|
|
417
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
418
|
+
const [valueNode, setValueNode] = React.useState(null);
|
|
419
|
+
const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
|
|
420
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
421
|
+
selectedIndexRef.current = selectedIndex;
|
|
422
|
+
activeIndexRef.current = activeIndex;
|
|
423
|
+
});
|
|
424
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
425
|
+
import_context.SelectProvider,
|
|
426
|
+
{
|
|
427
|
+
dir,
|
|
428
|
+
blockSelection: false,
|
|
429
|
+
size: sizeProp,
|
|
430
|
+
fallback: false,
|
|
431
|
+
selectedItem,
|
|
432
|
+
setSelectedItem,
|
|
433
|
+
forceUpdate,
|
|
434
|
+
valueNode,
|
|
435
|
+
onValueNodeChange: setValueNode,
|
|
436
|
+
onValueNodeHasChildrenChange: setValueNodeHasChildren,
|
|
437
|
+
valueNodeHasChildren,
|
|
438
|
+
scopeKey,
|
|
439
|
+
sheetBreakpoint,
|
|
440
|
+
scope: __scopeSelect,
|
|
441
|
+
setValueAtIndex: (index, value2) => {
|
|
442
|
+
listContentRef.current[index] = value2;
|
|
443
|
+
},
|
|
444
|
+
activeIndex,
|
|
445
|
+
onChange: setValue,
|
|
446
|
+
selectedIndex,
|
|
447
|
+
setActiveIndex,
|
|
448
|
+
setOpen,
|
|
449
|
+
setSelectedIndex,
|
|
450
|
+
value,
|
|
451
|
+
open,
|
|
452
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectSheetController, { onOpenChange: setOpen, __scopeSelect, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
453
|
+
SelectImpl,
|
|
454
|
+
{
|
|
455
|
+
activeIndexRef,
|
|
456
|
+
listContentRef,
|
|
457
|
+
selectedIndexRef,
|
|
458
|
+
...props,
|
|
459
|
+
open,
|
|
460
|
+
value,
|
|
461
|
+
children
|
|
462
|
+
}
|
|
463
|
+
) })
|
|
464
|
+
}
|
|
465
|
+
) });
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
Adapt: import_adapt.Adapt,
|
|
469
|
+
Content: import_SelectContent.SelectContent,
|
|
470
|
+
Group: SelectGroup,
|
|
471
|
+
Icon: SelectIcon,
|
|
472
|
+
Item: SelectItem,
|
|
473
|
+
ItemIndicator: SelectItemIndicator,
|
|
474
|
+
ItemText: SelectItemText,
|
|
475
|
+
Label: SelectLabel,
|
|
476
|
+
ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
|
|
477
|
+
ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
|
|
478
|
+
Trigger: SelectTrigger,
|
|
479
|
+
Value: SelectValue,
|
|
480
|
+
Viewport: import_SelectViewport.SelectViewport,
|
|
481
|
+
Sheet: import_sheet.ControlledSheet
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
Select.displayName = import_constants.SELECT_NAME;
|
|
485
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
486
|
+
0 && (module.exports = {
|
|
487
|
+
Select,
|
|
488
|
+
SelectGroupFrame,
|
|
489
|
+
SelectIcon,
|
|
490
|
+
SelectItem,
|
|
491
|
+
SelectItemTextFrame,
|
|
492
|
+
SelectSeparator,
|
|
493
|
+
SelectTrigger
|
|
494
|
+
});
|
|
2
495
|
//# sourceMappingURL=Select.js.map
|