release(tach-typography): v0.3.0
This commit is contained in:
@@ -7,6 +7,7 @@ import type { TextProps } from "antd/lib/typography/Text";
|
||||
import type { TitleProps } from "antd/lib/typography/Title";
|
||||
|
||||
import {
|
||||
tachTypographyMarkdownToHtml,
|
||||
tachTypographyClassName,
|
||||
type TypographyColor,
|
||||
type TypographyVariant,
|
||||
@@ -18,6 +19,8 @@ interface AdditionalProps {
|
||||
weight?: TypographyWeight;
|
||||
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
||||
className?: string | undefined;
|
||||
markdownEnabled?: boolean;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const createTypographyVariant = <P extends object>(
|
||||
@@ -25,20 +28,45 @@ const createTypographyVariant = <P extends object>(
|
||||
variant: TypographyVariant,
|
||||
) => {
|
||||
const Variant = React.forwardRef<HTMLElement, P & AdditionalProps>(
|
||||
({ color = "primary", weight = "normal", className, onClick, ...rest }, ref) => (
|
||||
<Component
|
||||
ref={ref as never}
|
||||
className={tachTypographyClassName({
|
||||
variant,
|
||||
color,
|
||||
weight,
|
||||
className,
|
||||
clickable: Boolean(onClick),
|
||||
})}
|
||||
onClick={onClick}
|
||||
{...(rest as P)}
|
||||
/>
|
||||
),
|
||||
(
|
||||
{
|
||||
color = "primary",
|
||||
weight = "normal",
|
||||
className,
|
||||
onClick,
|
||||
markdownEnabled = false,
|
||||
children,
|
||||
...rest
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const markdownHtml =
|
||||
markdownEnabled && typeof children === "string"
|
||||
? tachTypographyMarkdownToHtml(children)
|
||||
: undefined;
|
||||
const renderedChildren = markdownHtml ? (
|
||||
<span dangerouslySetInnerHTML={{ __html: markdownHtml }} />
|
||||
) : (
|
||||
children
|
||||
);
|
||||
const contentProps = { children: renderedChildren } as unknown as P;
|
||||
|
||||
return (
|
||||
<Component
|
||||
ref={ref as never}
|
||||
className={tachTypographyClassName({
|
||||
variant,
|
||||
color,
|
||||
weight,
|
||||
className,
|
||||
clickable: Boolean(onClick),
|
||||
})}
|
||||
onClick={onClick}
|
||||
{...(rest as P)}
|
||||
{...contentProps}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Variant.displayName = String(variant);
|
||||
|
||||
Reference in New Issue
Block a user