import { html } from '@webjsdev/core'; import { codeFigure, copyButton } from './code.ts'; /** * shadcn's package-manager command block (apps/v4/components/code-block-command.tsx) * and its Installation tabs (#1666): one command shown four ways, pnpm, * npm, yarn and bun, in a code figure with a tab row. The tabs are the kit's * , so with JavaScript off the first command is shown. */ const terminal = html``; /** The four package managers' spelling of running a package binary. */ export function packageCommands(args: string): Record<'pnpm' | 'npm' | 'yarn' | 'bun', string> { return { pnpm: `pnpm dlx @webjsdev/ui ${args}`, npm: `npx @webjsdev/ui ${args}`, yarn: `yarn dlx @webjsdev/ui ${args}`, bun: `bunx --bun @webjsdev/ui ${args}`, }; } export function commandBlock(commands: Record) { const keys = Object.keys(commands); return html`
${terminal}
${keys.map((k) => html`${k}`)}
${keys.map((k) => html`
${commands[k]}
`)}
${copyButton('command')}
`; } /** One file the Manual tab shows: its source, under the path it lands at. */ export interface ManualFile { source: string; title: string } /** * The Installation section: a Command tab with the add command, and a Manual * tab with the steps and the component's source. A component of several * files (chart) passes `files`, and the tab shows each under its own path. */ export function installTabs(slug: string, manual: { files?: ManualFile[]; source?: string; title?: string; dependencies?: string[] }) { const files = manual.files ?? [{ source: manual.source ?? '', title: manual.title ?? '' }]; return html` Command Manual ${commandBlock(packageCommands(`add ${slug}`))}
${manual.dependencies?.length ? html`

Install the following dependencies:

${commandBlock(packageCommands(`add ${manual.dependencies.join(' ')}`))}` : ''}

Copy and paste the following code into your project.

${files.map((f) => codeFigure(f.source, { title: f.title, lineNumbers: true }))}

Update the import paths to match your project setup.

`; }