Toggle
Form and input
A scrolling row of chips that filter a list; selected chips invert tone and unselected stay quiet.
실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.
내 앱에 넣기
아직 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/toggle --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 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.
언제 쓰나요
- Filter chipA scrolling row of chips that filter a list; selected chips invert tone and unselected stay quiet.
- Checkbox and switchOn state fills with the accent token; labels are part of the control so the whole row is the hit area.
- Plan cardsOne card per real plan with aligned slots for name, price, billing note and features. A monthly or yearly toggle updates every price. Recommended is a text label and a stronger border, not a scaled center card.
- Token themesRaw values, roles and component tokens in three layers with one brand variable on top, and both light and dark defined as token sets with a switch. Dark steps by gray levels, not neon glow.
- Tabs and segmented controlTwo to four options in one container where the active option lifts to the surface tone, or text tabs with a thin underline for sibling pages. Includes language switches that show codes. Colored pill tabs are replaced by tone steps.
대신 없애 주는 AI 티
- Colored outline pill badge (AC-05)
- Tinted pill badge (AC-04)
- Flat gray card with a hairline border, everywhere (AC-14)
- Three pricing tiers with the middle one raised (CMP-09)
- Same large radius and same soft shadow on everything (CMP-04)
- Dark only, no light mode (CMP-11)
- Cream background with a terracotta accent (COL-02)
- Near-black background with a neon glow (COL-03)
- Green as the replacement for banned purple (COL-05)
- Text that does not stand out from its background (COL-08)
- Rainbow of tinted boxes (COL-06)
정보
코드 보기
import * as React from 'react'
import { cn } from './_cn'
// Checkbox and Switch. On state uses the accent token so a theme recolors it.
// API follows shadcn/ui checkbox and switch (MIT). The dashed checkbox (an empty slot waiting to be
// filled, for task lists and setup steps) follows a 21st.dev checkbox the owner picked; it is only a
// dashed border, so no code came with it.
// Upstream license: MIT, Copyright (c) 2023 shadcn. Full text in THIRD_PARTY_NOTICES.md.
const CheckIcon = () => (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={1.75}
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className="h-3 w-3"
>
<path d="M5 13l4 4 10-10" />
</svg>
)
// ── Checkbox ─────────────────────────────────────────────────────────────────
export interface CheckboxProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {
label?: React.ReactNode
/** Unchecked box drawn with a dashed border: an empty slot to fill, as in a checklist. */
dashed?: boolean
}
export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
({ label, dashed, className, id, checked, disabled, ...props }, ref) => {
const reactId = React.useId()
const inputId = id ?? reactId
return (
<label
htmlFor={inputId}
className={cn(
'inline-flex min-h-11 select-none items-center gap-2 text-sm text-text desk:min-h-0',
disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer',
className,
)}
>
<span className="relative inline-flex">
<input
ref={ref}
id={inputId}
type="checkbox"
checked={checked}
disabled={disabled}
className="peer sr-only"
{...props}
/>
<span
className={cn(
'flex h-4 w-4 items-center justify-center rounded-md border border-border-input bg-transparent transition-colors',
dashed && 'border-dashed border-text-subtle peer-checked:border-solid',
'text-transparent peer-checked:border-transparent peer-checked:bg-accent peer-checked:text-accent-fg',
'peer-focus-visible:ring-2 peer-focus-visible:ring-ring',
)}
>
<CheckIcon />
</span>
</span>
{label != null && <span>{label}</span>}
</label>
)
},
)
Checkbox.displayName = 'Checkbox'
// ── Switch ───────────────────────────────────────────────────────────────────
export interface SwitchProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'size'> {
label?: React.ReactNode
}
export const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
({ label, className, id, checked, disabled, ...props }, ref) => {
const reactId = React.useId()
const inputId = id ?? reactId
return (
<label
htmlFor={inputId}
className={cn(
'inline-flex min-h-11 select-none items-center gap-2 text-sm text-text desk:min-h-0',
disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer',
className,
)}
>
<span className="relative inline-flex">
<input
ref={ref}
id={inputId}
type="checkbox"
role="switch"
checked={checked}
disabled={disabled}
className="peer sr-only"
{...props}
/>
<span
className={cn(
'block h-5 w-9 rounded-full border border-border bg-transparent transition-colors',
'peer-checked:border-transparent peer-checked:bg-accent',
'peer-focus-visible:ring-2 peer-focus-visible:ring-ring',
)}
/>
<span
className={cn(
'pointer-events-none absolute left-0.5 top-0.5 h-4 w-4 rounded-full bg-text transition-transform',
'peer-checked:translate-x-4 peer-checked:bg-accent-fg',
)}
/>
</span>
{label != null && <span>{label}</span>}
</label>
)
},
)
Switch.displayName = 'Switch'