mirror of
https://github.com/langgenius/dify.git
synced 2026-02-28 04:15:10 +00:00
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
Trigger i18n Sync on Push / trigger (push) Has been cancelled
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
|
|
import CodeBlock from './code-block'
|
|
|
|
const SAMPLE_CODE = `const greet = (name: string) => {
|
|
return \`Hello, \${name}\`
|
|
}
|
|
|
|
console.log(greet('Dify'))`
|
|
|
|
const CodeBlockDemo = ({
|
|
language = 'typescript',
|
|
}: {
|
|
language?: string
|
|
}) => {
|
|
return (
|
|
<div className="flex w-full max-w-xl flex-col gap-4 rounded-2xl border border-divider-subtle bg-components-panel-bg p-6">
|
|
<div className="text-xs uppercase tracking-[0.18em] text-text-tertiary">Code block</div>
|
|
<CodeBlock
|
|
className={`language-${language}`}
|
|
>
|
|
{SAMPLE_CODE}
|
|
</CodeBlock>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const meta = {
|
|
title: 'Base/Data Display/CodeBlock',
|
|
component: CodeBlockDemo,
|
|
parameters: {
|
|
layout: 'centered',
|
|
docs: {
|
|
description: {
|
|
component: 'Syntax highlighted code block with copy button and SVG toggle support.',
|
|
},
|
|
},
|
|
},
|
|
argTypes: {
|
|
language: {
|
|
control: 'radio',
|
|
options: ['typescript', 'json', 'mermaid'],
|
|
},
|
|
},
|
|
args: {
|
|
language: 'typescript',
|
|
},
|
|
tags: ['autodocs'],
|
|
} satisfies Meta<typeof CodeBlockDemo>
|
|
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
export const Playground: Story = {}
|
|
|
|
export const Mermaid: Story = {
|
|
args: {
|
|
language: 'mermaid',
|
|
},
|
|
render: ({ language }) => (
|
|
<div className="flex w-full max-w-xl flex-col gap-4 rounded-2xl border border-divider-subtle bg-components-panel-bg p-6">
|
|
<CodeBlock className={`language-${language}`}>
|
|
{`graph TD
|
|
Start --> Decision{User message?}
|
|
Decision -->|Tool| ToolCall[Call web search]
|
|
Decision -->|Respond| Answer[Compose draft]
|
|
`}
|
|
</CodeBlock>
|
|
</div>
|
|
),
|
|
}
|