UNPKG

@cimpress/react-components

Version:
39 lines 2.65 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Checkbox = void 0; const react_1 = __importDefault(require("react")); const css_1 = require("@emotion/css"); const utils_1 = require("../utils"); const styles_1 = __importDefault(require("./styles")); const CheckSvg_1 = require("../icons/CheckSvg"); const IndeterminateSvg_1 = require("../icons/IndeterminateSvg"); const checkboxStyle = (0, styles_1.default)({ checkbox: '.focusable-checkbox', label: 'label' }); 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 = (0, utils_1.useMemoizedId)({ id }); const backgroundColor = whiteBackground ? 'white' : undefined; const handleChange = (e) => onChange && onChange(e, payload); return (react_1.default.createElement("div", { className: (0, css_1.cx)('crc-checkbox', checkboxStyle, className), style: Object.assign(Object.assign({}, style), { backgroundColor, display: inline ? 'inline' : 'block' }) }, react_1.default.createElement("input", Object.assign({}, rest, { className: (0, css_1.cx)('focusable-checkbox', indeterminate && 'focusable-checkbox-indeterminate'), onChange: handleChange, onBlur: e => onBlur && onBlur(e), onFocus: e => onFocus && onFocus(e), type: "checkbox", id: inputId })), react_1.default.createElement("label", { htmlFor: inputId }, react_1.default.createElement("div", { "aria-hidden": "true" }, react_1.default.createElement(CheckSvg_1.CheckSvg, { className: "focusable-checkbox__check-icon" }), react_1.default.createElement(IndeterminateSvg_1.IndeterminateSvg, { className: "focusable-checkbox__indeterminate-icon" })), label))); }; exports.Checkbox = Checkbox; //# sourceMappingURL=Checkbox.js.map