diff --git a/frontend/components/Editor/components/Heading.js b/frontend/components/Editor/components/Heading.js index 9aa1431f..3a7aaa10 100644 --- a/frontend/components/Editor/components/Heading.js +++ b/frontend/components/Editor/components/Heading.js @@ -17,32 +17,6 @@ type Props = { component?: string, }; -const Wrapper = styled.div` - display: inline; - margin-left: ${props => (props.hasEmoji ? '-1.2em' : 0)} -`; - -const Anchor = styled.a` - visibility: hidden; - padding-left: .25em; - color: #dedede; - - &:hover { - color: #cdcdcd; - } -`; - -// $FlowIssue I don't know -const titleStyles = component => styled(component)` - position: relative; - - &:hover { - ${Anchor} { - visibility: visible; - } - } -`; - function Heading(props: Props) { const { parent, @@ -58,7 +32,7 @@ function Heading(props: Props) { const showPlaceholder = placeholder && firstHeading && !node.text; const slugish = _.escape(`${component}-${slug(node.text)}`); const showHash = readOnly && !!slugish; - const Component = titleStyles(component); + const Component = component; const emoji = editor.props.emoji || ''; const title = node.text.trim(); const startsWithEmojiAndSpace = @@ -76,4 +50,32 @@ function Heading(props: Props) { ); } +const Wrapper = styled.div` + display: inline; + margin-left: ${props => (props.hasEmoji ? '-1.2em' : 0)} +`; + +const Anchor = styled.a` + visibility: hidden; + padding-left: .25em; + color: #dedede; + + &:hover { + color: #cdcdcd; + } +`; + +export const Heading1 = styled(Heading)` + &:hover { + ${Anchor} { + visibility: visible; + } + } +`; +export const Heading2 = Heading1.withComponent('h2'); +export const Heading3 = Heading1.withComponent('h3'); +export const Heading4 = Heading1.withComponent('h4'); +export const Heading5 = Heading1.withComponent('h5'); +export const Heading6 = Heading1.withComponent('h6'); + export default Heading; diff --git a/frontend/components/Editor/schema.js b/frontend/components/Editor/schema.js index e90f2e84..6c95d36a 100644 --- a/frontend/components/Editor/schema.js +++ b/frontend/components/Editor/schema.js @@ -6,7 +6,14 @@ import InlineCode from './components/InlineCode'; import Image from './components/Image'; import Link from './components/Link'; import ListItem from './components/ListItem'; -import Heading from './components/Heading'; +import { + Heading1, + Heading2, + Heading3, + Heading4, + Heading5, + Heading6, +} from './components/Heading'; import Paragraph from './components/Paragraph'; import type { Props, Node, Transform } from './types'; @@ -47,12 +54,12 @@ const createSchema = () => { image: Image, link: Link, 'list-item': ListItem, - heading1: (props: Props) => , - heading2: (props: Props) => , - heading3: (props: Props) => , - heading4: (props: Props) => , - heading5: (props: Props) => , - heading6: (props: Props) => , + heading1: (props: Props) => , + heading2: (props: Props) => , + heading3: (props: Props) => , + heading4: (props: Props) => , + heading5: (props: Props) => , + heading6: (props: Props) => , }, rules: [