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.
Format Library: add subscript and superscript (WordPress#21819)
* Format Library: add subscript and superscript * Add icons
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { toggleFormat } from '@wordpress/rich-text'; | ||
import { RichTextToolbarButton } from '@wordpress/block-editor'; | ||
import { subscript as subscriptIcon } from '@wordpress/icons'; | ||
|
||
const name = 'core/subscript'; | ||
const title = __( 'Subscript' ); | ||
|
||
export const subscript = { | ||
name, | ||
title, | ||
tagName: 'sub', | ||
className: null, | ||
edit( { isActive, value, onChange, onFocus } ) { | ||
function onToggle() { | ||
onChange( toggleFormat( value, { type: name } ) ); | ||
} | ||
|
||
function onClick() { | ||
onToggle(); | ||
onFocus(); | ||
} | ||
|
||
return ( | ||
<RichTextToolbarButton | ||
icon={ subscriptIcon } | ||
title={ title } | ||
onClick={ onClick } | ||
isActive={ isActive } | ||
/> | ||
); | ||
}, | ||
}; |
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 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { toggleFormat } from '@wordpress/rich-text'; | ||
import { RichTextToolbarButton } from '@wordpress/block-editor'; | ||
import { superscript as superscriptIcon } from '@wordpress/icons'; | ||
|
||
const name = 'core/superscript'; | ||
const title = __( 'Superscript' ); | ||
|
||
export const superscript = { | ||
name, | ||
title, | ||
tagName: 'sup', | ||
className: null, | ||
edit( { isActive, value, onChange, onFocus } ) { | ||
function onToggle() { | ||
onChange( toggleFormat( value, { type: name } ) ); | ||
} | ||
|
||
function onClick() { | ||
onToggle(); | ||
onFocus(); | ||
} | ||
|
||
return ( | ||
<RichTextToolbarButton | ||
icon={ superscriptIcon } | ||
title={ title } | ||
onClick={ onClick } | ||
isActive={ isActive } | ||
/> | ||
); | ||
}, | ||
}; |
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,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG, Path } from '@wordpress/primitives'; | ||
|
||
const subscript = ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<Path d="M16.9 18.3l.8-1.2c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.1-.3-.4-.5-.6-.7-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.2 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3L15 19.4h4.3v-1.2h-2.4zM14.1 7.2h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" /> | ||
</SVG> | ||
); | ||
|
||
export default subscript; |
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,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG, Path } from '@wordpress/primitives'; | ||
|
||
const superscript = ( | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<Path d="M16.9 10.3l.8-1.3c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.2-.2-.4-.4-.7-.6-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.1 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3l-1.8 2.8h4.3v-1.2h-2.2zm-2.8-3.1h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" /> | ||
</SVG> | ||
); | ||
|
||
export default superscript; |