|
1 | | -import React from "react"; |
| 1 | +import React, { CSSProperties, ComponentType, SVGProps } from "react"; |
2 | 2 | import clsx from "clsx"; |
3 | 3 | import styles from "./styles.module.scss"; |
4 | 4 | import DocumentsSvg from "@site/static/img/documents-icon.svg"; |
5 | 5 |
|
| 6 | +const icons: Record<string, ComponentType<SVGProps<SVGSVGElement>>> = { |
| 7 | + documents: DocumentsSvg, |
| 8 | +}; |
| 9 | + |
6 | 10 | type DocsBannerProps = { |
7 | 11 | title: string; |
8 | 12 | description: string; |
| 13 | + icon?: string; |
| 14 | + backgroundColor?: string; |
| 15 | + backgroundColorDark?: string; |
9 | 16 | }; |
10 | 17 |
|
11 | 18 | export default function DocsBanner({ |
12 | 19 | title, |
13 | 20 | description, |
| 21 | + icon, |
| 22 | + backgroundColor, |
| 23 | + backgroundColorDark, |
14 | 24 | }: DocsBannerProps): JSX.Element { |
| 25 | + const Icon = (icon && icons[icon]) || icons.documents; |
| 26 | + |
| 27 | + backgroundColor ||= "var(--c-dirty-socks)"; // default banner bg color |
| 28 | + backgroundColorDark ||= "var(--c-primary-gray)"; // default banner bg color dark theme |
| 29 | + |
15 | 30 | //remove the dulpicate html <header> + h1 tags within the .markdown |
16 | 31 | React.useEffect(() => { |
17 | 32 | const header = document.querySelector(".markdown > header"); |
18 | | - if (header) { |
19 | | - header.remove(); |
20 | | - } |
| 33 | + if (header) header.remove(); |
21 | 34 | }, []); |
22 | 35 |
|
23 | 36 | return ( |
24 | | - <header className={clsx(styles.docsBanner)}> |
| 37 | + <header |
| 38 | + className={clsx(styles.docsBanner)} |
| 39 | + style={ |
| 40 | + { |
| 41 | + "--bg-docs-banner": backgroundColor, |
| 42 | + "--bg-docs-banner-dark": backgroundColorDark, |
| 43 | + } as CSSProperties |
| 44 | + } |
| 45 | + > |
25 | 46 | <div className={styles.docsBannerLeft}> |
26 | 47 | <h1 className="type-gamma">{title}</h1> |
27 | 48 | <p className="type-paragraph">{description}</p> |
28 | 49 | </div> |
29 | | - <DocumentsSvg className={styles.icon} /> |
| 50 | + |
| 51 | + <Icon className={styles.icon} /> |
30 | 52 | </header> |
31 | 53 | ); |
32 | 54 | } |
0 commit comments