-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Cover: Customizing Alignment of inner content #21091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
54cd584
0d1560b
569e33d
49e11ad
4ab514f
ccd4cde
a1d4c8e
5a747a0
d5bc9c3
37f4eb8
4651a81
1c27b72
69fe802
22073f6
eaa7cc4
74e0f95
ccabb0a
50ed904
ef5b7a6
19b3f7c
0c95094
604fb66
1d9ed4b
67184bf
0259d71
fa3d6c5
f25d306
4f8f1ca
13551d8
655efc6
af7f487
79dd122
6dabde1
96674de
53f4457
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { noop } from 'lodash'; | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { DOWN } from '@wordpress/keycodes'; | ||
| import { | ||
| Button, | ||
| Dropdown, | ||
| ToolbarGroup, | ||
| __experimentalAlignmentMatrixControl as AlignmentMatrixControl, | ||
| } from '@wordpress/components'; | ||
|
|
||
| export function BlockAlignmentMatrixToolbar( props ) { | ||
| const { | ||
| label = __( 'Change matrix alignment' ), | ||
| onChange = noop, | ||
| value = 'center', | ||
| } = props; | ||
|
|
||
| const icon = <AlignmentMatrixControl.Icon value={ value } />; | ||
| const className = 'block-editor-block-alignment-matrix-toolbar'; | ||
| const popoverClassName = `${ className }__popover`; | ||
|
|
||
| return ( | ||
| <Dropdown | ||
| position="bottom right" | ||
| className={ className } | ||
| popoverProps={ { className: popoverClassName } } | ||
| renderToggle={ ( { onToggle, isOpen } ) => { | ||
| const openOnArrowDown = ( event ) => { | ||
| if ( ! isOpen && event.keyCode === DOWN ) { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| onToggle(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <ToolbarGroup> | ||
| <Button | ||
| onClick={ onToggle } | ||
| aria-haspopup="true" | ||
| aria-expanded={ isOpen } | ||
| onKeyDown={ openOnArrowDown } | ||
| label={ label } | ||
| icon={ icon } | ||
| showTooltip | ||
| /> | ||
| </ToolbarGroup> | ||
| ); | ||
| } } | ||
| renderContent={ () => ( | ||
| <AlignmentMatrixControl | ||
| hasFocusBorder={ false } | ||
| onChange={ onChange } | ||
| value={ value } | ||
| /> | ||
| ) } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default BlockAlignmentMatrixToolbar; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .block-editor-block-alignment-matrix-toolbar__popover { | ||
| .components-popover__content { | ||
| min-width: 0; | ||
| padding: $grid-unit; | ||
| width: auto; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious to know why we need custom styling and whether these could be abstracted somehow in Dropdown.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently needed as there's no other way to style the dropdown menu. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,9 @@ | |
| }, | ||
| "customGradient": { | ||
| "type": "string" | ||
| }, | ||
| "contentPosition": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # AlignmentMatrixControl | ||
|
|
||
| AlignmentMatrixControl components let adjust horizontal and vertical alignments for UI. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```jsx | ||
| import { AlignmentMatrixControl } from '@wordpress/components'; | ||
| import { useState } from '@wordpress/elememt'; | ||
|
|
||
| const Example = () => { | ||
| const [ alignment, setAlignment ] = useState( 'center center' ); | ||
|
|
||
| return ( | ||
| <AlignmentMatrixControl value={ alignment } onChange={ setAlignment } /> | ||
| ); | ||
| }; | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { unstable_CompositeItem as CompositeItem } from 'reakit/Composite'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import Tooltip from '../tooltip'; | ||
| import VisuallyHidden from '../visually-hidden'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { ALIGNMENT_LABEL } from './utils'; | ||
| import { | ||
| Cell as CellView, | ||
| Point, | ||
| } from './styles/alignment-matrix-control-styles'; | ||
|
|
||
| export default function Cell( { isActive = false, value, ...props } ) { | ||
| const tooltipText = ALIGNMENT_LABEL[ value ]; | ||
|
|
||
| return ( | ||
| <Tooltip text={ tooltipText }> | ||
| <CompositeItem as={ CellView } role="gridcell" { ...props }> | ||
| { /* VoiceOver needs a text content to be rendered within grid cell, | ||
| otherwise it'll announce the content as "blank". So we use a visually | ||
| hidden element instead of aria-label. */ } | ||
| <VisuallyHidden>{ value }</VisuallyHidden> | ||
| <Point isActive={ isActive } role="presentation" /> | ||
| </CompositeItem> | ||
| </Tooltip> | ||
| ); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.