UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

1 lines 1.62 kB
{"version":3,"file":"inert.mjs","names":[],"sources":["../src/inert.ts"],"sourcesContent":["import { version } from 'react';\n\n// React 19 turned `inert` into a real boolean attribute, so a falsy value like `''`\n// is no longer reflected to the DOM. React 18 doesn't know `inert` and only serializes\n// a (non-undefined) string value. Resolve the consumer's React major once at module\n// load — `react` is a peer dependency, so this reads the same copy the component renders\n// with — and emit the value that major actually reflects.\n//\n// `parseInt` handles prerelease strings like `19.0.0-rc-...`. Experimental builds report\n// `0.0.0-experimental-...` (major 0) but ship React 19 behavior, so treat 0 as modern too.\nconst major = parseInt(version, 10);\nconst isModernReact = major >= 19 || major === 0;\n\n/**\n * Returns props to spread onto an element to apply (or omit) the `inert` attribute\n * correctly across React 18 and 19.\n *\n * Typed as `Record<string, unknown>` on purpose: React 18's types reject `inert` and\n * React 19's type it as `boolean`, so an untyped spread sidesteps both type-level shapes\n * regardless of which `@types/react` a consumer compiles against.\n *\n * @param active - Whether the element should be inert.\n */\nexport function inertProps(active: boolean): Record<string, unknown> {\n if (!active) {\n return {};\n }\n return { inert: isModernReact ? true : '' };\n}\n"],"mappings":";;;AAUA,MAAM,QAAQ,SAAS,SAAS,EAAE;AAClC,MAAM,gBAAgB,SAAS,MAAM,UAAU;;;;;;;;;;;AAY/C,SAAgB,WAAW,QAA0C;CACnE,IAAI,CAAC,QACH,OAAO,CAAC;CAEV,OAAO,EAAE,OAAO,gBAAgB,OAAO,GAAG;AAC5C"}