控件几何统一:字段不再被 flex 拉伸、表单容器独占主尺寸档位、多行文本按 --ctl-h 倒推 padding、数字框去 UA spinner、裸 select 补主题化箭头、密钥眼睛贴回右缘
parent
ca73bda68f
commit
8614360ab7
|
|
@ -82,12 +82,12 @@ export function SecretInput({
|
|||
<input id={id} value={value} type={shown ? 'text' : 'password'} placeholder={placeholder}
|
||||
autoComplete={autocomplete} maxLength={maxLength} disabled={disabled}
|
||||
aria-describedby={failed ? `${id || 'secret'}-hint` : undefined}
|
||||
className="pr-[62px]"
|
||||
className="pr-[34px]"
|
||||
onChange={(e) => onChange?.(e.target.value)} {...rest} />
|
||||
<button type="button" aria-label={hint} aria-pressed={shown} title={hint} disabled={disabled}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={reveal}
|
||||
className={cn('absolute right-[34px] top-1/2 -translate-y-1/2 w-[26px] h-[26px] p-0 grid place-items-center',
|
||||
className={cn('absolute right-[6px] top-1/2 -translate-y-1/2 w-[22px] h-[22px] p-0 grid place-items-center',
|
||||
'border rounded-[6px] bg-raise text-ink-3 border-line hover:text-ink hover:border-line-strong',
|
||||
shown && 'text-accent-bright border-accent-line bg-accent-tint-2')}>
|
||||
<EyeIcon shown={shown} loading={loading} />
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'add
|
|||
export type ButtonSize = 'sm' | 'md' | 'lg'
|
||||
|
||||
const BASE = 'inline-flex items-center justify-center gap-1.5 rounded-control border border-transparent '
|
||||
+ 'font-semibold whitespace-nowrap shrink-0 select-none h-(--ctl-h) px-[13px] text-[11px] leading-[1.2] '
|
||||
+ 'font-semibold whitespace-nowrap shrink-0 select-none h-(--ctl-h) px-[13px] text-caption leading-[1.2] '
|
||||
+ 'transition-[background,border-color,color,filter] duration-150 '
|
||||
+ 'disabled:opacity-35 disabled:cursor-not-allowed'
|
||||
|
||||
|
|
@ -32,9 +32,9 @@ const VARIANTS: Record<ButtonVariant, string> = {
|
|||
outline: 'bg-transparent text-ink-2 border-line-strong hover:not-disabled:bg-hover',
|
||||
ghost: 'bg-transparent text-ink-2 border-line-strong rounded-[7px] px-[9px] text-tiny h-(--ctl-h-md) '
|
||||
+ 'hover:not-disabled:border-line-bright hover:not-disabled:bg-hover',
|
||||
add: 'bg-accent-fill text-on-accent rounded-[8px] px-[10px] text-[11px] h-(--ctl-h-md) min-w-(--ctl-h-md) shadow-raise '
|
||||
add: 'bg-accent-fill text-on-accent rounded-[8px] px-[10px] text-caption h-(--ctl-h-md) min-w-(--ctl-h-md) shadow-raise '
|
||||
+ 'hover:not-disabled:brightness-[1.09] active:not-disabled:translate-y-px',
|
||||
del: 'bg-danger-tint-2 text-danger-bright border-danger-line rounded-[8px] px-[10px] text-[11px] h-(--ctl-h-md) min-w-(--ctl-h-md) '
|
||||
del: 'bg-danger-tint-2 text-danger-bright border-danger-line rounded-[8px] px-[10px] text-caption h-(--ctl-h-md) min-w-(--ctl-h-md) '
|
||||
+ 'hover:not-disabled:bg-danger hover:not-disabled:border-danger hover:not-disabled:text-danger-ink',
|
||||
link: 'border-transparent bg-transparent text-success text-body px-0 h-auto min-h-(--ctl-h-md) '
|
||||
+ 'hover:not-disabled:underline disabled:opacity-40'
|
||||
|
|
|
|||
|
|
@ -17,11 +17,17 @@ import { cn } from '../../lib/cn'
|
|||
*/
|
||||
|
||||
const LABEL = 'flex flex-row items-center gap-1.5 m-0 text-muted text-tiny tracking-[.3px] whitespace-nowrap'
|
||||
/** 控件吃满标签右侧宽度;标签文字本身不拉伸(否则被挤成两行) */
|
||||
/** 字段行内标签(标签在左):文字本身不拉伸,否则被挤成两行 */
|
||||
const LABEL_CHILD = '[&>label]:flex [&>label]:flex-row [&>label]:items-center [&>label]:gap-1.5 [&>label]:m-0 '
|
||||
+ '[&>label]:text-muted [&>label]:text-tiny [&>label]:tracking-[.3px] [&>label]:whitespace-nowrap'
|
||||
|
||||
const FIELD_INNER = '[&>*]:min-w-0 [&>*]:flex-1 [&_span:first-child]:flex-none [&_input[type=checkbox]]:flex-none [&_input[type=checkbox]]:w-auto [&_input[type=radio]]:flex-none'
|
||||
/**
|
||||
* 字段内部的排布:控件的宽度靠 base.css 的 w-full + flex 收缩填满标签右侧,
|
||||
* **不给 flex-1**。因为 <FormRow stack> 会把字段翻成纵向 flex,
|
||||
* flex-1 的 flex-basis:0% 会接管高度——同一抽屉里 input 被拉到 46px、
|
||||
* 旁边那行又是 38px,就是用户截图中「第一行明显更高」的根因。
|
||||
*/
|
||||
const FIELD_INNER = '[&>*]:min-w-0 [&_span:first-child]:flex-none [&_input[type=checkbox]]:flex-none [&_input[type=checkbox]]:w-auto [&_input[type=radio]]:flex-none'
|
||||
|
||||
export function Ctlbar({ children, className, as: As = 'div' }: { children: ReactNode; className?: string; as?: any }) {
|
||||
return (
|
||||
|
|
@ -84,7 +90,7 @@ export function FieldBlock({ label, required, children, className, title }: {
|
|||
title?: string
|
||||
}) {
|
||||
return (
|
||||
<label title={title} className={cn('flex flex-col gap-[5px] mb-[10px] min-w-0', className)}>
|
||||
<label title={title} className={cn('[--ctl-h:var(--ctl-h-main)] flex flex-col gap-[5px] mb-[10px] min-w-0', className)}>
|
||||
<span className="flex items-center gap-1 text-muted text-tiny tracking-[.3px] flex-wrap whitespace-nowrap">
|
||||
{label}{required && <Req />}
|
||||
</span>
|
||||
|
|
@ -93,7 +99,13 @@ export function FieldBlock({ label, required, children, className, title }: {
|
|||
)
|
||||
}
|
||||
|
||||
/** 短字段栅格:列数由容器决定,页面不写 @media;stack 把标签退回控件上方 */
|
||||
/**
|
||||
* 短字段栅格:列数由容器决定,页面不写 @media;stack 把标签退回控件上方。
|
||||
*
|
||||
* 表单容器显式声明自己是主尺寸(38px):抽屉/对话框里的字段永远同一档,
|
||||
* 不会因为外面套了一层紧凑档工具条(Ctlbar / ChipBar / 抽屉动作条)
|
||||
* 就整排缩水成 31px——一个容器只有一个 --ctl-h 档位。
|
||||
*/
|
||||
export function FormRow({ children, cols, tight, stack, className }: {
|
||||
children: ReactNode
|
||||
cols?: 2 | 3 | 4 | 6
|
||||
|
|
@ -105,14 +117,14 @@ export function FormRow({ children, cols, tight, stack, className }: {
|
|||
: cols === 6 ? 'repeat(6,minmax(78px,1fr))'
|
||||
: `repeat(${cols},minmax(0,1fr))`
|
||||
return (
|
||||
<div className={cn('grid mb-[10px] min-w-0 [&>*]:min-w-0',
|
||||
<div className={cn('[--ctl-h:var(--ctl-h-main)] grid mb-[10px] min-w-0 [&>*]:min-w-0',
|
||||
// 间距照旧站 .frow(gap: 8px 10px):列间 10px 是「标签在左」不贴到上一格控件的地板,
|
||||
// 之前这里只在 tight 时给 gap,非 tight 档位间距为 0,窄屏上「镜号」几乎贴着上一格的输入框。
|
||||
tight ? 'gap-[8px]' : 'gap-x-[10px] gap-y-[8px]',
|
||||
cols === undefined && 'max-mid:grid-cols-2',
|
||||
(cols === 3 || cols === 4) && 'max-mid:grid-cols-2',
|
||||
(cols === 4 || cols === 6) && 'max-nav:grid-cols-2',
|
||||
stack && 'gap-y-[10px] [&>*]:flex-col [&>*]:items-stretch [&>*]:gap-[5px] [&>*]:flex-none [&>*]:w-auto [&>*:not(span)]:w-full',
|
||||
stack && 'gap-y-[10px] [&>*]:flex-col [&>*]:items-stretch [&>*]:gap-[5px] [&>*]:w-auto [&>*:not(span)]:w-full',
|
||||
className)}
|
||||
style={{ gridTemplateColumns: tracks }}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -39,10 +39,35 @@
|
|||
}
|
||||
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]):not([type=color]),
|
||||
select { height: var(--ctl-h); padding-block: 0 }
|
||||
textarea { min-height: var(--ctl-h); resize: vertical; line-height: 1.65 }
|
||||
|
||||
/* 多行文本也归档位管:行数由 rows 决定,但「一行」必须正好等于 --ctl-h。
|
||||
默认 line-height 1.65 时 rows=2 的裸 textarea 量出来是 41.6px,
|
||||
比同一行里的 input(38px)高 3.6px,一排字段就参差不齐;
|
||||
把上下 padding 按 --ctl-h 倒推,rows=1 → 38px,之后每多一行正好多 1.5em。 */
|
||||
textarea {
|
||||
min-height: var(--ctl-h);
|
||||
resize: vertical;
|
||||
line-height: 1.5;
|
||||
padding-block: calc((var(--ctl-h) - 1.5em - 2px) / 2);
|
||||
}
|
||||
input:focus, textarea:focus, select:focus { border-color: var(--c-accent-deep) }
|
||||
input:disabled, textarea:disabled, select:disabled { @apply bg-sunken text-faint; opacity: .7 }
|
||||
select { appearance: none; -webkit-appearance: none }
|
||||
|
||||
/* 原生下拉:抹掉 UA 皮肤后必须自己补箭头,并给箭头腾出右侧空间 */
|
||||
select {
|
||||
appearance: none; -webkit-appearance: none;
|
||||
background-image: var(--ctl-caret);
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 8px center;
|
||||
background-size: 15px 15px;
|
||||
padding-right: 28px;
|
||||
}
|
||||
|
||||
/* 数字框:UA 的 spinner 比控件本身还高(模型抽屉里那颗大箭头),
|
||||
尺寸和配色都不受控,统一去掉;步进动作交给旁边的按钮。 */
|
||||
input[type=number] { appearance: textfield; -moz-appearance: textfield }
|
||||
input[type=number]::-webkit-outer-spin-button,
|
||||
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0 }
|
||||
|
||||
/* 勾选类控件不参与定高,跟随系统强调色改成主色 */
|
||||
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--c-accent-fill) }
|
||||
|
|
|
|||
|
|
@ -164,6 +164,10 @@
|
|||
--ctl-h-main: 38px;
|
||||
--ctl-h-md: 31px;
|
||||
--ctl-h: var(--ctl-h-main);
|
||||
/* 裸 <select> 的下拉箭头:base.css 把 select 的 appearance 抹掉了,
|
||||
不自己画就变成一个「没有 ▼ 的文本框」(分页条的「每页」正是这样)。
|
||||
几何与 components/forms/Caret.tsx 完全一致,只有颜色跟着主题翻。 */
|
||||
--ctl-caret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%23a1adb7' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
/* 顶栏高度:侧栏 sticky、分镜检查器的 top 都取这个值,差 1px 就露缝。
|
||||
64 = 顶栏内边距 7×2 + 下边框 1 + 流程控制台 49(17 + 4 + 16 + 内边距 10 + 边框 2)。 */
|
||||
--nex-bar: 64px;
|
||||
|
|
@ -172,6 +176,10 @@
|
|||
@media (max-width: 560px) {
|
||||
:root { --ctl-h-main: 40px; --ctl-h-md: 36px }
|
||||
}
|
||||
/* 浅色主题下箭头要更深一档,否则在白底上几乎看不见 */
|
||||
[data-theme="light"] {
|
||||
--ctl-caret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%234d5762' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
/* Tailwind v4 主题层:先清掉默认调色板/字阶,只留设计系统的语义名,
|
||||
这样「页面上出现一个没登记的颜色/字号」在类名上就看得出来。 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue