-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathautoLinkHeader.js
More file actions
36 lines (34 loc) · 1.06 KB
/
autoLinkHeader.js
File metadata and controls
36 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import { Flex, FlexItem, Content } from '@patternfly/react-core';
import LinkIcon from '@patternfly/react-icons/dist/esm/icons/link-icon';
import { Link } from '../link/link';
import { slugger } from '../../helpers/slugger';
import { css } from '@patternfly/react-styles';
export const AutoLinkHeader = ({
id,
headingLevel,
children,
metaText,
className
}) => {
const slug = id || slugger(children);
return (
<Content
id={slug}
component={headingLevel}
className={css('ws-heading', className)}
tabIndex={-1}
isEditorial
>
<Flex alignItems={{ default: 'alignItemsCenter'}} spaceItems={{ default: "spaceItemsSm" }} className={`ws-autolink-header ws-autolink-header-${headingLevel}`}>
<FlexItem>
<Link href={`#${slug}`} className="ws-heading-anchor" tabIndex="-1" aria-hidden>
<LinkIcon className="ws-heading-anchor-icon" style={{ verticalAlign: 'middle' }} />
</Link>
{children}
</FlexItem>
{metaText && <FlexItem>{metaText}</FlexItem>}
</Flex>
</Content>
)
};