xertica-ui 2.1.2 → 2.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/CHANGELOG.md +46 -0
- package/README.md +1 -1
- package/bin/cli.ts +1 -1
- package/bin/generate-tokens.ts +13 -7
- package/components/assistant/xertica-assistant/index.ts +2 -0
- package/components/assistant/xertica-assistant/parts/AssistantCollapsedView.tsx +97 -0
- package/components/assistant/xertica-assistant/parts/AssistantConversationList.tsx +104 -0
- package/components/assistant/xertica-assistant/parts/AssistantDocumentEditor.tsx +81 -0
- package/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.tsx +86 -0
- package/components/assistant/xertica-assistant/parts/AssistantHeader.tsx +77 -0
- package/components/assistant/xertica-assistant/parts/AssistantMessageBubble.tsx +573 -0
- package/components/assistant/xertica-assistant/parts/AssistantTabBar.tsx +65 -0
- package/components/assistant/xertica-assistant/parts/AssistantTypingIndicator.tsx +41 -0
- package/components/assistant/xertica-assistant/parts/AssistantWelcomeScreen.tsx +98 -0
- package/components/assistant/xertica-assistant/parts/index.ts +16 -0
- package/components/assistant/xertica-assistant/types.ts +139 -0
- package/components/assistant/xertica-assistant/use-assistant.ts +559 -0
- package/components/assistant/xertica-assistant/xertica-assistant.stories.tsx +200 -0
- package/components/assistant/xertica-assistant/xertica-assistant.tsx +198 -1460
- package/components/brand/theme-toggle/ThemeToggle.tsx +8 -27
- package/components/hooks/index.ts +3 -0
- package/components/hooks/use-layout-shortcuts.ts +46 -0
- package/components/layout/sidebar/index.ts +2 -0
- package/components/layout/sidebar/sidebar.stories.tsx +160 -8
- package/components/layout/sidebar/sidebar.tsx +606 -497
- package/components/layout/sidebar/use-sidebar.ts +104 -0
- package/components/media/audio-player/AudioPlayer.tsx +131 -206
- package/components/media/audio-player/use-audio-player.ts +298 -0
- package/components/pages/home-page/HomePage.tsx +1 -1
- package/components/pages/template-content/TemplateContent.tsx +5 -5
- package/components/pages/template-page/TemplatePage.tsx +5 -5
- package/components/shared/CustomTooltipContent.tsx +52 -0
- package/components/shared/layout-constants.ts +1 -1
- package/components/ui/chart/chart.stories.tsx +966 -7
- package/components/ui/chart/chart.tsx +918 -45
- package/components/ui/file-upload/file-upload.stories.tsx +100 -0
- package/components/ui/file-upload/file-upload.tsx +14 -74
- package/components/ui/file-upload/index.ts +1 -0
- package/components/ui/file-upload/use-file-upload.ts +181 -0
- package/components/ui/pagination/index.ts +2 -0
- package/components/ui/pagination/pagination.stories.tsx +94 -0
- package/components/ui/pagination/use-pagination.ts +194 -0
- package/components/ui/rich-text-editor/index.ts +2 -0
- package/components/ui/rich-text-editor/rich-text-editor.stories.tsx +129 -1
- package/components/ui/rich-text-editor/rich-text-editor.tsx +86 -305
- package/components/ui/rich-text-editor/use-rich-text-editor.ts +439 -0
- package/components/ui/stepper/index.ts +3 -1
- package/components/ui/stepper/stepper.stories.tsx +116 -0
- package/components/ui/stepper/stepper.tsx +4 -4
- package/components/ui/stepper/use-stepper.ts +137 -0
- package/components/ui/tree-view/index.ts +4 -1
- package/components/ui/tree-view/tree-view.stories.tsx +110 -4
- package/components/ui/tree-view/tree-view.tsx +17 -125
- package/components/ui/tree-view/use-tree-view.ts +229 -0
- package/contexts/AssistenteContext.tsx +17 -54
- package/contexts/BrandColorsContext.tsx +6 -17
- package/contexts/LayoutContext.tsx +5 -31
- package/dist/AssistantChart-BAudAfne.cjs +3591 -0
- package/dist/AssistantChart-BP8upjMk.js +3565 -0
- package/dist/AudioPlayer-1ypwE2Wh.cjs +936 -0
- package/dist/AudioPlayer-DuKXrCfy.js +937 -0
- package/dist/CustomTooltipContent-DHjkY0ww.js +40 -0
- package/dist/CustomTooltipContent-c_K-DWRr.cjs +56 -0
- package/dist/LanguageContext-BwhwC3G2.js +657 -0
- package/dist/LanguageContext-DvUt5jBg.cjs +656 -0
- package/dist/LayoutContext-BDmcZfMH.cjs +84 -0
- package/dist/LayoutContext-dbQvdC4O.js +85 -0
- package/dist/ThemeContext-RTy1m2Uq.js +82 -0
- package/dist/ThemeContext-bSzuOit2.cjs +81 -0
- package/dist/VerifyEmailPage-C_ihbcth.js +2828 -0
- package/dist/VerifyEmailPage-Dt7zgA4w.cjs +2827 -0
- package/dist/XerticaProvider-CW9hpCdF.cjs +39 -0
- package/dist/XerticaProvider-siSt9uG2.js +40 -0
- package/dist/XerticaXLogo-D8jf0SNv.cjs +214 -0
- package/dist/XerticaXLogo-fAJMy3H4.js +215 -0
- package/dist/assistant.cjs.js +2 -1
- package/dist/assistant.es.js +3 -2
- package/dist/brand.cjs.js +2 -2
- package/dist/brand.es.js +2 -2
- package/dist/cli.js +14 -8
- package/dist/components/assistant/xertica-assistant/index.d.ts +2 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantCollapsedView.d.ts +13 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantConversationList.d.ts +16 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantDocumentEditor.d.ts +17 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantFeedbackDialog.d.ts +19 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantHeader.d.ts +11 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantMessageBubble.d.ts +29 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantTabBar.d.ts +13 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantTypingIndicator.d.ts +4 -0
- package/dist/components/assistant/xertica-assistant/parts/AssistantWelcomeScreen.d.ts +17 -0
- package/dist/components/assistant/xertica-assistant/parts/index.d.ts +16 -0
- package/dist/components/assistant/xertica-assistant/types.d.ts +106 -0
- package/dist/components/assistant/xertica-assistant/use-assistant.d.ts +125 -0
- package/dist/components/assistant/xertica-assistant/xertica-assistant.d.ts +8 -97
- package/dist/components/hooks/index.d.ts +3 -0
- package/dist/components/hooks/use-layout-shortcuts.d.ts +22 -0
- package/dist/components/layout/sidebar/index.d.ts +2 -0
- package/dist/components/layout/sidebar/sidebar.d.ts +80 -0
- package/dist/components/layout/sidebar/use-sidebar.d.ts +22 -0
- package/dist/components/media/audio-player/AudioPlayer.d.ts +4 -1
- package/dist/components/media/audio-player/use-audio-player.d.ts +72 -0
- package/dist/components/shared/CustomTooltipContent.d.ts +20 -0
- package/dist/components/shared/layout-constants.d.ts +1 -1
- package/dist/components/ui/alert/alert.d.ts +1 -1
- package/dist/components/ui/badge/badge.d.ts +1 -1
- package/dist/components/ui/button/button.d.ts +2 -2
- package/dist/components/ui/chart/chart.d.ts +162 -5
- package/dist/components/ui/file-upload/file-upload.d.ts +2 -0
- package/dist/components/ui/file-upload/index.d.ts +1 -0
- package/dist/components/ui/file-upload/use-file-upload.d.ts +49 -0
- package/dist/components/ui/pagination/index.d.ts +2 -0
- package/dist/components/ui/pagination/use-pagination.d.ts +78 -0
- package/dist/components/ui/rich-text-editor/index.d.ts +2 -0
- package/dist/components/ui/rich-text-editor/use-rich-text-editor.d.ts +107 -0
- package/dist/components/ui/stepper/index.d.ts +3 -1
- package/dist/components/ui/stepper/stepper.d.ts +2 -2
- package/dist/components/ui/stepper/use-stepper.d.ts +60 -0
- package/dist/components/ui/tree-view/index.d.ts +4 -1
- package/dist/components/ui/tree-view/tree-view.d.ts +4 -6
- package/dist/components/ui/tree-view/use-tree-view.d.ts +60 -0
- package/dist/contexts/AssistenteContext.d.ts +10 -49
- package/dist/hooks.cjs.js +30 -10
- package/dist/hooks.es.js +25 -4
- package/dist/index.cjs.js +20 -9
- package/dist/index.es.js +38 -27
- package/dist/layout.cjs.js +82 -1
- package/dist/layout.es.js +83 -2
- package/dist/media.cjs.js +1 -1
- package/dist/media.es.js +1 -1
- package/dist/pages.cjs.js +1 -1
- package/dist/pages.es.js +1 -1
- package/dist/rich-text-editor-BmsjY03B.js +2949 -0
- package/dist/rich-text-editor-GS2kpTAK.cjs +2966 -0
- package/dist/sidebar-CVUGHOS_.cjs +756 -0
- package/dist/sidebar-CmvwjnVb.js +757 -0
- package/dist/ui.cjs.js +12 -2
- package/dist/ui.es.js +24 -14
- package/dist/use-audio-player-Bkh23vQ3.js +177 -0
- package/dist/use-audio-player-Dn1NR9xN.cjs +176 -0
- package/dist/utils/color-utils.d.ts +51 -0
- package/dist/xertica-assistant-BMqdyRVi.js +2082 -0
- package/dist/xertica-assistant-Bj3vBCq_.cjs +2081 -0
- package/dist/xertica-ui.css +1 -1
- package/docs/ai-usage.md +28 -10
- package/docs/architecture-improvements.md +463 -0
- package/docs/architecture.md +77 -1
- package/docs/components/assistant-chart.md +1 -1
- package/docs/components/assistant.md +159 -0
- package/docs/components/audio-player.md +46 -0
- package/docs/components/branding.md +251 -0
- package/docs/components/chart.md +354 -39
- package/docs/components/code-block.md +108 -0
- package/docs/components/file-upload.md +119 -2
- package/docs/components/formatted-document.md +113 -0
- package/docs/components/hooks.md +430 -0
- package/docs/components/image-with-fallback.md +106 -0
- package/docs/components/map-layers.md +140 -0
- package/docs/components/modern-chat-input.md +163 -0
- package/docs/components/pages.md +351 -0
- package/docs/components/pagination.md +187 -0
- package/docs/components/rich-text-editor.md +164 -0
- package/docs/components/sidebar.md +153 -4
- package/docs/components/stepper.md +157 -12
- package/docs/components/tree-view.md +164 -6
- package/docs/doc-audit.md +223 -0
- package/docs/getting-started.md +155 -1
- package/docs/guidelines.md +14 -8
- package/docs/layout.md +2 -2
- package/docs/llms.md +29 -9
- package/docs/patterns/detail-page.md +276 -0
- package/docs/patterns/settings.md +346 -0
- package/docs/patterns/wizard.md +217 -0
- package/guidelines/Guidelines.md +5 -3
- package/llms.txt +1 -1
- package/package.json +10 -10
- package/styles/xertica/tokens.css +41 -12
- package/templates/CLAUDE.md +16 -6
- package/templates/guidelines/Guidelines.md +16 -4
- package/templates/package.json +3 -3
- package/templates/src/styles/xertica/tokens.css +39 -10
- package/utils/color-utils.ts +72 -0
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
A lightweight, native WYSIWYG (What You See Is What You Get) document text editor built into the Xertica UI framework. It utilizes the browser's native `contentEditable` architecture and `document.execCommand` under the hood to provide essential text formatting without the overhead of massive third-party rendering engines.
|
|
6
6
|
|
|
7
|
+
The component ships in **two usage patterns**:
|
|
8
|
+
|
|
9
|
+
| Pattern | When to use |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `<RichTextEditor />` | Drop-in editor with full toolbar and status bar — zero configuration needed |
|
|
12
|
+
| `useRichTextEditor()` | Headless hook — bring your own toolbar, layout, and styling |
|
|
13
|
+
|
|
7
14
|
---
|
|
8
15
|
|
|
9
16
|
## Features
|
|
@@ -38,6 +45,12 @@ A lightweight, native WYSIWYG (What You See Is What You Get) document text edito
|
|
|
38
45
|
| `allowLists` | `boolean` | `true` | No | Whether to show list functionality in the toolbar. |
|
|
39
46
|
| `showWordCount` | `boolean` | `true` | No | Whether to show the word count in the footer. |
|
|
40
47
|
| `showCharacterCount` | `boolean` | `true` | No | Whether to show the character count in the footer. |
|
|
48
|
+
| `disabled` | `boolean` | `false` | No | Disables all editing and applies opacity-50. Hides the toolbar. |
|
|
49
|
+
| `readOnly` | `boolean` | `false` | No | Makes the editor non-editable while keeping full visual fidelity. Hides the toolbar. |
|
|
50
|
+
| `onFocus` | `() => void` | — | No | Called when the editor area receives focus. |
|
|
51
|
+
| `onBlur` | `() => void` | — | No | Called when the editor area loses focus. |
|
|
52
|
+
| `minHeight` | `string` | — | No | Minimum height of the editable area (CSS value, e.g. `"200px"`). |
|
|
53
|
+
| `maxHeight` | `string` | — | No | Maximum height of the editable area (CSS value, e.g. `"600px"`). |
|
|
41
54
|
|
|
42
55
|
---
|
|
43
56
|
|
|
@@ -70,6 +83,143 @@ export function EditorExample() {
|
|
|
70
83
|
}
|
|
71
84
|
```
|
|
72
85
|
|
|
86
|
+
### Minimal Toolbar
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<RichTextEditor
|
|
90
|
+
value={content}
|
|
91
|
+
onChange={setContent}
|
|
92
|
+
allowHeadings={false}
|
|
93
|
+
allowAlignment={false}
|
|
94
|
+
allowLists={false}
|
|
95
|
+
allowLinks={false}
|
|
96
|
+
allowSearch={false}
|
|
97
|
+
showWordCount={false}
|
|
98
|
+
showCharacterCount={false}
|
|
99
|
+
/>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Headless Hook — `useRichTextEditor()`
|
|
105
|
+
|
|
106
|
+
Use the headless hook when you need full control over the editor's UI — custom toolbar layout, custom styling, or embedding the editor logic inside a larger component.
|
|
107
|
+
|
|
108
|
+
### Import
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import { useRichTextEditor } from 'xertica-ui/ui';
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Hook Props
|
|
115
|
+
|
|
116
|
+
| Prop | Type | Required | Description |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| `value` | `string` | Yes | Current HTML value of the editor |
|
|
119
|
+
| `onChange` | `(value: string) => void` | No | Called whenever the editor content changes |
|
|
120
|
+
|
|
121
|
+
### Hook Return Value
|
|
122
|
+
|
|
123
|
+
| Property | Type | Description |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `editorRef` | `RefObject<HTMLDivElement>` | Attach to the `contenteditable` div |
|
|
126
|
+
| `searchInputRef` | `RefObject<HTMLInputElement>` | Attach to the search `<input>` |
|
|
127
|
+
| `linkInputRef` | `RefObject<HTMLInputElement>` | Attach to the link URL `<input>` |
|
|
128
|
+
| `activeFormats` | `ActiveFormats` | Map of currently active formatting commands |
|
|
129
|
+
| `isSearchOpen` | `boolean` | Whether the inline search bar is open |
|
|
130
|
+
| `setIsSearchOpen` | `(open: boolean) => void` | Toggle the search bar |
|
|
131
|
+
| `searchQuery` | `string` | Current search query string |
|
|
132
|
+
| `setSearchQuery` | `(query: string) => void` | Update the search query |
|
|
133
|
+
| `linkUrl` | `string` | Current link URL being edited |
|
|
134
|
+
| `setLinkUrl` | `(url: string) => void` | Update the link URL |
|
|
135
|
+
| `isLinkOpen` | `boolean` | Whether the link popover is open |
|
|
136
|
+
| `wordCount` | `number` | Word count of the editor content |
|
|
137
|
+
| `characterCount` | `number` | Character count of the editor content |
|
|
138
|
+
| `updateActiveFormats` | `() => void` | Re-read the current selection and update `activeFormats` |
|
|
139
|
+
| `execCommand` | `(command: string, value?: string) => void` | Execute a `document.execCommand` and sync state |
|
|
140
|
+
| `handleInput` | `() => void` | Call on every `input` event of the editor |
|
|
141
|
+
| `performSearch` | `(text: string, backward?: boolean) => void` | Search forward or backward |
|
|
142
|
+
| `handleCreateLink` | `() => void` | Create or update a hyperlink at the current selection |
|
|
143
|
+
| `handleUnlink` | `() => void` | Remove the hyperlink at the current cursor position |
|
|
144
|
+
| `onLinkPopoverOpenChange` | `(open: boolean) => void` | Handle link popover open/close |
|
|
145
|
+
|
|
146
|
+
### `ActiveFormats` Type
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
interface ActiveFormats {
|
|
150
|
+
bold: boolean;
|
|
151
|
+
italic: boolean;
|
|
152
|
+
underline: boolean;
|
|
153
|
+
justifyLeft: boolean;
|
|
154
|
+
justifyCenter: boolean;
|
|
155
|
+
justifyRight: boolean;
|
|
156
|
+
insertUnorderedList: boolean;
|
|
157
|
+
insertOrderedList: boolean;
|
|
158
|
+
link: boolean;
|
|
159
|
+
h1: boolean;
|
|
160
|
+
h2: boolean;
|
|
161
|
+
h3: boolean;
|
|
162
|
+
p: boolean;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Headless Hook Example
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { useState } from 'react';
|
|
170
|
+
import { useRichTextEditor } from 'xertica-ui/ui';
|
|
171
|
+
|
|
172
|
+
function MyMinimalEditor({ value, onChange }) {
|
|
173
|
+
const {
|
|
174
|
+
editorRef,
|
|
175
|
+
activeFormats,
|
|
176
|
+
execCommand,
|
|
177
|
+
handleInput,
|
|
178
|
+
wordCount,
|
|
179
|
+
} = useRichTextEditor({ value, onChange });
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div className="border rounded-lg overflow-hidden">
|
|
183
|
+
{/* Custom minimal toolbar */}
|
|
184
|
+
<div className="flex gap-1 p-2 border-b bg-muted/30">
|
|
185
|
+
<button
|
|
186
|
+
onClick={() => execCommand('bold')}
|
|
187
|
+
className={activeFormats.bold ? 'font-bold text-primary' : 'text-muted-foreground'}
|
|
188
|
+
>
|
|
189
|
+
B
|
|
190
|
+
</button>
|
|
191
|
+
<button
|
|
192
|
+
onClick={() => execCommand('italic')}
|
|
193
|
+
className={activeFormats.italic ? 'italic text-primary' : 'text-muted-foreground'}
|
|
194
|
+
>
|
|
195
|
+
I
|
|
196
|
+
</button>
|
|
197
|
+
<button
|
|
198
|
+
onClick={() => execCommand('underline')}
|
|
199
|
+
className={activeFormats.underline ? 'underline text-primary' : 'text-muted-foreground'}
|
|
200
|
+
>
|
|
201
|
+
U
|
|
202
|
+
</button>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
{/* Editor area */}
|
|
206
|
+
<div
|
|
207
|
+
ref={editorRef}
|
|
208
|
+
contentEditable
|
|
209
|
+
onInput={handleInput}
|
|
210
|
+
className="p-4 min-h-[200px] focus:outline-none"
|
|
211
|
+
data-placeholder="Start typing..."
|
|
212
|
+
/>
|
|
213
|
+
|
|
214
|
+
{/* Custom footer */}
|
|
215
|
+
<div className="px-4 py-1 border-t text-xs text-muted-foreground">
|
|
216
|
+
{wordCount} words
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
73
223
|
---
|
|
74
224
|
|
|
75
225
|
## Component Architecture Notes
|
|
@@ -77,3 +227,17 @@ export function EditorExample() {
|
|
|
77
227
|
- **Data Binding:** The editor takes `value` *only for its initial render mount*, then operates autonomously internally. It uses continuous `innerHTML` tracking out to the `onChange` event. Avoid forcefully re-rendering the component from the top-down while typing, as it can cause cursor jump displacement.
|
|
78
228
|
- **Radix UI Interaction:** The `DropdownMenu` inside the toolbar is customized with `modal={false}` and intercepts `onPointerDown` events on its MenuItems. This is a critical technical choice that prevents modern React Portals from stealing DOM focus away from the `contentEditable` area when selecting Headings.
|
|
79
229
|
- **CSS Encapsulation:** Core semantic elements (`h1`, `h2`, `h3`, `p`, `ul`, `b`, `i`) are uniquely targeted via the internal `.prose-editor` stylesheet, freeing the global scope from collisions.
|
|
230
|
+
- **Headless Hook:** All state, refs, and DOM-manipulation logic live in `useRichTextEditor`. The `RichTextEditor` component is a thin presentation layer on top of this hook.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## AI Rules
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
- ALWAYS use `useRichTextEditor()` when building a custom editor UI — never re-implement `execCommand` logic manually.
|
|
238
|
+
- The `editorRef` from the hook MUST be attached to the `contenteditable` div.
|
|
239
|
+
- Call `handleInput` on every `onInput` event of the editor div to keep `onChange` and `activeFormats` in sync.
|
|
240
|
+
- `execCommand` already calls `handleInput` internally — do not call both for the same action.
|
|
241
|
+
- `wordCount` and `characterCount` are computed from `editorRef.current.innerText` — they update after `handleInput` is called.
|
|
242
|
+
- The `activeFormats` object reflects the formatting state at the current cursor position. Use it to highlight active toolbar buttons.
|
|
243
|
+
```
|
|
@@ -6,6 +6,14 @@ The `Sidebar` is the primary vertical navigation panel of the application shell.
|
|
|
6
6
|
|
|
7
7
|
It is a responsive component that can be expanded or collapsed as an icon-only strip, fully integrated with the `LayoutContext` for state management.
|
|
8
8
|
|
|
9
|
+
The component ships with **three usage patterns** to cover different levels of customization:
|
|
10
|
+
|
|
11
|
+
| Pattern | When to use |
|
|
12
|
+
|---|---|
|
|
13
|
+
| **Monolithic API** (`<Sidebar />`) | Standard usage — pass props, get a fully-featured sidebar |
|
|
14
|
+
| **Compound Component API** (`<Sidebar.Root>` + sub-components) | Custom layouts — compose only the parts you need |
|
|
15
|
+
| **Headless Hook** (`useSidebar()`) | Full control — manage state yourself, render anything |
|
|
16
|
+
|
|
9
17
|
---
|
|
10
18
|
|
|
11
19
|
## Variants
|
|
@@ -36,6 +44,8 @@ Designed for complex tools, agents, or multi-context navigation.
|
|
|
36
44
|
|
|
37
45
|
## Props
|
|
38
46
|
|
|
47
|
+
### `<Sidebar />` (Monolithic API)
|
|
48
|
+
|
|
39
49
|
| Prop | Type | Default | Description |
|
|
40
50
|
|---|---|---|---|
|
|
41
51
|
| `expanded` | `boolean` | `auto` | Controlled state. Defaults to `LayoutContext` or local state. |
|
|
@@ -47,8 +57,45 @@ Designed for complex tools, agents, or multi-context navigation.
|
|
|
47
57
|
| `search` | `SidebarSearchConfig` | — | Search bar configuration (assistant variant). |
|
|
48
58
|
| `logo` | `ReactNode` | — | Logo shown when expanded. |
|
|
49
59
|
| `logoCollapsed` | `ReactNode` | — | Logo shown when collapsed. |
|
|
50
|
-
| `width` | `number` | `
|
|
60
|
+
| `width` | `number` | `280` | Expanded sidebar width in pixels. |
|
|
51
61
|
| `footer` | `SidebarFooterConfig` | — | Footer visibility flags (`showUser`, `showSettings`, `showLogout`). |
|
|
62
|
+
| `showFooter` | `boolean` | `true` for default, `false` for assistant | Whether to render the footer section. |
|
|
63
|
+
|
|
64
|
+
### `<Sidebar.Root />` (Compound Component)
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Default | Description |
|
|
67
|
+
|---|---|---|---|
|
|
68
|
+
| `expanded` | `boolean` | `auto` | Controlled expansion state. |
|
|
69
|
+
| `onToggle` | `() => void` | `auto` | Toggle callback. |
|
|
70
|
+
| `navigate` | `(path: string) => void` | `window.location.href` | Navigation handler. |
|
|
71
|
+
| `location` | `{ pathname: string }` | `window.location` | Current location for active state. |
|
|
72
|
+
| `width` | `number` | `280` | Expanded width in pixels. |
|
|
73
|
+
| `children` | `ReactNode` | — | Sub-components: `Sidebar.Header`, `Sidebar.Nav`, `Sidebar.Footer`, `Sidebar.Search`. |
|
|
74
|
+
|
|
75
|
+
### `useSidebar()` (Headless Hook)
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { useSidebar } from 'xertica-ui/layout';
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
expanded, // boolean — current expansion state
|
|
82
|
+
setExpanded, // (value: boolean | fn) => void
|
|
83
|
+
toggleExpanded, // () => void
|
|
84
|
+
isMobileViewport, // boolean
|
|
85
|
+
hasOverflow, // boolean — nav items overflow the container
|
|
86
|
+
visibleItems, // RouteGroup[] — items that fit in the nav
|
|
87
|
+
overflowItems, // RouteGroup[] — items that overflow
|
|
88
|
+
openSubmenu, // string | null
|
|
89
|
+
setOpenSubmenu, // (id: string | null) => void
|
|
90
|
+
isFilterOpen, // boolean
|
|
91
|
+
setIsFilterOpen, // (open: boolean) => void
|
|
92
|
+
navRef, // RefObject<HTMLElement> — attach to nav container
|
|
93
|
+
navigationGroups, // RouteGroup[] — the resolved groups passed in
|
|
94
|
+
} = useSidebar({
|
|
95
|
+
defaultExpanded: true,
|
|
96
|
+
navigationGroups: myGroups,
|
|
97
|
+
});
|
|
98
|
+
```
|
|
52
99
|
|
|
53
100
|
### RouteConfig
|
|
54
101
|
|
|
@@ -61,11 +108,21 @@ Designed for complex tools, agents, or multi-context navigation.
|
|
|
61
108
|
| `actions` | `ActionMenuItem[]` | Contextual action menu items (ellipsis button — assistant variant) |
|
|
62
109
|
| `description` | `ReactNode` | Auxiliary content shown when the route is active (assistant variant) |
|
|
63
110
|
|
|
111
|
+
### RouteGroup
|
|
112
|
+
|
|
113
|
+
| Field | Type | Description |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `id` | `string` | Unique identifier |
|
|
116
|
+
| `label` | `string` | Group title |
|
|
117
|
+
| `icon` | `ComponentType` | Group icon |
|
|
118
|
+
| `items` | `RouteConfig[]` | Navigation items in the group |
|
|
119
|
+
| `actions` | `ActionMenuItem[]` | Context menu for the entire group |
|
|
120
|
+
|
|
64
121
|
---
|
|
65
122
|
|
|
66
123
|
## Examples
|
|
67
124
|
|
|
68
|
-
###
|
|
125
|
+
### 1. Monolithic API — Flat Routes
|
|
69
126
|
|
|
70
127
|
```tsx
|
|
71
128
|
import { Sidebar } from 'xertica-ui/layout';
|
|
@@ -94,7 +151,7 @@ export function MySidebar() {
|
|
|
94
151
|
}
|
|
95
152
|
```
|
|
96
153
|
|
|
97
|
-
###
|
|
154
|
+
### 2. Monolithic API — Groups with Children
|
|
98
155
|
|
|
99
156
|
```tsx
|
|
100
157
|
import { BarChart, Users, Settings, Home } from 'lucide-react';
|
|
@@ -129,15 +186,107 @@ import { BarChart, Users, Settings, Home } from 'lucide-react';
|
|
|
129
186
|
/>
|
|
130
187
|
```
|
|
131
188
|
|
|
189
|
+
### 3. Compound Component API
|
|
190
|
+
|
|
191
|
+
Use this when you need to inject custom content between sections or reorder the layout:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { Sidebar } from 'xertica-ui/layout';
|
|
195
|
+
import { Home, BarChart } from 'lucide-react';
|
|
196
|
+
|
|
197
|
+
export function CustomSidebar({ expanded, onToggle }) {
|
|
198
|
+
return (
|
|
199
|
+
<Sidebar.Root
|
|
200
|
+
expanded={expanded}
|
|
201
|
+
onToggle={onToggle}
|
|
202
|
+
width={280}
|
|
203
|
+
location={{ pathname: window.location.pathname }}
|
|
204
|
+
navigate={(path) => window.location.href = path}
|
|
205
|
+
>
|
|
206
|
+
{/* Toggle button + logo */}
|
|
207
|
+
<Sidebar.Header logo={<MyLogo />} logoCollapsed={<MyIcon />} />
|
|
208
|
+
|
|
209
|
+
{/* Custom content injected between header and nav */}
|
|
210
|
+
<div className="px-4 py-2">
|
|
211
|
+
<span className="text-xs text-sidebar-foreground/60">v2.0.0</span>
|
|
212
|
+
</div>
|
|
213
|
+
|
|
214
|
+
{/* Navigation */}
|
|
215
|
+
<Sidebar.Nav
|
|
216
|
+
navigationGroups={[
|
|
217
|
+
{
|
|
218
|
+
id: 'main',
|
|
219
|
+
items: [
|
|
220
|
+
{ path: '/home', label: 'Home', icon: Home },
|
|
221
|
+
{ path: '/dashboard', label: 'Dashboard', icon: BarChart },
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
]}
|
|
225
|
+
/>
|
|
226
|
+
|
|
227
|
+
{/* Footer */}
|
|
228
|
+
<Sidebar.Footer
|
|
229
|
+
user={{ name: 'Admin', email: 'admin@example.com' }}
|
|
230
|
+
onLogout={() => signOut()}
|
|
231
|
+
showUser
|
|
232
|
+
showSettings
|
|
233
|
+
showLogout
|
|
234
|
+
/>
|
|
235
|
+
</Sidebar.Root>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 4. Headless Hook — Fully Custom UI
|
|
241
|
+
|
|
242
|
+
Use `useSidebar` when you need complete control over the rendered output:
|
|
243
|
+
|
|
244
|
+
```tsx
|
|
245
|
+
import { useSidebar } from 'xertica-ui/layout';
|
|
246
|
+
import { Home, BarChart } from 'lucide-react';
|
|
247
|
+
|
|
248
|
+
const groups = [
|
|
249
|
+
{
|
|
250
|
+
id: 'main',
|
|
251
|
+
items: [
|
|
252
|
+
{ path: '/home', label: 'Home', icon: Home },
|
|
253
|
+
{ path: '/dashboard', label: 'Dashboard', icon: BarChart },
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
export function MyCustomSidebar() {
|
|
259
|
+
const { expanded, toggleExpanded, navigationGroups } = useSidebar({
|
|
260
|
+
defaultExpanded: true,
|
|
261
|
+
navigationGroups: groups,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<aside style={{ width: expanded ? 280 : 80 }}>
|
|
266
|
+
<button onClick={toggleExpanded}>Toggle</button>
|
|
267
|
+
<nav>
|
|
268
|
+
{navigationGroups.flatMap(g => g.items).map(item => (
|
|
269
|
+
<a key={item.path} href={item.path}>
|
|
270
|
+
{expanded ? item.label : null}
|
|
271
|
+
</a>
|
|
272
|
+
))}
|
|
273
|
+
</nav>
|
|
274
|
+
</aside>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
132
279
|
---
|
|
133
280
|
|
|
134
281
|
## AI Rules
|
|
135
282
|
|
|
136
|
-
- **State Management** — Always use `useLayout()` to keep the Sidebar synchronized with the main content padding. Avoid managing `expanded` locally.
|
|
283
|
+
- **State Management** — Always use `useLayout()` to keep the Sidebar synchronized with the main content padding. Avoid managing `expanded` locally unless using the Headless Hook pattern.
|
|
137
284
|
- **Icons** — Pass the icon **component source** (e.g., `HomeIcon`), not a rendered element.
|
|
138
285
|
- **Groups** — Use `navigationGroups` in `default` variant for structured navigation with labels. Use `routes` for flat lists.
|
|
139
286
|
- **Children** — Add `children` to a `RouteConfig` to expose sub-routes via a ChevronRight button at the end of the item. Do not nest more than 2 levels.
|
|
140
287
|
- **Assistant Mode** — Use `fixedArea` to place high-priority "Create" buttons so they remain visible regardless of scrolling.
|
|
288
|
+
- **Compound Components** — Use `<Sidebar.Root>` + sub-components when you need to inject custom content between sections or reorder the layout.
|
|
289
|
+
- **Headless Hook** — Use `useSidebar()` only when you need a completely custom sidebar UI that shares none of the default rendering.
|
|
141
290
|
|
|
142
291
|
---
|
|
143
292
|
|
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
A visual multi-step progress indicator that shows the user's current position within a sequential process. Uses a composable primitive pattern: `<Stepper>` wraps one or more `<Step>` children, automatically inferring the total number of steps.
|
|
6
6
|
|
|
7
|
+
The package also exports a **headless `useStepper` hook** for building fully custom step-navigation UIs — including async validation guards before advancing — while reusing all the step-state logic.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
| Export | Description |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `Stepper` | Visual step indicator component |
|
|
16
|
+
| `Step` | Individual step item |
|
|
17
|
+
| `useStepper` | Headless hook — all step navigation logic, no UI |
|
|
18
|
+
| `UseStepperProps` | TypeScript props type for the hook |
|
|
19
|
+
| `UseStepperReturn` | TypeScript return type for the hook |
|
|
20
|
+
|
|
7
21
|
---
|
|
8
22
|
|
|
9
23
|
## When to Use
|
|
@@ -43,6 +57,7 @@ A visual multi-step progress indicator that shows the user's current position wi
|
|
|
43
57
|
| Prop | Type | Required | Description |
|
|
44
58
|
|---|---|---|---|
|
|
45
59
|
| `currentStep` | `number` | **Yes** | The currently active step (1-indexed) |
|
|
60
|
+
| `orientation` | `'horizontal' \| 'vertical'` | No | Layout direction (default: `'horizontal'`) |
|
|
46
61
|
| `className` | `string` | No | Additional CSS classes |
|
|
47
62
|
|
|
48
63
|
### `Step`
|
|
@@ -52,16 +67,9 @@ A visual multi-step progress indicator that shows the user's current position wi
|
|
|
52
67
|
| `step` | `number` | **Yes** | Position of this step (1-indexed, must match order) |
|
|
53
68
|
| `label` | `string` | **Yes** | Step label text |
|
|
54
69
|
| `description` | `string` | No | Optional supplementary text below the label |
|
|
70
|
+
| `error` | `boolean` | No | When `true`, renders the step in error state (red) |
|
|
55
71
|
| `className` | `string` | No | Additional CSS classes |
|
|
56
72
|
|
|
57
|
-
### `useStepper()` (hook)
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
const { currentStep, totalSteps } = useStepper();
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Access the stepper context from within a custom `Step` child component.
|
|
64
|
-
|
|
65
73
|
---
|
|
66
74
|
|
|
67
75
|
## Examples
|
|
@@ -97,7 +105,7 @@ const [currentStep, setCurrentStep] = useState(1);
|
|
|
97
105
|
onClick={() => setCurrentStep(s => Math.min(3, s + 1))}
|
|
98
106
|
disabled={currentStep === 3}
|
|
99
107
|
>
|
|
100
|
-
{currentStep ===
|
|
108
|
+
{currentStep === 3 ? 'Finish' : 'Next'}
|
|
101
109
|
</Button>
|
|
102
110
|
</div>
|
|
103
111
|
</div>
|
|
@@ -105,14 +113,151 @@ const [currentStep, setCurrentStep] = useState(1);
|
|
|
105
113
|
|
|
106
114
|
---
|
|
107
115
|
|
|
116
|
+
## `useStepper` Hook
|
|
117
|
+
|
|
118
|
+
A headless hook that manages step navigation state. Supports both **uncontrolled** (internal state) and **controlled** (external `step` prop) modes, plus an optional async `onBeforeNext` guard for validating the current step before advancing.
|
|
119
|
+
|
|
120
|
+
### Props
|
|
121
|
+
|
|
122
|
+
| Prop | Type | Default | Description |
|
|
123
|
+
|---|---|---|---|
|
|
124
|
+
| `totalSteps` | `number` | — | **Required.** Total number of steps in the flow |
|
|
125
|
+
| `initialStep` | `number` | `1` | Starting step (uncontrolled mode only) |
|
|
126
|
+
| `step` | `number` | — | Controlled current step — when provided, the hook uses this value instead of internal state |
|
|
127
|
+
| `onStepChange` | `(step: number) => void` | — | Called whenever the step changes |
|
|
128
|
+
| `onBeforeNext` | `(currentStep: number) => boolean \| Promise<boolean>` | — | Optional async guard — return `false` (or resolve to `false`) to block advancing to the next step |
|
|
129
|
+
|
|
130
|
+
### Return Value
|
|
131
|
+
|
|
132
|
+
| Property | Type | Description |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `currentStep` | `number` | The currently active step (1-indexed) |
|
|
135
|
+
| `totalSteps` | `number` | Total number of steps |
|
|
136
|
+
| `isFirstStep` | `boolean` | Whether the current step is the first step |
|
|
137
|
+
| `isLastStep` | `boolean` | Whether the current step is the last step |
|
|
138
|
+
| `canGoPrev` | `boolean` | Whether navigating to the previous step is possible |
|
|
139
|
+
| `canGoNext` | `boolean` | Whether navigating to the next step is possible |
|
|
140
|
+
| `next` | `() => Promise<void>` | Advance to the next step (runs `onBeforeNext` guard if provided) |
|
|
141
|
+
| `prev` | `() => void` | Go back to the previous step |
|
|
142
|
+
| `goTo` | `(step: number) => void` | Jump to a specific step number |
|
|
143
|
+
| `reset` | `() => void` | Reset to the initial step |
|
|
144
|
+
|
|
145
|
+
### Uncontrolled Example
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { useStepper, Stepper, Step, Button } from 'xertica-ui/ui';
|
|
149
|
+
|
|
150
|
+
function OnboardingWizard() {
|
|
151
|
+
const { currentStep, isFirstStep, isLastStep, next, prev } = useStepper({
|
|
152
|
+
totalSteps: 3,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className="space-y-8">
|
|
157
|
+
<Stepper currentStep={currentStep}>
|
|
158
|
+
<Step step={1} label="Account" />
|
|
159
|
+
<Step step={2} label="Plan" />
|
|
160
|
+
<Step step={3} label="Confirm" />
|
|
161
|
+
</Stepper>
|
|
162
|
+
|
|
163
|
+
<div className="min-h-[200px]">
|
|
164
|
+
{currentStep === 1 && <AccountForm />}
|
|
165
|
+
{currentStep === 2 && <PlanSelector />}
|
|
166
|
+
{currentStep === 3 && <ConfirmationSummary />}
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div className="flex justify-between">
|
|
170
|
+
<Button variant="outline" onClick={prev} disabled={isFirstStep}>
|
|
171
|
+
Previous
|
|
172
|
+
</Button>
|
|
173
|
+
<Button onClick={next} disabled={isLastStep}>
|
|
174
|
+
{isLastStep ? 'Finish' : 'Next'}
|
|
175
|
+
</Button>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### With Async Validation Guard
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { useStepper, Stepper, Step, Button } from 'xertica-ui/ui';
|
|
186
|
+
import { useForm } from 'react-hook-form';
|
|
187
|
+
|
|
188
|
+
function ValidatedWizard() {
|
|
189
|
+
const form = useForm();
|
|
190
|
+
|
|
191
|
+
const { currentStep, isFirstStep, isLastStep, next, prev } = useStepper({
|
|
192
|
+
totalSteps: 3,
|
|
193
|
+
onBeforeNext: async (step) => {
|
|
194
|
+
// Validate only the fields relevant to the current step
|
|
195
|
+
const fieldsPerStep: Record<number, string[]> = {
|
|
196
|
+
1: ['email', 'password'],
|
|
197
|
+
2: ['plan'],
|
|
198
|
+
};
|
|
199
|
+
const fields = fieldsPerStep[step];
|
|
200
|
+
if (!fields) return true;
|
|
201
|
+
return form.trigger(fields as never[]);
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<div className="space-y-8">
|
|
207
|
+
<Stepper currentStep={currentStep}>
|
|
208
|
+
<Step step={1} label="Account" />
|
|
209
|
+
<Step step={2} label="Plan" />
|
|
210
|
+
<Step step={3} label="Confirm" />
|
|
211
|
+
</Stepper>
|
|
212
|
+
|
|
213
|
+
<form>{/* step content */}</form>
|
|
214
|
+
|
|
215
|
+
<div className="flex justify-between">
|
|
216
|
+
<Button variant="outline" onClick={prev} disabled={isFirstStep}>
|
|
217
|
+
Previous
|
|
218
|
+
</Button>
|
|
219
|
+
<Button onClick={next}>
|
|
220
|
+
{isLastStep ? 'Submit' : 'Next'}
|
|
221
|
+
</Button>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Controlled Example
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
import { useStepper } from 'xertica-ui/ui';
|
|
232
|
+
import { useState } from 'react';
|
|
233
|
+
|
|
234
|
+
function ControlledWizard() {
|
|
235
|
+
const [step, setStep] = useState(1);
|
|
236
|
+
|
|
237
|
+
const { currentStep, next, prev, isFirstStep, isLastStep } = useStepper({
|
|
238
|
+
totalSteps: 4,
|
|
239
|
+
step, // controlled
|
|
240
|
+
onStepChange: setStep,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// currentStep === step at all times
|
|
244
|
+
return (/* ... */);
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
108
250
|
## AI Rules
|
|
109
251
|
|
|
110
|
-
- `step` props are **1-indexed** — the first step is `step={1}`, not `step={0}`.
|
|
252
|
+
- `step` props on `<Step>` are **1-indexed** — the first step is `step={1}`, not `step={0}`.
|
|
111
253
|
- Each `<Step>` `step` prop must match its position sequentially: `1, 2, 3, ...`.
|
|
112
254
|
- `currentStep` on `<Stepper>` must be a number from `1` to the total number of steps.
|
|
113
255
|
- Always render the navigation buttons (Previous/Next) below the Stepper.
|
|
114
|
-
- Disable "Previous" on step `1` and "Next" on the final step.
|
|
115
|
-
-
|
|
256
|
+
- Disable "Previous" on step `1` (`isFirstStep`) and "Next" on the final step (`isLastStep`).
|
|
257
|
+
- Use `onBeforeNext` for async form validation — return `false` to block advancing.
|
|
258
|
+
- `next()` is **async** — always `await` it or use it as an `onClick` handler directly (React handles the Promise).
|
|
259
|
+
- In controlled mode, pass both `step` and `onStepChange` — omitting `onStepChange` makes the hook read-only.
|
|
260
|
+
- Use `reset()` to return to step 1 after a successful submission.
|
|
116
261
|
|
|
117
262
|
---
|
|
118
263
|
|