yororen_ui 0.2.0

Reusable UI components and widgets built on top of gpui.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# Yororen UI

<p align="center">
  <a href="README_zh_CN.md">中文版</a> | <strong>English</strong>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License">
  <img src="https://img.shields.io/badge/rust-edition%202024-yellow.svg" alt="Rust Edition">
  <img src="https://img.shields.io/badge/gpui-based-2a2a2a.svg" alt="Powered by gpui">
</p>

<p align="center">
  <strong>Yororen UI</strong> is a reusable UI Components + Widgets library built on top of <a href="https://github.com/zed-industries/zed"><code>gpui</code></a> (Zed).
</p>

<p align="center">
  It is designed to be consumed by a <code>gpui</code> application crate, while keeping the UI layer self-contained (theme, components, widgets, and embedded icon assets).
</p>

---

## Features

<table>
  <tr>
    <td><strong>60+ Components</strong></td>
    <td>Buttons, inputs, badges, tooltips, icons, headings, cards, modals, tree controls, and more</td>
  </tr>
  <tr>
    <td><strong>Widgets</strong></td>
    <td>TitleBar, VirtualList and other advanced widgets</td>
  </tr>
  <tr>
    <td><strong>Theme System</strong></td>
    <td><code>GlobalTheme</code> + <code>ActiveTheme</code> helper, supporting light/dark mode</td>
  </tr>
  <tr>
    <td><strong>Animation System</strong></td>
    <td>Configurable animations with presets, easing functions, and orchestrator</td>
  </tr>
  <tr>
    <td><strong>Internationalization</strong></td>
    <td>Multi-language support (English, Chinese), text direction support (LTR/RTL)</td>
  </tr>
  <tr>
    <td><strong>Accessibility</strong></td>
    <td>ARIA support, focus management, keyboard navigation, focus trap</td>
  </tr>
  <tr>
    <td><strong>Embedded Assets</strong></td>
    <td>29+ SVG icons embedded via <code>rust-embed</code> (<code>assets/icons/**</code>)</td>
  </tr>
  <tr>
    <td><strong>Notification System</strong></td>
    <td>Toast notifications with various styles, queue management, and interactive actions</td>
  </tr>
</table>

---

## Quick Start

### 1) Register Components

Some components require one-time registration/initialization. Call `component::init` during app startup:

```rust
use gpui::App;
use yororen_ui::component;

fn init_ui(cx: &mut App) {
    component::init(cx);
}
```

### 2) Install the Global Theme

Yororen UI provides a `GlobalTheme` that selects light/dark palettes based on `WindowAppearance`.

```rust
use gpui::App;
use yororen_ui::theme::GlobalTheme;

fn init_theme(cx: &mut App) {
    cx.set_global(GlobalTheme::new(cx.window_appearance()));
}
```

Inside render functions you can access theme colors via `ActiveTheme`:

```rust
use gpui::{Render, div};
use yororen_ui::theme::ActiveTheme;

// in render(..., cx: &mut gpui::Context<Self>)
let theme = cx.theme();
let _ = div().bg(theme.surface.base).text_color(theme.content.primary);
```

### 2.5) Install i18n (Locale + RTL)

Yororen UI ships with an embedded JSON translation loader under `locales/*.json`.
Initialize `I18n` during app startup:

```rust
use gpui::App;
use yororen_ui::i18n::{I18n, Locale};

fn init_i18n(cx: &mut App) {
    // Load all embedded locales and pick a default.
    cx.set_global(I18n::with_embedded(Locale::new("en").unwrap()));
}
```

To preview RTL, switch the locale:

```rust
cx.set_global(I18n::with_embedded(Locale::new("ar").unwrap()));
```

### 3) Provide Assets (Icons)

This crate embeds its icons under `assets/icons/**` and exposes them as a `gpui::AssetSource` (`yororen_ui::assets::UiAsset`).

If your app only needs Yororen UI's icons, you can install them directly:

```rust
use gpui::Application;
use yororen_ui::assets::UiAsset;

let app = Application::new().with_assets(UiAsset);
```

If your app has its own assets too, compose asset sources so both sets are available. Yororen UI includes a small helper `CompositeAssetSource`:

```rust
use gpui::Application;
use yororen_ui::assets::{CompositeAssetSource, UiAsset};

// `MyAsset` is your own AssetSource implementation
let app = Application::new().with_assets(CompositeAssetSource::new(MyAsset, UiAsset));
```

**Important:** Your primary `AssetSource` should return `Ok(None)` when a path doesn't exist. If it returns an error on missing paths, it can prevent fallback to `UiAsset`.

---

## Demo Applications

We provide four official demo applications to help you get started:

| Demo | Description | Run Command |
|------|-------------|--------------|
| <a href="#counter">Counter</a> | Minimal counter app - perfect for learning basics | <code>cd demo/counter && cargo run</code> |
| <a href="#todolist">TodoList</a> | Todo app template - ideal for building full apps | <code>cd demo/todolist && cargo run</code> |
| <a href="#file-browser">File Browser</a> | File browser with tree structure | <code>cd demo/file_browser && cargo run</code> |
| <a href="#toast-notification">Toast Notification</a> | Toast notification showcase | <code>cd demo/toast_notification && cargo run</code> |

### Counter

<img src="demo/screenshots/counter.png" alt="Counter Demo" width="600">

A minimal counter application demonstrating the most fundamental Yororen UI concepts.

**Key Features:**
- Simple global state management (`Arc<Mutex<T>>`)
- Button click event handling (`on_click`)
- Reactive UI updates (`cx.notify()`)

**Best For:** Developers new to Yororen UI as their first learning example.

### TodoList

<img src="demo/screenshots/todolist.png" alt="TodoList Demo" width="600">

A todo list application template demonstrating standard patterns and best practices for building complete Yororen UI applications.

**Key Features:**
- Application bootstrap pattern
- Modular architecture (state, components, models)
- Global state management
- CRUD operations (create, read, update, delete todo items)

**Best For:** Developers building production applications, serving as a starter template.

### File Browser

<img src="demo/screenshots/file-browser.png" alt="File Browser Demo" width="600">

A fully functional file browser demo showing how to render and interact with complex hierarchical data structures.

**Key Features:**
- **Directory tree** (`Tree` + `TreeItem`): Display file system hierarchy
- **Icons**: File and folder icon display
- **Empty state**: Friendly message when no content
- **Context menu**: Right-click menu for copy/paste operations

**Best For:** Scenarios requiring tree structures, file managers, or any hierarchical data display.

### Toast Notification

<img src="demo/screenshots/toast-notification.png" alt="Toast Notification Demo" width="600">

Demonstrates the Toast notification component with various styles and usage patterns.

**Key Features:**
- Multiple Toast types: Success, Warning, Error, Info, Neutral
- Notification queue management (`NotificationCenter`)
- Interactive notifications (with action buttons)
- Custom notification content
- Different dismissal strategies (auto-dismiss/manual)

**Best For:** Applications that need to provide immediate feedback to users.

---

## Built with Yororen UI

Projects and applications built using Yororen UI.

### Yororen Accelerator

<img src="demo/screenshots/accelerator-1.png" alt="Yororen Accelerator" width="380">
<img src="demo/screenshots/accelerator-2.png" alt="Yororen Accelerator" width="380">

<img src="demo/screenshots/accelerator-3.png" alt="Yororen Accelerator" width="380">
<img src="demo/screenshots/accelerator-4.png" alt="Yororen Accelerator" width="380">

A network acceleration tool with native-transparent TCP forwarding + relay passthrough, built with Yororen UI.

**Key Highlights:**
- Complex dashboard with real-time statistics
- Custom window chrome with native-like experience
- Rich data tables and virtualized lists
- Server management and configuration UI

---

## What's Inside

### Modules

<table>
  <tr>
    <td><code>yororen_ui::theme</code></td>
    <td>
      <ul>
        <li><code>Theme</code> (palettes)</li>
        <li><code>GlobalTheme</code> (<code>gpui::Global</code>)</li>
        <li><code>ActiveTheme</code> trait (gives <code>theme()</code> on <code>App</code> and render contexts)</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::assets</code></td>
    <td>
      <ul>
        <li><code>UiAsset</code> (<code>gpui::AssetSource</code> for embedded icons)</li>
        <li><code>CompositeAssetSource</code> (compose two asset sources with fallback)</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::component</code></td>
    <td>
      <ul>
        <li>Common building blocks: <code>button</code>, <code>icon_button</code>, <code>text_input</code>, <code>password_input</code>, <code>tooltip</code>, <code>badge</code>, <code>divider</code>, etc.</li>
        <li><code>component::init(cx)</code> for any registrations</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::widget</code></td>
    <td>Higher-level widgets composed from components. Currently: <code>TitleBar</code> and <code>VirtualList</code>.</td>
  </tr>
  <tr>
    <td><code>yororen_ui::animation</code></td>
    <td>
      <ul>
        <li>Easing functions (linear, quad, cubic, back, elastic, bounce)</li>
        <li>Preset animations (fade, slide, scale, bounce)</li>
        <li>Animation orchestration (sequence, parallel, stagger)</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::a11y</code></td>
    <td>
      <ul>
        <li>ARIA role and attribute definitions</li>
        <li>Focus management (FocusTrap)</li>
        <li>Accessibility helpers</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::i18n</code></td>
    <td>
      <ul>
        <li>Multi-language support</li>
        <li>Locale management and runtime switching</li>
        <li>Number and date formatting</li>
      </ul>
    </td>
  </tr>
  <tr>
    <td><code>yororen_ui::notification</code></td>
    <td>
      <ul>
        <li><code>Toast</code> component</li>
        <li><code>NotificationCenter</code> for queue management</li>
      </ul>
    </td>
  </tr>
</table>

### Component Overview

<table>
  <tr>
    <td><strong>Foundation</strong></td>
    <td>Button, IconButton, Icon, Label, Text, Heading, Spacer, Divider, Card, FocusRing</td>
  </tr>
  <tr>
    <td><strong>Inputs</strong></td>
    <td>TextInput, PasswordInput, NumberInput, TextArea, SearchInput, FilePathInput, KeybindingInput</td>
  </tr>
  <tr>
    <td><strong>Selection</strong></td>
    <td>Checkbox, Radio, RadioGroup, Switch, Slider, Select, ComboBox</td>
  </tr>
  <tr>
    <td><strong>Display</strong></td>
    <td>Badge, Avatar, Image, Progress, Skeleton, Tag, Spinner</td>
  </tr>
  <tr>
    <td><strong>Overlays</strong></td>
    <td>Tooltip, Popover, Modal, Toast, DropdownMenu</td>
  </tr>
  <tr>
    <td><strong>Layout</strong></td>
    <td>Card, ListItem, EmptyState, Disclosure, ClickableSurface</td>
  </tr>
  <tr>
    <td><strong>Interaction</strong></td>
    <td>ToggleButton, SplitButton, DragHandle, ButtonGroup, ShortcutHint, KeybindingDisplay</td>
  </tr>
  <tr>
    <td><strong>Tree/Hierarchical</strong></td>
    <td>Tree, TreeNode, TreeItem, TreeData, TreeDrag</td>
  </tr>
  <tr>
    <td><strong>Forms</strong></td>
    <td>Form, ContextMenuTrigger</td>
  </tr>
  <tr>
    <td><strong>Navigation</strong></td>
    <td>TitleBar widget, VirtualList, VirtualRow</td>
  </tr>
</table>

### Icons

The component icon API uses strongly-typed names:

```rust
use yororen_ui::component::{icon, IconName};

let _ = icon(IconName::Minecraft);
```

Icon paths map to embedded SVG assets like `icons/minecraft.svg`.

---

## Requirements

<ul>
  <li><strong>Rust edition:</strong> 2024 (works with the toolchain used by your <code>gpui</code> app)</li>
  <li><code>gpui</code> is provided via <a href="https://crates.io/crates/gpui-ce"><code>gpui-ce</code></a> crate on crates.io</li>
</ul>

---

## Installation

### From crates.io (recommended)

```toml
[dependencies]
yororen_ui = "0.2"
```

### From GitHub (latest development)

```toml
[dependencies]
yororen_ui = { git = "https://github.com/MeowLynxSea/yororen-ui.git", tag = "v0.2.0" }
```

### From a local path (development)

```toml
[dependencies]
yororen_ui = { path = "../yororen-ui" }
```

---

## Dependencies

<code>gpui-ce</code> is distributed via crates.io with semantic versioning. Make sure your application uses a compatible version:

```toml
[dependencies]
gpui = { package = "gpui-ce", version = "0.3" }
```

In this repository, <code>gpui-ce</code> is specified in <code>Cargo.toml</code>.

---

## License

<ul>
  <li>Yororen UI is licensed under the <strong>Apache License, Version 2.0</strong>. See <code>LICENSE</code>.</li>
  <li>This project is built on top of <code>gpui</code> (Zed Industries), also Apache-2.0.</li>
</ul>

See <code>NOTICE</code> for attribution details.

---

## Contributing

Issues and PRs are welcome.

When changing visuals:
<ul>
  <li>Include screenshots or a short recording</li>
  <li>Keep changes <code>rustfmt</code> clean</li>
</ul>

---

## Wiki

See <a href="https://github.com/MeowLynxSea/yororen-ui/wiki" target="_blank">Yororen UI Wiki</a> for detailed documentation, guides, and component references.

---

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=MeowLynxSea/yororen-ui&type=date&legend=top-left)](https://www.star-history.com/#MeowLynxSea/yororen-ui&type=date&legend=top-left)