-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
PostSchedule
to make calendar/clock available as components (
- Loading branch information
1 parent
e63deab
commit e3e849f
Showing
9 changed files
with
164 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
DateTimePicker | ||
======= | ||
|
||
DateTimePicker is a React component to render a calendar and clock for selecting a date and time. The calendar and clock components can be accessed individually using the `DatePicker` and `TimePicker` components respectively. | ||
|
||
## Usage | ||
|
||
Render a DateTimePicker. | ||
|
||
```jsx | ||
import { DateTimePicker } from '@wordpress/components'; | ||
import { settings } from '@wordpress/date'; | ||
|
||
function selectTime( date, onUpdateDate ) { | ||
// To know if the current timezone is a 12 hour time with look for "a" in the time format. | ||
// We also make sure this a is not escaped by a "/". | ||
const is12HourTime = /a(?!\\)/i.test( | ||
settings.formats.time | ||
.toLowerCase() // Test only the lower case a | ||
.replace( /\\\\/g, '' ) // Replace "//" with empty strings | ||
.split( '' ).reverse().join( '' ) // Reverse the string and test for "a" not followed by a slash | ||
); | ||
|
||
return ( | ||
<DateTimePicker | ||
currentDate={ date } | ||
onChange={ onUpdateDate } | ||
locale={ settings.l10n.locale } | ||
is12Hour={ is12HourTime } | ||
/> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
The component accepts the following props: | ||
|
||
### currentDate | ||
|
||
The current date and time at initialization. | ||
|
||
- Type: `string` | ||
- Required: Yes | ||
|
||
### onChange | ||
|
||
The function called when a new date or time has been selected. It is passed the `currentDate` as an argument. | ||
|
||
- Type: `Function` | ||
- Required: No | ||
- Default: `noop` | ||
|
||
### locale | ||
|
||
The localization for the display of the date and time. | ||
|
||
- Type: `string` | ||
- Required: No | ||
|
||
### is12Hour | ||
|
||
Whether the current timezone is a 12 hour time. | ||
|
||
- Type: `bool` | ||
- Required: No |
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,16 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import ReactDatePicker from 'react-datepicker'; | ||
import moment from 'moment'; | ||
|
||
export function DatePicker( { currentDate, onChange, ...args } ) { | ||
const momentDate = currentDate ? moment( currentDate ) : moment(); | ||
|
||
return <ReactDatePicker | ||
inline | ||
selected={ momentDate } | ||
onChange={ onChange } | ||
{ ...args } | ||
/>; | ||
} |
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,25 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { DatePicker } from './date'; | ||
import { TimePicker } from './time'; | ||
|
||
export { DatePicker, TimePicker }; | ||
|
||
export function DateTimePicker( { currentDate, onChange, is12Hour, ...args } ) { | ||
return [ | ||
<DatePicker | ||
key="date-picker" | ||
currentDate={ currentDate } | ||
onChange={ onChange } | ||
{ ...args } | ||
/>, | ||
<TimePicker | ||
key="time-picker" | ||
currentTime={ currentDate } | ||
onChange={ onChange } | ||
is12Hour={ is12Hour } | ||
/>, | ||
]; | ||
} |
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,35 @@ | ||
@import '~react-datepicker/dist/react-datepicker'; | ||
|
||
.components-time-picker { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-top: 10px; | ||
|
||
.components-time-picker__input { | ||
width: 40px; | ||
} | ||
|
||
.components-time-picker__separator { | ||
padding: 0 4px; | ||
} | ||
|
||
.components-time-picker__am-button { | ||
margin-left: 8px; | ||
margin-right: -1px; | ||
border-radius: 3px 0 0 3px; | ||
} | ||
|
||
.components-time-picker__pm-button { | ||
margin-left: -1px; | ||
border-radius: 0 3px 3px 0; | ||
} | ||
|
||
.components-time-picker__am-button.is-toggled, | ||
.components-time-picker__pm-button.is-toggled { | ||
background: $light-gray-300; | ||
border-color: $dark-gray-100; | ||
box-shadow: inset 0 2px 5px -3px $dark-gray-500; | ||
transform: translateY(1px); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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