@daoyi/nmtl-ui 2.0.1-beta.11 → 2.0.1-beta.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/lib/components/Autocomplete-4d7fe6fc.js +487 -0
  2. package/lib/components/Autocomplete.js +20 -1
  3. package/lib/components/Avatar.js +53 -1
  4. package/lib/components/BackTop.js +124 -1
  5. package/lib/components/BarChart.js +762 -1
  6. package/lib/components/Breadcrumbs.js +122 -1
  7. package/lib/components/Button-305b69a0.js +92 -0
  8. package/lib/components/Button.js +6 -1
  9. package/lib/components/Carousel.js +4654 -1
  10. package/lib/components/Checkbox.js +37 -1
  11. package/lib/components/CollapseContent.js +180 -1
  12. package/lib/components/ContactModal-b3761fb6.js +12188 -0
  13. package/lib/components/ContactModal.js +24 -3
  14. package/lib/components/Drawer-b2edc79b.js +163 -0
  15. package/lib/components/Drawer.js +17 -1
  16. package/lib/components/Dropdown.js +134 -1
  17. package/lib/components/Empty-c6a44967.js +46 -0
  18. package/lib/components/Empty.js +5 -1
  19. package/lib/components/ExportButton.js +128 -1
  20. package/lib/components/ExtraTools-55f66039.js +3619 -0
  21. package/lib/components/ExtraTools.js +10 -22
  22. package/lib/components/Filter.js +821 -12
  23. package/lib/components/Footer.js +317 -1
  24. package/lib/components/ForwardLink-e86c1080.js +128 -0
  25. package/lib/components/ForwardLink.js +10 -0
  26. package/lib/components/Header.js +218 -1
  27. package/lib/components/Image.js +61 -1
  28. package/lib/components/Input.js +82 -1
  29. package/lib/components/InputMethod.js +33949 -12
  30. package/lib/components/KeywordSearch-870cc232.js +156 -0
  31. package/lib/components/KeywordSearch.js +22 -1
  32. package/lib/components/KeywordTicker.js +224 -1
  33. package/lib/components/Keywords.js +383 -1
  34. package/lib/components/Loading.js +28 -1
  35. package/lib/components/MUITheme.js +2639 -1
  36. package/lib/components/Modal-777fe87d.js +116 -0
  37. package/lib/components/Modal.js +10 -1
  38. package/lib/components/MoreButton-19055e07.js +148 -0
  39. package/lib/components/MoreButton.js +8 -1
  40. package/lib/components/Pagination.js +3702 -0
  41. package/lib/components/Radio.js +78 -1
  42. package/lib/components/SNA.js +1713 -22
  43. package/lib/components/Select-52ab5299.js +145 -0
  44. package/lib/components/Select.js +13 -1
  45. package/lib/components/Spin-8dc60bfe.js +75 -0
  46. package/lib/components/Spin.js +6 -1
  47. package/lib/components/Table.js +51 -1
  48. package/lib/components/Tooltip-6ebfa9c1.js +70 -0
  49. package/lib/components/Tooltip.js +7 -1
  50. package/lib/components/_commonjsHelpers-70de2c37.js +28 -0
  51. package/lib/components/_rollupPluginBabelHelpers-a52356f6.js +142 -0
  52. package/lib/components/createSvgIcon-e3803ee1.js +576 -0
  53. package/lib/components/dataExport-d55d6fa3.js +92 -0
  54. package/lib/components/debounce-127da66c.js +355 -0
  55. package/lib/components/defaultTheme-ed7746fe.js +1661 -0
  56. package/lib/components/globalConfig.js +293 -0
  57. package/lib/components/hoist-non-react-statics.cjs-3f408ad2.js +105 -0
  58. package/lib/components/index-b47819f3.js +481 -0
  59. package/lib/components/index-b76a85f4.js +61 -0
  60. package/lib/components/isObjectLike-e111475d.js +190 -0
  61. package/lib/components/style-inject.es-1f59c1d0.js +28 -1
  62. package/lib/components/toConsumableArray-dbe8af76.js +19 -0
  63. package/lib/components/transform-3a04288b.js +5475 -0
  64. package/lib/components/useTheme-d16d02d9.js +11 -0
  65. package/lib/components/withTheme-2d778133.js +6 -0
  66. package/lib/configs/config.selector.js +151 -0
  67. package/lib/configs/index.d.ts +1 -0
  68. package/lib/configs/index.js +1 -0
  69. package/lib/index.d.ts +2 -0
  70. package/lib/index.js +2 -0
  71. package/lib/utils/_rollupPluginBabelHelpers-8dd26e1a.js +121 -0
  72. package/lib/utils/arrayMerge.js +4953 -1
  73. package/lib/utils/chunkArray.js +15 -1
  74. package/lib/utils/convert2HtmlEntities.js +42 -1
  75. package/lib/utils/domToImage.js +802 -1
  76. package/lib/utils/downloadGephi.js +106 -1
  77. package/lib/utils/exportXlsx.js +219 -1
  78. package/lib/utils/historyAppendSearch.js +502 -1
  79. package/lib/utils/isDevelopMode.js +5 -1
  80. package/lib/utils/parseYMD.js +36 -1
  81. package/lib/utils/removeDuplicateItem.js +11 -1
  82. package/lib/utils/sendEmail.js +39 -1
  83. package/lib/utils/snaDefine-6a2bcd94.js +5 -0
  84. package/lib/utils/snaDefine.js +1 -1
  85. package/lib/utils/snaPreProcess.js +84 -1
  86. package/package.json +125 -127
  87. package/lib/components/Empty-54b79907.js +0 -1
  88. package/lib/components/KeywordSearch-5a393f12.js +0 -1
  89. package/lib/components/Select-f2441b83.js +0 -1
  90. package/lib/components/_rollupPluginBabelHelpers-1b8c042f.js +0 -1
  91. package/lib/components/_rollupPluginBabelHelpers-ec4e2a53.js +0 -1
  92. package/lib/components/createSvgIcon-62b64929.js +0 -1
  93. package/lib/components/createSvgIcon-e24792d4.js +0 -1
  94. package/lib/components/createTheme-7fffa109.js +0 -1
  95. package/lib/components/dataExport-9fccd4f0.js +0 -1
  96. package/lib/components/debounce-c993109b.js +0 -1
  97. package/lib/components/hoist-non-react-statics.cjs-d6a9befd.js +0 -1
  98. package/lib/components/index-11391ca3.js +0 -7
  99. package/lib/components/index-b2745105.js +0 -7
  100. package/lib/components/isObjectLike-2f1983fe.js +0 -1
  101. package/lib/components/style-inject.es-c875d022.js +0 -1
  102. package/lib/components/transform-95ae0119.js +0 -1
  103. package/lib/utils/_commonjsHelpers-e2cda605.js +0 -1
  104. package/lib/utils/_rollupPluginBabelHelpers-928a52ce.js +0 -1
