forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move HeadinglevelDropdown to its own component (WordPress#46003)
* Add a tag selection component for the block toolbar (replaces HeadingLevelDropdown) * Update index.php * update fixtures * Update CSS class, replace sprintf in the label with the tag name * Add visible tag name to the drop down, add placeholder icon * Update README.md * Try to fix issue with the deprecation * Update CHANGELOG.md * Simplify and rename component * Try reverting fixture changes * And again... * Update Query title to use the new component * Update Comments title * Update Site title with paragraph exception * Update Heading block * Update rich-text.test.js * Block Heading Dropdown - Add support for mobile (WordPress#47967) * Text changes for a native file and e2e test spec * Use the updated headingLevel icons * Update prop names * Add 'options' property to type definiton --------- Co-authored-by: Gerardo Pacheco <[email protected]> Co-authored-by: George Mamadashvili <[email protected]>
- Loading branch information
1 parent
40e6e02
commit 83a5d63
Showing
18 changed files
with
157 additions
and
105 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
52 changes: 52 additions & 0 deletions
52
packages/block-editor/src/components/block-heading-level-dropdown/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,52 @@ | ||
# Heading Level Dropdown | ||
|
||
`<HeadingLevelDropdown>` Adds a dropdown for selecting H1-H6 and paragraph HTML tags from the block toolbar. | ||
Uses `<ToolbarDropdownMenu>`. | ||
|
||
## Usage | ||
|
||
```jsx | ||
|
||
import { BlockControls, HeadingLevelDropdown } from '@wordpress/block-editor'; | ||
|
||
const HEADING_LEVELS = [ 0, 1, 2, 3, 4, 5, 6 ]; | ||
|
||
const MyHeadingLevelToolbar = () => ( | ||
<BlockControls group="block"> | ||
<HeadingLevelDropdown | ||
options={ HEADING_LEVELS } | ||
value={ tag } | ||
onChange={ ( newTag ) => | ||
setAttributes( { tag: newTag } ) | ||
} | ||
/> | ||
</BlockControls> | ||
); | ||
``` | ||
|
||
### Props | ||
|
||
#### options | ||
|
||
The list of available HTML tags, passed from the block. | ||
|
||
- Type: `Object` | ||
- Required: no | ||
|
||
#### value | ||
|
||
The chosen HTML tag. | ||
|
||
- Type: `string` | ||
- Required: no | ||
|
||
#### onChange | ||
|
||
Callback to run when toolbar value is changed. | ||
|
||
- Type: `string` | ||
- Required: yes | ||
|
||
## Related components | ||
|
||
Block Editor components are components that can be used to compose the UI of your block editor. Thus, they can only be used under a [`BlockEditorProvider`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/provider/README.md) in the components tree. |
43 changes: 43 additions & 0 deletions
43
packages/block-editor/src/components/block-heading-level-dropdown/heading-level-icon.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,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
headingLevel1, | ||
headingLevel2, | ||
headingLevel3, | ||
headingLevel4, | ||
headingLevel5, | ||
headingLevel6, | ||
paragraph, | ||
} from '@wordpress/icons'; | ||
|
||
/** @typedef {import('@wordpress/element').WPComponent} WPComponent */ | ||
|
||
/** | ||
* HeadingLevelIcon props. | ||
* | ||
* @typedef WPHeadingLevelIconProps | ||
* | ||
* @property {number} level The heading level to show an icon for. | ||
*/ | ||
|
||
const LEVEL_TO_PATH = { | ||
0: paragraph, | ||
1: headingLevel1, | ||
2: headingLevel2, | ||
3: headingLevel3, | ||
4: headingLevel4, | ||
5: headingLevel5, | ||
6: headingLevel6, | ||
}; | ||
|
||
/** | ||
* Heading level icon. | ||
* | ||
* @param {WPHeadingLevelIconProps} props Component props. | ||
* | ||
* @return {?WPComponent} The icon. | ||
*/ | ||
export default function HeadingLevelIcon( { level } ) { | ||
return LEVEL_TO_PATH[ level ] ?? null; | ||
} |
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
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
Oops, something went wrong.