Resizable
采用 Duostrap 经典灰阶渐变、斜切高光与 #52a8ec 焦点光晕的可调整分栏组件。
基于 Base 语义构建的 Duostrap 扩展分栏组件:分隔柄采用经典 #fff → #e6e6e6 垂直渐变、内嵌高光边框、可选凹刻抓握柄与 #52a8ec 蓝色焦点光晕,完整支持多面板比例分配、折叠停靠、RTL 与嵌套布局。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-hero"
class="h-56 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">One</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-nested"
class="h-full w-full min-h-0"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Two</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Three</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#duostrap-resizable-hero');
const nestedRoot = document.querySelector(
'#duostrap-resizable-nested'
);
setElementProps(root, {
defaultSizes: [50, 50],
constraints: [
{ min: 20, max: 75, collapsible: true },
{ min: 25 },
],
});
setElementProps(nestedRoot, {
orientation: 'vertical',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
});
root
.querySelectorAll(':scope > proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
root.querySelector(
':scope > proto-ui-duostrap-resizable-handle'
),
{ index: 0, withHandle: true }
);
nestedRoot
.querySelectorAll(':scope > proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
nestedRoot.querySelector(
':scope > proto-ui-duostrap-resizable-handle'
),
{ index: 0, withHandle: true }
);
</script>将于 0.3.0-rc.1 及后续版本中提供。可直接从 @proto.ui/prototypes-duostrap/resizable 导入原型并适配到目标宿主:
import { resizableRoot, resizablePanel, resizableHandle,} from '@proto.ui/prototypes-duostrap/resizable';import { DuostrapResizableRoot, DuostrapResizablePanel, DuostrapResizableHandle,} from '../proto-ui/components/react';
export function Example() { return ( <DuostrapResizableRoot defaultSizes={[50, 50]} className="h-56 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden" > <DuostrapResizablePanel index={0}>One</DuostrapResizablePanel> <DuostrapResizableHandle index={0} withHandle /> <DuostrapResizablePanel index={1}>Two</DuostrapResizablePanel> </DuostrapResizableRoot> );}DuostrapResizableRoot├── DuostrapResizablePanel (index: 0)├── DuostrapResizableHandle (index: 0, withHandle?)└── DuostrapResizablePanel (index: 1)- 多面板编号:
N个Panel使用index: 0..N-1,N - 1个Handle使用index: 0..N-2。每个分隔柄只调整相邻两个面板,并默认提供无障碍名称Resize panels。 - 视觉与交互:分隔柄在水平/垂直布局下自动切换
ew-resize/ns-resize光标;键盘聚焦时呈现 Duostrap 经典的#52a8ec外发光;禁用时切换为平铺#e6e6e6与opacity-65。 - 约束与受控:通过
constraints按索引配置min、max、collapsible与collapsedSize;传入sizes进入受控模式并响应sizesChange/sizesCommit。
将 orientation 设为 "vertical" 以垂直调整上下两个面板。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-vertical"
class="h-56 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Header</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Content</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector(
'#duostrap-resizable-vertical'
);
setElementProps(root, {
orientation: 'vertical',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
});
root
.querySelectorAll('proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
root.querySelector('proto-ui-duostrap-resizable-handle'),
{ index: 0 }
);
</script>在 Handle 上设置 withHandle 显示经典斜切抓握块,或省略以使用 6px 渐变分隔条。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex w-full max-w-md flex-col gap-4">
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-with-handle"
class="h-40 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Sidebar</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Content</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-hairline"
class="h-32 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Left</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Right</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const withGrip = document.querySelector(
'#duostrap-resizable-with-handle'
);
setElementProps(withGrip, {
defaultSizes: [25, 75],
constraints: [{ min: 15 }, { min: 30 }],
});
withGrip
.querySelectorAll('proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
withGrip
.querySelectorAll('proto-ui-duostrap-resizable-handle')
.forEach((handle, index) =>
setElementProps(handle, { index, withHandle: true })
);
const hairline = document.querySelector(
'#duostrap-resizable-hairline'
);
setElementProps(hairline, {
defaultSizes: [50, 50],
constraints: [{ min: 20 }, { min: 20 }],
});
hairline
.querySelectorAll('proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
hairline.querySelector('proto-ui-duostrap-resizable-handle'),
{ index: 0, withHandle: false }
);
</script>从右到左(RTL)
Section titled “从右到左(RTL)”设置 direction="rtl" 以适配从右到左的布局和方向键语义。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-rtl"
class="h-56 w-full max-w-md rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">واحد</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-rtl-nested"
class="h-full w-full min-h-0"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">اثنان</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">ثلاثة</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#duostrap-resizable-rtl');
const nestedRoot = document.querySelector(
'#duostrap-resizable-rtl-nested'
);
setElementProps(root, {
direction: 'rtl',
defaultSizes: [50, 50],
constraints: [{ min: 20 }, { min: 20 }],
});
setElementProps(nestedRoot, {
orientation: 'vertical',
direction: 'rtl',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
});
root
.querySelectorAll(':scope > proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
root.querySelector(
':scope > proto-ui-duostrap-resizable-handle'
),
{ index: 0, withHandle: true }
);
nestedRoot
.querySelectorAll(':scope > proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
setElementProps(
nestedRoot.querySelector(
':scope > proto-ui-duostrap-resizable-handle'
),
{ index: 0, withHandle: true }
);
</script>多面板与折叠
Section titled “多面板与折叠”组合三个面板并允许首个面板折叠;聚焦第一个分隔柄后按 Enter 可切换展开/折叠。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-resizable-root
id="duostrap-resizable-collapsible"
class="h-56 w-full max-w-2xl rounded-[4px] border border-[#ccc] bg-background shadow-[0_1px_3px_rgb(0_0_0/5.5%)] overflow-hidden"
>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Sidebar</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Editor</span>
</div>
</proto-ui-duostrap-resizable-panel>
<proto-ui-duostrap-resizable-handle></proto-ui-duostrap-resizable-handle>
<proto-ui-duostrap-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Inspector</span>
</div>
</proto-ui-duostrap-resizable-panel>
</proto-ui-duostrap-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector(
'#duostrap-resizable-collapsible'
);
setElementProps(root, {
defaultSizes: [25, 50, 25],
constraints: [
{ min: 15, max: 35, collapsible: true },
{ min: 30 },
{ min: 15, max: 35 },
],
});
root
.querySelectorAll('proto-ui-duostrap-resizable-panel')
.forEach((panel, index) => setElementProps(panel, { index }));
root
.querySelectorAll('proto-ui-duostrap-resizable-handle')
.forEach((handle, index) =>
setElementProps(handle, { index, withHandle: true })
);
</script>| 属性 | 类型 | 默认值 |
|---|---|---|
sizes | readonly number[] | — |
defaultSizes | readonly number[] | — |
constraints | readonly ResizablePanelConstraint[] | [] |
value | number | — |
defaultValue | number | 50 |
min | number | 10 |
max | number | 90 |
step | number | 1 |
collapsible | boolean | false |
disabled | boolean | false |
readOnly | boolean | false |
orientation | 'horizontal' 'vertical' | 'horizontal' |
direction | 'ltr' 'rtl' | 'ltr' |
Panel 与 Handle
Section titled “Panel 与 Handle”| 属性 | 类型 | 默认值 |
|---|---|---|
Panel.index | number | 0 |
Handle.index | number | 0 |
Handle.withHandle | boolean | false |
- 暴露状态:Root 暴露
value、sizes;Panel 暴露size;Handle 暴露value、focusVisible、disabled。 - 事件与方法:Root 触发
sizesChange/sizesCommit/valueChange/valueCommit,并暴露requestResize(index, next, commit?)、requestSizes(next, commit?)、requestValue(next, commit?)与cancelResize()。