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
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import type { HTMLTag, Polymorphic } from "corvos/plugins/jsx.ts";
export type Props<Tag extends HTMLTag> = Polymorphic<{
as: Tag;
level?: "xxl" | "xl" | "lg" | "md" | "sm" | "xs";
variant?: "static-black" | "static-white";
display?: boolean;
highlight?: boolean;
children?: JSX.Element;
}>;
const levelTagMap = {
lg: "h3",
md: "h4",
sm: "h5",
xl: "h2",
xs: "h6",
xxl: "h1",
} as const;
export const Heading = <T extends HTMLTag = "div">({
as,
children,
display,
level,
variant,
highlight,
class: cls,
...props
}: Props<T>) => {
const Tag = as ?? (level ? levelTagMap[level] : "strong");
return (
<Tag
class:list={[
"o-heading",
{
[`o-heading--${level}`]: level,
[`o-heading--${variant}`]: variant,
"o-heading--display": display,
"u-c-heading": Tag === "strong",
},
cls,
]}
{...props}
>
{highlight ? <span class="o-heading__highlight">{children}</span> : children}
</Tag>
);
};
|