UNPKG

@intility/bifrost-react

Version:

React library for Intility's design system, Bifrost.

203 lines 4.69 kB
import { c as _c } from "react-compiler-runtime"; import { forwardRef } from "react"; import classnames from "classnames"; import CheckboxIcon from "../common/CheckboxIcon.internal.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * Checkbox, radio button, or a switch toggle * * @see https://bifrost.intility.com/react/checkbox * * @example * <Checkbox label="Basic checkbox" /> * * @example * <Checkbox * label="Controlled state" * checked={selected} * onChange={() => setSelected(!selected)} * /> */ const Checkbox = /*#__PURE__*/forwardRef((t0, ref) => { const $ = _c(47); let align; let className; let inputClassName; let inputStyle; let label; let labelProps; let props; let style; let t1; let t2; let t3; let t4; let t5; let t6; if ($[0] !== t0) { ({ label, indeterminate: t1, hideLabel: t2, type: t3, button: t4, small: t5, className, align, state: t6, style, inputClassName, inputStyle, labelProps, ...props } = t0); $[0] = t0; $[1] = align; $[2] = className; $[3] = inputClassName; $[4] = inputStyle; $[5] = label; $[6] = labelProps; $[7] = props; $[8] = style; $[9] = t1; $[10] = t2; $[11] = t3; $[12] = t4; $[13] = t5; $[14] = t6; } else { align = $[1]; className = $[2]; inputClassName = $[3]; inputStyle = $[4]; label = $[5]; labelProps = $[6]; props = $[7]; style = $[8]; t1 = $[9]; t2 = $[10]; t3 = $[11]; t4 = $[12]; t5 = $[13]; t6 = $[14]; } const indeterminate = t1 === undefined ? false : t1; const hideLabel = t2 === undefined ? false : t2; const type = t3 === undefined ? "checkbox" : t3; const button = t4 === undefined ? false : t4; const small = t5 === undefined ? false : t5; const state = t6 === undefined ? "default" : t6; if (!align) { align = type === "switch" ? "right" : "left"; } const t7 = props.id; const t8 = labelProps; const t9 = labelProps?.className; const t10 = type === "switch"; const t11 = align === "right"; const t12 = state === "alert"; const t13 = state === "inherit"; let t14; if ($[15] !== button || $[16] !== className || $[17] !== hideLabel || $[18] !== small || $[19] !== t10 || $[20] !== t11 || $[21] !== t12 || $[22] !== t13 || $[23] !== t9) { t14 = classnames("bf-checkbox", "bf-open-sans", className, t9, { "bf-switch-wrapper": t10, "bf-checkbox-hidelabel": hideLabel, "bf-checkbox-button": button, "bf-checkbox-small": small, "bf-checkbox-right": t11, "bf-checkbox-alert": t12, "bf-checkbox-inherit": t13 }); $[15] = button; $[16] = className; $[17] = hideLabel; $[18] = small; $[19] = t10; $[20] = t11; $[21] = t12; $[22] = t13; $[23] = t9; $[24] = t14; } else { t14 = $[24]; } const t15 = labelProps?.style; let t16; if ($[25] !== style || $[26] !== t15) { t16 = { ...style, ...t15 }; $[25] = style; $[26] = t15; $[27] = t16; } else { t16 = $[27]; } const t17 = type === "radio" ? "radio" : "checkbox"; let t18; if ($[28] !== inputClassName || $[29] !== inputStyle || $[30] !== props || $[31] !== ref || $[32] !== t17) { t18 = /*#__PURE__*/_jsx("input", { type: t17, ...props, ref: ref, className: inputClassName, style: inputStyle }); $[28] = inputClassName; $[29] = inputStyle; $[30] = props; $[31] = ref; $[32] = t17; $[33] = t18; } else { t18 = $[33]; } let t19; if ($[34] !== indeterminate || $[35] !== type) { t19 = /*#__PURE__*/_jsx(CheckboxIcon, { type: type, indeterminate: indeterminate }); $[34] = indeterminate; $[35] = type; $[36] = t19; } else { t19 = $[36]; } let t20; if ($[37] !== label) { t20 = /*#__PURE__*/_jsx("span", { className: "bf-checkbox-text", children: label }); $[37] = label; $[38] = t20; } else { t20 = $[38]; } let t21; if ($[39] !== labelProps || $[40] !== props.id || $[41] !== t14 || $[42] !== t16 || $[43] !== t18 || $[44] !== t19 || $[45] !== t20) { t21 = /*#__PURE__*/_jsxs("label", { htmlFor: t7, ...t8, className: t14, style: t16, children: [t18, t19, t20] }); $[39] = labelProps; $[40] = props.id; $[41] = t14; $[42] = t16; $[43] = t18; $[44] = t19; $[45] = t20; $[46] = t21; } else { t21 = $[46]; } return t21; }); Checkbox.displayName = "Checkbox"; export default Checkbox;