@termuijs/ui 0.1.3 → 0.1.4
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/README.md +100 -19
- package/dist/index.cjs +977 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +277 -2
- package/dist/index.d.ts +277 -2
- package/dist/index.js +952 -26
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @termuijs/ui
|
|
2
2
|
|
|
3
|
-
High-level interactive components built on
|
|
3
|
+
High-level interactive components built on `@termuijs/widgets`. Modals, selects, tabs, toasts, prompts, notification center, and specialized inputs.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -12,24 +12,34 @@ Requires `@termuijs/core` and `@termuijs/widgets`.
|
|
|
12
12
|
|
|
13
13
|
## Components
|
|
14
14
|
|
|
15
|
+
### Composite widgets
|
|
16
|
+
|
|
15
17
|
| Component | What it does |
|
|
16
18
|
|-----------|-------------|
|
|
17
|
-
| `Select` | Dropdown with arrow key navigation and filtering |
|
|
18
|
-
| `MultiSelect` | Multiple selection with
|
|
19
|
+
| `Select` | Dropdown with arrow key navigation and optional filtering |
|
|
20
|
+
| `MultiSelect` | Multiple selection with checkbox indicators |
|
|
19
21
|
| `Modal` | Overlay dialog. Traps focus so Tab stays inside |
|
|
20
|
-
| `Tabs` | Tab container with keyboard switching
|
|
21
|
-
| `
|
|
22
|
-
| `Form` | Groups inputs together with validation and a submit handler |
|
|
22
|
+
| `Tabs` | Tab container with keyboard switching |
|
|
23
|
+
| `Form` | Groups inputs with validation and a submit handler |
|
|
23
24
|
| `Tree` | Collapsible tree view for hierarchical data |
|
|
24
|
-
| `ConfirmDialog` |
|
|
25
|
-
| `CommandPalette` | Fuzzy-search command launcher
|
|
25
|
+
| `ConfirmDialog` | Yes / No dialog |
|
|
26
|
+
| `CommandPalette` | Fuzzy-search command launcher |
|
|
26
27
|
| `Divider` | Horizontal or vertical separator line |
|
|
27
|
-
| `
|
|
28
|
+
| `NotificationCenter` | Floating notification stack. Render once at the app root |
|
|
29
|
+
|
|
30
|
+
### Input variants
|
|
31
|
+
|
|
32
|
+
| Component | What it does |
|
|
33
|
+
|-----------|-------------|
|
|
34
|
+
| `PasswordInput` | Text input with character masking. Alt+V toggles visibility |
|
|
35
|
+
| `NumberInput` | Digits and decimal only. Arrow keys step by configurable amount |
|
|
36
|
+
| `PathInput` | Text input with Tab-completion from the file system |
|
|
37
|
+
| `KeyboardShortcuts` | Renders a grouped grid of key bindings |
|
|
28
38
|
|
|
29
39
|
## Usage
|
|
30
40
|
|
|
31
41
|
```typescript
|
|
32
|
-
import { Select, Modal,
|
|
42
|
+
import { Select, Modal, NotificationCenter, useNotifications } from '@termuijs/ui'
|
|
33
43
|
|
|
34
44
|
const select = new Select({
|
|
35
45
|
label: 'Choose a color',
|
|
@@ -42,21 +52,92 @@ const modal = new Modal({
|
|
|
42
52
|
content: 'Delete this file?',
|
|
43
53
|
onClose: () => {},
|
|
44
54
|
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Notifications
|
|
58
|
+
|
|
59
|
+
Place `NotificationCenter` at your app root once. Then call `useNotifications()` from any component.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { NotificationCenter, useNotifications } from '@termuijs/ui'
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<Box>
|
|
67
|
+
<NotificationCenter position="top-right" />
|
|
68
|
+
<Dashboard />
|
|
69
|
+
</Box>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function Dashboard() {
|
|
74
|
+
const { notify, dismiss } = useNotifications()
|
|
75
|
+
|
|
76
|
+
useKeymap({
|
|
77
|
+
's': async () => {
|
|
78
|
+
await save()
|
|
79
|
+
notify('Saved', { type: 'success', duration: 2000 })
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
return <Box>...</Box>
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`notify()` returns an ID. Pass it to `dismiss(id)` to remove the notification early. Pass `duration: 0` for a persistent notification.
|
|
87
|
+
|
|
88
|
+
## Imperative prompts
|
|
89
|
+
|
|
90
|
+
Ask for user input without restructuring your component tree. All four functions return Promises.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { prompt } from '@termuijs/ui'
|
|
94
|
+
|
|
95
|
+
// Text input
|
|
96
|
+
const name = await prompt.text('Enter your name:')
|
|
97
|
+
|
|
98
|
+
// Confirmation
|
|
99
|
+
const ok = await prompt.confirm('Delete all logs?')
|
|
100
|
+
if (ok) deleteLogs()
|
|
101
|
+
|
|
102
|
+
// Single selection
|
|
103
|
+
const env = await prompt.select('Choose environment:', ['dev', 'staging', 'prod'])
|
|
104
|
+
|
|
105
|
+
// Multiple selection
|
|
106
|
+
const features = await prompt.multiSelect('Enable features:', ['auth', 'cache', 'logging'])
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Prompts block key input to the rest of the UI while open. A focus trap is applied automatically.
|
|
110
|
+
|
|
111
|
+
## Specialized inputs
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { PasswordInput, NumberInput, PathInput, KeyboardShortcuts } from '@termuijs/ui'
|
|
115
|
+
|
|
116
|
+
const pwd = new PasswordInput({ placeholder: 'Password', onChange: (v) => setVal(v) })
|
|
117
|
+
// Alt+V toggles character masking
|
|
118
|
+
|
|
119
|
+
const num = new NumberInput({
|
|
120
|
+
value: 10,
|
|
121
|
+
min: 0,
|
|
122
|
+
max: 100,
|
|
123
|
+
step: 5,
|
|
124
|
+
onChange: (v) => setCount(v),
|
|
125
|
+
})
|
|
126
|
+
// Arrow keys step up/down. Rejects non-numeric input.
|
|
45
127
|
|
|
46
|
-
|
|
47
|
-
|
|
128
|
+
const path = new PathInput({ cwd: process.cwd(), showHidden: false })
|
|
129
|
+
// Tab key completes from fs.readdirSync
|
|
48
130
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
{
|
|
54
|
-
{ label: 'Quit', action: () => app.exit() },
|
|
131
|
+
const shortcuts = new KeyboardShortcuts({
|
|
132
|
+
bindings: [
|
|
133
|
+
{ key: 'ctrl+c', description: 'Quit', category: 'General' },
|
|
134
|
+
{ key: '/', description: 'Search', category: 'Navigation' },
|
|
135
|
+
{ key: 'Enter', description: 'Select', category: 'Navigation' },
|
|
55
136
|
],
|
|
137
|
+
columns: 2,
|
|
56
138
|
})
|
|
57
139
|
```
|
|
58
140
|
|
|
59
|
-
|
|
60
141
|
## Documentation
|
|
61
142
|
|
|
62
143
|
Full docs at [www.termui.io/docs/ui/overview](https://www.termui.io/docs/ui/overview).
|