UNPKG

@braineet/ui

Version:

Braineet design system

62 lines 2.46 kB
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } import React from 'react'; import { SelectItem } from 'ariakit/select'; import { CheckboxInput, CheckboxBtn } from '../checkbox/item/styles'; import { BaseComboboxItem } from '../combobox'; import Icon from '../icon'; import { Option } from '../option'; import Text from '../text'; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; export var RenderOptions = function RenderOptions(_ref) { var value = _ref.value, options = _ref.options, multiple = _ref.multiple, noResult = _ref.noResult, renderOption = _ref.renderOption, classNames = _ref.classNames; if (options.length === 0) { if (typeof noResult === 'string') return /*#__PURE__*/_jsx(Text, { children: noResult }); if (typeof noResult === 'function') return noResult(); return noResult || null; } return options.map(function (option) { return /*#__PURE__*/_jsx(BaseComboboxItem, { focusOnHover: true, children: function children(props) { return /*#__PURE__*/_jsx(Option, _extends({ as: SelectItem, value: option.value, className: classNames.optionWrapper, style: option.style, ref: option.ref, leftSection: multiple && /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(CheckboxInput, { checked: value.includes(option.value) // needed to avoid a react warning , onChange: function onChange() {}, type: "checkbox", required: false }), /*#__PURE__*/_jsx(CheckboxBtn, { children: /*#__PURE__*/_jsx(Icon, { name: "tick", size: 16, color: "white" }) })] }) }, !(renderOption && typeof renderOption === 'function') ? option : {}, props, { children: renderOption && typeof renderOption === 'function' ? renderOption({ option: option, selected: option.value === value }) : null }), option.value); } }, option.value); }); }; RenderOptions.defaultProps = { classNames: {} };