@ticatec/uniface-element 0.3.18 → 0.3.19

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.
@@ -0,0 +1,377 @@
1
+ # Navigator
2
+
3
+ A step/wizard navigation component that guides users through a multi-step process. Visualizes progress and allows users to navigate between steps with clear status indicators.
4
+
5
+ ## Features
6
+
7
+ - **Step Visualization**: Visual representation of wizard steps
8
+ - **Status Indicators**: Completed, Warning, and Not Started states
9
+ - **Active Tracking**: Highlights the current active step
10
+ - **Item Highlighting**: Highlight specific items for attention
11
+ - **Click Navigation**: Click to navigate between steps
12
+ - **Custom Styling**: Flexible styling options
13
+ - **Dynamic Items**: Support for dynamic step lists
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @ticatec/uniface-element
19
+ ```
20
+
21
+ ```typescript
22
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
23
+ ```
24
+
25
+ ## Basic Usage
26
+
27
+ ```svelte
28
+ <script>
29
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
30
+
31
+ let activeItem = 0;
32
+ let items = [
33
+ { text: 'Step 1' },
34
+ { text: 'Step 2' },
35
+ { text: 'Step 3' },
36
+ { text: 'Step 4' }
37
+ ];
38
+
39
+ function getStatus(item) {
40
+ const index = items.indexOf(item);
41
+ if (index < activeItem) return NavItemStatus.Completed;
42
+ if (index === activeItem) return NavItemStatus.Completed;
43
+ return NavItemStatus.NotStart;
44
+ }
45
+
46
+ function handleClick(item) {
47
+ activeItem = items.indexOf(item);
48
+ console.log('Navigated to:', item.text);
49
+ }
50
+ </script>
51
+
52
+ <Navigator
53
+ {items}
54
+ activeItem={items[activeItem]}
55
+ retrieveStatus={getStatus}
56
+ itemClickHandler={handleClick}
57
+ />
58
+ ```
59
+
60
+ ## Props
61
+
62
+ | Prop | Type | Default | Description |
63
+ |------|------|---------|-------------|
64
+ | `items` | `Array<any>` | Required | Array of navigation items (must have `text` property) |
65
+ | `activeItem` | `any` | `null` | Currently active item |
66
+ | `highlights` | `Array<any>` | `[]` | Items to highlight for attention |
67
+ | `itemClickHandler` | `(item: any) => void` | Required | Callback when item is clicked |
68
+ | `retrieveStatus` | `(item: any) => NavItemStatus` | Required | Function to get item status |
69
+ | `style` | `string` | `''` | Custom CSS styles |
70
+
71
+ ## NavItemStatus Enum
72
+
73
+ | Status | Value | Description |
74
+ |--------|-------|-------------|
75
+ | `NavItemStatus.Completed` | `'nav-completed'` | Step is completed |
76
+ | `NavItemStatus.Warning` | `'nav-warning'` | Step has warnings |
77
+ | `NavItemStatus.NotStart` | `'nav-not-start'` | Step not started |
78
+
79
+ ## Examples
80
+
81
+ ### Basic Wizard Navigation
82
+
83
+ ```svelte
84
+ <script>
85
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
86
+
87
+ let currentStep = 0;
88
+
89
+ const steps = [
90
+ { text: 'Personal Info' },
91
+ { text: 'Contact Details' },
92
+ { text: 'Preferences' },
93
+ { text: 'Review' }
94
+ ];
95
+
96
+ function getStepStatus(step) {
97
+ const index = steps.indexOf(step);
98
+ if (index < currentStep) return NavItemStatus.Completed;
99
+ if (index === currentStep) return NavItemStatus.Completed;
100
+ return NavItemStatus.NotStart;
101
+ }
102
+
103
+ function handleStepClick(step) {
104
+ const index = steps.indexOf(step);
105
+ if (index <= currentStep) {
106
+ currentStep = index;
107
+ }
108
+ }
109
+
110
+ function nextStep() {
111
+ if (currentStep < steps.length - 1) {
112
+ currentStep++;
113
+ }
114
+ }
115
+
116
+ function prevStep() {
117
+ if (currentStep > 0) {
118
+ currentStep--;
119
+ }
120
+ }
121
+ </script>
122
+
123
+ <Navigator
124
+ items={steps}
125
+ activeItem={steps[currentStep]}
126
+ retrieveStatus={getStepStatus}
127
+ itemClickHandler={handleStepClick}
128
+ />
129
+
130
+ <div style="margin-top: 32px; padding: 24px; border: 1px solid #ddd;">
131
+ <h2>{steps[currentStep].text}</h2>
132
+ <p>Content for step {currentStep + 1}</p>
133
+
134
+ <div style="margin-top: 16px; display: flex; gap: 8px;">
135
+ <button disabled={currentStep === 0} on:click={prevStep}>Previous</button>
136
+ <button disabled={currentStep === steps.length - 1} on:click={nextStep}>Next</button>
137
+ </div>
138
+ </div>
139
+ ```
140
+
141
+ ### With Warning Status
142
+
143
+ ```svelte
144
+ <script>
145
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
146
+
147
+ let currentStep = 2;
148
+ const warningSteps = [1];
149
+
150
+ const steps = [
151
+ { text: 'Account' },
152
+ { text: 'Profile' },
153
+ { text: 'Settings' },
154
+ { text: 'Confirm' }
155
+ ];
156
+
157
+ function getStepStatus(step) {
158
+ const index = steps.indexOf(step);
159
+ if (warningSteps.includes(index)) return NavItemStatus.Warning;
160
+ if (index <= currentStep) return NavItemStatus.Completed;
161
+ return NavItemStatus.NotStart;
162
+ }
163
+
164
+ function handleStepClick(step) {
165
+ const index = steps.indexOf(step);
166
+ if (index <= currentStep) {
167
+ currentStep = index;
168
+ }
169
+ }
170
+ </script>
171
+
172
+ <Navigator
173
+ items={steps}
174
+ activeItem={steps[currentStep]}
175
+ retrieveStatus={getStepStatus}
176
+ itemClickHandler={handleStepClick}
177
+ />
178
+ ```
179
+
180
+ ### With Highlights
181
+
182
+ ```svelte
183
+ <script>
184
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
185
+
186
+ let currentStep = 1;
187
+ let highlightedSteps = [2, 3];
188
+
189
+ const steps = [
190
+ { text: 'Upload' },
191
+ { text: 'Process' },
192
+ { text: 'Verify' },
193
+ { text: 'Complete' }
194
+ ];
195
+
196
+ function getStepStatus(step) {
197
+ const index = steps.indexOf(step);
198
+ if (index < currentStep) return NavItemStatus.Completed;
199
+ if (index === currentStep) return NavItemStatus.Completed;
200
+ return NavItemStatus.NotStart;
201
+ }
202
+
203
+ function handleStepClick(step) {
204
+ const index = steps.indexOf(step);
205
+ if (index <= currentStep) {
206
+ currentStep = index;
207
+ }
208
+ }
209
+ </script>
210
+
211
+ <Navigator
212
+ items={steps}
213
+ activeItem={steps[currentStep]}
214
+ highlights={highlightedSteps.map(i => steps[i])}
215
+ retrieveStatus={getStepStatus}
216
+ itemClickHandler={handleStepClick}
217
+ />
218
+ ```
219
+
220
+ ### Custom Styling
221
+
222
+ ```svelte
223
+ <script>
224
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
225
+
226
+ const steps = [
227
+ { text: '①' },
228
+ { text: '②' },
229
+ { text: '③' },
230
+ { text: '④' }
231
+ ];
232
+
233
+ function getStepStatus(step) {
234
+ return NavItemStatus.NotStart;
235
+ }
236
+
237
+ function handleStepClick(step) {
238
+ console.log('Clicked:', step.text);
239
+ }
240
+ </script>
241
+
242
+ <Navigator
243
+ items={steps}
244
+ activeItem={steps[0]}
245
+ retrieveStatus={getStepStatus}
246
+ itemClickHandler={handleStepClick}
247
+ style="background: #f5f5f5; padding: 16px; border-radius: 8px;"
248
+ />
249
+ ```
250
+
251
+ ### Complete Form Wizard
252
+
253
+ ```svelte
254
+ <script>
255
+ import Navigator, { NavItemStatus } from '@ticatec/uniface-element/Navigator';
256
+ import Button from '@ticatec/uniface-element/Button';
257
+
258
+ let currentStep = 0;
259
+ let formData = {
260
+ name: '',
261
+ email: '',
262
+ phone: '',
263
+ address: ''
264
+ };
265
+
266
+ const wizardSteps = [
267
+ { text: 'Personal' },
268
+ { text: 'Contact' },
269
+ { text: 'Location' },
270
+ { text: 'Review' }
271
+ ];
272
+
273
+ function getStepStatus(step) {
274
+ const index = wizardSteps.indexOf(step);
275
+ if (index < currentStep) return NavItemStatus.Completed;
276
+ if (index === currentStep) return NavItemStatus.Completed;
277
+ return NavItemStatus.NotStart;
278
+ }
279
+
280
+ function handleStepClick(step) {
281
+ const index = wizardSteps.indexOf(step);
282
+ if (index <= currentStep) {
283
+ currentStep = index;
284
+ }
285
+ }
286
+
287
+ function canProceed() {
288
+ switch(currentStep) {
289
+ case 0: return formData.name.length > 0;
290
+ case 1: return formData.email.length > 0;
291
+ case 2: return formData.address.length > 0;
292
+ default: return true;
293
+ }
294
+ }
295
+ </script>
296
+
297
+ <div style="max-width: 800px; margin: 0 auto; padding: 24px;">
298
+ <Navigator
299
+ items={wizardSteps}
300
+ activeItem={wizardSteps[currentStep]}
301
+ retrieveStatus={getStepStatus}
302
+ itemClickHandler={handleStepClick}
303
+ />
304
+
305
+ <div style="margin-top: 32px; padding: 24px; border: 1px solid #ddd; border-radius: 8px;">
306
+ {#if currentStep === 0}
307
+ <h2>Personal Information</h2>
308
+ <label>
309
+ Full Name:
310
+ <input type="text" bind:value={formData.name} placeholder="Enter your name" />
311
+ </label>
312
+ {:else if currentStep === 1}
313
+ <h2>Contact Information</h2>
314
+ <label>
315
+ Email:
316
+ <input type="email" bind:value={formData.email} placeholder="your@email.com" />
317
+ </label>
318
+ {:else if currentStep === 2}
319
+ <h2>Location</h2>
320
+ <label>
321
+ Address:
322
+ <input type="text" bind:value={formData.address} placeholder="Your address" />
323
+ </label>
324
+ {:else}
325
+ <h2>Review Your Information</h2>
326
+ <pre>{JSON.stringify(formData, null, 2)}</pre>
327
+ {/if}
328
+
329
+ <div style="margin-top: 24px; display: flex; justify-content: space-between;">
330
+ <Button
331
+ disabled={currentStep === 0}
332
+ onclick={() => currentStep--}
333
+ >
334
+ Previous
335
+ </Button>
336
+
337
+ {#if currentStep < wizardSteps.length - 1}
338
+ <Button
339
+ type="primary"
340
+ disabled={!canProceed()}
341
+ onclick={() => currentStep++}
342
+ >
343
+ Next
344
+ </Button>
345
+ {:else}
346
+ <Button type="primary" onclick={() => console.log('Submit:', formData)}>
347
+ Submit
348
+ </Button>
349
+ {/if}
350
+ </div>
351
+ </div>
352
+ </div>
353
+ ```
354
+
355
+ ## Best Practices
356
+
357
+ 1. **Clear Steps**: Use concise, descriptive text for each step
358
+ 2. **Status Logic**: Implement clear status logic based on your workflow
359
+ 3. **Navigation Control**: Control which steps are clickable based on progress
360
+ 4. **Visual Feedback**: Use warnings to indicate issues or attention needed
361
+ 5. **Validation**: Prevent proceeding if current step is incomplete
362
+ 6. **Progress Indication**: Make it clear which step is active
363
+
364
+ ## Use Cases
365
+
366
+ - **Multi-step Forms**: Break complex forms into manageable steps
367
+ - **Wizards**: Guide users through complex processes
368
+ - **Onboarding**: Step-by-step user onboarding flows
369
+ - **Checkouts**: E-commerce checkout processes
370
+ - **Configuration**: Multi-stage configuration workflows
371
+
372
+ ## Accessibility
373
+
374
+ - Keyboard navigation support
375
+ - Clear visual indicators for current step
376
+ - Semantic HTML structure
377
+ - ARIA attributes for screen readers