@olwiba/ui 0.1.15 → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olwiba/ui",
3
- "version": "0.1.15",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- import { Building2, ShieldCheck, Sparkles } from 'lucide-react';
4
+ import { Building2, Loader2, ShieldCheck, Sparkles } from 'lucide-react';
5
5
  import {
6
6
  Badge,
7
7
  CardContent,
@@ -243,17 +243,18 @@ function DefaultForm({
243
243
  )}
244
244
 
245
245
  {error && (
246
- <p className="text-sm font-medium text-destructive">{error}</p>
246
+ <p role="alert" className="text-sm font-medium text-destructive">{error}</p>
247
247
  )}
248
248
  {success && (
249
- <p className="text-sm font-medium text-primary">{success}</p>
249
+ <p role="status" className="text-sm font-medium text-primary">{success}</p>
250
250
  )}
251
251
 
252
252
  <div className="flex flex-col gap-2">
253
253
  <Button type="submit" className="w-full" disabled={loading || (isVerify && code.length < codeLength)}>
254
+ {loading && <Loader2 className="size-4 animate-spin" />}
254
255
  {loading ? 'Please wait…' : copy.submit}
255
256
  </Button>
256
- {onSso && mode === 'signin' && (
257
+ {onSso && (mode === 'signin' || mode === 'signup') && (
257
258
  <Button type="button" variant="outline" className="w-full" onClick={onSso} disabled={loading}>
258
259
  Use SSO
259
260
  </Button>
@@ -64,12 +64,14 @@ export function BillingPanel({
64
64
  onUpdatePaymentMethod,
65
65
  className,
66
66
  }: BillingPanelProps) {
67
+ // Dates and amounts are display strings — sorting them would be lexicographic, so keep it off
67
68
  const invoiceColumns = React.useMemo<ColumnDef<BillingInvoice>[]>(() => [
68
- { accessorKey: 'date', header: 'Date' },
69
- { accessorKey: 'amount', header: 'Amount' },
69
+ { accessorKey: 'date', header: 'Date', enableSorting: false },
70
+ { accessorKey: 'amount', header: 'Amount', enableSorting: false },
70
71
  {
71
72
  accessorKey: 'status',
72
73
  header: 'Status',
74
+ enableSorting: false,
73
75
  cell: ({ row }) => (
74
76
  <Badge variant={invoiceStatusVariant[row.original.status]} className="capitalize">
75
77
  {row.original.status}
@@ -108,17 +110,21 @@ export function BillingPanel({
108
110
  </div>
109
111
  {usage && usage.length > 0 && (
110
112
  <div className="mt-4 space-y-4">
111
- {usage.map((metric) => (
112
- <div key={metric.label} className="space-y-1.5">
113
- <div className="flex items-center justify-between text-sm">
114
- <span>{metric.label}</span>
115
- <span className="text-muted-foreground">
116
- {metric.used}{metric.unit} / {metric.limit}{metric.unit}
117
- </span>
113
+ {usage.map((metric) => {
114
+ const overLimit = metric.limit > 0 && metric.used > metric.limit;
115
+ const percent = metric.limit > 0 ? Math.min(100, (metric.used / metric.limit) * 100) : 0;
116
+ return (
117
+ <div key={metric.label} className="space-y-1.5">
118
+ <div className="flex items-center justify-between text-sm">
119
+ <span>{metric.label}</span>
120
+ <span className={overLimit ? 'font-medium text-destructive' : 'text-muted-foreground'}>
121
+ {metric.used}{metric.unit} / {metric.limit}{metric.unit}
122
+ </span>
123
+ </div>
124
+ <Progress value={percent} className={overLimit ? '[&>div]:bg-destructive' : undefined} />
118
125
  </div>
119
- <Progress value={(metric.used / metric.limit) * 100} />
120
- </div>
121
- ))}
126
+ );
127
+ })}
122
128
  </div>
123
129
  )}
124
130
  </SettingsSection>
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- import { Check } from 'lucide-react';
4
+ import { Check, Loader2 } from 'lucide-react';
5
5
  import { cn } from '@olwiba/cn';
6
6
  import { Button } from '../primitives/Button';
7
7
 
@@ -57,8 +57,15 @@ export function OnboardingWizard({
57
57
  const handleNext = async () => {
58
58
  if (current.onNext) {
59
59
  setPending(true);
60
- const result = await current.onNext();
61
- setPending(false);
60
+ let result: boolean | string;
61
+ try {
62
+ result = await current.onNext();
63
+ } catch (err) {
64
+ setError(err instanceof Error ? err.message : 'Something went wrong. Please try again.');
65
+ return;
66
+ } finally {
67
+ setPending(false);
68
+ }
62
69
  if (result === false) { setError('Please complete this step before continuing.'); return; }
63
70
  if (typeof result === 'string') { setError(result); return; }
64
71
  }
@@ -75,9 +82,13 @@ export function OnboardingWizard({
75
82
 
76
83
  return (
77
84
  <div className={cn('w-full max-w-lg space-y-8', className)}>
78
- <ol className="flex items-center">
85
+ <ol className="flex items-center" aria-label="Progress">
79
86
  {steps.map((step, i) => (
80
- <li key={step.id} className={cn('flex items-center', i !== steps.length - 1 && 'flex-1')}>
87
+ <li
88
+ key={step.id}
89
+ aria-current={i === index ? 'step' : undefined}
90
+ className={cn('flex items-center', i !== steps.length - 1 && 'flex-1')}
91
+ >
81
92
  <div
82
93
  className={cn(
83
94
  'flex size-8 shrink-0 items-center justify-center rounded-full border text-xs font-medium',
@@ -85,6 +96,7 @@ export function OnboardingWizard({
85
96
  )}
86
97
  >
87
98
  {i < index ? <Check className="size-4" /> : i + 1}
99
+ <span className="sr-only">{step.title}{i < index ? ' (completed)' : ''}</span>
88
100
  </div>
89
101
  {i !== steps.length - 1 && (
90
102
  <div className={cn('mx-2 h-px flex-1', i < index ? 'bg-primary' : 'bg-border')} />
@@ -99,7 +111,7 @@ export function OnboardingWizard({
99
111
  {current.description && <p className="mt-1 text-sm text-muted-foreground">{current.description}</p>}
100
112
  </div>
101
113
  <div>{current.content}</div>
102
- {error && <p className="text-sm font-medium text-destructive">{error}</p>}
114
+ {error && <p role="alert" className="text-sm font-medium text-destructive">{error}</p>}
103
115
  </div>
104
116
 
105
117
  <div className="flex items-center justify-between">
@@ -107,6 +119,7 @@ export function OnboardingWizard({
107
119
  Back
108
120
  </Button>
109
121
  <Button type="button" onClick={handleNext} disabled={pending}>
122
+ {pending && <Loader2 className="size-4 animate-spin" />}
110
123
  {pending ? 'Please wait…' : isLast ? completeLabel : 'Continue'}
111
124
  </Button>
112
125
  </div>
@@ -6,7 +6,7 @@ export interface SettingsSectionProps {
6
6
  description?: string;
7
7
  /** Form fields, buttons, or any content for the right-hand column — e.g. a `<form>`. */
8
8
  children: React.ReactNode;
9
- /** Styles the content column for a destructive action (e.g. "Delete account"). @default false */
9
+ /** Marks the section as a destructive action (e.g. "Delete account") — renders the title in the destructive color. @default false */
10
10
  danger?: boolean;
11
11
  className?: string;
12
12
  }
@@ -50,39 +50,45 @@ export interface TeamMembersPanelProps {
50
50
  description?: string;
51
51
  }
52
52
 
53
- function InviteDialog({ roles, onInvite }: { roles: string[]; onInvite?: (email: string, role: string) => void }) {
53
+ function InviteDialog({ roles, onInvite, onClose }: { roles: string[]; onInvite?: (email: string, role: string) => void; onClose: () => void }) {
54
54
  const [email, setEmail] = React.useState('');
55
55
  const [role, setRole] = React.useState(roles[roles.length - 1] ?? roles[0]);
56
56
 
57
57
  return (
58
58
  <DialogContent>
59
- <DialogHeader>
60
- <DialogTitle>Invite a team member</DialogTitle>
61
- <DialogDescription>They&rsquo;ll get an email invite to join this workspace.</DialogDescription>
62
- </DialogHeader>
63
- <div className="space-y-4 py-2">
64
- <div className="space-y-2">
65
- <Label htmlFor="invite-email">Email address</Label>
66
- <Input id="invite-email" type="email" placeholder="name@company.com" value={email} onChange={(e) => setEmail(e.target.value)} />
67
- </div>
68
- <div className="space-y-2">
69
- <Label>Role</Label>
70
- <Select value={role} onValueChange={setRole}>
71
- <SelectTrigger><SelectValue /></SelectTrigger>
72
- <SelectContent>
73
- {roles.map((r) => <SelectItem key={r} value={r}>{r}</SelectItem>)}
74
- </SelectContent>
75
- </Select>
59
+ <form
60
+ onSubmit={(e) => {
61
+ e.preventDefault();
62
+ onInvite?.(email, role);
63
+ onClose();
64
+ }}
65
+ >
66
+ <DialogHeader>
67
+ <DialogTitle>Invite a team member</DialogTitle>
68
+ <DialogDescription>They&rsquo;ll get an email invite to join this workspace.</DialogDescription>
69
+ </DialogHeader>
70
+ <div className="space-y-4 py-4">
71
+ <div className="space-y-2">
72
+ <Label htmlFor="invite-email">Email address</Label>
73
+ <Input id="invite-email" type="email" required placeholder="name@company.com" value={email} onChange={(e) => setEmail(e.target.value)} />
74
+ </div>
75
+ <div className="space-y-2">
76
+ <Label>Role</Label>
77
+ <Select value={role} onValueChange={setRole}>
78
+ <SelectTrigger><SelectValue /></SelectTrigger>
79
+ <SelectContent>
80
+ {roles.map((r) => <SelectItem key={r} value={r}>{r}</SelectItem>)}
81
+ </SelectContent>
82
+ </Select>
83
+ </div>
76
84
  </div>
77
- </div>
78
- <DialogFooter>
79
- <DialogClose asChild>
80
- <Button variant="outline">Cancel</Button>
81
- </DialogClose>
82
- <DialogClose asChild>
83
- <Button disabled={!email} onClick={() => onInvite?.(email, role)}>Send invite</Button>
84
- </DialogClose>
85
- </DialogFooter>
85
+ <DialogFooter>
86
+ <DialogClose asChild>
87
+ <Button type="button" variant="outline">Cancel</Button>
88
+ </DialogClose>
89
+ <Button type="submit">Send invite</Button>
90
+ </DialogFooter>
91
+ </form>
86
92
  </DialogContent>
87
93
  );
88
94
  }
@@ -100,6 +106,7 @@ export function TeamMembersPanel({
100
106
  title = 'Team members',
101
107
  description = 'Manage who has access to this workspace.',
102
108
  }: TeamMembersPanelProps) {
109
+ const [inviteOpen, setInviteOpen] = React.useState(false);
103
110
  const columns = React.useMemo<ColumnDef<TeamMemberRecord>[]>(() => [
104
111
  {
105
112
  accessorKey: 'name',
@@ -132,7 +139,7 @@ export function TeamMembersPanel({
132
139
  <Badge variant="secondary">{row.original.role}</Badge>
133
140
  ),
134
141
  },
135
- {
142
+ ...(onRemove ? [{
136
143
  id: 'actions',
137
144
  header: '',
138
145
  cell: ({ row }) => (
@@ -144,29 +151,32 @@ export function TeamMembersPanel({
144
151
  </Button>
145
152
  </DropdownMenuTrigger>
146
153
  <DropdownMenuContent align="end">
147
- <DropdownMenuItem className="text-destructive" onClick={() => onRemove?.(row.original.id)}>
154
+ <DropdownMenuItem className="text-destructive" onClick={() => onRemove(row.original.id)}>
148
155
  Remove member
149
156
  </DropdownMenuItem>
150
157
  </DropdownMenuContent>
151
158
  </DropdownMenu>
152
159
  ),
153
160
  enableSorting: false,
154
- },
161
+ } satisfies ColumnDef<TeamMemberRecord>] : []),
155
162
  ], [roles, onRoleChange, onRemove]);
156
163
 
157
164
  return (
158
165
  <div className="space-y-4">
159
- <div className="flex items-center justify-between gap-4">
166
+ <div className="flex flex-wrap items-center justify-between gap-4">
160
167
  <div>
161
168
  <h2 className="text-base font-semibold">{title}</h2>
162
169
  <p className="mt-1 text-sm text-muted-foreground">{description}</p>
163
170
  </div>
164
- <Dialog>
165
- <DialogTrigger asChild>
166
- <Button><UserPlus className="size-4" /> Invite member</Button>
167
- </DialogTrigger>
168
- <InviteDialog roles={roles} onInvite={onInvite} />
169
- </Dialog>
171
+ {onInvite && (
172
+ <Dialog open={inviteOpen} onOpenChange={setInviteOpen}>
173
+ <DialogTrigger asChild>
174
+ <Button><UserPlus className="size-4" /> Invite member</Button>
175
+ </DialogTrigger>
176
+ {/* key resets the form fields each time the dialog opens */}
177
+ <InviteDialog key={String(inviteOpen)} roles={roles} onInvite={onInvite} onClose={() => setInviteOpen(false)} />
178
+ </Dialog>
179
+ )}
170
180
  </div>
171
181
  <DataTable columns={columns} data={members} searchKey="name" searchPlaceholder="Search members…" pageSize={0} />
172
182
  </div>
@@ -0,0 +1,82 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { Activity } from 'lucide-react';
5
+ import { Avatar, AvatarFallback, AvatarImage, cn } from '@olwiba/cn';
6
+
7
+ export interface ActivityFeedItem {
8
+ id: string;
9
+ /** Main line — pass rich nodes for emphasis, e.g. <><b>Ana</b> deployed to production</>. */
10
+ title: React.ReactNode;
11
+ description?: string;
12
+ /** Pre-formatted timestamp, e.g. "2h ago" or "Mar 4". */
13
+ timestamp?: string;
14
+ /** Avatar image — takes precedence over `icon`. */
15
+ avatar?: string;
16
+ /** Fallback initials when `avatar` is set but fails to load. */
17
+ initials?: string;
18
+ /** Icon node rendered in the timeline marker when there is no avatar. */
19
+ icon?: React.ReactNode;
20
+ }
21
+
22
+ export interface ActivityFeedProps {
23
+ items: ActivityFeedItem[];
24
+ emptyMessage?: string;
25
+ className?: string;
26
+ }
27
+
28
+ /**
29
+ * Vertical activity timeline — avatar or icon markers connected by a rail,
30
+ * one row per event. Presentation-only: pass pre-formatted timestamps and
31
+ * rich `title` nodes from your own data layer.
32
+ */
33
+ export function ActivityFeed({
34
+ items,
35
+ emptyMessage = 'No activity yet.',
36
+ className,
37
+ }: ActivityFeedProps) {
38
+ if (items.length === 0) {
39
+ return (
40
+ <div className={cn('flex flex-col items-center gap-2 py-10 text-center', className)}>
41
+ <Activity className="size-6 text-muted-foreground" />
42
+ <p className="text-sm text-muted-foreground">{emptyMessage}</p>
43
+ </div>
44
+ );
45
+ }
46
+
47
+ return (
48
+ <ol className={className}>
49
+ {items.map((item, i) => (
50
+ <li key={item.id} className="relative flex gap-3 pb-6 last:pb-0">
51
+ {/* Rail connecting this marker to the next */}
52
+ {i !== items.length - 1 && (
53
+ <span aria-hidden className="absolute left-4 top-9 bottom-0 w-px -translate-x-1/2 bg-border" />
54
+ )}
55
+ <span className="relative z-10 flex size-8 shrink-0 items-center justify-center">
56
+ {item.avatar ? (
57
+ <Avatar className="size-8">
58
+ <AvatarImage src={item.avatar} alt="" />
59
+ <AvatarFallback className="text-xs">{item.initials ?? '?'}</AvatarFallback>
60
+ </Avatar>
61
+ ) : (
62
+ <span className="flex size-8 items-center justify-center rounded-full border bg-card text-muted-foreground [&>svg]:size-4">
63
+ {item.icon ?? <Activity />}
64
+ </span>
65
+ )}
66
+ </span>
67
+ <div className="min-w-0 flex-1 pt-1">
68
+ <div className="flex items-baseline justify-between gap-2">
69
+ <p className="text-sm">{item.title}</p>
70
+ {item.timestamp && (
71
+ <span className="shrink-0 text-xs text-muted-foreground">{item.timestamp}</span>
72
+ )}
73
+ </div>
74
+ {item.description && (
75
+ <p className="mt-0.5 text-xs text-muted-foreground">{item.description}</p>
76
+ )}
77
+ </div>
78
+ </li>
79
+ ))}
80
+ </ol>
81
+ );
82
+ }
@@ -54,7 +54,13 @@ export function CommandMenu({
54
54
  }: CommandMenuProps) {
55
55
  const internal = useControlledOpen(false);
56
56
  const isOpen = openProp ?? internal.isOpen;
57
- const setOpen = onOpenChange ?? internal.setIsOpen;
57
+ const setOpen = React.useCallback(
58
+ (next: boolean) => {
59
+ if (openProp === undefined) internal.setIsOpen(next);
60
+ onOpenChange?.(next);
61
+ },
62
+ [openProp, onOpenChange, internal.setIsOpen],
63
+ );
58
64
 
59
65
  const runItem = (item: CommandMenuItem) => {
60
66
  setOpen(false);
@@ -135,7 +135,10 @@ export function DataTable<TData>({
135
135
  const canSort = header.column.getCanSort();
136
136
  const sortDir = header.column.getIsSorted();
137
137
  return (
138
- <TableHead key={header.id}>
138
+ <TableHead
139
+ key={header.id}
140
+ aria-sort={sortDir === 'asc' ? 'ascending' : sortDir === 'desc' ? 'descending' : canSort ? 'none' : undefined}
141
+ >
139
142
  {header.isPlaceholder ? null : canSort ? (
140
143
  <button
141
144
  type="button"
@@ -161,7 +164,11 @@ export function DataTable<TData>({
161
164
  key={row.id}
162
165
  data-state={row.getIsSelected() ? 'selected' : undefined}
163
166
  onClick={() => onRowClick?.(row.original)}
164
- className={cn(onRowClick && 'cursor-pointer')}
167
+ tabIndex={onRowClick ? 0 : undefined}
168
+ onKeyDown={onRowClick ? (e) => {
169
+ if (e.key === 'Enter' && e.target === e.currentTarget) onRowClick(row.original);
170
+ } : undefined}
171
+ className={cn(onRowClick && 'cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring')}
165
172
  >
166
173
  {row.getVisibleCells().map((cell) => (
167
174
  <TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
@@ -179,20 +186,23 @@ export function DataTable<TData>({
179
186
  </Table>
180
187
  </div>
181
188
 
182
- {pageSize > 0 && table.getPageCount() > 1 && (
189
+ {(selectable || (pageSize > 0 && table.getPageCount() > 1)) && (
183
190
  <div className="flex items-center justify-between">
184
191
  <p className="text-sm text-muted-foreground">
185
- {selectable && `${table.getFilteredSelectedRowModel().rows.length} of ${table.getFilteredRowModel().rows.length} selected · `}
186
- Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()}
192
+ {selectable && `${table.getFilteredSelectedRowModel().rows.length} of ${table.getFilteredRowModel().rows.length} selected`}
193
+ {selectable && pageSize > 0 && table.getPageCount() > 1 && ' · '}
194
+ {pageSize > 0 && table.getPageCount() > 1 && `Page ${table.getState().pagination.pageIndex + 1} of ${table.getPageCount()}`}
187
195
  </p>
188
- <div className="flex gap-2">
189
- <Button variant="outline" size="sm" onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>
190
- <ChevronLeft className="size-4" /> Previous
191
- </Button>
192
- <Button variant="outline" size="sm" onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>
193
- Next <ChevronRight className="size-4" />
194
- </Button>
195
- </div>
196
+ {pageSize > 0 && table.getPageCount() > 1 && (
197
+ <div className="flex gap-2">
198
+ <Button variant="outline" size="sm" onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()}>
199
+ <ChevronLeft className="size-4" /> Previous
200
+ </Button>
201
+ <Button variant="outline" size="sm" onClick={() => table.nextPage()} disabled={!table.getCanNextPage()}>
202
+ Next <ChevronRight className="size-4" />
203
+ </Button>
204
+ </div>
205
+ )}
196
206
  </div>
197
207
  )}
198
208
  </div>
@@ -66,6 +66,9 @@ export function FileUpload({
66
66
  const [isDragging, setIsDragging] = React.useState(false);
67
67
  const [validationError, setValidationError] = React.useState<string | null>(null);
68
68
  const inputRef = React.useRef<HTMLInputElement>(null);
69
+ // dragenter/dragleave fire for every child element crossed — count them so the
70
+ // highlight doesn't flicker while moving over the icon/text inside the zone
71
+ const dragDepth = React.useRef(0);
69
72
  const files = filesProp ?? internalFiles;
70
73
 
71
74
  const setFiles = React.useCallback(
@@ -92,7 +95,8 @@ export function FileUpload({
92
95
  const handleFiles = (fileList: FileList | null) => {
93
96
  if (!fileList || disabled) return;
94
97
  const incoming = Array.from(fileList);
95
- const room = maxFiles ? Math.max(0, maxFiles - files.length) : Infinity;
98
+ // Single mode replaces the current file, so the existing queue never counts against maxFiles
99
+ const room = maxFiles && multiple ? Math.max(0, maxFiles - files.length) : maxFiles || Infinity;
96
100
  if (maxFiles && room <= 0) {
97
101
  setValidationError(`You can only add up to ${maxFiles} file${maxFiles === 1 ? '' : 's'}.`);
98
102
  return;
@@ -124,11 +128,26 @@ export function FileUpload({
124
128
  role="button"
125
129
  tabIndex={disabled ? -1 : 0}
126
130
  onClick={() => !disabled && inputRef.current?.click()}
127
- onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') inputRef.current?.click(); }}
128
- onDragOver={(e) => { e.preventDefault(); if (!disabled) setIsDragging(true); }}
129
- onDragLeave={() => setIsDragging(false)}
131
+ onKeyDown={(e) => {
132
+ if (disabled) return;
133
+ if (e.key === 'Enter' || e.key === ' ') {
134
+ e.preventDefault();
135
+ inputRef.current?.click();
136
+ }
137
+ }}
138
+ onDragOver={(e) => e.preventDefault()}
139
+ onDragEnter={(e) => {
140
+ e.preventDefault();
141
+ dragDepth.current += 1;
142
+ if (!disabled) setIsDragging(true);
143
+ }}
144
+ onDragLeave={() => {
145
+ dragDepth.current = Math.max(0, dragDepth.current - 1);
146
+ if (dragDepth.current === 0) setIsDragging(false);
147
+ }}
130
148
  onDrop={(e) => {
131
149
  e.preventDefault();
150
+ dragDepth.current = 0;
132
151
  setIsDragging(false);
133
152
  handleFiles(e.dataTransfer.files);
134
153
  }}
@@ -154,7 +173,7 @@ export function FileUpload({
154
173
  />
155
174
  </div>
156
175
 
157
- {validationError && <p className="text-sm font-medium text-destructive">{validationError}</p>}
176
+ {validationError && <p role="alert" className="text-sm font-medium text-destructive">{validationError}</p>}
158
177
 
159
178
  {files.length > 0 && (
160
179
  <ul className="space-y-2">