docusaurus/lib/core/Header.js

29 lines
676 B
JavaScript
Raw Normal View History

2017-07-07 13:28:29 -04:00
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
2017-07-07 13:28:29 -04:00
*/
const React = require('react');
const toSlug = require('./toSlug.js');
2017-07-07 13:28:29 -04:00
class Header extends React.Component {
2017-07-07 13:28:29 -04:00
render() {
const slug = toSlug(this.props.toSlug || this.props.children);
const Heading = 'h' + this.props.level;
2017-07-07 13:28:29 -04:00
return (
<Heading {...this.props}>
<a className="anchor" id={slug} />
{this.props.children}{' '}
<a className="hash-link" href={'#' + slug}>
2017-07-10 19:38:35 -04:00
#
</a>
2017-07-07 13:28:29 -04:00
</Heading>
);
2017-07-10 19:38:35 -04:00
}
}
2017-07-07 13:28:29 -04:00
module.exports = Header;