@yandex/ui
Version:
Yandex UI components
19 lines (18 loc) • 1.23 kB
JavaScript
import { __assign, __rest } from "tslib";
import React from 'react';
import { cnSelect } from '../Select';
export var isGroup = function (value) {
return value.items !== undefined;
};
export var toGroupOptions = function (option) {
if (isGroup(option)) {
return (React.createElement("optgroup", { key: option.title, label: option.title }, option.items.map(toGroupOptions)));
}
return (React.createElement("option", { key: option.value, value: option.value, disabled: option.disabled }, option.content));
};
export var withNativeControl = function (Select) { return function (_a) {
var addonAfter = _a.addonAfter, name = _a.name, onChange = _a.onChange, options = _a.options, value = _a.value, onClick = _a.onClick, props = __rest(_a, ["addonAfter", "name", "onChange", "options", "value", "onClick"]);
return (React.createElement(Select, __assign({}, props, { value: value, options: options, addonAfter: React.createElement(React.Fragment, null,
React.createElement("select", { onClick: onClick, className: cnSelect('Control'), multiple: Array.isArray(value), name: name, onChange: onChange, tabIndex: -1, value: value }, options.map(toGroupOptions)),
addonAfter) })));
}; };