@stihl-design-system/components
Version:
Welcome to the STIHL Design System react component library.
107 lines (106 loc) • 5.13 kB
JavaScript
"use client";
import { jsx as V } from "react/jsx-runtime";
import { d as K } from "./index.D-sRdssb.js";
import { c as Q } from "./index.DL9mof6u.js";
import { forwardRef as W, useState as X } from "react";
import { D as Y } from "./Fieldset.C0RzpI-h.js";
import { DSRadio as Z } from "../radio.DHUfSPai.js";
import { g as m, r as M } from "./helpers.CexwVao7.js";
import '../assets/RadioGroup.CM2mYOzc.css';const oo = "ds-radio-group_root_12fot_1", eo = "ds-radio-group_root--horizontal_12fot_9", to = "ds-radio-group_root--invalid_12fot_12", O = {
root: oo,
rootHorizontal: eo,
rootInvalid: to
}, j = (i) => i.some(({
hint: s
}) => !!s), T = (i) => i.some(({
customArea: s,
isCustomAreaAbove: o
}) => !!s && !o), ro = ({
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", M("legend", "DSRadioGroup")));
if (!s)
throw new Error(m("DSRadioGroup", M("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", M("options", "DSRadioGroup")));
if (c === "horizontal" && j(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" && T(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."));
}, io = W((i, s) => {
const o = K.c(57);
let l, c, a, e, u, p, h, t, v, D, w, d, b, y, H, E, _, z;
o[0] !== i ? ({
legend: u,
name: p,
options: t,
className: l,
defaultValue: c,
description: a,
direction: b,
disabled: y,
hideUncheckedHints: H,
id: e,
invalid: E,
popoverContent: v,
popoverInfoButtonProps: D,
required: _,
systemFeedback: d,
value: z,
onChange: h,
...w
} = 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] = w, o[12] = d, o[13] = b, o[14] = y, o[15] = H, o[16] = E, o[17] = _, o[18] = z) : (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], w = o[11], d = o[12], b = o[13], y = o[14], H = o[15], E = o[16], _ = o[17], z = o[18]);
const L = b === void 0 ? "vertical" : b, n = y === void 0 ? !1 : y, S = H === void 0 ? !1 : H, f = E === void 0 ? !1 : E, g = _ === void 0 ? !1 : _;
process.env.NODE_ENV !== "production" && ro({
legend: u,
name: p,
options: t,
description: a,
direction: L,
id: e,
systemFeedback: d
});
const [$, J] = X(c), C = z !== void 0, A = C ? z : $, P = L === "horizontal" && !j(t) && !T(t), U = f && !!d;
let k;
o[19] !== P || o[20] !== U ? (k = Q(O.root, {
[O.rootHorizontal]: P,
[O.rootInvalid]: U
}), o[19] = P, o[20] = U, o[21] = k) : k = o[21];
const x = k;
let q;
o[22] !== n || o[23] !== C || o[24] !== h ? (q = (r) => {
if (n) {
r.preventDefault();
return;
}
C || J(r.target.value), h && h(r);
}, o[22] = n, o[23] = C, o[24] = h, o[25] = q) : q = o[25];
const B = q;
let I;
o[26] !== S || o[27] !== t ? (I = j(t) && !S, o[26] = S, o[27] = t, o[28] = I) : I = o[28];
const F = I;
let G;
o[29] !== F || o[30] !== A || o[31] !== n || o[32] !== S || o[33] !== e || o[34] !== f || o[35] !== p || o[36] !== t || o[37] !== s || o[38] !== g ? (G = t.map((r) => /* @__PURE__ */ V(Z, { name: p, checked: r.value === A, disabled: n, fieldsetId: e, hideUncheckedHint: S, hint: r.hint, invalid: f, isBold: F, required: g, ref: r.value === A ? s : null, ...r }, e + r.label + r.value + r.hint)), o[29] = F, o[30] = A, o[31] = n, o[32] = S, o[33] = e, o[34] = f, o[35] = p, o[36] = t, o[37] = s, o[38] = g, o[39] = G) : G = o[39];
let R;
o[40] !== x || o[41] !== G ? (R = /* @__PURE__ */ V("div", { className: x, children: G }), o[40] = x, o[41] = G, o[42] = R) : R = o[42];
let N;
return o[43] !== l || o[44] !== a || o[45] !== n || o[46] !== B || o[47] !== e || o[48] !== f || o[49] !== u || o[50] !== v || o[51] !== D || o[52] !== g || o[53] !== w || o[54] !== d || o[55] !== R ? (N = /* @__PURE__ */ V(Y, { id: e, legend: u, className: l, description: a, disabled: n, required: g, invalid: f, systemFeedback: d, popoverContent: v, popoverInfoButtonProps: D, ...w, role: "radiogroup", onChange: B, children: R }), o[43] = l, o[44] = a, o[45] = n, o[46] = B, o[47] = e, o[48] = f, o[49] = u, o[50] = v, o[51] = D, o[52] = g, o[53] = w, o[54] = d, o[55] = R, o[56] = N) : N = o[56], N;
});
io.displayName = "DSRadioGroup";
export {
io as D,
T as a,
j as o,
ro as v
};