UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

126 lines (125 loc) 6.12 kB
"use client"; import { jsx as T } from "react/jsx-runtime"; import { d as X } from "./index.D-sRdssb.js"; import { c as J } from "./index.DL9mof6u.js"; import { forwardRef as Y, useState as Z } from "react"; import { D as oo } from "./Fieldset.Bk8W5h13.js"; import { DSRadio as eo } from "../radio.DYKHJbxF.js"; import { g, r as W } from "./helpers.CexwVao7.js"; import '../assets/RadioGroup.q1lQ-HIZ.css';const to = "ds-radio-group_fieldset--custom-area-above_1r3gv_1", ro = "ds-radio-group_root_1r3gv_5", so = "ds-radio-group_root--horizontal_1r3gv_13", io = "ds-radio-group_root--invalid_1r3gv_16", ao = "ds-radio-group_root--custom-area-above_1r3gv_19", no = "ds-radio-group_root--custom-area-above--horizontal_1r3gv_26", H = { fieldsetCustomAreaAbove: to, root: ro, rootHorizontal: so, rootInvalid: io, rootCustomAreaAbove: ao, rootCustomAreaAboveHorizontal: no }, lo = (r) => r.some(({ hint: s }) => !!s), co = (r) => r.some(({ customArea: s, isCustomAreaAbove: o }) => !!s && !o), F = (r) => r.some(({ customArea: s, isCustomAreaAbove: o }) => !!s && o), uo = ({ legend: r, name: s, options: o, description: d, direction: p, hideUncheckedHints: a, id: t, systemFeedback: n }) => { if (!t && (d || n)) throw new Error(g("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 (!r) throw new Error(g("DSRadioGroup", W("legend", "DSRadioGroup"))); if (!s) throw new Error(g("DSRadioGroup", W("name", "DSRadioGroup"))); if (Array.isArray(o)) { if (o.length === 0) throw new Error(g("DSRadioGroup", "The options array must not be empty.")); } else throw new Error(g("DSRadioGroup", W("options", "DSRadioGroup"))); if (p === "horizontal" && co(o)) throw new Error(g("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.")); p === "horizontal" && a && console.warn(g("DSRadioGroup", "Setting 'hideUncheckedHints' to 'true' is not possible when direction is 'horizontal'. Please remove 'hideUncheckedHints' or change direction property to 'vertical'.")); }, po = Y((r, s) => { const o = X.c(66); let d, p, a, t, n, v, m, e, A, b, C, c, z, G, R, y, E, k; o[0] !== r ? ({ legend: n, name: v, options: e, className: d, defaultValue: p, description: a, direction: z, disabled: G, hideUncheckedHints: R, id: t, invalid: y, popoverContent: A, popoverInfoButtonProps: b, required: E, systemFeedback: c, value: k, onChange: m, ...C } = r, o[0] = r, o[1] = d, o[2] = p, o[3] = a, o[4] = t, o[5] = n, o[6] = v, o[7] = m, o[8] = e, o[9] = A, o[10] = b, o[11] = C, o[12] = c, o[13] = z, o[14] = G, o[15] = R, o[16] = y, o[17] = E, o[18] = k) : (d = o[1], p = o[2], a = o[3], t = o[4], n = o[5], v = o[6], m = o[7], e = o[8], A = o[9], b = o[10], C = o[11], c = o[12], z = o[13], G = o[14], R = o[15], y = o[16], E = o[17], k = o[18]); const u = z === void 0 ? "vertical" : z, l = G === void 0 ? !1 : G, h = R === void 0 ? !1 : R, f = y === void 0 ? !1 : y, D = E === void 0 ? !1 : E; process.env.NODE_ENV !== "production" && uo({ legend: n, name: v, options: e, description: a, direction: u, hideUncheckedHints: h, id: t, systemFeedback: c }); const [K, Q] = Z(p), N = k !== void 0, q = N ? k : K; let x; o[19] !== d || o[20] !== e ? (x = J({ [H.fieldsetCustomAreaAbove]: F(e) }, d), o[19] = d, o[20] = e, o[21] = x) : x = o[21]; const V = x, M = u === "horizontal", O = f && !!c; let I; o[22] !== u || o[23] !== e || o[24] !== M || o[25] !== O ? (I = J(H.root, { [H.rootHorizontal]: M, [H.rootInvalid]: O, [H.rootCustomAreaAbove]: F(e), [H.rootCustomAreaAboveHorizontal]: F(e) && u === "horizontal" }), o[22] = u, o[23] = e, o[24] = M, o[25] = O, o[26] = I) : I = o[26]; const $ = I; let P; o[27] !== l || o[28] !== N || o[29] !== m ? (P = (i) => { if (l) { i.preventDefault(); return; } N || Q(i.target.value), m && m(i); }, o[27] = l, o[28] = N, o[29] = m, o[30] = P) : P = o[30]; const j = P; let U; o[31] !== h || o[32] !== e ? (U = lo(e) && !h, o[31] = h, o[32] = e, o[33] = U) : U = o[33]; const L = U; let S; o[34] !== u || o[35] !== e ? (S = F(e) && u === "horizontal" ? { maxWidth: `calc(${e.length * 400}px + var(--ds-spacing-dynamic-xs))` } : void 0, o[34] = u, o[35] = e, o[36] = S) : S = o[36]; let _; o[37] !== L || o[38] !== q || o[39] !== l || o[40] !== h || o[41] !== t || o[42] !== f || o[43] !== v || o[44] !== e || o[45] !== s || o[46] !== D ? (_ = e.map((i) => /* @__PURE__ */ T(eo, { name: v, checked: i.value === q, disabled: l, fieldsetId: t, hideUncheckedHint: h, hint: i.hint, invalid: f, isBold: L, required: D, ref: i.value === q ? s : null, ...i }, t + i.label + i.value + i.hint)), o[37] = L, o[38] = q, o[39] = l, o[40] = h, o[41] = t, o[42] = f, o[43] = v, o[44] = e, o[45] = s, o[46] = D, o[47] = _) : _ = o[47]; let w; o[48] !== $ || o[49] !== S || o[50] !== _ ? (w = /* @__PURE__ */ T("div", { className: $, style: S, children: _ }), o[48] = $, o[49] = S, o[50] = _, o[51] = w) : w = o[51]; let B; return o[52] !== a || o[53] !== l || o[54] !== V || o[55] !== j || o[56] !== t || o[57] !== f || o[58] !== n || o[59] !== A || o[60] !== b || o[61] !== D || o[62] !== C || o[63] !== c || o[64] !== w ? (B = /* @__PURE__ */ T(oo, { id: t, legend: n, className: V, description: a, disabled: l, required: D, invalid: f, systemFeedback: c, popoverContent: A, popoverInfoButtonProps: b, ...C, role: "radiogroup", onChange: j, children: w }), o[52] = a, o[53] = l, o[54] = V, o[55] = j, o[56] = t, o[57] = f, o[58] = n, o[59] = A, o[60] = b, o[61] = D, o[62] = C, o[63] = c, o[64] = w, o[65] = B) : B = o[65], B; }); po.displayName = "DSRadioGroup"; export { po as D, co as a, F as b, lo as o, uo as v };