1
0
mirror of https://gitlab.com/MisterBiggs/brain-quartz.git synced 2025-07-25 07:41:30 +00:00

feat: conditional render component

This commit is contained in:
Jacky Zhao
2025-03-23 17:34:14 -07:00
parent 4e74d11b1a
commit aaa5c8e8e4
5 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
type ConditionalRenderConfig = {
component: QuartzComponent
condition: (props: QuartzComponentProps) => boolean
}
export default ((config: ConditionalRenderConfig) => {
const ConditionalRender: QuartzComponent = (props: QuartzComponentProps) => {
if (config.condition(props)) {
return <config.component {...props} />
}
return null
}
ConditionalRender.afterDOMLoaded = config.component.afterDOMLoaded
ConditionalRender.beforeDOMLoaded = config.component.beforeDOMLoaded
ConditionalRender.css = config.component.css
return ConditionalRender
}) satisfies QuartzComponentConstructor<ConditionalRenderConfig>