示例
工作区切换器
工作区页眉将切换器菜单与创建对话框结合起来:菜单用于快速切换,表单用于创建新工作区。
预览
Acme Inc
Pro plan, 8 members
Acme Inc
Northwind Labs
Personal
Create a workspace
Workspaces keep projects, members and billing separate.
Free
Pro
Enterprise
HTML
<bs:bsui-stack direction="row" gap="3" align="center" justify="space-between">
<bs:bsui-stack direction="row" gap="3" align="center">
<bs:bsui-avatar fallback="AC" alt="Acme Inc" />
<bs:bsui-stack direction="column" gap="1">
<bs:bsui-text content="Acme Inc" variant="label" tag="span" />
<bs:bsui-text content="Pro plan, 8 members" variant="caption" tag="span" />
</bs:bsui-stack>
</bs:bsui-stack>
<bs:bsui-stack direction="row" gap="2" align="center">
<bs:bsui-menu>
<bs:bsui-menu-trigger trigger_label="Switch" trigger_variant="outline" />
<bs:bsui-menu-popup>
<bs:bsui-menu-item label="Acme Inc" />
<bs:bsui-menu-item label="Northwind Labs" />
<bs:bsui-menu-item label="Personal" />
</bs:bsui-menu-popup>
</bs:bsui-menu>
<bs:bsui-dialog>
<bs:bsui-dialog-trigger trigger_label="New workspace" />
<bs:bsui-dialog-backdrop />
<bs:bsui-dialog-popup>
<bs:bsui-dialog-header>
<bs:bsui-dialog-title content="Create a workspace" />
<bs:bsui-dialog-description content="Workspaces keep projects, members and billing separate." />
</bs:bsui-dialog-header>
<bs:bsui-dialog-content>
<bs:bsui-stack direction="column" gap="4" align="stretch">
<bs:bsui-field>
<bs:bsui-field-label text="Name" />
<bs:bsui-input name="workspace_name" placeholder="Acme Inc" />
</bs:bsui-field>
<bs:bsui-field>
<bs:bsui-field-label text="Plan" />
<bs:bsui-select name="plan" defaultValue="free" placeholder="Pick a plan">
<bs:bsui-select-trigger />
<bs:bsui-select-popup>
<bs:bsui-select-option value="free" label="Free" />
<bs:bsui-select-option value="pro" label="Pro" />
<bs:bsui-select-option value="enterprise" label="Enterprise" />
</bs:bsui-select-popup>
</bs:bsui-select>
<bs:bsui-field-description text="Free includes three projects and two members." />
</bs:bsui-field>
</bs:bsui-stack>
</bs:bsui-dialog-content>
<bs:bsui-dialog-footer>
<bs:bsui-dialog-close variant="outline" label="Cancel" />
<bs:bsui-dialog-close variant="default" label="Create workspace" />
</bs:bsui-dialog-footer>
</bs:bsui-dialog-popup>
</bs:bsui-dialog>
</bs:bsui-stack>
</bs:bsui-stack>工作原理
菜单 store 会从上下文列出工作区;切换时会写入当前活动 ID,页眉中的身份信息会据此重新渲染。对话框表单会验证名称;创建时会将工作区添加到同一个 store,然后切换至该工作区。
此页面上的每项行为都是 WordPress Interactivity API:每个组件都会注册自己的 store,在服务器渲染的上下文中初始化状态,并通过上方标记中的指令绑定事件。没有针对单个页面的 JavaScript。