UNPKG

@cimpress/react-components

Version:
32 lines 2.2 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from 'react'; import { cx } from '@emotion/css'; import { useMemoizedId } from '../utils'; import createStyle from './styles'; import { CheckSvg } from '../icons/CheckSvg'; import { IndeterminateSvg } from '../icons/IndeterminateSvg'; const checkboxStyle = createStyle({ checkbox: '.focusable-checkbox', label: 'label' }); export const Checkbox = (_a) => { var { id, indeterminate, onChange, className, style = {}, label, payload, whiteBackground, onBlur, onFocus, inline } = _a, rest = __rest(_a, ["id", "indeterminate", "onChange", "className", "style", "label", "payload", "whiteBackground", "onBlur", "onFocus", "inline"]); const inputId = useMemoizedId({ id }); const backgroundColor = whiteBackground ? 'white' : undefined; const handleChange = (e) => onChange && onChange(e, payload); return (React.createElement("div", { className: cx('crc-checkbox', checkboxStyle, className), style: Object.assign(Object.assign({}, style), { backgroundColor, display: inline ? 'inline' : 'block' }) }, React.createElement("input", Object.assign({}, rest, { className: cx('focusable-checkbox', indeterminate && 'focusable-checkbox-indeterminate'), onChange: handleChange, onBlur: e => onBlur && onBlur(e), onFocus: e => onFocus && onFocus(e), type: "checkbox", id: inputId })), React.createElement("label", { htmlFor: inputId }, React.createElement("div", { "aria-hidden": "true" }, React.createElement(CheckSvg, { className: "focusable-checkbox__check-icon" }), React.createElement(IndeterminateSvg, { className: "focusable-checkbox__indeterminate-icon" })), label))); }; //# sourceMappingURL=Checkbox.js.map