2017-07-07 13:28:29 -04:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
|
|
|
*
|
2017-10-05 14:14:49 -04:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
2017-12-04 22:21:02 -05:00
|
|
|
const React = require('react');
|
|
|
|
|
const toSlug = require('./toSlug.js');
|
2017-07-07 13:28:29 -04:00
|
|
|
|
2017-10-26 19:13:56 -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);
|
2017-12-04 22:21:02 -05:00
|
|
|
const Heading = 'h' + this.props.level;
|
2017-07-07 13:28:29 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Heading {...this.props}>
|
2018-03-07 17:25:48 -05:00
|
|
|
<a className="anchor" id={slug} />
|
2017-12-04 22:21:02 -05:00
|
|
|
{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-10-26 19:13:56 -04:00
|
|
|
}
|
2017-07-07 13:28:29 -04:00
|
|
|
|
|
|
|
|
module.exports = Header;
|