UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

163 lines (162 loc) 8.79 kB
"use client"; import { jsx as _, jsxs as we } from "react/jsx-runtime"; import { d as xe } from "./index.CgTHIF3K.js"; import { c as ve } from "./index.CEyLAtio.js"; import { forwardRef as Be, useRef as Fe, useState as Ie, 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.DGTYCv63.js"; import { D as ze } from "./SystemFeedback.B9f67mjJ.js"; import { g as me, r as Me } from "./helpers.BbWkXTr3.js"; import '../assets/Select.CYACicZ3.css';const Te = "ds-select_root_d8v6g_1", Oe = "ds-select_hint_d8v6g_10", Ze = "ds-select_label_d8v6g_10", Je = "ds-select_label--hidden_d8v6g_100", Ke = "ds-select_label--disabled_d8v6g_113", Qe = "ds-select_feedback_d8v6g_133", Ue = "ds-select_select-wrapper_d8v6g_138", Xe = "ds-select_select_d8v6g_138", Ye = "ds-select_select--small_d8v6g_152", Ge = "ds-select_select--invalid_d8v6g_264", el = "ds-select_select--placeholder_d8v6g_379", ll = "ds-select_chevron_d8v6g_418", tl = "ds-select_chevron--small_d8v6g_422", sl = "ds-select_chevron--disabled_d8v6g_425", 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 }, ul = ["medium", "small"], al = ({ id: r, label: s, options: e }) => { if (!r) 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 = (r, s, e) => r === "" || s !== void 0 && s !== "" ? !1 : !(e !== void 0 && e !== ""), cl = Be((r, s) => { const e = xe.c(127); let i, n, d, l, f, b, S, D, a, Z, J, K, Q, U, X, c; e[0] !== r ? ({ id: l, label: f, options: S, className: i, defaultValue: n, disabled: Z, hideLabel: J, hint: d, invalid: K, placeholder: Q, required: U, size: X, systemFeedback: a, value: c, onChange: b, ...D } = r, e[0] = r, e[1] = i, e[2] = n, e[3] = d, e[4] = l, e[5] = f, e[6] = b, e[7] = S, e[8] = D, 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], n = e[2], d = e[3], l = e[4], f = e[5], b = e[6], S = e[7], D = 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 h = Z === void 0 ? !1 : Z, Pe = J === void 0 ? !1 : J, o = K === void 0 ? !1 : K, g = 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: f, options: S }); const qe = Fe(null), [pe, Ne] = Ie(c); let te; e[17] !== n || e[18] !== g || e[19] !== c ? (te = ol(g, n, c), e[17] = n, e[18] = g, e[19] = c, e[20] = te) : te = e[20]; const [Y, Ce] = Ie(te); let se, ae; e[21] !== c ? (se = () => { Ne(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) => { qe.current = ee, typeof s == "function" ? s(ee) : s && (s.current = ee); }, e[24] = s, e[25] = oe) : oe = e[25]; const ue = oe, G = Re(Pe), w = `${l}-label`, v = `${l}-feedback`, N = `${l}-hint`, _e = d ? ` ${N}` : ""; let ce; e[26] !== o || e[27] !== a || e[28] !== v ? (ce = [o && a && v].filter(Boolean).join(" ") || void 0, e[26] = o, e[27] = a, e[28] = v, e[29] = ce) : ce = e[29]; const Se = ce; let k, E, I, P, q, C, $, L, V, A, x, B, F, H, R, j, m, p, u; if (e[30] !== Se || e[31] !== _e || e[32] !== i || e[33] !== n || e[34] !== h || e[35] !== ue || e[36] !== G || e[37] !== d || e[38] !== N || e[39] !== l || e[40] !== o || e[41] !== Y || e[42] !== f || e[43] !== b || e[44] !== S || e[45] !== g || e[46] !== y || e[47] !== D || e[48] !== w || e[49] !== pe || e[50] !== le || e[51] !== a || e[52] !== v) { const ee = (he) => [g && /* @__PURE__ */ _("option", { value: "", children: g }, `${l}-hidden-option-disabled-placeholder`), ...he.map((O) => { if ("options" in O) { const { label: Ee, options: Ae } = O; return /* @__PURE__ */ _("optgroup", { label: Ee, children: Ae.map(ke) }, Ee); } else return ke(O); })], ke = il; let de; e[72] !== i ? (de = ve(t.root, i), e[72] = i, e[73] = de) : de = e[73]; const $e = de, ge = le === "small"; let re; e[74] !== o || e[75] !== Y || e[76] !== ge ? (re = ve(t.select, { [t.selectSmall]: ge, [t.selectInvalid]: o, [t.selectPlaceholder]: Y }), e[74] = o, e[75] = Y, e[76] = ge, e[77] = re) : re = e[77]; const Le = re; let ne; e[78] !== h || e[79] !== G ? (ne = ve(t.label, { [t.labelHidden]: G, [t.labelDisabled]: h }), e[78] = h, e[79] = G, e[80] = ne) : ne = e[80]; const De = ne, ye = le === "small"; let fe; e[81] !== h || e[82] !== ye ? (fe = ve(t.chevron, { [t.chevronSmall]: ye, [t.chevronDisabled]: h }), e[81] = h, e[82] = ye, e[83] = fe) : fe = e[83], k = fe; let be; e[84] !== b ? (be = (he) => { const { value: O } = he.target; Ce(O === ""), Ne(O), b && b(he); }, e[84] = b, e[85] = be) : be = e[85]; const Ve = be; j = $e; let T; e[86] !== y ? (T = y && /* @__PURE__ */ _(je, {}), e[86] = y, e[87] = T) : T = e[87], e[88] !== l || e[89] !== f || e[90] !== De || e[91] !== w || e[92] !== T ? (m = /* @__PURE__ */ we("label", { className: De, id: w, htmlFor: l, children: [ f, T ] }), e[88] = l, e[89] = f, e[90] = De, e[91] = w, e[92] = T, e[93] = m) : m = e[93], e[94] !== d || e[95] !== N ? (p = d && /* @__PURE__ */ _("div", { className: t.hint, id: N, children: d }), e[94] = d, e[95] = N, e[96] = p) : p = e[96], e[97] !== o || e[98] !== a || e[99] !== v ? (u = o && a && /* @__PURE__ */ _(ze, { className: t.feedback, message: a, variant: "error", id: v }), e[97] = o, e[98] = a, e[99] = v, e[100] = u) : u = e[100], R = t.selectWrapper, E = D, I = l, P = ue, q = Le, C = `${w}${_e}`, $ = Se, L = o, V = n, A = pe, x = h, B = y, F = Ve, H = ee(S), e[30] = Se, e[31] = _e, e[32] = i, e[33] = n, e[34] = h, e[35] = ue, e[36] = G, e[37] = d, e[38] = N, e[39] = l, e[40] = o, e[41] = Y, e[42] = f, e[43] = b, e[44] = S, e[45] = g, e[46] = y, e[47] = D, e[48] = w, e[49] = pe, e[50] = le, e[51] = a, e[52] = v, e[53] = k, e[54] = E, e[55] = I, e[56] = P, e[57] = q, 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] = p, e[71] = u; } else k = e[53], E = e[54], I = e[55], P = e[56], q = 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], p = e[70], u = e[71]; let W; e[101] !== E || e[102] !== I || e[103] !== P || e[104] !== q || 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__ */ _("select", { ...E, id: I, ref: P, className: q, "aria-labelledby": C, "aria-describedby": $, "aria-invalid": L, defaultValue: V, value: A, disabled: x, required: B, onChange: F, children: H }), e[101] = E, e[102] = I, e[103] = P, e[104] = q, 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] !== k ? (z = /* @__PURE__ */ _(We, { name: "chevron-down", className: k, "aria-hidden": "true" }), e[115] = k, e[116] = z) : z = e[116]; let M; e[117] !== R || e[118] !== W || e[119] !== z ? (M = /* @__PURE__ */ we("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] !== p || e[124] !== u || e[125] !== M ? (ie = /* @__PURE__ */ we("div", { className: j, children: [ m, p, u, M ] }), e[121] = j, e[122] = m, e[123] = p, e[124] = u, e[125] = M, e[126] = ie) : ie = e[126], ie; }); cl.displayName = "DSSelect"; function il(r) { const { label: s, value: e, isDisabled: i } = r; return /* @__PURE__ */ _("option", { value: e, disabled: i, children: s }, e); } export { cl as D, ul as S, ol as g, al as v };