Skip to content

Commit 57e9219

Browse files
committed
feat(single datepicker): add single datepicker
affects: @datepicker-react/hooks, @datepicker-react/styled
1 parent a2efb15 commit 57e9219

24 files changed

+11144
-1541
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**@datepicker-react/hooks or @datepicker-react/styled version**
11+
e.g. @datepicker-react/hooks@1.0.0
12+
13+
**Describe the bug**
14+
A clear and concise description of what the bug is.
15+
16+
**Source code (including props configuration)**
17+
Steps to reproduce the behavior:
18+
```
19+
<DateRangeInput
20+
onDatesChange={data => dispatch({type: 'dateChange', payload: data})}
21+
onFocusChange={focusedInput => dispatch({type: 'focusChange', payload: focusedInput})}
22+
startDate={state.startDate} // Date or null
23+
endDate={state.endDate} // Date or null
24+
focusedInput={state.focusedInput} // START_DATE, END_DATE or null
25+
/>
26+
```
27+
If you have custom methods that you are passing into a `@datepicker-react` component / hooks, please include the source for those as well.
28+
29+
**Screenshots/Gifs**
30+
If applicable, add screenshots or gifs to help explain your problem.
31+
32+
**Desktop (please complete the following information):**
33+
- OS: [e.g. iOS]
34+
- Browser [e.g. chrome, safari]
35+
- Version [e.g. 22]
36+
37+
**Smartphone (please complete the following information):**
38+
- Device: [e.g. iPhone6]
39+
- OS: [e.g. iOS8.1]
40+
- Browser [e.g. stock browser, safari]
41+
- Version [e.g. 22]
42+
43+
**Is the issue reproducible in Storybook?**
44+
Please link to the relevant storybook example
45+
46+
**Additional context**
47+
Add any other context about the problem here.

CODE_OF_CONDUCT.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers
6+
pledge to making participation in our project and our community a harassment-free experience for
7+
everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity
8+
and expression, level of experience, education, socio-economic status, nationality, personal
9+
appearance, race, religion, or sexual identity and orientation.
10+
11+
## Our Standards
12+
13+
Examples of behavior that contributes to creating a positive environment include:
14+
15+
- Using welcoming and inclusive language
16+
- Being respectful of differing viewpoints and experiences
17+
- Gracefully accepting constructive criticism
18+
- Focusing on what is best for the community
19+
- Showing empathy towards other community members
20+
21+
Examples of unacceptable behavior by participants include:
22+
23+
- The use of sexualized language or imagery and unwelcome sexual attention or advances
24+
- Trolling, insulting/derogatory comments, and personal or political attacks
25+
- Public or private harassment
26+
- Publishing others' private information, such as a physical or electronic address, without explicit
27+
permission
28+
- Other conduct which could reasonably be considered inappropriate in a professional setting
29+
30+
## Our Responsibilities
31+
32+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are
33+
expected to take appropriate and fair corrective action in response to any instances of unacceptable
34+
behavior.
35+
36+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits,
37+
code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or
38+
to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate,
39+
threatening, offensive, or harmful.
40+
41+
## Scope
42+
43+
This Code of Conduct applies both within project spaces and in public spaces when an individual is
44+
representing the project or its community. Examples of representing a project or community include
45+
using an official project e-mail address, posting via an official social media account, or acting as
46+
an appointed representative at an online or offline event. Representation of a project may be
47+
further defined and clarified by project maintainers.
48+
49+
## Enforcement
50+
51+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting
52+
the project team at [sedej.miha@gmail.com](mailto:sedej.miha@gmail.com). All complaints will be
53+
reviewed and investigated and will result in a response that is deemed necessary and appropriate to
54+
the circumstances. The project team is obligated to maintain confidentiality with regard to the
55+
reporter of an incident. Further details of specific enforcement policies may be posted separately.
56+
57+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face
58+
temporary or permanent repercussions as determined by other members of the project's leadership.
59+
60+
## Attribution
61+
62+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at
63+
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
64+
65+
[homepage]: https://www.contributor-covenant.org
66+
67+
For answers to common questions about this code of conduct, see
68+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Contribution Guidelines
2+
3+
Styled System has a [Code of Conduct][]. Please review and help enforce this code of conduct to help
4+
us foster an open and inclusive project.
5+
6+
[code of conduct]: ./CODE_OF_CONDUCT.MD
7+
8+
## How to Contribute
9+
10+
Feel free to contribute by opening and commenting on issues, helping answer questions, updating
11+
docs, or opening a pull request. For quick bug fixes or PRs that address an open issue, feel free to
12+
open a PR. If you'd like to suggest a new feature or change to the API, please open an issue for
13+
discussion first.
14+
15+
## Pull Requests
16+
17+
To submit a pull request, follow these steps
18+
19+
1. Fork and clone this repo
20+
2. Create a branch for your changes
21+
3. Install dependencies with `yarn install && bootstrap`
22+
4. Ensure tests are passing by running `yarn test`
23+
5. If you're fixing a bug, it's recommended to write a failing test before writing any code
24+
6. Make changes locally and commit them
25+
7. Try to make sure tests still pass and that there's 100% coverage
26+
8. Push your branch to origin
27+
9. Open a pull request in this repository with a clear title and description and link to any
28+
relevant issues
29+
10. Wait for a maintainer to review your PR
30+
31+
## Documentation
32+
33+
The documentation is in [README](./README.MD).
34+
35+
## Architecture
36+
37+
@datepicker-react is intentionally divided into two libraries, `@datepicker-react/styled`
38+
(./packages/styled) and `@datepicker-react/hooks` (./packages/hooks). `@datepicker-react/hooks`
39+
library contains hooks, which allows us to control the date picker. The second library
40+
(`@datepicker-react/styled`) contains date picker components.
41+
42+
### Monorepo
43+
44+
This repo is set up as a monorepo using Yarn workspaces and Lerna.

