feat(widget-markdown): add headings dropdown (#2879)

This commit is contained in:
Christian Fritsch 2019-11-18 23:16:33 +01:00 committed by Shawn Erquhart
parent dc0c4c51ed
commit 78face334f
6 changed files with 58 additions and 21 deletions

View File

@ -18,6 +18,7 @@ import iconGitlab from './gitlab.svg';
import iconGrid from './grid.svg'; import iconGrid from './grid.svg';
import iconH1 from './h1.svg'; import iconH1 from './h1.svg';
import iconH2 from './h2.svg'; import iconH2 from './h2.svg';
import iconHOptions from './h-options.svg';
import iconHome from './home.svg'; import iconHome from './home.svg';
import iconImage from './image.svg'; import iconImage from './image.svg';
import iconItalic from './italic.svg'; import iconItalic from './italic.svg';
@ -66,6 +67,7 @@ const images = {
grid: iconGrid, grid: iconGrid,
h1: iconH1, h1: iconH1,
h2: iconH2, h2: iconH2,
hOptions: iconHOptions,
home: iconHome, home: iconHome,
image: iconImage, image: iconImage,
italic: iconItalic, italic: iconItalic,

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" viewBox="0 0 22 20"><path fill="#7A8291" d="M3 4h10v12H3V4zm2 0v5h6V4H5zm0 7v5h6v-5H5M17.874 16.91l-3.493-4.117h6.986l-3.493 4.117z"></path></svg>

After

Width:  |  Height:  |  Size: 209 B

View File

@ -312,11 +312,13 @@ const components = {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
white-space: nowrap;
&:last-of-type { &:last-of-type {
border-bottom: 0; border-bottom: 0;
} }
&.active,
&:hover, &:hover,
&:active, &:active,
&:focus { &:focus {

View File

@ -58,6 +58,15 @@ const ToolbarToggleLabel = styled.span`
`}; `};
`; `;
const headingOptions = {
'heading-one': 'Heading 1',
'heading-two': 'Heading 2',
'heading-three': 'Heading 3',
'heading-four': 'Heading 4',
'heading-five': 'Heading 5',
'heading-six': 'Heading 6',
};
export default class Toolbar extends React.Component { export default class Toolbar extends React.Component {
static propTypes = { static propTypes = {
buttons: ImmutablePropTypes.list, buttons: ImmutablePropTypes.list,
@ -135,24 +144,45 @@ export default class Toolbar extends React.Component {
isHidden={this.isHidden('link')} isHidden={this.isHidden('link')}
disabled={disabled} disabled={disabled}
/> />
{/* Show dropdown if at least one heading is not hidden */}
{Object.keys(headingOptions).some(optionKey => {
return !this.isHidden(optionKey);
}) && (
<ToolbarDropdownWrapper>
<Dropdown
dropdownTopOverlap="36px"
renderButton={() => (
<DropdownButton>
<ToolbarButton <ToolbarButton
type="heading-one" type="headings"
label="Header 1" label="Headings"
icon="h1" icon="hOptions"
onClick={onBlockClick}
isActive={selectionHasBlock}
isHidden={this.isHidden('heading-one')}
disabled={disabled} disabled={disabled}
isActive={() =>
!disabled &&
Object.keys(headingOptions).some(optionKey => {
return selectionHasBlock(optionKey);
})
}
/> />
<ToolbarButton </DropdownButton>
type="heading-two" )}
label="Header 2" >
icon="h2" {!disabled &&
onClick={onBlockClick} Object.keys(headingOptions).map(
isActive={selectionHasBlock} (optionKey, idx) =>
isHidden={this.isHidden('heading-two')} !this.isHidden(optionKey) && (
disabled={disabled} <DropdownItem
key={idx}
label={headingOptions[optionKey]}
className={selectionHasBlock(optionKey) && 'active'}
onClick={() => onBlockClick(undefined, optionKey)}
/> />
),
)}
</Dropdown>
</ToolbarDropdownWrapper>
)}
<ToolbarButton <ToolbarButton
type="quote" type="quote"
label="Quote" label="Quote"

View File

@ -112,7 +112,9 @@ export default class Editor extends React.Component {
}; };
handleBlockClick = (event, type) => { handleBlockClick = (event, type) => {
if (event) {
event.preventDefault(); event.preventDefault();
}
let { value } = this.state; let { value } = this.state;
const { document: doc } = value; const { document: doc } = value;
const { unwrapList, wrapInList } = EditListConfigured.changes; const { unwrapList, wrapInList } = EditListConfigured.changes;

View File

@ -1,5 +1,5 @@
--- ---
label: "Markdown" label: 'Markdown'
title: markdown title: markdown
--- ---
@ -12,7 +12,7 @@ _Please note:_ If you want to use your markdown editor to fill a markdown file c
- **Data type:** markdown - **Data type:** markdown
- **Options:** - **Options:**
- `default`: accepts markdown content - `default`: accepts markdown content
- `buttons`: an array of strings representing the formatting buttons to display, all buttons shown by default. Buttons include: `bold`, `italic`, `code`, `link`, `heading-one`, `heading-two`, `quote`, `code-block`, `bulleted-list`, and `numbered-list`. - `buttons`: an array of strings representing the formatting buttons to display, all buttons shown by default. Buttons include: `bold`, `italic`, `code`, `link`, `heading-one`, `heading-two`, `heading-three`, `heading-four`, `heading-five`, `heading-six`, `quote`, `code-block`, `bulleted-list`, and `numbered-list`.
- **Example:** - **Example:**
```yaml ```yaml