UNPKG

@braineet/ui

Version:

Braineet design system

53 lines 2.13 kB
var _excluded = ["colorValue", "value", "name", "form", "uniqd", "field"]; 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); } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } /* eslint-disable no-nested-ternary */ import React from 'react'; import Icon from '../icon'; import { Checkbox, CheckboxColorStyled } from './sc.selectColor'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; var CheckboxColor = function CheckboxColor(_ref) { var colorValue = _ref.colorValue, v = _ref.value, name = _ref.name, form = _ref.form, uniqd = _ref.uniqd, field = _ref.field, restProps = _objectWithoutPropertiesLoose(_ref, _excluded); var fieldName = form && form.touched && field ? field.name : name; var value = field && field.value ? field.value : v; var onKeyDown = function onKeyDown(e) { if (e.key === 'Enter' && form.setFieldValue && field.name) { form.setFieldValue(field.name, colorValue); e.preventDefault(); e.stopPropagation(); } }; return /*#__PURE__*/_jsxs(CheckboxColorStyled, { as: "label", tabIndex: 0, htmlFor: "" + fieldName + uniqd + colorValue.replace('#', ''), colorValue: colorValue, onKeyDown: onKeyDown, isActive: value === colorValue, children: [value === colorValue ? /*#__PURE__*/_jsx(Icon, { color: "white", name: "tick", size: 24 }) : null, /*#__PURE__*/_jsx(Checkbox, _extends({ tabIndex: "-1", type: "radio", checked: value === colorValue }, field, restProps, { id: "" + fieldName + uniqd + colorValue.replace('#', ''), value: colorValue }))] }); }; CheckboxColor.defaultProps = { value: null, name: null, form: null, field: null }; export default CheckboxColor;