Skip to content

Commit

Permalink
feat: Add support for className in Title.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
natemate90 committed Jan 10, 2025
1 parent e06f549 commit f912c44
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions nextjs/src/components/title.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cva, VariantProps } from "class-variance-authority"
import clsx from "clsx"
import React from "react"
import Markdown from "react-markdown"
import remarkGfm from "remark-gfm"
Expand Down Expand Up @@ -32,13 +33,21 @@ const titleStyles = cva(["tracking-tight text-title-primary"], {
*/
type ChildrenORString =
| {
children: React.ReactNode
markdown?: never
}
children: React.ReactNode
markdown?: never
/**
* @warning only use className for positioning utilities.
*/
className?: string
}
| {
markdown: string
children?: never
}
markdown: string
children?: never
/**
* @warning only use className for positioning utilities.
*/
className?: string
}
type TitleProps = VariantProps<typeof titleStyles> & ChildrenORString

/**
Expand All @@ -53,6 +62,7 @@ const Title: React.FC<TitleProps> = ({
children,
markdown,
boldness,
className
}) => {
if (markdown) {
const headingLevel = markdown.startsWith("###")
Expand All @@ -64,15 +74,15 @@ const Title: React.FC<TitleProps> = ({
return (
<Markdown
remarkPlugins={[remarkGfm]}
className={titleStyles({ level: headingLevel, align, boldness })}
className={clsx([titleStyles({ level: headingLevel, align, boldness }), className])}
>
{markdown}
</Markdown>
)
}
const Tag = `h${level || 2}` as keyof JSX.IntrinsicElements
return (
<Tag className={titleStyles({ level, align, boldness })}>{children}</Tag>
<Tag className={clsx([titleStyles({ level, align, boldness })], className)}>{children}</Tag>
)
}

Expand Down

0 comments on commit f912c44

Please sign in to comment.