hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { Show } from "solid-js"; |
| 2 | import { Dynamic } from "solid-js/web"; |
| 3 | import type { JSX } from "solid-js"; |
| 4 | import { Illustration } from "@/components/ui/illustration"; |
| 5 | import { cn } from "@/lib/cn"; |
| 6 | import type { IllustrationName } from "@/lib/illustrations"; |
| 7 | |
| 8 | export type EmptyStateKind = |
| 9 | | "default" |
| 10 | | "search" |
| 11 | | "notes" |
| 12 | | "exams" |
| 13 | | "events" |
| 14 | | "courses" |
| 15 | | "messages" |
| 16 | | "meals" |
| 17 | | "homework" |
| 18 | | "payments" |
| 19 | | "people" |
| 20 | | "schedule" |
| 21 | | "whiteboard" |
| 22 | | "work" |
| 23 | | "coming-soon" |
| 24 | | "error"; |
| 25 | |
| 26 | const KIND_ILLUSTRATION: Record<EmptyStateKind, IllustrationName> = { |
| 27 | default: "empty", |
| 28 | search: "no-results", |
| 29 | notes: "notes", |
| 30 | exams: "exams", |
| 31 | events: "events", |
| 32 | courses: "courses", |
| 33 | messages: "messages", |
| 34 | meals: "meals", |
| 35 | homework: "homework", |
| 36 | payments: "payments", |
| 37 | people: "people", |
| 38 | schedule: "schedule", |
| 39 | whiteboard: "whiteboard", |
| 40 | work: "work", |
| 41 | "coming-soon": "coming-soon", |
| 42 | error: "server-down", |
| 43 | }; |
| 44 | |
| 45 | /** Empty panel with a theme-tinted illustration matching what is missing. */ |
| 46 | export function EmptyState(props: { |
| 47 | title: string; |
| 48 | /** Small line above the title, e.g. the "404" of the not-found page. */ |
| 49 | eyebrow?: string; |
| 50 | /** Render the title as the page's h1 (full-page states that own the page). */ |
| 51 | pageHeading?: boolean; |
| 52 | description?: string; |
| 53 | kind?: EmptyStateKind; |
| 54 | /** A way out, e.g. "clear search" under a no-results panel. */ |
| 55 | action?: JSX.Element; |
| 56 | class?: string; |
| 57 | }) { |
| 58 | const kind = () => props.kind ?? "default"; |
| 59 | |
| 60 | return ( |
| 61 | <div |
| 62 | class={cn( |
| 63 | "empty-state flex min-h-[289px] flex-col items-center justify-center gap-5 rounded-xl border border-border-hairline bg-surface-base px-10 py-12 text-center", |
| 64 | props.class, |
| 65 | )} |
| 66 | > |
| 67 | <Illustration name={KIND_ILLUSTRATION[kind()]} class="h-32 w-48 sm:h-36 sm:w-56" /> |
| 68 | |
| 69 | <div class="space-y-1.5"> |
| 70 | <Show when={props.eyebrow}> |
| 71 | <p class="text-3xl font-semibold tracking-tight text-text-strong">{props.eyebrow}</p> |
| 72 | </Show> |
| 73 | <Dynamic |
| 74 | component={props.pageHeading ? "h1" : "p"} |
| 75 | class="text-lg font-semibold leading-7 tracking-[-0.015em] text-text-strong" |
| 76 | > |
| 77 | {props.title} |
| 78 | </Dynamic> |
| 79 | <Show when={props.description}> |
| 80 | <p class="mx-auto max-w-[420px] text-sm leading-[21px] text-text-subtle">{props.description}</p> |
| 81 | </Show> |
| 82 | </div> |
| 83 | <Show when={props.action}>{props.action}</Show> |
| 84 | </div> |
| 85 | ); |
| 86 | } |