TypingCodeBlock — بلوک کد تایپی
بلوک کد تایپی یک توالی از مراحل را نشان میدهد: پرامپت (کپی کد) بیحرکت، تایپ کاراکتر به کاراکتر با نقش سینتکس، خروجی فوری با لحن عادی یا موفقیت، و مکث. رنگها از همان توکنهای کپی کد میآیند و با هر تم هویت خودش را میگیرد.
وضعیت: beta · لایه: ۳ (کپی کد) · توکنها: کپی کد
import { TypingCodeBlock } from '@tokapps/tuk';چهار نمونهٔ آماده
هر نمونه یک پیشنمایش زنده و یک بلوک کد قابلکپی دارد. کد از همان مراحل پیشنمایش ساخته میشود.
import { TypingCodeBlock } from '@tokapps/tuk';const steps = [ { type: 'prompt', text: "ali@tokapps:~/projects $ " }, { type: 'type', text: "ls -la", speed: 55 }, { type: 'output', text: "\n" }, { type: 'pause', ms: 220 }, { type: 'output', text: "total 24\ndrwxr-xr-x 6 ali staff 192 Oct 13 10:02 .\ndrwxr-xr-x 9 ali staff 288 Oct 12 18:44 ..\n-rw-r--r-- 1 ali staff 512 Oct 13 09:58 package.json\n-rw-r--r-- 1 ali staff 2048 Oct 13 09:58 tsconfig.json\ndrwxr-xr-x 7 ali staff 224 Oct 13 10:01 src\n" }, { type: 'pause', ms: 600 }, { type: 'prompt', text: "ali@tokapps:~/projects $ " }, { type: 'type', text: "cat package.json | head -4", speed: 40 }, { type: 'output', text: "\n" }, { type: 'pause', ms: 200 }, { type: 'output', text: "{\n \"name\": \"tokapps-app\",\n \"version\": \"0.1.0\",\n \"private\": true\n" }, { type: 'pause', ms: 600 }, { type: 'prompt', text: "ali@tokapps:~/projects $ " }, { type: 'type', text: "npm run build", speed: 48 }, { type: 'output', text: "\n" }, { type: 'pause', ms: 300 }, { type: 'output', text: "> tokapps-app@0.1.0 build\n> tsc && vite build\n\n" }, { type: 'output', text: "built in 1.24s\n", tone: 'success' }, { type: 'pause', ms: 600 }, { type: 'prompt', text: "ali@tokapps:~/projects $ " }, { type: 'type', text: "node -v", speed: 60 }, { type: 'output', text: "\n" }, { type: 'pause', ms: 180 }, { type: 'output', text: "v22.11.0\n" }, { type: 'prompt', text: "ali@tokapps:~/projects $ " },];<TypingCodeBlock steps={steps} language="terminal" />import { TypingCodeBlock } from '@tokapps/tuk';const steps = [ { type: 'type', text: "import", kind: 'keyword', speed: 30 }, { type: 'type', text: " { useState } ", speed: 30 }, { type: 'type', text: "from", kind: 'keyword', speed: 30 }, { type: 'type', text: " 'react'", kind: 'string', speed: 30 }, { type: 'type', text: ";\n\n", speed: 30 }, { type: 'type', text: "export", kind: 'keyword', speed: 30 }, { type: 'type', text: " ", speed: 30 }, { type: 'type', text: "function", kind: 'keyword', speed: 30 }, { type: 'type', text: " ", speed: 30 }, { type: 'type', text: "Counter", kind: 'function', speed: 30 }, { type: 'type', text: "({ start = ", speed: 30 }, { type: 'type', text: "0", kind: 'number', speed: 30 }, { type: 'type', text: " }: { start?: ", speed: 30 }, { type: 'type', text: "number", kind: 'type', speed: 30 }, { type: 'type', text: " }) {\n", speed: 30 }, { type: 'type', text: " const", kind: 'keyword', speed: 30 }, { type: 'type', text: " [count, setCount] = ", speed: 30 }, { type: 'type', text: "useState", kind: 'function', speed: 30 }, { type: 'type', text: "(start);\n", speed: 30 }, { type: 'type', text: " // Counter increments on every click\n", kind: 'comment', speed: 26 }, { type: 'type', text: " return", kind: 'keyword', speed: 30 }, { type: 'type', text: " <", speed: 30 }, { type: 'type', text: "button", kind: 'tag', speed: 30 }, { type: 'type', text: " onClick={() => ", speed: 30 }, { type: 'type', text: "setCount", kind: 'function', speed: 30 }, { type: 'type', text: "(count + ", speed: 30 }, { type: 'type', text: "1", kind: 'number', speed: 30 }, { type: 'type', text: ")}>{count}</", speed: 30 }, { type: 'type', text: "button", kind: 'tag', speed: 30 }, { type: 'type', text: ">;\n}", speed: 30 },];<TypingCodeBlock steps={steps} language="TypeScript" />import { TypingCodeBlock } from '@tokapps/tuk';const steps = [ { type: 'type', text: "@@ Button.tsx @@\n", kind: 'comment', speed: 22 }, { type: 'pause', ms: 150 }, { type: 'type', text: "- const base = \"btn\";\n", kind: 'deleted', speed: 16 }, { type: 'pause', ms: 120 }, { type: 'type', text: "+ const base = \"tds-btn\";\n", kind: 'inserted', speed: 16 }, { type: 'pause', ms: 120 }, { type: 'type', text: " export function Button() {\n", speed: 16 }, { type: 'pause', ms: 120 }, { type: 'type', text: "- return <button className={base}>\n", kind: 'deleted', speed: 16 }, { type: 'pause', ms: 120 }, { type: 'type', text: "+ return <button data-tds=\"button\">\n", kind: 'inserted', speed: 16 }, { type: 'pause', ms: 120 }, { type: 'type', text: " }\n", speed: 16 },];<TypingCodeBlock steps={steps} language="diff" />import { TypingCodeBlock } from '@tokapps/tuk';const steps = [ { type: 'type', text: "{\n", speed: 14 }, { type: 'type', text: " ", speed: 14 }, { type: 'type', text: "\"component\"", kind: 'property', speed: 14 }, { type: 'type', text: ": ", speed: 14 }, { type: 'type', text: "\"TypingCodeBlock\"", kind: 'string', speed: 14 }, { type: 'type', text: ",\n", speed: 14 }, { type: 'pause', ms: 260 }, { type: 'type', text: " ", speed: 14 }, { type: 'type', text: "\"version\"", kind: 'property', speed: 14 }, { type: 'type', text: ": ", speed: 14 }, { type: 'type', text: "1", kind: 'number', speed: 14 }, { type: 'type', text: ",\n", speed: 14 }, { type: 'pause', ms: 260 }, { type: 'type', text: " ", speed: 14 }, { type: 'type', text: "\"a11y\"", kind: 'property', speed: 14 }, { type: 'type', text: ": { ", speed: 14 }, { type: 'type', text: "\"copyable\"", kind: 'property', speed: 14 }, { type: 'type', text: ": ", speed: 14 }, { type: 'type', text: "true", kind: 'constant', speed: 14 }, { type: 'type', text: ", ", speed: 14 }, { type: 'type', text: "\"reducedMotion\"", kind: 'property', speed: 14 }, { type: 'type', text: ": ", speed: 14 }, { type: 'type', text: "\"respected\"", kind: 'string', speed: 14 }, { type: 'type', text: " }\n", speed: 14 }, { type: 'pause', ms: 200 }, { type: 'type', text: "}", speed: 14 },];<TypingCodeBlock steps={steps} language="JSON" />حالتهای رفتاری
import { TypingCodeBlock } from '@tokapps/tuk';<TypingCodeBlock steps={steps} loop speed={2} height="12rem" />import { TypingCodeBlock } from '@tokapps/tuk';<TypingCodeBlock steps={steps} autoPlay={false} replayLabel="شروع" />مراحل
| نوع | فیلدها | توضیح |
|---|---|---|
| کپی کد | کپی کد | پرامپت ثابت؛ بدون انیمیشن |
| کپی کد | کپی کد، کپی کد، کپی کد | تایپ کاراکتر به کاراکتر؛ کپی کد نقش سینتکس (keyword، string، function…) و کپی کد میانگین ms هر کاراکتر است |
| کپی کد | کپی کد، کپی کد (کپی کد یا کپی کد) | خروجی فوری؛ کپی کد را خودتان بگذارید |
| کپی کد | کپی کد | مکث بین مراحل |
پیکربندی
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| کپی کد | کپی کد | — | توالی مراحل؛ ثابت نگه دارید |
| کپی کد | کپی کد | — | عنوان؛ در نبود آن برچسب کپی کد یا کپی کد |
| کپی کد | کپی کد | — | برچسب محیط یا زبان |
| کپی کد | کپی کد | کپی کد | ضریب سرعت؛ کپی کد یعنی بدون انیمیشن |
| کپی کد | کپی کد | کپی کد | پس از پایان از اول اجرا شود |
| کپی کد | کپی کد | کپی کد | با ورود به دید شروع شود |
| کپی کد | کپی کد | کپی کد | برچسب دکمهٔ پخش |
| کپی کد | کپی کد | کپی کد | ارتفاع ناحیهٔ نمایش |
حالتها
| حالت | ظاهر | توضیح |
|---|---|---|
| idle | ناحیه خالی با کرسر | قبل از ورود به دید یا با کپی کد |
| playing | کرسر چشمکزن | در حال تایپ؛ کپی کد |
| done | کرسر ثابت | پایان؛ کپی کد |
| loop | تکرار با مکث ۱٫۲ ثانیه | با کپی کد |
| reduced motion | متن کامل بیدرنگ | با کپی کد یا کپی کد |
دسترسپذیری و چاپ
ناحیهٔ انیمیشن کپی کد است و متن کامل مراحل در یک کپی کد پنهان برای صفحهخوان است. دکمهٔ پخش فوکوس Button را دارد. در چاپ دکمه پنهان و کد کامل با کپی کد چاپ میشود. این کامپوننت صدا ندارد.
کی استفاده کنیم
- نمایش یک جلسه ترمینال یا دستورهایی که به ترتیب اجرا میشوند
- معرفی یک تغییر کد با تأکید بر ترتیب
- نمایش پاسخی که بهتدریج میآید
کی استفاده نکنیم
- کدی که کاربر باید کپی کند؛ برای آن از کپی کد استفاده کنید
- متن طولانی یا محتوایی که باید فوراً خوانده شود