仕組み
A time ruler in a soft panel: hour labels, a tick every step and dashed hour lines behind a lane. The block is a rounded gradient fill translated inside a rounded clip that starts at the start time, so its end stays round while it grows; the handle sits on the end, placed in container query units so it needs no measuring. Pressing anywhere on the lane moves the end there, dragging follows the pointer with transitions switched off, and the handle is a real slider for the keyboard.
向いている場面
- Showing one booked slot on today's timeline: a meeting, a focus block, a class, a delivery window.
- Letting people extend or shorten a booking in place, in fixed steps.
- A dashboard tile where the duration is the headline number.
向かない場面
- Several overlapping events: use a day calendar or schedule view.
- Picking both start and end from scratch: use a time range picker with inputs.
- Ranges longer than a day.
使い方
import { useState } from 'react'
import { TimeBlock } from './TimeBlock.jsx'
export function ReviewSlot() {
const [end, setEnd] = useState(12 * 60) // minutes from midnight
return (
<TimeBlock
title="Design review"
subtitle="Today"
onOpen={() => {}}
start={10 * 60 + 30}
end={end}
onChange={setEnd}
from={9 * 60}
to={13 * 60}
color={[3, 7]}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
start | number | 600 | Start time in minutes from midnight (630 is 10:30). Changing it replays the entrance. |
end / defaultEnd / onChange | number / number / (end: number) => void | — | End time in minutes. Pass end and onChange to control it, or defaultEnd to let the card keep it. Changes from outside slide the block; drags follow the pointer. |
from / to | number | — | Ruler range in minutes. By default from the hour before the start to at least four hours later. |
step / minDuration | number | 15 / step | Snap step in minutes, also the tick spacing and the arrow-key step; the shortest allowed block. |
editable | boolean | true | Lets people drag the end handle or press on the ruler. false shows the block read-only. |
title / subtitle / icon | ReactNode | — | Card header: a tinted icon tile, a 15px title and a quieter subtitle after it. |
onOpen / action | () => void / ReactNode | — | onOpen adds a chevron button at the end of the header. action replaces it with any node. |
caption | string | (start: string, end: string) => string | — | Line above the duration. By default the formatted range, such as 10:30 – 12:00. |
color | number | string | [number | string, number | string] | [3, 7] | Block gradient. A pair blends the first colour into the second; one colour runs from its tint to itself. Numbers 1–8 pick --ds-chart-N. |
formatTime / formatTick / formatDuration | (minutes: number) => string | '10:30' / formatTime / '1h 30m' | Formats for times (caption, tooltip), hour labels on the ruler and the duration. Digits in the duration show at hero size and words at unit size, in any language. |
labels | object | — | Replaces built-in text: open, handle (the slider name), range(start, end), value(end, duration) for the slider value text. |
replayKey | string | number | — | Change it to play the entrance again. |
className / style / ...rest | HTMLAttributes | — | Passed to the card root, which fills its container width. |
アクセシビリティ
- The handle is a slider with a name, min, max and a value text such as "12:00 PM, 1h 30m".
- Left and Down shorten by one step, Right and Up lengthen, Page Up and Page Down move an hour, Home and End jump to the shortest and the latest end.
- Keyboard focus shows a ring on the grip and the end-time tooltip; pointer focus does not.
- The caption and duration are real text; the ruler and block are hidden from screen readers.
- With editable false the slider is removed and the block is read-only. Reduced motion shows the final block at once and the duration does not count.
モーション
Entrance waits until 30% of the card is visible. Ticks rise 14ms apart and hour labels fade 50ms apart; from 160ms the block grows from its start over 900ms on cubic-bezier(0.22, 1, 0.36, 1) while the handle rides its end and the duration counts up. Changes of end from outside slide over 900ms; dragging has no transition. The tooltip fades and lifts in 160ms.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
TimeBlock.jsxtime-block.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



