UNPKG

alinea

Version:
73 lines (70 loc) 3.3 kB
import { T, j, l, p as p2 } from "./chunk-ORDS5C6Z.js"; import { H, I, K as K2, Q, U, a, u, w as w2 } from "./chunk-SOTBYUJY.js"; import { r as r2 } from "./chunk-2NTSADJL.js"; import { $6179b936705e76d3$export$ae780daf29e6d456, $f7dceffc5ad7768b$export$4e328f61c538687f, K, L, _, e, o2 as o, o3 as o2, p, r, w, y } from "./chunk-VUACWPFC.js"; // node_modules/@headlessui/react/dist/components/switch/switch.js import i, { Fragment as Z, createContext as ee, useCallback as te, useContext as oe, useMemo as R, useRef as re, useState as w3 } from "react"; var E = ee(null); E.displayName = "GroupContext"; var De = Z; function ge(n) { var u2; let [o3, s] = w3(null), [h, b] = K2(), [T2, t] = w2(), p3 = R(() => ({ switch: o3, setSwitch: s }), [o3, s]), y2 = {}, S = n, c = L(); return i.createElement(t, { name: "Switch.Description", value: T2 }, i.createElement(b, { name: "Switch.Label", value: h, props: { htmlFor: (u2 = p3.switch) == null ? void 0 : u2.id, onClick(d) { o3 && (d.currentTarget instanceof HTMLLabelElement && d.preventDefault(), o3.click(), o3.focus({ preventScroll: true })); } } }, i.createElement(E.Provider, { value: p3 }, c({ ourProps: y2, theirProps: S, slot: {}, defaultTag: De, name: "Switch.Group" })))); } var ve = "button"; function xe(n, o3) { var L2; let s = r(), h = u(), b = a(), { id: T2 = h || `headlessui-switch-${s}`, disabled: t = b || false, checked: p3, defaultChecked: y2, onChange: S, name: c, value: u2, form: d, autoFocus: m = false, ...F } = n, _2 = oe(E), [H2, k] = w3(null), M = re(null), U2 = y(M, o3, _2 === null ? null : _2.setSwitch, k), l2 = l(y2), [a2, r3] = T(p3, S, l2 != null ? l2 : false), I2 = p(), [P, D] = w3(false), g = o(() => { D(true), r3 == null || r3(!a2), I2.nextFrame(() => { D(false); }); }), B = o((e2) => { if (r2(e2.currentTarget)) return e2.preventDefault(); e2.preventDefault(), g(); }), K3 = o((e2) => { e2.key === o2.Space ? (e2.preventDefault(), g()) : e2.key === o2.Enter && p2(e2.currentTarget); }), W = o((e2) => e2.preventDefault()), O = I(), N = U(), { isFocusVisible: v, focusProps: J } = $f7dceffc5ad7768b$export$4e328f61c538687f({ autoFocus: m }), { isHovered: x, hoverProps: V } = $6179b936705e76d3$export$ae780daf29e6d456({ isDisabled: t }), { pressed: C, pressProps: X } = w({ disabled: t }), j2 = R(() => ({ checked: a2, disabled: t, hover: x, focus: v, active: C, autofocus: m, changing: P }), [a2, x, v, C, t, P, m]), $ = _({ id: T2, ref: U2, role: "switch", type: e(n, H2), tabIndex: n.tabIndex === -1 ? 0 : (L2 = n.tabIndex) != null ? L2 : 0, "aria-checked": a2, "aria-labelledby": O, "aria-describedby": N, disabled: t || void 0, autoFocus: m, onClick: B, onKeyUp: K3, onKeyPress: W }, J, V, X), q = te(() => { if (l2 !== void 0) return r3 == null ? void 0 : r3(l2); }, [r3, l2]), z = L(); return i.createElement(i.Fragment, null, c != null && i.createElement(j, { disabled: t, data: { [c]: u2 || "on" }, overrides: { type: "checkbox", checked: a2 }, form: d, onReset: q }), z({ ourProps: $, theirProps: F, slot: j2, defaultTag: ve, name: "Switch" })); } var Ce = K(xe); var Le = ge; var Re = Q; var Ge = H; var Ye = Object.assign(Ce, { Group: Le, Label: Re, Description: Ge }); export { Ye };