Skip to content

Layout Components

Container-type layout components such as cards, grids, lists, tabs, collapse, dialogs, drawers, timelines, step bars, carousels, trees, menus, and more. Container components must be closed with [/type]. The left side shows the formatted TokUI DSL, the right side renders it in real time — click "Edit" to make changes on the fly.

card is a general-purpose content container. tt sets the title, tx writes the body text directly (self-closing mode), and the main content is filled by child nodes. ft acts as a child container of card, automatically placed at the bottom of the card as a footer.

PropMeaningApplies toExample
ttTitlecardtt:用户信息
txSelf-closing body textcardtx:一段说明
hcTitle color (preset or color value)cardhc:primary
htTitle decoration stylecardht:underline
wWidthcardw:320
vVariantcardv:highlight
vAlignmentftv:right

card variants: highlight (highlighted border), flat (flat, no shadow), bordered (outlined), center / right (title alignment). ht title decorations: fill (tinted fill), accent (left color bar), underline (underline), dot (leading dot), pill (tinted pill). fill/pill use a soft "10% tinted background + accent text" scheme; custom hc colors are tinted the same way automatically. ft variants: left / center / right.

1[row]
2 [col span:6]
3 [card tt:基础卡片]
4 [p 这是基础卡片,承载正文与子组件。]
5 [/card]
6 [/col]
7 [col span:6]
8 [card tt:高亮卡片 v:highlight ht:underline hc:primary]
9 [p 带下划线标题的高亮卡片。]
10 [/card]
11 [/col]
12[/row]
13[card tt:带页脚的卡片 hc:danger ht:accent]
14 [p 主体内容:把操作按钮放进页脚区。]
15 [ft v:right]
16 [btn tx:取消]
17 [btn tx:确定 v:primary]
18 [/ft]
19[/card]
Loading TokUI…
TokUI DSL · code ↔ render

Grid row / col

Responsive layout based on a 12-column grid system. row is the container row, col is the column, and span specifies the column width (1-12).

PropMeaningApplies toExample
vAlignmentrowv:center
spanColumn width (1-12)colspan:4

row variants: left / center / right (horizontal alignment), inline (inline layout).

1[row]
2 [col span:4]
3 [callout t:info]
4 span:4
5 [/callout]
6[/col]
7[col span:4]
8 [callout t:success]
9 span:4
10[/callout]
11[/col]
12[col span:4]
13 [callout t:warning]
14 span:4
15[/callout]
16[/col]
17[/row]
18[row]
19 [col span:6]
20 [callout t:info]
21 span:6
22 [/callout]
23[/col]
24[col span:3]
25 [callout t:tip]
26 span:3
27[/callout]
28[/col]
29[col span:3]
30 [callout t:tip]
31 span:3
32[/callout]
33[/col]
34[/row]
Loading TokUI…
TokUI DSL · code ↔ render

List list / item

List container. list is unordered (ul) by default; t:ol switches it to an ordered list (ol). item is a list item (<li> semantics) — text is written inside the tag, child list can be nested, and plain hides the marker.

PropMeaningApplies toExample
tList typelistt:ol
plainRemove marker/numberlistplain
txItem textitemtx:第一项
1[row]
2 [col span:6]
3 [p v:bold 无序列表]
4 [list]
5 [item 第一项内容]
6 [item 第二项内容]
7 [item 第三项内容]
8 [/list]
9 [/col]
10 [col span:6]
11 [p v:bold 有序列表]
12 [list t:ol]
13 [item 步骤一]
14 [item 步骤二]
15 [item 步骤三]
16 [/list]
17 [/col]
18[/row]
19[p v:bold 嵌套列表]
20[list]
21 [item 主分类一[list]
22 [item 子项 A]
23 [item 子项 B]
24[/list]
25]
26[item 主分类二]
27[/list]
Loading TokUI…
TokUI DSL · code ↔ render

Tabs tabs / tab

tabs wraps multiple tab children. tt is each tab's navigation title, switched with pure CSS. Supports left/right arrow keyboard navigation.

PropMeaningApplies toExample
ttTab titletabtt:详情
1[tabs]
2 [tab tt:概览]
3 [p 这是概览页内容。]
4 [/tab]
5 [tab tt:详情]
6 [p 这是详情页内容,可放任意子组件。]
7 [stat tt:访问量 v:1024 trend:up]
8 [/tab]
9 [tab tt:设置]
10 [p 设置项放在这里。]
11 [/tab]
12[/tabs]
Loading TokUI…
TokUI DSL · code ↔ render

