forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

quick-link-column.tsx64 lines, 2.5 KiBHistoryRawDownload
1import { For, Show, onCleanup, type Component } from "solid-js";
2import { EmptyInline } from "@/components/ui/empty-inline";
3import { IconChevronRight } from "@/components/ui/icons";
4import type { IllustrationName } from "@/lib/illustrations";
5
6export type QuickLinkRow = {
7 id: string;
8 primary: string;
9 secondary?: string;
10 Icon: Component<{ class?: string }>;
11};
12
13export type QuickLinkColumnProps = {
14 title: string;
15 rows: QuickLinkRow[];
16 empty: string;
17 illustration?: IllustrationName;
18 onVisible?: () => void;
19 onOpen: (row: QuickLinkRow) => void;
20};
21
22/** Figma "Resource Columns" from ADM-01: a subtle column header and a short
23 * list of resource rows with a trailing caption, each navigating to the
24 * resource's real detail page. */
25export function QuickLinkColumn(props: QuickLinkColumnProps) {
26 const observe = (el: HTMLDivElement) => {
27 if (!props.onVisible) return;
28 if (typeof IntersectionObserver === "undefined") {
29 props.onVisible();
30 return;
31 }
32 const observer = new IntersectionObserver((entries) => {
33 if (entries.some((entry) => entry.isIntersecting)) {
34 observer.disconnect();
35 props.onVisible?.();
36 }
37 }, { rootMargin: "160px" });
38 observer.observe(el);
39 onCleanup(() => observer.disconnect());
40 };
41 return (
42 <div ref={observe} class="flex min-w-0 flex-1 flex-col rounded-xl border border-border-line bg-surface-base px-4 py-3">
43 <p class="pb-2 text-[13px] font-medium text-text-subtle">{props.title}</p>
44 <Show when={props.rows.length > 0} fallback={<EmptyInline class="border-t border-border-hairline" illustration={props.illustration} title={props.empty} />}>
45 <For each={props.rows}>
46 {(row) => (
47 <button
48 type="button"
49 onClick={() => props.onOpen(row)}
50 class="-mx-2 flex w-[calc(100%+1rem)] items-center gap-2.5 border-t border-border-hairline px-2 py-2.5 text-left outline-hidden transition-colors first:border-t-0 hover:bg-surface-tint focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
51 >
52 <row.Icon class="h-[15px] w-[15px] shrink-0 text-text-subtle" />
53 <span class="min-w-0 flex-1 truncate text-sm text-text-default">{row.primary}</span>
54 <Show when={row.secondary}>
55 <span class="shrink-0 text-xs text-text-subtle">{row.secondary}</span>
56 </Show>
57 <IconChevronRight class="h-3 w-3 shrink-0 text-text-subtle" />
58 </button>
59 )}
60 </For>
61 </Show>
62 </div>
63 );
64}