@arolariu/components
Version:
🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡
46 lines (45 loc) • 1.7 kB
JavaScript
"use client";
import * as __rspack_external_react from "react";
function useAnnounce() {
const politeRef = __rspack_external_react.useRef(null);
const assertiveRef = __rspack_external_react.useRef(null);
__rspack_external_react.useEffect(()=>{
const createRegion = (politeness)=>{
const element = document.createElement("div");
element.setAttribute("role", "status");
element.setAttribute("aria-live", politeness);
element.setAttribute("aria-atomic", "true");
Object.assign(element.style, {
position: "absolute",
width: "1px",
height: "1px",
padding: "0",
margin: "-1px",
overflow: "hidden",
clip: "rect(0,0,0,0)",
whiteSpace: "nowrap",
border: "0"
});
document.body.append(element);
return element;
};
politeRef.current = createRegion("polite");
assertiveRef.current = createRegion("assertive");
return ()=>{
politeRef.current?.remove();
assertiveRef.current?.remove();
politeRef.current = null;
assertiveRef.current = null;
};
}, []);
return __rspack_external_react.useCallback((message, politeness = "polite")=>{
const region = "assertive" === politeness ? assertiveRef.current : politeRef.current;
if (!region) return;
region.textContent = "";
requestAnimationFrame(()=>{
region.textContent = message;
});
}, []);
}
export { useAnnounce };
//# sourceMappingURL=useAnnounce.js.map