Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client: define the foundation of sectioned cards with multi-level nesting
Adorian Doranb618e5a00f6c
diff --git a/apps/client/src/widgets/react/Card.css b/apps/client/src/widgets/react/Card.cssnew file mode 100644index 0000000000..ea906cc0a8--- /dev/null+++ b/apps/client/src/widgets/react/Card.css@@ -0,0 +1,36 @@+.tn-card {+ --card-border-radius: 8px;+ --card-padding: 8px 16px;+ --card-section-gap: 3px;++ display: flex;+ flex-direction: column;+ gap: var(--card-section-gap);++ .tn-card-section {+ padding: var(--card-padding);+ border: 1px solid var(--card-border-color);+ background: var(--card-background-color);++ &:first-of-type {+ border-top-left-radius: var(--card-border-radius);+ border-top-right-radius: var(--card-border-radius);+ }++ &:last-of-type {+ border-bottom-left-radius: var(--card-border-radius);+ border-bottom-right-radius: var(--card-border-radius);+ }++ &.tn-card-section-nested {+ padding-left: calc(30px * var(--tn-card-section-nesting-level));+ opacity: .5;+ }++ &.tn-action:hover {+ background-color: var(--card-background-hover-color);+ transition: background-color .2s ease-out;+ }++ }+}\ No newline at end of filediff --git a/apps/client/src/widgets/react/Card.tsx b/apps/client/src/widgets/react/Card.tsxnew file mode 100644index 0000000000..fa6a0f489f--- /dev/null+++ b/apps/client/src/widgets/react/Card.tsx@@ -0,0 +1,43 @@+import "./Card.css";+import { ComponentChildren, createContext } from "preact";+import { JSX } from "preact";+import { useContext } from "preact/hooks";+import clsx from "clsx";++interface CardProps {+}++export function Card(props: {children: ComponentChildren} & CardProps) {+ return <div className="tn-card">+ {props.children}+ </div>;+}++interface CardSectionProps {+ subSections?: JSX.Element | JSX.Element[];+ childrenVisible?: boolean;+}++export function CardSection(props: {children: ComponentChildren} & CardSectionProps) {+ const parentContext = useContext(CardSectionContext);+ const nestingLevel = (parentContext && parentContext.nestingLevel + 1) ?? 0;++ return <>+ <section className={clsx(["tn-card-section", {"tn-card-section-nested": nestingLevel > 0}])}+ style={"--tn-card-section-nesting-level: " + nestingLevel}>+ {props.children} {nestingLevel}+ </section>++ {props?.childrenVisible &&+ <CardSectionContext.Provider value={{nestingLevel}}>+ {props.subSections}+ </CardSectionContext.Provider>+ }+ </>;+}++interface CardSectionContextType {+ nestingLevel: number;+}++export const CardSectionContext = createContext<CardSectionContextType | undefined>(undefined);\ No newline at end of file