-
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.
Update design of DateTimePicker and convert to Emotion
- Updates the design of DateTimePicker, DatePicker and TimePicker. - Converts CSS in DateTimePicker, DatePicker and TimePicker to Emotion where it makes sense to do so. - Allows removal of Reset button and Help functionality from DateTimePicker. - Adds PublishDateTimePicker to block-editor. This exposes a specialised DateTimePicker that is good for choosing a post publish date.
- Loading branch information
1 parent
515b283
commit b87608b
Showing
23 changed files
with
800 additions
and
605 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
54 changes: 54 additions & 0 deletions
54
packages/block-editor/src/components/publish-date-time-picker/README.md
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,54 @@ | ||
# `PublishDateTimePicker` | ||
|
||
`<PublishDateTimePicker />` is a component used to select the date and time that | ||
a post will be published. It wraps the `<DateTimePicker />` component found in | ||
`@wordpress/components` and adds additional post-specific controls. | ||
|
||
See [the documentation for | ||
DateTimePicker](https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/date-time) | ||
for more information. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { Dropdown, Button } from '@wordpress/components'; | ||
import { __experimentalPublishDateTimePicker as PublishDateTimePicker } from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
const MyDateTimePicker = () => { | ||
const [ date, setDate ] = useState( new Date() ); | ||
|
||
return ( | ||
<Dropdown | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
onClick={ onToggle } | ||
aria-expanded={ isOpen } | ||
> | ||
Select post date | ||
</Button> | ||
) } | ||
renderContent={ ( { onClose } ) => ( | ||
<PublishDateTimePicker | ||
currentDate={ date } | ||
onChange={ ( newDate ) => setDate( newDate ) } | ||
onClose={ onClose } | ||
/> | ||
) } | ||
/> | ||
); | ||
}; | ||
``` | ||
|
||
## Props | ||
|
||
`PublishDateTimePicker` supports all of the props that | ||
[`DateTimePicker`](https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/date-time#Props) | ||
supports, plus: | ||
|
||
### onClose | ||
|
||
Called when the user presses the close button. | ||
|
||
- Type: `Function` | ||
- Required: Yes |
50 changes: 50 additions & 0 deletions
50
packages/block-editor/src/components/publish-date-time-picker/index.js
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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
DateTimePicker, | ||
__experimentalHStack as HStack, | ||
__experimentalSpacer as Spacer, | ||
Button, | ||
} from '@wordpress/components'; | ||
import { closeSmall } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
function PublishDateTimePicker( | ||
{ onClose, onChange, ...additionalProps }, | ||
ref | ||
) { | ||
return ( | ||
<div ref={ ref } className="block-editor-publish-date-time-picker"> | ||
{ /* TODO: This header is essentially the same as the one in <PostVisiblity />. DRY it up. */ } | ||
<HStack className="block-editor-publish-date-time-picker__header"> | ||
<h2 className="block-editor-publish-date-time-picker__heading"> | ||
{ __( 'Publish' ) } | ||
</h2> | ||
<Spacer /> | ||
<Button | ||
className="block-editor-publish-date-time-picker__reset" | ||
variant="tertiary" | ||
onClick={ () => onChange?.( null ) } | ||
> | ||
{ __( 'Now' ) } | ||
</Button> | ||
<Button | ||
className="block-editor-publish-date-time-picker__close" | ||
icon={ closeSmall } | ||
label={ __( 'Close' ) } | ||
onClick={ onClose } | ||
/> | ||
</HStack> | ||
<DateTimePicker | ||
__nextRemoveHelpButton | ||
__nextRemoveResetButton | ||
onChange={ onChange } | ||
{ ...additionalProps } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default forwardRef( PublishDateTimePicker ); |
20 changes: 20 additions & 0 deletions
20
packages/block-editor/src/components/publish-date-time-picker/style.scss
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,20 @@ | ||
.block-editor-publish-date-time-picker__header { | ||
margin-bottom: 1em; | ||
} | ||
|
||
.block-editor-publish-date-time-picker__heading { | ||
font-size: $default-font-size; | ||
margin: 0; | ||
} | ||
|
||
.block-editor-publish-date-time-picker__reset { | ||
height: $icon-size; | ||
margin: 0; | ||
text-decoration: underline; | ||
} | ||
|
||
[class].block-editor-publish-date-time-picker__close { | ||
height: $icon-size; | ||
min-width: $icon-size; | ||
padding: 0; | ||
} |
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
Oops, something went wrong.