# React Native Week Strip

> React Native week strip date picker: one week of days under its month, swipe or arrows to change weeks, marked dates with dots, min/max and disabled days. For bookings, schedules and fitness apps. iOS, Material and web designs, zero native code.

# WeekStrip

`WeekStrip` is one week of days in a row, the compact date picker at the top of booking, schedule, habit and fitness screens. Tap a day to pick it; swipe or use the arrows for the next or previous week. The month and year most of the week falls in sit above it.

It's the [`Calendar`](./date-picker)'s day cells in a single week, so it follows the [design](../guides/designs) the same way and takes the same `markedDates`, `minDate`, `maxDate`, `isDateDisabled`, `renderDay` and styles.

```tsx
import { WeekStrip } from 'patine-ui';
```

```tsx live
import { useState } from 'react';
import { Text } from 'react-native';
import { WeekStrip } from 'patine-ui';

export default function Example() {
  const [day, setDay] = useState(new Date());
  return (
    <>
      <WeekStrip value={day} onValueChange={setDay} />
      <Text style={{ textAlign: 'center', color: '#6E685E' }}>{day.toDateString()}</Text>
    </>
  );
}
```

## Example: a habit tracker

A habit app's week: each day you did it gets a dot, the strip can't go past today, and the button marks or unmarks the day you're looking at.

```tsx live
import { useState } from 'react';
import { Box, Button, HStack, Text, VStack, WeekStrip, addDays, toDateKey } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const today = new Date();
const START = [1, 2, 4, 5, 8].map((n) => toDateKey(addDays(today, -n)));

export default function Example() {
  const [day, setDay] = useState(today);
  const [done, setDone] = useState<string[]>(START);
  const key = toDateKey(day);
  const marked = Object.fromEntries(done.map((k) => [k, { dots: ['#16A34A'] }]));
  const from = done.includes(toDateKey(today)) ? 0 : 1;
  let streak = 0;
  while (done.includes(toDateKey(addDays(today, -(from + streak))))) streak++;
  return (
    <Box border radius="lg" padding="md" gap="md" style={{ width: '100%', maxWidth: 420 }}>
      <HStack justify="space-between">
        <VStack>
          <Text weight="semibold">Read 20 pages</Text>
          <Text size="sm" color="textSecondary">{streak}-day streak</Text>
        </VStack>
      </HStack>
      <WeekStrip value={day} onValueChange={setDay} markedDates={marked} maxDate={today} />
      <Button
        variant={done.includes(key) ? 'outline' : 'default'}
        startIcon={done.includes(key) ? <Icon name="check" size="sm" color="success" /> : undefined}
        onPress={() => setDone((d) => (d.includes(key) ? d.filter((k) => k !== key) : [...d, key]))}
      >
        {done.includes(key) ? 'Done · tap to undo' : `Mark ${key === toDateKey(today) ? 'today' : day.toLocaleDateString(undefined, { weekday: 'long' })} done`}
      </Button>
    </Box>
  );
}
```

## Marked and disabled days

`markedDates` adds dots, a label or a disabled flag to days, keyed by `YYYY-MM-DD` ([`toDateKey`](../api/date-utils#todatekey)), as on the calendar. `minDate`, `maxDate` and `isDateDisabled` disable days, and the arrows stop at the weeks holding `minDate` and `maxDate`.

```tsx live
import { useState } from 'react';
import { WeekStrip, addDays, toDateKey } from 'patine-ui';

const today = new Date();
const CLASSES = {
  [toDateKey(today)]: { dots: ['#E4572E'] },
  [toDateKey(addDays(today, 2))]: { dots: ['#E4572E', '#2E86AB'] },
  [toDateKey(addDays(today, 4))]: { dots: ['#2E86AB'] },
};

export default function Schedule() {
  const [day, setDay] = useState(today);
  return (
    <WeekStrip
      value={day}
      onValueChange={setDay}
      markedDates={CLASSES}
      minDate={today}
      isDateDisabled={(date) => date.getDay() === 0}
    />
  );
}
```

## Weeks

The first day of the week comes from `locale` (Sunday in the US, Monday in most of Europe), or set `firstDayOfWeek`: `0` for Sunday to `6` for Saturday. The strip opens on the week of `initialWeek`, else of `value`, else of today, and moves to a new `value`'s week when you set one from outside.

`onWeekChange` fires with the first day of the week after an arrow or a swipe, to load that week's data:

```tsx
<WeekStrip value={day} onValueChange={setDay} markedDates={marks} onWeekChange={(start) => loadWeek(start)} />
```

`showHeader={false}` hides the title and arrows, leaving the days and the swipe. `formatTitle(weekStart, locale)` changes the title.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `Date \| null` | — | Selected day (controlled). |
| `defaultValue` | `Date \| null` | — | Initial day when uncontrolled. |
| `onValueChange` | `(date: Date) => void` | — | Fires when a day is tapped. |
| `initialWeek` | `Date` | the selected day or today | A day in the week shown first. |
| `onWeekChange` | `(weekStart: Date) => void` | — | Fires with the first day of the week after paging. |
| `firstDayOfWeek` | `number` (0–6) | from `locale`, else `0` | 0 = Sunday … 6 = Saturday. |
| `locale` | `string` | device | Weekday and month names. |
| `minDate` / `maxDate` | `Date` | — | Days outside are disabled, and paging stops at their weeks. |
| `isDateDisabled` | `(date: Date) => boolean` | — | Disable a day. |
| `markedDates` | `Record<string, MarkedDate>` | — | Dots, labels or disabled days, keyed by `YYYY-MM-DD`. |
| `showHeader` | `boolean` | `true` | Show the month title and the week arrows. |
| `formatTitle` | `(weekStart: Date, locale?: string) => string` | the month of the week's middle day | Title text. |
| `showWeekdays` | `boolean` | `true` | Show the weekday names. |
| `weekdayFormat` | `'short' \| 'narrow'` | from the design: `'narrow'` in Material, else `'short'` | Weekday names: `Mon` or `M`. |
| `enableSwipe` | `boolean` | `true` | Swipe left or right to change weeks. |
| `renderDay` | `(state: DayState, theme: Theme) => ReactNode` | — | Fully custom day cell, as on the [calendar](./date-picker#custom-days-and-arrows). |
| `renderArrow` | `(direction: 'prev' \| 'next', disabled: boolean) => ReactNode` | — | Custom arrows. |
| `dayHeight` | `number` | `44` | Day cell height. |
| `style` | `StyleProp<ViewStyle>` | — | Container style. |
| `styles` | `SlotStyles<CalendarSlot>` | — | The [calendar slots](./date-picker#slots). |
| `theme` | `DeepPartial<Theme>` | — | Theme override. |
| `design` | `'brand' \| 'ios' \| 'material' \| 'web' \| 'native'` | from `PatineProvider` | The look to follow, over the provider's: [brand, iOS, Material or web](../guides/designs), or `'native'` for the platform's own. |
| `testID` | `string` | — | Test ID. |

## Related

- [ExpandableCalendar](./expandable-calendar): this week, opening into its month
- [DatePicker](./date-picker): a whole month
- [MonthPicker](./month-picker): a month and year