README.md

Lines changed: 112 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
# @datepicker-react/styled
1+
<p align="center">
2+
<img width="150" height="150" src="./docs/logo.jpg">
3+
</p>
24

3-
[![Gzip size](https://img.shields.io/bundlephobia/minzip/@datepicker-react/styled.svg)](https://img.shields.io/bundlephobia/minzip/@datepicker-react/styled.svg) [![Coverage Status](https://coveralls.io/repos/github/tresko/react-datepicker/badge.svg?branch=master)](https://coveralls.io/github/tresko/react-datepicker?branch=master) [![Build Status](https://travis-ci.org/tresko/react-datepicker.svg?branch=master)](https://travis-ci.org/tresko/react-datepicker) [![Netlify Status](https://api.netlify.com/api/v1/badges/0c2c3960-87ee-4f5e-a4dc-1e2aac57d2b4/deploy-status)](https://app.netlify.com/sites/react-datepicker/deploys)
5+
<br />
6+
7+
[![Gzip size](https://img.shields.io/bundlephobia/minzip/@datepicker-react/styled.svg)](https://img.shields.io/bundlephobia/minzip/@datepicker-react/styled.svg)
8+
[![Coverage Status](https://coveralls.io/repos/github/tresko/react-datepicker/badge.svg?branch=master)](https://coveralls.io/github/tresko/react-datepicker?branch=master)
9+
[![Build Status](https://travis-ci.org/tresko/react-datepicker.svg?branch=master)](https://travis-ci.org/tresko/react-datepicker)
10+
[![Netlify Status](https://api.netlify.com/api/v1/badges/0c2c3960-87ee-4f5e-a4dc-1e2aac57d2b4/deploy-status)](https://app.netlify.com/sites/react-datepicker/deploys)
411

512
[![NPM](https://nodei.co/npm/@datepicker-react/styled.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/@datepicker-react/styled?downloads=true&downloadRank=true&stars=true)
613

7-
> An easily internationalizable, accessible, mobile-friendly datepicker library for the web, build with styled-components.
14+
> An easily internationalizable, accessible, mobile-friendly datepicker library for the web, build
15+
> with styled-components.
816
917
![example](./docs/datepicker.gif)
1018

@@ -15,32 +23,36 @@ For examples of the datepicker in action, go to https://react-datepicker.netlify
1523
OR
1624

1725
To run that demo on your own computer:
18-
* Clone this repository
19-
* `yarn install && bootstrap`
20-
* `yarn storybook`
21-
* Visit http://localhost:6006/
2226

27+
- Clone this repository
28+
- `yarn install && bootstrap`
29+
- `yarn storybook`
30+
- Visit http://localhost:6006/
2331

2432
## Getting Started
33+
2534
### Install
2635

27-
```sh
28-
yarn add @datepicker-react/styled styled-components
29-
```
36+
```sh
37+
yarn add @datepicker-react/styled styled-components
38+
```
3039

3140
### Include component
41+
3242
```js
3343
import {DateRangeInput, Datepicker} from '@datepicker-react/styled'
3444
```
3545

3646
### DateRangeInput
37-
The `DateRangeInput` is a fully controlled component that allows users to select a date range. You can control the selected
38-
dates using the `startDate`, `endDate`, and `onDatesChange` props as shown below. The `DateRangeInput` also manages internal
39-
state for partial dates entered by typing (although `onDatesChange` will not trigger until a date has been entered
40-
completely in that case). Similarly, you can control which input is focused as well as calendar visibility (the calendar is
41-
only visible if `focusedInput` is defined) with the `focusedInput` and `onFocusChange` props as shown below.
4247

43-
Here is the minimum *REQUIRED* setup you need to get the `DateRangeInput` working:
48+
The `DateRangeInput` is a fully controlled component that allows users to select a date range. You
49+
can control the selected dates using the `startDate`, `endDate`, and `onDatesChange` props as shown
50+
below. Similarly, you can control which input is focused as well as calendar visibility (the
51+
calendar is only visible if `focusedInput` is defined) with the `focusedInput` and `onFocusChange`
52+
props as shown below.
53+
54+
Here is the minimum _REQUIRED_ setup you need to get the `DateRangeInput` working:
55+
4456
```jsx
4557
import React, {useReducer} from 'react'
4658
import {DateRangeInput} from '@datepicker-react/styled'
@@ -64,7 +76,7 @@ function reducer(state, action) {
6476

6577
function App() {
6678
const [state, dispatch] = useReducer(reducer, initialState)
67-
79+
6880
return (
6981
<DateRangeInput
7082
onDatesChange={data => dispatch({type: 'dateChange', payload: data})}
@@ -77,7 +89,8 @@ function App() {
7789
}
7890
```
7991

80-
The following is a list of other *OPTIONAL* props you may provide to the `DateRangeInput` to customize appearance and behavior to your heart's desire.
92+
The following is a list of other _OPTIONAL_ props you may provide to the `DateRangeInput` to
93+
customize appearance and behavior to your heart's desire.
8194

8295
```ts
8396
displayFormat?: string | FormatFunction // Default: 'MM/DD/YYYY'
@@ -106,12 +119,12 @@ onDayRender?(date: Date): React.ReactNode
106119
```
107120
108121
### Datepicker
109-
The `Datepicker` is a fully controlled component that allows users to select a date range. You can control the selected
110-
dates using the `startDate`, `endDate`, and `onDatesChange` props as shown below. The `Datepicker` also manages internal
111-
state for partial dates entered by typing (although `onDatesChange` will not trigger until a date has been entered
112-
completely in that case). Similarly, you can control which input is focused with the `focusedInput` prop.
113122
114-
Here is the minimum *REQUIRED* setup you need to get the `Datepicker` working:
123+
The `Datepicker` is a fully controlled component that allows users to select a date range. You can
124+
control the selected dates using the `startDate`, `endDate`, and `onDatesChange` props as shown
125+
below. Similarly, you can control which input is focused with the `focusedInput` prop.
126+
127+
Here is the minimum _REQUIRED_ setup you need to get the `Datepicker` working:
115128
116129
```jsx
117130
import React, {useState} from 'react'
@@ -123,15 +136,15 @@ function App() {
123136
endDate: null,
124137
focusedInput: START_DATE,
125138
})
126-
139+
127140
function handleDatesChange(data: OnDatesChangeProps) {
128141
if (!data.focusedInput) {
129142
setState({...data, focusedInput: START_DATE})
130143
} else {
131144
setState(data)
132145
}
133146
}
134-
147+
135148
return (
136149
<Datepicker
137150
onDatesChange={handleDatesChange}
@@ -143,7 +156,8 @@ function App() {
143156
}
144157
```
145158
146-
The following is a list of other *OPTIONAL* props you may provide to the `Datepicker` to customize appearance and behavior to your heart's desire.
159+
The following is a list of other _OPTIONAL_ props you may provide to the `Datepicker` to customize
160+
appearance and behavior to your heart's desire.
147161
148162
```ts
149163
phrases?: DatepickerPhrases
@@ -168,9 +182,78 @@ monthLabelFormat?(date: Date): string
168182
onDayRender?(date: Date): React.ReactNode
169183
```
170184
185+
### DateSingleInput
186+
187+
The `DateSingleInput` is a fully controlled component that allows users to select a date. You can
188+
control the selected date using the `date` and `onDateChange` props as shown below. Similarly, you
189+
can control calendar visibility (the calendar is only visible if `showDatepicker` is `true`) with
190+
the `showDatepicker` and `onFocusChange` props as shown below.
191+
192+
Here is the minimum _REQUIRED_ setup you need to get the `DateSingleInput` working:
193+
194+
```jsx
195+
import React, {useState} from 'react'
196+
import {DateSingleInput} from '@datepicker-react/styled'
197+
198+
const initialState = {
199+
date: null,
200+
showDatepicker: false,
201+
}
202+
203+
function reducer(state, action) {
204+
switch (action.type) {
205+
case 'focusChange':
206+
return {...state, showDatepicker: action.payload}
207+
case 'dateChange':
208+
return action.payload
209+
default:
210+
throw new Error()
211+
}
212+
}
213+
214+
function App() {
215+
const [state, dispatch] = useReducer(reducer, initialState)
216+
217+
return (
218+
<DateSingleInput
219+
onDateChange={data => dispatch({type: 'dateChange', payload: data})}
220+
onFocusChange={focusedInput => dispatch({type: 'focusChange', payload: focusedInput})}
221+
date={state.date} // Date or null
222+
showDatepicker={state.showDatepicker} // Boolean
223+
/>
224+
)
225+
}
226+
```
227+
228+
The following is a list of other _OPTIONAL_ props you may provide to the `DateSingleInput` to customize
229+
appearance and behavior to your heart's desire.
230+
231+
```ts
232+
minBookingDate?: Date
233+
maxBookingDate?: Date
234+
numberOfMonths?: number
235+
firstDayOfWeek?: FirstDayOfWeek
236+
displayFormat?: string | FormatFunction
237+
phrases?: DateSingleInputPhrases
238+
showCalendarIcon?: boolean
239+
vertical?: boolean
240+
showResetDate?: boolean
241+
showClose?: boolean
242+
rtl?: boolean
243+
placement?: 'top' | 'bottom'
244+
initialVisibleMonth?(numberOfMonths: number): MonthType[]
245+
isDateBlocked?(date: Date): boolean
246+
onClose?(): void
247+
dayLabelFormat?(date: Date): string
248+
weekdayLabelFormat?(date: Date): string
249+
monthLabelFormat?(date: Date): string
250+
onDayRender?(date: Date): React.ReactNode
251+
```
252+
171253
### Theming
172254
173-
`@datepicker-react/styled` supports theming with Styled components `ThemeProvider` and `Styled System` theme-based style.
255+
`@datepicker-react/styled` supports theming with Styled components `ThemeProvider` and
256+
`Styled System` theme-based style.
174257
175258
```jsx
176259
<ThemeProvider
@@ -190,7 +273,8 @@ onDayRender?(date: Date): React.ReactNode
190273
191274
## How to build your own datepicker?
192275
193-
Simple. Use [React hooks (@datepicker-react/hooks)](https://github.com/tresko/react-datepicker/tree/master/packages/hooks).
276+
Simple. Use
277+
[React hooks (@datepicker-react/hooks)](https://github.com/tresko/react-datepicker/tree/master/packages/hooks).
194278
195279
## Who's using
196280

docs/datepicker.gif

113 KB
Loading

docs/logo.jpg

4.33 KB
Loading

0 commit comments

Comments
 (0)