Drawer
Um painel que desliza a partir de uma borda e pode ser arrastado para fechar. A coluna de conteúdo tem 384px, o título 18px e os botões do rodapé 44px.
Instalação
npx shadcn@latest add @sevenone/drawerUso
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"Exemplos
Padrão
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Move Goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<div className="flex items-center justify-center gap-2 px-4">
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(-10)} aria-label="Decrease goal">
<Minus />
</Button>
<div className="flex-1 text-center">
<div className="text-7xl font-bold tracking-tighter" aria-live="polite">{goal}</div>
<div className="text-sm text-muted-foreground uppercase">Calories/day</div>
</div>
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(10)} aria-label="Increase goal">
<Plus />
</Button>
</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>Lado
direction abre o drawer por "top" (cima), "right" (direita), "bottom" (baixo) ou "left" (esquerda).
<Drawer direction="right">
<DrawerTrigger asChild>
<Button variant="outline">Open from the right</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Filters</DrawerTitle>
<DrawerDescription>Choose what the list shows.</DrawerDescription>
</DrawerHeader>
…
<DrawerFooter>
<Button>Apply</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Acessibilidade
- É um diálogo: o foco entra nele quando abre e fica dentro até fechar; Esc fecha, e o foco volta para o gatilho.
- Arrastar nunca é a única forma: mantenha um botão Cancelar (DrawerClose) no rodapé.
- Sempre dê a ele um DrawerTitle; os leitores de tela anunciam o título com a descrição.
- O movimento de deslizar para quando a pessoa pede menos movimento.