-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Showing
29 changed files
with
577 additions
and
385 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
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,50 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import IconButton from '../icon-button'; | ||
import ToolbarButtonContainer from './toolbar-button-container'; | ||
|
||
function ToolbarButton( { | ||
containerClassName, | ||
icon, | ||
title, | ||
shortcut, | ||
subscript, | ||
onClick, | ||
className, | ||
isActive, | ||
isDisabled, | ||
extraProps, | ||
children, | ||
} ) { | ||
return ( | ||
<ToolbarButtonContainer className={ containerClassName }> | ||
<IconButton | ||
icon={ icon } | ||
label={ title } | ||
shortcut={ shortcut } | ||
data-subscript={ subscript } | ||
onClick={ ( event ) => { | ||
event.stopPropagation(); | ||
onClick(); | ||
} } | ||
className={ classnames( | ||
'components-toolbar__control', | ||
className, | ||
{ 'is-active': isActive } | ||
) } | ||
aria-pressed={ isActive } | ||
disabled={ isDisabled } | ||
{ ...extraProps } | ||
/> | ||
{ children } | ||
</ToolbarButtonContainer> | ||
); | ||
} | ||
|
||
export default ToolbarButton; |
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,77 @@ | ||
.components-toolbar__control.components-button { | ||
display: inline-flex; | ||
align-items: flex-end; | ||
margin: 0; | ||
padding: 3px; | ||
outline: none; | ||
cursor: pointer; | ||
position: relative; | ||
width: $icon-button-size; | ||
height: $icon-button-size; | ||
|
||
// Unset icon button styles | ||
&:active, | ||
&:not([aria-disabled="true"]):hover, | ||
&:not([aria-disabled="true"]):focus { | ||
outline: none; | ||
box-shadow: none; | ||
background: none; | ||
border: none; | ||
} | ||
|
||
// Disabled | ||
&:disabled { | ||
cursor: default; | ||
} | ||
|
||
& > svg { | ||
padding: 5px; | ||
border-radius: $radius-round-rectangle; | ||
height: 30px; | ||
width: 30px; | ||
} | ||
|
||
// Subscript for numbered icon buttons, like headings | ||
&[data-subscript] svg { | ||
padding: 5px 10px 5px 0; | ||
} | ||
|
||
&[data-subscript]::after { | ||
content: attr(data-subscript); | ||
font-family: $default-font; | ||
font-size: $default-font-size; | ||
font-weight: 600; | ||
line-height: 12px; | ||
position: absolute; | ||
right: 8px; | ||
bottom: 10px; | ||
} | ||
|
||
// Assign hover style to child element, not the button itself | ||
&:not(:disabled):not([aria-disabled="true"]):hover { | ||
box-shadow: none; | ||
} | ||
|
||
&:not(:disabled).is-active > svg, | ||
&:not(:disabled):hover > svg { | ||
@include formatting-button-style__hover; | ||
} | ||
|
||
// Active & toggled style | ||
&:not(:disabled).is-active > svg { | ||
@include formatting-button-style__active; | ||
} | ||
|
||
&:not(:disabled).is-active[data-subscript]::after { | ||
color: $white; | ||
} | ||
|
||
// Focus style | ||
&:not(:disabled):focus > svg { | ||
@include formatting-button-style__focus; | ||
} | ||
} | ||
|
||
.components-toolbar__control .dashicon { | ||
display: block; | ||
} |
File renamed without changes.
File renamed without changes.
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
35 changes: 35 additions & 0 deletions
35
packages/editor/src/components/rich-text/format-controls/bold/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,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { Fill, ToolbarButton } from '@wordpress/components'; | ||
import { toggleFormat } from '@wordpress/rich-text'; | ||
|
||
const Shortcut = () => null; | ||
|
||
export const bold = { | ||
format: 'bold', | ||
selector: 'strong', | ||
edit( { isActive, value, onChange } ) { | ||
const onToggle = () => onChange( toggleFormat( value, { type: 'strong' } ) ); | ||
|
||
return ( | ||
<Fragment> | ||
<Shortcut | ||
type="primary" | ||
key="b" | ||
onUse={ onToggle } | ||
/> | ||
<Fill name="RichText.ToolbarControls.bold"> | ||
<ToolbarButton | ||
icon="editor-bold" | ||
title={ __( 'Bold' ) } | ||
onClick={ onToggle } | ||
isActive={ isActive } | ||
/> | ||
</Fill> | ||
</Fragment> | ||
); | ||
}, | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/editor/src/components/rich-text/format-controls/code/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,25 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { toggleFormat } from '@wordpress/rich-text'; | ||
|
||
const Shortcut = () => null; | ||
|
||
export const code = { | ||
format: 'code', | ||
selector: 'code', | ||
edit( { value, onChange } ) { | ||
const onToggle = () => onChange( toggleFormat( value, { type: 'code' } ) ); | ||
|
||
return ( | ||
<Fragment> | ||
<Shortcut | ||
type="access" | ||
key="x" | ||
onUse={ onToggle } | ||
/> | ||
</Fragment> | ||
); | ||
}, | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/editor/src/components/rich-text/format-controls/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,13 @@ | ||
import { bold } from './bold'; | ||
import { code } from './code'; | ||
import { italic } from './italic'; | ||
import { link } from './link'; | ||
import { strikethrough } from './strikethrough'; | ||
|
||
export const formatControls = [ | ||
bold, | ||
code, | ||
italic, | ||
link, | ||
strikethrough, | ||
]; |
Oops, something went wrong.