@insymetri/styleguide 0.1.74 → 0.1.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,17 +1,124 @@
|
|
|
1
|
-
<script lang="ts">
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
2
|
import type {Snippet} from 'svelte'
|
|
3
3
|
import {cn} from '../utils/cn'
|
|
4
|
+
import IITableSkeleton from '../IITableSkeleton/IITableSkeleton.svelte'
|
|
5
|
+
|
|
6
|
+
type Column = {
|
|
7
|
+
/** Stable id (used as the header key today; the sort key when sorting lands). */
|
|
8
|
+
key: string
|
|
9
|
+
header: string
|
|
10
|
+
/** Renders the cell content for a row — badges, buttons, editable text, etc. */
|
|
11
|
+
cell: Snippet<[T]>
|
|
12
|
+
align?: 'left' | 'right' | 'center'
|
|
13
|
+
/** Width utility, e.g. `w-120` / `min-w-180`, and responsive hides like `max-md:hidden`. */
|
|
14
|
+
width?: string
|
|
15
|
+
/** Extra classes on the `<td>`, static or per-row (e.g. `text-secondary`, `font-mono`). */
|
|
16
|
+
class?: string | ((row: T) => string)
|
|
17
|
+
/** Extra classes on the `<th>`. */
|
|
18
|
+
headerClass?: string
|
|
19
|
+
}
|
|
4
20
|
|
|
5
21
|
type Props = {
|
|
6
|
-
|
|
22
|
+
columns: Column[]
|
|
23
|
+
rows: T[]
|
|
24
|
+
rowKey: (row: T) => string
|
|
25
|
+
loading?: boolean
|
|
26
|
+
loadingRows?: number
|
|
27
|
+
/** Rendered (spanning all columns) when there are no rows and not loading. */
|
|
28
|
+
empty?: Snippet
|
|
29
|
+
onRowClick?: (row: T, event: MouseEvent) => void
|
|
30
|
+
/** Per-row class for states like dimmed/disabled (e.g. `opacity-60`). */
|
|
31
|
+
rowClass?: (row: T) => string | false | undefined | null
|
|
32
|
+
/** Optional expandable content rendered as a spanning row beneath an expanded row. */
|
|
33
|
+
expandedRow?: Snippet<[T]>
|
|
34
|
+
isExpanded?: (row: T) => boolean
|
|
35
|
+
stickyHeader?: boolean
|
|
36
|
+
/** `sm` → text-small (default), `md` → text-default. */
|
|
37
|
+
size?: 'sm' | 'md'
|
|
7
38
|
class?: string
|
|
8
39
|
}
|
|
9
40
|
|
|
10
|
-
let {
|
|
41
|
+
let {
|
|
42
|
+
columns,
|
|
43
|
+
rows,
|
|
44
|
+
rowKey,
|
|
45
|
+
loading = false,
|
|
46
|
+
loadingRows = 5,
|
|
47
|
+
empty,
|
|
48
|
+
onRowClick,
|
|
49
|
+
rowClass,
|
|
50
|
+
expandedRow,
|
|
51
|
+
isExpanded,
|
|
52
|
+
stickyHeader = false,
|
|
53
|
+
size = 'sm',
|
|
54
|
+
class: className,
|
|
55
|
+
}: Props = $props()
|
|
56
|
+
|
|
57
|
+
const alignClass = {left: 'text-left', right: 'text-right', center: 'text-center'} as const
|
|
58
|
+
const cellText = $derived(size === 'sm' ? 'text-small' : 'text-default')
|
|
59
|
+
const interactive = $derived(!!onRowClick)
|
|
60
|
+
|
|
61
|
+
function cellClass(col: Column, row: T): string {
|
|
62
|
+
return typeof col.class === 'function' ? col.class(row) : (col.class ?? '')
|
|
63
|
+
}
|
|
11
64
|
</script>
|
|
12
65
|
|
|
13
66
|
<div class={cn('bg-surface border border-primary rounded-10 overflow-x-auto overflow-y-hidden', className)}>
|
|
14
67
|
<table class="w-full border-collapse">
|
|
15
|
-
{
|
|
68
|
+
<thead class={cn('bg-background border-b border-primary', stickyHeader && 'sticky top-0 z-1')}>
|
|
69
|
+
<tr>
|
|
70
|
+
{#each columns as col (col.key)}
|
|
71
|
+
<th
|
|
72
|
+
class={cn(
|
|
73
|
+
'px-16 py-8 text-tiny-strong text-secondary uppercase',
|
|
74
|
+
alignClass[col.align ?? 'left'],
|
|
75
|
+
col.width,
|
|
76
|
+
col.headerClass
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
{col.header}
|
|
80
|
+
</th>
|
|
81
|
+
{/each}
|
|
82
|
+
</tr>
|
|
83
|
+
</thead>
|
|
84
|
+
<tbody>
|
|
85
|
+
{#if loading}
|
|
86
|
+
<IITableSkeleton rows={loadingRows} columns={columns.map(() => 'text')} />
|
|
87
|
+
{:else if rows.length === 0}
|
|
88
|
+
{#if empty}
|
|
89
|
+
<tr>
|
|
90
|
+
<td colspan={columns.length} class="px-16 py-32 text-center">
|
|
91
|
+
{@render empty()}
|
|
92
|
+
</td>
|
|
93
|
+
</tr>
|
|
94
|
+
{/if}
|
|
95
|
+
{:else}
|
|
96
|
+
{#each rows as row (rowKey(row))}
|
|
97
|
+
<tr
|
|
98
|
+
class={cn(
|
|
99
|
+
'border-b border-primary last:border-b-0',
|
|
100
|
+
interactive && 'cursor-pointer hover:bg-background',
|
|
101
|
+
rowClass?.(row)
|
|
102
|
+
)}
|
|
103
|
+
style="transition: background-color var(--transition-fast)"
|
|
104
|
+
onclick={onRowClick ? e => onRowClick(row, e) : undefined}
|
|
105
|
+
onauxclick={onRowClick ? e => onRowClick(row, e) : undefined}
|
|
106
|
+
>
|
|
107
|
+
{#each columns as col (col.key)}
|
|
108
|
+
<td class={cn('px-16 py-8 text-body', cellText, alignClass[col.align ?? 'left'], col.width, cellClass(col, row))}>
|
|
109
|
+
{@render col.cell(row)}
|
|
110
|
+
</td>
|
|
111
|
+
{/each}
|
|
112
|
+
</tr>
|
|
113
|
+
{#if expandedRow && isExpanded?.(row)}
|
|
114
|
+
<tr class="border-b border-primary last:border-b-0 bg-background">
|
|
115
|
+
<td colspan={columns.length} class="px-16 py-12">
|
|
116
|
+
{@render expandedRow(row)}
|
|
117
|
+
</td>
|
|
118
|
+
</tr>
|
|
119
|
+
{/if}
|
|
120
|
+
{/each}
|
|
121
|
+
{/if}
|
|
122
|
+
</tbody>
|
|
16
123
|
</table>
|
|
17
124
|
</div>
|
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
declare function $$render<T>(): {
|
|
3
|
+
props: {
|
|
4
|
+
columns: {
|
|
5
|
+
/** Stable id (used as the header key today; the sort key when sorting lands). */
|
|
6
|
+
key: string;
|
|
7
|
+
header: string;
|
|
8
|
+
/** Renders the cell content for a row — badges, buttons, editable text, etc. */
|
|
9
|
+
cell: Snippet<[T]>;
|
|
10
|
+
align?: "left" | "right" | "center";
|
|
11
|
+
/** Width utility, e.g. `w-120` / `min-w-180`, and responsive hides like `max-md:hidden`. */
|
|
12
|
+
width?: string;
|
|
13
|
+
/** Extra classes on the `<td>`, static or per-row (e.g. `text-secondary`, `font-mono`). */
|
|
14
|
+
class?: string | ((row: T) => string);
|
|
15
|
+
/** Extra classes on the `<th>`. */
|
|
16
|
+
headerClass?: string;
|
|
17
|
+
}[];
|
|
18
|
+
rows: T[];
|
|
19
|
+
rowKey: (row: T) => string;
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
loadingRows?: number;
|
|
22
|
+
/** Rendered (spanning all columns) when there are no rows and not loading. */
|
|
23
|
+
empty?: Snippet;
|
|
24
|
+
onRowClick?: (row: T, event: MouseEvent) => void;
|
|
25
|
+
/** Per-row class for states like dimmed/disabled (e.g. `opacity-60`). */
|
|
26
|
+
rowClass?: (row: T) => string | false | undefined | null;
|
|
27
|
+
/** Optional expandable content rendered as a spanning row beneath an expanded row. */
|
|
28
|
+
expandedRow?: Snippet<[T]>;
|
|
29
|
+
isExpanded?: (row: T) => boolean;
|
|
30
|
+
stickyHeader?: boolean;
|
|
31
|
+
/** `sm` → text-small (default), `md` → text-default. */
|
|
32
|
+
size?: "sm" | "md";
|
|
33
|
+
class?: string;
|
|
34
|
+
};
|
|
35
|
+
exports: {};
|
|
36
|
+
bindings: "";
|
|
37
|
+
slots: {};
|
|
38
|
+
events: {};
|
|
5
39
|
};
|
|
6
|
-
declare
|
|
7
|
-
|
|
40
|
+
declare class __sveltets_Render<T> {
|
|
41
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
42
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
43
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
44
|
+
bindings(): "";
|
|
45
|
+
exports(): {};
|
|
46
|
+
}
|
|
47
|
+
interface $$IsomorphicComponent {
|
|
48
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
49
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
50
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
51
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
52
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
53
|
+
}
|
|
54
|
+
declare const IITable: $$IsomorphicComponent;
|
|
55
|
+
type IITable<T> = InstanceType<typeof IITable<T>>;
|
|
8
56
|
export default IITable;
|
package/dist/style/colors.css
CHANGED