UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

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