-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from hernansartorio/time-picking
Add basic time-picking support
- Loading branch information
Showing
10 changed files
with
184 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { setTime } from '../src/utils' | ||
|
||
describe('setTime', () => { | ||
test('should return first date with the time of the second date', () => { | ||
const dateWithNoTime = new Date(2021, 2, 13) | ||
const dateWithTime = new Date(2020, 1, 24, 18, 30) | ||
|
||
expect(setTime(dateWithNoTime, dateWithTime)).toEqual(new Date(2021, 2, 13, 18, 30)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useState } from 'react' | ||
import { enGB } from 'date-fns/locale' | ||
import { DatePicker } from '../../src' | ||
import Example from './Example' | ||
|
||
const code = ` | ||
import React, { useState } from 'react' | ||
import { enGB } from 'date-fns/locale' | ||
import { DatePicker } from 'react-nice-dates' | ||
import 'react-nice-dates/build/style.css' | ||
function DatePickerWithTimeExample() { | ||
const [date, setDate] = useState(new Date(2020, 1, 24, 18, 15)) | ||
return ( | ||
<DatePicker date={date} onDateChange={setDate} locale={enGB} format='dd/MM/yyyy HH:mm'> | ||
{({ inputProps, focused }) => <input className={'input' + (focused ? ' -focused' : '')} {...inputProps} />} | ||
</DatePicker> | ||
) | ||
} | ||
` | ||
|
||
export default function DatePickerWithTimeExample() { | ||
const [date, setDate] = useState(new Date(2020, 1, 24, 18, 15)) | ||
|
||
return ( | ||
<Example code={code}> | ||
<DatePicker date={date} onDateChange={setDate} locale={enGB} format='dd/MM/yyyy HH:mm'> | ||
{({ inputProps, focused }) => <input className={'input' + (focused ? ' -focused' : '')} {...inputProps} />} | ||
</DatePicker> | ||
</Example> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState } from 'react' | ||
import { enGB } from 'date-fns/locale' | ||
import { DatePicker, useDateInput } from '../../src' | ||
import Example from './Example' | ||
|
||
const code = ` | ||
import React, { useState } from 'react' | ||
import { enGB } from 'date-fns/locale' | ||
import { DatePicker } from 'react-nice-dates' | ||
import 'react-nice-dates/build/style.css' | ||
function DatePickerWithTimeInputExample() { | ||
const [date, setDate] = useState(new Date(2020, 1, 24, 18, 15)) | ||
const timeInputProps = useDateInput({ | ||
date, | ||
format: 'HH:mm', | ||
locale: enGB, | ||
onDateChange: setDate | ||
}) | ||
return ( | ||
<div style={{ display: 'flex' }}> | ||
<DatePicker date={date} onDateChange={setDate} locale={enGB} format='dd/MM/yyyy'> | ||
{({ inputProps, focused }) => ( | ||
<input className={'input' + (focused ? ' -focused' : '')} style={{ width: 150 }} {...inputProps} /> | ||
)} | ||
</DatePicker> | ||
<input className='input' style={{ marginLeft: 16, width: 80 }} {...timeInputProps} /> | ||
</div> | ||
) | ||
} | ||
` | ||
|
||
export default function DatePickerWithTimeInputExample() { | ||
const [date, setDate] = useState(new Date(2020, 1, 24, 18, 15)) | ||
|
||
const timeInputProps = useDateInput({ | ||
date, | ||
format: 'HH:mm', | ||
locale: enGB, | ||
onDateChange: setDate | ||
}) | ||
|
||
return ( | ||
<Example code={code}> | ||
<div style={{ display: 'flex' }}> | ||
<DatePicker date={date} onDateChange={setDate} locale={enGB} format='dd/MM/yyyy'> | ||
{({ inputProps, focused }) => ( | ||
<input className={'input' + (focused ? ' -focused' : '')} style={{ width: 150 }} {...inputProps} /> | ||
)} | ||
</DatePicker> | ||
|
||
<input className='input' style={{ marginLeft: 16, width: 80 }} {...timeInputProps} /> | ||
</div> | ||
</Example> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters