iter(g181): 控件高度统一三档
This commit is contained in:
@@ -5,7 +5,7 @@ import type { ButtonProps } from './types.js';
|
||||
export function button(props: ButtonProps): HTMLElement {
|
||||
return h(
|
||||
'button',
|
||||
{ class: `ua-btn ua-btn-${props.variant ?? 'primary'}`, type: props.type ?? 'button', disabled: props.disabled, onClick: props.onClick }, // 缺省 button:表单内不隐式提交
|
||||
{ class: `ua-btn ua-btn-${props.variant ?? 'primary'}${props.size && props.size !== 'md' ? ` is-${props.size}` : ''}`, type: props.type ?? 'button', disabled: props.disabled, onClick: props.onClick }, // 缺省 button:表单内不隐式提交
|
||||
props.label,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export function inputNumber(props: InputNumberProps): HTMLElement {
|
||||
const clamp = (v: number): number => Math.min(max, Math.max(min, v)); // 任何来源的值都夹回合法区间
|
||||
const quantize = (n: number): number => (props.precision === undefined ? n : Number(n.toFixed(props.precision))); // precision 归一(顺带消除步进浮点尾差)
|
||||
const emit = (v: number): void => { const n = quantize(clamp(v)); props.value(n); if (props.onChange) props.onChange(n); }; // 写回信号并回调
|
||||
const input = h('input', { class: 'ua-input ua-input-number-field', inputmode: 'decimal', disabled: props.disabled, 'aria-label': '数字输入' }) as HTMLInputElement;
|
||||
const input = h('input', { class: `ua-input ua-input-number-field${props.size && props.size !== 'md' ? ` is-${props.size}` : ''}`, inputmode: 'decimal', disabled: props.disabled, 'aria-label': '数字输入' }) as HTMLInputElement;
|
||||
const sync = (): void => { const text = props.precision === undefined ? String(props.value()) : props.value().toFixed(props.precision); if (input.value !== text) input.value = text; }; // 外部变化写回输入框(precision 定长显示)
|
||||
effect(sync);
|
||||
input.addEventListener('change', () => { const n = parseFloat(input.value); if (Number.isNaN(n)) sync(); else emit(n); }); // 非法输入回滚当前值
|
||||
|
||||
@@ -36,7 +36,7 @@ export function select(props: SelectProps): HTMLElement {
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: 'ua-select-trigger',
|
||||
class: `ua-select-trigger${props.size && props.size !== 'md' ? ` is-${props.size}` : ''}`,
|
||||
'aria-haspopup': 'listbox',
|
||||
'aria-expanded': () => String(open()),
|
||||
disabled: props.disabled, // 布尔或信号禁用,h() 直接透传(原生 button 拦截点击)
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { TextFieldProps } from './types.js';
|
||||
|
||||
/*** 文本输入:value 信号双向绑定,disabled 支持布尔或信号禁用,onInput 为输入回调;prefix/suffix 包附加组,clearable 一键清空,maxCount 显示字数统计 ***/
|
||||
export function textField(props: TextFieldProps): HTMLElement {
|
||||
const el = h('input', { class: 'ua-input', placeholder: props.placeholder ?? '', disabled: props.disabled }) as HTMLInputElement; // false/undefined 移除属性,Signal 走响应式
|
||||
const el = h('input', { class: `ua-input${props.size && props.size !== 'md' ? ` is-${props.size}` : ''}`, placeholder: props.placeholder ?? '', disabled: props.disabled }) as HTMLInputElement; // false/undefined 移除属性,Signal 走响应式
|
||||
if (props.value) {
|
||||
const signal = props.value;
|
||||
el.addEventListener('input', () => signal(el.value)); // 用户输入写回信号
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface PopoverProps {
|
||||
|
||||
/*** 按钮入参 ***/
|
||||
export interface ButtonProps {
|
||||
size?: 'sm' | 'md' | 'lg'; // 高度档位:走 --ua-control-h-* 三档;缺省 md
|
||||
label: string; // 按钮文案
|
||||
variant?: 'primary' | 'ghost' | 'danger'; // 视觉强度;缺省 primary
|
||||
type?: 'button' | 'submit' | 'reset'; // 原生类型;缺省 button(表单内不会意外触发提交)
|
||||
@@ -30,6 +31,7 @@ export interface ButtonProps {
|
||||
|
||||
/*** 文本输入入参 ***/
|
||||
export interface TextFieldProps {
|
||||
size?: 'sm' | 'md' | 'lg'; // 高度档位:走 --ua-control-h-* 三档;缺省 md
|
||||
placeholder?: string; // 占位文案
|
||||
value?: Signal<string>; // 双向绑定的信号
|
||||
disabled?: boolean | Signal<boolean>; // 禁用态:布尔直接置位,传信号则动态同步
|
||||
@@ -108,6 +110,7 @@ export interface SwitchProps {
|
||||
|
||||
/*** 下拉选择入参 ***/
|
||||
export interface SelectProps {
|
||||
size?: 'sm' | 'md' | 'lg'; // 高度档位:走 --ua-control-h-* 三档;缺省 md
|
||||
options: OptionItem[]; // 选项列表
|
||||
value?: Signal<string>; // 选中值信号,双向绑定
|
||||
placeholder?: string; // 未选中时的占位项文案
|
||||
@@ -203,6 +206,7 @@ export interface TextareaProps {
|
||||
|
||||
/*** 数字输入入参 ***/
|
||||
export interface InputNumberProps {
|
||||
size?: 'sm' | 'md' | 'lg'; // 高度档位:走 --ua-control-h-* 三档;缺省 md
|
||||
value: Signal<number>; // 当前值信号,双向绑定(按钮/键盘写回、外部赋值同步)
|
||||
min?: number; // 最小值;缺省无下限
|
||||
max?: number; // 最大值;缺省无上限
|
||||
|
||||
@@ -214,6 +214,11 @@
|
||||
"t": "() => void",
|
||||
"k": 1,
|
||||
"d": "点击回调"
|
||||
},
|
||||
{
|
||||
"n": "size",
|
||||
"t": "'sm' | 'md' | 'lg'",
|
||||
"d": "高度档位:sm 紧凑 / md 默认 / lg 大触控目标,走 --ua-control-h-* 三档;缺省 md"
|
||||
}
|
||||
],
|
||||
"example": "button({ label: '提交', variant: 'primary', onClick: () => console.log('clicked') })",
|
||||
@@ -270,6 +275,11 @@
|
||||
"n": "maxCount",
|
||||
"t": "number",
|
||||
"d": "字数上限:同时设原生 maxlength,并在输入框内侧显示实时计数;缺省不限"
|
||||
},
|
||||
{
|
||||
"n": "size",
|
||||
"t": "'sm' | 'md' | 'lg'",
|
||||
"d": "高度档位:sm 紧凑 / md 默认 / lg 大触控目标,走 --ua-control-h-* 三档;缺省 md"
|
||||
}
|
||||
],
|
||||
"example": "const name = signal(''); const el = textField({ value: name, placeholder: '输入名字…', onInput: (v) => console.log(v) })",
|
||||
@@ -333,6 +343,11 @@
|
||||
"n": "suffix",
|
||||
"t": "string | HTMLElement",
|
||||
"d": "后置附加块(textField/inputNumber 在输入框内侧后、textarea 在下方);缺省不渲染"
|
||||
},
|
||||
{
|
||||
"n": "size",
|
||||
"t": "'sm' | 'md' | 'lg'",
|
||||
"d": "高度档位:sm 紧凑 / md 默认 / lg 大触控目标,走 --ua-control-h-* 三档;缺省 md"
|
||||
}
|
||||
],
|
||||
"example": "const qty = signal(1); const el = inputNumber({ value: qty, min: 1, max: 99, onChange: (v) => console.log(v) })",
|
||||
@@ -607,6 +622,11 @@
|
||||
"t": "(value: string) => void",
|
||||
"k": 1,
|
||||
"d": "选中回调"
|
||||
},
|
||||
{
|
||||
"n": "size",
|
||||
"t": "'sm' | 'md' | 'lg'",
|
||||
"d": "高度档位:sm 紧凑 / md 默认 / lg 大触控目标,走 --ua-control-h-* 三档;缺省 md"
|
||||
}
|
||||
],
|
||||
"example": "const city = signal(''); select({ options: [{ value: 'bj', label: '北京' }], value: city, placeholder: '选择城市…' })",
|
||||
|
||||
+29
-7
@@ -6,6 +6,27 @@
|
||||
outline: 2px solid var(--ua-color-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
/* —— 控件高度三档:所有可交互控件统一走 --ua-control-h-*,size 档只改高度 —— */
|
||||
.ua-btn,
|
||||
.ua-input,
|
||||
.ua-select-trigger,
|
||||
.ua-input-number-field {
|
||||
box-sizing: border-box;
|
||||
height: var(--ua-control-h-md);
|
||||
}
|
||||
.ua-btn.is-sm,
|
||||
.ua-input.is-sm,
|
||||
.ua-select-trigger.is-sm,
|
||||
.ua-input-number-field.is-sm {
|
||||
height: var(--ua-control-h-sm);
|
||||
}
|
||||
.ua-btn.is-lg,
|
||||
.ua-input.is-lg,
|
||||
.ua-select-trigger.is-lg,
|
||||
.ua-input-number-field.is-lg {
|
||||
height: var(--ua-control-h-lg);
|
||||
}
|
||||
|
||||
.ua-btn {
|
||||
padding: var(--ua-space-15) var(--ua-space-35);
|
||||
border: 1px solid var(--ua-color-accent);
|
||||
@@ -913,6 +934,7 @@ body.ua-col-resizing {
|
||||
gap: var(--ua-space-1);
|
||||
}
|
||||
.ua-input-number .ua-btn {
|
||||
height: auto; /* 步进器是图标按钮:不吃控件统一高度 */
|
||||
padding: 5px var(--ua-space-3); /* 收窄为步进按钮 */
|
||||
line-height: 1.4;
|
||||
}
|
||||
@@ -1311,7 +1333,7 @@ button.ua-step-dot:hover {
|
||||
}
|
||||
.ua-page-btn {
|
||||
min-width: 28px;
|
||||
height: 28px;
|
||||
height: var(--ua-control-h-sm);
|
||||
padding: 0 var(--ua-space-2);
|
||||
border: 1px solid var(--ua-color-border);
|
||||
border-radius: var(--ua-radius-sm);
|
||||
@@ -1380,7 +1402,7 @@ button.ua-step-dot:hover {
|
||||
}
|
||||
.ua-skeleton-circle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
height: var(--ua-control-h-lg);
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -2554,7 +2576,7 @@ button.ua-step-dot:hover {
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
height: var(--ua-control-h-sm);
|
||||
border: 1px solid var(--ua-color-border);
|
||||
border-radius: 50%;
|
||||
background: var(--ua-color-bg);
|
||||
@@ -2737,7 +2759,7 @@ button.ua-step-dot:hover {
|
||||
}
|
||||
.ua-upload-thumb {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
height: var(--ua-control-h-sm);
|
||||
object-fit: cover;
|
||||
border: 1px solid var(--ua-color-border);
|
||||
border-radius: var(--ua-radius-sm);
|
||||
@@ -2869,7 +2891,7 @@ button.ua-step-dot:hover {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
height: var(--ua-control-h-lg);
|
||||
border-radius: 50%;
|
||||
font-size: var(--ua-font-size-lg);
|
||||
font-weight: 700;
|
||||
@@ -3364,10 +3386,10 @@ button.ua-step-dot:hover {
|
||||
margin-top: var(--ua-space-05);
|
||||
}
|
||||
.ua-datepicker-blank {
|
||||
height: 28px;
|
||||
height: var(--ua-control-h-sm);
|
||||
}
|
||||
.ua-datepicker-day {
|
||||
height: 28px;
|
||||
height: var(--ua-control-h-sm);
|
||||
font-size: var(--ua-font-size-sm);
|
||||
color: var(--ua-color-text);
|
||||
background: transparent;
|
||||
|
||||
Reference in New Issue
Block a user