-
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.
Cover: Customizing Alignment of inner content (#21091)
* Add initial AlignmentControl * Refactor AlignmentControl utils. Add basic tests for utils * Move AlignmentControl styled components to dedicated file * Add AlignControl icon. Refactor and share styles between main Control and Icon * Update Docs Manifest * Export AlignControl as __experimentalAlignControl * Fix export for AlignmentControl (__experimentalAlignmentControl) * Update packages/components/src/alignment-control/utils.js Co-Authored-By: Zebulan Stanphill <[email protected]> * Integrate AlignmentControl with Cover block Renamed AlignmentControl to AlignmentMatrixControl. * Update Docs manifest and Storyshot * Improve AlignmentMatrix rendering in Edit and Save functions Remove unused code from base AlignmentMatrix component * Prevent rendering of position className if undefined * Update Cover content position control label * Add padding to Cover (rather than inner content) * Adding a11y and RTL support to AlignmentMatrixControl Also refactors isRTL / useRTL from the rtl utils. * Add basic tests for keyboard movements * Cover: Customizing Alignment with Reakit Composite (#21333) * WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]> * Update comments in AlignmentMatrixControl * Remove unnecessary fragment in Story * Refactor styles. Add knobs to AlignmentMatrixControl story * Adjust icon style * Add Tooltip to AlignmentMatrixControl cell * Remove onBlur handling and border styles * Account for center position * Adding code comment for width/height props in AlignmentMatrixControlIcon * Add prefix support in useInstanceId * Add code comment regarding icon export from AlignmentMatrixControl * Remove export of AlignmentMatrixControl icon element * Update stories + snapshot * Simplify nested array flattening * Remove padding from Cover editor.scss * Adjust BlockAlignmentMatrixToolbar popover className * Move padding styles to top of wp-block-cover selector * Fix AlignmentMatrixControl tests for window.focus in JSDOM * Replace Array.flat with lodash.flattenDeep Due to lack of polyfill support (at the moment). Co-authored-by: Zebulan Stanphill <[email protected]> Co-authored-by: Haz <[email protected]>
- Loading branch information
1 parent
022eec5
commit 47389d5
Showing
24 changed files
with
801 additions
and
19 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
67 changes: 67 additions & 0 deletions
67
packages/block-editor/src/components/block-alignment-matrix-toolbar/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,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; |
7 changes: 7 additions & 0 deletions
7
packages/block-editor/src/components/block-alignment-matrix-toolbar/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,7 @@ | ||
.block-editor-block-alignment-matrix-toolbar__popover { | ||
.components-popover__content { | ||
min-width: 0; | ||
padding: $grid-unit; | ||
width: auto; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -40,6 +40,9 @@ | |
}, | ||
"customGradient": { | ||
"type": "string" | ||
}, | ||
"contentPosition": { | ||
"type": "string" | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
packages/components/src/alignment-matrix-control/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,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 } /> | ||
); | ||
}; | ||
``` |
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 @@ | ||
/** | ||
* 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> | ||
); | ||
} |
Oops, something went wrong.