Skip to content

Commit

Permalink
[docs-theme] adjust HeadingTag impl, fix #4342
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Oct 25, 2023
1 parent a6d197a commit 67d9133
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/docs-theme/src/tags/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { TypescriptExample } from "./typescript";
export function createDefaultRenderers(): Record<string, React.ComponentType<Tag>> {
return {
css: CssExample,
// HACKHACK https://github.com/palantir/blueprint/issues/4342
heading: Heading as React.ComponentType<Tag>,
heading: Heading,
interface: TypescriptExample,
method: Method,
page: () => null,
Expand Down
21 changes: 14 additions & 7 deletions packages/docs-theme/src/tags/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { HeadingTag } from "@documentalist/client";
import { isHeadingTag, type Tag } from "@documentalist/client";
import classNames from "classnames";
import * as React from "react";

Expand All @@ -23,15 +23,22 @@ import { Link } from "@blueprintjs/icons";

import { COMPONENT_DISPLAY_NAMESPACE } from "../common";

export const Heading: React.FC<HeadingTag> = ({ level, route, value }) =>
// use createElement so we can dynamically choose tag based on depth
React.createElement(
`h${level}`,
{ className: classNames(Classes.HEADING, "docs-title") },
export const Heading: React.FC<Tag> = props => {
if (!isHeadingTag(props)) {
return null;
}

const { level, route, value } = props;
const className = classNames(Classes.HEADING, "docs-title");
const children = [
<a className="docs-anchor" data-route={route} key="anchor" />,
<a className="docs-anchor-link" href={"#" + route} key="link">
<Link />
</a>,
value,
);
];

// use createElement so we can dynamically choose tag based on depth
return React.createElement(`h${level}`, { className }, children);
};
Heading.displayName = `${COMPONENT_DISPLAY_NAMESPACE}.Heading`;

0 comments on commit 67d9133

Please sign in to comment.