Skip to content

Commit b99ea91

Browse files
zhouLioncwandev
authored andcommitted
chore: create artifact example component with actions
1 parent 89681a6 commit b99ea91

File tree

4 files changed

+130
-12
lines changed

4 files changed

+130
-12
lines changed

packages/elements/src/artifact/index.tsx renamed to packages/elements/src/artifact/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,4 @@ export { default as ArtifactDescription } from './ArtifactDescription.vue'
77
export { default as ArtifactHeader } from './ArtifactHeader.vue'
88
export { default as ArtifactTitle } from './ArtifactTitle.vue'
99

10-
export type {
11-
ArtifactActionProps,
12-
ArtifactActionsProps,
13-
ArtifactCloseProps,
14-
ArtifactContentProps,
15-
ArtifactDescriptionProps,
16-
ArtifactHeaderProps,
17-
ArtifactProps,
18-
ArtifactTitleProps,
19-
} from './props'
10+
export * from './props'

packages/elements/src/artifact/props.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type Button from '@repo/shadcn-vue/components/ui/button/Button.vue'
22
import type { LucideIcon } from 'lucide-vue-next'
33
import type { HTMLAttributes } from 'vue'
44

5+
type ButtonProps = InstanceType<typeof Button>['$props']
6+
57
export type ArtifactProps = HTMLAttributes
68
export type ArtifactHeaderProps = HTMLAttributes
7-
export type ArtifactCloseProps = InstanceType<typeof Button>
9+
export type ArtifactCloseProps = ButtonProps
810
export type ArtifactTitleProps = HTMLAttributes
911
export type ArtifactDescriptionProps = HTMLAttributes
1012
export type ArtifactActionsProps = HTMLAttributes
11-
export type ArtifactActionProps = InstanceType<typeof Button> & {
13+
export type ArtifactActionProps = ButtonProps & {
1214
tooltip?: string
1315
label?: string
1416
icon?: LucideIcon

packages/examples/src/artifact.vue

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<script setup lang="ts">
2+
import {
3+
Artifact,
4+
ArtifactAction,
5+
ArtifactActions,
6+
ArtifactContent,
7+
ArtifactDescription,
8+
ArtifactHeader,
9+
ArtifactTitle,
10+
} from '@repo/elements/artifact'
11+
import { CodeBlock } from '@repo/elements/code-block'
12+
import { Copy, Download, Play, RefreshCw, Share } from 'lucide-vue-next'
13+
14+
const code = `# Dijkstra's Algorithm implementation
15+
import heapq
16+
17+
def dijkstra(graph, start):
18+
distances = {node: float('inf') for node in graph}
19+
distances[start] = 0
20+
heap = [(0, start)]
21+
visited = set()
22+
23+
while heap:
24+
current_distance, current_node = heapq.heappop(heap)
25+
if current_node in visited:
26+
continue
27+
visited.add(current_node)
28+
29+
for neighbor, weight in graph[current_node].items():
30+
distance = current_distance + weight
31+
if distance < distances[neighbor]:
32+
distances[neighbor] = distance
33+
heapq.heappush(heap, (distance, neighbor))
34+
35+
return distances
36+
37+
# Example graph
38+
graph = {
39+
'A': {'B': 1, 'C': 4},
40+
'B': {'A': 1, 'C': 2, 'D': 5},
41+
'C': {'A': 4, 'B': 2, 'D': 1},
42+
'D': {'B': 5, 'C': 1}
43+
}
44+
45+
print(dijkstra(graph, 'A'))`
46+
47+
function handleRun() {
48+
// eslint-disable-next-line no-console
49+
console.log('Run')
50+
}
51+
52+
function handleCopy() {
53+
// eslint-disable-next-line no-console
54+
console.log('Copy')
55+
}
56+
57+
function handleRegenerate() {
58+
// eslint-disable-next-line no-console
59+
console.log('Regenerate')
60+
}
61+
62+
function handleDownload() {
63+
// eslint-disable-next-line no-console
64+
console.log('Download')
65+
}
66+
67+
function handleShare() {
68+
// eslint-disable-next-line no-console
69+
console.log('Share')
70+
}
71+
</script>
72+
73+
<template>
74+
<Artifact>
75+
<ArtifactHeader>
76+
<div>
77+
<ArtifactTitle>Dijkstra's Algorithm Implementation</ArtifactTitle>
78+
<ArtifactDescription>Updated 1 minute ago</ArtifactDescription>
79+
</div>
80+
<div class="flex items-center gap-2">
81+
<ArtifactActions>
82+
<ArtifactAction
83+
:icon="Play"
84+
label="Run"
85+
tooltip="Run code"
86+
@click="handleRun"
87+
/>
88+
<ArtifactAction
89+
:icon="Copy"
90+
label="Copy"
91+
tooltip="Copy to clipboard"
92+
@click="handleCopy"
93+
/>
94+
<ArtifactAction
95+
:icon="RefreshCw"
96+
label="Regenerate"
97+
tooltip="Regenerate content"
98+
@click="handleRegenerate"
99+
/>
100+
<ArtifactAction
101+
:icon="Download"
102+
label="Download"
103+
tooltip="Download file"
104+
@click="handleDownload"
105+
/>
106+
<ArtifactAction
107+
:icon="Share"
108+
label="Share"
109+
tooltip="Share artifact"
110+
@click="handleShare"
111+
/>
112+
</ArtifactActions>
113+
</div>
114+
</ArtifactHeader>
115+
<ArtifactContent class="p-0">
116+
<CodeBlock
117+
class="border-none"
118+
:code="code"
119+
language="python"
120+
show-line-numbers
121+
/>
122+
</ArtifactContent>
123+
</Artifact>
124+
</template>

packages/examples/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { default as ActionsHover } from './actions-hover.vue'
22
export { default as Actions } from './actions.vue'
3+
export { default as Artifact } from './artifact.vue'
34
export { default as Branch } from './branch.vue'
45
export { default as ChainOfThought } from './chain-of-thought.vue'
56
export { default as Checkpoint } from './checkpoint.vue'

0 commit comments

Comments
 (0)