UNPKG

@braineet/ui

Version:

Braineet design system

64 lines 2.59 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); } 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 } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { 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: {} };