start-vibing-stacks 2.0.1 → 2.0.2

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/dist/ui.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Start Vibing Stacks — Terminal UI
3
3
  */
4
4
  import chalk from 'chalk';
5
- const VERSION = '2.0.1';
5
+ const VERSION = '2.0.2';
6
6
  const gradient = (text) => {
7
7
  const colors = [chalk.hex('#FF6B6B'), chalk.hex('#FF8E53'), chalk.hex('#FFBD2E'), chalk.hex('#48BB78'), chalk.hex('#4299E1'), chalk.hex('#9F7AEA')];
8
8
  return text.split('').map((c, i) => colors[i % colors.length](c)).join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "start-vibing-stacks",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "AI-powered multi-stack dev workflow for Claude Code. Supports PHP, Node.js, Python and more.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,298 @@
1
+ # React UI Patterns — Loading, Errors, Empty States & Forms
2
+
3
+ **ALWAYS invoke when handling async UI states, forms, or user feedback.**
4
+
5
+ ## Core Principles
6
+
7
+ 1. **Never show stale UI** — loading only when actually loading
8
+ 2. **Always surface errors** — users must KNOW when something fails
9
+ 3. **Optimistic updates** — make UI feel instant
10
+ 4. **Progressive disclosure** — show content as it becomes available
11
+ 5. **Disable during operations** — prevent double-submit
12
+
13
+ ## Loading State Decision Tree
14
+
15
+ ```
16
+ Error?
17
+ → Yes: Show ErrorState with retry
18
+ → No ↓
19
+
20
+ Loading AND no data?
21
+ → Yes: Show Skeleton or Spinner
22
+ → No ↓
23
+
24
+ Has data?
25
+ → Yes + items: Render data
26
+ → Yes + empty: Show EmptyState
27
+ → No: Show Spinner (fallback)
28
+ ```
29
+
30
+ ```tsx
31
+ // ✅ CORRECT — only loading when no data
32
+ const { data, isLoading, error, refetch } = useQuery(...);
33
+
34
+ if (error) return <ErrorState error={error} onRetry={refetch} />;
35
+ if (isLoading && !data) return <Skeleton />;
36
+ if (!data?.items.length) return <EmptyState />;
37
+ return <ItemList items={data.items} />;
38
+
39
+ // ❌ WRONG — flashes spinner on refetch when cached data exists
40
+ if (isLoading) return <Spinner />;
41
+ ```
42
+
43
+ ### Skeleton vs Spinner
44
+
45
+ | Use Skeleton | Use Spinner |
46
+ |---|---|
47
+ | Known content shape (cards, tables, lists) | Unknown shape (modals, inline actions) |
48
+ | Initial page load | Button submissions |
49
+ | Content placeholders | Small inline operations |
50
+
51
+ ```tsx
52
+ // Skeleton component
53
+ function CardSkeleton() {
54
+ return (
55
+ <div className="bg-card border border-card-line rounded-xl p-6 animate-pulse">
56
+ <div className="h-4 w-3/4 bg-muted rounded" />
57
+ <div className="mt-3 h-3 w-1/2 bg-muted rounded" />
58
+ <div className="mt-6 h-10 w-full bg-muted rounded" />
59
+ </div>
60
+ );
61
+ }
62
+
63
+ // Skeleton grid
64
+ function ListSkeleton({ count = 6 }: { count?: number }) {
65
+ return (
66
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
67
+ {Array.from({ length: count }, (_, i) => <CardSkeleton key={i} />)}
68
+ </div>
69
+ );
70
+ }
71
+ ```
72
+
73
+ ## Error Handling Hierarchy
74
+
75
+ ```
76
+ Level 1 — Inline error → Field validation (under input)
77
+ Level 2 — Toast notification → Recoverable, user can retry
78
+ Level 3 — Error banner → Page-level, data partially usable
79
+ Level 4 — Full error screen → Unrecoverable, needs user action
80
+ ```
81
+
82
+ ```tsx
83
+ // Reusable ErrorState
84
+ interface ErrorStateProps {
85
+ error: Error | string;
86
+ onRetry?: () => void;
87
+ title?: string;
88
+ }
89
+
90
+ function ErrorState({ error, onRetry, title }: ErrorStateProps) {
91
+ const message = typeof error === 'string' ? error : error.message;
92
+ return (
93
+ <div className="flex flex-col items-center justify-center py-12 text-center">
94
+ <div className="h-12 w-12 rounded-full bg-destructive/10 flex items-center justify-center mb-4">
95
+ <AlertCircle className="h-6 w-6 text-destructive" />
96
+ </div>
97
+ <h3 className="text-lg font-semibold text-foreground">{title ?? 'Something went wrong'}</h3>
98
+ <p className="mt-1 text-sm text-muted-foreground max-w-md">{message}</p>
99
+ {onRetry && (
100
+ <button onClick={onRetry}
101
+ className="mt-4 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary-hover transition-colors">
102
+ Try Again
103
+ </button>
104
+ )}
105
+ </div>
106
+ );
107
+ }
108
+ ```
109
+
110
+ ### NEVER Swallow Errors
111
+
112
+ ```tsx
113
+ // ✅ CORRECT — error surfaced to user
114
+ const mutation = useMutation({
115
+ mutationFn: createItem,
116
+ onSuccess: () => toast.success('Item created!'),
117
+ onError: (error) => {
118
+ console.error('createItem failed:', error);
119
+ toast.error('Failed to create item');
120
+ },
121
+ });
122
+
123
+ // ❌ WRONG — user sees nothing
124
+ try { await createItem(data); }
125
+ catch (e) { console.log(e); } // Silent failure!
126
+ ```
127
+
128
+ ## Empty States
129
+
130
+ **Every list/collection MUST have an empty state.**
131
+
132
+ ```tsx
133
+ // ✅ With empty state
134
+ function UserList({ users }: { users: User[] }) {
135
+ if (!users.length) {
136
+ return (
137
+ <EmptyState
138
+ icon={<Users className="h-8 w-8" />}
139
+ title="No users yet"
140
+ description="Invite your first team member"
141
+ action={{ label: 'Invite User', onClick: () => router.visit('/users/invite') }}
142
+ />
143
+ );
144
+ }
145
+ return <div className="space-y-2">{users.map(u => <UserCard key={u.id} user={u} />)}</div>;
146
+ }
147
+
148
+ // Reusable EmptyState
149
+ function EmptyState({ icon, title, description, action }: {
150
+ icon: ReactNode;
151
+ title: string;
152
+ description: string;
153
+ action?: { label: string; onClick: () => void };
154
+ }) {
155
+ return (
156
+ <div className="flex flex-col items-center justify-center py-16 text-center">
157
+ <div className="text-muted-foreground mb-4">{icon}</div>
158
+ <h3 className="text-lg font-semibold text-foreground">{title}</h3>
159
+ <p className="mt-1 text-sm text-muted-foreground max-w-sm">{description}</p>
160
+ {action && (
161
+ <button onClick={action.onClick}
162
+ className="mt-4 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary-hover transition-colors">
163
+ {action.label}
164
+ </button>
165
+ )}
166
+ </div>
167
+ );
168
+ }
169
+ ```
170
+
171
+ ## Button States
172
+
173
+ ```tsx
174
+ // ✅ CORRECT — disabled + loading indicator
175
+ <button
176
+ onClick={handleSubmit}
177
+ disabled={!isValid || isSubmitting}
178
+ className="bg-primary text-primary-foreground px-4 py-2 rounded-lg hover:bg-primary-hover disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
179
+ >
180
+ {isSubmitting ? (
181
+ <span className="flex items-center gap-2">
182
+ <Loader className="h-4 w-4 animate-spin" />
183
+ Saving...
184
+ </span>
185
+ ) : 'Save'}
186
+ </button>
187
+
188
+ // ❌ WRONG — user can click multiple times
189
+ <button onClick={handleSubmit}>
190
+ {isSubmitting ? 'Submitting...' : 'Submit'}
191
+ </button>
192
+ ```
193
+
194
+ ## Form Pattern (Inertia.js)
195
+
196
+ ```tsx
197
+ import { useForm } from '@inertiajs/react';
198
+
199
+ export default function CreateUser() {
200
+ const { data, setData, post, processing, errors, reset } = useForm({
201
+ name: '',
202
+ email: '',
203
+ });
204
+
205
+ const submit = (e: React.FormEvent) => {
206
+ e.preventDefault();
207
+ post('/users', {
208
+ onSuccess: () => {
209
+ toast.success('User created!');
210
+ reset();
211
+ },
212
+ onError: () => toast.error('Failed to create user'),
213
+ });
214
+ };
215
+
216
+ return (
217
+ <form onSubmit={submit} className="space-y-4">
218
+ <div>
219
+ <label className="block text-sm font-medium text-foreground mb-1">Name</label>
220
+ <input
221
+ value={data.name}
222
+ onChange={e => setData('name', e.target.value)}
223
+ className="w-full h-10 px-3 rounded-md border border-border bg-background text-foreground"
224
+ />
225
+ {errors.name && <p className="mt-1 text-sm text-destructive">{errors.name}</p>}
226
+ </div>
227
+
228
+ <div>
229
+ <label className="block text-sm font-medium text-foreground mb-1">Email</label>
230
+ <input
231
+ type="email"
232
+ value={data.email}
233
+ onChange={e => setData('email', e.target.value)}
234
+ className="w-full h-10 px-3 rounded-md border border-border bg-background text-foreground"
235
+ />
236
+ {errors.email && <p className="mt-1 text-sm text-destructive">{errors.email}</p>}
237
+ </div>
238
+
239
+ <button
240
+ type="submit"
241
+ disabled={processing}
242
+ className="bg-primary text-primary-foreground px-6 py-2 rounded-lg hover:bg-primary-hover disabled:opacity-50 transition-colors"
243
+ >
244
+ {processing ? (
245
+ <span className="flex items-center gap-2">
246
+ <Loader className="h-4 w-4 animate-spin" /> Creating...
247
+ </span>
248
+ ) : 'Create User'}
249
+ </button>
250
+ </form>
251
+ );
252
+ }
253
+ ```
254
+
255
+ ## Optimistic Updates
256
+
257
+ ```tsx
258
+ // Show result immediately, rollback on error
259
+ function ToggleFavorite({ item }: { item: Item }) {
260
+ const [optimistic, setOptimistic] = useState(item.isFavorite);
261
+
262
+ const toggle = () => {
263
+ setOptimistic(!optimistic); // Instant UI
264
+ router.post(`/items/${item.id}/favorite`, {}, {
265
+ preserveState: true,
266
+ onError: () => {
267
+ setOptimistic(item.isFavorite); // Rollback
268
+ toast.error('Failed to update');
269
+ },
270
+ });
271
+ };
272
+
273
+ return (
274
+ <button onClick={toggle} className="text-xl">
275
+ {optimistic ? '❤️' : '🤍'}
276
+ </button>
277
+ );
278
+ }
279
+ ```
280
+
281
+ ## Checklist — Before Shipping Any UI Component
282
+
283
+ - [ ] Error state handled and shown to user
284
+ - [ ] Loading state only when no data exists (no flash on refetch)
285
+ - [ ] Empty state for every collection/list
286
+ - [ ] Buttons disabled during async operations
287
+ - [ ] Buttons show loading indicator
288
+ - [ ] Form errors shown inline under fields
289
+ - [ ] Mutations have onError with user feedback
290
+ - [ ] Skeleton matches content layout shape
291
+
292
+ ## FORBIDDEN
293
+
294
+ 1. **`if (loading) return <Spinner />`** — check `loading && !data` instead
295
+ 2. **Silent catch** — always toast/display errors to user
296
+ 3. **No empty state** — every list needs one
297
+ 4. **Clickable button during submit** — always `disabled={processing}`
298
+ 5. **Console.log-only errors** — user must see feedback