@atlaskit/react-select 0.0.2
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/CHANGELOG.md +9 -0
- package/LICENSE.md +11 -0
- package/README.md +10 -0
- package/async/package.json +15 -0
- package/base/package.json +15 -0
- package/creatable/package.json +15 -0
- package/dist/cjs/accessibility/helpers.js +34 -0
- package/dist/cjs/accessibility/index.js +74 -0
- package/dist/cjs/async-creatable.js +27 -0
- package/dist/cjs/async.js +30 -0
- package/dist/cjs/builtins.js +18 -0
- package/dist/cjs/components/containers.js +100 -0
- package/dist/cjs/components/control.js +67 -0
- package/dist/cjs/components/group.js +79 -0
- package/dist/cjs/components/index.js +53 -0
- package/dist/cjs/components/indicators.js +214 -0
- package/dist/cjs/components/input.js +93 -0
- package/dist/cjs/components/internal/a11y-text.js +34 -0
- package/dist/cjs/components/internal/dummy-input.js +43 -0
- package/dist/cjs/components/internal/index.js +34 -0
- package/dist/cjs/components/internal/required-input.js +43 -0
- package/dist/cjs/components/internal/scroll-manager.js +57 -0
- package/dist/cjs/components/internal/use-scroll-capture.js +132 -0
- package/dist/cjs/components/internal/use-scroll-lock.js +149 -0
- package/dist/cjs/components/live-region.js +153 -0
- package/dist/cjs/components/menu.js +464 -0
- package/dist/cjs/components/multi-value.js +129 -0
- package/dist/cjs/components/option.js +62 -0
- package/dist/cjs/components/placeholder.js +39 -0
- package/dist/cjs/components/single-value.js +46 -0
- package/dist/cjs/creatable.js +30 -0
- package/dist/cjs/diacritics.js +274 -0
- package/dist/cjs/filters.js +50 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/nonce-provider.js +30 -0
- package/dist/cjs/select.js +1803 -0
- package/dist/cjs/state-manager.js +31 -0
- package/dist/cjs/styles.js +66 -0
- package/dist/cjs/theme.js +42 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/use-async.js +156 -0
- package/dist/cjs/use-creatable.js +114 -0
- package/dist/cjs/use-state-manager.js +83 -0
- package/dist/cjs/utils.js +357 -0
- package/dist/es2019/accessibility/helpers.js +24 -0
- package/dist/es2019/accessibility/index.js +72 -0
- package/dist/es2019/async-creatable.js +17 -0
- package/dist/es2019/async.js +16 -0
- package/dist/es2019/builtins.js +4 -0
- package/dist/es2019/components/containers.js +100 -0
- package/dist/es2019/components/control.js +62 -0
- package/dist/es2019/components/group.js +74 -0
- package/dist/es2019/components/index.js +41 -0
- package/dist/es2019/components/indicators.js +211 -0
- package/dist/es2019/components/input.js +88 -0
- package/dist/es2019/components/internal/a11y-text.js +25 -0
- package/dist/es2019/components/internal/dummy-input.js +36 -0
- package/dist/es2019/components/internal/index.js +4 -0
- package/dist/es2019/components/internal/required-input.js +35 -0
- package/dist/es2019/components/internal/scroll-manager.js +49 -0
- package/dist/es2019/components/internal/use-scroll-capture.js +128 -0
- package/dist/es2019/components/internal/use-scroll-lock.js +143 -0
- package/dist/es2019/components/live-region.js +151 -0
- package/dist/es2019/components/menu.js +466 -0
- package/dist/es2019/components/multi-value.js +134 -0
- package/dist/es2019/components/option.js +57 -0
- package/dist/es2019/components/placeholder.js +34 -0
- package/dist/es2019/components/single-value.js +41 -0
- package/dist/es2019/creatable.js +15 -0
- package/dist/es2019/diacritics.js +264 -0
- package/dist/es2019/filters.js +36 -0
- package/dist/es2019/index.js +8 -0
- package/dist/es2019/nonce-provider.js +19 -0
- package/dist/es2019/select.js +1766 -0
- package/dist/es2019/state-manager.js +22 -0
- package/dist/es2019/styles.js +56 -0
- package/dist/es2019/theme.js +36 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/use-async.js +117 -0
- package/dist/es2019/use-creatable.js +81 -0
- package/dist/es2019/use-state-manager.js +60 -0
- package/dist/es2019/utils.js +309 -0
- package/dist/esm/accessibility/helpers.js +24 -0
- package/dist/esm/accessibility/index.js +68 -0
- package/dist/esm/async-creatable.js +17 -0
- package/dist/esm/async.js +16 -0
- package/dist/esm/builtins.js +12 -0
- package/dist/esm/components/containers.js +96 -0
- package/dist/esm/components/control.js +62 -0
- package/dist/esm/components/group.js +74 -0
- package/dist/esm/components/index.js +43 -0
- package/dist/esm/components/indicators.js +209 -0
- package/dist/esm/components/input.js +88 -0
- package/dist/esm/components/internal/a11y-text.js +27 -0
- package/dist/esm/components/internal/dummy-input.js +37 -0
- package/dist/esm/components/internal/index.js +4 -0
- package/dist/esm/components/internal/required-input.js +36 -0
- package/dist/esm/components/internal/scroll-manager.js +49 -0
- package/dist/esm/components/internal/use-scroll-capture.js +126 -0
- package/dist/esm/components/internal/use-scroll-lock.js +143 -0
- package/dist/esm/components/live-region.js +148 -0
- package/dist/esm/components/menu.js +460 -0
- package/dist/esm/components/multi-value.js +122 -0
- package/dist/esm/components/option.js +57 -0
- package/dist/esm/components/placeholder.js +34 -0
- package/dist/esm/components/single-value.js +41 -0
- package/dist/esm/creatable.js +15 -0
- package/dist/esm/diacritics.js +268 -0
- package/dist/esm/filters.js +43 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/nonce-provider.js +20 -0
- package/dist/esm/select.js +1794 -0
- package/dist/esm/state-manager.js +22 -0
- package/dist/esm/styles.js +58 -0
- package/dist/esm/theme.js +36 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/use-async.js +149 -0
- package/dist/esm/use-creatable.js +107 -0
- package/dist/esm/use-state-manager.js +76 -0
- package/dist/esm/utils.js +328 -0
- package/dist/types/accessibility/helpers.d.ts +5 -0
- package/dist/types/accessibility/index.d.ts +125 -0
- package/dist/types/async-creatable.d.ts +10 -0
- package/dist/types/async.d.ts +9 -0
- package/dist/types/builtins.d.ts +5 -0
- package/dist/types/components/containers.d.ts +50 -0
- package/dist/types/components/control.d.ts +33 -0
- package/dist/types/components/group.d.ts +53 -0
- package/dist/types/components/index.d.ts +73 -0
- package/dist/types/components/indicators.d.ts +72 -0
- package/dist/types/components/input.d.ts +33 -0
- package/dist/types/components/internal/a11y-text.d.ts +8 -0
- package/dist/types/components/internal/dummy-input.d.ts +9 -0
- package/dist/types/components/internal/index.d.ts +4 -0
- package/dist/types/components/internal/required-input.d.ts +10 -0
- package/dist/types/components/internal/scroll-manager.d.ts +17 -0
- package/dist/types/components/internal/use-scroll-capture.d.ts +12 -0
- package/dist/types/components/internal/use-scroll-lock.d.ts +9 -0
- package/dist/types/components/live-region.d.ts +24 -0
- package/dist/types/components/menu.d.ts +130 -0
- package/dist/types/components/multi-value.d.ts +47 -0
- package/dist/types/components/option.d.ts +49 -0
- package/dist/types/components/placeholder.d.ts +22 -0
- package/dist/types/components/single-value.d.ts +28 -0
- package/dist/types/creatable.d.ts +10 -0
- package/dist/types/diacritics.d.ts +1 -0
- package/dist/types/filters.d.ts +15 -0
- package/dist/types/index.d.ts +28 -0
- package/dist/types/nonce-provider.d.ts +8 -0
- package/dist/types/select.d.ts +616 -0
- package/dist/types/state-manager.d.ts +17 -0
- package/dist/types/styles.d.ts +68 -0
- package/dist/types/theme.d.ts +27 -0
- package/dist/types/types.d.ts +134 -0
- package/dist/types/use-async.d.ts +31 -0
- package/dist/types/use-creatable.d.ts +46 -0
- package/dist/types/use-state-manager.d.ts +15 -0
- package/dist/types/utils.d.ts +44 -0
- package/dist/types-ts4.5/accessibility/helpers.d.ts +5 -0
- package/dist/types-ts4.5/accessibility/index.d.ts +125 -0
- package/dist/types-ts4.5/async-creatable.d.ts +10 -0
- package/dist/types-ts4.5/async.d.ts +9 -0
- package/dist/types-ts4.5/builtins.d.ts +5 -0
- package/dist/types-ts4.5/components/containers.d.ts +50 -0
- package/dist/types-ts4.5/components/control.d.ts +33 -0
- package/dist/types-ts4.5/components/group.d.ts +53 -0
- package/dist/types-ts4.5/components/index.d.ts +73 -0
- package/dist/types-ts4.5/components/indicators.d.ts +72 -0
- package/dist/types-ts4.5/components/input.d.ts +33 -0
- package/dist/types-ts4.5/components/internal/a11y-text.d.ts +8 -0
- package/dist/types-ts4.5/components/internal/dummy-input.d.ts +9 -0
- package/dist/types-ts4.5/components/internal/index.d.ts +4 -0
- package/dist/types-ts4.5/components/internal/required-input.d.ts +10 -0
- package/dist/types-ts4.5/components/internal/scroll-manager.d.ts +17 -0
- package/dist/types-ts4.5/components/internal/use-scroll-capture.d.ts +12 -0
- package/dist/types-ts4.5/components/internal/use-scroll-lock.d.ts +9 -0
- package/dist/types-ts4.5/components/live-region.d.ts +24 -0
- package/dist/types-ts4.5/components/menu.d.ts +130 -0
- package/dist/types-ts4.5/components/multi-value.d.ts +47 -0
- package/dist/types-ts4.5/components/option.d.ts +49 -0
- package/dist/types-ts4.5/components/placeholder.d.ts +22 -0
- package/dist/types-ts4.5/components/single-value.d.ts +28 -0
- package/dist/types-ts4.5/creatable.d.ts +10 -0
- package/dist/types-ts4.5/diacritics.d.ts +1 -0
- package/dist/types-ts4.5/filters.d.ts +15 -0
- package/dist/types-ts4.5/index.d.ts +28 -0
- package/dist/types-ts4.5/nonce-provider.d.ts +8 -0
- package/dist/types-ts4.5/select.d.ts +616 -0
- package/dist/types-ts4.5/state-manager.d.ts +17 -0
- package/dist/types-ts4.5/styles.d.ts +68 -0
- package/dist/types-ts4.5/theme.d.ts +27 -0
- package/dist/types-ts4.5/types.d.ts +134 -0
- package/dist/types-ts4.5/use-async.d.ts +31 -0
- package/dist/types-ts4.5/use-creatable.d.ts +46 -0
- package/dist/types-ts4.5/use-state-manager.d.ts +15 -0
- package/dist/types-ts4.5/utils.d.ts +44 -0
- package/package.json +83 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
|
+
var _excluded = ["className", "clearValue", "cx", "getStyles", "getClassNames", "getValue", "hasValue", "isMulti", "isRtl", "options", "selectOption", "selectProps", "setValue", "theme"];
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
// ==============================
|
|
9
|
+
// NO OP
|
|
10
|
+
// ==============================
|
|
11
|
+
|
|
12
|
+
export var noop = function noop() {};
|
|
13
|
+
export var emptyString = function emptyString() {
|
|
14
|
+
return '';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// ==============================
|
|
18
|
+
// Class Name Prefixer
|
|
19
|
+
// ==============================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* String representation of component state for styling with class names.
|
|
23
|
+
*
|
|
24
|
+
* Expects an array of strings OR a string/object pair:
|
|
25
|
+
* - className(['comp', 'comp-arg', 'comp-arg-2'])
|
|
26
|
+
* @returns 'react-select__comp react-select__comp-arg react-select__comp-arg-2'
|
|
27
|
+
* - className('comp', { some: true, state: false })
|
|
28
|
+
* @returns 'react-select__comp react-select__comp--some'
|
|
29
|
+
*/
|
|
30
|
+
function applyPrefixToName(prefix, name) {
|
|
31
|
+
if (!name) {
|
|
32
|
+
return prefix;
|
|
33
|
+
} else if (name[0] === '-') {
|
|
34
|
+
return prefix + name;
|
|
35
|
+
} else {
|
|
36
|
+
return prefix + '__' + name;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function classNames(prefix, state) {
|
|
40
|
+
for (var _len = arguments.length, classNameList = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
41
|
+
classNameList[_key - 2] = arguments[_key];
|
|
42
|
+
}
|
|
43
|
+
var arr = [].concat(classNameList);
|
|
44
|
+
if (state && prefix) {
|
|
45
|
+
for (var key in state) {
|
|
46
|
+
if (state.hasOwnProperty(key) && state[key]) {
|
|
47
|
+
arr.push("".concat(applyPrefixToName(prefix, key)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return arr.filter(function (i) {
|
|
52
|
+
return i;
|
|
53
|
+
}).map(function (i) {
|
|
54
|
+
return String(i).trim();
|
|
55
|
+
}).join(' ');
|
|
56
|
+
}
|
|
57
|
+
// ==============================
|
|
58
|
+
// Clean Value
|
|
59
|
+
// ==============================
|
|
60
|
+
|
|
61
|
+
export var cleanValue = function cleanValue(value) {
|
|
62
|
+
if (isArray(value)) {
|
|
63
|
+
return value.filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
66
|
+
return [value];
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ==============================
|
|
72
|
+
// Clean Common Props
|
|
73
|
+
// ==============================
|
|
74
|
+
|
|
75
|
+
export var cleanCommonProps = function cleanCommonProps(props) {
|
|
76
|
+
//className
|
|
77
|
+
var className = props.className,
|
|
78
|
+
clearValue = props.clearValue,
|
|
79
|
+
cx = props.cx,
|
|
80
|
+
getStyles = props.getStyles,
|
|
81
|
+
getClassNames = props.getClassNames,
|
|
82
|
+
getValue = props.getValue,
|
|
83
|
+
hasValue = props.hasValue,
|
|
84
|
+
isMulti = props.isMulti,
|
|
85
|
+
isRtl = props.isRtl,
|
|
86
|
+
options = props.options,
|
|
87
|
+
selectOption = props.selectOption,
|
|
88
|
+
selectProps = props.selectProps,
|
|
89
|
+
setValue = props.setValue,
|
|
90
|
+
theme = props.theme,
|
|
91
|
+
innerProps = _objectWithoutProperties(props, _excluded);
|
|
92
|
+
return _objectSpread({}, innerProps);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ==============================
|
|
96
|
+
// Get Style Props
|
|
97
|
+
// ==============================
|
|
98
|
+
|
|
99
|
+
export var getStyleProps = function getStyleProps(props, name, classNamesState) {
|
|
100
|
+
var cx = props.cx,
|
|
101
|
+
getStyles = props.getStyles,
|
|
102
|
+
getClassNames = props.getClassNames,
|
|
103
|
+
className = props.className;
|
|
104
|
+
return {
|
|
105
|
+
css: getStyles(name, props),
|
|
106
|
+
className: cx(classNamesState !== null && classNamesState !== void 0 ? classNamesState : {}, getClassNames(name, props), className)
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// ==============================
|
|
111
|
+
// Handle Input Change
|
|
112
|
+
// ==============================
|
|
113
|
+
|
|
114
|
+
export function handleInputChange(inputValue, actionMeta, onInputChange) {
|
|
115
|
+
if (onInputChange) {
|
|
116
|
+
var _newValue = onInputChange(inputValue, actionMeta);
|
|
117
|
+
if (typeof _newValue === 'string') {
|
|
118
|
+
return _newValue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return inputValue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ==============================
|
|
125
|
+
// Scroll Helpers
|
|
126
|
+
// ==============================
|
|
127
|
+
|
|
128
|
+
export function isDocumentElement(el) {
|
|
129
|
+
return [document.documentElement, document.body, window].indexOf(el) > -1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Normalized Scroll Top
|
|
133
|
+
// ------------------------------
|
|
134
|
+
|
|
135
|
+
export function normalizedHeight(el) {
|
|
136
|
+
if (isDocumentElement(el)) {
|
|
137
|
+
return window.innerHeight;
|
|
138
|
+
}
|
|
139
|
+
return el.clientHeight;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Normalized scrollTo & scrollTop
|
|
143
|
+
// ------------------------------
|
|
144
|
+
|
|
145
|
+
export function getScrollTop(el) {
|
|
146
|
+
if (isDocumentElement(el)) {
|
|
147
|
+
return window.pageYOffset;
|
|
148
|
+
}
|
|
149
|
+
return el.scrollTop;
|
|
150
|
+
}
|
|
151
|
+
export function scrollTo(el, top) {
|
|
152
|
+
// with a scroll distance, we perform scroll on the element
|
|
153
|
+
if (isDocumentElement(el)) {
|
|
154
|
+
window.scrollTo(0, top);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
el.scrollTop = top;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Get Scroll Parent
|
|
161
|
+
// ------------------------------
|
|
162
|
+
|
|
163
|
+
export function getScrollParent(element) {
|
|
164
|
+
var style = getComputedStyle(element);
|
|
165
|
+
var excludeStaticParent = style.position === 'absolute';
|
|
166
|
+
var overflowRx = /(auto|scroll)/;
|
|
167
|
+
if (style.position === 'fixed') {
|
|
168
|
+
return document.documentElement;
|
|
169
|
+
}
|
|
170
|
+
for (var parent = element; parent = parent.parentElement;) {
|
|
171
|
+
style = getComputedStyle(parent);
|
|
172
|
+
if (excludeStaticParent && style.position === 'static') {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (overflowRx.test(style.overflow + style.overflowY + style.overflowX)) {
|
|
176
|
+
return parent;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return document.documentElement;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Animated Scroll To
|
|
183
|
+
// ------------------------------
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param t: time (elapsed)
|
|
187
|
+
* @param b: initial value
|
|
188
|
+
* @param c: amount of change
|
|
189
|
+
* @param d: duration
|
|
190
|
+
*/
|
|
191
|
+
function easeOutCubic(t, b, c, d) {
|
|
192
|
+
return c * ((t = t / d - 1) * t * t + 1) + b;
|
|
193
|
+
}
|
|
194
|
+
export function animatedScrollTo(element, to) {
|
|
195
|
+
var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200;
|
|
196
|
+
var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop;
|
|
197
|
+
var start = getScrollTop(element);
|
|
198
|
+
var change = to - start;
|
|
199
|
+
var increment = 10;
|
|
200
|
+
var currentTime = 0;
|
|
201
|
+
function animateScroll() {
|
|
202
|
+
currentTime += increment;
|
|
203
|
+
var val = easeOutCubic(currentTime, start, change, duration);
|
|
204
|
+
scrollTo(element, val);
|
|
205
|
+
if (currentTime < duration) {
|
|
206
|
+
window.requestAnimationFrame(animateScroll);
|
|
207
|
+
} else {
|
|
208
|
+
callback(element);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
animateScroll();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Scroll Into View
|
|
215
|
+
// ------------------------------
|
|
216
|
+
|
|
217
|
+
export function scrollIntoView(menuEl, focusedEl) {
|
|
218
|
+
var menuRect = menuEl.getBoundingClientRect();
|
|
219
|
+
var focusedRect = focusedEl.getBoundingClientRect();
|
|
220
|
+
var overScroll = focusedEl.offsetHeight / 3;
|
|
221
|
+
if (focusedRect.bottom + overScroll > menuRect.bottom) {
|
|
222
|
+
scrollTo(menuEl, Math.min(focusedEl.offsetTop + focusedEl.clientHeight - menuEl.offsetHeight + overScroll, menuEl.scrollHeight));
|
|
223
|
+
} else if (focusedRect.top - overScroll < menuRect.top) {
|
|
224
|
+
scrollTo(menuEl, Math.max(focusedEl.offsetTop - overScroll, 0));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ==============================
|
|
229
|
+
// Get bounding client object
|
|
230
|
+
// ==============================
|
|
231
|
+
|
|
232
|
+
// cannot get keys using array notation with DOMRect
|
|
233
|
+
export function getBoundingClientObj(element) {
|
|
234
|
+
var rect = element.getBoundingClientRect();
|
|
235
|
+
return {
|
|
236
|
+
bottom: rect.bottom,
|
|
237
|
+
height: rect.height,
|
|
238
|
+
left: rect.left,
|
|
239
|
+
right: rect.right,
|
|
240
|
+
top: rect.top,
|
|
241
|
+
width: rect.width
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
// ==============================
|
|
245
|
+
// String to Key (kebabify)
|
|
246
|
+
// ==============================
|
|
247
|
+
|
|
248
|
+
export function toKey(str) {
|
|
249
|
+
return str.replace(/\W/g, '-');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ==============================
|
|
253
|
+
// Touch Capability Detector
|
|
254
|
+
// ==============================
|
|
255
|
+
|
|
256
|
+
export function isTouchCapable() {
|
|
257
|
+
try {
|
|
258
|
+
document.createEvent('TouchEvent');
|
|
259
|
+
return true;
|
|
260
|
+
} catch (e) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ==============================
|
|
266
|
+
// Mobile Device Detector
|
|
267
|
+
// ==============================
|
|
268
|
+
|
|
269
|
+
export function isMobileDevice() {
|
|
270
|
+
try {
|
|
271
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ==============================
|
|
278
|
+
// Passive Event Detector
|
|
279
|
+
// ==============================
|
|
280
|
+
|
|
281
|
+
// https://github.com/rafgraph/detect-it/blob/main/src/index.ts#L19-L36
|
|
282
|
+
var passiveOptionAccessed = false;
|
|
283
|
+
var options = {
|
|
284
|
+
get passive() {
|
|
285
|
+
return passiveOptionAccessed = true;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
// check for SSR
|
|
289
|
+
var w = typeof window !== 'undefined' ? window : {};
|
|
290
|
+
if (w.addEventListener && w.removeEventListener) {
|
|
291
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
292
|
+
w.addEventListener('p', noop, options);
|
|
293
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
294
|
+
w.removeEventListener('p', noop, false);
|
|
295
|
+
}
|
|
296
|
+
export var supportsPassiveEvents = passiveOptionAccessed;
|
|
297
|
+
export function notNullish(item) {
|
|
298
|
+
return item != null;
|
|
299
|
+
}
|
|
300
|
+
export function isArray(arg) {
|
|
301
|
+
return Array.isArray(arg);
|
|
302
|
+
}
|
|
303
|
+
export function valueTernary(isMulti, multiValue, singleValue) {
|
|
304
|
+
return isMulti ? multiValue : singleValue;
|
|
305
|
+
}
|
|
306
|
+
export function singleValueAsValue(singleValue) {
|
|
307
|
+
return singleValue;
|
|
308
|
+
}
|
|
309
|
+
export function multiValueAsValue(multiValue) {
|
|
310
|
+
return multiValue;
|
|
311
|
+
}
|
|
312
|
+
export var removeProps = function removeProps(propsObj) {
|
|
313
|
+
for (var _len2 = arguments.length, properties = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
314
|
+
properties[_key2 - 1] = arguments[_key2];
|
|
315
|
+
}
|
|
316
|
+
var propsMap = Object.entries(propsObj).filter(function (_ref) {
|
|
317
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
318
|
+
key = _ref2[0];
|
|
319
|
+
return !properties.includes(key);
|
|
320
|
+
});
|
|
321
|
+
return propsMap.reduce(function (newProps, _ref3) {
|
|
322
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
323
|
+
key = _ref4[0],
|
|
324
|
+
val = _ref4[1];
|
|
325
|
+
newProps[key] = val;
|
|
326
|
+
return newProps;
|
|
327
|
+
}, {});
|
|
328
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { AriaAttributes } from 'react';
|
|
2
|
+
import { type ActionMeta, type GroupBase, type InitialInputFocusedActionMeta, type OnChangeValue, type Options, type OptionsOrGroups } from '../types';
|
|
3
|
+
export type OptionContext = 'menu' | 'value';
|
|
4
|
+
export type GuidanceContext = 'menu' | 'input' | 'value';
|
|
5
|
+
export type AriaSelection<Option, IsMulti extends boolean> = InitialInputFocusedActionMeta<Option, IsMulti> | (ActionMeta<Option> & {
|
|
6
|
+
value: OnChangeValue<Option, IsMulti>;
|
|
7
|
+
option?: Option;
|
|
8
|
+
options?: Options<Option>;
|
|
9
|
+
});
|
|
10
|
+
export interface AriaGuidanceProps {
|
|
11
|
+
/**
|
|
12
|
+
* String value of selectProp aria-label
|
|
13
|
+
*/
|
|
14
|
+
'aria-label': AriaAttributes['aria-label'];
|
|
15
|
+
/**
|
|
16
|
+
* String indicating user's current context and available keyboard interactivity
|
|
17
|
+
*/
|
|
18
|
+
context: GuidanceContext;
|
|
19
|
+
/**
|
|
20
|
+
* Boolean value of selectProp isSearchable
|
|
21
|
+
*/
|
|
22
|
+
isSearchable: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Boolean value of selectProp isMulti
|
|
25
|
+
*/
|
|
26
|
+
isMulti: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Boolean value of selectProp isDisabled
|
|
29
|
+
*/
|
|
30
|
+
isDisabled: boolean | null;
|
|
31
|
+
/**
|
|
32
|
+
* Boolean value of selectProp tabSelectsValue
|
|
33
|
+
*/
|
|
34
|
+
tabSelectsValue: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Boolean value indicating if user focused the input for the first time
|
|
37
|
+
*/
|
|
38
|
+
isInitialFocus: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type AriaOnChangeProps<Option, IsMulti extends boolean> = AriaSelection<Option, IsMulti> & {
|
|
41
|
+
/**
|
|
42
|
+
* String derived label from selected or removed option/value
|
|
43
|
+
*/
|
|
44
|
+
label: string;
|
|
45
|
+
/**
|
|
46
|
+
* Array of labels derived from multiple selected or cleared options
|
|
47
|
+
*/
|
|
48
|
+
labels: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Boolean indicating if the selected menu option is disabled
|
|
51
|
+
*/
|
|
52
|
+
isDisabled: boolean | null;
|
|
53
|
+
};
|
|
54
|
+
export interface AriaOnFilterProps {
|
|
55
|
+
/**
|
|
56
|
+
* String indicating current inputValue of the input
|
|
57
|
+
*/
|
|
58
|
+
inputValue: string;
|
|
59
|
+
/**
|
|
60
|
+
* String derived from selectProp screenReaderStatus
|
|
61
|
+
*/
|
|
62
|
+
resultsMessage: string;
|
|
63
|
+
}
|
|
64
|
+
export interface AriaOnFocusProps<Option, Group extends GroupBase<Option>> {
|
|
65
|
+
/**
|
|
66
|
+
* String indicating whether the option was focused in the menu or as (multi-) value
|
|
67
|
+
*/
|
|
68
|
+
context: OptionContext;
|
|
69
|
+
/**
|
|
70
|
+
* Option that is being focused
|
|
71
|
+
*/
|
|
72
|
+
focused: Option;
|
|
73
|
+
/**
|
|
74
|
+
* Boolean indicating whether focused menu option has been disabled
|
|
75
|
+
*/
|
|
76
|
+
isDisabled: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Boolean indicating whether focused menu option is an already selected option
|
|
79
|
+
*/
|
|
80
|
+
isSelected: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* String derived label from focused option/value
|
|
83
|
+
*/
|
|
84
|
+
label: string;
|
|
85
|
+
/**
|
|
86
|
+
* Options provided as props to Select used to determine indexing
|
|
87
|
+
*/
|
|
88
|
+
options: OptionsOrGroups<Option, Group>;
|
|
89
|
+
/**
|
|
90
|
+
* selected option(s) of the Select
|
|
91
|
+
*/
|
|
92
|
+
selectValue: Options<Option>;
|
|
93
|
+
/**
|
|
94
|
+
* Boolean indicating whether user uses Apple device
|
|
95
|
+
*/
|
|
96
|
+
isAppleDevice: boolean;
|
|
97
|
+
}
|
|
98
|
+
export type AriaGuidance = (props: AriaGuidanceProps) => string;
|
|
99
|
+
export type AriaOnChange<Option, IsMulti extends boolean> = (props: AriaOnChangeProps<Option, IsMulti>) => string;
|
|
100
|
+
export type AriaOnFilter = (props: AriaOnFilterProps) => string;
|
|
101
|
+
export type AriaOnFocus<Option, Group extends GroupBase<Option> = GroupBase<Option>> = (props: AriaOnFocusProps<Option, Group>) => string;
|
|
102
|
+
export interface AriaLiveMessages<Option, IsMulti extends boolean, Group extends GroupBase<Option>> {
|
|
103
|
+
/**
|
|
104
|
+
* Guidance message used to convey component state and specific keyboard interactivity
|
|
105
|
+
*/
|
|
106
|
+
guidance?: (props: AriaGuidanceProps) => string;
|
|
107
|
+
/**
|
|
108
|
+
* OnChange message used to convey changes to value but also called when user selects disabled option
|
|
109
|
+
*/
|
|
110
|
+
onChange?: (props: AriaOnChangeProps<Option, IsMulti>) => string;
|
|
111
|
+
/**
|
|
112
|
+
* OnFilter message used to convey information about filtered results displayed in the menu
|
|
113
|
+
*/
|
|
114
|
+
onFilter?: (props: AriaOnFilterProps) => string;
|
|
115
|
+
/**
|
|
116
|
+
* OnFocus message used to convey information about the currently focused option or value
|
|
117
|
+
*/
|
|
118
|
+
onFocus?: (props: AriaOnFocusProps<Option, Group>) => string;
|
|
119
|
+
}
|
|
120
|
+
export declare const defaultAriaLiveMessages: {
|
|
121
|
+
guidance: (props: AriaGuidanceProps) => string;
|
|
122
|
+
onChange: <Option, IsMulti extends boolean>(props: AriaOnChangeProps<Option, IsMulti>) => string;
|
|
123
|
+
onFocus: <Option_1, Group extends GroupBase<Option_1>>(props: AriaOnFocusProps<Option_1, Group>) => string;
|
|
124
|
+
onFilter: (props: AriaOnFilterProps) => string;
|
|
125
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactElement, type RefAttributes } from 'react';
|
|
2
|
+
import Select from './select';
|
|
3
|
+
import { type GroupBase } from './types';
|
|
4
|
+
import { type AsyncAdditionalProps } from './use-async';
|
|
5
|
+
import { type CreatableAdditionalProps } from './use-creatable';
|
|
6
|
+
import { type StateManagerProps } from './use-state-manager';
|
|
7
|
+
export type AsyncCreatableProps<Option, IsMulti extends boolean, Group extends GroupBase<Option>> = StateManagerProps<Option, IsMulti, Group> & CreatableAdditionalProps<Option, Group> & AsyncAdditionalProps<Option, Group>;
|
|
8
|
+
type AsyncCreatableSelect = <Option = unknown, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: AsyncCreatableProps<Option, IsMulti, Group> & RefAttributes<Select<Option, IsMulti, Group>>) => ReactElement;
|
|
9
|
+
declare const AsyncCreatableSelect: AsyncCreatableSelect;
|
|
10
|
+
export default AsyncCreatableSelect;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactElement, type RefAttributes } from 'react';
|
|
2
|
+
import Select from './select';
|
|
3
|
+
import { type GroupBase } from './types';
|
|
4
|
+
import useAsync, { type AsyncProps } from './use-async';
|
|
5
|
+
export type { AsyncProps };
|
|
6
|
+
type AsyncSelect = <Option = unknown, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: AsyncProps<Option, IsMulti, Group> & RefAttributes<Select<Option, IsMulti, Group>>) => ReactElement;
|
|
7
|
+
declare const AsyncSelect: AsyncSelect;
|
|
8
|
+
export { useAsync };
|
|
9
|
+
export default AsyncSelect;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type GroupBase, type Option } from './types';
|
|
2
|
+
export declare const formatGroupLabel: <Option, Group extends GroupBase<Option>>(group: Group) => string;
|
|
3
|
+
export declare const getOptionLabel: (option: Option) => string;
|
|
4
|
+
export declare const getOptionValue: (option: Option) => string;
|
|
5
|
+
export declare const isOptionDisabled: (option: Option) => boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
import { jsx } from '@emotion/react';
|
|
7
|
+
import { type CommonPropsAndClassName, type CSSObjectWithLabel, type GroupBase } from '../types';
|
|
8
|
+
export interface ContainerProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the select is disabled.
|
|
11
|
+
*/
|
|
12
|
+
isDisabled: boolean;
|
|
13
|
+
isFocused: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The children to be rendered.
|
|
16
|
+
*/
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Inner props to be passed down to the container.
|
|
20
|
+
*/
|
|
21
|
+
innerProps: JSX.IntrinsicElements['div'];
|
|
22
|
+
}
|
|
23
|
+
export declare const containerCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ isDisabled, isRtl, }: ContainerProps<Option, IsMulti, Group>) => CSSObjectWithLabel;
|
|
24
|
+
export declare const SelectContainer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: ContainerProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
25
|
+
export interface ValueContainerProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
|
|
26
|
+
/**
|
|
27
|
+
* Props to be passed to the value container element.
|
|
28
|
+
*/
|
|
29
|
+
innerProps?: JSX.IntrinsicElements['div'];
|
|
30
|
+
/**
|
|
31
|
+
* The children to be rendered.
|
|
32
|
+
*/
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
isDisabled: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare const valueContainerCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ theme: { spacing }, isMulti, hasValue, selectProps: { controlShouldRenderValue }, }: ValueContainerProps<Option, IsMulti, Group>, unstyled: boolean) => CSSObjectWithLabel;
|
|
37
|
+
export declare const ValueContainer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: ValueContainerProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
38
|
+
export interface IndicatorsContainerProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
|
|
39
|
+
isDisabled: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The children to be rendered.
|
|
42
|
+
*/
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
/**
|
|
45
|
+
* Props to be passed to the indicators container element.
|
|
46
|
+
*/
|
|
47
|
+
innerProps?: {};
|
|
48
|
+
}
|
|
49
|
+
export declare const indicatorsContainerCSS: () => CSSObjectWithLabel;
|
|
50
|
+
export declare const IndicatorsContainer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: IndicatorsContainerProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode, type Ref } from 'react';
|
|
6
|
+
import { jsx } from '@emotion/react';
|
|
7
|
+
import { type CommonPropsAndClassName, type CSSObjectWithLabel, type GroupBase } from '../types';
|
|
8
|
+
export interface ControlProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
|
|
9
|
+
/**
|
|
10
|
+
* Children to render.
|
|
11
|
+
*/
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
innerRef: Ref<HTMLDivElement>;
|
|
14
|
+
/**
|
|
15
|
+
* The mouse down event and the innerRef to pass down to the controller element.
|
|
16
|
+
*/
|
|
17
|
+
innerProps: JSX.IntrinsicElements['div'];
|
|
18
|
+
/**
|
|
19
|
+
* Whether the select is disabled.
|
|
20
|
+
*/
|
|
21
|
+
isDisabled: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the select is focused.
|
|
24
|
+
*/
|
|
25
|
+
isFocused: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the select is expanded.
|
|
28
|
+
*/
|
|
29
|
+
menuIsOpen: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare const css: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ isDisabled, isFocused, theme: { colors, borderRadius, spacing }, }: ControlProps<Option, IsMulti, Group>, unstyled: boolean) => CSSObjectWithLabel;
|
|
32
|
+
declare const Control: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: ControlProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
33
|
+
export default Control;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
6
|
+
import { jsx } from '@emotion/react';
|
|
7
|
+
import { type SelectProps } from '../select';
|
|
8
|
+
import { type CommonProps, type CommonPropsAndClassName, type CSSObjectWithLabel, type CX, type GetStyles, type GroupBase, type Options, type Theme } from '../types';
|
|
9
|
+
export interface ForwardedHeadingProps<Option, Group extends GroupBase<Option>> {
|
|
10
|
+
id: string;
|
|
11
|
+
data: Group;
|
|
12
|
+
}
|
|
13
|
+
export interface GroupProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
|
|
14
|
+
/**
|
|
15
|
+
* The children to be rendered.
|
|
16
|
+
*/
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Component to wrap the label, receives headingProps.
|
|
20
|
+
*/
|
|
21
|
+
Heading: ComponentType<GroupHeadingProps<Option, IsMulti, Group>>;
|
|
22
|
+
/**
|
|
23
|
+
* Props to pass to Heading.
|
|
24
|
+
*/
|
|
25
|
+
headingProps: ForwardedHeadingProps<Option, Group>;
|
|
26
|
+
/**
|
|
27
|
+
* Props to be passed to the group element.
|
|
28
|
+
*/
|
|
29
|
+
innerProps: JSX.IntrinsicElements['div'];
|
|
30
|
+
/**
|
|
31
|
+
* Label to be displayed in the heading component.
|
|
32
|
+
*/
|
|
33
|
+
label: ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* The data of the group.
|
|
36
|
+
*/
|
|
37
|
+
data: Group;
|
|
38
|
+
options: Options<Option>;
|
|
39
|
+
}
|
|
40
|
+
export declare const groupCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ theme: { spacing } }: GroupProps<Option, IsMulti, Group>, unstyled: boolean) => CSSObjectWithLabel;
|
|
41
|
+
declare const Group: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: GroupProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
42
|
+
interface GroupHeadingPropsDefinedProps<Option, IsMulti extends boolean, Group extends GroupBase<Option>> extends ForwardedHeadingProps<Option, Group> {
|
|
43
|
+
className?: string | undefined;
|
|
44
|
+
selectProps: SelectProps<Option, IsMulti, Group>;
|
|
45
|
+
theme: Theme;
|
|
46
|
+
getStyles: GetStyles<Option, IsMulti, Group>;
|
|
47
|
+
getClassNames: CommonProps<Option, IsMulti, Group>['getClassNames'];
|
|
48
|
+
cx: CX;
|
|
49
|
+
}
|
|
50
|
+
export type GroupHeadingProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> = GroupHeadingPropsDefinedProps<Option, IsMulti, Group> & JSX.IntrinsicElements['div'];
|
|
51
|
+
export declare const groupHeadingCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ theme: { colors, spacing } }: GroupHeadingProps<Option, IsMulti, Group>, unstyled: boolean) => CSSObjectWithLabel;
|
|
52
|
+
export declare const GroupHeading: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: GroupHeadingProps<Option, IsMulti, Group>) => jsx.JSX.Element;
|
|
53
|
+
export default Group;
|