UNPKG

@stihl-design-system/components

Version:

Welcome to the STIHL Design System react component library.

185 lines (184 loc) 6.48 kB
"use client"; import { jsx as j } from "react/jsx-runtime"; import { d as D } from "./chunks/index.cKLI89Eg.js"; import { isValidElement as k, useState as H, createContext as G, forwardRef as L, cloneElement as J, useContext as K } from "react"; import { j as Q, a as W, u as X, m as Y, n as Z, c as ee, d as te, e as oe, o as se, s as ne, f as U, g as le, i as ie } from "./chunks/floating-ui.react.Chmq0RmI.js"; import { c as re } from "./chunks/index.DQOqod3i.js"; import { g as F, c as V } from "./chunks/helpers.CexwVao7.js"; import { u as ce } from "./chunks/useIsomorphicLayoutEffect.CnJ9AMFS.js"; import './assets/tooltip.C_BL2kou.css';const ae = "ds-tooltip_tooltip_juoi3_5", fe = { tooltip: ae }; function pe(n) { const t = D.c(24), { initialOpen: e, placement: o, isOpen: c, tooltipOffset: l, onOpenChange: T } = n === void 0 ? {} : n, a = e === void 0 ? !1 : e, s = o === void 0 ? "top" : o, r = l === void 0 ? 6 : l, [O, i] = H(a), f = c ?? O, u = T ?? i, w = "fixed", _ = W, y = se(r), N = Q({ crossAxis: s.includes("-"), fallbackAxisSideDirection: "start", padding: r }), b = ne({ padding: r }); let p; t[0] !== y || t[1] !== N || t[2] !== b ? (p = [y, N, b], t[0] = y, t[1] = N, t[2] = b, t[3] = p) : p = t[3]; let g; t[4] !== f || t[5] !== s || t[6] !== u || t[7] !== _ || t[8] !== p ? (g = { placement: s, open: f, strategy: w, onOpenChange: u, whileElementsMounted: _, middleware: p }, t[4] = f, t[5] = s, t[6] = u, t[7] = _, t[8] = p, t[9] = g) : g = t[9]; const v = X(g), E = v.context; let d; t[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (d = { move: !1, enabled: !0, mouseOnly: !0, delay: { open: 400, close: 0 } }, t[10] = d) : d = t[10]; const m = Y(E, d); let C; t[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (C = { enabled: !0 }, t[11] = C) : C = t[11]; const h = Z(E, C), x = ee(E); let S; t[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (S = { role: "tooltip" }, t[12] = S) : S = t[12]; const A = te(E, S); let P; t[13] !== x || t[14] !== h || t[15] !== m || t[16] !== A ? (P = [m, h, x, A], t[13] = x, t[14] = h, t[15] = m, t[16] = A, t[17] = P) : P = t[17]; const $ = oe(P); let R; return t[18] !== v || t[19] !== $ || t[20] !== f || t[21] !== u || t[22] !== r ? (R = { open: f, tooltipOffset: r, setOpen: u, ...$, ...v }, t[18] = v, t[19] = $, t[20] = f, t[21] = u, t[22] = r, t[23] = R) : R = t[23], R; } const de = (n) => { if (!k(n)) throw new Error(F("Tooltip", "Tooltip.Anchor child must be a valid React element.")); }, ue = ({ children: n, hasContent: t, hasAnchor: e }) => { if (!n) throw new Error(F("Tooltip", "A Tooltip must have children.")); if (!t) throw new Error(F("Tooltip", "A Tooltip must have a <Tooltip.Content> component as a child. Please add it to the children of Tooltip.")); if (!e) throw new Error(F("Tooltip", "A Tooltip must have a <Tooltip.Anchor> component as a child. Please add it to the children of Tooltip.")); }, q = G(null), z = () => { const n = K(q); if (n == null) throw new Error(F("Tooltip", "Components like Tooltip.Anchor or Tooltip.Content must be wrapped in <Tooltip />.")); return n; }, M = (n) => { const t = D.c(9); let e, o; t[0] !== n ? ({ children: e, ...o } = n, t[0] = n, t[1] = e, t[2] = o) : (e = t[1], o = t[2]); let c; t[3] !== o ? (c = { ...o }, t[3] = o, t[4] = c) : c = t[4]; const l = pe(c), T = V(e, M.Content), a = V(e, I); process.env.NODE_ENV !== "production" && ue({ children: e, hasContent: T, hasAnchor: a }); let s; return t[5] !== e || t[6] !== o || t[7] !== l ? (s = /* @__PURE__ */ j(q.Provider, { value: l, ...o, children: e }), t[5] = e, t[6] = o, t[7] = l, t[8] = s) : s = t[8], s; }, I = L((n, t) => { const e = D.c(4), { children: o, ...c } = n; process.env.NODE_ENV !== "production" && de(o); const l = z(), T = k(o) ? o.ref : null; let a; e[0] !== T || e[1] !== l.refs.setReference || e[2] !== t ? (a = [l.refs.setReference, t, T], e[0] = T, e[1] = l.refs.setReference, e[2] = t, e[3] = a) : a = e[3]; const s = U(a); if (k(o)) return J(o, l.getReferenceProps({ ...o.props, ...c, ref: s, "data-state": l.open ? "open" : "closed" })); }); I.displayName = "Tooltip.Anchor"; const B = L((n, t) => { const e = D.c(30), { style: o, className: c, children: l, ...T } = n, a = z(); let s, r, O, i; e[0] !== a ? ({ context: s, floatingStyles: r, getFloatingProps: O, ...i } = a, e[0] = a, e[1] = s, e[2] = r, e[3] = O, e[4] = i) : (s = e[1], r = e[2], O = e[3], i = e[4]); let f; e[5] !== t || e[6] !== i.refs.setFloating ? (f = [i.refs.setFloating, t], e[5] = t, e[6] = i.refs.setFloating, e[7] = f) : f = e[7]; const u = U(f); let w; e[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (w = { duration: { open: 400, close: 100 } }, e[8] = w) : w = e[8]; const { isMounted: _, status: y } = le(s, w), [N, b] = H(null); let p; e[9] !== i.refs.reference.current ? (p = () => { const A = i.refs.reference.current?.closest("dialog"); b(A instanceof HTMLDialogElement ? A : null); }, e[9] = i.refs.reference.current, e[10] = p) : p = e[10]; let g; if (e[11] !== s.open || e[12] !== i.refs.reference ? (g = [i.refs.reference, s.open], e[11] = s.open, e[12] = i.refs.reference, e[13] = g) : g = e[13], ce(p, g), !_) return null; const v = ie, E = N ?? void 0; let d; e[14] !== r || e[15] !== o ? (d = { ...r, ...o }, e[14] = r, e[15] = o, e[16] = d) : d = e[16]; let m; e[17] !== c ? (m = re(fe.tooltip, c), e[17] = c, e[18] = m) : m = e[18]; const C = O(T); let h; e[19] !== l || e[20] !== u || e[21] !== y || e[22] !== d || e[23] !== m || e[24] !== C ? (h = /* @__PURE__ */ j("div", { ref: u, style: d, className: m, ...C, "data-status": y, children: l }), e[19] = l, e[20] = u, e[21] = y, e[22] = d, e[23] = m, e[24] = C, e[25] = h) : h = e[25]; let x; return e[26] !== v || e[27] !== h || e[28] !== E ? (x = /* @__PURE__ */ j(v, { root: E, children: h }), e[26] = v, e[27] = h, e[28] = E, e[29] = x) : x = e[29], x; }); B.displayName = "Tooltip.Content"; M.Anchor = I; M.Content = B; M.displayName = "Tooltip"; export { M as Tooltip };