import "./Card.css"; import { ComponentChildren, createContext } from "preact"; import { JSX } from "preact"; import { useContext } from "preact/hooks"; import clsx from "clsx"; interface CardProps { className?: string; } export function Card(props: {children: ComponentChildren} & CardProps) { return
{props.children}
; } interface CardSectionProps { className?: string; subSections?: JSX.Element | JSX.Element[]; childrenVisible?: boolean; hasAction: boolean; onAction?: () => void; } export function CardSection(props: {children: ComponentChildren} & CardSectionProps) { const parentContext = useContext(CardSectionContext); const nestingLevel = (parentContext && parentContext.nestingLevel + 1) ?? 0; return <>
0, "tn-action": props?.hasAction} ], props.className)} style={"--tn-card-section-nesting-level: " + nestingLevel} onClick={() => {props.onAction?.()}}> {props.children}
{props?.childrenVisible && {props.subSections} } ; } interface CardSectionContextType { nestingLevel: number; } export const CardSectionContext = createContext(undefined);