import "./Card.css"; import { ComponentChildren, createContext } from "preact"; import { JSX, HTMLAttributes } from "preact"; import { useContext } from "preact/hooks"; import clsx from "clsx"; // #region Card Frame export interface CardFrameProps extends HTMLAttributes { className?: string; highlightOnHover?: boolean; children: ComponentChildren; } export function CardFrame({className, highlightOnHover, children, ...rest}: CardFrameProps) { return
{children}
; } // #endregion // #region Card export interface CardProps { className?: string; heading?: string; } export function Card(props: {children: ComponentChildren} & CardProps) { return
{props.heading &&
{props.heading}
}
{props.children}
; } // #endregion // #region Card Section export interface CardSectionProps { className?: string; subSections?: JSX.Element | JSX.Element[]; subSectionsVisible?: boolean; highlightOnHover?: boolean; onAction?: () => void; } interface CardSectionContextType { nestingLevel: number; } const CardSectionContext = createContext(undefined); export function CardSection(props: {children: ComponentChildren} & CardSectionProps) { const parentContext = useContext(CardSectionContext); const nestingLevel = (parentContext && parentContext.nestingLevel + 1) ?? 0; return <>
0, "tn-card-highlight-on-hover": props.highlightOnHover || props.onAction })} style={{"--tn-card-section-nesting-level": (nestingLevel) ? nestingLevel : null}} onClick={props.onAction}> {props.children}
{props.subSectionsVisible && props.subSections && {props.subSections} } ; } // #endregion