@rescui/select 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -0
- package/README.md +3 -0
- package/lib/common-prop-types.d.ts +25 -0
- package/lib/common-prop-types.js +18 -0
- package/lib/index.css +742 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -0
- package/lib/key-codes.d.ts +7 -0
- package/lib/key-codes.js +8 -0
- package/lib/parts/common-select.module.pcss.js +4 -0
- package/lib/parts/foldable.d.ts +34 -0
- package/lib/parts/foldable.js +297 -0
- package/lib/parts/form-trigger-wrapper.d.ts +13 -0
- package/lib/parts/form-trigger-wrapper.js +87 -0
- package/lib/parts/form-trigger.module.pcss.js +9 -0
- package/lib/parts/multiselect.d.ts +80 -0
- package/lib/parts/multiselect.js +399 -0
- package/lib/parts/native-select.d.ts +29 -0
- package/lib/parts/native-select.js +282 -0
- package/lib/parts/native-select.module.pcss.js +9 -0
- package/lib/parts/trigger.d.ts +37 -0
- package/lib/parts/trigger.js +307 -0
- package/lib/parts/trigger.module.pcss.js +30 -0
- package/lib/select.d.ts +86 -0
- package/lib/select.js +391 -0
- package/lib/state/multiselect/actions.d.ts +36 -0
- package/lib/state/multiselect/actions.js +45 -0
- package/lib/state/multiselect/reducer.d.ts +21 -0
- package/lib/state/multiselect/reducer.js +203 -0
- package/lib/state/multiselect/selectors.d.ts +6 -0
- package/lib/state/multiselect/selectors.js +39 -0
- package/lib/state/select/actions.d.ts +81 -0
- package/lib/state/select/actions.js +87 -0
- package/lib/state/select/reducer.d.ts +22 -0
- package/lib/state/select/reducer.js +199 -0
- package/lib/state/select/selectors.d.ts +20 -0
- package/lib/state/select/selectors.js +114 -0
- package/lib/types.d.ts +51 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +102 -0
- package/package.json +46 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ARROW_UP = "ArrowUp";
|
|
2
|
+
export declare const ARROW_DOWN = "ArrowDown";
|
|
3
|
+
export declare const SPACE = " ";
|
|
4
|
+
export declare const ESCAPE = "Escape";
|
|
5
|
+
export declare const ENTER = "Enter";
|
|
6
|
+
export declare const TAB = "Tab";
|
|
7
|
+
export declare const BACKSPACE = "Backspace";
|
package/lib/key-codes.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
export declare type FoldableProps = {
|
|
3
|
+
className?: string;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
gap?: number;
|
|
6
|
+
renderHiddenCounter?: (num: number, ref: React.Ref<HTMLElement>) => React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
declare type FoldableState = {
|
|
9
|
+
lastVisible: number;
|
|
10
|
+
renderingStage: number;
|
|
11
|
+
prevChildren: React.ReactNode;
|
|
12
|
+
};
|
|
13
|
+
export default class Foldable extends Component<FoldableProps, FoldableState> {
|
|
14
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
|
15
|
+
plusNRef: React.RefObject<HTMLElement>;
|
|
16
|
+
childrenEls: HTMLElement[];
|
|
17
|
+
childrenWidths: number[];
|
|
18
|
+
resizeObserver: ResizeObserver;
|
|
19
|
+
tagsResizeObserver: ResizeObserver;
|
|
20
|
+
constructor(props: FoldableProps);
|
|
21
|
+
static getDerivedStateFromProps(props: FoldableProps, state: FoldableState): {
|
|
22
|
+
prevChildren: React.ReactNode;
|
|
23
|
+
renderingStage: number;
|
|
24
|
+
};
|
|
25
|
+
observeChildren(): void;
|
|
26
|
+
componentDidMount(): void;
|
|
27
|
+
componentDidUpdate(): void;
|
|
28
|
+
componentWillUnmount(): void;
|
|
29
|
+
measureChildren: () => void;
|
|
30
|
+
recalculateLastVisibleAndSetStage: (nextStage?: number) => void;
|
|
31
|
+
renderChildren(lastVisible: number): React.FunctionComponentElement<any>[];
|
|
32
|
+
render(): JSX.Element;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import _Reflect$construct from "@babel/runtime-corejs3/core-js-stable/reflect/construct";
|
|
2
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
3
|
+
import _classCallCheck from "@babel/runtime-corejs3/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime-corejs3/helpers/esm/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime-corejs3/helpers/esm/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime-corejs3/helpers/esm/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime-corejs3/helpers/esm/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
10
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
11
|
+
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
12
|
+
var _excluded = ["children"];
|
|
13
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
|
+
|
|
19
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
20
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
21
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
22
|
+
import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
|
|
23
|
+
import React, { Component } from 'react';
|
|
24
|
+
import throttle from 'just-throttle';
|
|
25
|
+
import { ResizeObserver as ResizeObserver$1 } from '@juggle/resize-observer';
|
|
26
|
+
var ResizeObserver = typeof window !== 'undefined' && window.ResizeObserver || ResizeObserver$1;
|
|
27
|
+
|
|
28
|
+
function lastVisibleIndex(lens, maxLen, gap) {
|
|
29
|
+
var extra = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
30
|
+
var currentLen = 0;
|
|
31
|
+
|
|
32
|
+
for (var i = 0; i < lens.length; ++i) {
|
|
33
|
+
var gapIfNeeded = i === 0 ? 0 : gap;
|
|
34
|
+
|
|
35
|
+
if (currentLen + lens[i] + gapIfNeeded > maxLen - extra) {
|
|
36
|
+
return [i - 1, maxLen - currentLen];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
currentLen += lens[i] + gapIfNeeded;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return [lens.length - 1, maxLen - currentLen];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function measureElement(element) {
|
|
46
|
+
return {
|
|
47
|
+
width: element.offsetWidth,
|
|
48
|
+
height: element.offsetHeight
|
|
49
|
+
};
|
|
50
|
+
} // Flattens all child elements into a single list
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
var flatten = function flatten(children) {
|
|
54
|
+
var _context;
|
|
55
|
+
|
|
56
|
+
var flat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
57
|
+
|
|
58
|
+
var newFlat = _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(flat), _toConsumableArray(React.Children.toArray(children)));
|
|
59
|
+
|
|
60
|
+
if (children.props && children.props.children) {
|
|
61
|
+
return flatten(children.props.children, newFlat);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return newFlat;
|
|
65
|
+
}; // Strips all circular references and internal fields
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var simplify = function simplify(children) {
|
|
69
|
+
var flat = flatten(children);
|
|
70
|
+
return _mapInstanceProperty(flat).call(flat, function (_ref) {
|
|
71
|
+
var key = _ref.key,
|
|
72
|
+
type = _ref.type,
|
|
73
|
+
_ref$props = _ref.props,
|
|
74
|
+
flattenChildren = _ref$props.children,
|
|
75
|
+
props = _objectWithoutProperties(_ref$props, _excluded);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
key: key,
|
|
79
|
+
type: type,
|
|
80
|
+
props: props
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
var Foldable = /*#__PURE__*/function (_Component) {
|
|
86
|
+
_inherits(Foldable, _Component);
|
|
87
|
+
|
|
88
|
+
var _super = _createSuper(Foldable);
|
|
89
|
+
|
|
90
|
+
// eslint-disable-next-line react/sort-comp
|
|
91
|
+
function Foldable(props) {
|
|
92
|
+
var _this;
|
|
93
|
+
|
|
94
|
+
_classCallCheck(this, Foldable);
|
|
95
|
+
|
|
96
|
+
_this = _super.call(this, props);
|
|
97
|
+
|
|
98
|
+
_defineProperty(_assertThisInitialized(_this), "containerRef", void 0);
|
|
99
|
+
|
|
100
|
+
_defineProperty(_assertThisInitialized(_this), "plusNRef", void 0);
|
|
101
|
+
|
|
102
|
+
_defineProperty(_assertThisInitialized(_this), "childrenEls", void 0);
|
|
103
|
+
|
|
104
|
+
_defineProperty(_assertThisInitialized(_this), "childrenWidths", void 0);
|
|
105
|
+
|
|
106
|
+
_defineProperty(_assertThisInitialized(_this), "resizeObserver", void 0);
|
|
107
|
+
|
|
108
|
+
_defineProperty(_assertThisInitialized(_this), "tagsResizeObserver", void 0);
|
|
109
|
+
|
|
110
|
+
_defineProperty(_assertThisInitialized(_this), "measureChildren", function () {
|
|
111
|
+
var _assertThisInitialize = _assertThisInitialized(_this),
|
|
112
|
+
childrenEls = _assertThisInitialize.childrenEls;
|
|
113
|
+
|
|
114
|
+
if (childrenEls.some(function (r) {
|
|
115
|
+
return r === null;
|
|
116
|
+
})) {
|
|
117
|
+
throw new Error('childrenEls should be all not nulls');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_this.childrenWidths = _mapInstanceProperty(childrenEls).call(childrenEls, function (r) {
|
|
121
|
+
return measureElement(r).width;
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
_defineProperty(_assertThisInitialized(_this), "recalculateLastVisibleAndSetStage", function () {
|
|
126
|
+
var nextStage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
127
|
+
|
|
128
|
+
var _assertThisInitialize2 = _assertThisInitialized(_this),
|
|
129
|
+
containerRef = _assertThisInitialize2.containerRef,
|
|
130
|
+
plusNRef = _assertThisInitialize2.plusNRef;
|
|
131
|
+
|
|
132
|
+
if (!containerRef.current) {
|
|
133
|
+
throw new Error('containerRef should be not null during recalculate');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var containerWidth = measureElement(containerRef.current).width;
|
|
137
|
+
var plusNWidth = 0;
|
|
138
|
+
|
|
139
|
+
if (plusNRef.current) {
|
|
140
|
+
plusNWidth = measureElement(plusNRef.current).width;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var gap = _this.props.gap || 0;
|
|
144
|
+
|
|
145
|
+
var _lastVisibleIndex = lastVisibleIndex(_this.childrenWidths, containerWidth, gap, plusNWidth + gap + 1),
|
|
146
|
+
_lastVisibleIndex2 = _slicedToArray(_lastVisibleIndex, 2),
|
|
147
|
+
index = _lastVisibleIndex2[0],
|
|
148
|
+
extra = _lastVisibleIndex2[1];
|
|
149
|
+
|
|
150
|
+
var children = React.Children.toArray(_this.props.children);
|
|
151
|
+
var showLastChildIfFit = index === children.length - 2 && extra - gap - 1 > _this.childrenWidths[_this.childrenWidths.length - 1];
|
|
152
|
+
var newLastVisible = index + (showLastChildIfFit ? 1 : 0);
|
|
153
|
+
var newState = {
|
|
154
|
+
lastVisible: newLastVisible,
|
|
155
|
+
renderingStage: nextStage ? nextStage : _this.state.renderingStage
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
_this.setState(newState);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
_this.state = {
|
|
162
|
+
lastVisible: props.children.length - 1,
|
|
163
|
+
renderingStage: 0,
|
|
164
|
+
prevChildren: props.children
|
|
165
|
+
};
|
|
166
|
+
_this.containerRef = /*#__PURE__*/React.createRef();
|
|
167
|
+
_this.plusNRef = /*#__PURE__*/React.createRef();
|
|
168
|
+
_this.childrenEls = [];
|
|
169
|
+
_this.childrenWidths = [];
|
|
170
|
+
return _this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_createClass(Foldable, [{
|
|
174
|
+
key: "observeChildren",
|
|
175
|
+
value: function observeChildren() {
|
|
176
|
+
var _this2 = this;
|
|
177
|
+
|
|
178
|
+
var isInitialized = false;
|
|
179
|
+
|
|
180
|
+
var onTagsSizeChangedThrottled = function onTagsSizeChangedThrottled() {
|
|
181
|
+
if (isInitialized && // skip updating if the container is not displayed on the page
|
|
182
|
+
_this2.containerRef.current.offsetParent !== null) {
|
|
183
|
+
_this2.setState({
|
|
184
|
+
renderingStage: 0
|
|
185
|
+
});
|
|
186
|
+
} else {
|
|
187
|
+
isInitialized = true;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
if (this.tagsResizeObserver) {
|
|
192
|
+
this.tagsResizeObserver.disconnect();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.tagsResizeObserver = new ResizeObserver(onTagsSizeChangedThrottled);
|
|
196
|
+
this.childrenEls.forEach(function (child) {
|
|
197
|
+
return _this2.tagsResizeObserver.observe(child);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "componentDidMount",
|
|
202
|
+
value: function componentDidMount() {
|
|
203
|
+
var _this3 = this;
|
|
204
|
+
|
|
205
|
+
var renderingStage = this.state.renderingStage;
|
|
206
|
+
|
|
207
|
+
if (renderingStage === 0) {
|
|
208
|
+
this.measureChildren();
|
|
209
|
+
this.observeChildren();
|
|
210
|
+
this.recalculateLastVisibleAndSetStage(1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
var onSizeChangedThrottled = throttle(function () {
|
|
214
|
+
if (_this3.state.renderingStage === 2) {
|
|
215
|
+
_this3.recalculateLastVisibleAndSetStage();
|
|
216
|
+
}
|
|
217
|
+
}, 50);
|
|
218
|
+
this.resizeObserver = new ResizeObserver(onSizeChangedThrottled);
|
|
219
|
+
this.resizeObserver.observe(this.containerRef.current);
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "componentDidUpdate",
|
|
223
|
+
value: function componentDidUpdate() {
|
|
224
|
+
var renderingStage = this.state.renderingStage;
|
|
225
|
+
|
|
226
|
+
if (renderingStage === 0) {
|
|
227
|
+
this.measureChildren();
|
|
228
|
+
this.observeChildren();
|
|
229
|
+
this.recalculateLastVisibleAndSetStage(1);
|
|
230
|
+
} else if (renderingStage === 1) {
|
|
231
|
+
this.recalculateLastVisibleAndSetStage(2);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}, {
|
|
235
|
+
key: "componentWillUnmount",
|
|
236
|
+
value: function componentWillUnmount() {
|
|
237
|
+
if (this.resizeObserver) {
|
|
238
|
+
this.resizeObserver.disconnect();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (this.tagsResizeObserver) {
|
|
242
|
+
this.tagsResizeObserver.disconnect();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}, {
|
|
246
|
+
key: "renderChildren",
|
|
247
|
+
value: function renderChildren(lastVisible) {
|
|
248
|
+
var _context2,
|
|
249
|
+
_this4 = this;
|
|
250
|
+
|
|
251
|
+
var children = React.Children.toArray(this.props.children);
|
|
252
|
+
return _mapInstanceProperty(_context2 = _sliceInstanceProperty(children).call(children, 0, lastVisible + 1)).call(_context2, function (child, i) {
|
|
253
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
|
254
|
+
ref: function ref(el) {
|
|
255
|
+
if (el) {
|
|
256
|
+
_this4.childrenEls[i] = el;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}, {
|
|
263
|
+
key: "render",
|
|
264
|
+
value: function render() {
|
|
265
|
+
var renderHiddenCounter = this.props.renderHiddenCounter;
|
|
266
|
+
var children = React.Children.toArray(this.props.children);
|
|
267
|
+
var lastVisible = this.state.renderingStage === 0 ? children.length - 1 : this.state.lastVisible;
|
|
268
|
+
|
|
269
|
+
if (children.length !== this.childrenEls.length) {
|
|
270
|
+
var _context3;
|
|
271
|
+
|
|
272
|
+
this.childrenEls = _sliceInstanceProperty(_context3 = this.childrenEls).call(_context3, 0, children.length);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
276
|
+
className: this.props.className,
|
|
277
|
+
ref: this.containerRef
|
|
278
|
+
}, this.renderChildren(lastVisible), lastVisible !== children.length - 1 ? renderHiddenCounter(children.length - lastVisible - 1, this.plusNRef) : null);
|
|
279
|
+
}
|
|
280
|
+
}], [{
|
|
281
|
+
key: "getDerivedStateFromProps",
|
|
282
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
283
|
+
if (_JSON$stringify(simplify(props.children)) !== _JSON$stringify(simplify(state.prevChildren))) {
|
|
284
|
+
return {
|
|
285
|
+
prevChildren: props.children,
|
|
286
|
+
renderingStage: 0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
}]);
|
|
293
|
+
|
|
294
|
+
return Foldable;
|
|
295
|
+
}(Component);
|
|
296
|
+
|
|
297
|
+
export default Foldable;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Theme } from '@rescui/ui-contexts';
|
|
3
|
+
import { SelectSize } from '../types';
|
|
4
|
+
export declare type FormTriggerWrapperProps = {
|
|
5
|
+
size?: SelectSize;
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
className?: string;
|
|
8
|
+
error?: boolean | React.ReactNode;
|
|
9
|
+
label?: React.ReactNode;
|
|
10
|
+
note?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
declare const FormTriggerWrapper: React.FC<FormTriggerWrapperProps>;
|
|
13
|
+
export default FormTriggerWrapper;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useTheme, ThemeProvider } from '@rescui/ui-contexts';
|
|
4
|
+
import { useTextStyles, createTextCn } from '@rescui/typography';
|
|
5
|
+
import styles from './form-trigger.module.pcss.js';
|
|
6
|
+
var SIZE_TO_TEXT = {
|
|
7
|
+
l: 'rs-text-1',
|
|
8
|
+
m: 'rs-text-2',
|
|
9
|
+
s: 'rs-text-3'
|
|
10
|
+
};
|
|
11
|
+
var SIZE_STYLES = {
|
|
12
|
+
l: styles.sizeL,
|
|
13
|
+
m: styles.sizeM,
|
|
14
|
+
s: styles.sizeS
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function getErrorAndNoteTextClass(size, theme) {
|
|
18
|
+
var textCn = createTextCn(theme);
|
|
19
|
+
return textCn(size === 'l' ? 'rs-text-2' : 'rs-text-3');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var Note = function Note(_ref) {
|
|
23
|
+
var children = _ref.children,
|
|
24
|
+
size = _ref.size;
|
|
25
|
+
var theme = useTheme();
|
|
26
|
+
|
|
27
|
+
if (!children) {
|
|
28
|
+
return null;
|
|
29
|
+
} else {
|
|
30
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
className: cn(styles.note, getErrorAndNoteTextClass(size, theme))
|
|
32
|
+
}, children);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var Error = function Error(_ref2) {
|
|
37
|
+
var children = _ref2.children,
|
|
38
|
+
size = _ref2.size;
|
|
39
|
+
var theme = useTheme();
|
|
40
|
+
|
|
41
|
+
if (!children) {
|
|
42
|
+
return null;
|
|
43
|
+
} else {
|
|
44
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: cn(styles.errorMessage, getErrorAndNoteTextClass(size, theme))
|
|
46
|
+
}, children);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var Label = function Label(_ref3) {
|
|
51
|
+
var children = _ref3.children,
|
|
52
|
+
size = _ref3.size;
|
|
53
|
+
var textCn = useTextStyles();
|
|
54
|
+
|
|
55
|
+
if (!children) {
|
|
56
|
+
return null;
|
|
57
|
+
} else {
|
|
58
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
className: cn(styles.label, textCn(SIZE_TO_TEXT[size]))
|
|
60
|
+
}, children);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var FormTriggerWrapper = function FormTriggerWrapper(_ref4) {
|
|
65
|
+
var size = _ref4.size,
|
|
66
|
+
themeFromProps = _ref4.theme,
|
|
67
|
+
className = _ref4.className,
|
|
68
|
+
error = _ref4.error,
|
|
69
|
+
label = _ref4.label,
|
|
70
|
+
note = _ref4.note,
|
|
71
|
+
children = _ref4.children;
|
|
72
|
+
var theme = useTheme(themeFromProps);
|
|
73
|
+
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
74
|
+
theme: theme
|
|
75
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: cn(className, SIZE_STYLES[size]),
|
|
77
|
+
"data-test": "select-wrapper"
|
|
78
|
+
}, /*#__PURE__*/React.createElement(Label, {
|
|
79
|
+
size: size
|
|
80
|
+
}, label), children, /*#__PURE__*/React.createElement(Error, {
|
|
81
|
+
size: size
|
|
82
|
+
}, error), /*#__PURE__*/React.createElement(Note, {
|
|
83
|
+
size: size
|
|
84
|
+
}, note)));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default FormTriggerWrapper;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Theme } from '@rescui/ui-contexts';
|
|
3
|
+
import { SelectOptionOrGroup, SelectOption, SelectSize, SelectMode, NoOptionsMessage } from '../types';
|
|
4
|
+
export interface MultiselectProps {
|
|
5
|
+
/**
|
|
6
|
+
* Additional class name
|
|
7
|
+
*/
|
|
8
|
+
className?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array of options
|
|
11
|
+
*/
|
|
12
|
+
options: SelectOptionOrGroup[];
|
|
13
|
+
/**
|
|
14
|
+
* Default value for Multiselect state. `onChange` callback is required.
|
|
15
|
+
*/
|
|
16
|
+
defaultValue?: SelectOption[];
|
|
17
|
+
/**
|
|
18
|
+
* Is Multiselect preserve single string
|
|
19
|
+
*/
|
|
20
|
+
isSingleLine?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Is Multiselect supports clear the value
|
|
23
|
+
*/
|
|
24
|
+
isClearable?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Is Multiselect has been disabled
|
|
27
|
+
*/
|
|
28
|
+
isDisabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Is loader displayed inside select
|
|
31
|
+
*/
|
|
32
|
+
isLoading?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Input name attribute
|
|
35
|
+
*/
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Size
|
|
39
|
+
*/
|
|
40
|
+
size?: SelectSize;
|
|
41
|
+
/**
|
|
42
|
+
* Appearance mode
|
|
43
|
+
*/
|
|
44
|
+
mode?: SelectMode;
|
|
45
|
+
/**
|
|
46
|
+
* Appearance theme
|
|
47
|
+
*/
|
|
48
|
+
theme?: Theme;
|
|
49
|
+
/**
|
|
50
|
+
* Value of the select
|
|
51
|
+
*/
|
|
52
|
+
value?: SelectOption[];
|
|
53
|
+
/**
|
|
54
|
+
* Change value callback. `value => ...`
|
|
55
|
+
*/
|
|
56
|
+
onChange?: (newValue: SelectOption[]) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Error state flag or React.ReactNode (use with forms)
|
|
59
|
+
*/
|
|
60
|
+
error?: boolean | React.ReactNode;
|
|
61
|
+
/**
|
|
62
|
+
* Label element upper then Multiselect element (use with forms)
|
|
63
|
+
*/
|
|
64
|
+
label?: React.ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* Placement of dropdown element
|
|
67
|
+
*/
|
|
68
|
+
placement?: 'auto-start' | 'auto' | 'auto-end' | 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-end' | 'bottom' | 'bottom-start' | 'left-end' | 'left' | 'left-start';
|
|
69
|
+
/**
|
|
70
|
+
* Note element below then Multiselect element (use with forms)
|
|
71
|
+
*/
|
|
72
|
+
note?: React.ReactNode;
|
|
73
|
+
id?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Text to display when there are no options
|
|
76
|
+
*/
|
|
77
|
+
noOptionsMessage?: NoOptionsMessage;
|
|
78
|
+
}
|
|
79
|
+
declare const Multiselect: React.FC<MultiselectProps>;
|
|
80
|
+
export default Multiselect;
|