1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
11 |
|
12 | var _reactSelect = _interopRequireDefault(require("react-select"));
|
13 |
|
14 | var _Creatable = _interopRequireDefault(require("react-select/lib/Creatable"));
|
15 |
|
16 | var _Shimmer = _interopRequireDefault(require("./Shimmer"));
|
17 |
|
18 | var _reactWithStyles = require("react-with-styles");
|
19 |
|
20 | var _withStyles = require("../helpers/withStyles");
|
21 |
|
22 | var _CinnectaTheme = _interopRequireDefault(require("../themes/CinnectaTheme"));
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
27 |
|
28 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
29 |
|
30 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
31 |
|
32 | var propTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
|
33 | actionLink: _propTypes.default.string,
|
34 | autoCapitalize: _propTypes.default.bool,
|
35 | autoComplete: _propTypes.default.oneOf(['off', 'on']),
|
36 | autoCorrect: _propTypes.default.any,
|
37 | autoFocus: _propTypes.default.bool,
|
38 | book: _propTypes.default.bool,
|
39 | borderless: _propTypes.default.bool,
|
40 | clearable: _propTypes.default.bool,
|
41 | closeMenuOnSelect: _propTypes.default.bool,
|
42 | defaultValue: _propTypes.default.object,
|
43 | disabled: _propTypes.default.bool,
|
44 | flat: _propTypes.default.bool,
|
45 | floating: _propTypes.default.bool,
|
46 | focusBorderless: _propTypes.default.bool,
|
47 | id: _propTypes.default.string,
|
48 | inline: _propTypes.default.bool,
|
49 | inputRef: _propTypes.default.func,
|
50 | insidePrefix: _propTypes.default.bool,
|
51 | insideSuffix: _propTypes.default.bool,
|
52 | invalid: _propTypes.default.bool,
|
53 | inverse: _propTypes.default.bool,
|
54 | loading: _propTypes.default.bool,
|
55 | large: _propTypes.default.bool,
|
56 | loadingMessage: _propTypes.default.string,
|
57 | mask: _propTypes.default.func,
|
58 | maxLength: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
59 | multiple: _propTypes.default.bool,
|
60 | name: _propTypes.default.string.isRequired,
|
61 | noOptionsMessage: _propTypes.default.string,
|
62 | onBlur: _propTypes.default.func,
|
63 | onChange: _propTypes.default.func,
|
64 | onClear: _propTypes.default.func,
|
65 | onCreateOption: _propTypes.default.func,
|
66 | onFocus: _propTypes.default.func,
|
67 | onKeyDown: _propTypes.default.func,
|
68 | placeholder: _propTypes.default.string,
|
69 | prefix: _propTypes.default.object,
|
70 | prefixSeparator: _propTypes.default.bool,
|
71 | readOnly: _propTypes.default.bool,
|
72 | refForFocus: _propTypes.default.func,
|
73 | removeMargins: _propTypes.default.bool,
|
74 | removePrefixSpacing: _propTypes.default.bool,
|
75 | removeSuffixSpacing: _propTypes.default.bool,
|
76 | right: _propTypes.default.bool,
|
77 | shimmer: _propTypes.default.bool,
|
78 | showFakeValuePlaceholder: _propTypes.default.bool,
|
79 | showOverflowEllipsis: _propTypes.default.bool,
|
80 | small: _propTypes.default.bool,
|
81 | spellCheck: _propTypes.default.any,
|
82 | suffix: _propTypes.default.object,
|
83 | suffixSeparator: _propTypes.default.bool,
|
84 | suffixText: _propTypes.default.any,
|
85 | type: _propTypes.default.string,
|
86 | underlineFocus: _propTypes.default.bool,
|
87 | value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.array])
|
88 | });
|
89 |
|
90 | var defaultProps = {
|
91 | options: [],
|
92 | placeholder: 'Selecione...',
|
93 | clearable: false,
|
94 | closeMenuOnSelect: true,
|
95 | noOptionsMessage: 'Sem opções...'
|
96 | };
|
97 | var selectStyles = {
|
98 | option: function option(base, state) {
|
99 | return {
|
100 |
|
101 | appearance: 'none',
|
102 | borderWidth: 0,
|
103 | height: _CinnectaTheme.default.units(2),
|
104 | paddingTop: _CinnectaTheme.default.units(0.25),
|
105 | paddingRight: _CinnectaTheme.default.units(0.75),
|
106 | paddingBottom: _CinnectaTheme.default.units(0.25),
|
107 | paddingLeft: _CinnectaTheme.default.units(0.75),
|
108 | borderRadius: _CinnectaTheme.default.radius,
|
109 | fontSize: _CinnectaTheme.default.units(0.95),
|
110 | display: 'flex',
|
111 | alignItems: 'center',
|
112 | outline: 0,
|
113 | position: 'relative',
|
114 | margin: 0,
|
115 | fontWeight: 500,
|
116 | fontFamily: _CinnectaTheme.default.font.default,
|
117 | cursor: 'pointer',
|
118 | boxSizing: 'border-box',
|
119 | background: state.isSelected ? _CinnectaTheme.default.color.blueGrayDark : state.isFocused ? _CinnectaTheme.default.color.grayLight : _CinnectaTheme.default.color.white,
|
120 | color: state.isSelected ? _CinnectaTheme.default.color.white : _CinnectaTheme.default.color.primary,
|
121 | whiteSpace: 'nowrap',
|
122 | '&:hover': {
|
123 | background: !state.isSelected && _CinnectaTheme.default.color.blueGrayLight
|
124 | },
|
125 | '&:active': {
|
126 | background: !state.isSelected && _CinnectaTheme.default.color.blueGray
|
127 | }
|
128 | };
|
129 | },
|
130 | menu: function menu(base, state) {
|
131 | return {
|
132 |
|
133 | position: 'absolute',
|
134 | marginTop: _CinnectaTheme.default.units(.25),
|
135 | top: '100%',
|
136 | backgroundColor: _CinnectaTheme.default.color.white,
|
137 | boxShadow: "0 ".concat(_CinnectaTheme.default.units(0.5), " ").concat(_CinnectaTheme.default.units(0.75), " ").concat(_CinnectaTheme.default.units(-0.45), " ").concat(_CinnectaTheme.default.color.shadow),
|
138 | padding: _CinnectaTheme.default.units(0.5),
|
139 | borderRadius: _CinnectaTheme.default.radius,
|
140 | borderWidth: 1,
|
141 | borderStyle: 'solid',
|
142 | borderColor: _CinnectaTheme.default.color.blueGrayLight,
|
143 | zIndex: 2,
|
144 | minWidth: '100%',
|
145 | boxSizing: 'border-box'
|
146 |
|
147 |
|
148 | };
|
149 | },
|
150 | menuList: function menuList(base) {
|
151 | return _objectSpread({}, base, {
|
152 | padding: 0
|
153 | });
|
154 | },
|
155 | control: function control(base) {
|
156 | return {
|
157 |
|
158 | width: '100%',
|
159 | display: 'flex',
|
160 | alignItems: 'center',
|
161 | flex: 1,
|
162 | flexWrap: 'wrap',
|
163 | position: 'relative',
|
164 | boxSizing: 'border-box'
|
165 | };
|
166 | },
|
167 | container: function container() {
|
168 | return {
|
169 | width: '100%'
|
170 | };
|
171 | },
|
172 | indicatorSeparator: function indicatorSeparator() {
|
173 | return {
|
174 | display: 'none'
|
175 | };
|
176 | },
|
177 | dropdownIndicator: function dropdownIndicator(base, state) {
|
178 | return _objectSpread({}, base, {
|
179 | fill: _CinnectaTheme.default.color.grayDark,
|
180 | color: state.isFocused ? _CinnectaTheme.default.color.grayDarker : _CinnectaTheme.default.color.grayDark,
|
181 | opacity: 1,
|
182 | width: 32,
|
183 | '&:hover': {
|
184 | color: _CinnectaTheme.default.color.grayDarker
|
185 | }
|
186 | });
|
187 | },
|
188 | singleValue: function singleValue(base, state) {
|
189 | return _objectSpread({}, base, {
|
190 | transition: 'opacity 300ms',
|
191 | color: _CinnectaTheme.default.color.grayDarker,
|
192 | position: 'static',
|
193 | transform: 'none',
|
194 | maxWidth: '100%',
|
195 | order: 2
|
196 | });
|
197 | },
|
198 | input: function input(base) {
|
199 | return _objectSpread({}, base, {
|
200 | color: _CinnectaTheme.default.color.grayDarker,
|
201 | margin: 0,
|
202 | padding: 0,
|
203 | order: 1
|
204 | });
|
205 | },
|
206 | placeholder: function placeholder(base) {
|
207 | return _objectSpread({}, base, {
|
208 | color: _CinnectaTheme.default.input.placeholderColor,
|
209 | position: 'static',
|
210 | transform: 'none',
|
211 | order: 2
|
212 | });
|
213 | },
|
214 | multiValue: function multiValue(base) {
|
215 | return _objectSpread({}, base, {
|
216 | background: _CinnectaTheme.default.color.gray,
|
217 | color: _CinnectaTheme.default.color.grayDarker
|
218 | });
|
219 | },
|
220 | multiValueRemove: function multiValueRemove(base) {
|
221 | return _objectSpread({}, base, {
|
222 | borderRadius: '50%',
|
223 | height: 18,
|
224 | width: 18,
|
225 | padding: 0,
|
226 | marginTop: 2,
|
227 | marginLeft: 4,
|
228 | marginRight: 2,
|
229 | display: 'flex',
|
230 | alignItems: 'center',
|
231 | justifyContent: 'center',
|
232 | color: _CinnectaTheme.default.color.grayDarker,
|
233 | fill: _CinnectaTheme.default.color.grayDarker,
|
234 | '&:hover': {
|
235 | background: _CinnectaTheme.default.color.shadowWeak,
|
236 | color: _CinnectaTheme.default.color.grayDarker,
|
237 | fill: _CinnectaTheme.default.color.grayDarker
|
238 | }
|
239 | });
|
240 | },
|
241 | multiValueLabel: function multiValueLabel(base) {
|
242 | return _objectSpread({}, base, {
|
243 | color: _CinnectaTheme.default.color.grayDarker
|
244 | });
|
245 | }
|
246 | };
|
247 |
|
248 | var SelectOnly = function SelectOnly(_ref) {
|
249 | var autocomplete = _ref.autocomplete,
|
250 | autoFocus = _ref.autoFocus,
|
251 | book = _ref.book,
|
252 | borderless = _ref.borderless,
|
253 | clearable = _ref.clearable,
|
254 | css = _ref.css,
|
255 | closeMenuOnSelect = _ref.closeMenuOnSelect,
|
256 | defaultValue = _ref.defaultValue,
|
257 | disabled = _ref.disabled,
|
258 | flat = _ref.flat,
|
259 | floating = _ref.floating,
|
260 | focusBorderless = _ref.focusBorderless,
|
261 | id = _ref.id,
|
262 | inline = _ref.inline,
|
263 | inputRef = _ref.inputRef,
|
264 | insidePrefix = _ref.insidePrefix,
|
265 | insideSuffix = _ref.insideSuffix,
|
266 | invalid = _ref.invalid,
|
267 | inverse = _ref.inverse,
|
268 | large = _ref.large,
|
269 | loading = _ref.loading,
|
270 | multiple = _ref.multiple,
|
271 | name = _ref.name,
|
272 | _noOptionsMessage = _ref.noOptionsMessage,
|
273 | onBlur = _ref.onBlur,
|
274 | onChange = _ref.onChange,
|
275 | onClear = _ref.onClear,
|
276 | onCreateOption = _ref.onCreateOption,
|
277 | onFocus = _ref.onFocus,
|
278 | onKeyDown = _ref.onKeyDown,
|
279 | options = _ref.options,
|
280 | placeholder = _ref.placeholder,
|
281 | prefix = _ref.prefix,
|
282 | prefixSeparator = _ref.prefixSeparator,
|
283 | readOnly = _ref.readOnly,
|
284 | refForFocus = _ref.refForFocus,
|
285 | removeMargins = _ref.removeMargins,
|
286 | removePrefixSpacing = _ref.removePrefixSpacing,
|
287 | removeSuffixSpacing = _ref.removeSuffixSpacing,
|
288 | shimmer = _ref.shimmer,
|
289 | showFakeValuePlaceholder = _ref.showFakeValuePlaceholder,
|
290 | showOverflowEllipsis = _ref.showOverflowEllipsis,
|
291 | small = _ref.small,
|
292 | spellCheck = _ref.spellCheck,
|
293 | styles = _ref.styles,
|
294 | suffix = _ref.suffix,
|
295 | suffixSeparator = _ref.suffixSeparator,
|
296 | suffixText = _ref.suffixText,
|
297 | underlineFocus = _ref.underlineFocus,
|
298 | value = _ref.value;
|
299 | return _react.default.createElement("div", css(styles.selectOnly, !inline && styles.block, borderless && styles.borderless, disabled && styles.selectOnly_disabled, invalid && styles.selectOnly_invalid, flat && styles.selectOnly_flat, floating && styles.selectOnly_floating, focusBorderless && styles.selectOnly_focusBorderless, loading && styles.selectOnly_disabled, small && styles.selectOnly_small, removeMargins && styles.noMargin, insidePrefix && styles.selectOnly_insidePrefix, insideSuffix && styles.selectOnly_insideSuffix), shimmer && _react.default.createElement("div", css(styles.shimmer), _react.default.createElement(_Shimmer.default, {
|
300 | width: "100%",
|
301 | height: "100%"
|
302 | })), prefix && _react.default.createElement(_react.Fragment, null, _react.default.createElement("div", css(styles.selectOnly__prefix, removePrefixSpacing && styles.noPadding), prefix), prefixSeparator && _react.default.createElement("div", css(styles.separator, styles.separator_prefix, removePrefixSpacing && styles.noMargin))), onCreateOption ? _react.default.createElement(_Creatable.default, {
|
303 | closeMenuOnSelect: closeMenuOnSelect,
|
304 | formatCreateLabel: function formatCreateLabel(value) {
|
305 | return "Criar \"".concat(value, "\"");
|
306 | },
|
307 | defaultValue: defaultValue,
|
308 | isDisabled: disabled || loading,
|
309 | isLoading: loading,
|
310 | isClearable: clearable,
|
311 | isMulti: multiple,
|
312 | isSearchable: autocomplete,
|
313 | isValidNewOption: function isValidNewOption(inputValue, selectValue, selectOptions) {
|
314 | var isNotDuplicated = !selectOptions.map(function (option) {
|
315 | return option.label;
|
316 | }).includes(inputValue);
|
317 | var isNotEmpty = inputValue !== '';
|
318 | return isNotEmpty && isNotDuplicated;
|
319 | },
|
320 | name: name,
|
321 | noOptionsMessage: function noOptionsMessage() {
|
322 | return _noOptionsMessage;
|
323 | },
|
324 | onBlur: onBlur,
|
325 | onChange: onChange,
|
326 | onCreateOption: onCreateOption,
|
327 | onFocus: onFocus,
|
328 | onKeyDown: onKeyDown,
|
329 | options: options,
|
330 | placeholder: placeholder,
|
331 | styles: selectStyles,
|
332 | theme: function theme(_theme) {
|
333 | return _objectSpread({}, _theme, {
|
334 | width: '100%',
|
335 | borderRadius: 0,
|
336 | colors: _objectSpread({}, _theme.colors, {
|
337 | text: 'orangered',
|
338 | primary25: _CinnectaTheme.default.color.blueGray,
|
339 | primary: _CinnectaTheme.default.color.primary
|
340 | })
|
341 | });
|
342 | },
|
343 | value: value
|
344 | }) : _react.default.createElement(_reactSelect.default, {
|
345 | closeMenuOnSelect: closeMenuOnSelect,
|
346 | defaultValue: defaultValue,
|
347 | isDisabled: disabled,
|
348 | isLoading: loading,
|
349 | isClearable: clearable,
|
350 | isMulti: multiple,
|
351 | isSearchable: autocomplete,
|
352 | name: name,
|
353 | noOptionsMessage: function noOptionsMessage() {
|
354 | return _noOptionsMessage;
|
355 | },
|
356 | onBlur: onBlur,
|
357 | onChange: onChange,
|
358 | onFocus: onFocus,
|
359 | onKeyDown: onKeyDown,
|
360 | options: options,
|
361 | placeholder: placeholder,
|
362 | styles: selectStyles,
|
363 | theme: function theme(_theme2) {
|
364 | return _objectSpread({}, _theme2, {
|
365 | width: '100%',
|
366 | borderRadius: 0,
|
367 | colors: _objectSpread({}, _theme2.colors, {
|
368 | text: 'orangered',
|
369 | primary25: _CinnectaTheme.default.color.blueGray,
|
370 | primary: _CinnectaTheme.default.color.primary
|
371 | })
|
372 | });
|
373 | },
|
374 | value: value
|
375 | }), suffix && _react.default.createElement(_react.Fragment, null, suffixSeparator && _react.default.createElement("div", css(styles.separator, styles.separator_suffix, removeSuffixSpacing && styles.noMargin)), _react.default.createElement("div", css(styles.selectOnly__suffix, removeSuffixSpacing && styles.noPadding), suffix)));
|
376 | };
|
377 |
|
378 | SelectOnly.propTypes = propTypes;
|
379 | SelectOnly.defaultProps = defaultProps;
|
380 | var SelectOnlyWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
|
381 | var input = _ref2.input,
|
382 | color = _ref2.color,
|
383 | shadow = _ref2.shadow;
|
384 | return {
|
385 | selectOnly: _objectSpread({}, input.default, {
|
386 | display: 'inline-flex',
|
387 | position: 'relative',
|
388 | flexWrap: 'nowrap',
|
389 | alignItems: 'center',
|
390 | boxSizing: 'border-box',
|
391 | minHeight: 40,
|
392 | ':focus-within': _objectSpread({}, input.focus)
|
393 | }),
|
394 | selectOnly_focusBorderless: {
|
395 | ':focus-within': {
|
396 | borderWidth: 0
|
397 | }
|
398 | },
|
399 | selectOnly_insidePrefix: {
|
400 | height: 38
|
401 | },
|
402 | selectOnly_insideSuffix: {
|
403 | height: 38
|
404 | },
|
405 | selectOnly_disabled: _objectSpread({}, input.disabled),
|
406 | selectOnly_invalid: _objectSpread({}, input.invalid),
|
407 | selectOnly_flat: {
|
408 | borderColor: color.blueGray,
|
409 | background: color.white
|
410 | },
|
411 | selectOnly_floating: _objectSpread({}, shadow.level1, {
|
412 | background: color.white,
|
413 | borderColor: color.white
|
414 | }),
|
415 | selectOnly_small: _objectSpread({}, input.small),
|
416 | noMargin: {
|
417 | marginTop: 0,
|
418 | marginRight: 0,
|
419 | marginBottom: 0,
|
420 | marginLeft: 0
|
421 | },
|
422 | noPadding: {
|
423 | paddingTop: 0,
|
424 | paddingRight: 0,
|
425 | paddingBottom: 0,
|
426 | paddingLeft: 0
|
427 | },
|
428 | selectOnly__input: _objectSpread({}, input.default, {
|
429 | border: 0,
|
430 | margin: 0,
|
431 | background: color.transparent,
|
432 | width: '100%',
|
433 | height: 'auto',
|
434 | paddingTop: input.verticalPadding,
|
435 | paddingRight: input.horizontalPadding,
|
436 | paddingBottom: input.verticalPadding,
|
437 | paddingLeft: input.horizontalPadding,
|
438 | boxSizing: 'border-box',
|
439 | '::-ms-clear': {
|
440 | display: 'none'
|
441 | },
|
442 | ':focus': {
|
443 | outline: 'none',
|
444 | boxShadow: 'none',
|
445 | border: 0
|
446 | }
|
447 | }),
|
448 | selectOnly__input_ellipsis: {
|
449 | textOverflow: 'ellipsis'
|
450 | },
|
451 | selectOnly__input_defaultPlaceholder: {
|
452 | '::placeholder': {
|
453 | color: input.placeholderColor,
|
454 | opacity: 1
|
455 | }
|
456 | },
|
457 | selectOnly__input_fakeValuePlaceholder: {
|
458 | '::placeholder': {
|
459 | color: input.color,
|
460 | opacity: 1
|
461 | }
|
462 | },
|
463 | selectOnly__input_inversePlaceholder: {
|
464 | '::placeholder': {
|
465 | color: color.white,
|
466 | opacity: 1
|
467 | }
|
468 | },
|
469 | selectOnly__prefix: {
|
470 | paddingLeft: input.horizontalPadding,
|
471 | flexShrink: 0
|
472 | },
|
473 | selectOnly__suffix: {
|
474 | paddingRight: input.horizontalPadding,
|
475 | flexShrink: 0
|
476 | },
|
477 | separator: {
|
478 | width: 1,
|
479 | height: 24,
|
480 | background: color.gray,
|
481 | flexShrink: 0
|
482 | },
|
483 | separator_prefix: {
|
484 | marginLeft: input.horizontalPadding
|
485 | },
|
486 | separator_suffix: {
|
487 | marginRight: input.horizontalPadding
|
488 | },
|
489 | block: {
|
490 | display: 'flex',
|
491 | width: '100%'
|
492 | },
|
493 | borderless: {
|
494 | borderColor: input.background
|
495 | },
|
496 | shimmer: {
|
497 | position: 'absolute',
|
498 | width: '100%',
|
499 | height: '100%',
|
500 | top: 0,
|
501 | right: 0,
|
502 | bottom: 0,
|
503 | left: 0
|
504 | }
|
505 | };
|
506 | })(SelectOnly);
|
507 | var _default = SelectOnlyWithStyles;
|
508 | exports.default = _default; |
\ | No newline at end of file |