Skip to content

Commit

Permalink
Merge branch 'main' into F36-805-text-input-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cf-remylenoir authored Oct 20, 2023
2 parents 22dffb6 + 3b0414f commit 8b32755
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
22 changes: 20 additions & 2 deletions packages/components/datepicker/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,35 @@ You can use Datepicker with the [FormControl](/components/form-control) in order

```

### Limiting the date range

Use the `fromDate` and `toDate` properties to limit the available date range.

```jsx file=./examples/Datepicker/WithMinMaxDate.tsx

```

### Multiple months

If you need to show more than a month at once, use the `numberOfMonths` property.

```jsx file=./examples/Datepicker/WithMultipleMonths.tsx

```

### Open by default

Open the dropdown and display the Calendar by default without user interaction
Use the `defaultIsOpen` property to open the dropdown and display the Calendar by default without user interaction.

**Note**: the Calendar closes by pressing the escape key or by clicking outside of the Datepicker.

```jsx file=./examples/Datepicker/DefaultOpen.tsx

```

### Custom

If you need a custom solution, you can build it by leveraging our lower-level components, such as Calendar, Popover, and TextInput.
If you need a custom solution, you can build it by leveraging our lower-level components, such as [Calendar](/components/calendar), [Popover](/components/popover), and [TextInput](/components/text-input).
For example, Datepicker that uses text input as a trigger without a button.

```jsx file=./examples/Datepicker/Custom.tsx
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Datepicker } from '@contentful/f36-components';

export default function BasicExample() {
export default function DefaultOpenExample() {
const [selectedDay, setSelectedDay] = useState(new Date());

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { Datepicker } from '@contentful/f36-components';
import { FormControl } from '@contentful/f36-forms';

export default function BasicExample() {
export default function WithFormControlExample() {
const [selectedDay, setSelectedDay] = useState(new Date());

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState } from 'react';
import { Datepicker } from '@contentful/f36-components';

export default function WithMinMaxDateExample() {
const [selectedDay, setSelectedDay] = useState(new Date());
const fromDate = new Date();
const twoYearsFromNow = new Date(
new Date(fromDate).setFullYear(fromDate.getFullYear() + 2),
);

return (
<Datepicker
selected={selectedDay}
onSelect={setSelectedDay}
fromDate={fromDate}
toDate={twoYearsFromNow}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { useState } from 'react';
import { Datepicker } from '@contentful/f36-components';

export default function WithMultipleMonthsExample() {
const [selectedDay, setSelectedDay] = useState(new Date());

return (
<Datepicker
selected={selectedDay}
onSelect={setSelectedDay}
numberOfMonths={2}
/>
);
}
12 changes: 12 additions & 0 deletions packages/components/datepicker/stories/Datepicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ const testDate = new Date('2022-04-15');

export default {
component: Datepicker,
args: {
weekStartsOn: 1,
},
argTypes: {
weekStartsOn: {
control: {
type: 'number',
min: 0,
max: 6,
},
},
},
parameters: {
chromatic: { delay: 1000 },
},
Expand Down

0 comments on commit 8b32755

Please sign in to comment.