ChatCodeRunner

Data Display

코드와 실행 결과를 함께 보여주는 블록.

Usage

코드 블록과 실행 상태·출력을 하나의 카드로 함께 보여줄 때 사용한다.

import

import

import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';

API Reference

ChatCodeRunner Props

Prop

Type

Default

code
필수

string

지정 안 함

language
필수

ReactNode

지정 안 함

output
필수

readonly string[]

지정 안 함

state
필수

"running" | "error" | "idle" | "ok"

지정 안 함

durationMs

number

지정 안 함

labels

Partial<ChatCodeRunnerLabels>

지정 안 함

onRun

() => void

지정 안 함

같은 패밀리

@mildang/design-system/unofficial/Chat 에서 같이 내보내는 컴포넌트다.

예제

실행 전

import type { ComponentProps } from 'react';
import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatCodeRunner>;
const CODE = `pnpm --filter @mildang/design-system test \\\n+  --reporter=dot`;
const DEFAULT_ARGS: Props = { language: 'bash', code: CODE, state: 'idle', output: [], onRun: () => undefined };
export default function CodeRunnerIdleExample(props: Partial<Props> = {}) { return <ChatCodeRunner {...DEFAULT_ARGS} {...props} />; }

실행 중

import type { ComponentProps } from 'react';
import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatCodeRunner>;
const CODE = `pnpm --filter @mildang/design-system test \\\n+  --reporter=dot`;
const DEFAULT_ARGS: Props = { language: 'bash', code: CODE, state: 'running', output: ['· 12 tests', '· 3 files'], durationMs: 820, onRun: () => undefined };
export default function CodeRunnerRunningExample(props: Partial<Props> = {}) { return <ChatCodeRunner {...DEFAULT_ARGS} {...props} />; }

정상 종료

import type { ComponentProps } from 'react';
import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatCodeRunner>;
const CODE = `pnpm --filter @mildang/design-system test \\\n+  --reporter=dot`;
const DEFAULT_ARGS: Props = { language: 'bash', code: CODE, state: 'ok', output: ['✓ 12 tests passed', 'Duration  0.82s'], durationMs: 820, onRun: () => undefined };
export default function CodeRunnerOkExample(props: Partial<Props> = {}) { return <ChatCodeRunner {...DEFAULT_ARGS} {...props} />; }

실패

import type { ComponentProps } from 'react';
import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatCodeRunner>;
const DEFAULT_ARGS: Props = { language: 'python', code: 'raise RuntimeError("boom")', state: 'error', output: ['Traceback (most recent call last):', '  File "run.py", line 1, in <module>', 'RuntimeError: boom'], durationMs: 41, onRun: () => undefined };
export default function CodeRunnerErrorExample(props: Partial<Props> = {}) { return <ChatCodeRunner {...DEFAULT_ARGS} {...props} />; }

읽기 전용

import type { ComponentProps } from 'react';
import { ChatCodeRunner } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatCodeRunner>;
const CODE = `pnpm --filter @mildang/design-system test \\\n+  --reporter=dot`;
const DEFAULT_ARGS: Props = { language: 'bash', code: CODE, state: 'ok', output: ['✓ 12 tests passed'], durationMs: 820 };
export default function CodeRunnerReadOnlyExample(props: Partial<Props> = {}) { return <ChatCodeRunner {...DEFAULT_ARGS} {...props} />; }