Debian Codegraph @

node/@patternfly/react-core/src/components/CalendarMonth/examples/CalendarMonthSelectableDate.tsx

raw
1 import { useState } from 'react';
2 import { CalendarMonth, Title, CalendarMonthInlineProps } from '@patternfly/react-core';
3
4 export const CalendarMonthSelectableDate: React.FunctionComponent = () => {
5 const [date, setDate] = useState(new Date(2020, 10, 24));
6
7 const onMonthChange = (
8 _event: React.MouseEvent | React.ChangeEvent | React.FormEvent<HTMLInputElement> | undefined,
9 newDate: Date
10 ) => {
11 // eslint-disable-next-line no-console
12 console.log(`updated month: ${newDate.getMonth()}, updated year: ${newDate.getFullYear()}`);
13 };
14
15 const inlineProps: CalendarMonthInlineProps = {
16 component: 'article',
17 title: (
18 <Title headingLevel="h4" id="favorite-date">
19 Select your favorite date
20 </Title>
21 ),
22 ariaLabelledby: 'favorite-date'
23 };
24
25 return (
26 <>
27 <CalendarMonth
28 date={date}
29 onChange={(_event: React.MouseEvent<HTMLButtonElement, MouseEvent>, date: Date) => setDate(date)}
30 onMonthChange={onMonthChange}
31 inlineProps={inlineProps}
32 />
33 <pre>Selected date: {date.toString()}</pre>
34 </>
35 );
36 };