UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

378 lines (377 loc) 16.4 kB
"use client"; import { jsx as y, jsxs as Ae, Fragment as xe } from "react/jsx-runtime"; import { d as T } from "./index.CgTHIF3K.js"; import { c as x } from "./index.CEyLAtio.js"; import { useState as V, useEffect as ne, useContext as oe, createContext as De, useRef as U } from "react"; import { g as j, c as R, p as fe } from "./helpers.BbWkXTr3.js"; import { u as He } from "./useIsomorphicLayoutEffect.CnJ9AMFS.js"; import { DSLogo as Pe } from "../logo.C96KaG1P.js"; import { Logo100Years as Te } from "../logo100years.BcB6_c-o.js"; import '../assets/Header.CNqtWTxB.css';const Ee = (l) => { const e = T.c(3), t = 0, [n, r] = V("down"); let a, s; return e[0] !== t ? (a = () => { let c; c = window.scrollY; const d = () => { const o = window.scrollY, h = o > c ? "down" : "up"; Math.abs(o - c) > t && (r(h), c = o); }; return window.addEventListener("scroll", d, { passive: !0 }), () => window.removeEventListener("scroll", d); }, s = [t], e[0] = t, e[1] = a, e[2] = s) : (a = e[1], s = e[2]), ne(a, s), n; }, ut = ["full", "main"], Fe = ({ hasBrandArea: l, hasPrimaryArea: e, hasSecondaryArea: t }) => { if (l) 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.")); }, Ce = "ds-top-bar_root_q6oxc_1", Oe = "ds-top-bar_root--sticky_q6oxc_49", Ve = "ds-top-bar_root--fixed_q6oxc_53", Re = "ds-top-bar_content_q6oxc_62", Me = "ds-top-bar_content--variant-full_q6oxc_81", qe = "ds-top-bar_content--has-primary-area-and-secondary-area_q6oxc_85", ke = "ds-top-bar_primary_q6oxc_90", $e = "ds-top-bar_content--has-brand-add-on-with-primary-area-and-secondary-area_q6oxc_105", We = "ds-top-bar_brand_q6oxc_110", Ie = "ds-top-bar_content--has-primary-area_q6oxc_85", Le = "ds-top-bar_content--has-primary-area--with-brand-add-on_q6oxc_149", Ye = "ds-top-bar_brand-add-on_q6oxc_213", ze = "ds-top-bar_brand-add-on--double_q6oxc_234", Ue = "ds-top-bar_sub-title_q6oxc_248", je = "ds-top-bar_secondary_q6oxc_274", Ge = "ds-top-bar_logo_q6oxc_283", Je = "ds-top-bar_logo--reduced_q6oxc_293", _ = { root: Ce, rootSticky: Oe, rootFixed: Ve, content: Re, contentVariantFull: Me, contentHasPrimaryAreaAndSecondaryArea: qe, primary: ke, contentHasBrandAddOnWithPrimaryAreaAndSecondaryArea: $e, brand: We, contentHasPrimaryArea: Ie, contentHasPrimaryAreaWithBrandAddOn: Le, brandAddOn: Ye, brandAddOnDouble: ze, subTitle: Ue, secondary: je, logo: Ge, logoReduced: Je }, Ke = ({ hasBrandArea: l, hasPrimaryArea: e, hasSecondaryArea: t }) => { if (!l) 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>.")); }, ve = (l) => l == null || typeof l == "object" && !Array.isArray(l) && l !== null && Object.keys(l).length === 0, _t = ["100years"], L = (l) => { const e = T.c(28); let t, n, r, a; e[0] !== l ? ({ children: t, className: n, rootClassName: a, ...r } = l, e[0] = l, e[1] = t, e[2] = n, e[3] = r, e[4] = a) : (t = e[1], n = e[2], r = e[3], a = e[4]); const { variant: s, isHeaderSticky: c, isMobile: d, topBarAreaRef: o, isStickyMainNavigationVisible: h, hasBrandAddOn: m } = oe(G); let A, p; if (e[5] !== t || e[6] !== n || e[7] !== m || e[8] !== c || e[9] !== d || e[10] !== h || e[11] !== a || e[12] !== s) { const E = R(t, pe), u = R(t, ue), i = R(t, _e); process.env.NODE_ENV !== "production" && Ke({ hasBrandArea: E, hasPrimaryArea: u, hasSecondaryArea: i }); let b; e[15] !== c || e[16] !== d || e[17] !== h || e[18] !== a ? (b = x(_.root, a, c ? { [_.rootSticky]: !d && h, [_.rootFixed]: !d && !h } : {}), e[15] = c, e[16] = d, e[17] = h, e[18] = a, e[19] = b) : b = e[19], A = b, p = x(_.content, n, { [_.contentHasPrimaryArea]: u && !m && !i, [_.contentHasPrimaryAreaWithBrandAddOn]: u && m && !i, [_.contentHasBrandAddOnWithPrimaryAreaAndSecondaryArea]: m && u && i, [_.contentHasPrimaryAreaAndSecondaryArea]: u && i && !m, [_.contentVariantFull]: s === "full" }), e[5] = t, e[6] = n, e[7] = m, e[8] = c, e[9] = d, e[10] = h, e[11] = a, e[12] = s, e[13] = A, e[14] = p; } else A = e[13], p = e[14]; const g = p; let f; e[20] !== t || e[21] !== g || e[22] !== r ? (f = /* @__PURE__ */ y("section", { className: g, ...r, children: t }), e[20] = t, e[21] = g, e[22] = r, e[23] = f) : f = e[23]; let v; return e[24] !== A || e[25] !== f || e[26] !== o ? (v = /* @__PURE__ */ y("div", { className: A, ref: o, children: f }), e[24] = A, e[25] = f, e[26] = o, e[27] = v) : v = e[27], v; }, pe = (l) => { const e = T.c(26), { children: t, className: n } = l, { logoProps: r, brandAddOnProps: a, setHasBrandAddOn: s } = oe(G); let c; e[0] !== r ? (c = r || {}, e[0] = r, e[1] = c) : c = e[1]; const { aria: d, logo: o, href: h, target: m } = c, A = o === void 0 ? "main" : o, p = h === void 0 ? "/" : h, g = m === void 0 ? "_self" : m; let f; e[2] !== a || e[3] !== t || e[4] !== s ? (f = () => { t || !ve(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 = x(_.logo, { [_.logoReduced]: A.includes("reduced") }), e[9] = A, e[10] = E) : E = e[10]; const u = E; let i; e[11] !== n ? (i = x(_.brand, n), e[11] = n, e[12] = i) : i = e[12]; let b; e[13] !== d || e[14] !== p || e[15] !== A || e[16] !== u || e[17] !== g ? (b = /* @__PURE__ */ y(Pe, { className: u, aria: d, logo: A, href: p, target: g }), e[13] = d, e[14] = p, e[15] = A, e[16] = u, e[17] = g, e[18] = b) : b = e[18]; let S; e[19] !== a ? (S = ve(a) ? void 0 : /* @__PURE__ */ y(ge, { ...a }), e[19] = a, e[20] = S) : S = e[20]; let D; return e[21] !== t || e[22] !== S || e[23] !== i || e[24] !== b ? (D = /* @__PURE__ */ Ae("div", { className: i, children: [ b, S, t ] }), e[21] = t, e[22] = S, e[23] = i, e[24] = b, e[25] = D) : D = e[25], D; }; pe.displayName = "DSTopBar.BrandArea"; const ge = (l) => { const e = T.c(15), { children: t, className: n, subTitle: r, variant: a } = l; let s; e[0] !== n || e[1] !== r ? (s = x(_.brandAddOn, n, { [_.brandAddOnDouble]: r }), e[0] = n, e[1] = r, e[2] = s) : s = e[2]; const c = s; if (r) { let o; e[3] !== t ? (o = /* @__PURE__ */ y("span", { children: t }), e[3] = t, e[4] = o) : o = e[4]; let h; e[5] !== r ? (h = r && /* @__PURE__ */ y("span", { className: _.subTitle, children: r }), e[5] = r, e[6] = h) : h = e[6]; let m; return e[7] !== c || e[8] !== o || e[9] !== h ? (m = /* @__PURE__ */ Ae("div", { className: c, children: [ o, h ] }), e[7] = c, e[8] = o, e[9] = h, e[10] = m) : m = e[10], m; } if (a === "100years") { let o; return e[11] === Symbol.for("react.memo_cache_sentinel") ? (o = /* @__PURE__ */ y(Te, {}), e[11] = o) : o = e[11], o; } let d; return e[12] !== c || e[13] !== t ? (d = /* @__PURE__ */ y("div", { className: c, children: t }), e[12] = c, e[13] = t, e[14] = d) : d = e[14], d; }; ge.displayName = "DSTopBar.BrandAddOn"; const ue = (l) => { const e = T.c(5), { children: t, className: n } = l; let r; e[0] !== n ? (r = x(_.primary, n), e[0] = n, e[1] = r) : r = e[1]; let a; return e[2] !== t || e[3] !== r ? (a = /* @__PURE__ */ y("div", { className: r, children: t }), e[2] = t, e[3] = r, e[4] = a) : a = e[4], a; }; ue.displayName = "DSTopBar.PrimaryArea"; const _e = (l) => { const e = T.c(5), { children: t, className: n } = l; let r; e[0] !== n ? (r = x(_.secondary, n), e[0] = n, e[1] = r) : r = e[1]; let a; return e[2] !== t || e[3] !== r ? (a = /* @__PURE__ */ y("div", { className: r, children: t }), e[2] = t, e[3] = r, e[4] = a) : a = e[4], a; }; _e.displayName = "DSTopBar.SecondaryArea"; L.BrandArea = pe; L.PrimaryArea = ue; L.SecondaryArea = _e; const Qe = "ds-header_root_c5fh4_1", Xe = "ds-header_root--sticky_c5fh4_4", Ze = "ds-header_root--hidden_c5fh4_9", et = "ds-header_root--fixed_c5fh4_20", tt = "ds-header_main-navigation-area_c5fh4_37", at = "ds-header_main-navigation-area--fixed_c5fh4_90", rt = "ds-header_main-navigation-area--fixed--visible_c5fh4_105", nt = "ds-header_main-navigation-content_c5fh4_111", ot = "ds-header_main-navigation-content--variant-full_c5fh4_115", it = "ds-header_header-placeholder_c5fh4_120", st = "ds-header_header-placeholder--with-banner_c5fh4_123", N = { root: Qe, rootSticky: Xe, rootHidden: Ze, rootFixed: et, mainNavigationArea: tt, mainNavigationAreaFixed: at, mainNavigationAreaFixedVisible: rt, mainNavigationContent: nt, mainNavigationContentVariantFull: ot, headerPlaceholder: it, headerPlaceholderWithBanner: st }, G = De({ variant: "main" }), ie = (l) => { const e = T.c(57); let t, n, r, a, s, c, d; e[0] !== l ? ({ children: n, brandAddOnProps: t, className: r, isHeaderSticky: c, variant: d, logoProps: a, ...s } = l, e[0] = l, e[1] = t, e[2] = n, e[3] = r, e[4] = a, e[5] = s, e[6] = c, e[7] = d) : (t = e[1], n = e[2], r = e[3], a = e[4], s = e[5], c = e[6], d = e[7]); const o = c === void 0 ? !1 : c, h = d === void 0 ? "main" : d, [m, A] = V(!1); let p; e[8] !== n ? (p = R(n, ie.BannerArea, !0), e[8] = n, e[9] = p) : p = e[9]; const g = p, f = R(n, L.BrandArea), v = R(n, L.PrimaryArea), E = R(n, L.SecondaryArea); process.env.NODE_ENV !== "production" && Fe({ hasBrandArea: f, hasPrimaryArea: v, hasSecondaryArea: E }); const u = Ee(), [i, b] = V(!1), S = U(null), D = U(null), se = U(null), ce = U(null), [le, Ne] = V(!1), [M, Be] = V(!1), [w, ye] = V(!0), [de, we] = V(!1), he = U(i); let J, K; e[10] !== o ? (J = () => { if (o) { const B = () => { b((H) => (he.current = H, window.innerWidth < 1024)); }; return B(), window.addEventListener("resize", B), () => window.removeEventListener("resize", B); } }, 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] === Symbol.for("react.memo_cache_sentinel") ? (Q = () => { const B = () => { var F, O, re; const H = document.documentElement, Y = ((F = S.current) == null ? void 0 : F.offsetHeight) || 0, P = ((O = se.current) == null ? void 0 : O.offsetHeight) || 0; let C; if (!ce.current) C = Y + P; else { const z = (re = D.current) == null ? void 0 : re.offsetHeight; !z || z === Y ? C = parseInt(H.style.getPropertyValue("--ds-header-height").replace("rem", "")) * 16 || 0 : C = z; } H.style.setProperty("--ds-banner-height", `${fe(Y)}rem`), H.style.setProperty("--ds-header-height", `${fe(C)}rem`), H.style.setProperty("--ds-top-bar-height", `${fe(P)}rem`); }; return B(), window.addEventListener("resize", B), () => window.removeEventListener("resize", B); }, X = [], e[13] = Q, e[14] = X) : (Q = e[13], X = e[14]), He(Q, X); let Z; e[15] !== o || e[16] !== i || e[17] !== w || e[18] !== u ? (Z = () => { if (o) { const B = () => { const P = D.current, C = !!P && window.scrollY <= P.offsetHeight; Ne(C); const F = ce.current, O = se.current; if (!i && he.current && !w) { ye(C && !!P && window.scrollY <= P.offsetHeight); return; } const re = !!O && !!F && F.getBoundingClientRect().bottom > O.getBoundingClientRect().bottom, z = !F && !!O && !!S.current && (window.scrollY >= S.current.offsetHeight || 0) || !F && !S.current && !!O && window.scrollY >= 1; ye(F ? re && !!P && window.scrollY <= P.offsetHeight : !z); }; window.addEventListener("scroll", B, { passive: !0 }), B(); const H = D.current, Y = !!H && H.getBoundingClientRect().bottom > 0; return i && Be(u === "up" && !Y), i || we(u === "up" && !w), () => { window.removeEventListener("scroll", B); }; } }, e[15] = o, e[16] = i, e[17] = w, e[18] = u, e[19] = Z) : Z = e[19]; let ee; e[20] !== o || e[21] !== i || e[22] !== u ? (ee = [o, i, he, u], e[20] = o, e[21] = i, e[22] = u, e[23] = ee) : ee = e[23], ne(Z, ee); let te; e[24] !== r || e[25] !== M || e[26] !== o || e[27] !== le || e[28] !== i ? (te = x(N.root, r, o ? { [N.rootSticky]: i, [N.rootHidden]: i && !le, [N.rootFixed]: i && M } : {}), e[24] = r, e[25] = M, e[26] = o, e[27] = le, e[28] = i, e[29] = te) : te = e[29]; const me = te; let q; e[30] !== t || e[31] !== m || e[32] !== de || e[33] !== o || e[34] !== i || e[35] !== w || e[36] !== a || e[37] !== h ? (q = { variant: h, bannerAreaRef: S, brandAddOnProps: t, hasBrandAddOn: m, setHasBrandAddOn: A, isFixedMainNavigation: de, isHeaderSticky: o, isMobile: i, isStickyMainNavigationVisible: w, mainNavigationAreaRef: ce, topBarAreaRef: se, logoProps: a }, e[30] = t, e[31] = m, e[32] = de, e[33] = o, e[34] = i, e[35] = w, e[36] = a, e[37] = h, e[38] = q) : q = e[38]; let k; e[39] !== n || e[40] !== q ? (k = /* @__PURE__ */ y(G.Provider, { value: q, children: n }), e[39] = n, e[40] = q, e[41] = k) : k = e[41]; let $; e[42] !== s || e[43] !== me || e[44] !== k ? ($ = /* @__PURE__ */ y("header", { className: me, ...s, ref: D, children: k }), e[42] = s, e[43] = me, e[44] = k, e[45] = $) : $ = e[45]; let W; e[46] !== M || e[47] !== i ? (W = i && M && /* @__PURE__ */ y("div", { className: N.headerPlaceholder }), e[46] = M, e[47] = i, e[48] = W) : W = e[48]; let I; e[49] !== g || e[50] !== i || e[51] !== w ? (I = !i && !w && /* @__PURE__ */ y("div", { className: g ? N.headerPlaceholderWithBanner : N.headerPlaceholder }), e[49] = g, e[50] = i, e[51] = w, e[52] = I) : I = e[52]; let ae; return e[53] !== $ || e[54] !== W || e[55] !== I ? (ae = /* @__PURE__ */ Ae(xe, { children: [ $, W, I ] }), e[53] = $, e[54] = W, e[55] = I, e[56] = ae) : ae = e[56], ae; }, be = (l) => { const e = T.c(4), { children: t, className: n } = l, { bannerAreaRef: r } = oe(G); let a; return e[0] !== r || e[1] !== t || e[2] !== n ? (a = /* @__PURE__ */ y("div", { ref: r, className: n, children: t }), e[0] = r, e[1] = t, e[2] = n, e[3] = a) : a = e[3], a; }; be.displayName = "DSHeader.BannerArea"; const Se = (l) => { const e = T.c(15), { children: t, className: n } = l, { variant: r, isFixedMainNavigation: a, isHeaderSticky: s, isMobile: c, isStickyMainNavigationVisible: d, mainNavigationAreaRef: o } = oe(G); let h; e[0] !== n || e[1] !== a || e[2] !== s || e[3] !== c || e[4] !== d ? (h = x(N.mainNavigationArea, n, s ? { [N.mainNavigationAreaFixed]: !c && !d, [N.mainNavigationAreaFixedVisible]: !c && a } : {}), e[0] = n, e[1] = a, e[2] = s, e[3] = c, e[4] = d, e[5] = h) : h = e[5]; const m = h, A = r === "full"; let p; e[6] !== A ? (p = x(N.mainNavigationContent, { [N.mainNavigationContentVariantFull]: A }), e[6] = A, e[7] = p) : p = e[7]; const g = p; let f; e[8] !== t || e[9] !== g ? (f = /* @__PURE__ */ y("div", { className: g, children: t }), e[8] = t, e[9] = g, e[10] = f) : f = e[10]; let v; return e[11] !== o || e[12] !== m || e[13] !== f ? (v = /* @__PURE__ */ y("div", { className: m, ref: o, children: f }), e[11] = o, e[12] = m, e[13] = f, e[14] = v) : v = e[14], v; }; Se.displayName = "DSHeader.MainNavigationArea"; ie.BannerArea = be; ie.MainNavigationArea = Se; ie.displayName = "DSHeader"; export { _t as B, G as D, ut as H, ie as a, L as b, Ke as c, ve as i, Fe as v };