@ahrowe/ui 0.1.6 → 0.1.8

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.
package/docs/Toast.md ADDED
@@ -0,0 +1,68 @@
1
+ # Toast
2
+
3
+ **When to use:** Non-blocking notifications — save confirmations, error alerts, info messages, warnings. Toasts appear in a corner of the screen and auto-dismiss after a configurable duration.
4
+
5
+ **Import:** `import { ToastProvider, showToast } from '@ahrowe/ui'`
6
+ **Types:** `import type { ToastOptions, ToastType, ToastPosition } from '@ahrowe/ui'`
7
+
8
+ **Setup:** Wrap your app with `ToastProvider` (inside `ThemeProvider`):
9
+
10
+ ```tsx
11
+ import { ThemeProvider, ToastProvider } from '@ahrowe/ui';
12
+
13
+ <ThemeProvider>
14
+ <ToastProvider position="bottom-right" duration={3000}>
15
+ <App />
16
+ </ToastProvider>
17
+ </ThemeProvider>
18
+ ```
19
+
20
+ **Usage:** Call `showToast` anywhere — no component hierarchy required:
21
+
22
+ ```tsx
23
+ import { showToast } from '@ahrowe/ui';
24
+
25
+ // Simple message
26
+ showToast('Profile saved!');
27
+
28
+ // With type
29
+ showToast('Something went wrong.', { type: 'error' });
30
+ showToast('3 items updated.', { type: 'info' });
31
+ showToast('Your changes were saved.', { type: 'success' });
32
+ showToast('Disk space is low.', { type: 'warn' });
33
+
34
+ // Persistent (no auto-dismiss)
35
+ showToast('Processing…', { duration: 0, showCloseButton: true });
36
+
37
+ // With progress bar showing remaining time
38
+ showToast('Uploading file…', {
39
+ duration: 5000,
40
+ showRemainingTime: true,
41
+ });
42
+
43
+ // Override position per-toast
44
+ showToast('Copied!', { position: 'top-center', duration: 1500 });
45
+
46
+ // With slot overrides
47
+ showToast('Done', {
48
+ type: 'info',
49
+ classNames: { root: 'my-toast' },
50
+ styles: { progressBar: { backgroundColor: '#6200ea' } },
51
+ });
52
+ ```
53
+
54
+ **ToastProviderProps** (default config for all toasts):
55
+
56
+ | Prop | Type | Default | Description |
57
+ |------|------|---------|-------------|
58
+ | `position` | `ToastPosition` | `'bottom-right'` | Screen position |
59
+ | `duration` | `number` | `3000` | Auto-dismiss delay in ms; `0` = persistent |
60
+ | `showRemainingTime` | `boolean` | `false` | Show a progress bar draining to zero |
61
+ | `showCloseButton` | `boolean` | `false` | Show × button |
62
+ | `allowStacking` | `boolean` | `true` | Allow multiple toasts simultaneously |
63
+
64
+ **ToastPosition:** `'top-left'` `'top-center'` `'top-right'` `'bottom-left'` `'bottom-center'` `'bottom-right'`
65
+
66
+ **ToastType:** `'default'` `'info'` `'success'` `'error'` `'warn'`
67
+
68
+ **Slots:** `root` `icon` `content` `closeButton` `progressBar`
@@ -0,0 +1,108 @@
1
+ # VirtualList
2
+
3
+ **When to use:** Efficiently render large lists or tables — thousands of rows rendered with a virtualised scroll window so only visible rows are in the DOM. Supports column definitions, row selection, multi-select, column visibility toggling, and infinite scroll.
4
+
5
+ **Import:** `import { VirtualList } from '@ahrowe/ui'`
6
+ **Types:** `import type { VirtualListProps, VirtualListColumn } from '@ahrowe/ui'`
7
+
8
+ ```tsx
9
+ import { VirtualList } from '@ahrowe/ui';
10
+ import type { VirtualListColumn } from '@ahrowe/ui';
11
+
12
+ type User = { id: string; name: string; email: string; role: string };
13
+
14
+ // Simple list mode (no columns)
15
+ <VirtualList
16
+ items={users}
17
+ renderRow={(user) => (
18
+ <div className="row">{user.name} — {user.email}</div>
19
+ )}
20
+ height={500}
21
+ />
22
+
23
+ // Table mode with column definitions
24
+ const columns: VirtualListColumn<User>[] = [
25
+ {
26
+ key: 'name',
27
+ label: 'Name',
28
+ width: { type: 'flex', weight: 2 },
29
+ renderCell: (user) => <strong>{user.name}</strong>,
30
+ },
31
+ {
32
+ key: 'email',
33
+ label: 'Email',
34
+ width: { type: 'flex' },
35
+ renderCell: (user) => user.email,
36
+ },
37
+ {
38
+ key: 'role',
39
+ label: 'Role',
40
+ width: { type: 'fixed', px: 120 },
41
+ renderCell: (user) => user.role,
42
+ defaultHidden: true,
43
+ },
44
+ ];
45
+
46
+ <VirtualList
47
+ items={users}
48
+ columns={columns}
49
+ getItemKey={(user) => user.id}
50
+ selectedKey={selectedId}
51
+ onRowClick={(user) => setSelectedId(user.id)}
52
+ height={600}
53
+ />
54
+
55
+ // Infinite scroll
56
+ <VirtualList
57
+ items={items}
58
+ columns={columns}
59
+ onLoadMore={async () => { await fetchNextPage(); }}
60
+ isLoading={isInitialLoading}
61
+ height="100%"
62
+ />
63
+
64
+ // Multi-select
65
+ <VirtualList
66
+ items={items}
67
+ columns={columns}
68
+ multiSelect
69
+ selectedKeys={selectedKeys}
70
+ onSelectionChange={(keys) => setSelectedKeys(keys)}
71
+ height={500}
72
+ />
73
+ ```
74
+
75
+ **Column width types:**
76
+
77
+ ```ts
78
+ { type: 'fixed'; px: number } // fixed pixel width
79
+ { type: 'flex'; weight?: number } // flex, weight defaults to 1
80
+ { type: 'fit' } // shrink to content
81
+ ```
82
+
83
+ **Key props:**
84
+
85
+ | Prop | Type | Description |
86
+ |------|------|-------------|
87
+ | `items` | `T[]` | Data array (required) |
88
+ | `renderRow` | `(item, index) => ReactNode` | Row render fn — list mode (no columns) |
89
+ | `columns` | `VirtualListColumn<T>[]` | Column definitions — enables table/header mode |
90
+ | `height` | `number \| string` | Scroll viewport height (default `'100%'`) |
91
+ | `estimatedRowHeight` | `number` | Estimated row height before measurement (default `40`) |
92
+ | `overscan` | `number` | Extra rows rendered outside the viewport (default `3`) |
93
+ | `rowGap` | `number` | Gap in px between rows (default `0`) |
94
+ | `showDivider` | `boolean` | Row divider lines (default `true`) |
95
+ | `getItemKey` | `(item, index) => string \| number` | Stable key per item |
96
+ | `selectedKey` | `string \| number \| null` | Controlled single-select key |
97
+ | `onRowClick` | `(item, index) => void` | Row click handler |
98
+ | `multiSelect` | `boolean` | Enable checkbox multi-select column |
99
+ | `selectedKeys` | `Set<string \| number>` | Controlled multi-select keys |
100
+ | `onSelectionChange` | `(keys) => void` | Multi-select change callback |
101
+ | `showColumnToggle` | `boolean` | Show gear button to show/hide columns (default `true` when columns present) |
102
+ | `visibleColumnKeys` | `string[]` | Controlled visible column keys |
103
+ | `onVisibleColumnsChange` | `(keys) => void` | Column visibility change callback |
104
+ | `onLoadMore` | `() => Promise<void>` | Triggered near the bottom — append items in the handler |
105
+ | `loadMoreThreshold` | `number` | Distance from bottom that triggers `onLoadMore` (default `100`) |
106
+ | `isLoading` | `boolean` | Replaces list body with a full-height spinner |
107
+
108
+ **Slots:** `root` `header` `headerCell` `headerToggle` `togglePopover` `toggleItem` `body` `row` `cell` `selectCell` `loadingIndicator`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahrowe/ui",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },