@daoyi/nmtl-ui 2.0.1-beta.12 → 2.0.1-beta.121

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-3b418e5f.js +494 -0
  2. package/lib/components/Autocomplete.js +20 -1
  3. package/lib/components/Avatar.js +59 -1
  4. package/lib/components/BackTop.js +124 -1
  5. package/lib/components/BarChart.js +764 -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-763fc7cb.js +12188 -0
  13. package/lib/components/ContactModal.js +24 -3
  14. package/lib/components/Drawer-48414c2e.js +176 -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-0f9ca8be.js +3638 -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 +233 -1
  27. package/lib/components/Image.js +61 -1
  28. package/lib/components/Input.js +89 -1
  29. package/lib/components/InputMethod.js +33949 -12
  30. package/lib/components/KeywordSearch-fec33a2c.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 +32 -1
  35. package/lib/components/MUITheme.js +2657 -1
  36. package/lib/components/Modal-76fef34f.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 +83 -1
  42. package/lib/components/SNA.js +1721 -22
  43. package/lib/components/Select-141d7992.js +153 -0
  44. package/lib/components/Select.js +13 -1
  45. package/lib/components/Spin-8f87eadc.js +79 -0
  46. package/lib/components/Spin.js +7 -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-a9e3fae1.js +91 -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 +299 -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 +235 -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 +16 -19
  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,494 @@
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
+ // WCAG 4.1.2 progressbar 需可及名稱(axe aria-progressbar-name)
177
+ ,
178
+ "aria-label": getIntl().formatMessage({
179
+ id: 'aria.loading'
180
+ })
181
+ }), searchIcon &&
182
+ /*#__PURE__*/
183
+ // WCAG 2.1.1 / 4.1.2 搜尋圖示為可點擊元素,需可鍵盤操作並有名稱;
184
+ // MUI SvgIcon 預設 aria-hidden="true",可聚焦元素必須覆蓋(axe aria-hidden-focus)
185
+ React__default.createElement(SearchOutlined, {
186
+ className: "autocomplete__icon",
187
+ role: "button",
188
+ tabIndex: 0,
189
+ "aria-hidden": false,
190
+ "aria-label": getIntl().formatMessage({
191
+ id: 'aria.autocomplete.search'
192
+ }),
193
+ onClick: event => {
194
+ const tmpObj = {
195
+ labels: currentResult || '',
196
+ value: currentResult || ''
197
+ };
198
+ setCurrentDefaultValue(tmpObj);
199
+ return onEnter(event, tmpObj);
200
+ },
201
+ onKeyDown: event => {
202
+ if (event.key === 'Enter' || event.key === ' ') {
203
+ event.preventDefault();
204
+ const tmpObj = {
205
+ labels: currentResult || '',
206
+ value: currentResult || ''
207
+ };
208
+ setCurrentDefaultValue(tmpObj);
209
+ onEnter(event, tmpObj);
210
+ }
211
+ }
212
+ }), !searchIcon && !loading && arrowIcon && /*#__PURE__*/React__default.createElement(Box, {
213
+ style: {
214
+ top: 'calc(50% - 14px)',
215
+ right: '12px',
216
+ position: 'absolute'
217
+ }
218
+ }, /*#__PURE__*/React__default.createElement(default_1, null)), params.InputProps.endAdornment)
219
+ }
220
+ })), [loading, searchIcon, arrowIcon, ariaLabel, placeholder]);
221
+ return {
222
+ getValue,
223
+ getValueFromOptions,
224
+ defaultTag,
225
+ defaultRenderInput,
226
+ getUniqueArray
227
+ };
228
+ });
229
+
230
+ var css_248z = "@charset \"UTF-8\";\n/* 下拉選項鍵盤高亮可視化(R39):上下鍵挑選時 MUI 只給 data-focus=\"true\"+\n action.hover(4% 黑)底色,對使用者幾乎不可見(WCAG 2.4.7 精神)。\n 比照 R30 選單選項聚焦模式=亮底+2px 虛線內縮完整框。\n 顏色不寫死(R30-1a 教訓:彈窗底色各站不同,horror 為深底 paper):\n 外框 currentColor 跟隨選項文字色(文字對底 ≥4.5:1,外框對比自動達標)、\n 底色用中性半透明灰(深淺底皆可見)。\n 選單以 Popper 掛在 body,選擇器須在 .autocomplete 之外;\n 加 listbox 父層提高特異度(MUI JSS 同名規則注入較晚,同特異度會蓋掉本檔背景色) */\n.MuiAutocomplete-listbox .MuiAutocomplete-option[data-focus=true] {\n background-color: rgba(127, 127, 127, 0.25);\n outline: 2px dashed currentColor;\n outline-offset: -4px;\n}\n\n.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}";
231
+ styleInject(css_248z);
232
+
233
+ var Autocomplete = function Autocomplete(props) {
234
+ var options = props.options,
235
+ defaultValue = props.defaultValue,
236
+ renderAfterDefaultValueChange = props.renderAfterDefaultValueChange,
237
+ filterable = props.filterable,
238
+ loading = props.loading,
239
+ labelInValue = props.labelInValue,
240
+ disabled = props.disabled;
241
+ var className = props.className,
242
+ multiple = props.multiple,
243
+ freeTyping = props.freeTyping,
244
+ placeholder = props.placeholder,
245
+ searchIcon = props.searchIcon,
246
+ _renderInput = props.renderInput,
247
+ _renderTags = props.renderTags,
248
+ ariaLabel = props.ariaLabel;
249
+ var _onChange = props.onChange,
250
+ onSearch = props.onSearch,
251
+ onFocus = props.onFocus,
252
+ onBlur = props.onBlur,
253
+ onEnter = props.onEnter,
254
+ _onKeyDown = props.onKeyDown,
255
+ arrowIcon = props.arrowIcon;
256
+ var _useState = useState(true),
257
+ _useState2 = _slicedToArray(_useState, 2),
258
+ rerender = _useState2[0],
259
+ setRerender = _useState2[1];
260
+ var _useState3 = useState(),
261
+ _useState4 = _slicedToArray(_useState3, 2),
262
+ keyword = _useState4[0],
263
+ setKeyword = _useState4[1];
264
+ var _useState5 = useState(),
265
+ _useState6 = _slicedToArray(_useState5, 2),
266
+ currentResult = _useState6[0],
267
+ setCurrentResult = _useState6[1];
268
+ var _useState7 = useState(),
269
+ _useState8 = _slicedToArray(_useState7, 2),
270
+ isFocusItem = _useState8[0],
271
+ setFocusItem = _useState8[1];
272
+ var _useState9 = useState(),
273
+ _useState10 = _slicedToArray(_useState9, 2),
274
+ currentDefaultValue = _useState10[0],
275
+ setCurrentDefaultValue = _useState10[1];
276
+ var _useAutocomplete = useAutocomplete(_objectSpread2(_objectSpread2({}, {
277
+ options: options,
278
+ placeholder: placeholder,
279
+ loading: loading,
280
+ searchIcon: searchIcon,
281
+ labelInValue: labelInValue,
282
+ currentResult: currentResult,
283
+ onEnter: onEnter,
284
+ setCurrentDefaultValue: setCurrentDefaultValue,
285
+ arrowIcon: arrowIcon
286
+ }), {}, {
287
+ ariaLabel: ariaLabel
288
+ })),
289
+ getValue = _useAutocomplete.getValue,
290
+ getValueFromOptions = _useAutocomplete.getValueFromOptions,
291
+ defaultTag = _useAutocomplete.defaultTag,
292
+ defaultRenderInput = _useAutocomplete.defaultRenderInput,
293
+ getUniqueArray = _useAutocomplete.getUniqueArray;
294
+ var handleSearch = useRef(debounce_1(function (result) {
295
+ return onSearch(result);
296
+ }, 500)).current;
297
+ /* WCAG 2.4.3 renderAfterDefaultValueChange 重繪會使焦點掉到 body(NVDA 改從頁面頂端讀起、
298
+ 蓋掉 aria-live 播報)——unmount 前記錄焦點是否在元件內,remount 後還原 */
299
+ var rootRef = useRef(null);
300
+ var hadFocusRef = useRef(false);
301
+
302
+ // 複選時 defaultValue 必須為Array
303
+ // const currentDefaultValue = typeof defaultValue === 'string' && multiple ? undefined : getValueFromOptions(defaultValue);
304
+ useEffect(function () {
305
+ setCurrentDefaultValue(typeof defaultValue === 'string' && multiple ? {
306
+ label: keyword,
307
+ value: keyword
308
+ } : getValueFromOptions(defaultValue));
309
+ }, [JSON.stringify(defaultValue)]);
310
+ useEffect(function () {
311
+ if (renderAfterDefaultValueChange) {
312
+ hadFocusRef.current = !!(rootRef.current && rootRef.current.contains(document.activeElement));
313
+ setRerender(false);
314
+ }
315
+ }, [currentDefaultValue]); // defaultValue改變時強制rerender
316
+ useEffect(function () {
317
+ if (!rerender) {
318
+ setRerender(true);
319
+ } else if (hadFocusRef.current) {
320
+ // remount 完成後把焦點還給輸入框(初載/返回時焦點不在元件內,不會搶焦點)
321
+ hadFocusRef.current = false;
322
+ setTimeout(function () {
323
+ var input = rootRef.current && rootRef.current.querySelector('input');
324
+ if (input) input.focus();
325
+ }, 0);
326
+ }
327
+ }, [rerender]);
328
+ /* 監聽result變化時才觸發onSearch */
329
+ useEffect(function () {
330
+ if (currentResult) {
331
+ setKeyword(currentResult);
332
+ handleSearch(currentResult);
333
+ }
334
+ }, [currentResult]);
335
+
336
+ /* 這邊邏輯很複雜 變動需再三確認case */
337
+ return /*#__PURE__*/React__default.createElement("div", {
338
+ ref: rootRef,
339
+ className: classNames('autocomplete', {
340
+ 'autocomplete--showSearchIcon': searchIcon
341
+ }, className)
342
+ }, rerender && /*#__PURE__*/React__default.createElement(Autocomplete$1, {
343
+ className: "autocomplete__component",
344
+ options: Array.isArray(options) && (freeTyping && keyword ? [{
345
+ label: keyword,
346
+ value: keyword
347
+ }].concat(options) : options) || []
348
+ // value="asd"
349
+ ,
350
+ defaultValue: currentDefaultValue,
351
+ disabled: disabled,
352
+ multiple: multiple
353
+ // 篩選機制(依據filterable決定是否要render全部)
354
+ ,
355
+ filterOptions: function filterOptions(optionList, input) {
356
+ var _input$inputValue = input.inputValue,
357
+ inputValue = _input$inputValue === void 0 ? '' : _input$inputValue;
358
+ return (Array.isArray(optionList) ? optionList : []).filter(function (item) {
359
+ var _ref = item || {},
360
+ _ref$label = _ref.label,
361
+ label = _ref$label === void 0 ? '' : _ref$label;
362
+ return filterable ? label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1 : true;
363
+ });
364
+ },
365
+ onChange: function onChange(event, result) {
366
+ if (Array.isArray(result)) {
367
+ _onChange(result.map(function (item) {
368
+ return labelInValue ? item : getValue(item);
369
+ }));
370
+ } else if (result) {
371
+ _onChange(labelInValue ? result : getValue(result));
372
+ }
373
+ },
374
+ onInputChange: function onInputChange(event, result, reason) {
375
+ /* 此callback會經常被觸發 因此需要setState並搭配useEffect穩定觸發 */
376
+ if (result && typeof result === 'string' && reason === 'input') setCurrentResult(result);
377
+ },
378
+ onKeyDown: function onKeyDown(event) {
379
+ _onKeyDown(event);
380
+ switch (event.key) {
381
+ case 'ArrowDown':
382
+ case 'ArrowUp':
383
+ setFocusItem(true);
384
+ break;
385
+ case 'Enter':
386
+ if (!isFocusItem) {
387
+ var enterFreeTyping = freeTyping && !multiple;
388
+ onEnter(event, enterFreeTyping ? {
389
+ label: keyword,
390
+ value: keyword
391
+ } : undefined);
392
+ if (enterFreeTyping) setCurrentDefaultValue({
393
+ label: keyword,
394
+ value: keyword
395
+ });
396
+ }
397
+ break;
398
+ default:
399
+ setFocusItem(false);
400
+ }
401
+ },
402
+ getOptionLabel: function getOptionLabel(option) {
403
+ return option && option.label || '';
404
+ },
405
+ getOptionDisabled: function getOptionDisabled(option) {
406
+ return option.disabled;
407
+ },
408
+ renderInput: function renderInput(params) {
409
+ return _renderInput && _renderInput(params) || defaultRenderInput(params);
410
+ },
411
+ renderTags: function renderTags(tagValue, getTagProps) {
412
+ var uniqueArray = getUniqueArray(tagValue) || tagValue;
413
+ return _renderTags && _renderTags(uniqueArray, getTagProps) || defaultTag(uniqueArray, getTagProps);
414
+ }
415
+ // popupIcon={<ExpandMore />}
416
+ ,
417
+ popupIcon: null,
418
+ noOptionsText: /*#__PURE__*/React__default.createElement(Empty, null),
419
+ onFocus: onFocus,
420
+ onBlur: onBlur
421
+ }));
422
+ };
423
+ Autocomplete.defaultProps = {
424
+ className: undefined,
425
+ defaultValue: undefined,
426
+ renderAfterDefaultValueChange: false,
427
+ options: undefined,
428
+ freeTyping: false,
429
+ loading: false,
430
+ disabled: false,
431
+ labelInValue: true,
432
+ searchIcon: true,
433
+ multiple: false,
434
+ placeholder: 'Search...',
435
+ filterable: false,
436
+ renderInput: undefined,
437
+ renderTags: undefined,
438
+ onChange: function onChange() {},
439
+ onSearch: function onSearch() {},
440
+ onFocus: function onFocus() {},
441
+ onBlur: function onBlur() {},
442
+ onKeyDown: function onKeyDown() {},
443
+ onEnter: function onEnter() {},
444
+ arrowIcon: false,
445
+ ariaLabel: undefined
446
+ };
447
+ Autocomplete.propTypes = {
448
+ /** Css名稱 */
449
+ className: PropTypes.string,
450
+ /** 初始內容值 */
451
+ defaultValue: PropTypes.any,
452
+ /** 初始值變動後重新載入元件 */
453
+ renderAfterDefaultValueChange: PropTypes.bool,
454
+ /** 下拉選單內容 */
455
+ options: PropTypes.arrayOf(PropTypes.any),
456
+ /** 是否允許自由輸入 */
457
+ freeTyping: PropTypes.bool,
458
+ /** 是否載入中 */
459
+ loading: PropTypes.bool,
460
+ /** 是否禁止使用 */
461
+ disabled: PropTypes.bool,
462
+ /** onChange時 label value 一起回傳 */
463
+ labelInValue: PropTypes.bool,
464
+ /** 搜尋的圖案是否顯示 */
465
+ searchIcon: PropTypes.bool,
466
+ /** 是否複選 */
467
+ multiple: PropTypes.bool,
468
+ /** 提示字 */
469
+ placeholder: PropTypes.string,
470
+ /** 是否要啟動篩選功能(若關閉則option有什麼即顯示什麼) */
471
+ filterable: PropTypes.bool,
472
+ /** input客製化 */
473
+ renderInput: PropTypes.func,
474
+ /** 已選選項客製化 */
475
+ renderTags: PropTypes.func,
476
+ /** 變動時的callback */
477
+ onChange: PropTypes.func,
478
+ /** 搜尋時的callback */
479
+ onSearch: PropTypes.func,
480
+ /** Input被聚焦時的callback */
481
+ onFocus: PropTypes.func,
482
+ /** Input離開時的callback */
483
+ onBlur: PropTypes.func,
484
+ /** 鍵盤按下任意鍵的callback(早於內部處理) */
485
+ onKeyDown: PropTypes.func,
486
+ /** 鍵盤輸入Enter的callback */
487
+ onEnter: PropTypes.func,
488
+ /** 是否顯示arrow icon */
489
+ arrowIcon: PropTypes.bool,
490
+ /** 輸入框的無障礙名稱(WCAG 3.3.2),未提供時以placeholder代替 */
491
+ ariaLabel: PropTypes.string
492
+ };
493
+
494
+ 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-3b418e5f.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,59 @@
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
+ alt = _ref.alt,
15
+ _onError = _ref.onError,
16
+ _ref$defaultImg = _ref.defaultImg,
17
+ defaultImg = _ref$defaultImg === void 0 ? '' : _ref$defaultImg;
18
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Avatar$1, {
19
+ className: classNames('avatar', className),
20
+ variant: shape,
21
+ src: src,
22
+ alt: alt
23
+ }, defaultImg), typeof _onError === 'function' && /*#__PURE__*/React__default.createElement("img", {
24
+ src: src,
25
+ onError: function onError() {
26
+ return _onError();
27
+ },
28
+ alt: "",
29
+ "aria-hidden": true,
30
+ style: {
31
+ display: 'none'
32
+ }
33
+ }));
34
+ };
35
+ Avatar.defaultProps = {
36
+ className: undefined,
37
+ shape: 'circular',
38
+ src: undefined,
39
+ alt: undefined,
40
+ onError: undefined,
41
+ defaultImg: undefined
42
+ };
43
+
44
+ /* Write props detail information and 'npm run updateStory' will help you generate stories's argTypes */
45
+ Avatar.propTypes = {
46
+ /** Css Name */
47
+ className: PropTypes.string,
48
+ /** 形狀 */
49
+ shape: PropTypes.oneOf(['circle', 'circular', 'rounded', 'square']),
50
+ /** 圖片來源 */
51
+ src: PropTypes.string,
52
+ /** 圖片文字替代(WCAG 1.1.1);裝飾或與相鄰文字重複時傳空字串 */
53
+ alt: PropTypes.string,
54
+ /** 圖片有錯誤則callback */
55
+ onError: PropTypes.func,
56
+ defaultImg: PropTypes.string
57
+ };
58
+
59
+ export { Avatar as default };