|
1 | 1 | # Calendar |
2 | 2 |
|
3 | | -`Calendar` component provides a way to select a date or a range of dates while |
4 | | -allowing you to style them however. All the date, month & year calculations are |
5 | | -done internally to provide the ease of use. It follows the |
6 | | -[Grid Pattern](https://www.w3.org/TR/wai-aria-practices-1.2/#grid) for the |
7 | | -keyboard navigaiton & focus management. |
| 3 | +`Calendar` component provides a way to select a date while allowing you to style |
| 4 | +them however. All the date, month & year calculations are done internally using |
| 5 | +[@internationalized/date](https://react-spectrum.adobe.com/internationalized/date/index.html) |
| 6 | +to provide the ease of use. It follows the |
| 7 | +[Grid Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/grid/) for the keyboard |
| 8 | +navigaiton & focus management. Supports all the features as React Aria's |
| 9 | +[useCalendar](https://react-spectrum.adobe.com/react-aria/useCalendar.html#features). |
8 | 10 |
|
9 | | -<!-- INJECT_TOC --> |
| 11 | +<!-- ADD_TOC --> |
10 | 12 |
|
11 | 13 | ## Usage |
12 | 14 |
|
13 | | -### Base Calendar |
14 | | - |
15 | | -<!-- IMPORT_EXAMPLE src/calendar/stories/templates/CalendarBasicJsx.ts --> |
16 | | - |
17 | | -### Range Calendar |
18 | | - |
19 | | -Converting a normal calendar to a range calendar is as easy as just swaping out |
20 | | -the hook to range calendar hook. |
21 | | - |
22 | | -You'll need to import the `useRangeCalendarState` hook from the `@adaptui/react` |
23 | | -first |
24 | | - |
25 | | -```diff |
26 | | -- const state = useCalendarState(props); |
27 | | -+ const state = useRangeCalendarState(props); |
28 | | -``` |
29 | | - |
30 | | -Also we can customize and style the ranges with CSS attribute selectors |
31 | | - |
32 | | -```css |
33 | | -[data-is-range-selection] > span { |
34 | | - /* styles for any cells between start-end (inclusive) */ |
35 | | -} |
36 | | -[data-is-selection-start] > span { |
37 | | - /* styles for first selected range cell */ |
38 | | -} |
39 | | -[data-is-selection-end] > span { |
40 | | - /* styles for end selected range cell */ |
41 | | -} |
42 | | - |
43 | | -/* only applied if cell date is first or last of the month*/ |
44 | | -[data-is-range-start] > span { |
45 | | - /**/ |
46 | | -} |
47 | | -[data-is-range-end] > span { |
48 | | - /**/ |
49 | | -} |
50 | | -``` |
| 15 | +<!-- ADD_EXAMPLE src/calendar/stories/templates/CalendarBasicJsx.ts --> |
51 | 16 |
|
52 | 17 | <!-- CODESANDBOX |
53 | 18 | link_title: Calendar |
54 | 19 | js: src/calendar/stories/templates/CalendarBasicJsx.ts |
55 | 20 | css: src/calendar/stories/templates/CalendarBasicCss.ts |
56 | | -utils: src/calendar/stories/templates/UtilsJsx.ts |
| 21 | +files: [src/calendar/stories/templates/UtilsJsx.ts] |
57 | 22 | --> |
| 23 | +<!-- CODESANDBOX |
| 24 | +link_title: Calendar TS |
| 25 | +tsx: src/calendar/stories/templates/CalendarBasicTsx.ts |
| 26 | +css: src/calendar/stories/templates/CalendarBasicCss.ts |
| 27 | +files: [src/calendar/stories/templates/UtilsTsx.ts] |
| 28 | +--> |
| 29 | + |
| 30 | +## Other Examples |
58 | 31 |
|
59 | 32 | <!-- CODESANDBOX |
60 | | -link_title: Range Calendar |
61 | | -js: src/calendar/stories/templates/CalendarRangeJsx.ts |
62 | | -css: src/calendar/stories/templates/CalendarRangeCss.ts |
63 | | -utils: src/calendar/stories/templates/UtilsJsx.ts |
| 33 | +link_title: Calendar Styled |
| 34 | +js: src/calendar/stories/templates/CalendarStyledJsx.ts |
| 35 | +css: src/calendar/stories/templates/CalendarBasicCss.ts |
| 36 | +files: [src/calendar/stories/templates/UtilsJsx.ts] |
| 37 | +--> |
| 38 | +<!-- CODESANDBOX |
| 39 | +link_title: Calendar Styled TS |
| 40 | +tsx: src/calendar/stories/templates/CalendarStyledTsx.ts |
| 41 | +css: src/calendar/stories/templates/CalendarBasicCss.ts |
| 42 | +files: [src/calendar/stories/templates/UtilsTsx.ts] |
64 | 43 | --> |
65 | 44 |
|
66 | | -<!-- INJECT_COMPOSITION src/calendar --> |
| 45 | +<!-- ADD_COMPOSITION src/calendar --> |
67 | 46 |
|
68 | | -<!-- INJECT_PROPS src/calendar --> |
| 47 | +<!-- ADD_PROPS src/calendar --> |
0 commit comments