Tab-switch callback: once tabs declares on:"change:h", user tab switches report {index, title}; programmatic upd switches do not fire it.

Accordion accordion / Collapse collapse

accordion wraps multiple collapse panels, each independently collapsible. tt sets the title; open expands by default.

PropMeaningApplies toExample
ttTitlecollapsett:第一章
openExpand by defaultcollapseopen
idIdentifiercollapseid:sec1
1[accordion]
2 [collapse tt:什么是 TokUI? open]
3 [p TokUI 是零依赖的流式 UI 描述与渲染框架。]
4 [/collapse]
5 [collapse tt:核心特性]
6 [p 流式增量解析、纯原生 DOM、零外部依赖。]
7 [/collapse]
8 [collapse tt:适用场景]
9 [p AI 对话中的流式 UI 生成、低代码可视化搭建。]
10 [/collapse]
11[/accordion]
Loading TokUI…
TokUI DSL · code ↔ render

Dialog dialog

Built on the native <dialog> element, with a backdrop + centered modal. Esc / click backdrop / close button all dismiss it.

PropMeaningExample
ttTitlett:确认操作
idIdentifier (the trigger button's data-target points to it)id:myDialog
clkHandler nameclk:openDialog

Triggered by a button: the trigger button uses clk:openDialog data-target:"<the dialog's id>", and the matching [dialog id:...] must carry the same id. Clicking calls the built-in openDialog handler, which finds the dialog by id and calls showModal(). Cancel/confirm buttons inside use clk:closeDialog to dismiss the enclosing dialog (no id needed).

Close callback: once on:"close:h" is declared, user close paths (Esc / backdrop / ✕) are reported with detail {}; programmatic [upd id:x act:close] is not reported (loop prevention).

1[row]
2 [col span:6]
3 [btn tx:点击打开对话框 v:primary clk:openDialog data-target:demoDialog]
4 [dialog tt:用户协议 id:demoDialog]
5 [p 请仔细阅读以下协议内容,勾选同意后即可继续。]
6 [p v:muted 点击「同意并继续」或 / 遮罩可关闭对话框。]
7 [ft v:right]
8 [btn tx:取消 clk:closeDialog]
9 [btn tx:同意并继续 v:primary clk:closeDialog]
10 [/ft]
11 [/dialog]
12 [/col]
13[/row]
Loading TokUI…
TokUI DSL · code ↔ render

Drawer drawer

A panel that slides in from the side. pos controls the direction; w sets the width for left/right drawers and h sets the height for top/bottom drawers. Esc / backdrop / close button all dismiss it.

PropMeaningExample
ttTitlett:筛选条件
posPosition (left/right/top/bottom, default right)pos:left
wWidth (left/right drawers, default 360px)w:420
hHeight (top/bottom drawers, default 300px)h:260
idIdentifier (the trigger button's data-target points to it)id:myDrawer
clkHandler nameclk:openDrawer

pos variants: left / right / top / bottom.

Triggered by a button: the trigger button uses clk:openDrawer data-target:"<the drawer's id>", and the matching [drawer id:...] must carry the same id. Clicking calls the built-in openDrawer handler, which finds the drawer by id and adds the tokui-drawer--open class to slide it in. Cancel/confirm buttons inside use clk:closeDrawer to dismiss the enclosing drawer.

Close callback: once on:"close:h" is declared, user close paths (Esc / backdrop / ✕) are reported with detail {}; programmatic [upd id:x act:close] is not reported (loop prevention).

1[btn tx:打开筛选抽屉 clk:openDrawer v:primary data-target:demoDrawer]
2[drawer tt:筛选条件 pos:right w:360 id:demoDrawer]
3 [p 在这里放置筛选表单或详情内容,Esc / 遮罩 / 可关闭。]
4 [ft v:right]
5 [btn tx:取消 clk:closeDrawer]
6 [btn tx:应用 v:primary clk:closeDrawer]
7 [/ft]
8[/drawer]
Loading TokUI…
TokUI DSL · code ↔ render

Timeline timeline / ti

timeline is the container; ti is a single record. tm sets the timestamp, tt the title, t the status color (primary/success/warning/error/info). The body text goes inside the tag.

PropMeaningApplies toExample
vLayout (h/alternate/card)timelinev:alternate
tmTimestamptitm:2026-06-01
ttTitletitt:提交申请
tStatus colortit:success

timeline variants: h / horizontal (horizontal), alternate / alt (alternating left/right), card (card style).

1[timeline]
2 [ti tm:2026-06-01 09:00 tt:创建订单 t:primary 用户下单成功]
3 [ti tm:2026-06-01 10:30 tt:支付完成 t:success 已收到款项]
4 [ti tm:2026-06-02 08:00 tt:商家发货 t:warning 商品已出库]
5 [ti tm:2026-06-03 14:00 tt:签收确认 t:info 用户确认收货]
6[/timeline]
Loading TokUI…
TokUI DSL · code ↔ render

Steps steps / step

A horizontal flow indicator. v sets the current step (1-based), vd:vertical switches to a vertical layout, and s:sm reduces the size. A step child can use status:error to mark an error state.

PropMeaningApplies toExample
vCurrent step (1-based)stepsv:2
vdDirection (horizontal/vertical)stepsvd:vertical
sSizestepss:sm
ttStep titlesteptt:填写信息
statusPer-step statusstepstatus:error
1[steps v:3]
2 [step tt:填写信息 基本信息]
3 [step tt:身份验证 完成实名认证]
4 [step tt:设置支付 配置支付方式]
5 [step tt:完成注册 激活账号]
6[/steps]
Loading TokUI…
TokUI DSL · code ↔ render

Clickable steps: once steps declares on:"change:h", steps become clickable and a click reports {index, title}.

carousel is the container; children are carousel-item (or plain img). Children may also be written as [item] — inside carousel it renders as a slide (same name as [item] in list/desc, disambiguated by parent; item and carousel-item are equivalent and can be mixed). auto sets the autoplay interval (in milliseconds). Supports left/right arrows, indicator dots, dragging, and left/right keyboard navigation. thumb switches to a thumbnail legend below (replaces dots; click to jump smoothly). Sizing: w width, h height (plain numbers are px; %/vw/rem also accepted), or ratio aspect ratio (e.g. 16:9 / 4:3 / 1); when h or ratio is set, slides fill the height and images are cropped with object-fit:cover; h takes precedence over ratio.

PropMeaningApplies toExample
autoAutoplay interval (ms)carouselauto:3000
idIdentifiercarouselid:myCarousel
thumbShow thumbnail legend (replaces dots)carouselthumb
wWidth (plain number → px, or %/vw/rem)carouselw:480 / w:100%
hHeight (px; overrides ratio)carouselh:240
ratioAspect ratio (16:9 / 4:3 / 1)carouselratio:16:9
sImage URLcarousel-item / items:https://...
ttSlide titlecarousel-item / itemtt:第一张
txSlide descriptioncarousel-item / itemtx:说明文字
1[carousel auto:4000]
2 [item s:https://picsum.photos/seed/c1/600/280 tt:第一张 tx: item 声明]
3 [carousel-item s:https://picsum.photos/seed/c2/600/280 tt:第二张 tx:两种可混用]
4 [item s:https://picsum.photos/seed/c3/600/280 tt:第三张 tx:等价于 carousel-item]
5[/carousel]
Loading TokUI…
TokUI DSL · code ↔ render

Switch reporting: once on:"change:h" is declared, manual switches (arrows / dots / drag / keyboard) report {index}; autoplay does not fire it.

Fixed size (h) / aspect ratio (ratio) / thumbnail legend (thumb):

1[row]
2 [col span:6]
3 [carousel h:200]
4 [carousel-item s:https://picsum.photos/seed/cs1/600/300 tt:固定高 200px]
5 [/carousel]
6 [/col]
7 [col span:6]
8 [carousel ratio:16:9]
9 [carousel-item s:https://picsum.photos/seed/cs2/600/338 tt:16:9 比例]
10 [/carousel]
11 [/col]
12[/row]
Loading TokUI…
TokUI DSL · code ↔ render
1[carousel thumb ratio:21:9]
2 [carousel-item s:https://picsum.photos/seed/ct1/800/343 tt:日出]
3 [carousel-item s:https://picsum.photos/seed/ct2/800/343 tt:正午]
4 [carousel-item s:https://picsum.photos/seed/ct3/800/343 tt:黄昏]
5 [carousel-item s:https://picsum.photos/seed/ct4/800/343 tt:夜晚]
6[/carousel]
Loading TokUI…
TokUI DSL · code ↔ render

Tree tree / tn

tree is the container; child nodes tn can be nested recursively. On tn, leaf marks a leaf node, open expands by default, chk selects, and dis disables. On tree, chk enables checkbox mode.

PropMeaningApplies toExample
lField labeltreel:目录
clkSelect callbacktreeclk:onPick
chkCheckbox modetreechk
disDisable the whole treetreedis
v / txValue / display texttntx:src
leafLeaf nodetnleaf
openExpand by defaulttnopen
chk / disSelected / disabledtnchk
loadLazy-load data handlertnload:loadChildren
1[tree l:项目结构]
2 [tn tx:src open]
3 [tn tx:components leaf]
4 [tn tx:core leaf]
5 [tn tx:styles leaf]
6 [/tn]
7 [tn tx:tests open]
8 [tn tx:test-parser.js leaf]
9 [tn tx:test-renderer.js leaf]
10 [/tn]
11 [tn tx:package.json leaf]
12[/tree]
Loading TokUI…
TokUI DSL · code ↔ render

Select & check reporting: declare on:"change:h" to report {value, id} when a node is selected; in checkbox mode (chk), declare on:"check:h" to report {value: checked values array} on checkbox changes.

Lazy loading (load): when a tn declares load:data-handler, expanding the node for the first time calls fn({id, value}) (returning an array of child-node objects or a Promise) with a loading state shown while pending; loaded nodes are never re-fetched, and returned children may carry load themselves for recursive lazy loading. Completion reports the load event {value, count}.

menu is the container; menu-item is self-closing. v switches direction (vertical default / horizontal / inline), act sets the clk value of the active item, and bg/fc customize colors.

PropMeaningApplies toExample
vDirection variantmenuv:horizontal
actActive item clkmenuact:goHome
bg / fcBackground / text colormenubg:1f2937
txTextmenu-itemtx:首页
clkClick handlermenu-itemclk:goHome
iIcon glyphmenu-itemi:🏠
disDisabledmenu-itemdis
1[row]
2 [col span:6]
3 [p v:bold 竖向菜单]
4 [menu act:goHome]
5 [menu-item tx:首页 i:🏠 clk:goHome]
6 [menu-item tx:产品 i:📦 clk:goProduct]
7 [menu-item tx:文档 i:📖 clk:goDocs]
8 [menu-item tx:设置 i:⚙️ dis]
9 [/menu]
10 [/col]
11 [col span:6]
12 [p v:bold 横向菜单]
13 [menu v:horizontal]
14 [menu-item tx:概览 clk:go1]
15 [menu-item tx:分析 clk:go2]
16 [menu-item tx:报告 clk:go3]
17 [/menu]
18 [/col]
19[/row]
Loading TokUI…
TokUI DSL · code ↔ render

Activation callback & programmatic activation: once menu declares on:"change:h", changes of the active item report {value} (item identity resolves as id > v > text); the server can activate a menu item programmatically with [upd id:m act:activate v:identity].

Resizable Panel resizable

A two-pane layout with a draggable splitter. dir controls the direction; min/max/default constrain the first pane's size. The first child node goes into the first pane; the rest go into the second. Supports fine-tuning with arrow keys.

PropMeaningExample
dirDirection (h horizontal default / v vertical)dir:v
minMinimum size (px)min:120
maxMaximum size (px)max:600
defaultInitial size (px)default:240
wOverall widthw:100%

Horizontal · Sidebar + Main — The most common IDE / admin layout: a fixed-width left pane that can be dragged wider, and a right pane that fills the rest.

1[resizable dir:h min:140 max:320 default:200]
2 [menu]
3 [menu-item tx:Home i:🏠]
4 [menu-item tx:Product i:📦]
5 [menu-item tx:Orders i:📋]
6 [menu-item tx:Settings i:⚙️ dis]
7 [/menu]
8 [card tt:"Main Content"]
9 [p v:muted Left nav is draggable; right pane fills the remaining space.]
10 [p Common in IDEs, admin panels, and mail clients.]
11 [/card]
12[/resizable]
Loading TokUI…
TokUI DSL · code ↔ render

Vertical · Editor + Terminaldir:v splits top/bottom: code or preview above, logs or console below.

1[resizable dir:v min:80 max:240 default:140]
2 [code lang:js]
3 const greet = name => "Hello, " + name;\nconsole.log(greet("TokUI"));
4 [/code]
5 [terminal status:success]
6 $ npm run dev\n✓ ready on http://localhost:3109
7 [/terminal]
8[/resizable]
Loading TokUI…
TokUI DSL · code ↔ render

Nested · Three-pane Workspaceresizable nests: outer splits horizontally, the right pane splits vertically again, yielding three regions.

1[resizable dir:h min:120 max:260 default:160]
2 [card tt:"File Tree"]
3 [list]
4 [item src/]
5 [item components/]
6 [item core/]
7 [item styles/]
8 [/list]
9 [/card]
10 [resizable dir:v min:60 max:200 default:120]
11 [card tt:Preview]
12 [p v:muted Top: rendered output or docs.]
13 [/card]
14 [card tt:Console]
15 [terminal]
16 $ build ok\n✓ dist/tokui.umd.js
17 [/terminal]
18 [/card]
19 [/resizable]
20[/resizable]
Loading TokUI…
TokUI DSL · code ↔ render

Tight Constraint · Floating Rail — When min is close to max, the first pane is nearly fixed with only fine-tuning room.

1[resizable dir:h min:120 max:160 default:140]
2 [callout t:info]
3 Fixed rail (120–160px)
4[/callout]
5[callout t:success]
6Adaptive area: drag range is tightly constrained — handy for side badges or toolbars.
7[/callout]
8[/resizable]
Loading TokUI…
TokUI DSL · code ↔ render

Scroll Area scroll-area

A content region with a fixed outer size and custom scrollbar styling. h/w set the viewport size; overflowing content scrolls.

PropMeaningExample
hHeighth:160
wWidthw:100%
idIdentifierid:myScroll
virtualVirtual scrolling (uniform row-height mode)virtual
ihRow height (px, default 36)ih:40
1[scroll-area h:180]
2 [p 第一段:滚动区域内可放任意长内容,超出部分出现自定义滚动条。]
3 [p 第二段:固定高度 180px,自动纵向滚动。]
4 [p 第三段:常用于侧边栏长列表、聊天记录区、日志面板。]
5 [p 第四段:配合 row/col 可做多栏滚动。]
6 [p 第五段:滚动到底部。]
7[/scroll-area]
Loading TokUI…
TokUI DSL · code ↔ render

Virtual scrolling & load-more: virtual mounts only the visible window plus a buffer into the DOM (uniform row-height mode — not suitable for variable-height rows); scrolling past the 80% threshold near the bottom reports the loadmore event (on:"loadmore:h", detail {}) — handy for long lists and chat-history "load more".

sidebar is a container; children are sidebar-content (main content) and sidebar-footer (footer). collapsible enables the collapse button.

PropMeaningApplies toExample
wWidth (default 260)sidebarw:240
posPosition (left/right)sidebarpos:left
collapsibleCollapsiblesidebarcollapsible
ttTitle / logo textsidebartt:控制台
bg / fcBackground / text colorsidebarbg:111827
1[sidebar tt:控制台 w:240]
2 [sidebar-content]
3 [menu]
4 [menu-item tx:仪表盘 clk:goDash]
5 [menu-item tx:用户管理 clk:goUsers]
6 [menu-item tx:系统设置 clk:goSettings]
7 [/menu]
8 [/sidebar-content]
9 [sidebar-footer]
10 [p v:muted v:sm v:center 当前用户:admin]
11 [/sidebar-footer]
12[/sidebar]
Loading TokUI…
TokUI DSL · code ↔ render

Tooltip tooltip

A lightweight hover-revealed text tip. tt is the tip content, tx is the trigger text, and pos controls the direction. It pops up on mouse enter and dismisses on leave/blur/Esc.

PropMeaningExample
ttTip texttt:这是提示
txTrigger texttx:悬停看我
posDirection (default top)pos:bottom

Variants: top / bottom / left / right.

1[p]
2[tooltip tt:上方提示 tx:悬停(上) pos:top]
3·
4[tooltip tt:下方提示 tx:悬停(下) pos:bottom]
5·
6[tooltip tt:左侧提示 tx:悬停(左) pos:left]
7·
8[tooltip tt:右侧提示 tx:悬停(右) pos:right]
9[/p]
10[p v:muted 移入触发文本即可看到提示气泡。]
11[/p]
Loading TokUI…
TokUI DSL · code ↔ render

Popover popover

A richer popup card than tooltip, supporting a title and arbitrary child content. trig switches the trigger mode (click default / hover), pos controls the direction, and w sets the panel width.

PropMeaningExample
txTrigger texttx:点击查看
ttTitlett:用户信息
posDirection (default top)pos:bottom
trigTrigger modetrig:hover
wPanel widthw:240
1[popover tt:操作菜单 tx:点击展开 pos:bottom w:240 trig:click]
2 [list plain]
3 [item 新建项目]
4 [item 导入数据]
5 [item 导出报表]
6 [/list]
7[/popover]
8[popover tt:悬浮预览 tx:悬停预览 pos:top trig:hover]
9[p 鼠标悬停即可展示富内容。[/popover]
Loading TokUI…
TokUI DSL · code ↔ render

Hover Card hover-card

hover-card is a container; children are hover-trigger (trigger area) and hover-content (pop-up content). delay controls the show delay, pos controls the direction, and the content is positioned with position:fixed to avoid clipping.

PropMeaningApplies toExample
posDirection (default bottom)hover-cardpos:right
wPop-up width (px)hover-cardw:280
delayShow delay (ms, default 300)hover-carddelay:200
1[hover-card pos:bottom w:240 delay:200]
2 [hover-trigger]
3 [a u:# tx:@TokUI v:underline]
4 [/hover-trigger]
5 [hover-content]
6 [card tt:TokUI]
7 [p v:sm 零依赖的流式 UI 描述与渲染框架。]
8 [tag tx:开源 t:success round]
9 [/card]
10 [/hover-content]
11[/hover-card]
Loading TokUI…
TokUI DSL · code ↔ render

Popconfirm popconfirm

A small confirmation popup with OK / Cancel buttons triggered on click. tt is the question text, tx the trigger button text, clk the confirm callback, t the confirm button type, and pos the direction.

PropMeaningExample
ttQuestion texttt:确定删除吗?
txTrigger button texttx:删除
clkConfirm callbackclk:onConfirm
tConfirm button type (default primary)t:danger
posDirection (default top)pos:right
ok-text / cancel-textButton textok-text:删除
1[p]
2[popconfirm tt:确定要删除这条记录吗? tx:删除 t:danger clk:onDelDelete pos:bottom ok-text:删除]
3[popconfirm tt:确认提交本次表单? tx:提交 clk:onSubmit pos:top]
4[/p]
Loading TokUI…
TokUI DSL · code ↔ render

Back to Top backtop

A back-to-top button that appears after a page or container scrolls past a threshold. t sets the threshold (default 200), container switches to in-container mode, and v sets the shape.

PropMeaningExample
tVisibility threshold (px, default 200)t:300
vShape (circle / round / square)v:round
txButton text (default )tx:顶部
sSizes:lg
containerIn-container modecontainer
bottom / rightDistance from bottom / right (px)bottom:40

backtop floats in the bottom-right corner and is only visible after scrolling. The example below uses a callout to describe its behavior.

1[callout t:tip tt:回到顶部组件]
2[p [backtop t:200 v:circle tx:]
3滚动页面超过 200px 即在右下角出现,点击平滑回到顶部。]
4[/callout]
Loading TokUI…
TokUI DSL · code ↔ render

Command Palette command

command is a container; children are command-group (group, tt title), whose items use item (or command-item — equivalent; item recommended). Built-in fuzzy search, keyboard up/down selection, and Enter to confirm.

PropMeaningApplies toExample
phSearch box placeholdercommandph:搜索命令...
clkSelect callbackcommandclk:onCommand
idIdentifier (the trigger button's data-target points to it)commandid:cmdMain
ttGroup titlecommand-grouptt:常用
txDisplay textitem / command-itemtx:新建文件
vSearch value (defaults to tx)item / command-itemv:new file
clkItem callbackitem / command-itemclk:cmdNew
shortcutShortcut hintitem / command-itemshortcut:⌘N

The palette is hidden by default and triggered by a button: the trigger uses clk:openCommand data-target:"<the command's id>", and the matching [command id:...] carries the same id. Use hotkey to opt into Cmd/Ctrl+K (only one hotkey instance per page). When an item is selected: the item-level clk handler receives { value, text }; if the command root also has clk, a root-level callback fires with { value, text, clk } (clk = the item's handler name). Clicking the panel backdrop / search box fires nothing.

1[btn tx: 打开命令面板 clk:openCommand data-target:demoCmd v:primary]
2[command ph:输入命令或搜索... clk:onCommand id:demoCmd]
3 [command-group tt:常用操作]
4 [item tx:新建文件 clk:cmdNew shortcut:⌘N]
5 [item tx:打开项目 clk:cmdOpen shortcut:⌘O]
6 [item tx:搜索替换 clk:cmdSearch shortcut:⌘F]
7 [/command-group]
8 [command-group tt:导航]
9 [item tx:跳到行 clk:cmdGoto]
10 [item tx:切换主题 clk:cmdTheme]
11 [/command-group]
12[/command]
Loading TokUI…
TokUI DSL · code ↔ render

Canvas Panel canvas

canvas is a container; children are canvas-content (content area). pos controls the dock direction, w the width, open expands it by default, and closable whether it can be closed.

PropMeaningApplies toExample
ttTitle (default Canvas)canvastt:预览
posPosition (left/right, default right)canvaspos:right
wWidth (default 400)canvasw:360
openExpand by defaultcanvasopen
closableClosable (default on)canvasclosable
txSelf-closing body textcanvastx:简单内容
1[canvas tt:实时预览 pos:right w:340 open]
2 [canvas-content]
3 [p 这是画布面板的内容区,常用于代码/设计预览。]
4 [callout t:success tt:就绪]
5 [p v:sm 面板默认展开,可点击边缘标签折叠。[/callout]
6 [/canvas-content]
7[/canvas]
Loading TokUI…
TokUI DSL · code ↔ render

Anchor anchor

Dual mode. In-page section navigation for long documents: clicking an item smooth-scrolls to its target, and scroll-spy highlights the item closest to the top while scrolling. Target elements must carry an id (e.g. [h2 id:sec-a 第一章]).

PropMeaningExample
optAnchor shorthand string target-id:title;... (double quotes required, atomic self-closing)opt:"sec-a:第一章;sec-b:第二章"
topscroll-spy activation offset (px, defaults to 12)top:20
vVariant: horizontal modev:horizontal
onchange reports {value} (target id)on:"change:h"
idElement IDid:pageAnchor

Container mode with lk children (supports nested anchors):

PropMeaningExample
hTarget element id (# prefix allowed)h:sec-a
txDisplay texttx:第一章
dDepth 1-3 (indented)d:1

After a click activation, the spy won't steal the highlight back during smooth scrolling (900ms suppression window); [upd id:x v:目标id] activates programmatically (silent).

1[anchor opt:"s1:第一章;s2:第二章"]
2[h2 id:s1 第一章]
3[p 内容……]
4[h2 id:s2 第二章]
5[p 内容……]
Loading TokUI…
TokUI DSL · code ↔ render

Clicking calls scrollIntoView for smooth scrolling. The server can highlight an item programmatically with [upd id:pageAnchor v:target-id] (silent — not reported).

1[anchor opt:"s1:第一章;s2:第二章"]
2[h2 id:s1 第一章]
3[p 内容……]
4[h2 id:s2 第二章]
5[p 内容……]
Loading TokUI…
TokUI DSL · code ↔ render

Affix affix

Container. Pins its content with position:fixed once scrolling crosses an offset (top or bottom), inserting a placeholder automatically to prevent layout jumps. Pin-state changes are reported via the change event.

PropMeaningExample
topPin to top: offset (px) from the scroll container's top edge; defaults to top:0top:8
bottomPin to bottom: offset (px) from the container's bottom edge (mutually exclusive with top)bottom:8
targetExplicit scroll container selector (auto-detects the nearest scrollable ancestor by default)target:#list
onPin-state change reports {fixed:true/false}on:"change:h"

Bottom semantics: while the element sits below the bottom line it stays pinned to the bottom, and it releases once scrolled past its original position (same as AntD offsetBottom). The scroll listener attaches to window in the capture phase, so nested scroll containers (chat panes, scroll-area) are all detected.

1[affix top:8]
2[btn tx:固定按钮 v:primary]
3[/affix]
Loading TokUI…
TokUI DSL · code ↔ render
1[affix top:8]
2[btn tx:固定按钮 v:primary]
3[/affix]
Loading TokUI…
TokUI DSL · code ↔ render

Masonry masonry

Container. A CSS-columns masonry layout: cols for a fixed column count or minw for auto columns (minimum item width — the column count adapts to the container width); gap sets the spacing. Children are balanced across columns automatically and streaming appends flow naturally. Zero JS layout computation; children get break-inside: avoid so they are never cut mid-block.

PropMeaningExample
colsFixed column count (1-6, defaults to 2)cols:3
minwAuto-column mode: minimum item width (px, wins over cols)minw:200
gapGap (px, defaults to 8)gap:10
1[masonry cols:3]
2[card tt:A]
3 [p 短内容]
4[/card]
5[card tt:B]
6 [p 这是一段比较长的内容,用来撑高这张卡片,让瀑布流高低错落的效果更明显。]
7 [p 再来一段补充说明。]
8[/card]
9[card tt:C]
10 [p 适中内容]
11 [p 第二行]
12[/card]
13[card tt:D]
14 [p ]
15[/card]
16[card tt:E]
17 [p 长内容示例]
18 [p 第二段]
19 [p 第三段]
20 [p 第四段]
21[/card]
22[card tt:F]
23 [p 适中]
24[/card]
25[card tt:G]
26 [p 瀑布流按列依次填充,卡片高度各不相同,才能看出与网格布局的区别。]
27[/card]
28[card tt:H]
29 [p ]
30[/card]
31[card tt:I]
32 [p 收尾卡片]
33 [p 内容]
34[/card]
35[/masonry]
Loading TokUI…
TokUI DSL · code ↔ render

Tour tour / tour-step

The tour container wraps a series of tour-step markers (self-closing) that walk the user through page elements step by step. Keyboard: Esc closes, ←/→ switch steps. A step without tgt shows its panel centered.

PropMeaningApplies toExample
openAuto-start once the container closestouropen
maskBackdrop mask (on by default; mask:false turns it off)tourmask:false
idIdentifier (for targeted upd control)tourid:tour1
onEvent reporting (see below)touron:"change:h,finish:h,close:h"
tgtTarget element id (may include #)tour-steptgt:"#btn-a"
ttStep titletour-steptt:第一步
txStep description (or write body text)tour-steptx:说明文字
posPanel placement (top/bottom/left/right, default bottom)tour-steppos:bottom

Events: change (step switch, detail {index,target}) / finish (completed) / close (skip · ✕ · Esc). Programmatic control: [upd id:tour1 act:open] (v optionally picks the starting step), [upd id:tour1 act:goto v:N], [upd id:tour1 act:close] — all silent, never reported.

1[tour open]
2[tour-step tt:第一步 tx:这是引导说明]
3[tour-step tt:完成 tx:无目标步骤居中显示]
4[/tour]
Loading TokUI…
TokUI DSL · code ↔ render

Imperative Confirm modal.confirm

An imperative confirm dialog — a host-side JS API, not part of the DSL — invoked directly from page code. It returns a Promise<boolean>: true on confirm, false on cancel / Esc / backdrop click. The alias TokUI.confirm(opts) is equivalent.

js
const ok = await TokUI.modal.confirm({
  tt: 'Confirm deletion',
  tx: 'Are you sure you want to delete this record?',
  t: 'danger',           // OK button type: 'danger' | 'primary' (default)
  'ok-text': 'Delete',    // defaults to i18n common.ok
  'cancel-text': 'Cancel', // defaults to i18n common.cancel
  onOk() { /* callback alongside the Promise */ },
  onCancel() {}
});
OptionMeaningDefault
ttTitlei18n modal.aria
txBody textnone (body area not rendered)
tOK button typeprimary
ok-text / cancel-textButton labelsi18n common.ok / common.cancel
onOk / onCancelCallbacks (alongside the Promise)

The overlay's aria text also comes from i18n (modal.aria), so multilingual sites need no manual handling.

When nesting container components deeply, close each container with [/type] immediately after its content to avoid rendering glitches caused by misplaced implicit closing during streaming parsing.