UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

369 lines (368 loc) 16.1 kB
"use client"; import { jsx as g, jsxs as Ae, Fragment as _e } from "react/jsx-runtime"; import { d as T } from "./index.CgTHIF3K.js"; import { c as D } from "./index.CEyLAtio.js"; import { useState as V, useEffect as ne, useContext as oe, createContext as He, useRef as U } from "react"; import { g as j, c as R, p as fe } from "./helpers.BbWkXTr3.js"; import { u as Pe } from "./useIsomorphicLayoutEffect.CnJ9AMFS.js"; import { DSLogo as xe } from "../logo.C96KaG1P.js"; import '../assets/Header.DO34x-dO.css';const Te = (d) => { const e = T.c(3), t = 0, [r, n] = V("down"); let a, s; return e[0] !== t ? (a = () => { let l; l = window.scrollY; const c = () => { const o = window.scrollY, h = o > l ? "down" : "up"; Math.abs(o - l) > t && (n(h), l = o); }; return window.addEventListener("scroll", c, { passive: !0 }), () => window.removeEventListener("scroll", c); }, s = [t], e[0] = t, e[1] = a, e[2] = s) : (a = e[1], s = e[2]), ne(a, s), r; }, At = ["full", "main"], Ee = ({ hasBrandArea: d, hasPrimaryArea: e, hasSecondaryArea: t }) => { if (d) throw new Error(j("DSHeader", "A <DSTopBar.BrandArea> component was detected as a direct child of DSHeader. Please move it into the DSTopBar component.")); if (e) throw new Error(j("DSHeader", "A <DSTopBar.PrimaryArea> component was detected as a direct child of DSHeader. Please move it into the DSTopBar component.")); if (t) throw new Error(j("DSHeader", "A <DSTopBar.SecondaryArea> component was detected as a direct child of DSHeader. Please move it into the DSTopBar component.")); }, Fe = "ds-top-bar_root_ryiho_1", Ce = "ds-top-bar_root--sticky_ryiho_47", Oe = "ds-top-bar_root--fixed_ryiho_51", Ve = "ds-top-bar_content_ryiho_59", Re = "ds-top-bar_content--variant-full_ryiho_78", Me = "ds-top-bar_content--has-primary-area-and-secondary-area_ryiho_82", ke = "ds-top-bar_primary_ryiho_87", $e = "ds-top-bar_content--has-brand-add-on-with-primary-area-and-secondary-area_ryiho_102", We = "ds-top-bar_brand_ryiho_107", Ie = "ds-top-bar_content--has-primary-area_ryiho_82", Le = "ds-top-bar_content--has-primary-area--with-brand-add-on_ryiho_146", Ye = "ds-top-bar_brand-add-on_ryiho_210", ze = "ds-top-bar_brand-add-on--double_ryiho_231", qe = "ds-top-bar_sub-title_ryiho_245", Ue = "ds-top-bar_secondary_ryiho_271", je = "ds-top-bar_logo_ryiho_280", Ge = "ds-top-bar_logo--reduced_ryiho_290", u = { root: Fe, rootSticky: Ce, rootFixed: Oe, content: Ve, contentVariantFull: Re, contentHasPrimaryAreaAndSecondaryArea: Me, primary: ke, contentHasBrandAddOnWithPrimaryAreaAndSecondaryArea: $e, brand: We, contentHasPrimaryArea: Ie, contentHasPrimaryAreaWithBrandAddOn: Le, brandAddOn: Ye, brandAddOnDouble: ze, subTitle: qe, secondary: Ue, logo: je, logoReduced: Ge }, Je = ({ hasBrandArea: d, hasPrimaryArea: e, hasSecondaryArea: t }) => { if (!d) throw new Error(j("DSTopBar", "A <DSTopBar.BrandArea> component is required. Please include it as a child of DSTopBar.")); if (!e && t) throw new Error(j("DSTopBar", "A <DSTopBar.PrimaryArea> is required when using <DSTopBar.SecondaryArea>. Please include <DSTopBar.PrimaryArea> as a child of DSTopBar, or move the content from <DSTopBar.SecondaryArea> into <DSTopBar.PrimaryArea>.")); }, ge = (d) => d == null || typeof d == "object" && !Array.isArray(d) && d !== null && Object.keys(d).length === 0, pt = ["double", "single"], Y = (d) => { const e = T.c(28); let t, r, n, a; e[0] !== d ? ({ children: t, className: r, rootClassName: a, ...n } = d, e[0] = d, e[1] = t, e[2] = r, e[3] = n, e[4] = a) : (t = e[1], r = e[2], n = e[3], a = e[4]); const { variant: s, isHeaderSticky: l, isMobile: c, topBarAreaRef: o, isStickyMainNavigationVisible: h, hasBrandAddOn: m } = oe(G); let A, p; if (e[5] !== t || e[6] !== r || e[7] !== m || e[8] !== l || e[9] !== c || e[10] !== h || e[11] !== a || e[12] !== s) { const E = R(t, pe), y = R(t, ye), i = R(t, ue); process.env.NODE_ENV !== "production" && Je({ hasBrandArea: E, hasPrimaryArea: y, hasSecondaryArea: i }); let b; e[15] !== l || e[16] !== c || e[17] !== h || e[18] !== a ? (b = D(u.root, a, l ? { [u.rootSticky]: !c && h, [u.rootFixed]: !c && !h } : {}), e[15] = l, e[16] = c, e[17] = h, e[18] = a, e[19] = b) : b = e[19], A = b, p = D(u.content, r, { [u.contentHasPrimaryArea]: y && !m && !i, [u.contentHasPrimaryAreaWithBrandAddOn]: y && m && !i, [u.contentHasBrandAddOnWithPrimaryAreaAndSecondaryArea]: m && y && i, [u.contentHasPrimaryAreaAndSecondaryArea]: y && i && !m, [u.contentVariantFull]: s === "full" }), e[5] = t, e[6] = r, e[7] = m, e[8] = l, e[9] = c, e[10] = h, e[11] = a, e[12] = s, e[13] = A, e[14] = p; } else A = e[13], p = e[14]; const _ = p; let f; e[20] !== t || e[21] !== _ || e[22] !== n ? (f = /* @__PURE__ */ g("section", { className: _, ...n, children: t }), e[20] = t, e[21] = _, e[22] = n, e[23] = f) : f = e[23]; let v; return e[24] !== A || e[25] !== f || e[26] !== o ? (v = /* @__PURE__ */ g("div", { className: A, ref: o, children: f }), e[24] = A, e[25] = f, e[26] = o, e[27] = v) : v = e[27], v; }, pe = (d) => { const e = T.c(26), { children: t, className: r } = d, { logoProps: n, brandAddOnProps: a, setHasBrandAddOn: s } = oe(G); let l; e[0] !== n ? (l = n || {}, e[0] = n, e[1] = l) : l = e[1]; const { aria: c, logo: o, href: h, target: m } = l, A = o === void 0 ? "main" : o, p = h === void 0 ? "/" : h, _ = m === void 0 ? "_self" : m; let f; e[2] !== a || e[3] !== t || e[4] !== s ? (f = () => { t || !ge(a) ? s == null || s(!0) : s == null || s(!1); }, e[2] = a, e[3] = t, e[4] = s, e[5] = f) : f = e[5]; let v; e[6] !== a || e[7] !== t ? (v = [t, a], e[6] = a, e[7] = t, e[8] = v) : v = e[8], ne(f, v); let E; e[9] !== A ? (E = D(u.logo, { [u.logoReduced]: A.includes("reduced") }), e[9] = A, e[10] = E) : E = e[10]; const y = E; let i; e[11] !== r ? (i = D(u.brand, r), e[11] = r, e[12] = i) : i = e[12]; let b; e[13] !== c || e[14] !== p || e[15] !== A || e[16] !== y || e[17] !== _ ? (b = /* @__PURE__ */ g(xe, { className: y, aria: c, logo: A, href: p, target: _ }), e[13] = c, e[14] = p, e[15] = A, e[16] = y, e[17] = _, e[18] = b) : b = e[18]; let S; e[19] !== a ? (S = ge(a) ? void 0 : /* @__PURE__ */ g(be, { ...a }), e[19] = a, e[20] = S) : S = e[20]; let H; return e[21] !== t || e[22] !== S || e[23] !== i || e[24] !== b ? (H = /* @__PURE__ */ Ae("div", { className: i, children: [ b, S, t ] }), e[21] = t, e[22] = S, e[23] = i, e[24] = b, e[25] = H) : H = e[25], H; }; pe.displayName = "DSTopBar.BrandArea"; const be = (d) => { const e = T.c(10), { children: t, className: r, subTitle: n, variant: a } = d, s = a === void 0 ? "single" : a, l = s === "double"; let c; e[0] !== r || e[1] !== l ? (c = D(u.brandAddOn, r, { [u.brandAddOnDouble]: l }), e[0] = r, e[1] = l, e[2] = c) : c = e[2]; const o = c; let h; e[3] !== t || e[4] !== n || e[5] !== s ? (h = s === "single" ? t : /* @__PURE__ */ Ae(_e, { children: [ /* @__PURE__ */ g("span", { children: t }), n && /* @__PURE__ */ g("span", { className: u.subTitle, children: n }) ] }), e[3] = t, e[4] = n, e[5] = s, e[6] = h) : h = e[6]; let m; return e[7] !== o || e[8] !== h ? (m = /* @__PURE__ */ g("span", { className: o, children: h }), e[7] = o, e[8] = h, e[9] = m) : m = e[9], m; }; be.displayName = "DSTopBar.BrandAddOn"; const ye = (d) => { const e = T.c(5), { children: t, className: r } = d; let n; e[0] !== r ? (n = D(u.primary, r), e[0] = r, e[1] = n) : n = e[1]; let a; return e[2] !== t || e[3] !== n ? (a = /* @__PURE__ */ g("div", { className: n, children: t }), e[2] = t, e[3] = n, e[4] = a) : a = e[4], a; }; ye.displayName = "DSTopBar.PrimaryArea"; const ue = (d) => { const e = T.c(5), { children: t, className: r } = d; let n; e[0] !== r ? (n = D(u.secondary, r), e[0] = r, e[1] = n) : n = e[1]; let a; return e[2] !== t || e[3] !== n ? (a = /* @__PURE__ */ g("div", { className: n, children: t }), e[2] = t, e[3] = n, e[4] = a) : a = e[4], a; }; ue.displayName = "DSTopBar.SecondaryArea"; Y.BrandArea = pe; Y.PrimaryArea = ye; Y.SecondaryArea = ue; const Ke = "ds-header_root_g2mvw_1", Qe = "ds-header_root--sticky_g2mvw_4", Xe = "ds-header_root--hidden_g2mvw_9", Ze = "ds-header_root--fixed_g2mvw_20", et = "ds-header_main-navigation-area_g2mvw_36", tt = "ds-header_main-navigation-area--fixed_g2mvw_88", at = "ds-header_main-navigation-area--fixed--visible_g2mvw_103", rt = "ds-header_main-navigation-content_g2mvw_108", nt = "ds-header_main-navigation-content--variant-full_g2mvw_112", ot = "ds-header_header-placeholder_g2mvw_117", it = "ds-header_header-placeholder--with-banner_g2mvw_120", N = { root: Ke, rootSticky: Qe, rootHidden: Xe, rootFixed: Ze, mainNavigationArea: et, mainNavigationAreaFixed: tt, mainNavigationAreaFixedVisible: at, mainNavigationContent: rt, mainNavigationContentVariantFull: nt, headerPlaceholder: ot, headerPlaceholderWithBanner: it }, G = He({ variant: "main" }), ie = (d) => { const e = T.c(58); let t, r, n, a, s, l, c; e[0] !== d ? ({ children: r, brandAddOnProps: t, className: n, isHeaderSticky: l, variant: c, logoProps: a, ...s } = d, e[0] = d, e[1] = t, e[2] = r, e[3] = n, e[4] = a, e[5] = s, e[6] = l, e[7] = c) : (t = e[1], r = e[2], n = e[3], a = e[4], s = e[5], l = e[6], c = e[7]); const o = l === void 0 ? !1 : l, h = c === void 0 ? "main" : c, [m, A] = V(!1); let p; e[8] !== r ? (p = R(r, ie.BannerArea, !0), e[8] = r, e[9] = p) : p = e[9]; const _ = p, f = R(r, Y.BrandArea), v = R(r, Y.PrimaryArea), E = R(r, Y.SecondaryArea); process.env.NODE_ENV !== "production" && Ee({ hasBrandArea: f, hasPrimaryArea: v, hasSecondaryArea: E }); const y = Te(), [i, b] = V(!1), S = U(null), H = U(null), se = U(null), de = U(null), [le, we] = V(!1), [M, Be] = V(!1), [B, ve] = V(!0), [ce, De] = V(!1), he = U(i); let J, K; e[10] !== o ? (J = () => { if (o) { const w = () => { b((P) => (he.current = P, window.innerWidth < 1024)); }; return w(), window.addEventListener("resize", w), () => window.removeEventListener("resize", w); } }, K = [o], e[10] = o, e[11] = J, e[12] = K) : (J = e[11], K = e[12]), ne(J, K); let Q, X; e[13] !== o ? (Q = () => { if (o) { const w = () => { var F, O, re; const P = document.documentElement, z = ((F = S.current) == null ? void 0 : F.offsetHeight) || 0, x = ((O = se.current) == null ? void 0 : O.offsetHeight) || 0; let C; if (!de.current) C = z + x; else { const q = (re = H.current) == null ? void 0 : re.offsetHeight; !q || q === z ? C = parseInt(P.style.getPropertyValue("--ds-header-height").replace("rem", "")) * 16 || 0 : C = q; } P.style.setProperty("--ds-banner-height", `${fe(z)}rem`), P.style.setProperty("--ds-header-height", `${fe(C)}rem`), P.style.setProperty("--ds-top-bar-height", `${fe(x)}rem`); }; return w(), window.addEventListener("resize", w), () => window.removeEventListener("resize", w); } }, X = [o], e[13] = o, e[14] = Q, e[15] = X) : (Q = e[14], X = e[15]), Pe(Q, X); let Z; e[16] !== o || e[17] !== i || e[18] !== B || e[19] !== y ? (Z = () => { if (o) { const w = () => { const x = H.current, C = !!x && window.scrollY <= x.offsetHeight; we(C); const F = de.current, O = se.current; if (!i && he.current && !B) { ve(C && !!x && window.scrollY <= x.offsetHeight); return; } const re = !!O && !!F && F.getBoundingClientRect().bottom > O.getBoundingClientRect().bottom, q = !F && !!O && !!S.current && (window.scrollY >= S.current.offsetHeight || 0) || !F && !S.current && !!O && window.scrollY >= 1; ve(F ? re && !!x && window.scrollY <= x.offsetHeight : !q); }; window.addEventListener("scroll", w, { passive: !0 }), w(); const P = H.current, z = !!P && P.getBoundingClientRect().bottom > 0; return i && Be(y === "up" && !z), i || De(y === "up" && !B), () => { window.removeEventListener("scroll", w); }; } }, e[16] = o, e[17] = i, e[18] = B, e[19] = y, e[20] = Z) : Z = e[20]; let ee; e[21] !== o || e[22] !== i || e[23] !== y ? (ee = [o, i, he, y], e[21] = o, e[22] = i, e[23] = y, e[24] = ee) : ee = e[24], ne(Z, ee); let te; e[25] !== n || e[26] !== M || e[27] !== o || e[28] !== le || e[29] !== i ? (te = D(N.root, n, o ? { [N.rootSticky]: i, [N.rootHidden]: i && !le, [N.rootFixed]: i && M } : {}), e[25] = n, e[26] = M, e[27] = o, e[28] = le, e[29] = i, e[30] = te) : te = e[30]; const me = te; let k; e[31] !== t || e[32] !== m || e[33] !== ce || e[34] !== o || e[35] !== i || e[36] !== B || e[37] !== a || e[38] !== h ? (k = { variant: h, bannerAreaRef: S, brandAddOnProps: t, hasBrandAddOn: m, setHasBrandAddOn: A, isFixedMainNavigation: ce, isHeaderSticky: o, isMobile: i, isStickyMainNavigationVisible: B, mainNavigationAreaRef: de, topBarAreaRef: se, logoProps: a }, e[31] = t, e[32] = m, e[33] = ce, e[34] = o, e[35] = i, e[36] = B, e[37] = a, e[38] = h, e[39] = k) : k = e[39]; let $; e[40] !== r || e[41] !== k ? ($ = /* @__PURE__ */ g(G.Provider, { value: k, children: r }), e[40] = r, e[41] = k, e[42] = $) : $ = e[42]; let W; e[43] !== s || e[44] !== me || e[45] !== $ ? (W = /* @__PURE__ */ g("header", { className: me, ...s, ref: H, children: $ }), e[43] = s, e[44] = me, e[45] = $, e[46] = W) : W = e[46]; let I; e[47] !== M || e[48] !== i ? (I = i && M && /* @__PURE__ */ g("div", { className: N.headerPlaceholder }), e[47] = M, e[48] = i, e[49] = I) : I = e[49]; let L; e[50] !== _ || e[51] !== i || e[52] !== B ? (L = !i && !B && /* @__PURE__ */ g("div", { className: _ ? N.headerPlaceholderWithBanner : N.headerPlaceholder }), e[50] = _, e[51] = i, e[52] = B, e[53] = L) : L = e[53]; let ae; return e[54] !== W || e[55] !== I || e[56] !== L ? (ae = /* @__PURE__ */ Ae(_e, { children: [ W, I, L ] }), e[54] = W, e[55] = I, e[56] = L, e[57] = ae) : ae = e[57], ae; }, Se = (d) => { const e = T.c(4), { children: t, className: r } = d, { bannerAreaRef: n } = oe(G); let a; return e[0] !== n || e[1] !== t || e[2] !== r ? (a = /* @__PURE__ */ g("div", { ref: n, className: r, children: t }), e[0] = n, e[1] = t, e[2] = r, e[3] = a) : a = e[3], a; }; Se.displayName = "DSHeader.BannerArea"; const Ne = (d) => { const e = T.c(15), { children: t, className: r } = d, { variant: n, isFixedMainNavigation: a, isHeaderSticky: s, isMobile: l, isStickyMainNavigationVisible: c, mainNavigationAreaRef: o } = oe(G); let h; e[0] !== r || e[1] !== a || e[2] !== s || e[3] !== l || e[4] !== c ? (h = D(N.mainNavigationArea, r, s ? { [N.mainNavigationAreaFixed]: !l && !c, [N.mainNavigationAreaFixedVisible]: !l && a } : {}), e[0] = r, e[1] = a, e[2] = s, e[3] = l, e[4] = c, e[5] = h) : h = e[5]; const m = h, A = n === "full"; let p; e[6] !== A ? (p = D(N.mainNavigationContent, { [N.mainNavigationContentVariantFull]: A }), e[6] = A, e[7] = p) : p = e[7]; const _ = p; let f; e[8] !== t || e[9] !== _ ? (f = /* @__PURE__ */ g("div", { className: _, children: t }), e[8] = t, e[9] = _, e[10] = f) : f = e[10]; let v; return e[11] !== o || e[12] !== m || e[13] !== f ? (v = /* @__PURE__ */ g("div", { className: m, ref: o, children: f }), e[11] = o, e[12] = m, e[13] = f, e[14] = v) : v = e[14], v; }; Ne.displayName = "DSHeader.MainNavigationArea"; ie.BannerArea = Se; ie.MainNavigationArea = Ne; ie.displayName = "DSHeader"; export { pt as B, G as D, At as H, ie as a, Y as b, Je as c, ge as i, Ee as v };