-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace block navigation dropdown (#164)
* Replace block navigation dropdown Use a local version as the core one is deprecated and moving to a sidebar only * Add style of TOC
- Loading branch information
1 parent
d7ab55f
commit 66a1f32
Showing
3 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/components/block-editor-toolbar/block-navigation/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,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button, Dropdown } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { listView } from '@wordpress/icons'; | ||
import { store as blockEditorStore, ListView } from '@wordpress/block-editor'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
function BlockNavigationDropdown( { isDisabled, ...props }, ref ) { | ||
const hasBlocks = useSelect( ( select ) => !! select( blockEditorStore ).getBlockCount(), [] ); | ||
const isEnabled = hasBlocks && ! isDisabled; | ||
|
||
return ( | ||
<Dropdown | ||
contentClassName="block-editor-block-navigation__popover" | ||
position="bottom right" | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
{ ...props } | ||
ref={ ref } | ||
icon={ listView } | ||
aria-expanded={ isOpen } | ||
aria-haspopup="true" | ||
onClick={ isEnabled ? onToggle : undefined } | ||
/* translators: button label text should, if possible, be under 16 characters. */ | ||
label={ __( 'List view' ) } | ||
className="block-editor-block-navigation" | ||
aria-disabled={ ! isEnabled } | ||
/> | ||
) } | ||
renderContent={ () => ( | ||
<div className="block-editor-block-navigation__container"> | ||
<p className="block-editor-block-navigation__label"> | ||
{ __( 'List view' ) } | ||
</p> | ||
|
||
<ListView /> | ||
</div> | ||
) } | ||
/> | ||
); | ||
} | ||
|
||
export default forwardRef( BlockNavigationDropdown ); |
78 changes: 78 additions & 0 deletions
78
src/components/block-editor-toolbar/block-navigation/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,78 @@ | ||
@import '@wordpress/base-styles/_colors'; | ||
@import '@wordpress/base-styles/_variables'; | ||
@import '@wordpress/base-styles/_mixins'; | ||
@import '@wordpress/base-styles/_breakpoints'; | ||
@import '@wordpress/base-styles/_animations'; | ||
@import '@wordpress/base-styles/_z-index'; | ||
|
||
.table-of-contents__popover.components-popover .components-popover__content { | ||
min-width: 380px; | ||
} | ||
|
||
.components-popover.table-of-contents__popover { | ||
z-index: z-index(".components-popover.table-of-contents__popover"); | ||
} | ||
|
||
.table-of-contents__popover { | ||
.components-popover__content { | ||
padding: $grid-unit-20; | ||
|
||
@include break-small { | ||
max-height: calc(100vh - 120px); | ||
overflow-y: auto; | ||
} | ||
} | ||
|
||
hr { | ||
margin: 10px -16px 0; | ||
} | ||
} | ||
|
||
.table-of-contents__wrapper:focus::before { | ||
content: ""; | ||
display: block; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); | ||
pointer-events: none; | ||
} | ||
|
||
.table-of-contents__counts { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin: 0; | ||
margin-top: -$grid-unit-10; | ||
} | ||
|
||
.table-of-contents__count { | ||
flex-basis: 33%; | ||
display: flex; | ||
flex-direction: column; | ||
font-size: $default-font-size; | ||
color: $gray-900; | ||
padding-right: $grid-unit-10; | ||
margin-bottom: 0; | ||
margin-top: $grid-unit-10; | ||
|
||
&:nth-child(4n) { | ||
padding-right: 0; | ||
} | ||
} | ||
|
||
.table-of-contents__number, | ||
.table-of-contents__popover .word-count { | ||
font-size: 21px; | ||
font-weight: 400; | ||
line-height: 30px; | ||
color: $gray-900; | ||
} | ||
|
||
.table-of-contents__title { | ||
display: block; | ||
margin-top: 20px; | ||
font-size: 15px; | ||
font-weight: 600; | ||
} |
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