@stihl-design-system/components
Version:
Welcome to the STIHL Design System react component library.
64 lines (63 loc) • 2.25 kB
JavaScript
"use client";
import { g as i } from "./helpers.CexwVao7.js";
import { h as l } from "./has-window.ut_-aShB.js";
const n = "ds-alert-live-region", s = "ds-status-live-region", c = () => {
if (l)
return document.getElementById(n);
}, u = () => {
if (l)
return document.getElementById(s);
}, d = () => {
if (!l)
return;
const t = document.querySelectorAll(`#${n}`), e = document.querySelectorAll(`#${s}`);
if (t.length > 1)
throw new Error(i("DSAriaLiveRegions", `The DSAriaLiveRegions component with id="${n}" should only be present once on the page. Found ${t.length} instances.`));
if (e.length > 1)
throw new Error(i("DSAriaLiveRegions", `The DSAriaLiveRegions component with id="${s}" should only be present once on the page. Found ${e.length} instances.`));
}, R = (t) => {
if (!l || !document.body)
return;
d();
const e = c(), o = u();
if (e && o)
return;
if (e || o) {
const g = e ? n : s;
throw new Error(i("DSAriaLiveRegions", `Only one of the required aria-live regions is present on the page (found "${g}"). Expected both "${n}" and "${s}".`));
}
const r = document.createElement("span");
r.id = n, r.setAttribute("role", "alert"), r.className = t;
const a = document.createElement("span");
a.id = s, a.setAttribute("role", "status"), a.className = t, document.body.prepend(r, a);
}, p = (t) => {
const e = c();
if (e)
return e;
throw new Error(i(t, 'The DSAriaLiveRegions component has to be placed at the root of your application, as close to the "body" as possible, e.g. in your "App.tsx" or "layout.tsx". See the DSAriaLiveRegions documentation for setup options.'));
}, h = (t) => {
const e = u();
if (e)
return e;
throw new Error(i(t, 'The DSAriaLiveRegions component has to be placed at the root of your application, as close to the "body" as possible, e.g. in your "App.tsx" or "layout.tsx". See the DSAriaLiveRegions documentation for setup options.'));
}, A = 350, v = (t, e) => {
const o = p(e);
o.innerText = t;
}, L = (t, e) => {
const o = h(e);
o.innerText = t, setTimeout(() => {
o.innerText = "";
}, A);
};
export {
n as A,
s as a,
c as b,
u as c,
h as d,
R as e,
L as f,
p as g,
v as s,
d as v
};