epn-ui
Version:
Дизайн система кабинета ВМ
45 lines (42 loc) • 4.44 kB
JavaScript
import { __assign } from '../../_virtual/_tslib.js';
import React from 'react';
import Select from 'antd/lib/select';
import clsx from 'clsx';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronDown } from '@fortawesome/pro-regular-svg-icons/faChevronDown';
import { faCheck } from '@fortawesome/pro-regular-svg-icons/faCheck';
import { FavouriteOption } from './customOptions/Favoutite/index.js';
import Loader from '../Loader/index.js';
import Empty from '../Empty/index.js';
import { defaultFilterOptions } from './utils/index.js';
var Option = Select.Option;
function BaseSelect(_a) {
var showSearch = _a.showSearch, options = _a.options, _b = _a.filterOption, filterOption = _b === void 0 ? defaultFilterOptions : _b, disabled = _a.disabled, defaultValue = _a.defaultValue, mode = _a.mode, value = _a.value, _c = _a.maxTagCount, maxTagCount = _c === void 0 ? 4 : _c, placeholder = _a.placeholder, customOption = _a.customOption, className = _a.className, dropdownClassName = _a.dropdownClassName, fieldNames = _a.fieldNames, optionLabelProp = _a.optionLabelProp, loading = _a.loading, notFoundContent = _a.notFoundContent, style = _a.style, _d = _a.size, size = _d === void 0 ? 'middle' : _d, defaultOpen = _a.defaultOpen, id = _a.id, status = _a.status, searchValue = _a.searchValue, placement = _a.placement, autoFocus = _a.autoFocus, allowClear = _a.allowClear, open = _a.open, tokenSeparators = _a.tokenSeparators, maxTagPlaceholder = _a.maxTagPlaceholder, getPopupContainer = _a.getPopupContainer, onInputKeyDown = _a.onInputKeyDown, onBlur = _a.onBlur, onChange = _a.onChange, onFocus = _a.onFocus, onClear = _a.onClear, onPopupScroll = _a.onPopupScroll, onSearch = _a.onSearch, onSelect = _a.onSelect;
var isSearchField = Array.isArray(options) && options.length >= 7;
return (React.createElement(Select, { onInputKeyDown: onInputKeyDown, onChange: onChange, onBlur: onBlur, onFocus: onFocus, onClear: onClear, onPopupScroll: onPopupScroll, onSearch: onSearch, onSelect: onSelect, style: style, className: clsx('epn-select', className), popupClassName: clsx('epn-select-dropdown', dropdownClassName), id: id, open: open, getPopupContainer: getPopupContainer, status: status, placement: placement, allowClear: allowClear, autoFocus: autoFocus, loading: loading, defaultOpen: defaultOpen, fieldNames: fieldNames, notFoundContent: notFoundContent || React.createElement(Empty, { locale: "ru" }), optionLabelProp: optionLabelProp, placeholder: placeholder, maxTagCount: maxTagCount, mode: mode, value: value, defaultValue: defaultValue, disabled: disabled, options: customOption !== undefined ? undefined : options, showSearch: showSearch !== undefined ? showSearch : isSearchField, filterOption: filterOption, searchValue: searchValue, suffixIcon: !loading ? React.createElement(FontAwesomeIcon, { icon: faChevronDown }) : undefined, menuItemSelectedIcon: mode === 'multiple' ? React.createElement(FontAwesomeIcon, { icon: faCheck }) : undefined, tagRender: function (_a) {
var label = _a.label;
return React.createElement("div", { className: "epn-select-customTag" }, label);
}, tokenSeparators: tokenSeparators, maxTagPlaceholder: typeof maxTagPlaceholder !== 'undefined'
? maxTagPlaceholder
: function (omittedValues) {
var overflowItemsCount = omittedValues.length;
return "+".concat(overflowItemsCount);
}, dropdownRender: loading
? function (menu) {
if (Array.isArray(options) && (options === null || options === void 0 ? void 0 : options.length) === 0)
return (React.createElement("div", { className: "epn-select-dropdown-loading" },
React.createElement(Loader, null)));
return (React.createElement(React.Fragment, null,
menu,
React.createElement(Loader, null)));
}
: undefined, size: size }, customOption !== undefined &&
options &&
options.map(function (item) {
var CustomOptionsComponent = customOption;
return (React.createElement(Option, __assign({ key: item.value }, item),
React.createElement(CustomOptionsComponent, __assign({}, item))));
})));
}
BaseSelect.FavouriteOption = FavouriteOption;
export { BaseSelect as default };