Skip to content

Commit ec2a4bc

Browse files
Add examples
1 parent 106af7c commit ec2a4bc

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,86 @@ Demo: (https://twitter.com/RichardLindhout/status/1294636692540985344)
99

1010
## Usage
1111

12-
import from '...'
12+
### Single date
13+
14+
```tsx
15+
import * as React from 'react'
16+
import { Button } from 'react-native-paper'
17+
import { DatePickerModal } from 'react-native-paper-dates'
18+
19+
function SingleDatePage() {
20+
const [visible, setVisible] = React.useState(false)
21+
const onDismiss = React.useCallback(() => {
22+
setVisible(false)
23+
}, [setVisible])
24+
25+
const onChange = React.useCallback(({ date }) => {
26+
setVisible(false)
27+
console.log({ date })
28+
}, [])
29+
30+
const date = new Date()
31+
32+
return (
33+
<>
34+
<DatePickerModal
35+
mode="single"
36+
visible={visible}
37+
onDismiss={onDismiss}
38+
date={date}
39+
onConfirm={onChange}
40+
saveLabel={'Save'} // optional
41+
label={'Select period'} // optional
42+
/>
43+
<Button onPress={()=> setVisible(true)}>
44+
Pick date
45+
</Button>
46+
</>
47+
)
48+
}
49+
```
50+
51+
### Start / end
52+
```tsx
53+
import * as React from 'react'
54+
import { Button } from 'react-native-paper'
55+
import { DatePickerModal } from 'react-native-paper-dates'
56+
57+
export default function RangeDatePage() {
58+
const [visible, setVisible] = React.useState(false)
59+
const onDismiss = React.useCallback(() => {
60+
setVisible(false)
61+
}, [setVisible])
62+
63+
const onChange = React.useCallback(({ date }) => {
64+
setVisible(false)
65+
console.log({ date })
66+
}, [])
67+
68+
69+
return (
70+
<>
71+
<DatePickerModal
72+
mode="range"
73+
visible={visible}
74+
onDismiss={onDismiss}
75+
startDate={undefined}
76+
endDate={undefined}
77+
onConfirm={onChange}
78+
saveLabel={'Save'} // optional
79+
label={'Select period'} // optional
80+
startLabel={'From'} // optional
81+
endLabel={'To'} // optional
82+
/>
83+
<Button onPress={()=> setVisible(true)}>
84+
Pick range
85+
</Button>
86+
</>
87+
)
88+
}
89+
```
90+
91+
1392

1493
## Roadmap
1594

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-paper-dates",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Performant Date Picker for React Native Paper",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)