Cómo funciona
Seven equal day cells on a grid, each with the weekday, the date and up to three dots. The ink pill is one element under the cells moved with transform: translateX(index × (cell + gap)) and a light overshoot, and the chosen day's text turns to the surface colour as it arrives. Changing day or week is derived during render, so the very first frame already holds the old page beside the new one: the week rows slide by their own width, the agenda pages by 32px with a fade, and the month name rises in. A touch swipe drags the row with resistance (the translate property, separate from the slide) and turns the week past 44px. Dates are 'YYYY-MM-DD' strings handled as UTC midnights, so daylight saving never moves a day.
Úsalo para
- Picking a day close to today: bills, bookings, classes, deliveries, shifts.
- A day view in a mobile app where the week is the natural unit and the details sit right below.
- Showing at a glance which days have something on them.
Busca otra opción cuando
- Picking a date far away or a range: use a date picker or date range picker.
- Dense schedules with many items per day: use a full calendar or a time grid.
Uso
import { useState } from 'react'
import { WeekStrip } from './WeekStrip.jsx'
const events = {
'2026-11-26': [{ id: 'b1', title: 'Car insurance', detail: '$86.10', tone: 2 }],
'2026-11-28': [{ id: 'b2', title: 'Internet', detail: '$49.00', tone: 7 }],
}
export function BillsWeek() {
const [day, setDay] = useState('2026-11-26')
return (
<WeekStrip
value={day}
onChange={setDay}
events={events}
weekStartsOn={1}
locale="en-US"
label="Bills by day"
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
value / defaultValue / onChange | string | Date / string | Date / (iso) => void | - / today / - | The chosen day, controlled or uncontrolled, as 'YYYY-MM-DD' (a Date is accepted). onChange receives the new day as 'YYYY-MM-DD'. |
events | { [iso]: { id?, title, detail?, tone?, color? }[] } | — | What is on each day. Up to three dots show per day, coloured by tone (chart colour 1–8) or color; the default agenda lists title and detail. |
renderAgenda | (iso, events) => ReactNode | null | — | Draws the agenda for the chosen day. It slides in from the side you moved toward. Pass null to show the strip alone. |
today | string | Date | the current day | The day marked as today (accent number, aria-current="date"). |
weekStartsOn | 0 | 1 | 1 | 0 starts weeks on Sunday, 1 on Monday. |
locale / weekdayFormat | string / 'narrow' | 'short' | 'long' | 'en' / 'short' | Language of the month and weekday names (Intl), and how long the weekday name is. |
showHeader / showDots | boolean / boolean | true / true | Show the month with previous and next week buttons; show the dots. |
label | string | 'Week' | Accessible name of the row of days (the tab list). |
labels | object | — | Replaces built-in text: previous, next, empty, day(date, count). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accesibilidad
- The days are a tablist of tab buttons with aria-selected and a roving tabindex; the agenda is the tabpanel labelled by the chosen day.
- Left and Right move one day (crossing into the next week), Home and End go to the ends of the week, PageUp and PageDown turn the week; focus follows the selection.
- Each day is named in full with its item count, for example “Thursday, November 26, 2 items”; today has aria-current="date".
- The previous and next week buttons are 32px (40px on touch screens) and named through labels; the month name is announced politely when it changes.
- The leaving page is aria-hidden and inert, so it is never read or focused.
- Reduced motion swaps days and weeks at once and the pill jumps.
Movimiento
Pill: transform 420ms cubic-bezier(0.3, 1.25, 0.5, 1); the chosen day's text inverts over 240ms after 60ms. Week: both rows slide by their width plus 16px over 360ms ease-out. Agenda: the old page fades 20px the other way in 160ms, and the new one follows 70ms later, entering from 32px with a fade over 360ms. Swipe: the row follows the finger at 45% up to 72px and eases back in 240ms.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
WeekStrip.jsxweek-strip.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.