mirror of
https://github.com/zoriya/v10.git
synced 2026-08-09 07:37:48 +00:00
20 lines
634 B
JavaScript
20 lines
634 B
JavaScript
"use client";
|
|
import { useId } from "react";
|
|
//#region src/utils/use-safe-id.ts
|
|
const UNSAFE_CHARS = /[^a-zA-Z0-9_-]/g;
|
|
/**
|
|
* Generate a CSS-safe identifier from React's `useId()`.
|
|
*
|
|
* `useId()` returns values like `:r0:` which contain colons — invalid
|
|
* in CSS `<dashed-ident>` tokens (used by `anchor-name` / `position-anchor`).
|
|
* This hook strips non-alphanumeric/underscore/hyphen characters and
|
|
* optionally prepends a prefix.
|
|
*/
|
|
function useSafeId(prefix) {
|
|
const raw = useId().replace(UNSAFE_CHARS, "");
|
|
return prefix ? `${prefix}-${raw}` : raw;
|
|
}
|
|
//#endregion
|
|
export { useSafeId };
|
|
|
|
//# sourceMappingURL=use-safe-id.js.map
|