@stihl-design-system/components
Version:
Welcome to the STIHL Design System react component library.
371 lines (370 loc) • 16.2 kB
JavaScript
"use client";
import { jsx as _, jsxs as me, Fragment as He } from "react/jsx-runtime";
import { d as T } from "./index.D-sRdssb.js";
import { c as H } from "./index.DL9mof6u.js";
import { useState as O, useEffect as ae, useContext as re, createContext as xe, useRef as L } from "react";
import { g as Y, c as F, p as he } from "./helpers.CexwVao7.js";
import { u as De } from "./useIsomorphicLayoutEffect.CnJ9AMFS.js";
import { DSLogo as Pe } from "../logo.DprmD8HU.js";
import { Logo100Years as Te } from "../logo100years.DDzCrczW.js";
import '../assets/Header.CNqtWTxB.css';const Ee = (s) => {
const e = T.c(3), t = 0, [n, r] = O("down");
let a, d;
return e[0] !== t ? (a = () => {
let c = window.scrollY;
const l = () => {
const o = window.scrollY, h = o > c ? "down" : "up";
Math.abs(o - c) > t && (r(h), c = o);
};
return window.addEventListener("scroll", l, {
passive: !0
}), () => window.removeEventListener("scroll", l);
}, d = [t], e[0] = t, e[1] = a, e[2] = d) : (a = e[1], d = e[2]), ae(a, d), n;
}, ut = ["full", "main"], Oe = ({
hasBrandArea: s,
hasPrimaryArea: e,
hasSecondaryArea: t
}) => {
if (s)
throw new Error(Y("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(Y("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(Y("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_q6oxc_1", Ce = "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", u = {
root: Fe,
rootSticky: Ce,
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: s,
hasPrimaryArea: e,
hasSecondaryArea: t
}) => {
if (!s)
throw new Error(Y("DSTopBar", "A <DSTopBar.BrandArea> component is required. Please include it as a child of DSTopBar."));
if (!e && t)
throw new Error(Y("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>."));
}, _e = (s) => s == null || typeof s == "object" && !Array.isArray(s) && s !== null && Object.keys(s).length === 0, _t = ["100years"], $ = (s) => {
const e = T.c(28);
let t, n, r, a;
e[0] !== s ? ({
children: t,
className: n,
rootClassName: a,
...r
} = s, e[0] = s, 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: d,
isHeaderSticky: c,
isMobile: l,
topBarAreaRef: o,
isStickyMainNavigationVisible: h,
hasBrandAddOn: m
} = re(z);
let y, p;
if (e[5] !== t || e[6] !== n || e[7] !== m || e[8] !== c || e[9] !== l || e[10] !== h || e[11] !== a || e[12] !== d) {
const B = F(t, fe), A = F(t, Ae), i = F(t, pe);
process.env.NODE_ENV !== "production" && Ke({
hasBrandArea: B,
hasPrimaryArea: A,
hasSecondaryArea: i
});
let S;
e[15] !== c || e[16] !== l || e[17] !== h || e[18] !== a ? (S = H(u.root, a, c ? {
[u.rootSticky]: !l && h,
[u.rootFixed]: !l && !h
} : {}), e[15] = c, e[16] = l, e[17] = h, e[18] = a, e[19] = S) : S = e[19], y = S, p = H(u.content, n, {
[u.contentHasPrimaryArea]: A && !m && !i,
[u.contentHasPrimaryAreaWithBrandAddOn]: A && m && !i,
[u.contentHasBrandAddOnWithPrimaryAreaAndSecondaryArea]: m && A && i,
[u.contentHasPrimaryAreaAndSecondaryArea]: A && i && !m,
[u.contentVariantFull]: d === "full"
}), e[5] = t, e[6] = n, e[7] = m, e[8] = c, e[9] = l, e[10] = h, e[11] = a, e[12] = d, e[13] = y, e[14] = p;
} else
y = e[13], p = e[14];
const v = p;
let f;
e[20] !== t || e[21] !== v || e[22] !== r ? (f = /* @__PURE__ */ _("section", { className: v, ...r, children: t }), e[20] = t, e[21] = v, e[22] = r, e[23] = f) : f = e[23];
let g;
return e[24] !== y || e[25] !== f || e[26] !== o ? (g = /* @__PURE__ */ _("div", { className: y, ref: o, children: f }), e[24] = y, e[25] = f, e[26] = o, e[27] = g) : g = e[27], g;
}, fe = (s) => {
const e = T.c(22), {
children: t,
className: n
} = s, {
logoProps: r,
brandAddOnProps: a,
setHasBrandAddOn: d
} = re(z), {
aria: c,
logo: l,
href: o,
target: h
} = r || {}, m = l === void 0 ? "main" : l, y = o === void 0 ? "/" : o, p = h === void 0 ? "_self" : h;
let v;
e[0] !== a || e[1] !== t || e[2] !== d ? (v = () => {
t || !_e(a) ? d?.(!0) : d?.(!1);
}, e[0] = a, e[1] = t, e[2] = d, e[3] = v) : v = e[3];
let f;
e[4] !== a || e[5] !== t ? (f = [t, a], e[4] = a, e[5] = t, e[6] = f) : f = e[6], ae(v, f);
const g = H(u.logo, {
[u.logoReduced]: m.includes("reduced")
});
let B;
e[7] !== n ? (B = H(u.brand, n), e[7] = n, e[8] = B) : B = e[8];
let A;
e[9] !== c || e[10] !== y || e[11] !== m || e[12] !== g || e[13] !== p ? (A = /* @__PURE__ */ _(Pe, { className: g, aria: c, logo: m, href: y, target: p }), e[9] = c, e[10] = y, e[11] = m, e[12] = g, e[13] = p, e[14] = A) : A = e[14];
let i;
e[15] !== a ? (i = _e(a) ? void 0 : /* @__PURE__ */ _(ye, { ...a }), e[15] = a, e[16] = i) : i = e[16];
let S;
return e[17] !== t || e[18] !== B || e[19] !== A || e[20] !== i ? (S = /* @__PURE__ */ me("div", { className: B, children: [
A,
i,
t
] }), e[17] = t, e[18] = B, e[19] = A, e[20] = i, e[21] = S) : S = e[21], S;
};
fe.displayName = "DSTopBar.BrandArea";
const ye = (s) => {
const e = T.c(15), {
children: t,
className: n,
subTitle: r,
variant: a
} = s;
let d;
e[0] !== n || e[1] !== r ? (d = H(u.brandAddOn, n, {
[u.brandAddOnDouble]: r
}), e[0] = n, e[1] = r, e[2] = d) : d = e[2];
const c = d;
if (r) {
let o;
e[3] !== t ? (o = /* @__PURE__ */ _("span", { children: t }), e[3] = t, e[4] = o) : o = e[4];
let h;
e[5] !== r ? (h = r && /* @__PURE__ */ _("span", { className: u.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__ */ me("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__ */ _(Te, {}), e[11] = o) : o = e[11], o;
}
let l;
return e[12] !== c || e[13] !== t ? (l = /* @__PURE__ */ _("div", { className: c, children: t }), e[12] = c, e[13] = t, e[14] = l) : l = e[14], l;
};
ye.displayName = "DSTopBar.BrandAddOn";
const Ae = (s) => {
const e = T.c(5), {
children: t,
className: n
} = s;
let r;
e[0] !== n ? (r = H(u.primary, n), e[0] = n, e[1] = r) : r = e[1];
let a;
return e[2] !== t || e[3] !== r ? (a = /* @__PURE__ */ _("div", { className: r, children: t }), e[2] = t, e[3] = r, e[4] = a) : a = e[4], a;
};
Ae.displayName = "DSTopBar.PrimaryArea";
const pe = (s) => {
const e = T.c(5), {
children: t,
className: n
} = s;
let r;
e[0] !== n ? (r = H(u.secondary, n), e[0] = n, e[1] = r) : r = e[1];
let a;
return e[2] !== t || e[3] !== r ? (a = /* @__PURE__ */ _("div", { className: r, children: t }), e[2] = t, e[3] = r, e[4] = a) : a = e[4], a;
};
pe.displayName = "DSTopBar.SecondaryArea";
$.BrandArea = fe;
$.PrimaryArea = Ae;
$.SecondaryArea = pe;
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", b = {
root: Qe,
rootSticky: Xe,
rootHidden: Ze,
rootFixed: et,
mainNavigationArea: tt,
mainNavigationAreaFixed: at,
mainNavigationAreaFixedVisible: rt,
mainNavigationContent: nt,
mainNavigationContentVariantFull: ot,
headerPlaceholder: it,
headerPlaceholderWithBanner: st
}, z = xe({
variant: "main"
}), ne = (s) => {
const e = T.c(57);
let t, n, r, a, d, c, l;
e[0] !== s ? ({
children: n,
brandAddOnProps: t,
className: r,
isHeaderSticky: c,
variant: l,
logoProps: a,
...d
} = s, e[0] = s, e[1] = t, e[2] = n, e[3] = r, e[4] = a, e[5] = d, e[6] = c, e[7] = l) : (t = e[1], n = e[2], r = e[3], a = e[4], d = e[5], c = e[6], l = e[7]);
const o = c === void 0 ? !1 : c, h = l === void 0 ? "main" : l, [m, y] = O(!1);
let p;
e[8] !== n ? (p = F(n, ne.BannerArea, !0), e[8] = n, e[9] = p) : p = e[9];
const v = p, f = F(n, $.BrandArea), g = F(n, $.PrimaryArea), B = F(n, $.SecondaryArea);
process.env.NODE_ENV !== "production" && Oe({
hasBrandArea: f,
hasPrimaryArea: g,
hasSecondaryArea: B
});
const A = Ee(), [i, S] = O(!1), W = L(null), U = L(null), oe = L(null), ie = L(null), [se, be] = O(!1), [C, Se] = O(!1), [w, ue] = O(!0), [ce, Ne] = O(!1), de = L(i);
let j, G;
e[10] !== o ? (j = () => {
if (o) {
const N = () => {
S((x) => (de.current = x, window.innerWidth < 1024));
};
return N(), window.addEventListener("resize", N), () => window.removeEventListener("resize", N);
}
}, G = [o], e[10] = o, e[11] = j, e[12] = G) : (j = e[11], G = e[12]), ae(j, G);
let J, K;
e[13] === Symbol.for("react.memo_cache_sentinel") ? (J = () => {
const N = () => {
const x = document.documentElement, I = W.current?.offsetHeight || 0, D = oe.current?.offsetHeight || 0;
let E;
if (!ie.current)
E = I + D;
else {
const P = U.current?.offsetHeight;
!P || P === I ? E = parseInt(x.style.getPropertyValue("--ds-header-height").replace("rem", "")) * 16 || 0 : E = P;
}
x.style.setProperty("--ds-banner-height", `${he(I)}rem`), x.style.setProperty("--ds-header-height", `${he(E)}rem`), x.style.setProperty("--ds-top-bar-height", `${he(D)}rem`);
};
return N(), window.addEventListener("resize", N), () => window.removeEventListener("resize", N);
}, K = [], e[13] = J, e[14] = K) : (J = e[13], K = e[14]), De(J, K);
let Q;
e[15] !== o || e[16] !== i || e[17] !== w || e[18] !== A ? (Q = () => {
if (o) {
const N = () => {
const D = U.current, E = !!D && window.scrollY <= D.offsetHeight;
be(E);
const P = ie.current, te = oe.current;
if (!i && de.current && !w) {
ue(E && !!D && window.scrollY <= D.offsetHeight);
return;
}
const Be = !!te && !!P && P.getBoundingClientRect().bottom > te.getBoundingClientRect().bottom, we = !P && !!te && !!W.current && (window.scrollY >= W.current.offsetHeight || 0) || !P && !W.current && !!te && window.scrollY >= 1;
ue(P ? Be && !!D && window.scrollY <= D.offsetHeight : !we);
};
window.addEventListener("scroll", N, {
passive: !0
}), N();
const x = U.current, I = !!x && x.getBoundingClientRect().bottom > 0;
return i && Se(A === "up" && !I), i || Ne(A === "up" && !w), () => {
window.removeEventListener("scroll", N);
};
}
}, e[15] = o, e[16] = i, e[17] = w, e[18] = A, e[19] = Q) : Q = e[19];
let X;
e[20] !== o || e[21] !== i || e[22] !== A ? (X = [o, i, de, A], e[20] = o, e[21] = i, e[22] = A, e[23] = X) : X = e[23], ae(Q, X);
let Z;
e[24] !== r || e[25] !== C || e[26] !== o || e[27] !== se || e[28] !== i ? (Z = H(b.root, r, o ? {
[b.rootSticky]: i,
[b.rootHidden]: i && !se,
[b.rootFixed]: i && C
} : {}), e[24] = r, e[25] = C, e[26] = o, e[27] = se, e[28] = i, e[29] = Z) : Z = e[29];
const le = Z;
let V;
e[30] !== t || e[31] !== m || e[32] !== ce || e[33] !== o || e[34] !== i || e[35] !== w || e[36] !== a || e[37] !== h ? (V = {
variant: h,
bannerAreaRef: W,
brandAddOnProps: t,
hasBrandAddOn: m,
setHasBrandAddOn: y,
isFixedMainNavigation: ce,
isHeaderSticky: o,
isMobile: i,
isStickyMainNavigationVisible: w,
mainNavigationAreaRef: ie,
topBarAreaRef: oe,
logoProps: a
}, e[30] = t, e[31] = m, e[32] = ce, e[33] = o, e[34] = i, e[35] = w, e[36] = a, e[37] = h, e[38] = V) : V = e[38];
let R;
e[39] !== n || e[40] !== V ? (R = /* @__PURE__ */ _(z.Provider, { value: V, children: n }), e[39] = n, e[40] = V, e[41] = R) : R = e[41];
let M;
e[42] !== d || e[43] !== le || e[44] !== R ? (M = /* @__PURE__ */ _("header", { className: le, ...d, ref: U, children: R }), e[42] = d, e[43] = le, e[44] = R, e[45] = M) : M = e[45];
let q;
e[46] !== C || e[47] !== i ? (q = i && C && /* @__PURE__ */ _("div", { className: b.headerPlaceholder }), e[46] = C, e[47] = i, e[48] = q) : q = e[48];
let k;
e[49] !== v || e[50] !== i || e[51] !== w ? (k = !i && !w && /* @__PURE__ */ _("div", { className: v ? b.headerPlaceholderWithBanner : b.headerPlaceholder }), e[49] = v, e[50] = i, e[51] = w, e[52] = k) : k = e[52];
let ee;
return e[53] !== M || e[54] !== q || e[55] !== k ? (ee = /* @__PURE__ */ me(He, { children: [
M,
q,
k
] }), e[53] = M, e[54] = q, e[55] = k, e[56] = ee) : ee = e[56], ee;
}, ve = (s) => {
const e = T.c(4), {
children: t,
className: n
} = s, {
bannerAreaRef: r
} = re(z);
let a;
return e[0] !== r || e[1] !== t || e[2] !== n ? (a = /* @__PURE__ */ _("div", { ref: r, className: n, children: t }), e[0] = r, e[1] = t, e[2] = n, e[3] = a) : a = e[3], a;
};
ve.displayName = "DSHeader.BannerArea";
const ge = (s) => {
const e = T.c(15), {
children: t,
className: n
} = s, {
variant: r,
isFixedMainNavigation: a,
isHeaderSticky: d,
isMobile: c,
isStickyMainNavigationVisible: l,
mainNavigationAreaRef: o
} = re(z);
let h;
e[0] !== n || e[1] !== a || e[2] !== d || e[3] !== c || e[4] !== l ? (h = H(b.mainNavigationArea, n, d ? {
[b.mainNavigationAreaFixed]: !c && !l,
[b.mainNavigationAreaFixedVisible]: !c && a
} : {}), e[0] = n, e[1] = a, e[2] = d, e[3] = c, e[4] = l, e[5] = h) : h = e[5];
const m = h, y = r === "full";
let p;
e[6] !== y ? (p = H(b.mainNavigationContent, {
[b.mainNavigationContentVariantFull]: y
}), e[6] = y, e[7] = p) : p = e[7];
const v = p;
let f;
e[8] !== t || e[9] !== v ? (f = /* @__PURE__ */ _("div", { className: v, children: t }), e[8] = t, e[9] = v, e[10] = f) : f = e[10];
let g;
return e[11] !== o || e[12] !== m || e[13] !== f ? (g = /* @__PURE__ */ _("div", { className: m, ref: o, children: f }), e[11] = o, e[12] = m, e[13] = f, e[14] = g) : g = e[14], g;
};
ge.displayName = "DSHeader.MainNavigationArea";
ne.BannerArea = ve;
ne.MainNavigationArea = ge;
ne.displayName = "DSHeader";
export {
_t as B,
z as D,
ut as H,
ne as a,
$ as b,
Ke as c,
_e as i,
Oe as v
};