1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4 |
|
5 | var __rest = this && this.__rest || function (s, e) {
|
6 | var t = {};
|
7 | for (var p in s) {
|
8 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
9 | }
|
10 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
11 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
12 | }
|
13 | return t;
|
14 | };
|
15 | import classNames from 'classnames';
|
16 | import RcSelect, { OptGroup, Option } from 'rc-select';
|
17 | import omit from "rc-util/es/omit";
|
18 | import * as React from 'react';
|
19 | import { useContext } from 'react';
|
20 | import { ConfigContext } from '../config-provider';
|
21 | import defaultRenderEmpty from '../config-provider/defaultRenderEmpty';
|
22 | import DisabledContext from '../config-provider/DisabledContext';
|
23 | import SizeContext from '../config-provider/SizeContext';
|
24 | import { FormItemInputContext } from '../form/context';
|
25 | import { getTransitionDirection, getTransitionName } from '../_util/motion';
|
26 | import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
|
27 | import getIcons from './utils/iconUtil';
|
28 | import useStyle from './style';
|
29 | import genPurePanel from '../_util/PurePanel';
|
30 | import warning from '../_util/warning';
|
31 | import { useCompactItemContext } from '../space/Compact';
|
32 | var SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
33 | var InternalSelect = function InternalSelect(_a, ref) {
|
34 | var _classNames2;
|
35 | var customizePrefixCls = _a.prefixCls,
|
36 | _a$bordered = _a.bordered,
|
37 | bordered = _a$bordered === void 0 ? true : _a$bordered,
|
38 | className = _a.className,
|
39 | getPopupContainer = _a.getPopupContainer,
|
40 | popupClassName = _a.popupClassName,
|
41 | dropdownClassName = _a.dropdownClassName,
|
42 | _a$listHeight = _a.listHeight,
|
43 | listHeight = _a$listHeight === void 0 ? 256 : _a$listHeight,
|
44 | placement = _a.placement,
|
45 | _a$listItemHeight = _a.listItemHeight,
|
46 | listItemHeight = _a$listItemHeight === void 0 ? 24 : _a$listItemHeight,
|
47 | customizeSize = _a.size,
|
48 | customDisabled = _a.disabled,
|
49 | notFoundContent = _a.notFoundContent,
|
50 | customStatus = _a.status,
|
51 | showArrow = _a.showArrow,
|
52 | props = __rest(_a, ["prefixCls", "bordered", "className", "getPopupContainer", "popupClassName", "dropdownClassName", "listHeight", "placement", "listItemHeight", "size", "disabled", "notFoundContent", "status", "showArrow"]);
|
53 | var _React$useContext = React.useContext(ConfigContext),
|
54 | getContextPopupContainer = _React$useContext.getPopupContainer,
|
55 | getPrefixCls = _React$useContext.getPrefixCls,
|
56 | renderEmpty = _React$useContext.renderEmpty,
|
57 | direction = _React$useContext.direction,
|
58 | virtual = _React$useContext.virtual,
|
59 | dropdownMatchSelectWidth = _React$useContext.dropdownMatchSelectWidth;
|
60 | var size = React.useContext(SizeContext);
|
61 | var prefixCls = getPrefixCls('select', customizePrefixCls);
|
62 | var rootPrefixCls = getPrefixCls();
|
63 | var _useCompactItemContex = useCompactItemContext(prefixCls, direction),
|
64 | compactSize = _useCompactItemContex.compactSize,
|
65 | compactItemClassnames = _useCompactItemContex.compactItemClassnames;
|
66 | var _useStyle = useStyle(prefixCls),
|
67 | _useStyle2 = _slicedToArray(_useStyle, 2),
|
68 | wrapSSR = _useStyle2[0],
|
69 | hashId = _useStyle2[1];
|
70 | var mode = React.useMemo(function () {
|
71 | var m = props.mode;
|
72 | if (m === 'combobox') {
|
73 | return undefined;
|
74 | }
|
75 | if (m === SECRET_COMBOBOX_MODE_DO_NOT_USE) {
|
76 | return 'combobox';
|
77 | }
|
78 | return m;
|
79 | }, [props.mode]);
|
80 | var isMultiple = mode === 'multiple' || mode === 'tags';
|
81 | var mergedShowArrow = showArrow !== undefined ? showArrow : props.loading || !(isMultiple || mode === 'combobox');
|
82 |
|
83 | var _useContext = useContext(FormItemInputContext),
|
84 | contextStatus = _useContext.status,
|
85 | hasFeedback = _useContext.hasFeedback,
|
86 | isFormItemInput = _useContext.isFormItemInput,
|
87 | feedbackIcon = _useContext.feedbackIcon;
|
88 | var mergedStatus = getMergedStatus(contextStatus, customStatus);
|
89 |
|
90 | var mergedNotFound;
|
91 | if (notFoundContent !== undefined) {
|
92 | mergedNotFound = notFoundContent;
|
93 | } else if (mode === 'combobox') {
|
94 | mergedNotFound = null;
|
95 | } else {
|
96 | mergedNotFound = (renderEmpty || defaultRenderEmpty)('Select');
|
97 | }
|
98 |
|
99 | var _getIcons = getIcons(_extends(_extends({}, props), {
|
100 | multiple: isMultiple,
|
101 | hasFeedback: hasFeedback,
|
102 | feedbackIcon: feedbackIcon,
|
103 | showArrow: mergedShowArrow,
|
104 | prefixCls: prefixCls
|
105 | })),
|
106 | suffixIcon = _getIcons.suffixIcon,
|
107 | itemIcon = _getIcons.itemIcon,
|
108 | removeIcon = _getIcons.removeIcon,
|
109 | clearIcon = _getIcons.clearIcon;
|
110 | var selectProps = omit(props, ['suffixIcon', 'itemIcon']);
|
111 | var rcSelectRtlDropdownClassName = classNames(popupClassName || dropdownClassName, _defineProperty({}, prefixCls + "-dropdown-" + direction, direction === 'rtl'), hashId);
|
112 | var mergedSize = compactSize || customizeSize || size;
|
113 |
|
114 | var disabled = React.useContext(DisabledContext);
|
115 | var mergedDisabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled;
|
116 | var mergedClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, prefixCls + "-lg", mergedSize === 'large'), _defineProperty(_classNames2, prefixCls + "-sm", mergedSize === 'small'), _defineProperty(_classNames2, prefixCls + "-rtl", direction === 'rtl'), _defineProperty(_classNames2, prefixCls + "-borderless", !bordered), _defineProperty(_classNames2, prefixCls + "-in-form-item", isFormItemInput), _classNames2), getStatusClassNames(prefixCls, mergedStatus, hasFeedback), compactItemClassnames, className, hashId);
|
117 |
|
118 | var getPlacement = function getPlacement() {
|
119 | if (placement !== undefined) {
|
120 | return placement;
|
121 | }
|
122 | return direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
|
123 | };
|
124 |
|
125 | if (process.env.NODE_ENV !== 'production') {
|
126 | process.env.NODE_ENV !== "production" ? warning(!dropdownClassName, 'Select', '`dropdownClassName` is deprecated. Please use `popupClassName` instead.') : void 0;
|
127 | }
|
128 |
|
129 | return wrapSSR( React.createElement(RcSelect, _extends({
|
130 | ref: ref,
|
131 | virtual: virtual,
|
132 | dropdownMatchSelectWidth: dropdownMatchSelectWidth
|
133 | }, selectProps, {
|
134 | transitionName: getTransitionName(rootPrefixCls, getTransitionDirection(placement), props.transitionName),
|
135 | listHeight: listHeight,
|
136 | listItemHeight: listItemHeight,
|
137 | mode: mode,
|
138 | prefixCls: prefixCls,
|
139 | placement: getPlacement(),
|
140 | direction: direction,
|
141 | inputIcon: suffixIcon,
|
142 | menuItemSelectedIcon: itemIcon,
|
143 | removeIcon: removeIcon,
|
144 | clearIcon: clearIcon,
|
145 | notFoundContent: mergedNotFound,
|
146 | className: mergedClassName,
|
147 | getPopupContainer: getPopupContainer || getContextPopupContainer,
|
148 | dropdownClassName: rcSelectRtlDropdownClassName,
|
149 | showArrow: hasFeedback || showArrow,
|
150 | disabled: mergedDisabled
|
151 | })));
|
152 | };
|
153 | var Select = React.forwardRef(InternalSelect);
|
154 |
|
155 |
|
156 | var PurePanel = genPurePanel(Select);
|
157 | Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = SECRET_COMBOBOX_MODE_DO_NOT_USE;
|
158 | Select.Option = Option;
|
159 | Select.OptGroup = OptGroup;
|
160 | Select._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
161 | export default Select; |
\ | No newline at end of file |