Skip to content

Commit 27ffef5

Browse files
committed
doc: add basic doc
1 parent c5c3c06 commit 27ffef5

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

  • packages/react-use-calendar-component

packages/react-use-calendar-component/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,88 @@ This package is still under development, the API interface may change frequently
2020

2121
- [Single Mode](./src/app/components/Examples/Single.tsx)
2222
- [Multiple Mode](./src/app/components/Examples/Multiple.tsx)
23+
24+
## Install
25+
26+
```sh
27+
npm install react-use-calendar-component
28+
```
29+
30+
## API Reference
31+
32+
```ts
33+
import useCalendarComponent from 'react-use-calendar-component';
34+
35+
const {
36+
selectedDates,
37+
displayedYear,
38+
displayedMonth,
39+
changeDisplayedYear,
40+
changeDisplayedMonth,
41+
getDateCellInfos,
42+
} = useCalendarComponent({ initialDisplayedDate, selectType, value, onChange });
43+
```
44+
45+
### Args
46+
47+
#### `initialDisplayedDate`
48+
49+
This value will be used to generate the date cells at beginning. Its default value is `new Date()`.
50+
51+
#### `selectType`
52+
53+
The selection type of the calendar, currently support `'single' | 'multiple'`. Its default value is `'single'`.
54+
55+
> This option must be set if you don't want to use `single` type.
56+
57+
#### `value`
58+
59+
Set it up to get the full control of the calendar. For `'single'` selection type, the type of this value should be `Date`. For `'multiple'` selection type, the type of this value should be `Date[]`.
60+
61+
#### `onChange`
62+
63+
```ts
64+
type OnChange: (value: Date|Date[]) => void
65+
```
66+
67+
For `single` selection type, the `value` is a `Date` instance. For `multiple` selection type, the `value` is an array of `Date` instances.
68+
69+
### Returns
70+
71+
#### `selectedDates`
72+
73+
An array contains the `Date` instances of all selected date.
74+
75+
#### `displayedYear`
76+
77+
The year of the calendar which should be rendered.
78+
79+
#### `displayedMonth`
80+
81+
The month of the calendar which should be rendered.
82+
83+
#### `changeDisplayedYear`
84+
85+
Call this function to add a value to `displayedYear`.
86+
87+
#### `changeDisplayedMonth`
88+
89+
Call this function to add a value to `displayedMonth`.
90+
91+
#### `getDateCellInfos`
92+
93+
```ts
94+
interface DateCellInfo {
95+
key: string;
96+
year: number;
97+
month: number;
98+
dayOfMonth: number;
99+
dayOfWeek: number;
100+
isToday: boolean;
101+
isSelected: boolean;
102+
monthStatus: 'current' | 'next' | 'previous';
103+
selectThisDate: (options?: SelectDateOptions) => void;
104+
}
105+
```
106+
107+
This function returns an array of `DateCellInfo`. It can be used to render your calendar.

0 commit comments

Comments
 (0)