modal-drawer-system
БесплатноБез исполняемых скриптовНе проверенImplements accessible modals and drawers with focus trap, ESC to close, scroll lock, portal rendering, and ARIA attributes. Includes sample implementations…
от patricio0312rev★ 64 звезды на GitHubОб этом скилле
Modal & Drawer System Generator
Create accessible, polished modal dialogs and drawer components.
Core Workflow
- Choose type: Modal (center), Drawer (side), Bottom Sheet
- Setup portal: Render outside DOM hierarchy
- Focus management: Focus trap and restoration
- Accessibility: ARIA attributes, keyboard shortcuts
- Animations: Smooth enter/exit transitions
- Scroll lock: Prevent body scroll when open
- Backdrop: Click outside to close
Base Modal Component
"use client";
import { useEffect, useRef } from "react";
import { createPortal } from "react-dom";
import { X } from "lucide-react";
interface ModalProps {
isOpen: boolean;
onClose: () => void;
title?: string;
description?: string;
children: React.ReactNode;
size?: "sm" | "md" | "lg" | "xl" | "full";
closeOnEscape?: boolean;
closeOnBackdrop?: boolean;
}
export function Modal({
isOpen,
onClose,
title,
description,
children,
size = "md",
closeOnEscape = true,
closeOnBackdrop = true,
}: ModalProps) {
const modalRef = useRef<HTMLDivElement>(null);
// ESC key handler
useEffect(() => {
if (!isOpen || !closeOnEscape) return;
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose();
};
document.addEventListener("keydown", handleEscape);
return () => document.removeEventListener("keydown", handleEscape);
}, [isOpen, closeOnEscape, onClose]);
// Focus trap
useEffect(() => {
if (!isOpen) return;
const focusableElements = modalRef.current?.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
);
const firstElement = focusableElements?.[0] as HTMLElement;
const lastElement = focusableElements?.[
focusableElements.length - 1
] as HTMLElement;
const handleTab = (e: KeyboardEvent) => {
if (e.key !== "Tab") return;
if (e.shiftKey && document.activeElement === firstElement) {
e.preventDefault();
lastElement?.focus();
} else if (!e.shiftKey && document.activeElement === lastElement) {
e.preventDefault();
firstElement?.focus();
}
};
firstElement?.focus();
document.addEventListener("keydown", handleTab);
return () => document.removeEventListener("keydown", handleTab);
}, [isOpen]);
// Body scroll lock
useEffect(() => {
if (isOpen) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = "";
}
return () => {
document.body.style.overflow = "";
};
}, [isOpen]);
if (!isOpen) return null;
const sizeClasses = {
sm: "max-w-sm",
md: "max-w-md",
lg: "max-w-lg",
xl: "max-w-xl",
full: "max-w-full mx-4",
};
return createPortal(
<div
className="fixed inset-0 z-50 flex items-center justify-center"
role="dialog"
aria-modal="true"
aria-labelledby={title ? "modal-title" : undefined}
aria-describedby={description ? "modal-description" : undefined}
>
{/* Backdrop */}
<div
className="absolute inset-0 bg-black/50 backdrop-blur-sm animate-in fade-in"
onClick={closeOnBackdrop ? onClose : undefined}
/>
{/* Modal */}
<div
ref={modalRef}
className={`relative z-10 w-full ${sizeClasses[size]} animate-in zoom-in-95 slide-in-from-bottom-4 duration-200`}
>
<div className="rounded-lg bg-white shadow-xl">
{/* Header */}
{(title || description) && (
<div className="border-b px-6 py-4">
{title && (
<h2 id="modal-title" className="text-xl font-semibold">
{title}
</h2>
)}
{description && (
<p
id="modal-description"
className="mt-1 text-sm text-gray-600"
>
{description}
</p>
)}
</div>
)}
{/* Close button */}
<button
onClick={onClose}
className="absolute right-4 top-4 rounded-lg p-1 hover:bg-gray-100"
aria-label="Close modal"
>
<X className="h-5 w-5" />
</button>
{/* Content */}
<div className="p-6">{children}</div>
</div>
</div>
</div>,
document.body
);
}
Drawer Component
interface DrawerProps {
isOpen: boolean;
onClose: () => void;
position?: "left" | "right" | "bottom";
title?: string;
children: React.ReactNode;
}
export function Drawer({
isOpen,
onClose,
position = "right",
title,
children,
}: DrawerProps) {
// Similar hooks as Modal (ESC, focus trap, scroll lock)
const positionClasses = {
left: "left-0 top-0 h-full w-80 animate-in slide-in-from-left",
right: "right-0 top-0 h-full w-80 animate-in slide-in-from-right",
bottom: "bottom-0 le
Установить modal-drawer-system в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл modal-drawer-system?
Implements accessible modals and drawers with focus trap, ESC to close, scroll lock, portal rendering, and ARIA attributes. Includes sample implementations for common use cases like edit forms, confirmations, and detail views. Use when building "modals", "dialogs", "drawers", "sidebars", or "overlays".
Как установить скилл modal-drawer-system?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modal-drawer-system запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic