@app-studio/web 0.9.35 → 0.9.37
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/dist/components/Calendar/Calendar/Calendar.props.d.ts +8 -0
- package/dist/components/KanbanBoard/KanbanBoard/KanbanBoard.props.d.ts +5 -0
- package/dist/components/KanbanBoard/KanbanBoard/KanbanBoard.state.d.ts +7 -3
- package/dist/components/OKR/OKR/OKR.props.d.ts +72 -0
- package/dist/components/OKR/OKR/OKR.style.d.ts +19 -0
- package/dist/components/OKR/OKR/OKR.view.d.ts +4 -0
- package/dist/components/OKR/OKR.d.ts +4 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/pages/okr.page.d.ts +3 -0
- package/dist/web.cjs.development.js +774 -199
- package/dist/web.cjs.development.js.map +1 -1
- package/dist/web.cjs.production.min.js +1 -1
- package/dist/web.cjs.production.min.js.map +1 -1
- package/dist/web.esm.js +774 -200
- package/dist/web.esm.js.map +1 -1
- package/dist/web.umd.development.js +774 -199
- package/dist/web.umd.development.js.map +1 -1
- package/dist/web.umd.production.min.js +1 -1
- package/dist/web.umd.production.min.js.map +1 -1
- package/docs/README.md +2 -1
- package/docs/components/Calendar.mdx +3 -0
- package/docs/components/Flow.mdx +1 -0
- package/docs/components/KanbanBoard.mdx +4 -0
- package/docs/components/OKR.mdx +475 -0
- package/docs/components/Title.mdx +1 -0
- package/docs/components/Tree.mdx +1 -0
- package/docs/components.md +178 -0
- package/package.json +1 -1
- package/docs/api-reference/README.md +0 -103
- package/docs/api-reference/data-display/flow.md +0 -220
- package/docs/api-reference/data-display/tree.md +0 -210
- package/docs/api-reference/form/chat-input.md +0 -206
- package/docs/api-reference/utility/button.md +0 -145
- package/docs/api-reference/utility/title.md +0 -301
package/docs/components.md
CHANGED
|
@@ -129,6 +129,30 @@ const TextExamples = () => (
|
|
|
129
129
|
);
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
### Title
|
|
133
|
+
|
|
134
|
+
A component for rendering animated and highlighted titles in hero sections and other prominent areas of the UI.
|
|
135
|
+
|
|
136
|
+
**Example:**
|
|
137
|
+
```tsx
|
|
138
|
+
import { Title } from '@app-studio/web';
|
|
139
|
+
|
|
140
|
+
const HeroTitle = () => (
|
|
141
|
+
<Title
|
|
142
|
+
size="xl"
|
|
143
|
+
highlightText="Platform"
|
|
144
|
+
highlightStyle="gradient"
|
|
145
|
+
highlightColor="theme.primary"
|
|
146
|
+
highlightSecondaryColor="theme.secondary"
|
|
147
|
+
centered
|
|
148
|
+
>
|
|
149
|
+
Welcome to Our Platform
|
|
150
|
+
</Title>
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
For detailed documentation, see [Title Component](./components/Title.mdx).
|
|
155
|
+
|
|
132
156
|
## III. Form Components
|
|
133
157
|
|
|
134
158
|
### TextField
|
|
@@ -172,6 +196,37 @@ const MyForm = () => (
|
|
|
172
196
|
);
|
|
173
197
|
```
|
|
174
198
|
|
|
199
|
+
### ChatInput
|
|
200
|
+
|
|
201
|
+
A customizable chat input field with support for file uploads, prompt examples, and agent controls.
|
|
202
|
+
|
|
203
|
+
**Example:**
|
|
204
|
+
```tsx
|
|
205
|
+
import { ChatInput } from '@app-studio/web';
|
|
206
|
+
import { useState } from 'react';
|
|
207
|
+
|
|
208
|
+
const ChatExample = () => {
|
|
209
|
+
const [inputValue, setInputValue] = useState('');
|
|
210
|
+
|
|
211
|
+
const handleSubmit = (message) => {
|
|
212
|
+
console.log('Message submitted:', message);
|
|
213
|
+
setInputValue('');
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<ChatInput
|
|
218
|
+
onSubmit={handleSubmit}
|
|
219
|
+
value={inputValue}
|
|
220
|
+
onChange={setInputValue}
|
|
221
|
+
placeholder="Type your message here..."
|
|
222
|
+
hideAttachments={false}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
For detailed documentation, see [ChatInput Component](./components/ChatInput.mdx).
|
|
229
|
+
|
|
175
230
|
## IV. Feedback Components
|
|
176
231
|
|
|
177
232
|
### Alert
|
|
@@ -283,3 +338,126 @@ const KanbanCardExample = () => (
|
|
|
283
338
|
/>
|
|
284
339
|
);
|
|
285
340
|
```
|
|
341
|
+
|
|
342
|
+
### Tree
|
|
343
|
+
|
|
344
|
+
A component for displaying hierarchical data with expandable/collapsible nodes. Supports both a compound component pattern and a data-driven approach.
|
|
345
|
+
|
|
346
|
+
**Example:**
|
|
347
|
+
```tsx
|
|
348
|
+
import { Tree } from '@app-studio/web';
|
|
349
|
+
import { FolderIcon, FileIcon } from '@app-studio/web';
|
|
350
|
+
|
|
351
|
+
const FileTreeExample = () => {
|
|
352
|
+
const treeData = [
|
|
353
|
+
{
|
|
354
|
+
id: 'root',
|
|
355
|
+
label: 'Project',
|
|
356
|
+
icon: <FolderIcon size={16} />,
|
|
357
|
+
children: [
|
|
358
|
+
{
|
|
359
|
+
id: 'src',
|
|
360
|
+
label: 'src',
|
|
361
|
+
icon: <FolderIcon size={16} />,
|
|
362
|
+
children: [
|
|
363
|
+
{ id: 'components', label: 'components', icon: <FileIcon size={16} /> },
|
|
364
|
+
{ id: 'utils', label: 'utils', icon: <FileIcon size={16} /> },
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
];
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
<Tree
|
|
373
|
+
items={treeData}
|
|
374
|
+
defaultExpandedItems={['root', 'src']}
|
|
375
|
+
onItemSelect={(itemId) => console.log(`Selected: ${itemId}`)}
|
|
376
|
+
/>
|
|
377
|
+
);
|
|
378
|
+
};
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
For detailed documentation, see [Tree Component](./components/Tree.mdx).
|
|
382
|
+
|
|
383
|
+
### Flow
|
|
384
|
+
|
|
385
|
+
A component for creating interactive workflow diagrams and flowcharts with support for node connections, drag-and-drop functionality, and viewport controls.
|
|
386
|
+
|
|
387
|
+
**Example:**
|
|
388
|
+
```tsx
|
|
389
|
+
import { Flow } from '@app-studio/web';
|
|
390
|
+
import { useState } from 'react';
|
|
391
|
+
|
|
392
|
+
const FlowExample = () => {
|
|
393
|
+
const [nodes, setNodes] = useState([
|
|
394
|
+
{
|
|
395
|
+
id: 'node-1',
|
|
396
|
+
position: { x: 50, y: 50 },
|
|
397
|
+
data: { label: 'Start Node', subtitle: 'Begin here' },
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
id: 'node-2',
|
|
401
|
+
position: { x: 50, y: 200 },
|
|
402
|
+
data: { label: 'Process Node', subtitle: 'Do something' },
|
|
403
|
+
},
|
|
404
|
+
]);
|
|
405
|
+
|
|
406
|
+
const [edges, setEdges] = useState([
|
|
407
|
+
{ id: 'edge-1-2', source: 'node-1', target: 'node-2' },
|
|
408
|
+
]);
|
|
409
|
+
|
|
410
|
+
return (
|
|
411
|
+
<Flow
|
|
412
|
+
nodes={nodes}
|
|
413
|
+
edges={edges}
|
|
414
|
+
onNodesChange={setNodes}
|
|
415
|
+
onEdgesChange={setEdges}
|
|
416
|
+
/>
|
|
417
|
+
);
|
|
418
|
+
};
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
For detailed documentation, see [Flow Component](./components/Flow.mdx).
|
|
422
|
+
|
|
423
|
+
### OKR
|
|
424
|
+
|
|
425
|
+
A component for displaying and tracking Objectives and Key Results (OKRs). Provides a comprehensive view of progress, status, and ownership for strategic goals.
|
|
426
|
+
|
|
427
|
+
**Example:**
|
|
428
|
+
```tsx
|
|
429
|
+
import { OKR } from '@app-studio/web';
|
|
430
|
+
|
|
431
|
+
const OKRExample = () => {
|
|
432
|
+
const objectives = [
|
|
433
|
+
{
|
|
434
|
+
id: '1',
|
|
435
|
+
title: 'Launch New Feature',
|
|
436
|
+
description: 'Successfully launch the new feature to all users.',
|
|
437
|
+
owner: 'John Doe',
|
|
438
|
+
timeframe: 'Q4 2025',
|
|
439
|
+
tags: ['new-feature', 'launch'],
|
|
440
|
+
progress: 50,
|
|
441
|
+
status: 'onTrack',
|
|
442
|
+
keyResults: [
|
|
443
|
+
{
|
|
444
|
+
id: '1.1',
|
|
445
|
+
title: 'Complete development',
|
|
446
|
+
progress: 80,
|
|
447
|
+
status: 'onTrack',
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
id: '1.2',
|
|
451
|
+
title: 'Complete QA testing',
|
|
452
|
+
progress: 40,
|
|
453
|
+
status: 'atRisk',
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
},
|
|
457
|
+
];
|
|
458
|
+
|
|
459
|
+
return <OKR objectives={objectives} />;
|
|
460
|
+
};
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
For detailed documentation, see [OKR Component](./components/OKR.mdx).
|
package/package.json
CHANGED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# API Reference
|
|
2
|
-
|
|
3
|
-
This section provides detailed API documentation for all components in the App Studio Web Component Library.
|
|
4
|
-
|
|
5
|
-
## Component Categories
|
|
6
|
-
|
|
7
|
-
- [Layout Components](#layout-components)
|
|
8
|
-
- [Form Components](#form-components)
|
|
9
|
-
- [Navigation Components](#navigation-components)
|
|
10
|
-
- [Feedback Components](#feedback-components)
|
|
11
|
-
- [Data Display Components](#data-display-components)
|
|
12
|
-
- [Utility Components](#utility-components)
|
|
13
|
-
- [Interactive Components](#interactive-components)
|
|
14
|
-
|
|
15
|
-
## Layout Components
|
|
16
|
-
|
|
17
|
-
- [View](./layout/view.md) - Base container component
|
|
18
|
-
- [Horizontal](./layout/horizontal.md) - Horizontal flex container
|
|
19
|
-
- [Vertical](./layout/vertical.md) - Vertical flex container
|
|
20
|
-
- [Center](./layout/center.md) - Centered flex container
|
|
21
|
-
- [AspectRatio](./layout/aspect-ratio.md) - Container with fixed aspect ratio
|
|
22
|
-
- [Separator](./layout/separator.md) - Visual or semantic separator
|
|
23
|
-
- [Resizable](./layout/resizable.md) - Resizable container
|
|
24
|
-
|
|
25
|
-
## Form Components
|
|
26
|
-
|
|
27
|
-
- [Checkbox](./form/checkbox.md) - Checkbox input
|
|
28
|
-
- [ChatInput](./form/chat-input.md) - Chat input with file uploads and prompt examples
|
|
29
|
-
- [Radio](./form/radio.md) - Radio input
|
|
30
|
-
- [Select](./form/select.md) - Select dropdown
|
|
31
|
-
- [Switch](./form/switch.md) - Toggle switch
|
|
32
|
-
- [TextArea](./form/text-area.md) - Multi-line text input
|
|
33
|
-
- [TextField](./form/text-field.md) - Single-line text input
|
|
34
|
-
- [OTPInput](./form/otp-input.md) - One-time password input
|
|
35
|
-
|
|
36
|
-
## Navigation Components
|
|
37
|
-
|
|
38
|
-
- [Accordion](./navigation/accordion.md) - Expandable content sections
|
|
39
|
-
- [Menubar](./navigation/menubar.md) - Horizontal menu
|
|
40
|
-
- [NavigationMenu](./navigation/navigation-menu.md) - Navigation menu
|
|
41
|
-
- [Pagination](./navigation/pagination.md) - Page navigation
|
|
42
|
-
- [Sidebar](./navigation/sidebar.md) - Side navigation
|
|
43
|
-
- [Tabs](./navigation/tabs.md) - Tabbed interface
|
|
44
|
-
|
|
45
|
-
## Feedback Components
|
|
46
|
-
|
|
47
|
-
- [Alert](./feedback/alert.md) - Informational message
|
|
48
|
-
- [Modal](./feedback/modal.md) - Dialog box
|
|
49
|
-
- [Toast](./feedback/toast.md) - Temporary notification
|
|
50
|
-
- [Tooltip](./feedback/tooltip.md) - Contextual information
|
|
51
|
-
|
|
52
|
-
## Data Display Components
|
|
53
|
-
|
|
54
|
-
- [Avatar](./data-display/avatar.md) - User or entity representation
|
|
55
|
-
- [Badge](./data-display/badge.md) - Small count or status indicator
|
|
56
|
-
- [Card](./data-display/card.md) - Content container
|
|
57
|
-
- [Table](./data-display/table.md) - Tabular data
|
|
58
|
-
- [Chart](./data-display/chart.md) - Data visualization
|
|
59
|
-
- [Flow](./data-display/flow.md) - Interactive workflow diagrams and flowcharts
|
|
60
|
-
- [Tree](./data-display/tree.md) - Hierarchical tree structure
|
|
61
|
-
|
|
62
|
-
## Utility Components
|
|
63
|
-
|
|
64
|
-
- [Button](./utility/button.md) - Interactive button
|
|
65
|
-
- [Gradient](./utility/gradient.md) - Gradient background
|
|
66
|
-
- [Loader](./utility/loader.md) - Loading indicator
|
|
67
|
-
- [Text](./utility/text.md) - Text display
|
|
68
|
-
|
|
69
|
-
## Interactive Components
|
|
70
|
-
|
|
71
|
-
- [Carousel](./interactive/carousel.md) - Slideshow
|
|
72
|
-
- [ContextMenu](./interactive/context-menu.md) - Right-click menu
|
|
73
|
-
- [DropdownMenu](./interactive/dropdown-menu.md) - Dropdown menu
|
|
74
|
-
- [HoverCard](./interactive/hover-card.md) - Card that appears on hover
|
|
75
|
-
- [Slider](./interactive/slider.md) - Range input
|
|
76
|
-
- [Toggle](./interactive/toggle.md) - Toggle button
|
|
77
|
-
- [ToggleGroup](./interactive/toggle-group.md) - Group of toggle buttons
|
|
78
|
-
|
|
79
|
-
## Component API Structure
|
|
80
|
-
|
|
81
|
-
Each component's API documentation follows a consistent structure:
|
|
82
|
-
|
|
83
|
-
1. **Import** - How to import the component
|
|
84
|
-
2. **Props** - Detailed list of props with types and descriptions
|
|
85
|
-
3. **Examples** - Basic usage examples
|
|
86
|
-
4. **Variants** - Available variants and their usage
|
|
87
|
-
5. **Compound Components** - Sub-components (if applicable)
|
|
88
|
-
6. **Accessibility** - Accessibility features and considerations
|
|
89
|
-
7. **Best Practices** - Recommended usage patterns
|
|
90
|
-
|
|
91
|
-
## Generating API Documentation
|
|
92
|
-
|
|
93
|
-
Component API documentation is automatically generated using the `bot-doc` tool. To regenerate documentation for a component:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
npm run bot-doc -- ComponentName src/components/ComponentName
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
To regenerate documentation for all components:
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
npm run create-docs
|
|
103
|
-
```
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# Flow
|
|
2
|
-
|
|
3
|
-
The Flow component is used to create interactive workflow diagrams and flowcharts with support for node connections, drag-and-drop functionality, and viewport controls.
|
|
4
|
-
|
|
5
|
-
## Import
|
|
6
|
-
|
|
7
|
-
```jsx
|
|
8
|
-
import { Flow } from '@app-studio/web';
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Props
|
|
12
|
-
|
|
13
|
-
| Prop | Type | Default | Description |
|
|
14
|
-
| ---- | ---- | ------- | ----------- |
|
|
15
|
-
| nodes | FlowNode[] | [] | Array of nodes in the flow |
|
|
16
|
-
| edges | NodeConnection[] | [] | Array of edges/connections between nodes |
|
|
17
|
-
| size | 'sm' \| 'md' \| 'lg' | 'md' | Size of the flow nodes |
|
|
18
|
-
| variant | 'default' \| 'outline' \| 'filled' | 'default' | Visual variant of the flow nodes |
|
|
19
|
-
| direction | 'horizontal' \| 'vertical' | 'vertical' | Direction of the flow layout |
|
|
20
|
-
| showControls | boolean | true | Whether to show viewport controls (zoom in/out, reset) |
|
|
21
|
-
| allowAddingNodes | boolean | true | Whether to allow adding new nodes |
|
|
22
|
-
| allowDraggingNodes | boolean | true | Whether to allow dragging nodes |
|
|
23
|
-
| selectedNodeId | string | undefined | ID of the currently selected node |
|
|
24
|
-
| onNodeSelect | (nodeId: string \| null) => void | undefined | Callback when a node is selected |
|
|
25
|
-
| onNodesChange | (nodes: FlowNode[]) => void | undefined | Callback when nodes change |
|
|
26
|
-
| onEdgesChange | (edges: NodeConnection[]) => void | undefined | Callback when edges change |
|
|
27
|
-
| onNodeAdd | (node: FlowNode) => void | undefined | Callback when a node is added |
|
|
28
|
-
| onNodeDragStart | (nodeId: string) => void | undefined | Callback when node dragging starts |
|
|
29
|
-
| onNodeDrag | (nodeId: string, position: NodePosition) => void | undefined | Callback during node dragging |
|
|
30
|
-
| onNodeDragEnd | (nodeId: string, position: NodePosition) => void | undefined | Callback when node dragging ends |
|
|
31
|
-
| viewport | FlowViewport | { zoom: 1, x: 0, y: 0 } | Current viewport state (zoom level and position) |
|
|
32
|
-
| onViewportChange | (viewport: FlowViewport) => void | undefined | Callback when viewport changes |
|
|
33
|
-
| views | object | {} | Custom styling for different parts of the component |
|
|
34
|
-
|
|
35
|
-
## Node Structure
|
|
36
|
-
|
|
37
|
-
The `FlowNode` interface defines the structure of nodes in the Flow component:
|
|
38
|
-
|
|
39
|
-
```tsx
|
|
40
|
-
interface FlowNode {
|
|
41
|
-
id: string;
|
|
42
|
-
type?: 'default' | 'start' | 'end' | 'decision' | 'process' | string;
|
|
43
|
-
position: { x: number; y: number };
|
|
44
|
-
data?: {
|
|
45
|
-
label?: string;
|
|
46
|
-
subtitle?: string;
|
|
47
|
-
icon?: React.ReactNode;
|
|
48
|
-
number?: number;
|
|
49
|
-
[key: string]: any;
|
|
50
|
-
};
|
|
51
|
-
selected?: boolean;
|
|
52
|
-
isDragging?: boolean;
|
|
53
|
-
draggable?: boolean;
|
|
54
|
-
style?: ViewProps;
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Edge Structure
|
|
59
|
-
|
|
60
|
-
The `NodeConnection` interface defines the structure of edges in the Flow component:
|
|
61
|
-
|
|
62
|
-
```tsx
|
|
63
|
-
interface NodeConnection {
|
|
64
|
-
id: string;
|
|
65
|
-
source: string;
|
|
66
|
-
target: string;
|
|
67
|
-
label?: string;
|
|
68
|
-
style?: ViewProps;
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Examples
|
|
73
|
-
|
|
74
|
-
### Basic Usage
|
|
75
|
-
|
|
76
|
-
```jsx
|
|
77
|
-
import React, { useState } from 'react';
|
|
78
|
-
import { Flow } from '@app-studio/web';
|
|
79
|
-
import { View } from 'app-studio';
|
|
80
|
-
|
|
81
|
-
export const BasicFlow = () => {
|
|
82
|
-
// Initial nodes and edges
|
|
83
|
-
const [nodes, setNodes] = useState([
|
|
84
|
-
{
|
|
85
|
-
id: 'node-1',
|
|
86
|
-
position: { x: 50, y: 50 },
|
|
87
|
-
data: {
|
|
88
|
-
label: 'Start Node',
|
|
89
|
-
subtitle: 'Begin here'
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
id: 'node-2',
|
|
94
|
-
position: { x: 50, y: 200 },
|
|
95
|
-
data: {
|
|
96
|
-
label: 'Process Node',
|
|
97
|
-
subtitle: 'Do something'
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
]);
|
|
101
|
-
|
|
102
|
-
const [edges, setEdges] = useState([
|
|
103
|
-
{ id: 'edge-1-2', source: 'node-1', target: 'node-2' },
|
|
104
|
-
]);
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<View height="400px" border="1px solid" borderColor="color.gray.200" borderRadius={8}>
|
|
108
|
-
<Flow
|
|
109
|
-
nodes={nodes}
|
|
110
|
-
edges={edges}
|
|
111
|
-
onNodesChange={setNodes}
|
|
112
|
-
onEdgesChange={setEdges}
|
|
113
|
-
/>
|
|
114
|
-
</View>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### With Node Addition
|
|
120
|
-
|
|
121
|
-
```jsx
|
|
122
|
-
import React, { useState } from 'react';
|
|
123
|
-
import { Flow } from '@app-studio/web';
|
|
124
|
-
import { View } from 'app-studio';
|
|
125
|
-
|
|
126
|
-
export const FlowWithNodeAddition = () => {
|
|
127
|
-
const [nodes, setNodes] = useState([
|
|
128
|
-
{
|
|
129
|
-
id: 'node-1',
|
|
130
|
-
position: { x: 50, y: 50 },
|
|
131
|
-
data: { label: 'Start', subtitle: 'Begin workflow' },
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
id: 'node-2',
|
|
135
|
-
position: { x: 50, y: 200 },
|
|
136
|
-
data: { label: 'Process', subtitle: 'Do something' },
|
|
137
|
-
},
|
|
138
|
-
]);
|
|
139
|
-
|
|
140
|
-
const [edges, setEdges] = useState([
|
|
141
|
-
{ id: 'edge-1-2', source: 'node-1', target: 'node-2' },
|
|
142
|
-
]);
|
|
143
|
-
|
|
144
|
-
const [selectedNodeId, setSelectedNodeId] = useState(null);
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<View height="400px" border="1px solid" borderColor="color.gray.200" borderRadius={8}>
|
|
148
|
-
<Flow
|
|
149
|
-
nodes={nodes}
|
|
150
|
-
edges={edges}
|
|
151
|
-
onNodesChange={setNodes}
|
|
152
|
-
onEdgesChange={setEdges}
|
|
153
|
-
selectedNodeId={selectedNodeId}
|
|
154
|
-
onNodeSelect={setSelectedNodeId}
|
|
155
|
-
allowAddingNodes={true}
|
|
156
|
-
onNodeAdd={(newNode) => {
|
|
157
|
-
setNodes((prevNodes) => [...prevNodes, newNode]);
|
|
158
|
-
}}
|
|
159
|
-
/>
|
|
160
|
-
</View>
|
|
161
|
-
);
|
|
162
|
-
};
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Compound Components
|
|
166
|
-
|
|
167
|
-
The Flow component uses a compound component pattern with the following sub-components:
|
|
168
|
-
|
|
169
|
-
```jsx
|
|
170
|
-
// These are primarily for potential direct use or a more componentized future version
|
|
171
|
-
Flow.Node // Renders a single node
|
|
172
|
-
Flow.Edge // Renders a connection between nodes
|
|
173
|
-
Flow.Controls // Renders viewport controls
|
|
174
|
-
Flow.AddNodeButton // Renders a button to add a new node
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
## Customization
|
|
178
|
-
|
|
179
|
-
The Flow component can be customized using the `views` prop:
|
|
180
|
-
|
|
181
|
-
```jsx
|
|
182
|
-
<Flow
|
|
183
|
-
// ...other props
|
|
184
|
-
views={{
|
|
185
|
-
container: { /* styles for the main flow container */ },
|
|
186
|
-
node: {
|
|
187
|
-
container: { /* styles for the node's root View */ },
|
|
188
|
-
content: { /* styles for the content wrapper inside the node */ },
|
|
189
|
-
icon: { /* styles for the node's icon View */ },
|
|
190
|
-
},
|
|
191
|
-
edge: {
|
|
192
|
-
path: { /* styles for the SVG path */ },
|
|
193
|
-
label: { /* styles for the edge label */ },
|
|
194
|
-
},
|
|
195
|
-
controls: {
|
|
196
|
-
container: { /* styles for the controls container */ },
|
|
197
|
-
button: { /* styles for individual control buttons */ },
|
|
198
|
-
},
|
|
199
|
-
addNodeButton: { /* styles for the add node button */ },
|
|
200
|
-
}}
|
|
201
|
-
/>
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## Accessibility
|
|
205
|
-
|
|
206
|
-
The Flow component implements the following accessibility features:
|
|
207
|
-
|
|
208
|
-
- Keyboard navigation for selecting nodes
|
|
209
|
-
- ARIA attributes for interactive elements
|
|
210
|
-
- Focus management for controls and nodes
|
|
211
|
-
- Proper contrast for node and edge colors
|
|
212
|
-
|
|
213
|
-
## Best Practices
|
|
214
|
-
|
|
215
|
-
- Provide clear labels and subtitles for nodes to improve understanding
|
|
216
|
-
- Use consistent node types and styling for similar functionality
|
|
217
|
-
- Implement proper error handling for node and edge operations
|
|
218
|
-
- Consider viewport size when determining initial node positions
|
|
219
|
-
- Use the `onNodeAdd` callback to validate new node positions
|
|
220
|
-
- Implement undo/redo functionality for node operations when needed
|