feat(widget-markdown): add headings dropdown (#2879)
This commit is contained in:
parent
dc0c4c51ed
commit
78face334f
@ -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,
|
||||||
|
@ -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 |
@ -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 {
|
||||||
|
@ -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}
|
||||||
/>
|
/>
|
||||||
<ToolbarButton
|
{/* Show dropdown if at least one heading is not hidden */}
|
||||||
type="heading-one"
|
{Object.keys(headingOptions).some(optionKey => {
|
||||||
label="Header 1"
|
return !this.isHidden(optionKey);
|
||||||
icon="h1"
|
}) && (
|
||||||
onClick={onBlockClick}
|
<ToolbarDropdownWrapper>
|
||||||
isActive={selectionHasBlock}
|
<Dropdown
|
||||||
isHidden={this.isHidden('heading-one')}
|
dropdownTopOverlap="36px"
|
||||||
disabled={disabled}
|
renderButton={() => (
|
||||||
/>
|
<DropdownButton>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
type="heading-two"
|
type="headings"
|
||||||
label="Header 2"
|
label="Headings"
|
||||||
icon="h2"
|
icon="hOptions"
|
||||||
onClick={onBlockClick}
|
disabled={disabled}
|
||||||
isActive={selectionHasBlock}
|
isActive={() =>
|
||||||
isHidden={this.isHidden('heading-two')}
|
!disabled &&
|
||||||
disabled={disabled}
|
Object.keys(headingOptions).some(optionKey => {
|
||||||
/>
|
return selectionHasBlock(optionKey);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</DropdownButton>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{!disabled &&
|
||||||
|
Object.keys(headingOptions).map(
|
||||||
|
(optionKey, idx) =>
|
||||||
|
!this.isHidden(optionKey) && (
|
||||||
|
<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"
|
||||||
|
@ -112,7 +112,9 @@ export default class Editor extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleBlockClick = (event, type) => {
|
handleBlockClick = (event, type) => {
|
||||||
event.preventDefault();
|
if (event) {
|
||||||
|
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;
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user