|
1
|
import type { Meta, StoryObj } from "@storybook/react" |
|
2
|
import React from "react" |
|
3
|
|
|
4
|
import { TooltipProvider } from "../tooltip" |
|
5
|
import { CodeBlock } from "./code-block" |
|
6
|
|
|
7
|
const meta: Meta<typeof CodeBlock> = { |
|
8
|
title: "Components/CodeBlock", |
|
9
|
component: CodeBlock, |
|
10
|
parameters: { |
|
11
|
layout: "centered", |
|
12
|
}, |
|
13
|
} |
|
14
|
|
|
15
|
export default meta |
|
16
|
|
|
17
|
type Story = StoryObj<typeof CodeBlock> |
|
18
|
|
|
19
|
const snippets = [ |
|
20
|
{ |
|
21
|
label: "cURL", |
|
22
|
language: "markdown", |
|
23
|
code: `curl -H 'x-publishable-key: YOUR_API_KEY' 'http://localhost:9000/store/products/PRODUCT_ID'`, |
|
24
|
}, |
|
25
|
{ |
|
26
|
label: "Medusa JS Client", |
|
27
|
language: "jsx", |
|
28
|
code: `// Install the JS Client in your storefront project: @medusajs/medusa-js\n\nimport Medusa from "@medusajs/medusa-js"\n\nconst medusa = new Medusa({ publishableApiKey: "YOUR_API_KEY"})\nconst product = await medusa.products.retrieve("PRODUCT_ID")\nconsole.log(product.id)`, |
|
29
|
}, |
|
30
|
{ |
|
31
|
label: "Medusa React", |
|
32
|
language: "tsx", |
|
33
|
code: `// Install the React SDK and required dependencies in your storefront project:\n// medusa-react @tanstack/react-query @medusajs/medusa\n\nimport { useProduct } from "medusa-react"\n\nconst { product } = useProduct("PRODUCT_ID")\nconsole.log(product.id)`, |
|
34
|
}, |
|
35
|
] |
|
36
|
|
|
37
|
export const Default: Story = { |
|
38
|
render: () => { |
|
39
|
return ( |
|
40
|
<TooltipProvider> |
|
41
|
<div className="h-[300px] w-[700px]"> |
|
42
|
<CodeBlock snippets={snippets}> |
|
43
|
<CodeBlock.Header></CodeBlock.Header> |
|
44
|
<CodeBlock.Body> |
|
45
|
<span>/store/products/:id</span> |
|
46
|
</CodeBlock.Body> |
|
47
|
</CodeBlock> |
|
48
|
</div> |
|
49
|
</TooltipProvider> |
|
50
|
) |
|
51
|
}, |
|
52
|
} |
|
53
|
|
|
54
|
const generateStartupLog = () => { |
|
55
|
const services = [ |
|
56
|
{ name: "Models", time: 14 }, |
|
57
|
{ name: "Repositories", time: 35 }, |
|
58
|
{ name: "Strategies", time: 24 }, |
|
59
|
{ name: "Modules", time: 1 }, |
|
60
|
{ name: "Database", time: 654 }, |
|
61
|
{ name: "Services", time: 7 }, |
|
62
|
{ name: "Express", time: 5 }, |
|
63
|
{ name: "Plugins", time: 7 }, |
|
64
|
{ name: "Subscribers", time: 6 }, |
|
65
|
{ name: "API", time: 28 }, |
|
66
|
{ name: "Cache", time: 12 }, |
|
67
|
{ name: "Queue", time: 45 }, |
|
68
|
{ name: "Middleware", time: 8 }, |
|
69
|
{ name: "WebSockets", time: 15 }, |
|
70
|
{ name: "Authentication", time: 42 }, |
|
71
|
] |
|
72
|
|
|
73
|
const lines = services.flatMap((service) => [ |
|
74
|
`✔ ${service.name} initialized – ${service.time}ms`, |
|
75
|
`✔ ${service.name} validated – ${service.time + 5}ms`, |
|
76
|
`✔ ${service.name} configured – ${service.time + 10}ms`, |
|
77
|
`✔ ${service.name} optimized – ${service.time + 3}ms`, |
|
78
|
]) |
|
79
|
|
|
80
|
return `medusa develop\n${lines.join("\n")}\n✔ Server is ready on port: 9000` |
|
81
|
} |
|
82
|
|
|
83
|
const code = generateStartupLog() |
|
84
|
|
|
85
|
export const ManyLines: Story = { |
|
86
|
render: () => { |
|
87
|
return ( |
|
88
|
<TooltipProvider> |
|
89
|
<CodeBlock |
|
90
|
snippets={[ |
|
91
|
{ |
|
92
|
code: code, |
|
93
|
label: "Test", |
|
94
|
language: "bash", |
|
95
|
hideCopy: true, |
|
96
|
}, |
|
97
|
]} |
|
98
|
className="h-full max-h-[300px] w-[700px]" |
|
99
|
> |
|
100
|
<CodeBlock.Header></CodeBlock.Header> |
|
101
|
<CodeBlock.Body /> |
|
102
|
</CodeBlock> |
|
103
|
</TooltipProvider> |
|
104
|
) |
|
105
|
}, |
|
106
|
} |