# Day schedule with an expandable calendar

> A React Native day planner for iOS, Android and the web: a week strip with dots on busy days that expands into a month, the selected day's events in a list, and a new event added from a bottom sheet with a time picker. One file, built with Patine's ExpandableCalendar, List, ListItem, BottomSheet and TimePicker.

# Day schedule

A calendar app's day view: a week strip with a dot under every busy day (pull it, or tap the month, to see the whole month), that day's events in time order, and **Add** to put a new one in at the time you pick on the wheels.

```tsx live device
import { useMemo, useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import {
  addDays,
  BottomSheet,
  Button,
  ExpandableCalendar,
  formatDate,
  List,
  ListItem,
  Text,
  TextField,
  TimePicker,
  toDateKey,
  useTheme,
} from 'patine-ui';
import { Icon } from '@patine-ui/icons';

type Event = { id: number; day: string; at: Date; title: string; where?: string; color: string };

const at = (day: Date, hours: number, minutes = 0) => {
  const time = new Date(day);
  time.setHours(hours, minutes, 0, 0);
  return time;
};
const clock = (time: Date) => formatDate(time, undefined, { hour: 'numeric', minute: '2-digit' });

const firstEvents = (today: Date): Event[] =>
  [
    { offset: 0, h: 8, m: 30, title: 'School run', color: '#F76B15' },
    { offset: 0, h: 10, m: 0, title: 'Design review', where: 'Room 3 · Marvila office', color: '#3E63DD' },
    { offset: 0, h: 13, m: 0, title: 'Lunch with Noa', where: 'Prado, Rua das Pedras Negras', color: '#30A46C' },
    { offset: 0, h: 18, m: 30, title: 'Climbing', where: 'Lisbon Climbing Wall', color: '#8E4EC6' },
    { offset: 1, h: 9, m: 0, title: 'Dentist', where: 'Clínica Sorriso', color: '#E5484D' },
    { offset: 2, h: 19, m: 0, title: 'Fado night', where: 'Tasca do Chico', color: '#8E4EC6' },
    { offset: 4, h: 11, m: 0, title: 'Flat viewing', where: 'Rua da Rosa 118', color: '#3E63DD' },
  ].map((e, id) => {
    const day = addDays(today, e.offset);
    return { id, day: toDateKey(day), at: at(day, e.h, e.m), title: e.title, where: e.where, color: e.color };
  });

export default function DaySchedule() {
  const { colors } = useTheme();
  const today = useMemo(() => new Date(), []);
  const [day, setDay] = useState(today);
  const [events, setEvents] = useState(() => firstEvents(today));
  const [adding, setAdding] = useState(false);
  const [title, setTitle] = useState('');
  const [time, setTime] = useState(() => at(today, 15));

  const marks = useMemo(
    () => Object.fromEntries(events.map((e) => [e.day, { dots: [e.color] }])),
    [events]
  );
  const shown = events.filter((e) => e.day === toDateKey(day)).sort((a, b) => +a.at - +b.at);

  const add = () => {
    setEvents((all) => [...all, { id: Date.now(), day: toDateKey(day), at: at(day, time.getHours(), time.getMinutes()), title: title.trim() || 'New event', color: colors.primary }]);
    setTitle('');
    setAdding(false);
  };

  return (
    <View style={[styles.screen, { backgroundColor: colors.background }]}>
      <ExpandableCalendar value={day} onValueChange={setDay} markedDates={marks} />
      <ScrollView contentContainerStyle={styles.content}>
        <View style={styles.dayRow}>
          <Text weight="semibold" size="lg">
            {formatDate(day, undefined, { weekday: 'long', day: 'numeric', month: 'long' })}
          </Text>
          <Button size="sm" variant="secondary" startIcon={<Icon name="plus" size="sm" color="text" />} onPress={() => setAdding(true)}>
            Add
          </Button>
        </View>
        {shown.length ? (
          <List>
            {shown.map((e) => (
              <ListItem
                key={e.id}
                title={e.title}
                description={e.where}
                leading={
                  <View style={styles.time}>
                    <View style={[styles.bar, { backgroundColor: e.color }]} />
                    <Text size="sm" weight="medium">
                      {clock(e.at)}
                    </Text>
                  </View>
                }
                showChevron={false}
              />
            ))}
          </List>
        ) : (
          <Text color="textSecondary" style={styles.free}>
            Nothing planned. A free day.
          </Text>
        )}
      </ScrollView>

      <BottomSheet
        open={adding}
        onOpenChange={setAdding}
        title="New event"
        footer={
          <Button size="lg" onPress={add}>
            Add at {clock(time)}
          </Button>
        }
      >
        <View style={styles.sheet}>
          <TextField label="Title" placeholder="Coffee with Rafael" value={title} onValueChange={setTitle} />
          <Text weight="medium">Starts</Text>
          <TimePicker value={time} onValueChange={setTime} minuteInterval={15} />
        </View>
      </BottomSheet>
    </View>
  );
}

const styles = StyleSheet.create({
  screen: { flex: 1 },
  content: { gap: 12, paddingVertical: 16 },
  dayRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16 },
  time: { flexDirection: 'row', alignItems: 'center', gap: 10, width: 84 },
  bar: { width: 4, height: 32, borderRadius: 2 },
  free: { textAlign: 'center', paddingVertical: 32 },
  sheet: { gap: 12, paddingHorizontal: 16, paddingBottom: 8 },
});
```

## Components used

- [ExpandableCalendar](/docs/components/expandable-calendar): a [week strip](/docs/components/week-strip) that opens into the month, with `markedDates` dots
- [List, ListItem](/docs/components/list): the day's events, each with a coloured bar and the time in `leading`
- [BottomSheet](/docs/components/bottom-sheet): the new event, with the Add button in its `footer`
- [TimePicker](/docs/components/time-picker): wheels on iOS, a clock in Material and columns on the web, with `minuteInterval`
- [TextField](/docs/components/text-field), [Button](/docs/components/button), [Text](/docs/components/text), [Patine Icons](/docs/components/icons)

## How it works

- **Days are keys.** Each event stores its day as `toDateKey(date)`, so the calendar's dots and the list's filter compare plain `YYYY-MM-DD` strings in local time, never `toISOString()`.
- **The dots follow the data.** `markedDates` is built from the events, so a new event puts a dot under its day at once.
- **A picker in a sheet.** The time sits inline in the sheet rather than in a field, so adding an event is one sheet, not two.
