UNPKG

8.07 kBJavaScriptView Raw
1import { createVNode as _createVNode } from "vue";
2
3function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
5function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
7function _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; }
8
9function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
10
11import { computed, defineComponent, inject, ref } from 'vue';
12import omit from 'omit.js';
13import classNames from '../_util/classNames';
14import RcSelect, { Option, OptGroup, BaseProps } from '../vc-select';
15import { defaultConfigProvider } from '../config-provider';
16import getIcons from './utils/iconUtil';
17import PropTypes from '../_util/vue-types';
18import { tuple } from '../_util/type';
19export var SelectProps = function SelectProps() {
20 return _extends(_extends({}, omit(BaseProps(), ['inputIcon', 'mode', 'getInputElement', 'backfill', 'class', 'style'])), {
21 value: {
22 type: [Array, Object, String, Number]
23 },
24 defaultValue: {
25 type: [Array, Object, String, Number]
26 },
27 notFoundContent: PropTypes.VNodeChild,
28 suffixIcon: PropTypes.VNodeChild,
29 itemIcon: PropTypes.VNodeChild,
30 size: PropTypes.oneOf(tuple('small', 'middle', 'large', 'default')),
31 mode: PropTypes.oneOf(tuple('multiple', 'tags', 'SECRET_COMBOBOX_MODE_DO_NOT_USE')),
32 bordered: PropTypes.looseBool.def(true),
33 transitionName: PropTypes.string.def('slide-up'),
34 choiceTransitionName: PropTypes.string.def('')
35 });
36};
37var Select = defineComponent({
38 name: 'ASelect',
39 Option: Option,
40 OptGroup: OptGroup,
41 inheritAttrs: false,
42 props: SelectProps(),
43 SECRET_COMBOBOX_MODE_DO_NOT_USE: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
44 emits: ['change', 'update:value'],
45 setup: function setup(props, _ref) {
46 var attrs = _ref.attrs,
47 emit = _ref.emit;
48 var selectRef = ref(null);
49 var configProvider = inject('configProvider', defaultConfigProvider);
50
51 var focus = function focus() {
52 if (selectRef.value) {
53 selectRef.value.focus();
54 }
55 };
56
57 var blur = function blur() {
58 if (selectRef.value) {
59 selectRef.value.blur();
60 }
61 };
62
63 var mode = computed(function () {
64 var mode = props.mode;
65
66 if (mode === 'combobox') {
67 return undefined;
68 }
69
70 if (mode === Select.SECRET_COMBOBOX_MODE_DO_NOT_USE) {
71 return 'combobox';
72 }
73
74 return mode;
75 });
76 var prefixCls = computed(function () {
77 return configProvider.getPrefixCls('select', props.prefixCls);
78 });
79 var mergedClassName = computed(function () {
80 var _classNames;
81
82 return classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls.value, "-lg"), props.size === 'large'), _defineProperty(_classNames, "".concat(prefixCls.value, "-sm"), props.size === 'small'), _defineProperty(_classNames, "".concat(prefixCls.value, "-rtl"), props.direction === 'rtl'), _defineProperty(_classNames, "".concat(prefixCls.value, "-borderless"), !props.bordered), _classNames), attrs.class);
83 });
84
85 var triggerChange = function triggerChange() {
86 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
87 args[_key] = arguments[_key];
88 }
89
90 emit.apply(void 0, ['update:value'].concat(args));
91 emit.apply(void 0, ['change'].concat(args));
92 };
93
94 return {
95 selectRef: selectRef,
96 mergedClassName: mergedClassName,
97 mode: mode,
98 focus: focus,
99 blur: blur,
100 configProvider: configProvider,
101 triggerChange: triggerChange,
102 prefixCls: prefixCls
103 };
104 },
105 render: function render() {
106 var _a;
107
108 var configProvider = this.configProvider,
109 mode = this.mode,
110 mergedClassName = this.mergedClassName,
111 triggerChange = this.triggerChange,
112 prefixCls = this.prefixCls,
113 slots = this.$slots,
114 $props = this.$props;
115 var props = $props;
116 var notFoundContent = props.notFoundContent,
117 _props$listHeight = props.listHeight,
118 listHeight = _props$listHeight === void 0 ? 256 : _props$listHeight,
119 _props$listItemHeight = props.listItemHeight,
120 listItemHeight = _props$listItemHeight === void 0 ? 24 : _props$listItemHeight,
121 getPopupContainer = props.getPopupContainer,
122 dropdownClassName = props.dropdownClassName,
123 direction = props.direction,
124 virtual = props.virtual,
125 dropdownMatchSelectWidth = props.dropdownMatchSelectWidth;
126 var renderEmpty = configProvider.renderEmpty,
127 getContextPopupContainer = configProvider.getPopupContainer;
128 var isMultiple = mode === 'multiple' || mode === 'tags'; // ===================== Empty =====================
129
130 var mergedNotFound;
131
132 if (notFoundContent !== undefined) {
133 mergedNotFound = notFoundContent;
134 } else if (slots.notFoundContent) {
135 mergedNotFound = slots.notFoundContent();
136 } else if (mode === 'combobox') {
137 mergedNotFound = null;
138 } else {
139 mergedNotFound = renderEmpty('Select');
140 } // ===================== Icons =====================
141
142
143 var _getIcons = getIcons(_extends(_extends({}, this.$props), {
144 multiple: isMultiple,
145 prefixCls: prefixCls
146 }), slots),
147 suffixIcon = _getIcons.suffixIcon,
148 itemIcon = _getIcons.itemIcon,
149 removeIcon = _getIcons.removeIcon,
150 clearIcon = _getIcons.clearIcon;
151
152 var selectProps = omit(props, ['prefixCls', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'size', 'bordered']);
153 var rcSelectRtlDropDownClassName = classNames(dropdownClassName, _defineProperty({}, "".concat(prefixCls, "-dropdown-").concat(direction), direction === 'rtl'));
154 return _createVNode(RcSelect, _objectSpread(_objectSpread(_objectSpread({
155 "ref": "selectRef",
156 "virtual": virtual,
157 "dropdownMatchSelectWidth": dropdownMatchSelectWidth
158 }, selectProps), this.$attrs), {}, {
159 "listHeight": listHeight,
160 "listItemHeight": listItemHeight,
161 "mode": mode,
162 "prefixCls": prefixCls,
163 "direction": direction,
164 "inputIcon": suffixIcon,
165 "menuItemSelectedIcon": itemIcon,
166 "removeIcon": removeIcon,
167 "clearIcon": clearIcon,
168 "notFoundContent": mergedNotFound,
169 "class": mergedClassName,
170 "getPopupContainer": getPopupContainer || getContextPopupContainer,
171 "dropdownClassName": rcSelectRtlDropDownClassName,
172 "onChange": triggerChange,
173 "dropdownRender": selectProps.dropdownRender || this.$slots.dropdownRender
174 }), {
175 default: function _default() {
176 return [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)];
177 }
178 });
179 }
180});
181/* istanbul ignore next */
182
183Select.install = function (app) {
184 app.component(Select.name, Select);
185 app.component(Select.Option.displayName, Select.Option);
186 app.component(Select.OptGroup.displayName, Select.OptGroup);
187 return app;
188};
189
190export default Select;
\No newline at end of file