fix: filter out empty children
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
import { Children } from "react"
|
|
||||||
|
|
||||||
|
import { checkForEmptyChildren } from "../../utils/checkForEmptyChildren"
|
||||||
import { subtitleVariants } from "./variants"
|
import { subtitleVariants } from "./variants"
|
||||||
|
|
||||||
import type { SubtitleProps } from "./subtitle"
|
import type { SubtitleProps } from "./subtitle"
|
||||||
@@ -13,7 +13,7 @@ export default function Subtitle({
|
|||||||
textTransform,
|
textTransform,
|
||||||
...props
|
...props
|
||||||
}: SubtitleProps) {
|
}: SubtitleProps) {
|
||||||
if (Children.toArray(props.children).length === 0) {
|
if (checkForEmptyChildren(props.children) === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const Comp = asChild ? Slot : "p"
|
const Comp = asChild ? Slot : "p"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Children } from "react"
|
import { checkForEmptyChildren } from "../../utils/checkForEmptyChildren"
|
||||||
|
|
||||||
import { headingVariants } from "./variants"
|
import { headingVariants } from "./variants"
|
||||||
|
|
||||||
import type { HeadingProps } from "./title"
|
import type { HeadingProps } from "./title"
|
||||||
@@ -13,7 +12,7 @@ export default function Title({
|
|||||||
textAlign,
|
textAlign,
|
||||||
textTransform,
|
textTransform,
|
||||||
}: HeadingProps) {
|
}: HeadingProps) {
|
||||||
if (Children.toArray(children).length === 0) {
|
if (checkForEmptyChildren(children) === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const Hx = level
|
const Hx = level
|
||||||
|
|||||||
13
components/TempDesignSystem/utils/checkForEmptyChildren.ts
Normal file
13
components/TempDesignSystem/utils/checkForEmptyChildren.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Children, type ReactNode } from "react"
|
||||||
|
|
||||||
|
export function checkForEmptyChildren(children: ReactNode) {
|
||||||
|
return Children.toArray(children).filter((child) => {
|
||||||
|
if (child === "") {
|
||||||
|
return false
|
||||||
|
} else if (child == null) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}).length
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user