@braineet/ui
Version:
Braineet design system
54 lines • 2.34 kB
JavaScript
var _excluded = ["colorValue", "value", "name", "form", "uniqd", "field"];
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); }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
/* eslint-disable no-nested-ternary */
import React from 'react';
import Icon from '../icon';
import { Checkbox, CheckboxColorStyled } from './sc.selectColor';
import { jsx as _jsx } from "react/jsx-runtime";
import { 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;