本文へ移動
日本語
「ホップドットフィルター」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

Every item keeps an empty slot in front of its label, so nothing shifts when the choice changes; one dot travels between those slots. Positions are measured only when the choice or the size of the row changes. The flight is two Web Animations on transform: an outer span moves sideways while the inner ball rises with a falling-off speed and drops with a gathering one, so the path is a real arc. Distance sets the arc's height (9 to 26px) and its time, which scales from --ds-duration-base. The ball squashes to 145% × 62% at touchdown against the line, rebounds and rests, and a thin ring spreads from the landing spot. The new label's colour change is delayed to about two thirds of the flight. When the labels are wider than the row, the row scrolls sideways, fades the edge that hides more and brings the chosen item into view.

向いている場面

  • A short set of filters over a list or a gallery: meal types, article topics, product ranges.
  • Editorial pages and landing pages where a filled pill or a heavy tab bar would be too loud.
  • A page header in the large size, next to a big title.

向かない場面

  • Switching between panels of different content: use sliding tabs, which also manage the panels.
  • Choosing several filters at once: use checkboxes or chips.

使い方

import { useState } from 'react'
import { HopDotFilter } from './HopDotFilter.jsx'

const meals = [
  { value: 'all', label: 'All', count: 48 },
  { value: 'breakfast', label: 'Breakfast', count: 12 },
  { value: 'lunch', label: 'Lunch', count: 14 },
  { value: 'dinner', label: 'Dinner', count: 15 },
]

export function RecipeFilter() {
  const [meal, setMeal] = useState('all')
  return <HopDotFilter label="Meal" items={meals} value={meal} onChange={setMeal} />
}

プロパティ

プロパティ型既定値説明
items{ value, label, count?, disabled? }[]—The filters in order. count, when given, sits small after the label.
value / defaultValue / onChangestring / string / (value) => void- / first enabled item / -The chosen filter, controlled or uncontrolled. onChange fires as soon as an item is chosen; the dot is still in the air.
labelstring—Accessible name of the group, such as "Meal".
size'md' | 'lg''md'md is 15px text for a card or toolbar; lg is 22px text for the top of a page.
tone'accent' | 'ink''accent'Colour of the dot and its landing ring. The chosen label is always ink.
...restHTMLAttributes—Other attributes go to the root <div>.

アクセシビリティ

  • The row is a radiogroup named by label; every item is a radio with aria-checked. Only the chosen item is in the tab order.
  • Left and Up choose the previous item, Right and Down the next, Home and End the ends, wrapping round; focus follows and shows a ring.
  • The chosen item is ink and the others grey, so the choice does not depend on the colour of the dot; the dot and its ring are hidden from assistive tech.
  • Reduced motion moves the dot straight to the new label and changes the colours at once.
  • Touch: every item is a full-height button, and a long row scrolls sideways with the finger.

モーション

Flight: about 1 to 2.2 × --ds-duration-base depending on distance; sideways on cubic-bezier(0.45, 0.05, 0.35, 1), up on an ease-out and down on an ease-in. Landing: squash, rebound and rest over 0.85 × --ds-duration-base; the ring grows from 0.4 to 2.6 × and fades. Label colour: --ds-duration-base, the new one delayed to about 62% of the flight.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

HopDotFilter.jsxhop-dot-filter.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

ナビゲーション