hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits
| 1 | import { For, Show, type Component } from "solid-js"; |
| 2 | import { cn } from "@/lib/cn"; |
| 3 | import { useT } from "@/stores/preferences-context"; |
| 4 | |
| 5 | export type ProgressRingSegment = { |
| 6 | id: string; |
| 7 | label: string; |
| 8 | value: number; |
| 9 | colorClass: string; |
| 10 | }; |
| 11 | |
| 12 | export type ChartProgressRingProps = { |
| 13 | title?: string; |
| 14 | subtitle?: string; |
| 15 | valueText?: string; |
| 16 | subtext?: string; |
| 17 | segments: ProgressRingSegment[]; |
| 18 | total?: number; |
| 19 | class?: string; |
| 20 | }; |
| 21 | |
| 22 | export const ChartProgressRing: Component<ChartProgressRingProps> = (props) => { |
| 23 | const t = useT(); |
| 24 | const calculatedTotal = () => props.total ?? props.segments.reduce((acc, s) => acc + s.value, 0); |
| 25 | |
| 26 | return ( |
| 27 | <div class={cn("flex flex-col gap-4 rounded-lg border border-border bg-card p-4 shadow-sm", props.class)}> |
| 28 | <Show when={props.title}> |
| 29 | <div class="border-b border-border pb-3"> |
| 30 | <div> |
| 31 | <h3 class="text-sm font-semibold tracking-tight text-foreground">{props.title}</h3> |
| 32 | <Show when={props.subtitle}> |
| 33 | <p class="text-xs text-muted-foreground mt-0.5">{props.subtitle}</p> |
| 34 | </Show> |
| 35 | </div> |
| 36 | </div> |
| 37 | </Show> |
| 38 | |
| 39 | <Show |
| 40 | when={calculatedTotal() > 0} |
| 41 | fallback={ |
| 42 | <div class="px-4 py-8 text-center"> |
| 43 | <p class="text-xs font-semibold text-foreground/80">{t("dashboard.chartEmpty")}</p> |
| 44 | <p class="text-[11px] text-muted-foreground mt-0.5">{t("dashboard.chartEmptyHint")}</p> |
| 45 | </div> |
| 46 | } |
| 47 | > |
| 48 | <div class="flex flex-col justify-between gap-4 py-1"> |
| 49 | {/* Total Stat Highlight */} |
| 50 | <div class="flex items-baseline gap-2"> |
| 51 | <span class="font-mono text-3xl font-bold tracking-tight text-foreground"> |
| 52 | {props.valueText ?? calculatedTotal()} |
| 53 | </span> |
| 54 | <Show when={props.subtext}> |
| 55 | <span class="text-xs font-medium text-muted-foreground">{props.subtext}</span> |
| 56 | </Show> |
| 57 | </div> |
| 58 | |
| 59 | {/* Multi-Segmented Progress Gauge Bar */} |
| 60 | <div class="flex h-3.5 w-full overflow-hidden rounded-full bg-muted/60 dark:bg-muted/40 p-0.5 border border-border/40"> |
| 61 | <For each={props.segments}> |
| 62 | {(segment) => { |
| 63 | const pct = () => (calculatedTotal() > 0 ? (segment.value / calculatedTotal()) * 100 : 0); |
| 64 | return ( |
| 65 | <Show when={pct() > 0}> |
| 66 | <div |
| 67 | class={cn("h-full rounded-full transition-all duration-500 ease-out", segment.colorClass)} |
| 68 | style={{ width: `${pct()}%` }} |
| 69 | title={`${segment.label}: ${segment.value} (${Math.round(pct())}%)`} |
| 70 | /> |
| 71 | </Show> |
| 72 | ); |
| 73 | }} |
| 74 | </For> |
| 75 | </div> |
| 76 | |
| 77 | {/* Legend Grid */} |
| 78 | <div class="grid grid-cols-2 gap-2 pt-1 sm:grid-cols-2"> |
| 79 | <For each={props.segments}> |
| 80 | {(segment) => ( |
| 81 | <div class="flex items-center justify-between rounded-xl border border-border/40 bg-muted/30 px-3 py-2 text-xs"> |
| 82 | <div class="flex items-center gap-2 truncate"> |
| 83 | <span class={cn("h-2.5 w-2.5 shrink-0 rounded-full", segment.colorClass)} /> |
| 84 | <span class="truncate font-medium text-muted-foreground">{segment.label}</span> |
| 85 | </div> |
| 86 | <span class="font-mono font-semibold text-foreground ml-2">{segment.value}</span> |
| 87 | </div> |
| 88 | )} |
| 89 | </For> |
| 90 | </div> |
| 91 | </div> |
| 92 | </Show> |
| 93 | </div> |
| 94 | ); |
| 95 | }; |