-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.tsx
More file actions
179 lines (151 loc) · 4.63 KB
/
Copy pathexample.tsx
File metadata and controls
179 lines (151 loc) · 4.63 KB
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
import { StreamingIndicator } from "./component"
import * as React from "react"
// Example 1: Dots variant
export function DotsIndicatorExample() {
return <StreamingIndicator variant="dots" message="Loading..." />
}
// Example 2: Pulse variant
export function PulseIndicatorExample() {
return <StreamingIndicator variant="pulse" message="Processing data..." />
}
// Example 3: Spinner variant
export function SpinnerIndicatorExample() {
return <StreamingIndicator variant="spinner" message="Generating report..." />
}
// Example 4: Typing indicator (for AI chat)
export function TypingIndicatorExample() {
return <StreamingIndicator variant="typing" />
}
// Example 5: Progress indicator with steps
export function ProgressIndicatorExample() {
const [steps, setSteps] = React.useState([
{ label: "Analyzing input...", status: "completed" as const },
{ label: "Generating response...", status: "active" as const },
{ label: "Formatting output...", status: "pending" as const },
])
// Simulate progress
React.useEffect(() => {
const timer = setTimeout(() => {
setSteps([
{ label: "Analyzing input...", status: "completed" },
{ label: "Generating response...", status: "completed" },
{ label: "Formatting output...", status: "active" },
])
}, 2000)
return () => clearTimeout(timer)
}, [])
return <StreamingIndicator variant="progress" steps={steps} />
}
// Example 6: With token counter
export function TokenCounterIndicatorExample() {
const [tokenCount, setTokenCount] = React.useState(0)
// Simulate token counting
React.useEffect(() => {
const interval = setInterval(() => {
setTokenCount((prev) => prev + Math.floor(Math.random() * 10) + 5)
}, 100)
const timeout = setTimeout(() => {
clearInterval(interval)
}, 3000)
return () => {
clearInterval(interval)
clearTimeout(timeout)
}
}, [])
return (
<StreamingIndicator
variant="dots"
message="Generating response..."
tokenCount={tokenCount}
showTokenCounter
/>
)
}
// Example 7: Complete AI workflow with progress
export function CompleteAIWorkflowExample() {
const [currentStep, setCurrentStep] = React.useState(0)
const [tokenCount, setTokenCount] = React.useState(0)
const stepLabels = [
"Analyzing your request...",
"Searching knowledge base...",
"Generating response...",
"Formatting output...",
]
const steps = stepLabels.map((label, index) => ({
label,
status:
index < currentStep
? ("completed" as const)
: index === currentStep
? ("active" as const)
: ("pending" as const),
}))
// Simulate workflow progress
React.useEffect(() => {
if (currentStep < stepLabels.length) {
const timer = setTimeout(() => {
setCurrentStep((prev) => prev + 1)
}, 2000)
return () => clearTimeout(timer)
}
}, [currentStep, stepLabels.length])
// Simulate token counting during generation step
React.useEffect(() => {
if (currentStep === 2) {
const interval = setInterval(() => {
setTokenCount((prev) => prev + Math.floor(Math.random() * 15) + 5)
}, 100)
const timeout = setTimeout(() => {
clearInterval(interval)
}, 2000)
return () => {
clearInterval(interval)
clearTimeout(timeout)
}
}
}, [currentStep])
return (
<StreamingIndicator
variant="progress"
steps={steps}
tokenCount={tokenCount}
showTokenCounter={currentStep === 2}
/>
)
}
// Example 8: Multiple indicators in a dashboard
export function DashboardIndicatorsExample() {
return (
<div className="grid gap-4 md:grid-cols-2">
<StreamingIndicator variant="dots" message="Loading analytics..." />
<StreamingIndicator variant="pulse" message="Syncing data..." />
<StreamingIndicator variant="spinner" message="Generating insights..." />
<StreamingIndicator variant="typing" />
</div>
)
}
// Example 9: Conditional rendering based on state
export function ConditionalIndicatorExample() {
const [isLoading, setIsLoading] = React.useState(true)
React.useEffect(() => {
const timer = setTimeout(() => {
setIsLoading(false)
}, 3000)
return () => clearTimeout(timer)
}, [])
return (
<div className="space-y-4">
{isLoading ? (
<StreamingIndicator
variant="dots"
message="Loading data..."
/>
) : (
<div className="rounded-lg border border-border bg-card p-4">
<p className="text-foreground">Data loaded successfully!</p>
</div>
)}
</div>
)
}
export default DotsIndicatorExample