apps/mantine.dev/src/pages/dates/time-grid.mdx
import { TimeGridDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.TimeGrid);
Use the TimeGrid component to capture a time value from the user with a
predefined set of time slots:
import { useState } from 'react';
import { TimeGrid } from '@mantine/dates';
function Demo() {
const [value, setValue] = useState<string | null>('10:00');
return <TimeGrid value={value} onChange={setValue} data={['10:00', '12: 00']} />;
}
The data prop accepts an array of time values in 24-hour format. Values
must be unique. To generate a time range, use the getTimeRange function
exported from the @mantine/dates package:
import { TimeGrid, getTimeRange } from '@mantine/dates';
function WithArray() {
return <TimeGrid data={['10:00', '12:00']} />
}
function WithRange() {
// In this example we generate time range from 10:00 to 14:00 with 1 hour step:
// ['10:00', '11:00', '12:00', '13:00', '14:00']
return <TimeGrid data={getTimeRange({ from: '10:00', to: '14:00', step: '01:00' })} />
}
Set the minTime and maxTime props to limit the available time range.
Both props accept time values in 24-hour format:
You can disable specific time values by providing an array of disabled
values to the disableTime prop:
Set the allowDeselect prop to allow deselecting the time value by clicking on
the control with the selected value:
Set the disabled prop to disable all controls: