Examples
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.
Loading…
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: a week strip that opens into the month, with
markedDatesdots - List, ListItem: the day's events, each with a coloured bar and the time in
leading - BottomSheet: the new event, with the Add button in its
footer - TimePicker: wheels on iOS, a clock in Material and columns on the web, with
minuteInterval - TextField, Button, Text, Patine 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 plainYYYY-MM-DDstrings in local time, nevertoISOString(). - The dots follow the data.
markedDatesis 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.