Shortcuts cheatsheet
Command palette and shortcuts
Open with a shortcut, type to filter grouped commands and pages, move with arrows, trap focus inside. A companion sheet lists keyboard shortcuts by area.
실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.
내 앱에 넣기
아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.
git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이
src/components/taster에 들어갑니다.node ../taster/packages/engine/cli.mjs add blocks/shortcuts-cheatsheet --from https://taster-six.vercel.app --dir src/components/taster부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고,
tokens.css를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.// tailwind.config.cjs module.exports = { presets: [require('./src/components/taster/tailwind-preset.cjs')], content: ['./index.html', './src/**/*.{ts,tsx}'], };Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는
src/의 스타일시트 맨 위에 이 두 줄을 넣습니다.@import "tailwindcss"; @config "../tailwind.config.cjs";tokens.css는:root에--bg,--text,--border,--accent를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.
언제 쓰나요
- Command paletteOpen with a shortcut, type to filter grouped commands and pages, move with arrows, trap focus inside. A companion sheet lists keyboard shortcuts by area.
정보
코드 보기
'use client'
import * as React from 'react'
import { useFocusTrap } from './use-hotkeys'
// ShortcutsCheatsheet. A keyboard help sheet. Groups are defined by the caller.
export interface ShortcutRow {
keys: string[]
label: string
}
export interface ShortcutGroup {
title: string
rows: ShortcutRow[]
}
export interface ShortcutsCheatsheetProps {
groups: ShortcutGroup[]
onClose: () => void
title?: string
/** Name of the close button for screen readers. */
closeLabel?: string
}
function Key({ children }: { children: React.ReactNode }) {
return (
<kbd className="rounded border border-border bg-bg-sunken px-1.5 py-0.5 text-xs text-text">
{children}
</kbd>
)
}
export function ShortcutsCheatsheet({ groups, onClose, title = 'Keyboard shortcuts', closeLabel = 'Close' }: ShortcutsCheatsheetProps) {
const dialogRef = React.useRef<HTMLDivElement>(null)
// The trap moves focus into the sheet on open and back to the opener on close.
useFocusTrap(dialogRef)
const titleId = React.useId()
React.useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
e.stopPropagation()
onClose()
}
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
return (
<>
<div
className="fixed inset-0 z-40"
style={{ background: 'var(--scrim)' }}
onClick={onClose}
aria-hidden="true"
/>
<div
ref={dialogRef}
role="dialog"
aria-modal="true"
aria-labelledby={titleId}
tabIndex={-1}
className="fixed left-1/2 top-1/2 z-50 w-[min(560px,94vw)] -translate-x-1/2 -translate-y-1/2 rounded-lg border border-border bg-bg-popover p-6 shadow-[var(--sh-pop)] outline-none"
>
<div className="mb-4 flex items-center justify-between gap-3">
<h2 id={titleId} className="m-0 text-base font-semibold text-text">{title}</h2>
<button
type="button"
onClick={onClose}
aria-label={closeLabel}
className="-mr-2 inline-flex size-11 shrink-0 items-center justify-center rounded-md text-text-subtle outline-none transition-colors hover:text-text focus-visible:ring-2 focus-visible:ring-ring desk:size-9"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" aria-hidden="true">
<path d="M6 6l12 12M18 6L6 18" />
</svg>
</button>
</div>
<div className="grid gap-6 sm:grid-cols-2">
{groups.map((g) => (
<div key={g.title}>
<div className="mb-2 text-xs font-medium text-text-subtle">{g.title}</div>
<div className="divide-y divide-border-soft">
{g.rows.map((r, i) => (
<div key={i} className="flex items-center justify-between gap-3 py-1.5">
<span className="text-sm text-text-muted">{r.label}</span>
<span className="flex shrink-0 items-center gap-1">
{r.keys.map((k, ki) => (
<Key key={ki}>{k}</Key>
))}
</span>
</div>
))}
</div>
</div>
))}
</div>
</div>
</>
)
}