UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

105 lines (104 loc) 4.93 kB
"use client"; import { jsx as F } from "react/jsx-runtime"; import { d as $ } from "./index.CgTHIF3K.js"; import { c as J } from "./index.CEyLAtio.js"; import { forwardRef as K, useState as Q } from "react"; import { D as W } from "./Fieldset.D7cLR5ze.js"; import { DSRadio as X } from "../radio.7_N_alaS.js"; import { g as m, r as V } from "./helpers.BbWkXTr3.js"; import '../assets/RadioGroup.CM2mYOzc.css';const Y = "ds-radio-group_root_12fot_1", Z = "ds-radio-group_root--horizontal_12fot_9", oo = "ds-radio-group_root--invalid_12fot_12", B = { root: Y, rootHorizontal: Z, rootInvalid: oo }, M = (i) => i.some(({ hint: s }) => !!s), j = (i) => i.some(({ customArea: s, isCustomAreaAbove: o }) => !!s && !o), eo = ({ legend: i, name: s, options: o, description: l, direction: c, id: a, systemFeedback: e }) => { if (!a && (l || e)) throw new Error(m("DSRadioGroup", 'A unique "id" prop is required when providing the description or systemFeedback property. Please add a unique "id" prop to the DSRadioGroup component.')); if (!i) throw new Error(m("DSRadioGroup", V("legend", "DSRadioGroup"))); if (!s) throw new Error(m("DSRadioGroup", V("name", "DSRadioGroup"))); if (Array.isArray(o)) { if (o.length === 0) throw new Error(m("DSRadioGroup", "The options array must not be empty.")); } else throw new Error(m("DSRadioGroup", V("options", "DSRadioGroup"))); if (c === "horizontal" && M(o)) throw new Error(m("DSRadioGroup", "Horizontal direction is not possible when options contain a hint. Please remove hints or change direction property to 'vertical'.")); if (c === "horizontal" && j(o)) throw new Error(m("DSRadioGroup", "Horizontal direction is not possible when options contain a custom area without isCustomAreaAbove set to true. Please remove custom areas, change direction property to 'vertical' or set isCustomAreaAbove to true.")); }, to = K((i, s) => { const o = $.c(53); let l, c, a, e, u, p, h, t, v, d, G, R, b, y, H, E; o[0] !== i ? ({ legend: u, name: p, options: t, className: l, defaultValue: c, description: a, direction: G, disabled: R, hideUncheckedHints: b, id: e, invalid: y, required: H, systemFeedback: d, value: E, onChange: h, ...v } = i, o[0] = i, o[1] = l, o[2] = c, o[3] = a, o[4] = e, o[5] = u, o[6] = p, o[7] = h, o[8] = t, o[9] = v, o[10] = d, o[11] = G, o[12] = R, o[13] = b, o[14] = y, o[15] = H, o[16] = E) : (l = o[1], c = o[2], a = o[3], e = o[4], u = o[5], p = o[6], h = o[7], t = o[8], v = o[9], d = o[10], G = o[11], R = o[12], b = o[13], y = o[14], H = o[15], E = o[16]); const O = G === void 0 ? "vertical" : G, n = R === void 0 ? !1 : R, D = b === void 0 ? !1 : b, f = y === void 0 ? !1 : y, w = H === void 0 ? !1 : H; process.env.NODE_ENV !== "production" && eo({ legend: u, name: p, options: t, description: a, direction: O, id: e, systemFeedback: d }); const [L, T] = Q(c), _ = E !== void 0, z = _ ? E : L, N = O === "horizontal" && !M(t) && !j(t), I = f && !!d; let A; o[17] !== N || o[18] !== I ? (A = J(B.root, { [B.rootHorizontal]: N, [B.rootInvalid]: I }), o[17] = N, o[18] = I, o[19] = A) : A = o[19]; const P = A; let C; o[20] !== n || o[21] !== _ || o[22] !== h ? (C = (r) => { if (n) { r.preventDefault(); return; } _ || T(r.target.value), h && h(r); }, o[20] = n, o[21] = _, o[22] = h, o[23] = C) : C = o[23]; const U = C; let k; o[24] !== D || o[25] !== t ? (k = M(t) && !D, o[24] = D, o[25] = t, o[26] = k) : k = o[26]; const x = k; let S; o[27] !== x || o[28] !== z || o[29] !== n || o[30] !== D || o[31] !== e || o[32] !== f || o[33] !== p || o[34] !== t || o[35] !== s || o[36] !== w ? (S = t.map((r) => /* @__PURE__ */ F(X, { name: p, checked: r.value === z, disabled: n, fieldsetId: e, hideUncheckedHint: D, hint: r.hint, invalid: f, isBold: x, required: w, ref: r.value === z ? s : null, ...r }, e + r.label + r.value + r.hint)), o[27] = x, o[28] = z, o[29] = n, o[30] = D, o[31] = e, o[32] = f, o[33] = p, o[34] = t, o[35] = s, o[36] = w, o[37] = S) : S = o[37]; let g; o[38] !== P || o[39] !== S ? (g = /* @__PURE__ */ F("div", { className: P, children: S }), o[38] = P, o[39] = S, o[40] = g) : g = o[40]; let q; return o[41] !== l || o[42] !== a || o[43] !== n || o[44] !== U || o[45] !== e || o[46] !== f || o[47] !== u || o[48] !== w || o[49] !== v || o[50] !== d || o[51] !== g ? (q = /* @__PURE__ */ F(W, { id: e, legend: u, className: l, description: a, disabled: n, required: w, invalid: f, systemFeedback: d, ...v, role: "radiogroup", onChange: U, children: g }), o[41] = l, o[42] = a, o[43] = n, o[44] = U, o[45] = e, o[46] = f, o[47] = u, o[48] = w, o[49] = v, o[50] = d, o[51] = g, o[52] = q) : q = o[52], q; }); to.displayName = "DSRadioGroup"; export { to as D, j as a, M as o, eo as v };