-
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.
- Loading branch information
1 parent
00c32f4
commit dec49d1
Showing
2 changed files
with
100 additions
and
1 deletion.
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
87 changes: 87 additions & 0 deletions
87
packages/edit-site/src/components/style-book/navigation-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,87 @@ | ||
/** | ||
* 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 { __, _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock( | ||
blockEditorPrivateApis | ||
); | ||
|
||
const NAVIGATION_STATES = [ | ||
{ | ||
key: 'default', | ||
title: __( 'Navigation Item' ), | ||
}, | ||
{ | ||
key: ':active', | ||
title: __( 'Navigation Item (Active)' ), | ||
}, | ||
{ | ||
key: ':any-link', | ||
title: __( 'Navigation Item (Any Link)' ), | ||
}, | ||
{ | ||
key: ':focus', | ||
title: __( 'Navigation Item (Focus)' ), | ||
}, | ||
{ | ||
key: ':hover', | ||
title: __( 'Navigation Item (Hover)' ), | ||
}, | ||
{ | ||
key: ':link', | ||
title: __( 'Navigation Item (Link)' ), | ||
}, | ||
{ | ||
key: ':visited', | ||
title: __( 'Navigation Item (Visited)' ), | ||
}, | ||
]; | ||
|
||
function NavigationExamples() { | ||
const [ elementsLink ] = useGlobalStyle( 'elements.link' ); | ||
|
||
const blocks = [ | ||
...NAVIGATION_STATES.map( ( { key } ) => { | ||
const styles = | ||
( key !== 'default' ? elementsLink[ key ] : elementsLink ) || | ||
{}; | ||
return createBlock( 'core/navigation-link', { | ||
label: _x( 'About', 'navigation link preview example' ), | ||
url: 'https://example.com', | ||
style: styles, | ||
} ); | ||
} ), | ||
]; | ||
|
||
return ( | ||
<Grid columns={ 2 } gap={ 6 }> | ||
{ blocks.map( ( block, index ) => ( | ||
<View | ||
key={ `navigation-example-${ NAVIGATION_STATES[ index ].key }` } | ||
> | ||
<span className="edit-site-style-book__example-subtitle"> | ||
{ NAVIGATION_STATES[ index ].title } | ||
</span> | ||
<ExperimentalBlockEditorProvider value={ [ block ] }> | ||
<BlockList appender={ false } /> | ||
</ExperimentalBlockEditorProvider> | ||
</View> | ||
) ) } | ||
</Grid> | ||
); | ||
} | ||
|
||
export default NavigationExamples; |