-
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.
Add button states in the stylebook design section
- Loading branch information
1 parent
47718ab
commit 7869490
Showing
3 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/edit-site/src/components/style-book/button-examples.tsx
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,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { __experimentalGrid as Grid } from '@wordpress/components'; | ||
import { View } from '@wordpress/primitives'; | ||
import { | ||
BlockList, | ||
privateApis as blockEditorPrivateApis, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock( | ||
blockEditorPrivateApis | ||
); | ||
|
||
const BUTTON_STATE_NAMES = [ | ||
'default', | ||
':active', | ||
':any-link', | ||
':focus', | ||
':hover', | ||
':link', | ||
':visited', | ||
]; | ||
|
||
function ButtonExamples() { | ||
const [ elementsButton ] = useGlobalStyle( 'elements.button' ); | ||
const blocks = BUTTON_STATE_NAMES.map( ( state ) => { | ||
const styles = | ||
( state !== 'default' | ||
? elementsButton[ state ] | ||
: elementsButton ) || {}; | ||
return createBlock( 'core/button', { | ||
text: __( 'Call to Action' ), | ||
style: styles, | ||
} ); | ||
} ); | ||
|
||
return ( | ||
<Grid columns={ 2 } gap={ 6 }> | ||
{ blocks.map( ( block, key ) => ( | ||
<View key={ `button-example-${ key }` }> | ||
<ExperimentalBlockEditorProvider value={ [ block ] }> | ||
<BlockList appender={ false } /> | ||
</ExperimentalBlockEditorProvider> | ||
|
||
<span className="edit-site-style-book__example-subtitle"> | ||
{ BUTTON_STATE_NAMES[ key ] } | ||
</span> | ||
</View> | ||
) ) } | ||
</Grid> | ||
); | ||
} | ||
|
||
export default ButtonExamples; |
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