Files
developer-roadmap/components/md-renderer/mdx-components/heading.tsx

82 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-08-20 17:06:26 +02:00
import React from 'react';
import styled from 'styled-components';
import LinkIcon from 'components/icons/link.svg';
const linkify = (Component: React.FunctionComponent<any>) => {
return function EnrichedHeading(props: { children: string }): React.ReactNode {
const text = props.children;
2021-12-05 02:04:20 +01:00
const id = text?.toLowerCase && text
2021-08-20 17:06:26 +02:00
.toLowerCase()
.replace(/[^\x00-\x7F]/g, '')
.replace(/\s+/g, '-')
.replace(/[?!]/g, '');
return (
<Component id={id}>
<HeaderLink href={`#${id}`}>
<LinkIcon />
</HeaderLink>
{props.children}
</Component>
);
};
};
const HeaderLink = styled.a`
position: absolute;
top: 0;
left: -25px;
width: 25px;
display: none;
height: 100%;
align-items: center;
justify-content: flex-start;
`;
const H1 = styled.h1`
position: relative;
2021-12-04 16:04:31 +01:00
font-size: 32px;
2021-08-21 16:44:49 +02:00
line-height: 40px;
2021-08-20 17:06:26 +02:00
font-weight: 700;
2021-12-04 16:04:31 +01:00
margin: 20px 0 10px !important;
2021-08-20 17:06:26 +02:00
&:hover ${HeaderLink} {
display: flex;
}
`;
const H2 = styled(H1).attrs({ as: 'h2' })`
2021-12-04 16:04:31 +01:00
font-size: 30px;
2021-08-20 17:06:26 +02:00
`;
const H3 = styled(H1).attrs({ as: 'h3' })`
margin: 22px 0 8px;
2021-12-04 16:04:31 +01:00
font-size: 28px;
2021-08-20 17:06:26 +02:00
`;
const H4 = styled(H1).attrs({ as: 'h4' })`
margin: 18px 0 8px;
font-size: 24px;
`;
const H5 = styled(H1).attrs({ as: 'h5' })`
margin: 14px 0 8px;
font-size: 18px;
`;
const H6 = styled(H1).attrs({ as: 'h6' })`
margin: 12px 0 8px;
font-size: 18px;
`;
const Headings = {
2021-12-09 16:39:09 +01:00
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H6
2021-08-20 17:06:26 +02:00
};
export default Headings;