Claude Code के साथ Radix UI
Claude Code का उपयोग करके radix ui सीखें। Practical tips और code examples शामिल हैं।
Radix UIでアクセシブルなUI buildする
Radix UIはaccessibilityに優れたヘッドレスUIcomponentlibrary है।styleを持たないため、自由にデザインを適用でき、WAI-ARIApatternに準拠したインタラクションが自動でimplementationされ है।Claude Codeはcomponentの組み立て सेスタイリング तक一貫してサポートし है।
ダイアlog(modal)のimplementation
Claude Codeにアクセシブルなmodalを依頼 करें।
> Radix UIのDialogでconfirmmodalを作って。
> Tailwind CSSでスタイリング、animation付きで。
import * as Dialog from "@radix-ui/react-dialog";
interface ConfirmDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description: string;
onConfirm: () => void;
confirmLabel?: string;
variant?: "danger" | "default";
}
function ConfirmDialog({
open,
onOpenChange,
title,
description,
onConfirm,
confirmLabel = "confirm",
variant = "default",
}: ConfirmDialogProps) {
return (
<Dialog.Root open={open} onOpenChange={onOpenChange}>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50 data-[state=open]:animate-fadeIn" />
<Dialog.Content className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white rounded-lg p-6 w-full max-w-md shadow-xl data-[state=open]:animate-slideUp">
<Dialog.Title className="text-lg font-semibold">
{title}
</Dialog.Title>
<Dialog.Description className="mt-2 text-gray-600">
{description}
</Dialog.Description>
<div className="mt-6 flex justify-end gap-3">
<Dialog.Close asChild>
<button className="px-4 py-2 rounded bg-gray-100 hover:bg-gray-200">
キャンセル
</button>
</Dialog.Close>
<button
onClick={() => {
onConfirm();
onOpenChange(false);
}}
className={`px-4 py-2 rounded text-white ${
variant === "danger"
? "bg-red-500 hover:bg-red-600"
: "bg-blue-500 hover:bg-blue-600"
}`}
>
{confirmLabel}
</button>
</div>
<Dialog.Close asChild>
<button
className="absolute top-4 right-4 text-gray-400 hover:text-gray-600"
aria-label="Close"
>
✕
</button>
</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}
ドロップダウンmenu
keyボードnavigation完備のドロップダウン है।
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
function UserMenu({ user }: { user: User }) {
return (
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<button className="flex items-center gap-2 p-2 rounded-full hover:bg-gray-100">
<img
src={user.avatar}
alt={user.name}
className="w-8 h-8 rounded-full"
/>
<span>{user.name}</span>
</button>
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content
className="min-w-[200px] bg-white rounded-lg shadow-lg border p-1"
sideOffset={5}
align="end"
>
<DropdownMenu.Label className="px-3 py-2 text-sm text-gray-500">
{user.email}
</DropdownMenu.Label>
<DropdownMenu.Separator className="h-px bg-gray-200 my-1" />
<DropdownMenu.Item className="px-3 py-2 text-sm rounded cursor-pointer hover:bg-blue-50 hover:text-blue-600 outline-none">
プロフィール
</DropdownMenu.Item>
<DropdownMenu.Item className="px-3 py-2 text-sm rounded cursor-pointer hover:bg-blue-50 hover:text-blue-600 outline-none">
settings
</DropdownMenu.Item>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger className="px-3 py-2 text-sm rounded cursor-pointer hover:bg-blue-50 outline-none flex justify-between">
theme
<span>▸</span>
</DropdownMenu.SubTrigger>
<DropdownMenu.Portal>
<DropdownMenu.SubContent className="min-w-[150px] bg-white rounded-lg shadow-lg border p-1">
<DropdownMenu.RadioGroup value="light">
<DropdownMenu.RadioItem value="light" className="px-3 py-2 text-sm rounded hover:bg-blue-50 outline-none">
light
</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="dark" className="px-3 py-2 text-sm rounded hover:bg-blue-50 outline-none">
dark
</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="system" className="px-3 py-2 text-sm rounded hover:bg-blue-50 outline-none">
システム
</DropdownMenu.RadioItem>
</DropdownMenu.RadioGroup>
</DropdownMenu.SubContent>
</DropdownMenu.Portal>
</DropdownMenu.Sub>
<DropdownMenu.Separator className="h-px bg-gray-200 my-1" />
<DropdownMenu.Item className="px-3 py-2 text-sm rounded cursor-pointer hover:bg-red-50 text-red-600 outline-none">
logアウト
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
);
}
tabcomponent
import * as Tabs from "@radix-ui/react-tabs";
function SettingsTabs() {
return (
<Tabs.Root defaultValue="general" className="w-full">
<Tabs.List className="flex border-b" aria-label="settings">
{["general", "security", "notifications"].map((tab) => (
<Tabs.Trigger
key={tab}
value={tab}
className="px-4 py-2 text-sm border-b-2 border-transparent data-[state=active]:border-blue-500 data-[state=active]:text-blue-600 hover:text-gray-700"
>
{tab === "general" && "一般"}
{tab === "security" && "security"}
{tab === "notifications" && "通知"}
</Tabs.Trigger>
))}
</Tabs.List>
<Tabs.Content value="general" className="p-4">
<h3 className="text-lg font-medium">一般settings</h3>
{/* 一般settingsのform */}
</Tabs.Content>
<Tabs.Content value="security" className="p-4">
<h3 className="text-lg font-medium">securitysettings</h3>
{/* securitysettingsのform */}
</Tabs.Content>
<Tabs.Content value="notifications" className="p-4">
<h3 className="text-lg font-medium">通知settings</h3>
{/* 通知settingsのform */}
</Tabs.Content>
</Tabs.Root>
);
}
ツールチップとポップオーバー
import * as Tooltip from "@radix-ui/react-tooltip";
function IconButton({ icon, label }: { icon: React.ReactNode; label: string }) {
return (
<Tooltip.Provider delayDuration={300}>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<button className="p-2 rounded hover:bg-gray-100" aria-label={label}>
{icon}
</button>
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="bg-gray-900 text-white text-xs px-3 py-1.5 rounded shadow-lg"
sideOffset={5}
>
{label}
<Tooltip.Arrow className="fill-gray-900" />
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
);
}
Summary
Radix UIはaccessibilityを犠牲にする बातなく、自由度の高いUI buildできる優れたlibrary है।Claude Code का उपयोग करके、各componentの組み立てとスタイリングを素早くimplementationでき है।
Radix UIをベースにしたUIbuildはshadcn/uiutilizationガイドを、animationのaddはFramer Motionanimationimplementationを、accessibilityの全般的なsupportはaccessibilityimplementationガイドをदेखें。Radix UIofficial documentationもconfirmしておきましょう。
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।