moi-computer 0.0.1
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/LICENSE +95 -0
- package/README.md +71 -0
- package/bin/moi.mjs +25 -0
- package/bunfig.toml +3 -0
- package/client/CLAUDE.md +12 -0
- package/client/api/workspaces.ts +158 -0
- package/client/assets/claude.svg +3 -0
- package/client/assets/favicon.png +0 -0
- package/client/assets/hermes-nous.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/moi-logo.svg +11 -0
- package/client/assets/openclaw.svg +22 -0
- package/client/components/App.tsx +35 -0
- package/client/components/BottomPanel.tsx +33 -0
- package/client/components/ChatInput.tsx +62 -0
- package/client/components/ChatPanel.tsx +206 -0
- package/client/components/ChatPopup.tsx +60 -0
- package/client/components/CustomizePanel.tsx +117 -0
- package/client/components/HiddenPanel.tsx +79 -0
- package/client/components/HomePage.tsx +17 -0
- package/client/components/MarkdownContent.tsx +41 -0
- package/client/components/ThreadSelector.tsx +88 -0
- package/client/components/TurnView.tsx +618 -0
- package/client/components/WidgetErrorBoundary.tsx +46 -0
- package/client/components/WidgetFrame.tsx +66 -0
- package/client/components/WidgetGrid.tsx +113 -0
- package/client/components/WidgetShell.tsx +44 -0
- package/client/components/Widgets.tsx +132 -0
- package/client/components/WorkspacePreview.tsx +48 -0
- package/client/components/WorkspacesPage.tsx +237 -0
- package/client/components/layout/SidebarLayout.tsx +260 -0
- package/client/components/playground/LedLogo.tsx +181 -0
- package/client/components/playground/PixelPainter.tsx +105 -0
- package/client/components/playground/PlaygroundPage.tsx +71 -0
- package/client/components/routes/workspace/[id].tsx +282 -0
- package/client/components/ui/button.tsx +48 -0
- package/client/components/ui/dropdown-menu.tsx +257 -0
- package/client/components/ui/input.tsx +21 -0
- package/client/components/ui/popover.tsx +79 -0
- package/client/components/ui/textarea.tsx +18 -0
- package/client/externalize-react.ts +29 -0
- package/client/hooks/useChat.ts +88 -0
- package/client/hooks/useFitsSidebar.ts +34 -0
- package/client/hooks/useGridReconcile.ts +73 -0
- package/client/hooks/useMeiEvents.ts +66 -0
- package/client/hooks/useScrollFade.ts +38 -0
- package/client/hooks/useWidget.ts +72 -0
- package/client/hooks/useWidgetList.ts +30 -0
- package/client/hooks/useWorkspaceTheme.ts +76 -0
- package/client/index.css +182 -0
- package/client/index.html +43 -0
- package/client/index.tsx +19 -0
- package/client/lib/WorkspaceContext.tsx +24 -0
- package/client/lib/WorkspaceLayoutContext.tsx +92 -0
- package/client/lib/cn.ts +6 -0
- package/client/lib/grid-pack.ts +35 -0
- package/client/lib/group-turns.ts +44 -0
- package/client/lib/mcp-icons.ts +53 -0
- package/client/lib/ws.ts +129 -0
- package/client/main.tsx +23 -0
- package/client/store/chat.tsx +162 -0
- package/client/store/ui.ts +21 -0
- package/client/theme.css +66 -0
- package/lib/claude-adapter.ts +602 -0
- package/lib/format.ts +212 -0
- package/lib/themes.ts +89 -0
- package/lib/types.ts +144 -0
- package/package.json +117 -0
- package/server/CLAUDE.md +6 -0
- package/server/agent.ts +132 -0
- package/server/build-widget.ts +343 -0
- package/server/cli.ts +632 -0
- package/server/constants.ts +3 -0
- package/server/control.ts +98 -0
- package/server/functions-worker.ts +89 -0
- package/server/functions.ts +171 -0
- package/server/layout.ts +83 -0
- package/server/openclaw-adapter.ts +242 -0
- package/server/openclaw-gateway.ts +255 -0
- package/server/openclaw-session.ts +485 -0
- package/server/openclaw-strip.ts +134 -0
- package/server/openclaw.ts +206 -0
- package/server/registry.ts +150 -0
- package/server/skills-template.ts +21 -0
- package/server/state.ts +87 -0
- package/server/theme.ts +55 -0
- package/server/web.ts +321 -0
- package/server/widgets.ts +254 -0
- package/tsconfig.json +21 -0
- package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
- package/workspace/.claude/skills/widgets/SKILL.md +176 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
Widget design guidelines. Read this file before creating or modifying any widget.
|
|
2
|
+
|
|
3
|
+
## 1. Design Philosophy
|
|
4
|
+
|
|
5
|
+
Six principles that guide every widget decision.
|
|
6
|
+
|
|
7
|
+
1. **Glanceable, not readable.** A widget communicates its value in under 2 seconds. If the user needs to read a paragraph, it belongs in a full view — not a widget.
|
|
8
|
+
2. **Content is the interface.** The data itself — a number, a label, an icon — is the design. Remove everything that isn't the information. No decorative chrome, no filler.
|
|
9
|
+
3. **Focused, not cramped.** Each widget serves one purpose. Show the most relevant, up-to-date information for that purpose. Avoid combining unrelated data.
|
|
10
|
+
4. **Hierarchy through restraint.** Use one primary element (large, prominent) and optional secondary context (smaller, muted). Three visual layers maximum: primary, secondary, tertiary. If you need more, split into two widgets.
|
|
11
|
+
5. **Both modes are first-class.** Dark and light themes must look intentional, not derived. Design for the dark widget surface explicitly — it's the default.
|
|
12
|
+
6. **Calm confidence.** Generous whitespace, deliberate alignment, and quiet typography signal quality. Empty space is not wasted space.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 2. Craft Rules
|
|
17
|
+
|
|
18
|
+
### 2.1 Visual Hierarchy
|
|
19
|
+
|
|
20
|
+
- Every widget has exactly one focal element — the piece of information the user's eye hits first.
|
|
21
|
+
- Support it with at most two secondary elements (label, icon, subtitle).
|
|
22
|
+
- Tertiary elements (timestamps, units, metadata) recede into `text-muted-foreground` and smaller sizes.
|
|
23
|
+
- If two elements compete for attention, one of them shouldn't be there.
|
|
24
|
+
|
|
25
|
+
### 2.2 Typography Discipline
|
|
26
|
+
|
|
27
|
+
- Use at most **2 font families** per widget: `font-sans` for UI text, `font-mono` for live numeric data.
|
|
28
|
+
- Use at most **3 type sizes** per widget. More sizes = more visual noise.
|
|
29
|
+
- Use at most **2 font weights** per widget (e.g. `font-normal` + `font-bold`).
|
|
30
|
+
|
|
31
|
+
### 2.3 Spacing as Meaning
|
|
32
|
+
|
|
33
|
+
- Tight spacing (4–8px) means "these belong together."
|
|
34
|
+
- Medium spacing (12–16px) means "same group, different items."
|
|
35
|
+
- Wide spacing (24–32px) means "section break."
|
|
36
|
+
- Spacing communicates relationships. Use it instead of dividers when possible.
|
|
37
|
+
|
|
38
|
+
### 2.4 Color Intent
|
|
39
|
+
|
|
40
|
+
- Widget backgrounds should be **metaphorical** — pick a color that relates to the widget's content (sky blue for weather, green for health, amber for notes).
|
|
41
|
+
- Beyond the background, use only semantic tokens for text, borders, and UI elements.
|
|
42
|
+
- Color communicates meaning (status, category), never decoration. If removing the color changes nothing, remove it.
|
|
43
|
+
- Never use raw color values (`text-white`, `#ff0000`). Always semantic tokens or the metaphorical background palette.
|
|
44
|
+
|
|
45
|
+
### 2.5 Information Density
|
|
46
|
+
|
|
47
|
+
- Balance density: content should feel complete but not cluttered.
|
|
48
|
+
- Every element must earn its pixel. Ask: "If I remove this, does the widget still make sense?" If yes, remove it.
|
|
49
|
+
- Prefer showing dynamic information that changes throughout the day over static labels.
|
|
50
|
+
- Widgets are not mini-apps. No tabs, navigation, or multi-step flows.
|
|
51
|
+
|
|
52
|
+
### 2.6 Alignment and Balance
|
|
53
|
+
|
|
54
|
+
- Align elements to a consistent internal grid. Left-align text by default.
|
|
55
|
+
- Center content only when the widget has a single focal element (a clock, a stat, a gauge).
|
|
56
|
+
- For mixed content (label + value + icon), use flex layouts with consistent gaps.
|
|
57
|
+
|
|
58
|
+
### 2.7 Consistency With Intentional Contrast
|
|
59
|
+
|
|
60
|
+
- All widgets on the dashboard should feel like they belong to the same family.
|
|
61
|
+
- Break the pattern in exactly **one** place per widget to create a focal point — a larger number, a colored icon, a bold label.
|
|
62
|
+
- If everything is emphasized, nothing is.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 3. Anti-Patterns
|
|
67
|
+
|
|
68
|
+
Things to never do in a widget:
|
|
69
|
+
|
|
70
|
+
- No inline `style={{}}` or custom CSS. Tailwind covers everything.
|
|
71
|
+
- No `text-white`, `text-black`, or raw hex colors. Semantic tokens only (except metaphorical backgrounds).
|
|
72
|
+
- No raw `<svg>` icons. Use `@tabler/icons-react` components.
|
|
73
|
+
- No text below `text-xs`. Unreadable at widget scale.
|
|
74
|
+
- No text above `text-3xl`. Wastes space in a 160px cell.
|
|
75
|
+
- No horizontal scrolling. Truncate with `truncate` or `line-clamp-2`.
|
|
76
|
+
- No spinners for initial load. Use skeleton placeholders.
|
|
77
|
+
- No full app layouts (tabs, sidebars, navigation, multi-step flows).
|
|
78
|
+
- No marketing copy, long descriptions, or instructions.
|
|
79
|
+
- No auto-playing sound or video. Media playback must be user-initiated.
|
|
80
|
+
- No excessive padding. Widgets are compact — every pixel counts.
|
|
81
|
+
- No rounded corners on the widget root — the card container handles this.
|
|
82
|
+
- No competing animations. One transition at a time.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 4. Workflow
|
|
87
|
+
|
|
88
|
+
When creating or modifying a widget, follow this order:
|
|
89
|
+
|
|
90
|
+
1. **Purpose.** Define the single thing this widget communicates. Write it in one sentence.
|
|
91
|
+
2. **Size.** Choose grid span (`colSpan` x `rowSpan`) based on information density. Start small — only go larger if the content demands it.
|
|
92
|
+
3. **Hierarchy.** Identify the primary element, then secondary, then tertiary. Sketch the layout mentally.
|
|
93
|
+
4. **Background.** Choose a metaphorical background color from the palette (Section 6).
|
|
94
|
+
5. **Build.** Implement using tokens (Sections 5–8) and component patterns (Section 9).
|
|
95
|
+
6. **Check.** Verify against anti-patterns (Section 3). Remove anything that doesn't earn its space.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 5. Grid & Widget Sizing
|
|
100
|
+
|
|
101
|
+
### Grid Constants
|
|
102
|
+
|
|
103
|
+
| Property | Value |
|
|
104
|
+
|----------|-------|
|
|
105
|
+
| Columns | 4 |
|
|
106
|
+
| Row height | 160px |
|
|
107
|
+
| Gap (between cells) | 16px |
|
|
108
|
+
| Container padding | 0px |
|
|
109
|
+
| Max container width | 1184px |
|
|
110
|
+
|
|
111
|
+
### How Widget Size Is Calculated
|
|
112
|
+
|
|
113
|
+
Each widget exports a `config` with `colSpan` and `rowSpan` (both default to 1):
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
export const config = { rowSpan: 2, colSpan: 1 } as const
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Height** is deterministic — it depends only on `rowSpan`:
|
|
120
|
+
```
|
|
121
|
+
height = rowSpan × 160 + (rowSpan − 1) × 16
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Width** depends on `colSpan` and the actual container width. At max container (1184px), one column is 284px:
|
|
125
|
+
```
|
|
126
|
+
width = colSpan × columnWidth + (colSpan − 1) × 16
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Size Reference Table
|
|
130
|
+
|
|
131
|
+
These are the **exact pixel dimensions** your widget content must fit within. Content that exceeds the height will be clipped by `overflow-hidden` on the card container.
|
|
132
|
+
|
|
133
|
+
| Config | Name | Width | Height | Usable area (after p-4) |
|
|
134
|
+
|--------|------|-------|--------|------------------------|
|
|
135
|
+
| `1×1` | Small | ~284px | **160px** | ~252 × 128px |
|
|
136
|
+
| `1×2` | Tall | ~284px | **336px** | ~252 × 304px |
|
|
137
|
+
| `2×1` | Wide | ~584px | **160px** | ~552 × 128px |
|
|
138
|
+
| `2×2` | Medium | ~584px | **336px** | ~552 × 304px |
|
|
139
|
+
| `3×1` | Wide-L | ~884px | **160px** | ~852 × 128px |
|
|
140
|
+
| `4×1` | Full-W | ~1184px | **160px** | ~1152 × 128px |
|
|
141
|
+
| `4×2` | Full | ~1184px | **336px** | ~1152 × 304px |
|
|
142
|
+
|
|
143
|
+
> Width is approximate (column width varies with viewport). Height is exact. **Always design for the height constraint first** — it's the dimension that causes overflow.
|
|
144
|
+
|
|
145
|
+
### Height Budget
|
|
146
|
+
|
|
147
|
+
When planning content for a widget, count the pixels vertically. With `p-4` (16px padding top + bottom), the usable height is `height - 32px`.
|
|
148
|
+
|
|
149
|
+
**1-row widget (160px total, 128px usable):**
|
|
150
|
+
- Category label (text-xs): ~16px
|
|
151
|
+
- Gap: ~16px
|
|
152
|
+
- Hero metric (text-2xl): ~32px
|
|
153
|
+
- Subtitle (text-xs): ~16px
|
|
154
|
+
- Remaining: ~48px for spacing or one more element
|
|
155
|
+
|
|
156
|
+
**2-row widget (336px total, 304px usable):**
|
|
157
|
+
- Category label: ~16px
|
|
158
|
+
- Gap: ~16px
|
|
159
|
+
- Hero metric (text-2xl): ~32px
|
|
160
|
+
- Subtitle: ~16px
|
|
161
|
+
- Stats row: ~32px
|
|
162
|
+
- Remaining: ~192px for lists, charts, or generous spacing
|
|
163
|
+
|
|
164
|
+
If your content doesn't fit the height budget, either reduce content or increase `rowSpan`. Never allow content to overflow.
|
|
165
|
+
|
|
166
|
+
### Sizing Rules
|
|
167
|
+
|
|
168
|
+
- Choose the **smallest size** that fits the content. Start at 1×1 and grow only if information demands it.
|
|
169
|
+
- **Height is the hard constraint.** Width is flexible (columns resize with the viewport), but height is fixed at `rowSpan × 160 + (rowSpan − 1) × 16`.
|
|
170
|
+
- Always use `w-full h-full` on the widget root to fill the card.
|
|
171
|
+
- Use `overflow-hidden` if there's any risk of content exceeding bounds (e.g. dynamic text).
|
|
172
|
+
- Use `flex flex-col` on the root and `mt-auto` to push footer elements (timestamps) to the bottom — this works because the widget fills its exact height.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 6. Colors
|
|
177
|
+
|
|
178
|
+
### Semantic Tokens
|
|
179
|
+
|
|
180
|
+
Use these for all UI elements (text, borders, interactive states). They auto-resolve to dark theme inside widgets.
|
|
181
|
+
|
|
182
|
+
| Token | Class | Purpose |
|
|
183
|
+
|-------|-------|---------|
|
|
184
|
+
| **Primary text** | `text-foreground` | Main content, headings, hero numbers |
|
|
185
|
+
| **Secondary text** | `text-muted-foreground` | Supporting labels, captions, timestamps |
|
|
186
|
+
| **Subdued text** | `text-foreground/50` | Lowest-priority metadata |
|
|
187
|
+
| **Error text** | `text-destructive` | Error messages, destructive states |
|
|
188
|
+
| **Surface** | `bg-background` | Widget surface (dark) |
|
|
189
|
+
| **Raised surface** | `bg-card` | Cards within cards, inset areas |
|
|
190
|
+
| **Muted surface** | `bg-muted` | Subdued backgrounds, skeleton blocks |
|
|
191
|
+
| **Secondary surface** | `bg-secondary` | Tags, badges, inset regions |
|
|
192
|
+
| **Primary action** | `bg-primary text-primary-foreground` | Buttons, key interactive elements |
|
|
193
|
+
| **Border** | `border-border` | Dividers, outlines |
|
|
194
|
+
|
|
195
|
+
**Rules:**
|
|
196
|
+
- Never use `text-white`, `text-black`, or raw hex/rgb values
|
|
197
|
+
- Never use palette colors for text or interactive elements — only for widget backgrounds
|
|
198
|
+
- Opacity modifiers are allowed on `text-foreground` (e.g. `text-foreground/70`) for subtle hierarchy
|
|
199
|
+
|
|
200
|
+
### Metaphorical Background Palette
|
|
201
|
+
|
|
202
|
+
Widget backgrounds use Tailwind palette colors that relate to the widget's content. This creates visual identity and makes the dashboard feel alive.
|
|
203
|
+
|
|
204
|
+
| Content domain | Background classes | Range |
|
|
205
|
+
|----------------|-------------------|-------|
|
|
206
|
+
| Weather / sky | `bg-sky-500`, `bg-sky-600`, `bg-blue-600`, `bg-blue-700` | 500–700 |
|
|
207
|
+
| Night / dark sky | `bg-indigo-900`, `bg-slate-800` | 800–900 |
|
|
208
|
+
| Overcast / fog | `bg-slate-500`, `bg-slate-600` | 500–600 |
|
|
209
|
+
| Nature / health | `bg-emerald-600`, `bg-green-600` | 500–700 |
|
|
210
|
+
| Finance / money | `bg-emerald-700`, `bg-teal-600` | 600–700 |
|
|
211
|
+
| Music / audio | `bg-violet-600`, `bg-fuchsia-600` | 500–700 |
|
|
212
|
+
| Alerts / urgent | `bg-red-600`, `bg-orange-600` | 500–700 |
|
|
213
|
+
| Time / clock | `bg-blue-600`, `bg-indigo-600` | 500–700 |
|
|
214
|
+
| Notes / text | `bg-amber-500`, `bg-yellow-500` | 400–600 |
|
|
215
|
+
| Social / comms | `bg-pink-500`, `bg-rose-500` | 400–600 |
|
|
216
|
+
| Productivity | `bg-cyan-600`, `bg-sky-700` | 500–700 |
|
|
217
|
+
| Neutral / generic | `bg-zinc-700`, `bg-neutral-700` | 600–800 |
|
|
218
|
+
|
|
219
|
+
**Rules:**
|
|
220
|
+
- Use the **500–700 range** for most backgrounds — vivid enough to feel distinct, dark enough for white text contrast
|
|
221
|
+
- Use **800–900** only for night/dark themes
|
|
222
|
+
- Fall back to `bg-background` (solid dark) only when no metaphor fits — try to find one first
|
|
223
|
+
- Pair backgrounds with `text-foreground` (white in dark theme) and `text-foreground/70` for secondary text
|
|
224
|
+
- Don't use palette colors for anything besides the widget root background
|
|
225
|
+
|
|
226
|
+
### Status Colors
|
|
227
|
+
|
|
228
|
+
Status dots are the one exception to "no palette colors for UI elements" — they encode meaning.
|
|
229
|
+
|
|
230
|
+
| State | Dot color | Text |
|
|
231
|
+
|-------|-----------|------|
|
|
232
|
+
| Active / healthy | `bg-emerald-400` | `Active`, `Connected`, `Healthy` |
|
|
233
|
+
| Warning | `bg-amber-400` | `Warning`, `Degraded` |
|
|
234
|
+
| Error / down | `bg-red-400` | `Error`, `Down`, `Failed` |
|
|
235
|
+
| Inactive / off | `bg-foreground/30` | `Inactive`, `Off`, `Paused` |
|
|
236
|
+
|
|
237
|
+
Always pair a status dot with a text label. Don't rely on color alone.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 7. Typography
|
|
242
|
+
|
|
243
|
+
### Font Stack
|
|
244
|
+
|
|
245
|
+
| Role | Class | When to use |
|
|
246
|
+
|------|-------|-------------|
|
|
247
|
+
| **UI text** | `font-sans` | All labels, headings, body text, descriptions |
|
|
248
|
+
| **Numeric data** | `font-mono tabular-nums` | Clocks, counters, live-updating numbers, stats |
|
|
249
|
+
|
|
250
|
+
Use `font-mono` only for numbers that update frequently — it prevents digit-width jitter. All other text uses `font-sans`.
|
|
251
|
+
|
|
252
|
+
### Type Scale
|
|
253
|
+
|
|
254
|
+
| Role | Classes | Use for |
|
|
255
|
+
|------|---------|---------|
|
|
256
|
+
| **Hero metric** | `text-3xl font-bold` | The single most important number in a 2x2 or larger widget |
|
|
257
|
+
| **Large metric** | `text-2xl font-bold` | Primary number in a 2x1 widget |
|
|
258
|
+
| **Medium metric** | `text-xl font-bold` | Primary number in a 1x1 widget, or secondary number in larger widgets |
|
|
259
|
+
| **Title** | `text-sm font-semibold` | Widget heading, section label |
|
|
260
|
+
| **Body** | `text-sm` | Supporting text, descriptions |
|
|
261
|
+
| **Caption** | `text-xs text-muted-foreground` | Timestamps, units, metadata, tertiary info |
|
|
262
|
+
|
|
263
|
+
**Limits:**
|
|
264
|
+
- Never go below `text-xs` (unreadable at widget scale)
|
|
265
|
+
- Never go above `text-3xl` (wastes space)
|
|
266
|
+
- Max 3 sizes per widget
|
|
267
|
+
- Max 2 weights per widget (`font-normal` + one of `font-semibold` or `font-bold`)
|
|
268
|
+
|
|
269
|
+
### Line Height & Tracking
|
|
270
|
+
|
|
271
|
+
- Hero/large metrics: add `leading-none` to keep numbers tight
|
|
272
|
+
- Body text: default leading is fine (don't override)
|
|
273
|
+
- Monospace numbers: always pair with `tabular-nums` to prevent width jitter
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## 8. Spacing, Radius, Motion & Icons
|
|
278
|
+
|
|
279
|
+
### Spacing Scale
|
|
280
|
+
|
|
281
|
+
Based on a 4px unit. Every spacing value should come from this scale.
|
|
282
|
+
|
|
283
|
+
| Token | Value | Tailwind | Semantic meaning |
|
|
284
|
+
|-------|-------|----------|-----------------|
|
|
285
|
+
| **Micro** | 2px | `gap-0.5`, `p-0.5` | Optical adjustment |
|
|
286
|
+
| **Tight** | 4px | `gap-1`, `p-1` | Belongs together (icon + label) |
|
|
287
|
+
| **Snug** | 8px | `gap-2`, `p-2` | Related items in a row |
|
|
288
|
+
| **Base** | 12px | `gap-3`, `p-3` | Comfortable separation |
|
|
289
|
+
| **Medium** | 16px | `gap-4`, `p-4` | Standard content padding, group separation |
|
|
290
|
+
| **Wide** | 24px | `gap-6`, `p-6` | Section break within widget |
|
|
291
|
+
| **Spacious** | 32px | `gap-8`, `p-8` | Major section break (rare in widgets) |
|
|
292
|
+
|
|
293
|
+
Content padding: `p-4` for all widgets, `p-6` for 2x2 or larger if needed. Never let content touch the card edges. Inner elements use `gap-*` for spacing between siblings, not margin.
|
|
294
|
+
|
|
295
|
+
Icon-text pairing: `gap-1` (4px) inline, `gap-2` (8px) stacked.
|
|
296
|
+
|
|
297
|
+
### Border Radius
|
|
298
|
+
|
|
299
|
+
The widget container applies outer border radius automatically (`rounded-2xl`). Do not add `rounded-*` to the widget root.
|
|
300
|
+
|
|
301
|
+
| Element | Class |
|
|
302
|
+
|---------|-------|
|
|
303
|
+
| Inner cards/surfaces | `rounded-lg` or `rounded-xl` |
|
|
304
|
+
| Tags/badges | `rounded-md` or `rounded-full` |
|
|
305
|
+
| Skeleton blocks | `rounded` or `rounded-md` |
|
|
306
|
+
| Images/avatars | `rounded-lg` or `rounded-full` |
|
|
307
|
+
|
|
308
|
+
Inner radius should always be smaller than outer radius.
|
|
309
|
+
|
|
310
|
+
### Motion & Animation
|
|
311
|
+
|
|
312
|
+
| Category | Duration | Use for |
|
|
313
|
+
|----------|----------|---------|
|
|
314
|
+
| **Micro** | 100–150ms | Hover states, opacity toggles, color transitions |
|
|
315
|
+
| **Standard** | 200–250ms | Content appearing, card transitions |
|
|
316
|
+
| **Emphasis** | 300ms | Important state changes (max for widgets) |
|
|
317
|
+
|
|
318
|
+
- Enter: `ease-out`. Exit: `ease-in`. Interactive: `ease-in-out`.
|
|
319
|
+
- Use `tw-animate-css` classes. No custom `@keyframes` unless absolutely necessary.
|
|
320
|
+
- Widget appear: `animate-in fade-in-0 zoom-in-95 duration-200`
|
|
321
|
+
- Content update: `animate-in fade-in-0 duration-150`
|
|
322
|
+
- Never animate frequently-updating numbers — just swap the value.
|
|
323
|
+
- Never exceed 300ms. One animation at a time. Every animation must communicate a state change.
|
|
324
|
+
|
|
325
|
+
### Iconography
|
|
326
|
+
|
|
327
|
+
All icons from `@tabler/icons-react`. No other packages. No raw `<svg>`.
|
|
328
|
+
|
|
329
|
+
| Context | Size prop |
|
|
330
|
+
|---------|-----------|
|
|
331
|
+
| Inline with `text-xs`/`text-sm` | `size={16}` |
|
|
332
|
+
| Inline with `text-base`/`text-lg` | `size={20}` |
|
|
333
|
+
| Standalone / decorative | `size={24}` |
|
|
334
|
+
| Hero icon (rare, 2x2 widgets) | `size={32}` |
|
|
335
|
+
| Inside `Button` | Don't set `size` |
|
|
336
|
+
|
|
337
|
+
Always set `stroke={1.5}`. Icons reinforce meaning — pair with a label except in obvious cases (refresh, close). Use `text-foreground` for primary, `text-foreground/70` or `text-muted-foreground` for secondary. Max 3–4 icons per widget.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 9. Widget Component Patterns
|
|
342
|
+
|
|
343
|
+
### 9.1 Metric Widget
|
|
344
|
+
|
|
345
|
+
Display a single important number with context. Sizes: 1x1, 1x2, 2x1.
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
┌──────────────────────┐
|
|
349
|
+
│ ▪ Category Label │ ← text-xs text-foreground/70, optional icon (size={12})
|
|
350
|
+
│ │
|
|
351
|
+
│ 42.7° │ ← text-2xl font-bold font-mono tabular-nums leading-none
|
|
352
|
+
│ Feels like 38° │ ← text-xs text-foreground/70
|
|
353
|
+
│ │
|
|
354
|
+
│ Updated 5m ago │ ← text-xs text-foreground/50, pushed to bottom with mt-auto
|
|
355
|
+
└──────────────────────┘
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
```tsx
|
|
359
|
+
<div className="flex flex-col w-full h-full p-4 {bg-color}">
|
|
360
|
+
<div className="flex items-center gap-1">
|
|
361
|
+
<Icon size={12} stroke={1.5} className="text-foreground/70" />
|
|
362
|
+
<span className="text-xs text-foreground/70">Label</span>
|
|
363
|
+
</div>
|
|
364
|
+
<span className="text-2xl font-bold font-mono tabular-nums leading-none mt-4">42.7°</span>
|
|
365
|
+
<span className="text-xs text-foreground/70 mt-1">Subtitle</span>
|
|
366
|
+
<span className="text-xs text-foreground/50 mt-auto">Updated 5m ago</span>
|
|
367
|
+
</div>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Variants: **Centered** (`items-center justify-center text-center`), **With icon** (icon + metric in a `flex items-end gap-2` row), **With trend** (`text-xs text-emerald-400` for positive), **With sparkline** (mini chart beside the number, 2x1 recommended).
|
|
371
|
+
|
|
372
|
+
### 9.2 Dual Metric Widget
|
|
373
|
+
|
|
374
|
+
Compare two related numbers side by side. Sizes: 2x1, 2x2.
|
|
375
|
+
|
|
376
|
+
```tsx
|
|
377
|
+
<div className="flex flex-col w-full h-full p-4 {bg-color}">
|
|
378
|
+
<span className="text-xs text-foreground/70">Category</span>
|
|
379
|
+
<div className="flex items-end gap-6 mt-4">
|
|
380
|
+
<div className="flex flex-col">
|
|
381
|
+
<span className="text-xl font-bold font-mono tabular-nums leading-none">72</span>
|
|
382
|
+
<span className="text-xs text-foreground/70 mt-1">Heart Rate</span>
|
|
383
|
+
</div>
|
|
384
|
+
<div className="flex flex-col">
|
|
385
|
+
<span className="text-xl font-bold font-mono tabular-nums leading-none">118/76</span>
|
|
386
|
+
<span className="text-xs text-foreground/70 mt-1">Blood Pressure</span>
|
|
387
|
+
</div>
|
|
388
|
+
</div>
|
|
389
|
+
</div>
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Max 2 metrics. Both use the same type size. Separate with `gap-6` or `border-r border-foreground/20`.
|
|
393
|
+
|
|
394
|
+
### 9.3 List Widget
|
|
395
|
+
|
|
396
|
+
Short list of items (3–7 rows). Sizes: 1x2, 2x2.
|
|
397
|
+
|
|
398
|
+
```tsx
|
|
399
|
+
<div className="flex flex-col w-full h-full p-4 {bg-color}">
|
|
400
|
+
<span className="text-sm font-semibold text-foreground">Title</span>
|
|
401
|
+
<div className="flex flex-col mt-3">
|
|
402
|
+
{items.map((item, i) => (
|
|
403
|
+
<div
|
|
404
|
+
key={i}
|
|
405
|
+
className={cx(
|
|
406
|
+
'flex items-center justify-between py-2',
|
|
407
|
+
i > 0 && 'border-t border-foreground/10'
|
|
408
|
+
)}
|
|
409
|
+
>
|
|
410
|
+
<div className="flex items-center gap-2 min-w-0">
|
|
411
|
+
<Icon size={16} stroke={1.5} className="text-foreground/70 shrink-0" />
|
|
412
|
+
<span className="text-sm text-foreground truncate">{item.label}</span>
|
|
413
|
+
</div>
|
|
414
|
+
<span className="text-xs text-foreground/70 shrink-0 ml-2">{item.value}</span>
|
|
415
|
+
</div>
|
|
416
|
+
))}
|
|
417
|
+
</div>
|
|
418
|
+
</div>
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Max 7 items in a 2-row widget, 3–4 in a 1-row. Truncate long labels. Right-align numeric values. Min `h-8` per row for interactive items.
|
|
422
|
+
|
|
423
|
+
### 9.4 Status Widget
|
|
424
|
+
|
|
425
|
+
Current state of something (on/off, healthy/error). Size: 1x1.
|
|
426
|
+
|
|
427
|
+
```tsx
|
|
428
|
+
<div className="flex flex-col items-center justify-center w-full h-full p-4 {bg-color}">
|
|
429
|
+
<div className="flex items-center gap-2">
|
|
430
|
+
<span className="h-2 w-2 rounded-full bg-emerald-400" />
|
|
431
|
+
<span className="text-sm font-semibold text-foreground">Active</span>
|
|
432
|
+
</div>
|
|
433
|
+
<span className="text-xs text-foreground/70 mt-1">Server Name</span>
|
|
434
|
+
</div>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
Status dot: `h-2 w-2 rounded-full`. See Section 6 for status colors.
|
|
438
|
+
|
|
439
|
+
### 9.5 Progress Widget
|
|
440
|
+
|
|
441
|
+
Progress toward a goal. Sizes: 1x1, 2x1.
|
|
442
|
+
|
|
443
|
+
```tsx
|
|
444
|
+
<div className="flex flex-col w-full h-full p-4 {bg-color}">
|
|
445
|
+
<span className="text-xs text-foreground/70">Steps Today</span>
|
|
446
|
+
<span className="text-xl font-bold font-mono tabular-nums leading-none mt-3">7,432</span>
|
|
447
|
+
<div className="flex items-center gap-2 mt-3">
|
|
448
|
+
<div className="flex-1 h-1.5 bg-foreground/20 rounded-full overflow-hidden">
|
|
449
|
+
<div className="h-full bg-foreground rounded-full" />
|
|
450
|
+
</div>
|
|
451
|
+
<span className="text-xs text-foreground/70 shrink-0">74%</span>
|
|
452
|
+
</div>
|
|
453
|
+
<span className="text-xs text-foreground/50 mt-1">Goal: 10,000</span>
|
|
454
|
+
</div>
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
Track: `h-1.5 bg-foreground/20 rounded-full`. Fill: `h-full bg-foreground rounded-full` with inline width. Always show numeric value alongside the bar.
|
|
458
|
+
|
|
459
|
+
### 9.6 Chart Widget
|
|
460
|
+
|
|
461
|
+
Visualize data trends. Sizes: 2x1 (sparkline), 2x2 (full), 4x2 (detailed).
|
|
462
|
+
|
|
463
|
+
```tsx
|
|
464
|
+
<div className="flex items-center w-full h-full p-4 {bg-color}">
|
|
465
|
+
<div className="flex flex-col shrink-0">
|
|
466
|
+
<span className="text-xs text-foreground/70">Revenue</span>
|
|
467
|
+
<span className="text-xl font-bold font-mono tabular-nums leading-none mt-1">$12.4k</span>
|
|
468
|
+
<span className="text-xs text-emerald-400 mt-1">+8.2%</span>
|
|
469
|
+
</div>
|
|
470
|
+
<div className="flex-1 h-full ml-4">{/* SVG or canvas chart */}</div>
|
|
471
|
+
</div>
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
Charts must always include a numeric readout. Primary series: `stroke-foreground` / `fill-foreground/80`. Secondary: `stroke-foreground/40`. Gridlines: `stroke-foreground/10`. Labels: `text-xs text-foreground/50 font-mono tabular-nums`.
|
|
475
|
+
|
|
476
|
+
### 9.7 Toggle / Control Widget
|
|
477
|
+
|
|
478
|
+
Quick on/off action. Size: 1x1.
|
|
479
|
+
|
|
480
|
+
```tsx
|
|
481
|
+
<div className="flex flex-col items-center justify-center w-full h-full p-4 {bg-color}">
|
|
482
|
+
<Icon size={24} stroke={1.5} className="text-foreground" />
|
|
483
|
+
<span className="text-sm font-semibold text-foreground mt-2">Label</span>
|
|
484
|
+
<button
|
|
485
|
+
onClick={toggle}
|
|
486
|
+
className={cx(
|
|
487
|
+
'mt-2 px-3 py-1 rounded-full text-xs font-semibold transition-colors',
|
|
488
|
+
isOn ? 'bg-foreground text-background' : 'bg-foreground/20 text-foreground/70'
|
|
489
|
+
)}
|
|
490
|
+
>
|
|
491
|
+
{isOn ? 'ON' : 'OFF'}
|
|
492
|
+
</button>
|
|
493
|
+
</div>
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Active = `bg-foreground text-background` (inverted). Inactive = `bg-foreground/20`. Max 1–2 interactive elements per 1x1.
|
|
497
|
+
|
|
498
|
+
### 9.8 Media Widget
|
|
499
|
+
|
|
500
|
+
Album art, photo, or visual content. Sizes: 1x1, 2x1, 2x2.
|
|
501
|
+
|
|
502
|
+
```tsx
|
|
503
|
+
<div className="relative w-full h-full overflow-hidden">
|
|
504
|
+
<img src={url} alt={alt} className="w-full h-full object-cover" />
|
|
505
|
+
<div className="absolute inset-x-0 bottom-0 bg-linear-to-t from-black/60 to-transparent p-4">
|
|
506
|
+
<span className="text-sm font-semibold text-white">Title</span>
|
|
507
|
+
<span className="text-xs text-white/70">Subtitle</span>
|
|
508
|
+
</div>
|
|
509
|
+
</div>
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Images: `object-cover`. Text over images requires gradient overlay. `text-white` is acceptable here — it's an image overlay, not a semantic surface.
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
## 10. UX Patterns
|
|
517
|
+
|
|
518
|
+
### 10.1 Loading
|
|
519
|
+
|
|
520
|
+
Show skeleton shapes that mirror the widget's real layout. Communicates "content is coming" without text.
|
|
521
|
+
|
|
522
|
+
```tsx
|
|
523
|
+
<div className="flex flex-col w-full h-full p-4 {bg-color}">
|
|
524
|
+
<div className="h-3 w-20 bg-foreground/20 rounded animate-pulse" />
|
|
525
|
+
<div className="h-8 w-24 bg-foreground/20 rounded animate-pulse mt-4" />
|
|
526
|
+
<div className="h-3 w-28 bg-foreground/20 rounded animate-pulse mt-2" />
|
|
527
|
+
<div className="h-3 w-16 bg-foreground/20 rounded animate-pulse mt-auto" />
|
|
528
|
+
</div>
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
- Skeleton blocks: `bg-foreground/20 rounded animate-pulse`. Match the real layout's height, width, and position.
|
|
532
|
+
- Vary block widths to mimic real content.
|
|
533
|
+
- **Never use spinners** for initial load. Keep the metaphorical background color during loading.
|
|
534
|
+
|
|
535
|
+
### 10.2 Error
|
|
536
|
+
|
|
537
|
+
```tsx
|
|
538
|
+
<div className="flex flex-col items-center justify-center w-full h-full p-4 gap-2 bg-background">
|
|
539
|
+
<Icon size={24} stroke={1.5} className="text-muted-foreground" />
|
|
540
|
+
<span className="text-xs text-destructive text-center">Could not load weather</span>
|
|
541
|
+
<button
|
|
542
|
+
onClick={retry}
|
|
543
|
+
className="text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground transition-colors"
|
|
544
|
+
>
|
|
545
|
+
Try again
|
|
546
|
+
</button>
|
|
547
|
+
</div>
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
- Use `bg-background` — drop the metaphorical color for errors.
|
|
551
|
+
- Max one sentence, human-readable. Never show stack traces.
|
|
552
|
+
- Always offer retry if the operation can be retried. Use a contextual icon.
|
|
553
|
+
|
|
554
|
+
### 10.3 Empty State
|
|
555
|
+
|
|
556
|
+
```tsx
|
|
557
|
+
<div className="flex flex-col items-center justify-center w-full h-full p-4 gap-2 bg-background">
|
|
558
|
+
<Icon size={24} stroke={1.5} className="text-muted-foreground" />
|
|
559
|
+
<span className="text-sm text-muted-foreground text-center">No tasks yet</span>
|
|
560
|
+
<span className="text-xs text-muted-foreground/70 text-center">Add a task to get started</span>
|
|
561
|
+
</div>
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
- Use `bg-background`. All text in `text-muted-foreground`. Don't leave completely blank.
|
|
565
|
+
|
|
566
|
+
### 10.4 Refreshing
|
|
567
|
+
|
|
568
|
+
- **Keep showing current data** during refresh. Never blank the widget.
|
|
569
|
+
- Spinning icon: `animate-spin` on refresh button. Disable while refreshing: `disabled:opacity-50`.
|
|
570
|
+
- Update in place when new data arrives. Use `animate-in fade-in-0 duration-150` for changed values.
|
|
571
|
+
|
|
572
|
+
### 10.5 Stale Data
|
|
573
|
+
|
|
574
|
+
```tsx
|
|
575
|
+
<span className="text-xs text-foreground/50 mt-auto">Updated {timeAgo(fetchedAt)}</span>
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Position at widget bottom with `mt-auto`. Use `text-xs text-foreground/50`. Re-render on interval (e.g. every 60s).
|
|
579
|
+
|
|
580
|
+
### 10.6 Interactive Elements
|
|
581
|
+
|
|
582
|
+
- Use the project's `Button` component: `default` (1 per widget max), `outline`, `ghost`, `icon`/`icon-sm`.
|
|
583
|
+
- Tap targets: icon buttons `h-8 w-8` (32px), text buttons `h-9 px-4`, list rows `h-8`.
|
|
584
|
+
- Max 1–2 actions per widget. Immediate visual feedback for every interaction.
|
|
585
|
+
- Use `transition-colors` for hover states. Disable during async: `disabled:opacity-50`.
|
|
586
|
+
|
|
587
|
+
### 10.7 Server Function Data Flow
|
|
588
|
+
|
|
589
|
+
```tsx
|
|
590
|
+
export default function MyWidget() {
|
|
591
|
+
const [data, setData] = useState<DataType | null>(null)
|
|
592
|
+
const [error, setError] = useState<string | null>(null)
|
|
593
|
+
const [loading, setLoading] = useState(true)
|
|
594
|
+
|
|
595
|
+
const load = useCallback(async () => {
|
|
596
|
+
try {
|
|
597
|
+
const result = await fetchData()
|
|
598
|
+
setData(result)
|
|
599
|
+
setError(null)
|
|
600
|
+
} catch {
|
|
601
|
+
setError('Could not load data')
|
|
602
|
+
} finally {
|
|
603
|
+
setLoading(false)
|
|
604
|
+
}
|
|
605
|
+
}, [])
|
|
606
|
+
|
|
607
|
+
useEffect(() => { load() }, [load])
|
|
608
|
+
|
|
609
|
+
if (loading) return <Skeleton />
|
|
610
|
+
if (error || !data) return <ErrorState error={error} onRetry={load} />
|
|
611
|
+
return <Content data={data} />
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
Always handle three states: loading, error, success. Wrap fetch in `useCallback` for reuse. For refresh, add separate `refreshing` state so existing content stays visible.
|
|
616
|
+
|
|
617
|
+
### 10.8 Conditional Classes
|
|
618
|
+
|
|
619
|
+
Use `cx()` helper for conditional classes (widgets can't import from `@/client/lib/cn`):
|
|
620
|
+
|
|
621
|
+
```tsx
|
|
622
|
+
function cx(...classes: (string | false | undefined | null)[]) {
|
|
623
|
+
return classes.filter(Boolean).join(' ')
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Usage
|
|
627
|
+
<div className={cx('flex p-4', isActive && 'bg-foreground/10')} />
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
Never use template literal ternaries for `className`.
|