From da5cb8ae7d5990643c34c08b018994b384eb025d Mon Sep 17 00:00:00 2001 From: Julien Rousseau Date: Thu, 30 Nov 2023 00:02:15 -0500 Subject: [PATCH] create details ui component --- web/src/modules/ui/details.tsx | 104 ++++++++++++++++++++++++++++++++ web/src/modules/ui/index.ts | 1 + web/src/resources/formatters.ts | 5 ++ 3 files changed, 110 insertions(+) create mode 100644 web/src/modules/ui/details.tsx create mode 100644 web/src/resources/formatters.ts diff --git a/web/src/modules/ui/details.tsx b/web/src/modules/ui/details.tsx new file mode 100644 index 0000000..35eaa44 --- /dev/null +++ b/web/src/modules/ui/details.tsx @@ -0,0 +1,104 @@ +import { A } from "@solidjs/router"; +import { Component, For, Match, Show, Switch, ValidComponent } from "solid-js"; +import { Dynamic } from "solid-js/web"; +import { z } from "zod"; +import { Icon } from "./icon"; + +type Linkify> = Partial<{ + [K in keyof T]: T[K] extends Record ? Linkify : string; +}>; + +type DetailsProps> = { + header?: string[]; + data: T; + links?: Linkify; + depth?: number; +}; + +export const Details = >( + props: DetailsProps, +) => { + return ( +
    + + + {([key, value]) => ( + + )} + +
+ ); +}; + +// TODO +const DetailsHeader: Component<{ header?: string[] }> = (props) => { + return ( + 0}> +
  • + {(heading) =>

    {heading}

    }
    +
  • +
    + ); +}; + +type DetailsRowProps = { + label: string; + value: unknown; + depth: number; + links?: Record | string; +}; + +const DetailsRow: Component = (props) => { + const hasLink = typeof props.links === "string"; + + const Inner = () => ( +
    + + {props.label} + + + + +
    + {String(props.value)}}> + + + + + +
    } + links={(props.links as any)?.[props.label]} + depth={props.depth + 1} + /> + + +
    +
    + ); + + return ( +
  • 1, + }} + > + }> + + + + +
  • + ); +}; diff --git a/web/src/modules/ui/index.ts b/web/src/modules/ui/index.ts index 843c8a9..6bbcb91 100644 --- a/web/src/modules/ui/index.ts +++ b/web/src/modules/ui/index.ts @@ -1,6 +1,7 @@ export * from "./accordion"; export * from "./backdrop"; export * from "./card"; +export * from "./details"; export * from "./icon"; export * from "./no-content"; export * from "./skeleton"; diff --git a/web/src/resources/formatters.ts b/web/src/resources/formatters.ts new file mode 100644 index 0000000..6afaf1a --- /dev/null +++ b/web/src/resources/formatters.ts @@ -0,0 +1,5 @@ +export const dateFormatter = new Intl.DateTimeFormat("fr-CA", {}); +export const moneyFormatter = new Intl.NumberFormat("fr-CA", { + style: "currency", + currency: "CAD", +});