Resizable
支持多面板比例分配、折叠停靠、RTL 布局与嵌套分栏的可调整面板组件。
支持键盘操作、约束折叠与嵌套方向的可调整分栏组件。本页示例使用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-hero"
class="h-56 w-full max-w-md rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">One</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-nested"
class="h-full w-full min-h-0"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Two</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Three</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#shadcn-resizable-hero');
const nestedRoot = document.querySelector(
'#shadcn-resizable-nested'
);
setElementProps(root, {
defaultSizes: [50, 50],
constraints: [
{ min: 20, max: 75, collapsible: true },
{ min: 25 },
],
styleProfile: 'rhea',
});
setElementProps(nestedRoot, {
orientation: 'vertical',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
styleProfile: 'rhea',
});
root
.querySelectorAll(':scope > proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
root.querySelector(':scope > proto-ui-shadcn-resizable-handle'),
{ index: 0, withHandle: true, styleProfile: 'rhea' }
);
nestedRoot
.querySelectorAll(':scope > proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
nestedRoot.querySelector(
':scope > proto-ui-shadcn-resizable-handle'
),
{ index: 0, withHandle: true, styleProfile: 'rhea' }
);
</script>将于 0.3.0-rc.1 及后续版本中提供。可直接从 @proto.ui/prototypes-shadcn/resizable 导入原型并使用目标宿主 Adapter 适配:
import { resizableRoot, resizablePanel, resizableHandle,} from '@proto.ui/prototypes-shadcn/resizable';import { ShadcnResizableRoot, ShadcnResizablePanel, ShadcnResizableHandle,} from '../proto-ui/components/react';
export function Example() { return ( <ShadcnResizableRoot orientation="horizontal" defaultSizes={[50, 50]} className="h-56 max-w-md rounded-lg border border-border overflow-hidden" > <ShadcnResizablePanel index={0}>One</ShadcnResizablePanel> <ShadcnResizableHandle index={0} withHandle /> <ShadcnResizablePanel index={1}>Two</ShadcnResizablePanel> </ShadcnResizableRoot> );}Proto UI 中的 resizableRoot、resizablePanel 与 resizableHandle 分别对应上游 shadcn/ui 的 ResizablePanelGroup、ResizablePanel 与 ResizableHandle:
ResizableRoot├── ResizablePanel (index: 0)├── ResizableHandle (index: 0)└── ResizablePanel (index: 1)- 布局包含
N个Panel(index: 0..N-1)与N - 1个Handle(index: 0..N-2)。每个Handle只调整其相邻的两个面板,保持这两个面板的总比例及其他面板尺寸不变。 Panel将无量纲百分比暴露到静态 CSS 变量--pui-size,由flex-basis规则驱动布局;拖动距离按面板自身实际总长度归一化,不计入分隔柄宽度。constraints可按面板索引配置min(默认0)、max(默认100)、collapsible(默认false)和collapsedSize(默认0);传入sizes进入受控模式并监听sizesChange/sizesCommit。- 键盘支持方向键、
Shift10 倍步进、Home/End与Enter折叠切换;每个Handle的默认无障碍名称为Resize panels。
将 orientation 设为 "vertical" 以垂直调整上下两个面板。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-vertical"
class="h-56 w-full max-w-md rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Header</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Content</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#shadcn-resizable-vertical');
setElementProps(root, {
orientation: 'vertical',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
styleProfile: 'rhea',
});
root
.querySelectorAll('proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
root.querySelector('proto-ui-shadcn-resizable-handle'),
{ index: 0, styleProfile: 'rhea' }
);
</script>在 Handle 上启用 withHandle 显示可抓握的装饰柄;未设置时渲染极简 1px 分隔线。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex w-full max-w-md flex-col gap-4">
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-with-handle"
class="h-40 w-full max-w-md rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Sidebar</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Content</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-hairline"
class="h-32 w-full max-w-md rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Left</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Right</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const withGrip = document.querySelector(
'#shadcn-resizable-with-handle'
);
setElementProps(withGrip, {
defaultSizes: [25, 75],
constraints: [{ min: 15 }, { min: 30 }],
styleProfile: 'rhea',
});
withGrip
.querySelectorAll('proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
withGrip
.querySelectorAll('proto-ui-shadcn-resizable-handle')
.forEach((handle, index) =>
setElementProps(handle, {
index,
withHandle: true,
styleProfile: 'rhea',
})
);
const hairline = document.querySelector(
'#shadcn-resizable-hairline'
);
setElementProps(hairline, {
defaultSizes: [50, 50],
constraints: [{ min: 20 }, { min: 20 }],
styleProfile: 'rhea',
});
hairline
.querySelectorAll('proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
hairline.querySelector('proto-ui-shadcn-resizable-handle'),
{ index: 0, withHandle: false, styleProfile: 'rhea' }
);
</script>从右到左(RTL)
Section titled “从右到左(RTL)”在 Root 上设置 direction="rtl" 以镜像面板排布与左右方向键的增减语义。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-rtl"
class="h-56 w-full max-w-md rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">واحد</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-rtl-nested"
class="h-full w-full min-h-0"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">اثنان</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">ثلاثة</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#shadcn-resizable-rtl');
const nestedRoot = document.querySelector(
'#shadcn-resizable-rtl-nested'
);
setElementProps(root, {
direction: 'rtl',
defaultSizes: [50, 50],
constraints: [{ min: 20 }, { min: 20 }],
styleProfile: 'rhea',
});
setElementProps(nestedRoot, {
orientation: 'vertical',
direction: 'rtl',
defaultSizes: [25, 75],
constraints: [{ min: 20 }, { min: 25 }],
styleProfile: 'rhea',
});
root
.querySelectorAll(':scope > proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
root.querySelector(':scope > proto-ui-shadcn-resizable-handle'),
{ index: 0, withHandle: true, styleProfile: 'rhea' }
);
nestedRoot
.querySelectorAll(':scope > proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
setElementProps(
nestedRoot.querySelector(
':scope > proto-ui-shadcn-resizable-handle'
),
{ index: 0, withHandle: true, styleProfile: 'rhea' }
);
</script>多面板与折叠
Section titled “多面板与折叠”通过 defaultSizes 和 constraints 组合三栏工作区;聚焦首个分隔柄并按 Enter 可折叠或展开左侧栏。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-shadcn-resizable-root
id="shadcn-resizable-collapsible"
class="h-56 w-full max-w-2xl rounded-lg border border-border bg-background overflow-hidden"
>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Sidebar</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Editor</span>
</div>
</proto-ui-shadcn-resizable-panel>
<proto-ui-shadcn-resizable-handle></proto-ui-shadcn-resizable-handle>
<proto-ui-shadcn-resizable-panel>
<div class="flex h-full items-center justify-center p-6">
<span class="font-semibold text-sm">Inspector</span>
</div>
</proto-ui-shadcn-resizable-panel>
</proto-ui-shadcn-resizable-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector(
'#shadcn-resizable-collapsible'
);
setElementProps(root, {
defaultSizes: [25, 50, 25],
constraints: [
{ min: 15, max: 35, collapsible: true },
{ min: 30 },
{ min: 15, max: 35 },
],
styleProfile: 'rhea',
});
root
.querySelectorAll('proto-ui-shadcn-resizable-panel')
.forEach((panel, index) =>
setElementProps(panel, { index, styleProfile: 'rhea' })
);
root
.querySelectorAll('proto-ui-shadcn-resizable-handle')
.forEach((handle, index) =>
setElementProps(handle, {
index,
withHandle: true,
styleProfile: 'rhea',
})
);
</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' |
styleProfile | ShadcnStyleId | 'new-york-v4' |
Panel 与 Handle
Section titled “Panel 与 Handle”| 属性 | 类型 | 默认值 |
|---|---|---|
Panel.index | number | 0 |
Panel.styleProfile | ShadcnStyleId | 'new-york-v4' |
Handle.index | number | 0 |
Handle.withHandle | boolean | false |
Handle.styleProfile | ShadcnStyleId | 'new-york-v4' |
- 暴露状态:Root 暴露
value与sizes;Panel 暴露size;Handle 暴露value、focusVisible与disabled。 - 事件:Root 触发
sizesChange/sizesCommit(载荷{ sizes })与双面板兼容事件valueChange/valueCommit(载荷{ value })。取消拖拽不会触发*Commit。 - 方法:Root 暴露
requestResize(index, next, commit?)、requestSizes(next, commit?)、requestValue(next, commit?)与cancelResize()。