tutu/src/material/typography.tsx

75 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-01-16 22:06:20 +08:00
import { splitProps, type Ref, ComponentProps, ValidComponent } from "solid-js";
2024-07-14 20:28:44 +08:00
import { Dynamic } from "solid-js/web";
2025-01-16 22:06:20 +08:00
export type TypographyProps<E extends ValidComponent> = {
2024-07-14 20:28:44 +08:00
ref?: Ref<E>;
component?: E;
class?: string;
2025-01-16 22:06:20 +08:00
} & ComponentProps<E>;
2024-07-14 20:28:44 +08:00
type TypographyKind =
| "display4"
| "display3"
| "display2"
| "display1"
| "headline"
| "title"
| "subheading"
| "body1"
| "body2"
| "caption"
| "buttonText";
2025-01-16 22:06:20 +08:00
export function Typography<T extends ValidComponent>(
2024-08-05 15:33:00 +08:00
props: { typography: TypographyKind } & TypographyProps<T>,
) {
2024-07-14 20:28:44 +08:00
const [managed, passthough] = splitProps(props, [
"ref",
"component",
"class",
"typography",
]);
return (
<Dynamic
ref={managed.ref}
component={managed.component ?? "span"}
2024-11-06 19:38:34 +08:00
class={`${managed.class || ""} ${managed.typography}`}
2024-07-14 20:28:44 +08:00
{...passthough}
></Dynamic>
);
2024-08-05 15:33:00 +08:00
}
2024-07-14 20:28:44 +08:00
2025-01-16 22:06:20 +08:00
export function Display4<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"display4"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Display3<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"display3"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Display2<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"display2"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Display1<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"display1"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Headline<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"headline"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Title<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"title"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Subheading<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"subheading"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Body1<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"body1"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Body2<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"body2"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function Caption<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"caption"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}
2025-01-16 22:06:20 +08:00
export function ButtonText<E extends ValidComponent>(props: TypographyProps<E>) {
2024-08-05 15:33:00 +08:00
return <Typography typography={"buttonText"} {...props}></Typography>;
2024-07-14 20:28:44 +08:00
}