Lumen Yang
2025-09-05 a4028289aae22f2a073b2837c3a85d9fc4a86087
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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>