iter(g09): 新增 descriptions 描述列表组件

This commit is contained in:
HIsheR
2026-10-26 10:23:22 +08:00
parent 086831d474
commit d8d45fcac0
12 changed files with 268 additions and 12 deletions
+21
View File
@@ -0,0 +1,21 @@
import { h } from '@ui-arch/frame';
import type { DescriptionItem, DescriptionsProps } from './types.js';
/*** 单个描述项:字段名 + 字段值,span 控制跨列(超出列数时按整行处理) ***/
function cell(item: DescriptionItem, column: number): HTMLElement {
const cellEl = h('div', { class: 'ua-desc-item' },
h('div', { class: 'ua-desc-label' }, item.label),
h('div', { class: 'ua-desc-value' }, item.value));
cellEl.style.gridColumn = `span ${Math.min(item.span ?? 1, column)}`; // 跨列不越界
return cellEl;
}
/*** 描述列表:label:value 两栏网格,column 定桌面列数,窄屏由样式表降到单列;bordered 走表格形态 ***/
export function descriptions(props: DescriptionsProps): HTMLElement {
const column = props.column ?? 3;
const grid = h('div', { class: `ua-desc ua-desc-${props.size ?? 'md'}${props.bordered ? ' is-bordered' : ''}` },
...props.items.map((item) => cell(item, column)));
grid.style.setProperty('--ua-desc-col', String(column)); // 列数交给 CSS 变量,媒体查询可在窄屏覆盖
if (!props.title) return grid;
return h('div', { class: 'ua-desc-wrap' }, h('div', { class: 'ua-desc-title' }, props.title), grid);
}