diff --git a/AGENTS.md b/AGENTS.md index 6bbd9f25..f75095f9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,17 @@ and static registry. Components use React 19, Base UI, StyleX, and TypeScript. catalogs, inline previews, guides, search, machine-readable docs, and registry hosting. The first release is copy/paste-only and does not publish an npm package. +## Blocks + +Install login, signup, and sidebar blocks by their numbered registry names. +The CLI puts blocks in the `blocks` directory under the configured components directory. +Connect authentication forms to your authentication service before use. +Authentication blocks with social buttons install components/icons/social.tsx. +Reuse AppleIcon, FacebookIcon, GitHubIcon, and GoogleIcon from this file. +Give icon-only buttons an accessible name. +Sidebar blocks share the installed sidebar-workspace.tsx file. +Sidebar10 and Sidebar13 open their panels by default. Set defaultOpen to false to start with the panel closed. + ## Commands ```sh diff --git a/README.md b/README.md index cc5b36f7..9fa864ca 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,32 @@ except for local HTTP. It must not contain credentials, query strings, or fragments. The CLI rejects redirects. See [installation](https://ui.yopem.com/docs/installation). +## Install a block + +[Browse blocks](https://ui.yopem.com/blocks). Select Base UI or Ark UI for the +gallery. Each preview starts in Desktop mode. Select Tablet or Mobile to try a +narrower layout. + +Choose `login-01` through `login-05`, `signup-01` through `signup-05`, or +`sidebar-01` through `sidebar-16`. Install one layout by name: + +```sh +bunx --bun @yopem-ui/cli add sidebar-09 +``` + +Both providers install blocks under `components/blocks`. The CLI installs their +UI primitives separately. Import the layout from the block file: + +```tsx +import { Sidebar09 } from "@/components/blocks/sidebar-09" + +export function MailPage() { + return +} +``` + +Authentication blocks provide forms, not an authentication service. + ## Styling Use `Box` for generic containers. Use its `render` prop to select a semantic diff --git a/apps/docs/src/catalog/block-gallery-code.tsx b/apps/docs/src/catalog/block-gallery-code.tsx new file mode 100644 index 00000000..db5a6f06 --- /dev/null +++ b/apps/docs/src/catalog/block-gallery-code.tsx @@ -0,0 +1,299 @@ +import { Stack } from "@registry/components/ui/stack" +import { Text } from "@registry/components/ui/text" +import { Wrap } from "@registry/components/ui/wrap" +import { Box } from "@registry/providers/base-ui/components/ui/box" +import { Button } from "@registry/providers/base-ui/components/ui/button" +import { + Select, + SelectItem, + SelectPopup, + SelectTrigger, + SelectValue, +} from "@registry/providers/base-ui/components/ui/select" +import { tokens } from "@registry/styles/tokens.stylex" +import * as stylex from "@stylexjs/stylex" +import { Await, Link } from "@tanstack/react-router" +import { + CodeIcon, + CheckIcon, + CopyIcon, + MaximizeIcon, + MonitorIcon, + TabletIcon, + SmartphoneIcon, + ExternalLinkIcon, + BookOpenIcon, +} from "lucide-react" +import { useId, useState } from "react" +import { z } from "zod" + +import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard" + +import type { ComponentProvider } from "./provider" + +import { BlockGalleryPreview } from "./block-gallery-preview" +import { CopyableCode } from "./code-block" +import { usePackageManagerCommand } from "./package-manager" + +const blockFiles = z.object({ + files: z.array(z.object({ target: z.string(), content: z.string() })), +}) + +async function loadFiles(url: string) { + try { + const response = await fetch(url) + + if (!response.ok) return null + + return blockFiles.parse(await response.json()).files + } catch { + return null + } +} + +function FileViewer({ files }: { files: z.infer["files"] }) { + const [target, setTarget] = useState(files[0]?.target) + const file = files.find((entry) => entry.target === target) + + if (!file) return No source files available. + + const items = files.map(({ target: value }) => ({ + label: value.split("/").pop() ?? value, + value, + })) + + return ( + + + + + + ) +} + +function SourceFiles({ url }: { url: string }) { + const [files] = useState(() => loadFiles(url)) + + return ( + Loading block code…}> + {(result) => + result ? ( + + ) : ( + + Could not load block code. Close and reopen to retry. + + ) + } + + ) +} + +const styles = stylex.create({ + panel: { + gap: "0.75rem", + padding: "0.75rem", + backgroundColor: tokens["--muted"], + border: `1px solid ${tokens["--card-border"]}`, + borderRadius: tokens["--radius"], + }, + panelHeader: { + alignItems: "center", + justifyContent: "space-between", + gap: "0.5rem", + }, + title: { fontSize: "0.875rem", fontWeight: 600 }, + + files: { gap: "0.5rem" }, + label: { + display: { default: "none", "@media (min-width: 54rem)": "inline" }, + }, + devices: { + display: "flex", + alignItems: "center", + marginInlineStart: "auto", + gap: "0.125rem", + flexShrink: 0, + }, + action: { + paddingInline: { default: 0, "@media (min-width: 54rem)": "0.75rem" }, + minInlineSize: "2rem", + flexShrink: 0, + }, + toolbar: { + flexWrap: "nowrap", + overflowX: "auto", + gap: { default: "0.125rem", "@media (min-width: 54rem)": "0.5rem" }, + alignItems: "center", + paddingBlock: "0.5rem", + borderBlockStart: `1px solid ${tokens["--border"]}`, + }, + icon: { inlineSize: "1rem", blockSize: "1rem" }, +}) + +export function blockInstallCommand(name: string, provider: ComponentProvider) { + return `bunx --bun @yopem-ui/cli init --provider ${provider} &&\nbunx --bun @yopem-ui/cli add ${name}` +} + +export function BlockGalleryCode({ + name, + provider, + previewUrl, +}: { + name: string + provider: ComponentProvider + previewUrl: string +}) { + const command = usePackageManagerCommand(blockInstallCommand(name, provider)) + const { copyToClipboard, isCopied, copyError } = useCopyToClipboard() + const ClipboardIcon = isCopied ? CheckIcon : CopyIcon + const panelId = useId() + const [size, setSize] = useState<"Desktop" | "Tablet" | "Mobile">("Desktop") + const [open, setOpen] = useState(false) + const ark = provider === "ark-ui" + const url = `/r/${ark ? "ark-ui/" : ""}${name}.json` + + return ( + + + + + + + + + {( + [ + ["Desktop", MonitorIcon], + ["Tablet", TabletIcon], + ["Mobile", SmartphoneIcon], + ] as const + ).map(([label, Icon]) => ( + + ))}{" "} + + + + {copyError && {copyError}} + {open && ( + + + Block source + + + + )} + + + ) +} diff --git a/apps/docs/src/catalog/block-gallery-preview.tsx b/apps/docs/src/catalog/block-gallery-preview.tsx new file mode 100644 index 00000000..f0f36b5d --- /dev/null +++ b/apps/docs/src/catalog/block-gallery-preview.tsx @@ -0,0 +1,82 @@ +import { Box } from "@registry/providers/base-ui/components/ui/box" +import { tokens } from "@registry/styles/tokens.stylex" +import * as stylex from "@stylexjs/stylex" +import { useState } from "react" + +const styles = stylex.create({ + viewport: { + position: "relative", + inlineSize: "100%", + aspectRatio: "16 / 10", + maxBlockSize: "48rem", + marginInline: "auto", + overflow: "hidden", + border: `1px solid ${tokens["--card-border"]}`, + borderRadius: tokens["--radius"], + backgroundColor: tokens["--background"], + }, + tablet: { maxInlineSize: "768px", aspectRatio: "4 / 3" }, + mobile: { + maxInlineSize: "390px", + aspectRatio: "9 / 16", + maxBlockSize: "42rem", + }, + frame: (width: number, scale: number) => ({ + display: "block", + borderWidth: 0, + position: "absolute", + insetBlockStart: 0, + insetInlineStart: 0, + inlineSize: `${width}px`, + blockSize: `${100 / scale}%`, + transform: `scale(${scale})`, + transformOrigin: "top left", + }), +}) + +export function BlockGalleryPreview({ + name, + src, + size, +}: { + name: string + size: "Desktop" | "Tablet" | "Mobile" + src: string +}) { + const [width, setWidth] = useState(0) + + const virtualWidth = + size === "Mobile" ? 390 : size === "Tablet" ? 768 : Math.max(width, 1024) + + const scale = width && virtualWidth ? width / virtualWidth : 1 + + return ( + +