@@ -0,0 +1,487 @@
1
+ import { _ as _extends$1, a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-a52356f6.js';
2
+ import React__default, { useCallback, useState, useRef, useEffect } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { c as classNames } from './index-b76a85f4.js';
5
+ import { d as debounce_1 } from './debounce-127da66c.js';
6
+ import { Autocomplete as Autocomplete$1 } from '@material-ui/lab';
7
+ import { Chip, TextField, CircularProgress } from '@material-ui/core';
8
+ import { Close, SearchOutlined } from '@material-ui/icons';
9
+ import { r as requireCreateSvgIcon, i as interopRequireDefault, a as interopRequireWildcard } from './createSvgIcon-e3803ee1.js';
10
+ import { _ as _extends, m as merge, d as defaultTheme, c as compose, b as borders, a as display, f as flexbox, g as grid, p as positions, e as palette, h as boxShadow, s as sizing, i as spacing, t as typography } from './defaultTheme-ed7746fe.js';
11
+ import 'react-is';
12
+ import { _ as _toConsumableArray } from './toConsumableArray-dbe8af76.js';
13
+ import { styled as styled$1 } from '@material-ui/styles';
14
+ import { getIntl } from './globalConfig';
15
+ import { s as styleInject } from './style-inject.es-1f59c1d0.js';
16
+ import { E as Empty } from './Empty-c6a44967.js';
17
+
18
+ var ArrowDropDown = {};
19
+
20
+ function omit(input, fields) {
21
+ var output = {};
22
+ Object.keys(input).forEach(function (prop) {
23
+ if (fields.indexOf(prop) === -1) {
24
+ output[prop] = input[prop];
25
+ }
26
+ });
27
+ return output;
28
+ }
29
+
30
+ function styleFunctionSx(styleFunction) {
31
+ var newStyleFunction = function newStyleFunction(props) {
32
+ var output = styleFunction(props);
33
+
34
+ if (props.css) {
35
+ return _extends({}, merge(output, styleFunction(_extends({
36
+ theme: props.theme
37
+ }, props.css))), omit(props.css, [styleFunction.filterProps]));
38
+ }
39
+
40
+ if (props.sx) {
41
+ return _extends({}, merge(output, styleFunction(_extends({
42
+ theme: props.theme
43
+ }, props.sx))), omit(props.sx, [styleFunction.filterProps]));
44
+ }
45
+
46
+ return output;
47
+ };
48
+
49
+ newStyleFunction.propTypes = {};
50
+ newStyleFunction.filterProps = ['css', 'sx'].concat(_toConsumableArray(styleFunction.filterProps));
51
+ return newStyleFunction;
52
+ }
53
+
54
+ var _interopRequireDefault = interopRequireDefault.exports;
55
+
56
+ var _interopRequireWildcard = interopRequireWildcard.exports;
57
+
58
+ Object.defineProperty(ArrowDropDown, "__esModule", {
59
+ value: true
60
+ });
61
+ var default_1 = ArrowDropDown.default = void 0;
62
+
63
+ var React = _interopRequireWildcard(React__default);
64
+
65
+ var _createSvgIcon = _interopRequireDefault(requireCreateSvgIcon());
66
+
67
+ var _default = (0, _createSvgIcon.default)( /*#__PURE__*/React.createElement("path", {
68
+ d: "M7 10l5 5 5-5z"
69
+ }), 'ArrowDropDown');
70
+
71
+ default_1 = ArrowDropDown.default = _default;
72
+
73
+ var styled = function styled(Component) {
74
+ var componentCreator = styled$1(Component);
75
+ return function (style, options) {
76
+ return componentCreator(style, _extends({
77
+ defaultTheme: defaultTheme
78
+ }, options));
79
+ };
80
+ };
81
+
82
+ var styleFunction = styleFunctionSx(compose(borders, display, flexbox, grid, positions, palette, boxShadow, sizing, spacing, typography));
83
+ /**
84
+ * @ignore - do not document.
85
+ */
86
+
87
+ var Box = styled('div')(styleFunction, {
88
+ name: 'MuiBox'
89
+ });
90
+
91
+ var useAutocomplete = (_ref => {
92
+ let {
93
+ options,
94
+ placeholder,
95
+ loading,
96
+ searchIcon,
97
+ labelInValue,
98
+ onEnter,
99
+ currentResult,
100
+ setCurrentDefaultValue,
101
+ arrowIcon,
102
+ ariaLabel
103
+ } = _ref;
104
+ const getValue = useCallback(data => typeof data === 'object' ? data.value : data, []);
105
+ const getLabel = useCallback(value => {
106
+ const finder = (Array.isArray(options) ? options : []).find(item => getValue(item) === getValue(value)
107
+ // typeof item === 'object' ? item.label === value : item === value
108
+ );
109
+
110
+ // console.log('options', options);
111
+ // console.log('value', value);
112
+ // console.log('finder', finder);
113
+ if (finder) {
114
+ return typeof finder === 'object' ? finder.label : finder;
115
+ }
116
+ return typeof value === 'object' ? value.label : value;
117
+ }, [options]);
118
+
119
+ // Filter duplicate data by each item.value
120
+ const getUniqueArray = useCallback(result => {
121
+ if (!Array.isArray(result)) return undefined;
122
+ return [...new Map(result.map(obj => [obj.value, obj])).values()];
123
+ }, []);
124
+
125
+ /* 若MUI的Autocomplete下方的options列表要勾選已選的項目 必須從options取出才可 */
126
+ const getValueFromOptions = useCallback(defaultValue => {
127
+ if (Array.isArray(options)) {
128
+ if (Array.isArray(defaultValue)) {
129
+ return defaultValue.map(
130
+ // item有可能為 object({ label, value }) 或 string(value)
131
+ item => options.find(_ref2 => {
132
+ let {
133
+ value
134
+ } = _ref2;
135
+ return item === value || item.value === value;
136
+ }) || item
137
+ // if (typeof item === 'object') return options.find(({ value }) => item.value === value) || item;
138
+ // return item;
139
+ );
140
+ }
141
+
142
+ const result = options.find(_ref3 => {
143
+ let {
144
+ value
145
+ } = _ref3;
146
+ return defaultValue === value;
147
+ });
148
+ return labelInValue ? defaultValue : result || {
149
+ label: defaultValue,
150
+ value: defaultValue
151
+ };
152
+ }
153
+ return defaultValue;
154
+ }, [options, labelInValue]);
155
+ const defaultTag = useCallback((tagValue, getTagProps) => tagValue.map((option, index) => /*#__PURE__*/React__default.createElement(Chip, _extends$1({
156
+ label: getLabel(option),
157
+ deleteIcon: /*#__PURE__*/React__default.createElement(Close, null)
158
+ }, getTagProps({
159
+ index
160
+ })))), [options]);
161
+ const defaultRenderInput = useCallback(params => /*#__PURE__*/React__default.createElement(TextField
162
+ // WCAG 3.3.2 輸入框需有可及名稱(placeholder 不是 label),未提供 ariaLabel 時以 placeholder 代替
163
+ , _extends$1({}, params, {
164
+ inputProps: {
165
+ ...params.inputProps,
166
+ 'aria-label': ariaLabel || placeholder
167
+ },
168
+ variant: "outlined",
169
+ placeholder: placeholder,
170
+ InputProps: {
171
+ ...params.InputProps,
172
+ endAdornment: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, loading && /*#__PURE__*/React__default.createElement(CircularProgress, {
173
+ className: "autocomplete__icon",
174
+ color: "inherit",
175
+ size: 20
176
+ }), searchIcon &&
177
+ /*#__PURE__*/
178
+ // WCAG 2.1.1 / 4.1.2 搜尋圖示為可點擊元素,需可鍵盤操作並有名稱
179
+ React__default.createElement(SearchOutlined, {
180
+ className: "autocomplete__icon",
181
+ role: "button",
182
+ tabIndex: 0,
183
+ "aria-label": getIntl().formatMessage({
184
+ id: 'aria.autocomplete.search'
185
+ }),
186
+ onClick: event => {
187
+ const tmpObj = {
188
+ labels: currentResult || '',
189
+ value: currentResult || ''
190
+ };
191
+ setCurrentDefaultValue(tmpObj);
192
+ return onEnter(event, tmpObj);
193
+ },
194
+ onKeyDown: event => {
195
+ if (event.key === 'Enter' || event.key === ' ') {
196
+ event.preventDefault();
197
+ const tmpObj = {
198
+ labels: currentResult || '',
199
+ value: currentResult || ''
200
+ };
201
+ setCurrentDefaultValue(tmpObj);
202
+ onEnter(event, tmpObj);
203
+ }
204
+ }
205
+ }), !searchIcon && !loading && arrowIcon && /*#__PURE__*/React__default.createElement(Box, {
206
+ style: {
207
+ top: 'calc(50% - 14px)',
208
+ right: '12px',
209
+ position: 'absolute'
210
+ }
211
+ }, /*#__PURE__*/React__default.createElement(default_1, null)), params.InputProps.endAdornment)
212
+ }
213
+ })), [loading, searchIcon, arrowIcon, ariaLabel, placeholder]);
214
+ return {
215
+ getValue,
216
+ getValueFromOptions,
217
+ defaultTag,
218
+ defaultRenderInput,
219
+ getUniqueArray
220
+ };
221
+ });
222
+
223
+ var css_248z = ".autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n flex-wrap: wrap;\n padding: 0px 8px;\n}\n.autocomplete .MuiChip-deleteIcon {\n width: 16px;\n height: 16px;\n}\n.autocomplete__icon {\n font-size: 1.25rem;\n margin-right: 8px;\n cursor: pointer;\n}\n.autocomplete--showSearchIcon .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n display: flex;\n flex-wrap: nowrap;\n padding: 4px 8px;\n}";
224
+ styleInject(css_248z);
225
+
226
+ var Autocomplete = function Autocomplete(props) {
227
+ var options = props.options,
228
+ defaultValue = props.defaultValue,
229
+ renderAfterDefaultValueChange = props.renderAfterDefaultValueChange,
230
+ filterable = props.filterable,
231
+ loading = props.loading,
232
+ labelInValue = props.labelInValue,
233
+ disabled = props.disabled;
234
+ var className = props.className,
235
+ multiple = props.multiple,
236
+ freeTyping = props.freeTyping,
237
+ placeholder = props.placeholder,
238
+ searchIcon = props.searchIcon,
239
+ _renderInput = props.renderInput,
240
+ _renderTags = props.renderTags,
241
+ ariaLabel = props.ariaLabel;
242
+ var _onChange = props.onChange,
243
+ onSearch = props.onSearch,
244
+ onFocus = props.onFocus,
245
+ onBlur = props.onBlur,
246
+ onEnter = props.onEnter,
247
+ _onKeyDown = props.onKeyDown,
248
+ arrowIcon = props.arrowIcon;
249
+ var _useState = useState(true),
250
+ _useState2 = _slicedToArray(_useState, 2),
251
+ rerender = _useState2[0],
252
+ setRerender = _useState2[1];
253
+ var _useState3 = useState(),
254
+ _useState4 = _slicedToArray(_useState3, 2),
255
+ keyword = _useState4[0],
256
+ setKeyword = _useState4[1];
257
+ var _useState5 = useState(),
258
+ _useState6 = _slicedToArray(_useState5, 2),
259
+ currentResult = _useState6[0],
260
+ setCurrentResult = _useState6[1];
261
+ var _useState7 = useState(),
262
+ _useState8 = _slicedToArray(_useState7, 2),
263
+ isFocusItem = _useState8[0],
264
+ setFocusItem = _useState8[1];
265
+ var _useState9 = useState(),
266
+ _useState10 = _slicedToArray(_useState9, 2),
267
+ currentDefaultValue = _useState10[0],
268
+ setCurrentDefaultValue = _useState10[1];
269
+ var _useAutocomplete = useAutocomplete(_objectSpread2(_objectSpread2({}, {
270
+ options: options,
271
+ placeholder: placeholder,
272
+ loading: loading,
273
+ searchIcon: searchIcon,
274
+ labelInValue: labelInValue,
275
+ currentResult: currentResult,
276
+ onEnter: onEnter,
277
+ setCurrentDefaultValue: setCurrentDefaultValue,
278
+ arrowIcon: arrowIcon
279
+ }), {}, {
280
+ ariaLabel: ariaLabel
281
+ })),
282
+ getValue = _useAutocomplete.getValue,
283
+ getValueFromOptions = _useAutocomplete.getValueFromOptions,
284
+ defaultTag = _useAutocomplete.defaultTag,
285
+ defaultRenderInput = _useAutocomplete.defaultRenderInput,
286
+ getUniqueArray = _useAutocomplete.getUniqueArray;
287
+ var handleSearch = useRef(debounce_1(function (result) {
288
+ return onSearch(result);
289
+ }, 500)).current;
290
+ /* WCAG 2.4.3 renderAfterDefaultValueChange 重繪會使焦點掉到 body(NVDA 改從頁面頂端讀起、
291
+ 蓋掉 aria-live 播報)——unmount 前記錄焦點是否在元件內,remount 後還原 */
292
+ var rootRef = useRef(null);
293
+ var hadFocusRef = useRef(false);
294
+
295
+ // 複選時 defaultValue 必須為Array
296
+ // const currentDefaultValue = typeof defaultValue === 'string' && multiple ? undefined : getValueFromOptions(defaultValue);
297
+ useEffect(function () {
298
+ setCurrentDefaultValue(typeof defaultValue === 'string' && multiple ? {
299
+ label: keyword,
300
+ value: keyword
301
+ } : getValueFromOptions(defaultValue));
302
+ }, [JSON.stringify(defaultValue)]);
303
+ useEffect(function () {
304
+ if (renderAfterDefaultValueChange) {
305
+ hadFocusRef.current = !!(rootRef.current && rootRef.current.contains(document.activeElement));
306
+ setRerender(false);
307
+ }
308
+ }, [currentDefaultValue]); // defaultValue改變時強制rerender
309
+ useEffect(function () {
310
+ if (!rerender) {
311
+ setRerender(true);
312
+ } else if (hadFocusRef.current) {
313
+ // remount 完成後把焦點還給輸入框(初載/返回時焦點不在元件內,不會搶焦點)
314
+ hadFocusRef.current = false;
315
+ setTimeout(function () {
316
+ var input = rootRef.current && rootRef.current.querySelector('input');
317
+ if (input) input.focus();
318
+ }, 0);
319
+ }
320
+ }, [rerender]);
321
+ /* 監聽result變化時才觸發onSearch */
322
+ useEffect(function () {
323
+ if (currentResult) {
324
+ setKeyword(currentResult);
325
+ handleSearch(currentResult);
326
+ }
327
+ }, [currentResult]);
328
+
329
+ /* 這邊邏輯很複雜 變動需再三確認case */
330
+ return /*#__PURE__*/React__default.createElement("div", {
331
+ ref: rootRef,
332
+ className: classNames('autocomplete', {
333
+ 'autocomplete--showSearchIcon': searchIcon
334
+ }, className)
335
+ }, rerender && /*#__PURE__*/React__default.createElement(Autocomplete$1, {
336
+ className: "autocomplete__component",
337
+ options: Array.isArray(options) && (freeTyping && keyword ? [{
338
+ label: keyword,
339
+ value: keyword
340
+ }].concat(options) : options) || []
341
+ // value="asd"
342
+ ,
343
+ defaultValue: currentDefaultValue,
344
+ disabled: disabled,
345
+ multiple: multiple
346
+ // 篩選機制(依據filterable決定是否要render全部)
347
+ ,
348
+ filterOptions: function filterOptions(optionList, input) {
349
+ var _input$inputValue = input.inputValue,
350
+ inputValue = _input$inputValue === void 0 ? '' : _input$inputValue;
351
+ return (Array.isArray(optionList) ? optionList : []).filter(function (item) {
352
+ var _ref = item || {},
353
+ _ref$label = _ref.label,
354
+ label = _ref$label === void 0 ? '' : _ref$label;
355
+ return filterable ? label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1 : true;
356
+ });
357
+ },
358
+ onChange: function onChange(event, result) {
359
+ if (Array.isArray(result)) {
360
+ _onChange(result.map(function (item) {
361
+ return labelInValue ? item : getValue(item);
362
+ }));
363
+ } else if (result) {
364
+ _onChange(labelInValue ? result : getValue(result));
365
+ }
366
+ },
367
+ onInputChange: function onInputChange(event, result, reason) {
368
+ /* 此callback會經常被觸發 因此需要setState並搭配useEffect穩定觸發 */
369
+ if (result && typeof result === 'string' && reason === 'input') setCurrentResult(result);
370
+ },
371
+ onKeyDown: function onKeyDown(event) {
372
+ _onKeyDown(event);
373
+ switch (event.key) {
374
+ case 'ArrowDown':
375
+ case 'ArrowUp':
376
+ setFocusItem(true);
377
+ break;
378
+ case 'Enter':
379
+ if (!isFocusItem) {
380
+ var enterFreeTyping = freeTyping && !multiple;
381
+ onEnter(event, enterFreeTyping ? {
382
+ label: keyword,
383
+ value: keyword
384
+ } : undefined);
385
+ if (enterFreeTyping) setCurrentDefaultValue({
386
+ label: keyword,
387
+ value: keyword
388
+ });
389
+ }
390
+ break;
391
+ default:
392
+ setFocusItem(false);
393
+ }
394
+ },
395
+ getOptionLabel: function getOptionLabel(option) {
396
+ return option && option.label || '';
397
+ },
398
+ getOptionDisabled: function getOptionDisabled(option) {
399
+ return option.disabled;
400
+ },
401
+ renderInput: function renderInput(params) {
402
+ return _renderInput && _renderInput(params) || defaultRenderInput(params);
403
+ },
404
+ renderTags: function renderTags(tagValue, getTagProps) {
405
+ var uniqueArray = getUniqueArray(tagValue) || tagValue;
406
+ return _renderTags && _renderTags(uniqueArray, getTagProps) || defaultTag(uniqueArray, getTagProps);
407
+ }
408
+ // popupIcon={<ExpandMore />}
409
+ ,
410
+ popupIcon: null,
411
+ noOptionsText: /*#__PURE__*/React__default.createElement(Empty, null),
412
+ onFocus: onFocus,
413
+ onBlur: onBlur
414
+ }));
415
+ };
416
+ Autocomplete.defaultProps = {
417
+ className: undefined,
418
+ defaultValue: undefined,
419
+ renderAfterDefaultValueChange: false,
420
+ options: undefined,
421
+ freeTyping: false,
422
+ loading: false,
423
+ disabled: false,
424
+ labelInValue: true,
425
+ searchIcon: true,
426
+ multiple: false,
427
+ placeholder: 'Search...',
428
+ filterable: false,
429
+ renderInput: undefined,
430
+ renderTags: undefined,
431
+ onChange: function onChange() {},
432
+ onSearch: function onSearch() {},
433
+ onFocus: function onFocus() {},
434
+ onBlur: function onBlur() {},
435
+ onKeyDown: function onKeyDown() {},
436
+ onEnter: function onEnter() {},
437
+ arrowIcon: false,
438
+ ariaLabel: undefined
439
+ };
440
+ Autocomplete.propTypes = {
441
+ /** Css名稱 */
442
+ className: PropTypes.string,
443
+ /** 初始內容值 */
444
+ defaultValue: PropTypes.any,
445
+ /** 初始值變動後重新載入元件 */
446
+ renderAfterDefaultValueChange: PropTypes.bool,
447
+ /** 下拉選單內容 */
448
+ options: PropTypes.arrayOf(PropTypes.any),
449
+ /** 是否允許自由輸入 */
450
+ freeTyping: PropTypes.bool,
451
+ /** 是否載入中 */
452
+ loading: PropTypes.bool,
453
+ /** 是否禁止使用 */
454
+ disabled: PropTypes.bool,
455
+ /** onChange時 label value 一起回傳 */
456
+ labelInValue: PropTypes.bool,
457
+ /** 搜尋的圖案是否顯示 */
458
+ searchIcon: PropTypes.bool,
459
+ /** 是否複選 */
460
+ multiple: PropTypes.bool,
461
+ /** 提示字 */
462
+ placeholder: PropTypes.string,
463
+ /** 是否要啟動篩選功能(若關閉則option有什麼即顯示什麼) */
464
+ filterable: PropTypes.bool,
465
+ /** input客製化 */
466
+ renderInput: PropTypes.func,
467
+ /** 已選選項客製化 */
468
+ renderTags: PropTypes.func,
469
+ /** 變動時的callback */
470
+ onChange: PropTypes.func,
471
+ /** 搜尋時的callback */
472
+ onSearch: PropTypes.func,
473
+ /** Input被聚焦時的callback */
474
+ onFocus: PropTypes.func,
475
+ /** Input離開時的callback */
476
+ onBlur: PropTypes.func,
477
+ /** 鍵盤按下任意鍵的callback(早於內部處理) */
478
+ onKeyDown: PropTypes.func,
479
+ /** 鍵盤輸入Enter的callback */
480
+ onEnter: PropTypes.func,
481
+ /** 是否顯示arrow icon */
482
+ arrowIcon: PropTypes.bool,
483
+ /** 輸入框的無障礙名稱(WCAG 3.3.2),未提供時以placeholder代替 */
484
+ ariaLabel: PropTypes.string
485
+ };
486
+
487
+ export { Autocomplete as A };
@@ -1 +1,20 @@
1
- import{_ as e,a as n,b as o}from"./_rollupPluginBabelHelpers-ec4e2a53.js";import t,{useCallback as r,useState as a,useRef as l,useEffect as u}from"react";import i from"prop-types";import{c}from"./index-b2745105.js";import{d as p}from"./debounce-c993109b.js";import{Autocomplete as s}from"@material-ui/lab";import{Chip as f,TextField as d,CircularProgress as m}from"@material-ui/core";import{Close as b,SearchOutlined as g}from"@material-ui/icons";import h from"./Empty.js";import{s as y}from"./style-inject.es-1f59c1d0.js";y(".autocomplete .MuiAutocomplete-inputRoot[class*='MuiOutlinedInput-root'] {\n padding: 0px 8px; }\n\n.autocomplete .MuiChip-deleteIcon {\n width: 16px;\n height: 16px; }\n\n.autocomplete__icon {\n font-size: 1.25rem;\n margin-right: 8px; }\n\n.autocomplete--showSearchIcon .MuiAutocomplete-inputRoot[class*='MuiOutlinedInput-root'] {\n display: flex;\n flex-wrap: nowrap;\n padding: 4px 8px; }\n");var I=function(i){var y=i.options,I=i.defaultValue,v=i.renderAfterDefaultValueChange,A=i.filterable,V=i.loading,x=i.labelInValue,E=i.disabled,w=i.className,C=i.multiple,O=i.freeTyping,T=i.placeholder,_=i.searchIcon,j=i.renderInput,N=i.renderTags,F=i.onChange,S=i.onSearch,D=i.onFocus,B=i.onBlur,M=i.onEnter,P=a(!0),R=n(P,2),k=R[0],L=R[1],z=a(),H=n(z,2),J=H[0],K=H[1],U=a(),q=n(U,2),G=q[0],Q=q[1],W=a(),X=n(W,2),Y=X[0],Z=X[1],$=a(),ee=n($,2),ne=ee[0],oe=ee[1],te=(n=>{let{options:o,placeholder:a,loading:l,searchIcon:u,labelInValue:i}=n;const c=r((e=>"object"==typeof e?e.value:e),[]),p=r((e=>{const n=(Array.isArray(o)?o:[]).find((n=>c(n)===c(e)));return n?"object"==typeof n?n.label:n:"object"==typeof e?e.label:e}),[o]),s=r((e=>{if(Array.isArray(o)){if(Array.isArray(e))return e.map((e=>o.find((n=>{let{value:o}=n;return e===o||e.value===o}))||e));const n=o.find((n=>{let{value:o}=n;return e===o}));return i?e:n||{label:e,value:e}}return e}),[o,i]),h=r(((n,o)=>n.map(((n,r)=>t.createElement(f,e({label:p(n),deleteIcon:t.createElement(b,null)},o({index:r})))))),[o]),y=r((n=>t.createElement(d,e({},n,{variant:"outlined",placeholder:a,InputProps:{...n.InputProps,endAdornment:t.createElement(t.Fragment,null,l&&t.createElement(m,{className:"autocomplete__icon",color:"inherit",size:20}),u&&t.createElement(g,{className:"autocomplete__icon"}),n.InputProps.endAdornment)}}))),[l,u]);return{getValue:c,getValueFromOptions:s,defaultTag:h,defaultRenderInput:y}})(o({},{options:y,placeholder:T,loading:V,searchIcon:_,labelInValue:x})),re=te.getValue,ae=te.getValueFromOptions,le=te.defaultTag,ue=te.defaultRenderInput,ie=l(p((function(e){return S(e)}),500)).current;return u((function(){oe("string"==typeof I&&C?{label:J,value:J}:ae(I))}),[JSON.stringify(I)]),u((function(){v&&L(!1)}),[ne]),u((function(){k||L(!0)}),[k]),u((function(){G&&(K(G),ie(G))}),[G]),t.createElement("div",{className:c("autocomplete",{"autocomplete--showSearchIcon":_},w)},k&&t.createElement(s,{className:"autocomplete__component",options:Array.isArray(y)&&(O&&J?[{label:J,value:J}].concat(y):y)||[],defaultValue:ne,disabled:E,multiple:C,filterOptions:function(e,n){var o=n.inputValue,t=void 0===o?"":o;return(Array.isArray(e)?e:[]).filter((function(e){var n=(e||{}).label;return!A||(void 0===n?"":n).toLowerCase().indexOf(t.toLowerCase())>-1}))},onChange:function(e,n){Array.isArray(n)?F(n.map((function(e){return x?e:re(e)}))):n&&F(x?n:re(n))},onInputChange:function(e,n,o){n&&"string"==typeof n&&"input"===o&&Q(n)},onKeyDown:function(e){switch(e.key){case"ArrowDown":case"ArrowUp":Z(!0);break;case"Enter":if(!Y){var n=O&&!C;M(e,n?{label:J,value:J}:void 0),n&&oe({label:J,value:J})}break;default:Z(!1)}},getOptionLabel:function(e){return e&&e.label||""},getOptionDisabled:function(e){return e.disabled},renderInput:function(e){return j&&j(e)||ue(e)},renderTags:function(e,n){return N&&N(e,n)||le(e,n)},popupIcon:null,noOptionsText:t.createElement(h,null),onFocus:D,onBlur:B}))};I.defaultProps={className:void 0,defaultValue:void 0,renderAfterDefaultValueChange:!1,options:void 0,freeTyping:!1,loading:!1,disabled:!1,labelInValue:!0,searchIcon:!0,multiple:!1,placeholder:"Search...",filterable:!1,renderInput:void 0,renderTags:void 0,onChange:function(){},onSearch:function(){},onFocus:function(){},onBlur:function(){},onEnter:function(){}},I.propTypes={className:i.string,defaultValue:i.any,renderAfterDefaultValueChange:i.bool,options:i.arrayOf(i.any),freeTyping:i.bool,loading:i.bool,disabled:i.bool,labelInValue:i.bool,searchIcon:i.bool,multiple:i.bool,placeholder:i.string,filterable:i.bool,renderInput:i.func,renderTags:i.func,onChange:i.func,onSearch:i.func,onFocus:i.func,onBlur:i.func,onEnter:i.func};export{I as default};
1
+ export { A as default } from './Autocomplete-4d7fe6fc.js';
2
+ import './_rollupPluginBabelHelpers-a52356f6.js';
3
+ import 'react';
4
+ import 'prop-types';
5
+ import './index-b76a85f4.js';
6
+ import './debounce-127da66c.js';
7
+ import './isObjectLike-e111475d.js';
8
+ import './_commonjsHelpers-70de2c37.js';
9
+ import '@material-ui/lab';
10
+ import '@material-ui/core';
11
+ import '@material-ui/icons';
12
+ import './createSvgIcon-e3803ee1.js';
13
+ import './defaultTheme-ed7746fe.js';
14
+ import 'react-is';
15
+ import '@material-ui/styles';
16
+ import 'react-dom';
17
+ import './toConsumableArray-dbe8af76.js';
18
+ import './globalConfig';
19
+ import './style-inject.es-1f59c1d0.js';
20
+ import './Empty-c6a44967.js';
@@ -1 +1,53 @@
1
- import r from"react";import{c as a}from"./index-b2745105.js";import e from"prop-types";import{Avatar as s}from"@material-ui/core";import{s as o}from"./style-inject.es-1f59c1d0.js";o("");var t=function(e){var o=e.className,t=e.shape,c=e.src,i=e.onError;return r.createElement(s,{className:a("avatar",o),variant:t,src:c},r.createElement("img",{src:c,onError:function(){return i()},alt:"test",style:{display:"none"}}))};t.defaultProps={className:void 0,shape:"circular",src:void 0,onError:void 0},t.propTypes={className:e.string,shape:e.oneOf(["circle","circular","rounded","square"]),src:e.string,onError:e.func};export{t as default};
1
+ import React__default from 'react';
2
+ import { c as classNames } from './index-b76a85f4.js';
3
+ import PropTypes from 'prop-types';
4
+ import { Avatar as Avatar$1 } from '@material-ui/core';
5
+ import { s as styleInject } from './style-inject.es-1f59c1d0.js';
6
+
7
+ var css_248z = "";
8
+ styleInject(css_248z);
9
+
10
+ var Avatar = function Avatar(_ref) {
11
+ var className = _ref.className,
12
+ shape = _ref.shape,
13
+ src = _ref.src,
14
+ _onError = _ref.onError,
15
+ _ref$defaultImg = _ref.defaultImg,
16
+ defaultImg = _ref$defaultImg === void 0 ? '' : _ref$defaultImg;
17
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Avatar$1, {
18
+ className: classNames('avatar', className),
19
+ variant: shape,
20
+ src: src
21
+ }, defaultImg), typeof _onError === 'function' && /*#__PURE__*/React__default.createElement("img", {
22
+ src: src,
23
+ onError: function onError() {
24
+ return _onError();
25
+ },
26
+ alt: "test",
27
+ style: {
28
+ display: 'none'
29
+ }
30
+ }));
31
+ };
32
+ Avatar.defaultProps = {
33
+ className: undefined,
34
+ shape: 'circular',
35
+ src: undefined,
36
+ onError: undefined,
37
+ defaultImg: undefined
38
+ };
39
+
40
+ /* Write props detail information and 'npm run updateStory' will help you generate stories's argTypes */
41
+ Avatar.propTypes = {
42
+ /** Css Name */
43
+ className: PropTypes.string,
44
+ /** 形狀 */
45
+ shape: PropTypes.oneOf(['circle', 'circular', 'rounded', 'square']),
46
+ /** 圖片來源 */
47
+ src: PropTypes.string,
48
+ /** 圖片有錯誤則callback */
49
+ onError: PropTypes.func,
50
+ defaultImg: PropTypes.string
51
+ };
52
+
53
+ export { Avatar as default };