-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Improve ToolbarButton (#18931)
* Initial refactor on ToolbarButton * Update storyshots * Update ToolbarButton styles * Update snapshots * Remove unnecessary styles for components-toolbar-button * Update Toolbar Button imports * Refactors
- Loading branch information
Showing
13 changed files
with
311 additions
and
303 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
26 changes: 0 additions & 26 deletions
26
packages/components/src/toolbar-button/accessible-toolbar-button-container.js
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/components/src/toolbar-button/accessible-toolbar-button-container.native.js
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
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,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useToolbarItem } from 'reakit/Toolbar'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef, useContext } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ToolbarContext from '../toolbar-context'; | ||
|
||
function ToolbarItem( { children, ...props }, ref ) { | ||
const accessibleToolbarState = useContext( ToolbarContext ); | ||
// https://reakit.io/docs/composition/#props-hooks | ||
const itemProps = useToolbarItem( accessibleToolbarState, { ...props, ref } ); | ||
|
||
if ( typeof children !== 'function' ) { | ||
// eslint-disable-next-line no-console | ||
console.warn( '`ToolbarItem` is a generic headless component that accepts only function children props' ); | ||
return null; | ||
} | ||
|
||
if ( ! accessibleToolbarState ) { | ||
// eslint-disable-next-line no-console | ||
console.warn( '`ToolbarItem` should be rendered within `<Toolbar __experimentalAccessibilityLabel="label">`' ); | ||
return null; | ||
} | ||
|
||
return children( itemProps ); | ||
} | ||
|
||
export default forwardRef( ToolbarItem ); |
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 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
function ToolbarItem( { children, ...props }, ref ) { | ||
if ( typeof children !== 'function' ) { | ||
// eslint-disable-next-line no-console | ||
console.warn( '`ToolbarItem` is a generic headless component that accepts only function children props' ); | ||
return null; | ||
} | ||
|
||
return children( { ...props, ref } ); | ||
} | ||
|
||
export default forwardRef( ToolbarItem ); |
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.