@stihl-design-system/components
Version:
Welcome to the STIHL Design System react component library.
163 lines (162 loc) • 8.79 kB
JavaScript
"use client";
import { jsx as v, jsxs as ge } from "react/jsx-runtime";
import { d as xe } from "./index.CgTHIF3K.js";
import { c as he } from "./index.CEyLAtio.js";
import { forwardRef as Be, useRef as Fe, useState as Ee, useEffect as He } from "react";
import { u as Re } from "./useBreakpoint.CMOR9ZOB.js";
import { Asterisk as je } from "../asterisk.CR60hx8S.js";
import { D as We } from "./Icon.NSsVrYeq.js";
import { D as ze } from "./SystemFeedback.CyGbUCzT.js";
import { g as me, r as Me } from "./helpers.BbWkXTr3.js";
import '../assets/Select.C1gWF32A.css';const Te = "ds-select_root_17q4p_1", Oe = "ds-select_hint_17q4p_10", Ze = "ds-select_label_17q4p_10", Je = "ds-select_label--hidden_17q4p_131", Ke = "ds-select_label--disabled_17q4p_144", Qe = "ds-select_feedback_17q4p_164", Ue = "ds-select_select-wrapper_17q4p_169", Xe = "ds-select_select_17q4p_169", Ye = "ds-select_select--small_17q4p_183", Ge = "ds-select_select--invalid_17q4p_295", el = "ds-select_select--placeholder_17q4p_410", ll = "ds-select_chevron_17q4p_449", tl = "ds-select_chevron--small_17q4p_453", sl = "ds-select_chevron--disabled_17q4p_456", t = {
root: Te,
hint: Oe,
label: Ze,
labelHidden: Je,
labelDisabled: Ke,
feedback: Qe,
selectWrapper: Ue,
select: Xe,
selectSmall: Ye,
selectInvalid: Ge,
selectPlaceholder: el,
chevron: ll,
chevronSmall: tl,
chevronDisabled: sl
}, _l = ["medium", "small"], al = ({
id: n,
label: s,
options: e
}) => {
if (!n)
throw new Error(me("DSSelect", 'A unique "id" prop is required. Please add a unique "id" prop to the DSSelect component.'));
if (!s)
throw new Error(me("DSSelect", `A label is always required for a11y reasons. Please add a descriptive "label" prop to the DSSelect component. If you don't want to display a label, set hideLabel={true}.`));
if (Array.isArray(e)) {
if (e.length === 0)
throw new Error(me("DSSelect", "The options array must not be empty."));
} else throw new Error(me("DSSelect", Me("options", "DSSelect")));
}, ol = (n, s, e) => n === "" || s !== void 0 && s !== "" ? !1 : !(e !== void 0 && e !== ""), cl = Be((n, s) => {
const e = xe.c(127);
let i, d, r, l, p, f, S, q, a, Z, J, K, Q, U, X, c;
e[0] !== n ? ({
id: l,
label: p,
options: S,
className: i,
defaultValue: d,
disabled: Z,
hideLabel: J,
hint: r,
invalid: K,
placeholder: Q,
required: U,
size: X,
systemFeedback: a,
value: c,
onChange: f,
...q
} = n, e[0] = n, e[1] = i, e[2] = d, e[3] = r, e[4] = l, e[5] = p, e[6] = f, e[7] = S, e[8] = q, e[9] = a, e[10] = Z, e[11] = J, e[12] = K, e[13] = Q, e[14] = U, e[15] = X, e[16] = c) : (i = e[1], d = e[2], r = e[3], l = e[4], p = e[5], f = e[6], S = e[7], q = e[8], a = e[9], Z = e[10], J = e[11], K = e[12], Q = e[13], U = e[14], X = e[15], c = e[16]);
const b = Z === void 0 ? !1 : Z, Ie = J === void 0 ? !1 : J, o = K === void 0 ? !1 : K, D = Q === void 0 ? "Select" : Q, y = U === void 0 ? !1 : U, le = X === void 0 ? "medium" : X;
process.env.NODE_ENV !== "production" && al({
id: l,
label: p,
options: S
});
const Pe = Fe(null), [ue, we] = Ee(c);
let te;
e[17] !== d || e[18] !== D || e[19] !== c ? (te = ol(D, d, c), e[17] = d, e[18] = D, e[19] = c, e[20] = te) : te = e[20];
const [Y, Ce] = Ee(te);
let se, ae;
e[21] !== c ? (se = () => {
we(c);
}, ae = [c], e[21] = c, e[22] = se, e[23] = ae) : (se = e[22], ae = e[23]), He(se, ae);
let oe;
e[24] !== s ? (oe = (ee) => {
Pe.current = ee, typeof s == "function" ? s(ee) : s && (s.current = ee);
}, e[24] = s, e[25] = oe) : oe = e[25];
const _e = oe, G = Re(Ie), g = `${l}-label`, h = `${l}-feedback`, w = `${l}-hint`, ve = r ? ` ${w}` : "";
let ce;
e[26] !== o || e[27] !== a || e[28] !== h ? (ce = [o && a && h].filter(Boolean).join(" ") || void 0, e[26] = o, e[27] = a, e[28] = h, e[29] = ce) : ce = e[29];
const Se = ce;
let N, k, E, I, P, C, $, L, V, A, x, B, F, H, R, j, m, u, _;
if (e[30] !== Se || e[31] !== ve || e[32] !== i || e[33] !== d || e[34] !== b || e[35] !== _e || e[36] !== G || e[37] !== r || e[38] !== w || e[39] !== l || e[40] !== o || e[41] !== Y || e[42] !== p || e[43] !== f || e[44] !== S || e[45] !== D || e[46] !== y || e[47] !== q || e[48] !== g || e[49] !== ue || e[50] !== le || e[51] !== a || e[52] !== h) {
const ee = (be) => [D && /* @__PURE__ */ v("option", { value: "", children: D }, `${l}-hidden-option-disabled-placeholder`), ...be.map((O) => {
if ("options" in O) {
const {
label: ke,
options: Ae
} = O;
return /* @__PURE__ */ v("optgroup", { label: ke, children: Ae.map(Ne) }, ke);
} else
return Ne(O);
})], Ne = il;
let re;
e[72] !== i ? (re = he(t.root, i), e[72] = i, e[73] = re) : re = e[73];
const $e = re, De = le === "small";
let ne;
e[74] !== o || e[75] !== Y || e[76] !== De ? (ne = he(t.select, {
[t.selectSmall]: De,
[t.selectInvalid]: o,
[t.selectPlaceholder]: Y
}), e[74] = o, e[75] = Y, e[76] = De, e[77] = ne) : ne = e[77];
const Le = ne;
let de;
e[78] !== b || e[79] !== G ? (de = he(t.label, {
[t.labelHidden]: G,
[t.labelDisabled]: b
}), e[78] = b, e[79] = G, e[80] = de) : de = e[80];
const qe = de, ye = le === "small";
let pe;
e[81] !== b || e[82] !== ye ? (pe = he(t.chevron, {
[t.chevronSmall]: ye,
[t.chevronDisabled]: b
}), e[81] = b, e[82] = ye, e[83] = pe) : pe = e[83], N = pe;
let fe;
e[84] !== f ? (fe = (be) => {
const {
value: O
} = be.target;
Ce(O === ""), we(O), f && f(be);
}, e[84] = f, e[85] = fe) : fe = e[85];
const Ve = fe;
j = $e;
let T;
e[86] !== y ? (T = y && /* @__PURE__ */ v(je, {}), e[86] = y, e[87] = T) : T = e[87], e[88] !== l || e[89] !== p || e[90] !== qe || e[91] !== g || e[92] !== T ? (m = /* @__PURE__ */ ge("label", { className: qe, id: g, htmlFor: l, children: [
p,
T
] }), e[88] = l, e[89] = p, e[90] = qe, e[91] = g, e[92] = T, e[93] = m) : m = e[93], e[94] !== r || e[95] !== w ? (u = r && /* @__PURE__ */ v("div", { className: t.hint, id: w, children: r }), e[94] = r, e[95] = w, e[96] = u) : u = e[96], e[97] !== o || e[98] !== a || e[99] !== h ? (_ = o && a && /* @__PURE__ */ v(ze, { className: t.feedback, message: a, variant: "error", id: h }), e[97] = o, e[98] = a, e[99] = h, e[100] = _) : _ = e[100], R = t.selectWrapper, k = q, E = l, I = _e, P = Le, C = `${g}${ve}`, $ = Se, L = o, V = d, A = ue, x = b, B = y, F = Ve, H = ee(S), e[30] = Se, e[31] = ve, e[32] = i, e[33] = d, e[34] = b, e[35] = _e, e[36] = G, e[37] = r, e[38] = w, e[39] = l, e[40] = o, e[41] = Y, e[42] = p, e[43] = f, e[44] = S, e[45] = D, e[46] = y, e[47] = q, e[48] = g, e[49] = ue, e[50] = le, e[51] = a, e[52] = h, e[53] = N, e[54] = k, e[55] = E, e[56] = I, e[57] = P, e[58] = C, e[59] = $, e[60] = L, e[61] = V, e[62] = A, e[63] = x, e[64] = B, e[65] = F, e[66] = H, e[67] = R, e[68] = j, e[69] = m, e[70] = u, e[71] = _;
} else
N = e[53], k = e[54], E = e[55], I = e[56], P = e[57], C = e[58], $ = e[59], L = e[60], V = e[61], A = e[62], x = e[63], B = e[64], F = e[65], H = e[66], R = e[67], j = e[68], m = e[69], u = e[70], _ = e[71];
let W;
e[101] !== k || e[102] !== E || e[103] !== I || e[104] !== P || e[105] !== C || e[106] !== $ || e[107] !== L || e[108] !== V || e[109] !== A || e[110] !== x || e[111] !== B || e[112] !== F || e[113] !== H ? (W = /* @__PURE__ */ v("select", { ...k, id: E, ref: I, className: P, "aria-labelledby": C, "aria-describedby": $, "aria-invalid": L, defaultValue: V, value: A, disabled: x, required: B, onChange: F, children: H }), e[101] = k, e[102] = E, e[103] = I, e[104] = P, e[105] = C, e[106] = $, e[107] = L, e[108] = V, e[109] = A, e[110] = x, e[111] = B, e[112] = F, e[113] = H, e[114] = W) : W = e[114];
let z;
e[115] !== N ? (z = /* @__PURE__ */ v(We, { name: "chevron-down", className: N, "aria-hidden": "true" }), e[115] = N, e[116] = z) : z = e[116];
let M;
e[117] !== R || e[118] !== W || e[119] !== z ? (M = /* @__PURE__ */ ge("div", { className: R, children: [
W,
z
] }), e[117] = R, e[118] = W, e[119] = z, e[120] = M) : M = e[120];
let ie;
return e[121] !== j || e[122] !== m || e[123] !== u || e[124] !== _ || e[125] !== M ? (ie = /* @__PURE__ */ ge("div", { className: j, children: [
m,
u,
_,
M
] }), e[121] = j, e[122] = m, e[123] = u, e[124] = _, e[125] = M, e[126] = ie) : ie = e[126], ie;
});
cl.displayName = "DSSelect";
function il(n) {
const {
label: s,
value: e,
isDisabled: i
} = n;
return /* @__PURE__ */ v("option", { value: e, disabled: i, children: s }, e);
}
export {
cl as D,
_l as S,
ol as g,
al as v
};