@@directive("'use client'") module TablerIcons = { type props = {className?: string} module IconCheck = { @module("@tabler/icons-react") external make: React.component = "IconCheck" } module IconCopy = { @module("@tabler/icons-react") external make: React.component = "IconCopy" } module IconTerminal = { @module("@tabler/icons-react") external make: React.component = "IconTerminal" } } @val @scope(("navigator", "clipboard")) external writeText: string => promise = "writeText" @react.component let make = (~npm, ~yarn, ~pnpm, ~bun) => { let (packageManager, setPackageManager) = Config.PackageManager.use() let (hasCopied, setHasCopied) = React.useState(() => false) React.useEffect(() => { if hasCopied { let timer = setTimeout(~handler=() => setHasCopied(_ => false), ~timeout=2000) Some(() => clearTimeout(timer)) } else { None } }, [hasCopied]) let tabs = React.useMemo( () => dict{"npm": npm, "yarn": yarn, "pnpm": pnpm, "bun": bun}, [npm, yarn, pnpm, bun], ) let copyCommand = React.useCallback(_ => { tabs ->Dict.get((packageManager :> string)) ->Option.forEach(command => { writeText(command)->ignore setHasCopied(_ => true) }) }, (packageManager, tabs))
setPackageManager(_ => value)} >
{tabs ->Dict.toArray ->Array.map(((key, _)) => {key->React.string} ) ->React.array}
{tabs ->Dict.toArray ->Array.map(((key, value)) =>
              
                {value->React.string}
              
            
) ->React.array}
}