@snowui-design-system/components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/package.json +47 -0
- package/src/App.svelte +103 -0
- package/src/components/Avatar.md +452 -0
- package/src/components/Avatar.svelte +593 -0
- package/src/components/Avatar.test.ts +231 -0
- package/src/components/AvatarGroup.md +246 -0
- package/src/components/AvatarGroup.svelte +691 -0
- package/src/components/AvatarGroup.test.ts +142 -0
- package/src/components/Badge.md +164 -0
- package/src/components/Badge.svelte +461 -0
- package/src/components/Badge.test.ts +293 -0
- package/src/components/Button.md +312 -0
- package/src/components/Button.svelte +796 -0
- package/src/components/Button.test.ts +631 -0
- package/src/components/Checkbox.md +313 -0
- package/src/components/Checkbox.svelte +466 -0
- package/src/components/Checkbox.test.ts +57 -0
- package/src/components/CodeBlock.md +240 -0
- package/src/components/CodeBlock.svelte +1287 -0
- package/src/components/CodeBlock.test.ts +192 -0
- package/src/components/Form.md +33 -0
- package/src/components/Form.test.ts +307 -0
- package/src/components/Frame.svelte +220 -0
- package/src/components/Icon.md +279 -0
- package/src/components/Icon.svelte +505 -0
- package/src/components/Icon.test.ts +82 -0
- package/src/components/Image.md +292 -0
- package/src/components/Image.svelte +634 -0
- package/src/components/Image.test.ts +42 -0
- package/src/components/ImageGroup.md +168 -0
- package/src/components/ImageGroup.svelte +151 -0
- package/src/components/ImageGroup.test.ts +46 -0
- package/src/components/InView.test.ts +55 -0
- package/src/components/Input.md +666 -0
- package/src/components/Input.svelte +2741 -0
- package/src/components/Input.test.ts +503 -0
- package/src/components/Kbd.md +100 -0
- package/src/components/Kbd.svelte +110 -0
- package/src/components/Kbd.test.ts +50 -0
- package/src/components/Listbox.md +245 -0
- package/src/components/Listbox.svelte +389 -0
- package/src/components/Listbox.test.ts +139 -0
- package/src/components/MenuItem.md +184 -0
- package/src/components/MenuItem.svelte +326 -0
- package/src/components/MenuItem.test.ts +167 -0
- package/src/components/Morph.test.ts +53 -0
- package/src/components/Popover.md +87 -0
- package/src/components/Popover.svelte +186 -0
- package/src/components/Popover.test.ts +60 -0
- package/src/components/QuickAction.md +146 -0
- package/src/components/QuickAction.svelte +161 -0
- package/src/components/QuickAction.test.ts +299 -0
- package/src/components/Radio.md +318 -0
- package/src/components/Radio.svelte +502 -0
- package/src/components/Radio.test.ts +76 -0
- package/src/components/Select.md +492 -0
- package/src/components/Select.svelte +535 -0
- package/src/components/Select.test.ts +146 -0
- package/src/components/Skeleton.md +323 -0
- package/src/components/Skeleton.svelte +791 -0
- package/src/components/Skeleton.test.ts +121 -0
- package/src/components/Spinner.md +136 -0
- package/src/components/Spinner.svelte +296 -0
- package/src/components/Spinner.test.ts +88 -0
- package/src/components/SplitText.test.ts +142 -0
- package/src/components/Stagger.test.ts +57 -0
- package/src/components/Test.md +72 -0
- package/src/components/Test.svelte +106 -0
- package/src/components/Test.test.ts +27 -0
- package/src/components/Text.md +450 -0
- package/src/components/Text.svelte +507 -0
- package/src/components/Text.test.ts +150 -0
- package/src/components/Textarea.md +240 -0
- package/src/components/Textarea.svelte +742 -0
- package/src/components/Textarea.test.ts +131 -0
- package/src/components/Toggle.md +196 -0
- package/src/components/Toggle.svelte +384 -0
- package/src/components/Toggle.test.ts +57 -0
- package/src/components/Tooltip.md +164 -0
- package/src/components/Tooltip.svelte +417 -0
- package/src/components/Tooltip.test.ts +64 -0
- package/src/context.ts +312 -0
- package/src/dev.ts +10 -0
- package/src/index.ts +29 -0
- package/src/keys.ts +26 -0
- package/src/lib/search-filter.md +82 -0
- package/src/lib/search-filter.ts +57 -0
- package/src/lib/truncate.md +25 -0
- package/src/lib/truncate.ts +234 -0
- package/src/logic/README.md +146 -0
- package/src/logic/collapse.svelte.ts +6 -0
- package/src/logic/frame-dom-runtime.md +19 -0
- package/src/logic/frame-dom-runtime.svelte.ts +286 -0
- package/src/logic/frame-field-control.md +38 -0
- package/src/logic/frame-field-control.ts +95 -0
- package/src/logic/frame-identity.md +68 -0
- package/src/logic/frame-identity.svelte.ts +25 -0
- package/src/logic/frame-layout.md +91 -0
- package/src/logic/frame-layout.svelte.ts +111 -0
- package/src/logic/frame-motion-defaults.md +180 -0
- package/src/logic/frame-motion-defaults.ts +711 -0
- package/src/logic/frame-profile.md +156 -0
- package/src/logic/frame-profile.ts +130 -0
- package/src/logic/frame-prop-filter.md +34 -0
- package/src/logic/frame-prop-filter.ts +254 -0
- package/src/logic/frame-responsive.md +91 -0
- package/src/logic/frame-responsive.svelte.ts +92 -0
- package/src/logic/frame-skeleton-runtime.md +20 -0
- package/src/logic/frame-skeleton-runtime.svelte.ts +160 -0
- package/src/logic/frame-truncation.md +127 -0
- package/src/logic/frame-truncation.svelte.ts +193 -0
- package/src/logic/frame-types.md +157 -0
- package/src/logic/frame-types.ts +434 -0
- package/src/logic/frame-utils.md +22 -0
- package/src/logic/frame-utils.ts +250 -0
- package/src/logic/geometry-cache.ts +120 -0
- package/src/logic/image-preview.md +24 -0
- package/src/logic/image-preview.ts +186 -0
- package/src/logic/layout-flip.ts +109 -0
- package/src/logic/motion-config.ts +102 -0
- package/src/logic/motion-types.md +47 -0
- package/src/logic/motion-types.ts +119 -0
- package/src/logic/observer.md +20 -0
- package/src/logic/observer.svelte.ts +53 -0
- package/src/logic/responsive.md +64 -0
- package/src/logic/responsive.svelte.ts +118 -0
- package/src/logic/text-collapse.md +22 -0
- package/src/logic/text-collapse.svelte.ts +507 -0
- package/src/logic/wc-adapter.ts +188 -0
- package/src/motion/NumberFlow.md +16 -0
- package/src/motion/README.md +87 -0
- package/src/motion/defaults/bridge.md +53 -0
- package/src/motion/defaults/bridge.ts +171 -0
- package/src/motion/defaults/content-crossfade.ts +22 -0
- package/src/motion/defaults/expand.md +66 -0
- package/src/motion/defaults/expand.ts +22 -0
- package/src/motion/defaults/fade-out.md +41 -0
- package/src/motion/defaults/fade-out.ts +14 -0
- package/src/motion/defaults/morph.md +42 -0
- package/src/motion/defaults/morph.ts +14 -0
- package/src/motion/defaults/move.md +81 -0
- package/src/motion/defaults/move.ts +31 -0
- package/src/motion/defaults/number.md +41 -0
- package/src/motion/defaults/number.ts +17 -0
- package/src/motion/defaults/replace.md +56 -0
- package/src/motion/defaults/replace.ts +22 -0
- package/src/motion/defaults/rotate.css +15 -0
- package/src/motion/defaults/rotate.md +60 -0
- package/src/motion/defaults/rotate.ts +20 -0
- package/src/motion/defaults/while-2xl.ts +9 -0
- package/src/motion/defaults/while-active.ts +12 -0
- package/src/motion/defaults/while-appear.ts +12 -0
- package/src/motion/defaults/while-click.ts +9 -0
- package/src/motion/defaults/while-collapsed.ts +12 -0
- package/src/motion/defaults/while-disabled.ts +13 -0
- package/src/motion/defaults/while-disappear.ts +12 -0
- package/src/motion/defaults/while-drag.ts +9 -0
- package/src/motion/defaults/while-editing.ts +9 -0
- package/src/motion/defaults/while-expanded.ts +12 -0
- package/src/motion/defaults/while-focus.ts +9 -0
- package/src/motion/defaults/while-hover.ts +13 -0
- package/src/motion/defaults/while-idle.ts +9 -0
- package/src/motion/defaults/while-key.ts +9 -0
- package/src/motion/defaults/while-lg.ts +9 -0
- package/src/motion/defaults/while-load.ts +11 -0
- package/src/motion/defaults/while-md.ts +9 -0
- package/src/motion/defaults/while-reload.ts +12 -0
- package/src/motion/defaults/while-scroll.ts +9 -0
- package/src/motion/defaults/while-sm.ts +9 -0
- package/src/motion/defaults/while-uploading.ts +9 -0
- package/src/motion/defaults/while-validating.ts +9 -0
- package/src/motion/defaults/while-xl.ts +9 -0
- package/src/motion/defaults/while-xs.ts +9 -0
- package/src/styles/README.md +95 -0
- package/src/styles/auto-layout.css +111 -0
- package/src/styles/index.css +7 -0
- package/src/styles/layout.css +319 -0
- package/src/styles/scale.css +106 -0
- package/src/styles/scale.md +218 -0
- package/src/styles/scrollbar.css +173 -0
- package/src/styles/tokens.css +192 -0
- package/src/vite-env.d.ts +9 -0
- package/src//344/273/243/347/240/201.txt +61 -0
|
@@ -0,0 +1,2741 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Input 组件:基础单行输入框
|
|
3
|
+
v1.0.42
|
|
4
|
+
|
|
5
|
+
变更记录 (2026-04-09):
|
|
6
|
+
- 修复嵌入原生宿主的 segment 识别:`Field row > Input as="segment"` 现在会显式导出 `data-as / data-embedded`,让 Field 分段 padding 与分隔线规则正确命中
|
|
7
|
+
- 按需求文档给出的期望 HTML 收敛 `text` 链路:改回可见原生 `<input>`,移除额外的 editor / placeholder 覆盖层
|
|
8
|
+
- `Field > Input` 的 text 结构回到 `div > input`,placeholder 与输入内容统一走浏览器原生单行输入排版
|
|
9
|
+
|
|
10
|
+
变更记录 (2026-04-27):
|
|
11
|
+
- 直系 `as="leading"` / `as="trailing"` 支持复杂结构,按三段布局显式落列;自定义 trailing 保持替换默认 trailing 槽的行为
|
|
12
|
+
- 内建清除 X 恢复为输入有值且 Input focus-within 时显示,失焦隐藏且不预留额外 gap
|
|
13
|
+
|
|
14
|
+
变更记录 (2026-04-25):
|
|
15
|
+
- 修复独立 Input 有值但 X 隐藏时右侧输入区域多出 8px:只有内建清除按钮时,隐藏态不再保留 grid gap;X 显示时再恢复 gap 与按钮列。
|
|
16
|
+
|
|
17
|
+
变更记录 (2026-03-31):
|
|
18
|
+
- 错误态焦点外环统一回收到 layout.css 的 Field Profile,Input / Select / Textarea / Field 共用同一套 focus ring
|
|
19
|
+
- 默认错误图标改为组件内建 trailing 挂件,并对齐 Figma 的单行居中布局与红色语义
|
|
20
|
+
|
|
21
|
+
变更记录 (2026-03-30):
|
|
22
|
+
- 对齐 Figma 错误焦点态:独立 invalid 输入框的 focus ring 改为 Black/4% 4px 外环,保留红色 0.5px 内边框
|
|
23
|
+
|
|
24
|
+
变更记录 (2026-03-29, v1.0.39):
|
|
25
|
+
- 修复 `list` / `datalist` 建议项失效:当文本输入声明 `list` 时,组件回退为可见原生 `<input type="text">`,保留浏览器原生建议列表能力
|
|
26
|
+
|
|
27
|
+
变更记录 (2026-03-29, v1.0.38):
|
|
28
|
+
- 明确移除 `type="file"` 支持:组件内部统一把 `file` 归一为 `text`,不再透传浏览器原生文件上传器
|
|
29
|
+
- 删除文件选择器专用样式,避免 `Input` 继续保留 file 类型的残余视觉实现
|
|
30
|
+
|
|
31
|
+
变更记录 (2026-03-28, v1.0.37):
|
|
32
|
+
- 明确移除 `type="range"` 支持:组件内部统一把 `range` 归一为 `text`,不再直接透传浏览器原生滑杆
|
|
33
|
+
- 回收 demo 中对 `Input type="range"` 的示例引用,避免把非设计体系内的原生滑杆误认为组件能力
|
|
34
|
+
|
|
35
|
+
变更记录 (2026-03-25, v1.0.36):
|
|
36
|
+
- 新增 `type="color"` 的默认可见展示层:改为 Figma 对应的“色点 + # + HEX”呈现,颜色值随原生 color picker 同步更新
|
|
37
|
+
- 保留隐藏原生 `<input type="color">` 作为真实宿主,继续承接表单归属、聚焦、键盘与 `bind:value` 同步能力
|
|
38
|
+
- 对齐示例规范:颜色输入示例改回直接使用 `<Input type="color" />`,不再用 `Frame + Text` 人工拼装展示态
|
|
39
|
+
|
|
40
|
+
变更记录 (2026-03-24):
|
|
41
|
+
- 对齐 number 默认 stepper 与 `Button iconButton={true}` 的基准高度:默认上下箭头按钮盒子回到 `sm` iconButton 对应尺寸,并复用相同箭头资源,避免 Playground 中默认 stepper 比自定义 iconButton 版本更高
|
|
42
|
+
|
|
43
|
+
变更记录 (2026-03-19, v1.0.35):
|
|
44
|
+
- 新增“不能编辑”视觉规则:`readonly` 统一采用 `Background/2` 背景且移除边框,覆盖独立模式与 Field 容器模式
|
|
45
|
+
- 修复数字输入框原生上下箭头未完全隐藏的问题:增强 `type="number"` 的浏览器兜底隐藏规则,保留自定义 `as="up/down"` 步进按钮
|
|
46
|
+
- 规范性对齐 (v1.5.10): 补齐 Props 接口中的 children 声明,对齐 enableResponsive 默认值为 true,并同步修正 Frame 能力开关显式传参
|
|
47
|
+
- CSS 规范对齐: 收敛 stepper 相关选择器到 :global(:where()),移除强制优先级写法,补齐主题 token fallback,并改用 Input 命名空间变量承接自身几何样式
|
|
48
|
+
- 内部逻辑优化: 保持 renderHints 与 Skeleton.svelte 计算链路一致
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
变更记录 (2026-03-14):
|
|
52
|
+
- Refactor: Input 的 focus 变量桥接回归 Field Profile 通用值,默认聚焦态改为 Black/40% 内边框 + Black/4% 的 4px 外层 ring
|
|
53
|
+
- Fix: placeholder 最终修复为拆分浏览器私有选择器并分别命中,统一输出 Black/20%
|
|
54
|
+
- Cleanup: 移除为光标问题添加的 placeholder 覆盖层与专项 cursor 兜底,回归原生 input + Field Profile 的最小实现
|
|
55
|
+
- Refactor: Input 默认边框/hover/focus/cursor 改为通过 Field Profile 变量桥接到 layout.css,focus 效果与文字光标统一由通用 Profile 控制
|
|
56
|
+
- Refactor: 抽离字段宿主桥接逻辑到 ../logic/frame-field-control.ts,统一 value/defaultValue、invalid/aria-invalid 与 file 类型值同步规则,为后续 Textarea/Select 复用
|
|
57
|
+
- Slim: 删除组件内重复的默认 hover/focus 规则,改为依赖 Field Profile 的通用行为;移除冗余 data-disabled 链路
|
|
58
|
+
- Refactor: 改用 ../logic/frame-prop-filter.ts 提供的共享 props 分发器,复用 Frame 内部关键字识别逻辑,为后续 Textarea/原生宿主类组件提供统一接口
|
|
59
|
+
- 按 Figma 样式翻译更新默认视觉:14 文字、12/16 padding、8 gap、16 圆角、Black/20% 0.5px 内边框、Background/3 背景
|
|
60
|
+
- 默认高度随排版与 padding 推导,符合流式布局规范,并同步更新 Skeleton renderHints
|
|
61
|
+
- 补齐默认 focus 链路,避免组件基础样式覆盖 Field Profile 的 focus ring
|
|
62
|
+
|
|
63
|
+
变更记录 (2026-03-16):
|
|
64
|
+
- 重构 text/date 编辑体验:`text` 与 `date` 改为“可见自定义编辑层 + 隐藏原生宿主同步值”的实现,统一选中文字视觉
|
|
65
|
+
- 修正日期分段高亮命中方式:Chrome 中 `year/month/day` 采用 `::-webkit-datetime-edit-* :focus` 链路,而非 `::selection`
|
|
66
|
+
- 收敛先前无效的普通 input `::selection` 方案,保留 Field 高亮变量给可命中的日期分段样式复用
|
|
67
|
+
- 修复普通 placeholder 颜色回归:沿用日期空态的成功方式,为 `:placeholder-shown` 的 input 本体追加 `Black/20%` 文本色,避免浏览器未命中 `::placeholder` 时仍显示为正文色
|
|
68
|
+
- 再次修复日期空态文案颜色:沿用 placeholder 的成功修复方式,把空值 `date input` 本体文字颜色也统一压到 `Black/20%`,不再只依赖浏览器内部字段伪元素
|
|
69
|
+
- 修复日期空态文案颜色:`type="date"` 在空值时改由组件侧统一把浏览器内部日期占位文本压到 `Black/20%`,与普通 placeholder 保持一致
|
|
70
|
+
- 修复无 trailing 按钮时的日期宿主外观:`type="date"` 在未绑定自定义 trigger 时恢复浏览器原生 appearance,保留默认日期 icon;仅在存在 `Button as="trailing"` 时才切换到自定义隐藏链路
|
|
71
|
+
- 修正日期 icon 修复判断:恢复 `::-webkit-calendar-picker-indicator` 隐藏分支,并与宿主右侧遮罩共同作为组合修复;此前删除该分支会导致默认日期 icon 再次出现
|
|
72
|
+
- 修复日期 trigger 命中不稳定:改为在 Input 运行时检测同一局部容器内的 direct trailing Button,并回写自身 `data-has-date-trigger`
|
|
73
|
+
- 移除 `control="date-picker"` 依赖;日期输入的自定义触发器仅基于局部容器内的 `Button as="trailing"` 自动识别
|
|
74
|
+
|
|
75
|
+
变更记录 (2026-03-15):
|
|
76
|
+
- 新增自定义日期触发器桥接:当宿主被自动 trailing 日期触发器绑定时,隐藏原生日期选择 icon,把选择入口交给外部组合按钮
|
|
77
|
+
|
|
78
|
+
变更记录 (2026-03-13):
|
|
79
|
+
- 新增基于 Frame 的单行输入组件,承接原生 <input> 属性透传与 Frame 通用能力
|
|
80
|
+
- 组件仅负责输入控件本体,不内建 Label / Description / Error
|
|
81
|
+
- 新增 invalid / readonly / file selector / datalist 等基础样式链路
|
|
82
|
+
|
|
83
|
+
文档: ./Input.md
|
|
84
|
+
-->
|
|
85
|
+
|
|
86
|
+
<!--
|
|
87
|
+
@file Input.svelte
|
|
88
|
+
@implementation_details (2026-03-19)
|
|
89
|
+
1. 数字步进器增强:
|
|
90
|
+
- 探测逻辑: 使用 $effect 和 MutationObserver 监听 hostElement 内部 children。
|
|
91
|
+
- 识别协议: 通过 [data-as="up/down"] 属性识别自定义按钮,不限组件类名(由 frame-dom-runtime 确保导出)。
|
|
92
|
+
- 分离渲染: 将 Up 和 Down 的隐藏逻辑解耦,支持局部替换(仅 Up 或仅 Down),防止 4 箭头叠加。
|
|
93
|
+
2. 布局优化:
|
|
94
|
+
- 应用 padding-x: 步进器容器不再使用负 margin,而是使用 var(--snowui-input-padding-x) 对齐,保持与文字区域留白一致。
|
|
95
|
+
- 原生隐藏: 强化 webkit-spin-button 隐藏规则,统一使用无强制优先级的 appearance: none。
|
|
96
|
+
3. 日期/时间激活: 优化交互,使得日期编辑器空白区域点击能激活首个有效选区。
|
|
97
|
+
-->
|
|
98
|
+
<script lang="ts">
|
|
99
|
+
import Frame, { type FrameProps } from "./Frame.svelte";
|
|
100
|
+
import {
|
|
101
|
+
ArrowLineDown2,
|
|
102
|
+
ArrowLineUp2,
|
|
103
|
+
Calendar,
|
|
104
|
+
Clock,
|
|
105
|
+
Warning,
|
|
106
|
+
} from "@snowui-design-system/resource-svelte";
|
|
107
|
+
import { getField, getListboxOwner, getListboxHeaderPortal } from "../context";
|
|
108
|
+
import {
|
|
109
|
+
resolveFrameFieldInvalid,
|
|
110
|
+
resolveFrameFieldValue,
|
|
111
|
+
syncFrameFieldValue,
|
|
112
|
+
} from "../logic/frame-field-control";
|
|
113
|
+
import { splitFrameHostProps } from "../logic/frame-prop-filter";
|
|
114
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
115
|
+
|
|
116
|
+
type InputValue = string | number | undefined;
|
|
117
|
+
type TemporalInputType =
|
|
118
|
+
| "date"
|
|
119
|
+
| "month"
|
|
120
|
+
| "week"
|
|
121
|
+
| "time"
|
|
122
|
+
| "datetime-local";
|
|
123
|
+
type TemporalSegmentKey =
|
|
124
|
+
| "year"
|
|
125
|
+
| "month"
|
|
126
|
+
| "day"
|
|
127
|
+
| "week"
|
|
128
|
+
| "hour"
|
|
129
|
+
| "minute"
|
|
130
|
+
| "second";
|
|
131
|
+
type DateDraft = Record<TemporalSegmentKey, string>;
|
|
132
|
+
|
|
133
|
+
interface Props extends Omit<FrameProps, "tag" | "profile"> {
|
|
134
|
+
type?: HTMLInputAttributes["type"];
|
|
135
|
+
value?: InputValue;
|
|
136
|
+
defaultValue?: InputValue;
|
|
137
|
+
placeholder?: string;
|
|
138
|
+
name?: string;
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
readonly?: boolean;
|
|
141
|
+
required?: boolean;
|
|
142
|
+
autocomplete?: HTMLInputAttributes["autocomplete"];
|
|
143
|
+
minlength?: number;
|
|
144
|
+
maxlength?: number;
|
|
145
|
+
pattern?: string;
|
|
146
|
+
min?: number | string;
|
|
147
|
+
max?: number | string;
|
|
148
|
+
step?: number | string;
|
|
149
|
+
inputmode?: HTMLInputAttributes["inputmode"];
|
|
150
|
+
enterkeyhint?: HTMLInputAttributes["enterkeyhint"];
|
|
151
|
+
spellcheck?: boolean;
|
|
152
|
+
list?: string;
|
|
153
|
+
accept?: string;
|
|
154
|
+
multiple?: boolean;
|
|
155
|
+
capture?: boolean | "user" | "environment";
|
|
156
|
+
form?: string;
|
|
157
|
+
autofocus?: boolean;
|
|
158
|
+
tabindex?: number;
|
|
159
|
+
title?: string;
|
|
160
|
+
id?: string;
|
|
161
|
+
invalid?: boolean;
|
|
162
|
+
onclick?: (event: MouseEvent) => void;
|
|
163
|
+
ondblclick?: (event: MouseEvent) => void;
|
|
164
|
+
oninput?: (event: Event) => void;
|
|
165
|
+
onchange?: (event: Event) => void;
|
|
166
|
+
onfocus?: (event: FocusEvent) => void;
|
|
167
|
+
onblur?: (event: FocusEvent) => void;
|
|
168
|
+
onkeydown?: (event: KeyboardEvent) => void;
|
|
169
|
+
onkeyup?: (event: KeyboardEvent) => void;
|
|
170
|
+
onkeypress?: (event: KeyboardEvent) => void;
|
|
171
|
+
onpaste?: (event: ClipboardEvent) => void;
|
|
172
|
+
oncopy?: (event: ClipboardEvent) => void;
|
|
173
|
+
oncut?: (event: ClipboardEvent) => void;
|
|
174
|
+
children?: import("svelte").Snippet;
|
|
175
|
+
/**
|
|
176
|
+
* 仅当 `as="search"` 且位于 `<Listbox>` 内时生效。
|
|
177
|
+
* 启用后,搜索无匹配时按 Enter 可将用户输入的文本作为自定义选项添加并选中。
|
|
178
|
+
*/
|
|
179
|
+
allowCustomValue?: boolean;
|
|
180
|
+
[key: string]: any;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let {
|
|
184
|
+
type = "text",
|
|
185
|
+
value = $bindable(),
|
|
186
|
+
defaultValue = undefined,
|
|
187
|
+
placeholder = undefined,
|
|
188
|
+
name = undefined,
|
|
189
|
+
disabled = false,
|
|
190
|
+
readonly = false,
|
|
191
|
+
required = false,
|
|
192
|
+
autocomplete = undefined,
|
|
193
|
+
minlength = undefined,
|
|
194
|
+
maxlength = undefined,
|
|
195
|
+
pattern = undefined,
|
|
196
|
+
min = undefined,
|
|
197
|
+
max = undefined,
|
|
198
|
+
step = undefined,
|
|
199
|
+
inputmode = undefined,
|
|
200
|
+
enterkeyhint = undefined,
|
|
201
|
+
spellcheck = undefined,
|
|
202
|
+
list = undefined,
|
|
203
|
+
accept = undefined,
|
|
204
|
+
multiple = undefined,
|
|
205
|
+
capture = undefined,
|
|
206
|
+
form = undefined,
|
|
207
|
+
autofocus = undefined,
|
|
208
|
+
tabindex = undefined,
|
|
209
|
+
title = undefined,
|
|
210
|
+
id = undefined,
|
|
211
|
+
invalid = false,
|
|
212
|
+
onclick: userOnClick = undefined,
|
|
213
|
+
ondblclick: userOnDoubleClick = undefined,
|
|
214
|
+
oninput: userOnInput = undefined,
|
|
215
|
+
onchange: userOnChange = undefined,
|
|
216
|
+
onfocus: userOnFocus = undefined,
|
|
217
|
+
onblur: userOnBlur = undefined,
|
|
218
|
+
onkeydown: userOnKeyDown = undefined,
|
|
219
|
+
onkeyup: userOnKeyUp = undefined,
|
|
220
|
+
onkeypress: userOnKeyPress = undefined,
|
|
221
|
+
onpaste: userOnPaste = undefined,
|
|
222
|
+
oncopy: userOnCopy = undefined,
|
|
223
|
+
oncut: userOnCut = undefined,
|
|
224
|
+
enableAutoLayout = true,
|
|
225
|
+
enableResponsive = true,
|
|
226
|
+
enableContext = true,
|
|
227
|
+
enableScaleObserver = false,
|
|
228
|
+
class: userClass = "",
|
|
229
|
+
style: userStyle = "",
|
|
230
|
+
renderHints: userRenderHints = undefined,
|
|
231
|
+
children = undefined,
|
|
232
|
+
allowCustomValue = false,
|
|
233
|
+
...rest
|
|
234
|
+
}: Props = $props();
|
|
235
|
+
|
|
236
|
+
const splitProps = $derived.by(() => splitFrameHostProps(rest));
|
|
237
|
+
const frameRestProps = $derived(splitProps.frameProps);
|
|
238
|
+
const inputRestProps = $derived(splitProps.hostProps);
|
|
239
|
+
const internalAutoLayout = $derived(
|
|
240
|
+
enableAutoLayout === false ? true : enableAutoLayout,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const normalizedInputType = $derived(
|
|
244
|
+
type === "range" || type === "file" ? "text" : (type ?? "text"),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
const fieldControlOptions = $derived({
|
|
248
|
+
controlType: normalizedInputType,
|
|
249
|
+
skipTypes: ["file"],
|
|
250
|
+
});
|
|
251
|
+
let didApplyAutofocus = false;
|
|
252
|
+
|
|
253
|
+
const resolvedValue = $derived(
|
|
254
|
+
resolveFrameFieldValue(value, defaultValue, fieldControlOptions),
|
|
255
|
+
);
|
|
256
|
+
const resolvedInvalid = $derived(
|
|
257
|
+
resolveFrameFieldInvalid(invalid, inputRestProps),
|
|
258
|
+
);
|
|
259
|
+
const isCustomColorType = $derived(normalizedInputType === "color");
|
|
260
|
+
const isCustomTemporalType = $derived(
|
|
261
|
+
normalizedInputType === "date" ||
|
|
262
|
+
normalizedInputType === "month" ||
|
|
263
|
+
normalizedInputType === "week" ||
|
|
264
|
+
normalizedInputType === "time" ||
|
|
265
|
+
normalizedInputType === "datetime-local",
|
|
266
|
+
);
|
|
267
|
+
const isTemporalValueEmpty = $derived(
|
|
268
|
+
isCustomTemporalType &&
|
|
269
|
+
(resolvedValue === undefined ||
|
|
270
|
+
resolvedValue === null ||
|
|
271
|
+
resolvedValue === ""),
|
|
272
|
+
);
|
|
273
|
+
const isClearableType = $derived(
|
|
274
|
+
normalizedInputType !== "number" &&
|
|
275
|
+
!isCustomColorType &&
|
|
276
|
+
!isCustomTemporalType,
|
|
277
|
+
);
|
|
278
|
+
const hasClearableValue = $derived(
|
|
279
|
+
isClearableType &&
|
|
280
|
+
resolvedValue !== undefined &&
|
|
281
|
+
String(resolvedValue) !== "",
|
|
282
|
+
);
|
|
283
|
+
const temporalInputType = $derived(
|
|
284
|
+
isCustomTemporalType
|
|
285
|
+
? (normalizedInputType as TemporalInputType)
|
|
286
|
+
: null,
|
|
287
|
+
);
|
|
288
|
+
const fieldContext = getField();
|
|
289
|
+
const isEmbedded = $derived(!!fieldContext);
|
|
290
|
+
const listboxOwner = getListboxOwner();
|
|
291
|
+
const isListboxSearch = $derived(rest.as === "search" && !!listboxOwner);
|
|
292
|
+
const listboxHeaderPortal = getListboxHeaderPortal();
|
|
293
|
+
// as="search" 时若未显式设置 maxlength,默认限制 100 字符
|
|
294
|
+
const resolvedMaxlength = $derived(isListboxSearch ? (maxlength ?? 100) : maxlength);
|
|
295
|
+
const embeddedRoleClass = $derived.by(() => {
|
|
296
|
+
const role = rest.as;
|
|
297
|
+
if (typeof role !== "string" || !role.trim()) return "";
|
|
298
|
+
return `snowui-role-${role
|
|
299
|
+
.trim()
|
|
300
|
+
.toLowerCase()
|
|
301
|
+
.replace(/[^a-z0-9_-]+/g, "-")}`;
|
|
302
|
+
});
|
|
303
|
+
const rendersEmbeddedNativeHost = $derived(
|
|
304
|
+
isEmbedded && !isCustomColorType && !isCustomTemporalType,
|
|
305
|
+
);
|
|
306
|
+
let hostElement = $state<HTMLElement | undefined>(undefined);
|
|
307
|
+
// as="search" 时自动移入 Listbox header 区域(固定置顶,不随选项滚动)
|
|
308
|
+
$effect(() => {
|
|
309
|
+
if (!isListboxSearch || !listboxHeaderPortal?.el || !hostElement) return;
|
|
310
|
+
listboxHeaderPortal.el.appendChild(hostElement);
|
|
311
|
+
});
|
|
312
|
+
let nativeInputElement = $state<HTMLInputElement | undefined>(undefined);
|
|
313
|
+
let dateEditorFocused = $state(false);
|
|
314
|
+
let dateDraft = $state<DateDraft>({
|
|
315
|
+
year: "",
|
|
316
|
+
month: "",
|
|
317
|
+
day: "",
|
|
318
|
+
week: "",
|
|
319
|
+
hour: "",
|
|
320
|
+
minute: "",
|
|
321
|
+
second: "",
|
|
322
|
+
});
|
|
323
|
+
let lastDateChangeValue = $state("");
|
|
324
|
+
let lastResolvedDateValue = $state("");
|
|
325
|
+
let preserveDateDraftOnBlur = $state(false);
|
|
326
|
+
let activeDateSegment = $state<TemporalSegmentKey | null>(null);
|
|
327
|
+
let replaceDateSegmentOnNextKey = $state(false);
|
|
328
|
+
let hasTemporalTrigger = $state(false);
|
|
329
|
+
let hasRootAccessory = $state(false);
|
|
330
|
+
let hasCustomStepperUp = $state(false);
|
|
331
|
+
let hasCustomStepperDown = $state(false);
|
|
332
|
+
let hasCustomTrailing = $state(false);
|
|
333
|
+
|
|
334
|
+
const stepperCurrentValue = $derived(
|
|
335
|
+
normalizedInputType === "number" &&
|
|
336
|
+
resolvedValue !== undefined &&
|
|
337
|
+
resolvedValue !== null &&
|
|
338
|
+
resolvedValue !== ""
|
|
339
|
+
? parseFloat(String(resolvedValue))
|
|
340
|
+
: NaN,
|
|
341
|
+
);
|
|
342
|
+
const stepUpDisabled = $derived(
|
|
343
|
+
disabled ||
|
|
344
|
+
readonly ||
|
|
345
|
+
(max !== undefined &&
|
|
346
|
+
max !== null &&
|
|
347
|
+
!isNaN(stepperCurrentValue) &&
|
|
348
|
+
stepperCurrentValue >= Number(max)),
|
|
349
|
+
);
|
|
350
|
+
const stepDownDisabled = $derived(
|
|
351
|
+
disabled ||
|
|
352
|
+
readonly ||
|
|
353
|
+
(min !== undefined &&
|
|
354
|
+
min !== null &&
|
|
355
|
+
!isNaN(stepperCurrentValue) &&
|
|
356
|
+
stepperCurrentValue <= Number(min)),
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
const EMPTY_DATE_DRAFT: DateDraft = {
|
|
360
|
+
year: "",
|
|
361
|
+
month: "",
|
|
362
|
+
day: "",
|
|
363
|
+
week: "",
|
|
364
|
+
hour: "",
|
|
365
|
+
minute: "",
|
|
366
|
+
second: "",
|
|
367
|
+
};
|
|
368
|
+
const TEMPORAL_SEGMENT_ORDER: Record<
|
|
369
|
+
TemporalInputType,
|
|
370
|
+
TemporalSegmentKey[]
|
|
371
|
+
> = {
|
|
372
|
+
date: ["year", "month", "day"],
|
|
373
|
+
month: ["year", "month"],
|
|
374
|
+
week: ["year", "week"],
|
|
375
|
+
time: ["hour", "minute", "second"],
|
|
376
|
+
"datetime-local": ["year", "month", "day", "hour", "minute", "second"],
|
|
377
|
+
};
|
|
378
|
+
const TEMPORAL_SEPARATOR_AFTER: Partial<
|
|
379
|
+
Record<TemporalSegmentKey, string>
|
|
380
|
+
> = {
|
|
381
|
+
year: "/",
|
|
382
|
+
month: "/",
|
|
383
|
+
day: " ",
|
|
384
|
+
hour: ":",
|
|
385
|
+
minute: ":",
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const inputRenderHints = $derived({
|
|
389
|
+
variant: userRenderHints?.variant ?? "line",
|
|
390
|
+
width: userRenderHints?.width ?? "100%",
|
|
391
|
+
height: userRenderHints?.height,
|
|
392
|
+
radius: userRenderHints?.radius ?? "var(--radius-4)",
|
|
393
|
+
});
|
|
394
|
+
const colorDisplayValue = $derived(
|
|
395
|
+
normalizeColorValue(resolvedValue) ?? "#000000",
|
|
396
|
+
);
|
|
397
|
+
const colorHexValue = $derived(colorDisplayValue.slice(1));
|
|
398
|
+
const TemporalDefaultIcon = $derived(
|
|
399
|
+
getTemporalDefaultIcon(temporalInputType),
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
function syncValueFromTarget(target: EventTarget | null) {
|
|
403
|
+
syncFrameFieldValue(
|
|
404
|
+
target,
|
|
405
|
+
(nextValue) => {
|
|
406
|
+
value = nextValue;
|
|
407
|
+
},
|
|
408
|
+
fieldControlOptions,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function handleInput(event: Event) {
|
|
413
|
+
syncValueFromTarget(event.currentTarget);
|
|
414
|
+
if (isListboxSearch) {
|
|
415
|
+
const v = (event.currentTarget as HTMLInputElement)?.value ?? "";
|
|
416
|
+
listboxOwner!.setFilterText(v);
|
|
417
|
+
}
|
|
418
|
+
userOnInput?.(event);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function handleChange(event: Event) {
|
|
422
|
+
syncValueFromTarget(event.currentTarget);
|
|
423
|
+
userOnChange?.(event);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function handleClear() {
|
|
427
|
+
value = "";
|
|
428
|
+
if (isListboxSearch) listboxOwner?.setFilterText("");
|
|
429
|
+
nativeInputElement?.focus();
|
|
430
|
+
emitSyntheticInput();
|
|
431
|
+
emitSyntheticChange();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 当 Listbox 关闭时,清空搜索 Input 的值
|
|
435
|
+
$effect(() => {
|
|
436
|
+
if (isListboxSearch && listboxOwner && !listboxOwner.open) {
|
|
437
|
+
value = "";
|
|
438
|
+
if (nativeInputElement) nativeInputElement.value = "";
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// as="search" + allowCustomValue 时,Enter 键将未匹配的输入添加为自定义选项
|
|
443
|
+
function handleSearchKeydown(event: KeyboardEvent) {
|
|
444
|
+
if (!isListboxSearch || !listboxOwner) return;
|
|
445
|
+
if (event.key === "Enter" && allowCustomValue) {
|
|
446
|
+
const text = (event.currentTarget as HTMLInputElement)?.value?.trim() ?? "";
|
|
447
|
+
if (!text) return;
|
|
448
|
+
const hasMatch =
|
|
449
|
+
listboxOwner.options.some(o => !o.disabled) ||
|
|
450
|
+
listboxOwner.customOptions.some(o => o.value === text);
|
|
451
|
+
if (!hasMatch) {
|
|
452
|
+
event.preventDefault();
|
|
453
|
+
listboxOwner.addCustomOption(text);
|
|
454
|
+
listboxOwner.selectOption(text);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function getResolvedStringValue(nextValue: InputValue) {
|
|
460
|
+
return nextValue === undefined || nextValue === null
|
|
461
|
+
? ""
|
|
462
|
+
: String(nextValue);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function normalizeColorValue(nextValue: InputValue) {
|
|
466
|
+
const rawValue = getResolvedStringValue(nextValue).trim();
|
|
467
|
+
if (!rawValue) return null;
|
|
468
|
+
|
|
469
|
+
const normalizedHex = rawValue.startsWith("#")
|
|
470
|
+
? rawValue.slice(1)
|
|
471
|
+
: rawValue;
|
|
472
|
+
|
|
473
|
+
if (/^[0-9a-fA-F]{3}$/.test(normalizedHex)) {
|
|
474
|
+
return `#${normalizedHex
|
|
475
|
+
.split("")
|
|
476
|
+
.map((char) => char + char)
|
|
477
|
+
.join("")
|
|
478
|
+
.toUpperCase()}`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (/^[0-9a-fA-F]{6}$/.test(normalizedHex)) {
|
|
482
|
+
return `#${normalizedHex.toUpperCase()}`;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function handleStepUp() {
|
|
489
|
+
if (disabled || readonly || normalizedInputType !== "number") return;
|
|
490
|
+
nativeInputElement?.stepUp();
|
|
491
|
+
syncValueFromTarget(nativeInputElement ?? null);
|
|
492
|
+
emitSyntheticChange();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function handleStepDown() {
|
|
496
|
+
if (disabled || readonly || normalizedInputType !== "number") return;
|
|
497
|
+
nativeInputElement?.stepDown();
|
|
498
|
+
syncValueFromTarget(nativeInputElement ?? null);
|
|
499
|
+
emitSyntheticChange();
|
|
500
|
+
}
|
|
501
|
+
function emitSyntheticChange() {
|
|
502
|
+
userOnChange?.(new Event("change", { bubbles: true }));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function emitSyntheticInput() {
|
|
506
|
+
userOnInput?.(new Event("input", { bubbles: true }));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function getTemporalSegments(inputType: TemporalInputType | null) {
|
|
510
|
+
return inputType ? TEMPORAL_SEGMENT_ORDER[inputType] : [];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function getTemporalDefaultIcon(inputType: TemporalInputType | null) {
|
|
514
|
+
return inputType === "time" ? Clock : Calendar;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function getTemporalTriggerLabel(inputType: TemporalInputType | null) {
|
|
518
|
+
return inputType === "time" ? "打开时间选择" : "打开日期选择";
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function getTemporalAriaLabel(segment: TemporalSegmentKey) {
|
|
522
|
+
return segment === "year"
|
|
523
|
+
? "年"
|
|
524
|
+
: segment === "month"
|
|
525
|
+
? "月"
|
|
526
|
+
: segment === "day"
|
|
527
|
+
? "日"
|
|
528
|
+
: segment === "week"
|
|
529
|
+
? "周"
|
|
530
|
+
: segment === "hour"
|
|
531
|
+
? "时"
|
|
532
|
+
: segment === "minute"
|
|
533
|
+
? "分"
|
|
534
|
+
: "秒";
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function getTemporalPlaceholder(segment: TemporalSegmentKey) {
|
|
538
|
+
return segment === "year"
|
|
539
|
+
? "年"
|
|
540
|
+
: segment === "month"
|
|
541
|
+
? "月"
|
|
542
|
+
: segment === "day"
|
|
543
|
+
? "日"
|
|
544
|
+
: segment === "week"
|
|
545
|
+
? "周"
|
|
546
|
+
: "00";
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function getTemporalSegmentLength(segment: TemporalSegmentKey) {
|
|
550
|
+
return segment === "year" ? 4 : 2;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function parseDateValue(
|
|
554
|
+
value: string,
|
|
555
|
+
inputType: TemporalInputType | null = temporalInputType,
|
|
556
|
+
): DateDraft {
|
|
557
|
+
const draft = { ...EMPTY_DATE_DRAFT };
|
|
558
|
+
if (!inputType || !value) return draft;
|
|
559
|
+
|
|
560
|
+
if (inputType === "date") {
|
|
561
|
+
const match = value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
562
|
+
if (!match) return draft;
|
|
563
|
+
const [, year, month, day] = match;
|
|
564
|
+
return { ...draft, year, month, day };
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (inputType === "month") {
|
|
568
|
+
const match = value.match(/^(\d{4})-(\d{2})$/);
|
|
569
|
+
if (!match) return draft;
|
|
570
|
+
const [, year, month] = match;
|
|
571
|
+
return { ...draft, year, month };
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (inputType === "week") {
|
|
575
|
+
const match = value.match(/^(\d{4})-W(\d{2})$/);
|
|
576
|
+
if (!match) return draft;
|
|
577
|
+
const [, year, week] = match;
|
|
578
|
+
return { ...draft, year, week };
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (inputType === "time") {
|
|
582
|
+
const match = value.match(/^(\d{2}):(\d{2})(?::(\d{2}))?$/);
|
|
583
|
+
if (!match) return draft;
|
|
584
|
+
const [, hour, minute, second = "00"] = match;
|
|
585
|
+
return { ...draft, hour, minute, second };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const match = value.match(
|
|
589
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/,
|
|
590
|
+
);
|
|
591
|
+
if (!match) return draft;
|
|
592
|
+
const [, year, month, day, hour, minute, second = "00"] = match;
|
|
593
|
+
return { ...draft, year, month, day, hour, minute, second };
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function sanitizeDateSegment(
|
|
597
|
+
segment: TemporalSegmentKey,
|
|
598
|
+
value: string,
|
|
599
|
+
): string {
|
|
600
|
+
const maxLength = getTemporalSegmentLength(segment);
|
|
601
|
+
return value.replace(/\D/g, "").slice(0, maxLength);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function formatDateSegmentDisplayValue(
|
|
605
|
+
segment: TemporalSegmentKey,
|
|
606
|
+
value: string,
|
|
607
|
+
) {
|
|
608
|
+
if (!value) {
|
|
609
|
+
return getTemporalPlaceholder(segment);
|
|
610
|
+
}
|
|
611
|
+
if (segment !== "year") {
|
|
612
|
+
return value.padStart(2, "0");
|
|
613
|
+
}
|
|
614
|
+
return value;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function getMaxDayForDraft(year: string, month: string) {
|
|
618
|
+
const numericYear = Number(year);
|
|
619
|
+
const numericMonth = Number(month);
|
|
620
|
+
if (
|
|
621
|
+
year.length === 4 &&
|
|
622
|
+
Number.isInteger(numericYear) &&
|
|
623
|
+
Number.isInteger(numericMonth) &&
|
|
624
|
+
numericMonth >= 1 &&
|
|
625
|
+
numericMonth <= 12
|
|
626
|
+
) {
|
|
627
|
+
return new Date(numericYear, numericMonth, 0).getDate();
|
|
628
|
+
}
|
|
629
|
+
return 31;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function getMaxWeekForYear(year: string) {
|
|
633
|
+
const numericYear = Number(year);
|
|
634
|
+
if (year.length !== 4 || !Number.isInteger(numericYear)) {
|
|
635
|
+
return 53;
|
|
636
|
+
}
|
|
637
|
+
const date = new Date(Date.UTC(numericYear, 11, 28));
|
|
638
|
+
const day = date.getUTCDay() || 7;
|
|
639
|
+
date.setUTCDate(date.getUTCDate() + 4 - day);
|
|
640
|
+
const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
|
|
641
|
+
return Math.ceil(
|
|
642
|
+
((date.getTime() - yearStart.getTime()) / 86400000 + 1) / 7,
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function clampDateSegmentValue(
|
|
647
|
+
segment: TemporalSegmentKey,
|
|
648
|
+
value: string,
|
|
649
|
+
draft: DateDraft,
|
|
650
|
+
) {
|
|
651
|
+
if (!value || segment === "year") {
|
|
652
|
+
return value;
|
|
653
|
+
}
|
|
654
|
+
const numericValue = Number(value);
|
|
655
|
+
if (!Number.isInteger(numericValue)) {
|
|
656
|
+
return value;
|
|
657
|
+
}
|
|
658
|
+
if (segment === "month") {
|
|
659
|
+
return String(Math.min(12, Math.max(1, numericValue))).padStart(
|
|
660
|
+
2,
|
|
661
|
+
"0",
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
if (segment === "week") {
|
|
665
|
+
return String(
|
|
666
|
+
Math.min(
|
|
667
|
+
getMaxWeekForYear(draft.year),
|
|
668
|
+
Math.max(1, numericValue),
|
|
669
|
+
),
|
|
670
|
+
).padStart(2, "0");
|
|
671
|
+
}
|
|
672
|
+
if (segment === "hour") {
|
|
673
|
+
return String(Math.min(23, Math.max(0, numericValue))).padStart(
|
|
674
|
+
2,
|
|
675
|
+
"0",
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
if (segment === "minute" || segment === "second") {
|
|
679
|
+
return String(Math.min(59, Math.max(0, numericValue))).padStart(
|
|
680
|
+
2,
|
|
681
|
+
"0",
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
const maxDay = getMaxDayForDraft(draft.year, draft.month);
|
|
685
|
+
return String(Math.min(maxDay, Math.max(1, numericValue))).padStart(
|
|
686
|
+
2,
|
|
687
|
+
"0",
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function normalizeDateDraft(
|
|
692
|
+
draft: DateDraft,
|
|
693
|
+
options: { padPartialMonthDay?: boolean } = {},
|
|
694
|
+
) {
|
|
695
|
+
const nextDraft = { ...draft };
|
|
696
|
+
|
|
697
|
+
if (nextDraft.month) {
|
|
698
|
+
if (options.padPartialMonthDay && nextDraft.month.length === 1) {
|
|
699
|
+
nextDraft.month = nextDraft.month.padStart(2, "0");
|
|
700
|
+
}
|
|
701
|
+
if (nextDraft.month.length === 2) {
|
|
702
|
+
nextDraft.month = clampDateSegmentValue(
|
|
703
|
+
"month",
|
|
704
|
+
nextDraft.month,
|
|
705
|
+
nextDraft,
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (nextDraft.day) {
|
|
711
|
+
if (options.padPartialMonthDay && nextDraft.day.length === 1) {
|
|
712
|
+
nextDraft.day = nextDraft.day.padStart(2, "0");
|
|
713
|
+
}
|
|
714
|
+
if (nextDraft.day.length === 2) {
|
|
715
|
+
nextDraft.day = clampDateSegmentValue(
|
|
716
|
+
"day",
|
|
717
|
+
nextDraft.day,
|
|
718
|
+
nextDraft,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (nextDraft.week) {
|
|
724
|
+
if (options.padPartialMonthDay && nextDraft.week.length === 1) {
|
|
725
|
+
nextDraft.week = nextDraft.week.padStart(2, "0");
|
|
726
|
+
}
|
|
727
|
+
if (nextDraft.week.length === 2) {
|
|
728
|
+
nextDraft.week = clampDateSegmentValue(
|
|
729
|
+
"week",
|
|
730
|
+
nextDraft.week,
|
|
731
|
+
nextDraft,
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
for (const segment of ["hour", "minute", "second"] as const) {
|
|
737
|
+
if (!nextDraft[segment]) continue;
|
|
738
|
+
if (options.padPartialMonthDay && nextDraft[segment].length === 1) {
|
|
739
|
+
nextDraft[segment] = nextDraft[segment].padStart(2, "0");
|
|
740
|
+
}
|
|
741
|
+
if (nextDraft[segment].length === 2) {
|
|
742
|
+
nextDraft[segment] = clampDateSegmentValue(
|
|
743
|
+
segment,
|
|
744
|
+
nextDraft[segment],
|
|
745
|
+
nextDraft,
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return nextDraft;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function normalizeDateSegmentInput(
|
|
754
|
+
segment: TemporalSegmentKey,
|
|
755
|
+
value: string,
|
|
756
|
+
) {
|
|
757
|
+
const sanitized = sanitizeDateSegment(segment, value);
|
|
758
|
+
if (
|
|
759
|
+
segment === "month" &&
|
|
760
|
+
sanitized.length === 1 &&
|
|
761
|
+
Number(sanitized) > 1
|
|
762
|
+
) {
|
|
763
|
+
return {
|
|
764
|
+
value: sanitized.padStart(2, "0"),
|
|
765
|
+
shouldMoveNext: true,
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
if (
|
|
769
|
+
segment === "day" &&
|
|
770
|
+
sanitized.length === 1 &&
|
|
771
|
+
Number(sanitized) > 3
|
|
772
|
+
) {
|
|
773
|
+
return {
|
|
774
|
+
value: sanitized.padStart(2, "0"),
|
|
775
|
+
shouldMoveNext: true,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (
|
|
779
|
+
segment === "week" &&
|
|
780
|
+
sanitized.length === 1 &&
|
|
781
|
+
Number(sanitized) > 5
|
|
782
|
+
) {
|
|
783
|
+
return {
|
|
784
|
+
value: sanitized.padStart(2, "0"),
|
|
785
|
+
shouldMoveNext: true,
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
if (
|
|
789
|
+
segment === "hour" &&
|
|
790
|
+
sanitized.length === 1 &&
|
|
791
|
+
Number(sanitized) > 2
|
|
792
|
+
) {
|
|
793
|
+
return {
|
|
794
|
+
value: sanitized.padStart(2, "0"),
|
|
795
|
+
shouldMoveNext: true,
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
if (
|
|
799
|
+
(segment === "minute" || segment === "second") &&
|
|
800
|
+
sanitized.length === 1 &&
|
|
801
|
+
Number(sanitized) > 5
|
|
802
|
+
) {
|
|
803
|
+
return {
|
|
804
|
+
value: sanitized.padStart(2, "0"),
|
|
805
|
+
shouldMoveNext: true,
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
if (segment !== "year" && sanitized.length === 2) {
|
|
809
|
+
const nextDraft = normalizeDateDraft({
|
|
810
|
+
...dateDraft,
|
|
811
|
+
[segment]: sanitized,
|
|
812
|
+
});
|
|
813
|
+
return {
|
|
814
|
+
value: nextDraft[segment],
|
|
815
|
+
shouldMoveNext: true,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
return {
|
|
819
|
+
value: sanitized,
|
|
820
|
+
shouldMoveNext:
|
|
821
|
+
(segment === "year" && sanitized.length === 4) ||
|
|
822
|
+
(segment !== "year" && sanitized.length === 2),
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function getDateSegmentElement(segment: TemporalSegmentKey) {
|
|
827
|
+
return hostElement?.querySelector(`[data-segment="${segment}"]`) as
|
|
828
|
+
| HTMLElement
|
|
829
|
+
| undefined;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function isValidCalendarDate(year: string, month: string, day: string) {
|
|
833
|
+
if (year.length !== 4 || month.length < 1 || day.length < 1) {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
const numericYear = Number(year);
|
|
837
|
+
const numericMonth = Number(month);
|
|
838
|
+
const numericDay = Number(day);
|
|
839
|
+
if (
|
|
840
|
+
!Number.isInteger(numericYear) ||
|
|
841
|
+
!Number.isInteger(numericMonth) ||
|
|
842
|
+
!Number.isInteger(numericDay)
|
|
843
|
+
) {
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
if (numericMonth < 1 || numericMonth > 12) return false;
|
|
847
|
+
if (numericDay < 1 || numericDay > 31) return false;
|
|
848
|
+
const date = new Date(numericYear, numericMonth - 1, numericDay);
|
|
849
|
+
return (
|
|
850
|
+
date.getFullYear() === numericYear &&
|
|
851
|
+
date.getMonth() === numericMonth - 1 &&
|
|
852
|
+
date.getDate() === numericDay
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function isValidTemporalDraft(
|
|
857
|
+
nextDraft: DateDraft,
|
|
858
|
+
inputType: TemporalInputType | null = temporalInputType,
|
|
859
|
+
) {
|
|
860
|
+
if (!inputType) return false;
|
|
861
|
+
if (inputType === "date") {
|
|
862
|
+
return isValidCalendarDate(
|
|
863
|
+
nextDraft.year,
|
|
864
|
+
nextDraft.month,
|
|
865
|
+
nextDraft.day,
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
if (inputType === "month") {
|
|
869
|
+
return (
|
|
870
|
+
nextDraft.year.length === 4 &&
|
|
871
|
+
nextDraft.month.length === 2 &&
|
|
872
|
+
Number(nextDraft.month) >= 1 &&
|
|
873
|
+
Number(nextDraft.month) <= 12
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
if (inputType === "week") {
|
|
877
|
+
const numericWeek = Number(nextDraft.week);
|
|
878
|
+
return (
|
|
879
|
+
nextDraft.year.length === 4 &&
|
|
880
|
+
nextDraft.week.length === 2 &&
|
|
881
|
+
Number.isInteger(numericWeek) &&
|
|
882
|
+
numericWeek >= 1 &&
|
|
883
|
+
numericWeek <= getMaxWeekForYear(nextDraft.year)
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
if (inputType === "time") {
|
|
887
|
+
return (
|
|
888
|
+
nextDraft.hour.length === 2 &&
|
|
889
|
+
nextDraft.minute.length === 2 &&
|
|
890
|
+
nextDraft.second.length === 2
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
return (
|
|
894
|
+
isValidCalendarDate(
|
|
895
|
+
nextDraft.year,
|
|
896
|
+
nextDraft.month,
|
|
897
|
+
nextDraft.day,
|
|
898
|
+
) &&
|
|
899
|
+
nextDraft.hour.length === 2 &&
|
|
900
|
+
nextDraft.minute.length === 2 &&
|
|
901
|
+
nextDraft.second.length === 2
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function formatDateDraft(
|
|
906
|
+
nextDraft: DateDraft,
|
|
907
|
+
inputType: TemporalInputType | null = temporalInputType,
|
|
908
|
+
) {
|
|
909
|
+
const segments = getTemporalSegments(inputType);
|
|
910
|
+
if (segments.length === 0) return "";
|
|
911
|
+
if (!segments.some((segment) => nextDraft[segment])) return "";
|
|
912
|
+
if (!isValidTemporalDraft(nextDraft, inputType)) return "";
|
|
913
|
+
if (inputType === "date") {
|
|
914
|
+
return `${nextDraft.year}-${nextDraft.month}-${nextDraft.day}`;
|
|
915
|
+
}
|
|
916
|
+
if (inputType === "month") {
|
|
917
|
+
return `${nextDraft.year}-${nextDraft.month}`;
|
|
918
|
+
}
|
|
919
|
+
if (inputType === "week") {
|
|
920
|
+
return `${nextDraft.year}-W${nextDraft.week}`;
|
|
921
|
+
}
|
|
922
|
+
if (inputType === "time") {
|
|
923
|
+
return `${nextDraft.hour}:${nextDraft.minute}:${nextDraft.second}`;
|
|
924
|
+
}
|
|
925
|
+
return `${nextDraft.year}-${nextDraft.month}-${nextDraft.day}T${nextDraft.hour}:${nextDraft.minute}:${nextDraft.second}`;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function focusDateSegment(segment: TemporalSegmentKey, selectAll = true) {
|
|
929
|
+
const target = getDateSegmentElement(segment);
|
|
930
|
+
activeDateSegment = segment;
|
|
931
|
+
replaceDateSegmentOnNextKey = selectAll;
|
|
932
|
+
target?.focus();
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function moveDateSegment(
|
|
936
|
+
segment: TemporalSegmentKey,
|
|
937
|
+
direction: "prev" | "next",
|
|
938
|
+
) {
|
|
939
|
+
const segments = getTemporalSegments(temporalInputType);
|
|
940
|
+
const currentIndex = segments.indexOf(segment);
|
|
941
|
+
if (currentIndex === -1) return;
|
|
942
|
+
const nextIndex =
|
|
943
|
+
direction === "prev" ? currentIndex - 1 : currentIndex + 1;
|
|
944
|
+
const nextSegment = segments[nextIndex];
|
|
945
|
+
if (nextSegment) focusDateSegment(nextSegment);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
function commitDateDraft(nextDraft: DateDraft, emitChange = false) {
|
|
949
|
+
dateDraft = nextDraft;
|
|
950
|
+
const formatted = formatDateDraft(nextDraft);
|
|
951
|
+
value = formatted;
|
|
952
|
+
if (formatted !== getResolvedStringValue(nativeInputElement?.value)) {
|
|
953
|
+
if (nativeInputElement) nativeInputElement.value = formatted;
|
|
954
|
+
}
|
|
955
|
+
emitSyntheticInput();
|
|
956
|
+
if (emitChange && formatted !== lastDateChangeValue) {
|
|
957
|
+
lastDateChangeValue = formatted;
|
|
958
|
+
emitSyntheticChange();
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function handleDateSegmentFocus(
|
|
963
|
+
segment: TemporalSegmentKey,
|
|
964
|
+
event: FocusEvent,
|
|
965
|
+
) {
|
|
966
|
+
dateEditorFocused = true;
|
|
967
|
+
preserveDateDraftOnBlur = false;
|
|
968
|
+
activeDateSegment = segment;
|
|
969
|
+
replaceDateSegmentOnNextKey = true;
|
|
970
|
+
userOnFocus?.(event);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function handleDateSegmentMouseDown(
|
|
974
|
+
segment: TemporalSegmentKey,
|
|
975
|
+
event: MouseEvent,
|
|
976
|
+
) {
|
|
977
|
+
if (disabled || readonly) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
event.preventDefault();
|
|
981
|
+
focusDateSegment(segment);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function handleDateSegmentClick(
|
|
985
|
+
segment: TemporalSegmentKey,
|
|
986
|
+
event: MouseEvent,
|
|
987
|
+
) {
|
|
988
|
+
if (disabled || readonly) {
|
|
989
|
+
userOnClick?.(event);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
event.preventDefault();
|
|
993
|
+
event.stopPropagation();
|
|
994
|
+
focusDateSegment(segment);
|
|
995
|
+
userOnClick?.(event);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function handleDateEditorClick(event: MouseEvent) {
|
|
999
|
+
if (disabled || readonly) {
|
|
1000
|
+
userOnClick?.(event);
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
// 如果点击的是容器本身(包括分隔符等空白区域),则聚焦第一个分段
|
|
1004
|
+
// 注意:点击 trigger 按钮时不聚焦分段,否则焦点移动会关闭刚打开的系统 picker
|
|
1005
|
+
const target = event.target as HTMLElement;
|
|
1006
|
+
if (target.closest(".snowui-input-date-trigger")) {
|
|
1007
|
+
userOnClick?.(event);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
if (
|
|
1011
|
+
target.closest(".snowui-input-date-editor") === event.currentTarget
|
|
1012
|
+
) {
|
|
1013
|
+
const segments = getTemporalSegments(temporalInputType);
|
|
1014
|
+
if (segments.length > 0) {
|
|
1015
|
+
focusDateSegment(segments[0]);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
userOnClick?.(event);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function handleDateSegmentBlur(event: FocusEvent) {
|
|
1022
|
+
const relatedTarget = event.relatedTarget;
|
|
1023
|
+
if (
|
|
1024
|
+
relatedTarget instanceof HTMLElement &&
|
|
1025
|
+
relatedTarget.closest(".snowui-input-date-editor") ===
|
|
1026
|
+
hostElement?.querySelector(".snowui-input-date-editor")
|
|
1027
|
+
) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
dateEditorFocused = false;
|
|
1031
|
+
activeDateSegment = null;
|
|
1032
|
+
replaceDateSegmentOnNextKey = false;
|
|
1033
|
+
const normalizedDraft = normalizeDateDraft(dateDraft, {
|
|
1034
|
+
padPartialMonthDay: true,
|
|
1035
|
+
});
|
|
1036
|
+
if (
|
|
1037
|
+
Object.keys(normalizedDraft).some(
|
|
1038
|
+
(segment) =>
|
|
1039
|
+
normalizedDraft[segment as TemporalSegmentKey] !==
|
|
1040
|
+
dateDraft[segment as TemporalSegmentKey],
|
|
1041
|
+
)
|
|
1042
|
+
) {
|
|
1043
|
+
commitDateDraft(normalizedDraft);
|
|
1044
|
+
}
|
|
1045
|
+
const formatted = formatDateDraft(normalizedDraft);
|
|
1046
|
+
const segments = getTemporalSegments(temporalInputType);
|
|
1047
|
+
preserveDateDraftOnBlur =
|
|
1048
|
+
formatted === "" &&
|
|
1049
|
+
segments.some((segment) => normalizedDraft[segment] !== "");
|
|
1050
|
+
if (formatted !== lastDateChangeValue) {
|
|
1051
|
+
lastDateChangeValue = formatted;
|
|
1052
|
+
emitSyntheticChange();
|
|
1053
|
+
}
|
|
1054
|
+
userOnBlur?.(event);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function handleDateSegmentKeyDown(
|
|
1058
|
+
segment: TemporalSegmentKey,
|
|
1059
|
+
event: KeyboardEvent,
|
|
1060
|
+
) {
|
|
1061
|
+
if (disabled || readonly) {
|
|
1062
|
+
userOnKeyDown?.(event);
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (event.key === "Enter") {
|
|
1066
|
+
event.preventDefault();
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (/^\d$/.test(event.key)) {
|
|
1070
|
+
event.preventDefault();
|
|
1071
|
+
const currentValue = dateDraft[segment];
|
|
1072
|
+
const nextRawValue = replaceDateSegmentOnNextKey
|
|
1073
|
+
? event.key
|
|
1074
|
+
: `${currentValue}${event.key}`;
|
|
1075
|
+
const normalized = normalizeDateSegmentInput(segment, nextRawValue);
|
|
1076
|
+
const nextValue = normalized.value;
|
|
1077
|
+
const nextDraft = { ...dateDraft, [segment]: nextValue };
|
|
1078
|
+
commitDateDraft(nextDraft);
|
|
1079
|
+
replaceDateSegmentOnNextKey = false;
|
|
1080
|
+
if (normalized.shouldMoveNext) {
|
|
1081
|
+
moveDateSegment(segment, "next");
|
|
1082
|
+
}
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
if (event.key === "/" || event.key === "-" || event.key === ".") {
|
|
1086
|
+
event.preventDefault();
|
|
1087
|
+
moveDateSegment(segment, "next");
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
if (event.key === "ArrowLeft") {
|
|
1091
|
+
moveDateSegment(segment, "prev");
|
|
1092
|
+
event.preventDefault();
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
if (event.key === "ArrowRight") {
|
|
1096
|
+
moveDateSegment(segment, "next");
|
|
1097
|
+
event.preventDefault();
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
1101
|
+
event.preventDefault();
|
|
1102
|
+
const currentValue = dateDraft[segment];
|
|
1103
|
+
if (replaceDateSegmentOnNextKey) {
|
|
1104
|
+
if (currentValue.length === 0) {
|
|
1105
|
+
moveDateSegment(segment, "prev");
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
commitDateDraft({ ...dateDraft, [segment]: "" });
|
|
1109
|
+
replaceDateSegmentOnNextKey = true;
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
if (currentValue.length === 0) {
|
|
1113
|
+
moveDateSegment(segment, "prev");
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
const nextValue = currentValue.slice(0, -1);
|
|
1117
|
+
commitDateDraft({ ...dateDraft, [segment]: nextValue });
|
|
1118
|
+
replaceDateSegmentOnNextKey = nextValue.length === 0;
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
userOnKeyDown?.(event);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function handleDateSegmentPaste(
|
|
1125
|
+
segment: TemporalSegmentKey,
|
|
1126
|
+
event: ClipboardEvent,
|
|
1127
|
+
) {
|
|
1128
|
+
if (disabled || readonly) {
|
|
1129
|
+
userOnPaste?.(event);
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
1133
|
+
if (!text) {
|
|
1134
|
+
userOnPaste?.(event);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
const digits = text.replace(/\D/g, "");
|
|
1139
|
+
const segments = getTemporalSegments(temporalInputType);
|
|
1140
|
+
const totalLength = segments.reduce(
|
|
1141
|
+
(sum, key) => sum + getTemporalSegmentLength(key),
|
|
1142
|
+
0,
|
|
1143
|
+
);
|
|
1144
|
+
if (digits.length >= totalLength && segments.length > 0) {
|
|
1145
|
+
event.preventDefault();
|
|
1146
|
+
const nextDraft = { ...dateDraft };
|
|
1147
|
+
let cursor = 0;
|
|
1148
|
+
for (const key of segments) {
|
|
1149
|
+
const length = getTemporalSegmentLength(key);
|
|
1150
|
+
nextDraft[key] = digits.slice(cursor, cursor + length);
|
|
1151
|
+
cursor += length;
|
|
1152
|
+
}
|
|
1153
|
+
commitDateDraft(nextDraft, true);
|
|
1154
|
+
focusDateSegment(segments[segments.length - 1]);
|
|
1155
|
+
userOnPaste?.(event);
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
const sanitized = sanitizeDateSegment(segment, text);
|
|
1159
|
+
event.preventDefault();
|
|
1160
|
+
const normalized = normalizeDateSegmentInput(segment, sanitized);
|
|
1161
|
+
commitDateDraft({ ...dateDraft, [segment]: normalized.value });
|
|
1162
|
+
replaceDateSegmentOnNextKey = false;
|
|
1163
|
+
if (normalized.shouldMoveNext) {
|
|
1164
|
+
moveDateSegment(segment, "next");
|
|
1165
|
+
}
|
|
1166
|
+
userOnPaste?.(event);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function handleNativeDateInput(event: Event) {
|
|
1170
|
+
syncValueFromTarget(event.currentTarget);
|
|
1171
|
+
const nextValue =
|
|
1172
|
+
event.currentTarget instanceof HTMLInputElement
|
|
1173
|
+
? event.currentTarget.value
|
|
1174
|
+
: "";
|
|
1175
|
+
dateDraft = parseDateValue(nextValue, temporalInputType);
|
|
1176
|
+
userOnInput?.(event);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function handleNativeDateChange(event: Event) {
|
|
1180
|
+
handleNativeDateInput(event);
|
|
1181
|
+
lastDateChangeValue =
|
|
1182
|
+
event.currentTarget instanceof HTMLInputElement
|
|
1183
|
+
? event.currentTarget.value
|
|
1184
|
+
: "";
|
|
1185
|
+
userOnChange?.(event);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function tryOpenNativeTemporalPicker() {
|
|
1189
|
+
const input = nativeInputElement as
|
|
1190
|
+
| (HTMLInputElement & { showPicker?: () => void })
|
|
1191
|
+
| undefined;
|
|
1192
|
+
if (!input || disabled) return;
|
|
1193
|
+
|
|
1194
|
+
// 某些浏览器(Safari / 旧版 Chrome)对 opacity:0 的元素拒绝 showPicker / click(),
|
|
1195
|
+
// 临时覆盖 opacity 为极小非零值,完成调用后立即还原。
|
|
1196
|
+
// 不调用 input.focus():focus 会触发 handleDateSegmentBlur 并引起状态更新,
|
|
1197
|
+
// 可能在某些 runtime 条件下导致 picker 被取消。
|
|
1198
|
+
input.style.setProperty("opacity", "0.001", "important");
|
|
1199
|
+
try {
|
|
1200
|
+
if (typeof input.showPicker === "function") {
|
|
1201
|
+
input.showPicker();
|
|
1202
|
+
} else {
|
|
1203
|
+
input.click();
|
|
1204
|
+
}
|
|
1205
|
+
} catch {
|
|
1206
|
+
// showPicker 被拒绝;回退到 click()
|
|
1207
|
+
try {
|
|
1208
|
+
input.click();
|
|
1209
|
+
} catch {
|
|
1210
|
+
// ignore
|
|
1211
|
+
}
|
|
1212
|
+
} finally {
|
|
1213
|
+
input.style.removeProperty("opacity");
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
$effect(() => {
|
|
1218
|
+
const host = hostElement;
|
|
1219
|
+
if (!host) {
|
|
1220
|
+
hasRootAccessory = false;
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
const update = () => {
|
|
1225
|
+
hasRootAccessory = Array.from(host.children).some((child) => {
|
|
1226
|
+
if (!(child instanceof HTMLElement)) return false;
|
|
1227
|
+
return !child.matches(
|
|
1228
|
+
".snowui-input-control, .snowui-input-control-native, .snowui-input-date-editor",
|
|
1229
|
+
);
|
|
1230
|
+
});
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
update();
|
|
1234
|
+
|
|
1235
|
+
const observer = new MutationObserver(update);
|
|
1236
|
+
observer.observe(host, {
|
|
1237
|
+
childList: true,
|
|
1238
|
+
subtree: false,
|
|
1239
|
+
attributes: true,
|
|
1240
|
+
attributeFilter: ["class", "data-as"],
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
return () => observer.disconnect();
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
$effect(() => {
|
|
1247
|
+
const host = hostElement;
|
|
1248
|
+
if (!host || !isCustomTemporalType) {
|
|
1249
|
+
hasTemporalTrigger = false;
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
const scope = host.parentElement;
|
|
1254
|
+
if (!(scope instanceof HTMLElement)) {
|
|
1255
|
+
hasTemporalTrigger = false;
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
const update = () => {
|
|
1260
|
+
hasTemporalTrigger = Array.from(scope.children).some(
|
|
1261
|
+
(child) =>
|
|
1262
|
+
child instanceof HTMLElement &&
|
|
1263
|
+
child.matches(".snowui-button.snowui-role-trailing"),
|
|
1264
|
+
);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
update();
|
|
1268
|
+
queueMicrotask(update);
|
|
1269
|
+
|
|
1270
|
+
const observer = new MutationObserver(update);
|
|
1271
|
+
observer.observe(scope, {
|
|
1272
|
+
childList: true,
|
|
1273
|
+
subtree: true,
|
|
1274
|
+
attributes: true,
|
|
1275
|
+
attributeFilter: ["class"],
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
return () => {
|
|
1279
|
+
observer.disconnect();
|
|
1280
|
+
};
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
$effect(() => {
|
|
1284
|
+
const host = hostElement;
|
|
1285
|
+
if (!host) return;
|
|
1286
|
+
|
|
1287
|
+
const updateTrailing = () => {
|
|
1288
|
+
// 检测是否存在用户自定义的 trailing 元素 (排除内置的 stepper 按钮、Warning 和内置 clear 按钮)
|
|
1289
|
+
hasCustomTrailing = !!host.querySelector(
|
|
1290
|
+
'[data-as="trailing"]:not(.snowui-input-warning-icon):not(.snowui-input-clear-btn)',
|
|
1291
|
+
);
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
updateTrailing();
|
|
1295
|
+
const observer = new MutationObserver(updateTrailing);
|
|
1296
|
+
observer.observe(host, { childList: true, subtree: true });
|
|
1297
|
+
return () => observer.disconnect();
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
$effect(() => {
|
|
1301
|
+
const host = hostElement;
|
|
1302
|
+
if (!host || type !== "number") {
|
|
1303
|
+
hasCustomStepperUp = false;
|
|
1304
|
+
hasCustomStepperDown = false;
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
const update = () => {
|
|
1309
|
+
hasCustomStepperUp = !!host.querySelector(
|
|
1310
|
+
'[data-as="up"]:not(.snowui-input-stepper-btn)',
|
|
1311
|
+
);
|
|
1312
|
+
hasCustomStepperDown = !!host.querySelector(
|
|
1313
|
+
'[data-as="down"]:not(.snowui-input-stepper-btn)',
|
|
1314
|
+
);
|
|
1315
|
+
|
|
1316
|
+
// 绑定事件
|
|
1317
|
+
if (hasCustomStepperUp) {
|
|
1318
|
+
const btn = host.querySelector(
|
|
1319
|
+
'[data-as="up"]:not(.snowui-input-stepper-btn)',
|
|
1320
|
+
) as HTMLElement;
|
|
1321
|
+
btn.onclick = (e) => {
|
|
1322
|
+
e.preventDefault();
|
|
1323
|
+
handleStepUp();
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
if (hasCustomStepperDown) {
|
|
1327
|
+
const btn = host.querySelector(
|
|
1328
|
+
'[data-as="down"]:not(.snowui-input-stepper-btn)',
|
|
1329
|
+
) as HTMLElement;
|
|
1330
|
+
btn.onclick = (e) => {
|
|
1331
|
+
e.preventDefault();
|
|
1332
|
+
handleStepDown();
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
update();
|
|
1338
|
+
const observer = new MutationObserver(update);
|
|
1339
|
+
observer.observe(host, { childList: true, subtree: true });
|
|
1340
|
+
return () => observer.disconnect();
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
$effect(() => {
|
|
1344
|
+
if (!isCustomTemporalType || dateEditorFocused) return;
|
|
1345
|
+
const nextValue = getResolvedStringValue(resolvedValue);
|
|
1346
|
+
if (preserveDateDraftOnBlur && nextValue === lastResolvedDateValue) {
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
preserveDateDraftOnBlur = false;
|
|
1350
|
+
lastResolvedDateValue = nextValue;
|
|
1351
|
+
const nextDraft = parseDateValue(nextValue, temporalInputType);
|
|
1352
|
+
dateDraft = nextDraft;
|
|
1353
|
+
if (lastDateChangeValue === "") {
|
|
1354
|
+
lastDateChangeValue = nextValue;
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1358
|
+
$effect(() => {
|
|
1359
|
+
if (!autofocus || didApplyAutofocus) return;
|
|
1360
|
+
didApplyAutofocus = true;
|
|
1361
|
+
if (isCustomTemporalType) {
|
|
1362
|
+
requestAnimationFrame(() => {
|
|
1363
|
+
const firstSegment = getTemporalSegments(temporalInputType)[0];
|
|
1364
|
+
if (firstSegment) {
|
|
1365
|
+
focusDateSegment(firstSegment, false);
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
</script>
|
|
1371
|
+
|
|
1372
|
+
{#if rendersEmbeddedNativeHost}
|
|
1373
|
+
<div
|
|
1374
|
+
bind:this={hostElement}
|
|
1375
|
+
class={`snowui-input snowui-field-host${(hasRootAccessory || (resolvedInvalid && !hasCustomTrailing)) ? " snowui-input-has-root-accessory" : ""}${embeddedRoleClass ? ` ${embeddedRoleClass}` : ""}${userClass ? ` ${userClass}` : ""}`}
|
|
1376
|
+
data-auto-layout="true"
|
|
1377
|
+
data-as={typeof rest.as === "string" ? rest.as : undefined}
|
|
1378
|
+
data-embedded={isEmbedded ? "true" : undefined}
|
|
1379
|
+
data-has-root-accessory={(hasRootAccessory || (resolvedInvalid && !hasCustomTrailing))
|
|
1380
|
+
? "true"
|
|
1381
|
+
: undefined}
|
|
1382
|
+
data-has-value={hasClearableValue ? "true" : undefined}
|
|
1383
|
+
data-invalid={resolvedInvalid ? "true" : undefined}
|
|
1384
|
+
data-readonly={readonly ? "true" : undefined}
|
|
1385
|
+
data-input-type={normalizedInputType}
|
|
1386
|
+
data-requested-input-type={type !== normalizedInputType ? type : undefined}
|
|
1387
|
+
style={userStyle || undefined}
|
|
1388
|
+
>
|
|
1389
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
1390
|
+
<input
|
|
1391
|
+
{...inputRestProps}
|
|
1392
|
+
bind:this={nativeInputElement}
|
|
1393
|
+
class="snowui-input-control snowui-input-embedded-native"
|
|
1394
|
+
{id}
|
|
1395
|
+
type={normalizedInputType}
|
|
1396
|
+
{name}
|
|
1397
|
+
{placeholder}
|
|
1398
|
+
{disabled}
|
|
1399
|
+
{readonly}
|
|
1400
|
+
{required}
|
|
1401
|
+
{autocomplete}
|
|
1402
|
+
{minlength}
|
|
1403
|
+
maxlength={resolvedMaxlength}
|
|
1404
|
+
{pattern}
|
|
1405
|
+
{min}
|
|
1406
|
+
{max}
|
|
1407
|
+
{step}
|
|
1408
|
+
{inputmode}
|
|
1409
|
+
{enterkeyhint}
|
|
1410
|
+
{spellcheck}
|
|
1411
|
+
{list}
|
|
1412
|
+
{accept}
|
|
1413
|
+
{multiple}
|
|
1414
|
+
{capture}
|
|
1415
|
+
{form}
|
|
1416
|
+
{autofocus}
|
|
1417
|
+
{tabindex}
|
|
1418
|
+
{title}
|
|
1419
|
+
value={resolvedValue}
|
|
1420
|
+
aria-invalid={resolvedInvalid
|
|
1421
|
+
? "true"
|
|
1422
|
+
: inputRestProps["aria-invalid"]}
|
|
1423
|
+
onclick={userOnClick}
|
|
1424
|
+
ondblclick={userOnDoubleClick}
|
|
1425
|
+
oninput={handleInput}
|
|
1426
|
+
onchange={handleChange}
|
|
1427
|
+
onfocus={userOnFocus}
|
|
1428
|
+
onblur={userOnBlur}
|
|
1429
|
+
onkeydown={userOnKeyDown}
|
|
1430
|
+
onkeyup={userOnKeyUp}
|
|
1431
|
+
onkeypress={userOnKeyPress}
|
|
1432
|
+
onpaste={userOnPaste}
|
|
1433
|
+
oncopy={userOnCopy}
|
|
1434
|
+
oncut={userOnCut}
|
|
1435
|
+
/>
|
|
1436
|
+
{@render children?.()}
|
|
1437
|
+
{#if isClearableType && !disabled && !readonly}
|
|
1438
|
+
<button
|
|
1439
|
+
type="button"
|
|
1440
|
+
class="snowui-input-clear-btn"
|
|
1441
|
+
data-as="trailing"
|
|
1442
|
+
aria-label="清除输入"
|
|
1443
|
+
onclick={handleClear}
|
|
1444
|
+
onmousedown={(e) => e.preventDefault()}
|
|
1445
|
+
tabindex={-1}
|
|
1446
|
+
>
|
|
1447
|
+
<svg
|
|
1448
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
1449
|
+
viewBox="0 0 32 32"
|
|
1450
|
+
aria-hidden="true"
|
|
1451
|
+
focusable="false"
|
|
1452
|
+
>
|
|
1453
|
+
<path fill="currentColor" d="M16 3a13 13 0 1 0 13 13A13.013 13.013 0 0 0 16 3m4.708 16.293a1 1 0 0 1-1.415 1.415L16 17.414l-3.293 3.293a1 1 0 0 1-1.415-1.415L14.587 16l-3.293-3.293a1 1 0 1 1 1.415-1.415L16 14.587l3.293-3.293a1 1 0 0 1 1.415 1.415L17.414 16z"/>
|
|
1454
|
+
</svg>
|
|
1455
|
+
</button>
|
|
1456
|
+
{/if}
|
|
1457
|
+
{#if resolvedInvalid && !hasCustomTrailing}
|
|
1458
|
+
<span
|
|
1459
|
+
class="snowui-input-warning-icon snowui-role-trailing text-secondary-red"
|
|
1460
|
+
aria-hidden="true"
|
|
1461
|
+
>
|
|
1462
|
+
<Warning size={16} />
|
|
1463
|
+
</span>
|
|
1464
|
+
{/if}
|
|
1465
|
+
</div>
|
|
1466
|
+
{:else}
|
|
1467
|
+
<Frame
|
|
1468
|
+
bind:element={hostElement}
|
|
1469
|
+
tag="div"
|
|
1470
|
+
profile={isEmbedded ? "Container" : "Field"}
|
|
1471
|
+
class={`snowui-input${isEmbedded ? " snowui-field-host" : ""}${hasRootAccessory ? " snowui-input-has-root-accessory" : ""}${userClass ? ` ${userClass}` : ""}`}
|
|
1472
|
+
data-invalid={resolvedInvalid ? "true" : undefined}
|
|
1473
|
+
data-readonly={readonly ? "true" : undefined}
|
|
1474
|
+
data-input-type={normalizedInputType}
|
|
1475
|
+
data-requested-input-type={type !== normalizedInputType ? type : undefined}
|
|
1476
|
+
data-temporal-input={isCustomTemporalType ? "true" : undefined}
|
|
1477
|
+
data-temporal-empty={isTemporalValueEmpty ? "true" : undefined}
|
|
1478
|
+
data-has-temporal-trigger={hasTemporalTrigger ? "true" : undefined}
|
|
1479
|
+
data-embedded={isEmbedded ? "true" : undefined}
|
|
1480
|
+
data-has-root-accessory={hasRootAccessory ? "true" : undefined}
|
|
1481
|
+
data-has-value={hasClearableValue ? "true" : undefined}
|
|
1482
|
+
{disabled}
|
|
1483
|
+
style={userStyle || undefined}
|
|
1484
|
+
enableResponsive={enableResponsive}
|
|
1485
|
+
enableContext={enableContext}
|
|
1486
|
+
enableScaleObserver={enableScaleObserver}
|
|
1487
|
+
enableAutoLayout={internalAutoLayout}
|
|
1488
|
+
renderHints={inputRenderHints}
|
|
1489
|
+
{...frameRestProps}
|
|
1490
|
+
>
|
|
1491
|
+
{#if isCustomColorType}
|
|
1492
|
+
<div class="snowui-input-color-shell">
|
|
1493
|
+
<input
|
|
1494
|
+
{...inputRestProps}
|
|
1495
|
+
bind:this={nativeInputElement}
|
|
1496
|
+
class="snowui-input-control snowui-input-control-native snowui-input-control-color-native"
|
|
1497
|
+
{id}
|
|
1498
|
+
type="color"
|
|
1499
|
+
{name}
|
|
1500
|
+
disabled={disabled || readonly}
|
|
1501
|
+
{required}
|
|
1502
|
+
{autocomplete}
|
|
1503
|
+
{form}
|
|
1504
|
+
{tabindex}
|
|
1505
|
+
{title}
|
|
1506
|
+
value={colorDisplayValue}
|
|
1507
|
+
aria-invalid={resolvedInvalid
|
|
1508
|
+
? "true"
|
|
1509
|
+
: inputRestProps["aria-invalid"]}
|
|
1510
|
+
aria-readonly={readonly ? "true" : undefined}
|
|
1511
|
+
onclick={userOnClick}
|
|
1512
|
+
ondblclick={userOnDoubleClick}
|
|
1513
|
+
oninput={handleInput}
|
|
1514
|
+
onchange={handleChange}
|
|
1515
|
+
onfocus={userOnFocus}
|
|
1516
|
+
onblur={userOnBlur}
|
|
1517
|
+
onkeydown={userOnKeyDown}
|
|
1518
|
+
onkeyup={userOnKeyUp}
|
|
1519
|
+
onkeypress={userOnKeyPress}
|
|
1520
|
+
onpaste={userOnPaste}
|
|
1521
|
+
oncopy={userOnCopy}
|
|
1522
|
+
oncut={userOnCut}
|
|
1523
|
+
/>
|
|
1524
|
+
<div class="snowui-input-color-display" aria-hidden="true">
|
|
1525
|
+
<span
|
|
1526
|
+
class="snowui-input-color-swatch"
|
|
1527
|
+
style={`--snowui-input-color-swatch: ${colorDisplayValue};`}
|
|
1528
|
+
></span>
|
|
1529
|
+
<span class="snowui-input-color-text">
|
|
1530
|
+
<span class="snowui-input-color-prefix">#</span>
|
|
1531
|
+
<span class="snowui-input-color-value">{colorHexValue}</span
|
|
1532
|
+
>
|
|
1533
|
+
</span>
|
|
1534
|
+
</div>
|
|
1535
|
+
</div>
|
|
1536
|
+
{:else if isCustomTemporalType}
|
|
1537
|
+
<input
|
|
1538
|
+
{...inputRestProps}
|
|
1539
|
+
bind:this={nativeInputElement}
|
|
1540
|
+
class="snowui-input-control snowui-input-control-native snowui-input-control-date-native"
|
|
1541
|
+
{id}
|
|
1542
|
+
type={normalizedInputType}
|
|
1543
|
+
{name}
|
|
1544
|
+
{disabled}
|
|
1545
|
+
{readonly}
|
|
1546
|
+
{required}
|
|
1547
|
+
{autocomplete}
|
|
1548
|
+
{min}
|
|
1549
|
+
{max}
|
|
1550
|
+
{step}
|
|
1551
|
+
{form}
|
|
1552
|
+
tabindex={-1}
|
|
1553
|
+
{title}
|
|
1554
|
+
value={resolvedValue}
|
|
1555
|
+
aria-invalid={resolvedInvalid
|
|
1556
|
+
? "true"
|
|
1557
|
+
: inputRestProps["aria-invalid"]}
|
|
1558
|
+
aria-hidden="true"
|
|
1559
|
+
oninput={handleNativeDateInput}
|
|
1560
|
+
onchange={handleNativeDateChange}
|
|
1561
|
+
/>
|
|
1562
|
+
|
|
1563
|
+
<div
|
|
1564
|
+
class="snowui-input-date-editor"
|
|
1565
|
+
aria-disabled={disabled ? "true" : undefined}
|
|
1566
|
+
{title}
|
|
1567
|
+
role="textbox"
|
|
1568
|
+
tabindex="-1"
|
|
1569
|
+
onkeydown={(e) => {
|
|
1570
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1571
|
+
e.preventDefault();
|
|
1572
|
+
focusDateSegment(getTemporalSegments(temporalInputType)[0]);
|
|
1573
|
+
}
|
|
1574
|
+
}}
|
|
1575
|
+
onclick={handleDateEditorClick}
|
|
1576
|
+
>
|
|
1577
|
+
{#each getTemporalSegments(temporalInputType) as segment, index}
|
|
1578
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1579
|
+
<span
|
|
1580
|
+
class="snowui-input-date-segment-shell"
|
|
1581
|
+
data-active={activeDateSegment === segment
|
|
1582
|
+
? "true"
|
|
1583
|
+
: undefined}
|
|
1584
|
+
onmousedown={(event) =>
|
|
1585
|
+
handleDateSegmentMouseDown(segment, event)}
|
|
1586
|
+
>
|
|
1587
|
+
<span
|
|
1588
|
+
class="snowui-input-date-segment"
|
|
1589
|
+
data-segment={segment}
|
|
1590
|
+
role="spinbutton"
|
|
1591
|
+
aria-label={getTemporalAriaLabel(segment)}
|
|
1592
|
+
aria-valuetext={formatDateSegmentDisplayValue(
|
|
1593
|
+
segment,
|
|
1594
|
+
dateDraft[segment],
|
|
1595
|
+
)}
|
|
1596
|
+
data-placeholder={!dateDraft[segment]
|
|
1597
|
+
? "true"
|
|
1598
|
+
: undefined}
|
|
1599
|
+
tabindex={disabled ? undefined : (tabindex ?? 0)}
|
|
1600
|
+
onmousedown={(event) =>
|
|
1601
|
+
handleDateSegmentMouseDown(segment, event)}
|
|
1602
|
+
onclick={(event) =>
|
|
1603
|
+
handleDateSegmentClick(segment, event)}
|
|
1604
|
+
ondblclick={userOnDoubleClick}
|
|
1605
|
+
onfocus={(event) =>
|
|
1606
|
+
handleDateSegmentFocus(segment, event)}
|
|
1607
|
+
onblur={handleDateSegmentBlur}
|
|
1608
|
+
onkeydown={(event) =>
|
|
1609
|
+
handleDateSegmentKeyDown(segment, event)}
|
|
1610
|
+
onkeyup={userOnKeyUp}
|
|
1611
|
+
onkeypress={userOnKeyPress}
|
|
1612
|
+
onpaste={(event) =>
|
|
1613
|
+
handleDateSegmentPaste(segment, event)}
|
|
1614
|
+
oncopy={userOnCopy}
|
|
1615
|
+
oncut={userOnCut}
|
|
1616
|
+
>
|
|
1617
|
+
{formatDateSegmentDisplayValue(
|
|
1618
|
+
segment,
|
|
1619
|
+
dateDraft[segment],
|
|
1620
|
+
)}
|
|
1621
|
+
</span>
|
|
1622
|
+
</span>
|
|
1623
|
+
{#if index < getTemporalSegments(temporalInputType).length - 1}
|
|
1624
|
+
<span class="snowui-input-date-separator"
|
|
1625
|
+
>{TEMPORAL_SEPARATOR_AFTER[segment] ?? "/"}</span
|
|
1626
|
+
>
|
|
1627
|
+
{/if}
|
|
1628
|
+
{/each}
|
|
1629
|
+
{#if !hasTemporalTrigger}
|
|
1630
|
+
<button
|
|
1631
|
+
type="button"
|
|
1632
|
+
class="snowui-input-date-trigger"
|
|
1633
|
+
aria-label={getTemporalTriggerLabel(temporalInputType)}
|
|
1634
|
+
onmousedown={(event) => event.preventDefault()}
|
|
1635
|
+
onclick={tryOpenNativeTemporalPicker}
|
|
1636
|
+
{disabled}
|
|
1637
|
+
tabindex={disabled ? undefined : -1}
|
|
1638
|
+
>
|
|
1639
|
+
<TemporalDefaultIcon />
|
|
1640
|
+
</button>
|
|
1641
|
+
{/if}
|
|
1642
|
+
</div>
|
|
1643
|
+
{:else}
|
|
1644
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
1645
|
+
<input
|
|
1646
|
+
{...inputRestProps}
|
|
1647
|
+
bind:this={nativeInputElement}
|
|
1648
|
+
class="snowui-input-control"
|
|
1649
|
+
{id}
|
|
1650
|
+
type={normalizedInputType}
|
|
1651
|
+
{name}
|
|
1652
|
+
{placeholder}
|
|
1653
|
+
{disabled}
|
|
1654
|
+
{readonly}
|
|
1655
|
+
{required}
|
|
1656
|
+
{autocomplete}
|
|
1657
|
+
{minlength}
|
|
1658
|
+
maxlength={resolvedMaxlength}
|
|
1659
|
+
{pattern}
|
|
1660
|
+
{min}
|
|
1661
|
+
{max}
|
|
1662
|
+
{step}
|
|
1663
|
+
{inputmode}
|
|
1664
|
+
{enterkeyhint}
|
|
1665
|
+
{spellcheck}
|
|
1666
|
+
{list}
|
|
1667
|
+
{accept}
|
|
1668
|
+
{multiple}
|
|
1669
|
+
{capture}
|
|
1670
|
+
{form}
|
|
1671
|
+
{autofocus}
|
|
1672
|
+
{tabindex}
|
|
1673
|
+
{title}
|
|
1674
|
+
value={resolvedValue}
|
|
1675
|
+
aria-invalid={resolvedInvalid
|
|
1676
|
+
? "true"
|
|
1677
|
+
: inputRestProps["aria-invalid"]}
|
|
1678
|
+
onclick={userOnClick}
|
|
1679
|
+
ondblclick={userOnDoubleClick}
|
|
1680
|
+
oninput={handleInput}
|
|
1681
|
+
onchange={handleChange}
|
|
1682
|
+
onfocus={userOnFocus}
|
|
1683
|
+
onblur={userOnBlur}
|
|
1684
|
+
onkeydown={(e) => { handleSearchKeydown(e); userOnKeyDown?.(e); }}
|
|
1685
|
+
onkeyup={userOnKeyUp}
|
|
1686
|
+
onkeypress={userOnKeyPress}
|
|
1687
|
+
onpaste={userOnPaste}
|
|
1688
|
+
oncopy={userOnCopy}
|
|
1689
|
+
oncut={userOnCut}
|
|
1690
|
+
/>
|
|
1691
|
+
{/if}
|
|
1692
|
+
|
|
1693
|
+
{#if normalizedInputType === "number"}
|
|
1694
|
+
<div
|
|
1695
|
+
class="snowui-input-stepper"
|
|
1696
|
+
data-custom={hasCustomStepperUp || hasCustomStepperDown
|
|
1697
|
+
? "true"
|
|
1698
|
+
: undefined}
|
|
1699
|
+
>
|
|
1700
|
+
{#if !hasCustomStepperUp}
|
|
1701
|
+
<button
|
|
1702
|
+
type="button"
|
|
1703
|
+
class="snowui-input-stepper-btn"
|
|
1704
|
+
data-as="up"
|
|
1705
|
+
aria-label="增加数值"
|
|
1706
|
+
disabled={stepUpDisabled}
|
|
1707
|
+
onclick={handleStepUp}
|
|
1708
|
+
onmousedown={(e) => e.preventDefault()}
|
|
1709
|
+
>
|
|
1710
|
+
<ArrowLineUp2 />
|
|
1711
|
+
</button>
|
|
1712
|
+
{/if}
|
|
1713
|
+
{#if !hasCustomStepperDown}
|
|
1714
|
+
<button
|
|
1715
|
+
type="button"
|
|
1716
|
+
class="snowui-input-stepper-btn"
|
|
1717
|
+
data-as="down"
|
|
1718
|
+
aria-label="减少数值"
|
|
1719
|
+
disabled={stepDownDisabled}
|
|
1720
|
+
onclick={handleStepDown}
|
|
1721
|
+
onmousedown={(e) => e.preventDefault()}
|
|
1722
|
+
>
|
|
1723
|
+
<ArrowLineDown2 />
|
|
1724
|
+
</button>
|
|
1725
|
+
{/if}
|
|
1726
|
+
{@render children?.()}
|
|
1727
|
+
{#if resolvedInvalid && !hasCustomTrailing}
|
|
1728
|
+
<span
|
|
1729
|
+
class="snowui-input-warning-icon snowui-role-trailing text-secondary-red"
|
|
1730
|
+
aria-hidden="true"
|
|
1731
|
+
>
|
|
1732
|
+
<Warning size={16} />
|
|
1733
|
+
</span>
|
|
1734
|
+
{/if}
|
|
1735
|
+
</div>
|
|
1736
|
+
{:else}
|
|
1737
|
+
{@render children?.()}
|
|
1738
|
+
{#if isClearableType && !disabled && !readonly}
|
|
1739
|
+
<button
|
|
1740
|
+
type="button"
|
|
1741
|
+
class="snowui-input-clear-btn"
|
|
1742
|
+
data-as="trailing"
|
|
1743
|
+
aria-label="清除输入"
|
|
1744
|
+
onclick={handleClear}
|
|
1745
|
+
onmousedown={(e) => e.preventDefault()}
|
|
1746
|
+
tabindex={-1}
|
|
1747
|
+
>
|
|
1748
|
+
<svg
|
|
1749
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
1750
|
+
viewBox="0 0 32 32"
|
|
1751
|
+
aria-hidden="true"
|
|
1752
|
+
focusable="false"
|
|
1753
|
+
>
|
|
1754
|
+
<path fill="currentColor" d="M16 3a13 13 0 1 0 13 13A13.013 13.013 0 0 0 16 3m4.708 16.293a1 1 0 0 1-1.415 1.415L16 17.414l-3.293 3.293a1 1 0 0 1-1.415-1.415L14.587 16l-3.293-3.293a1 1 0 1 1 1.415-1.415L16 14.587l3.293-3.293a1 1 0 0 1 1.415 1.415L17.414 16z"/>
|
|
1755
|
+
</svg>
|
|
1756
|
+
</button>
|
|
1757
|
+
{/if}
|
|
1758
|
+
{#if resolvedInvalid && !hasCustomTrailing}
|
|
1759
|
+
<span
|
|
1760
|
+
class="snowui-input-warning-icon snowui-role-trailing text-secondary-red"
|
|
1761
|
+
aria-hidden="true"
|
|
1762
|
+
>
|
|
1763
|
+
<Warning size={16} />
|
|
1764
|
+
</span>
|
|
1765
|
+
{/if}
|
|
1766
|
+
{/if}
|
|
1767
|
+
</Frame>
|
|
1768
|
+
{/if}
|
|
1769
|
+
|
|
1770
|
+
<style>
|
|
1771
|
+
:global(:where(.snowui-input)) {
|
|
1772
|
+
display: flex;
|
|
1773
|
+
flex-direction: row;
|
|
1774
|
+
flex-wrap: nowrap;
|
|
1775
|
+
align-items: center;
|
|
1776
|
+
position: relative;
|
|
1777
|
+
--snowui-input-width: 100%;
|
|
1778
|
+
--snowui-input-height: auto;
|
|
1779
|
+
--snowui-input-radius: var(--radius-4);
|
|
1780
|
+
--snowui-input-background: var(--surface-1, #ffffffcc);
|
|
1781
|
+
--snowui-input-padding-y: var(--padding-3); /* 12px */
|
|
1782
|
+
--snowui-input-padding-x: var(--padding-4); /* 16px */
|
|
1783
|
+
--snowui-input-gap: var(--gap-2);
|
|
1784
|
+
--snowui-input-font-size: var(--text-14);
|
|
1785
|
+
--snowui-input-line-height: var(--leading-14);
|
|
1786
|
+
--snowui-input-placeholder-color: var(--black-20, #00000033);
|
|
1787
|
+
--snowui-input-warning-icon-color: var(--secondary-red, #ff4747ff);
|
|
1788
|
+
--snowui-input-warning-icon-size: var(--size-4);
|
|
1789
|
+
--snowui-input-warning-icon-line-height: 1;
|
|
1790
|
+
--snowui-input-stepper-button-size: var(--size-4); /* 16px */
|
|
1791
|
+
--snowui-input-stepper-icon-size: var(--size-4);
|
|
1792
|
+
width: var(--snowui-input-width-override, var(--snowui-input-width));
|
|
1793
|
+
height: var(
|
|
1794
|
+
--snowui-input-height-override,
|
|
1795
|
+
var(--snowui-input-height)
|
|
1796
|
+
);
|
|
1797
|
+
min-width: 0;
|
|
1798
|
+
gap: var(--snowui-input-gap-override, var(--snowui-input-gap));
|
|
1799
|
+
padding: var(--snowui-input-padding-y) var(--snowui-input-padding-x);
|
|
1800
|
+
border-radius: var(
|
|
1801
|
+
--snowui-input-radius-override,
|
|
1802
|
+
var(--snowui-input-radius)
|
|
1803
|
+
);
|
|
1804
|
+
background-color: var(
|
|
1805
|
+
--snowui-input-background-override,
|
|
1806
|
+
var(--snowui-input-background)
|
|
1807
|
+
);
|
|
1808
|
+
box-sizing: border-box;
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
/* 所有嵌入态 Input 外层 div 不持有自身 padding,避免与内层 control 的 override padding 叠加 */
|
|
1812
|
+
:global(:where(.snowui-input[data-embedded="true"])) {
|
|
1813
|
+
padding: 0;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/* 非 segment 嵌入态(单宿主模式):高度收敛到行高,保持内联视觉 */
|
|
1817
|
+
:global(.snowui-input[data-embedded="true"]:not(.snowui-role-segment)) {
|
|
1818
|
+
height: var(
|
|
1819
|
+
--snowui-input-line-height-override,
|
|
1820
|
+
var(--snowui-input-line-height)
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
:global(:where(.snowui-input-embedded-native)) {
|
|
1825
|
+
display: block;
|
|
1826
|
+
width: 100%;
|
|
1827
|
+
min-width: 0;
|
|
1828
|
+
border-radius: 0;
|
|
1829
|
+
background-color: transparent;
|
|
1830
|
+
box-shadow: none;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
:global(:where(.snowui-input-stepper)) {
|
|
1834
|
+
display: flex;
|
|
1835
|
+
flex-direction: column;
|
|
1836
|
+
align-items: center;
|
|
1837
|
+
justify-content: center;
|
|
1838
|
+
padding: var(--snowui-input-padding-y) var(--snowui-input-padding-x)
|
|
1839
|
+
var(--snowui-input-padding-y) 0;
|
|
1840
|
+
box-sizing: border-box;
|
|
1841
|
+
z-index: 2;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
:global(:where(.snowui-input-stepper-btn)) {
|
|
1845
|
+
display: flex;
|
|
1846
|
+
align-items: center;
|
|
1847
|
+
justify-content: center;
|
|
1848
|
+
width: var(--snowui-input-stepper-button-size);
|
|
1849
|
+
height: var(--snowui-input-stepper-button-size);
|
|
1850
|
+
min-width: var(--snowui-input-stepper-button-size);
|
|
1851
|
+
min-height: var(--snowui-input-stepper-button-size);
|
|
1852
|
+
padding: 0;
|
|
1853
|
+
border: none;
|
|
1854
|
+
border-radius: var(--radius-full);
|
|
1855
|
+
background: transparent;
|
|
1856
|
+
color: var(--black-100, #000000ff);
|
|
1857
|
+
opacity: var(--snowui-state-opacity, 0.4);
|
|
1858
|
+
cursor: pointer;
|
|
1859
|
+
transition:
|
|
1860
|
+
color var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out),
|
|
1861
|
+
opacity var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out);
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
:global(:where(.snowui-input-stepper-btn:hover:not(:disabled))) {
|
|
1865
|
+
opacity: var(--snowui-state-opacity, 1);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
:global(:where(.snowui-input-stepper-btn:disabled)) {
|
|
1869
|
+
opacity: 0.4;
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
:global(:where(.snowui-input-stepper-btn svg)) {
|
|
1873
|
+
width: var(--snowui-input-stepper-icon-size);
|
|
1874
|
+
height: var(--snowui-input-stepper-icon-size);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
:global(
|
|
1878
|
+
:where(
|
|
1879
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
1880
|
+
> .snowui-input-stepper
|
|
1881
|
+
)
|
|
1882
|
+
)
|
|
1883
|
+
) {
|
|
1884
|
+
display: grid;
|
|
1885
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
1886
|
+
align-items: stretch;
|
|
1887
|
+
gap: var(--snowui-input-gap);
|
|
1888
|
+
padding: 0; /* Stepper 场景下由内部控制 Padding */
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
:global(
|
|
1892
|
+
:where(
|
|
1893
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
1894
|
+
:has(> .snowui-input-stepper)
|
|
1895
|
+
)
|
|
1896
|
+
)
|
|
1897
|
+
) {
|
|
1898
|
+
display: grid;
|
|
1899
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
1900
|
+
align-items: center;
|
|
1901
|
+
gap: var(--snowui-input-gap);
|
|
1902
|
+
box-sizing: border-box;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
:global(
|
|
1906
|
+
:where(
|
|
1907
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
1908
|
+
[data-embedded="true"]
|
|
1909
|
+
):not(:focus-within):has(> .snowui-input-clear-btn):not(
|
|
1910
|
+
:has(
|
|
1911
|
+
> [data-as="leading"],
|
|
1912
|
+
> [data-as="trailing"]:not(
|
|
1913
|
+
.snowui-input-clear-btn
|
|
1914
|
+
),
|
|
1915
|
+
> .snowui-input-warning-icon,
|
|
1916
|
+
> .snowui-input-stepper
|
|
1917
|
+
)
|
|
1918
|
+
)
|
|
1919
|
+
)
|
|
1920
|
+
) {
|
|
1921
|
+
gap: 0;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
:global(
|
|
1925
|
+
:where(
|
|
1926
|
+
.snowui-input[data-embedded="true"][data-has-root-accessory="true"]:not(
|
|
1927
|
+
:focus-within
|
|
1928
|
+
):has(
|
|
1929
|
+
> .snowui-input-clear-btn
|
|
1930
|
+
):not(
|
|
1931
|
+
:has(
|
|
1932
|
+
> [data-as="leading"],
|
|
1933
|
+
> [data-as="trailing"]:not(
|
|
1934
|
+
.snowui-input-clear-btn
|
|
1935
|
+
),
|
|
1936
|
+
> .snowui-input-warning-icon,
|
|
1937
|
+
> .snowui-input-stepper
|
|
1938
|
+
)
|
|
1939
|
+
)
|
|
1940
|
+
)
|
|
1941
|
+
) {
|
|
1942
|
+
gap: 0;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
:global(
|
|
1946
|
+
:where(
|
|
1947
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
1948
|
+
:has(> .snowui-input-stepper)
|
|
1949
|
+
)[data-embedded="true"]
|
|
1950
|
+
)
|
|
1951
|
+
) {
|
|
1952
|
+
display: grid;
|
|
1953
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
1954
|
+
align-items: center;
|
|
1955
|
+
gap: var(--snowui-input-gap);
|
|
1956
|
+
box-sizing: border-box;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
:global(
|
|
1960
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
1961
|
+
:has(> .snowui-input-stepper)
|
|
1962
|
+
):has(> [data-as="leading"]):not(:has(> [data-as="trailing"]))
|
|
1963
|
+
) {
|
|
1964
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
1965
|
+
gap: var(--snowui-input-gap);
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
:global(
|
|
1969
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
1970
|
+
:has(> .snowui-input-stepper)
|
|
1971
|
+
):has(> [data-as="leading"]):has(> [data-as="trailing"])
|
|
1972
|
+
) {
|
|
1973
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
1974
|
+
gap: var(--snowui-input-gap);
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
:global(
|
|
1978
|
+
:where(
|
|
1979
|
+
.snowui-input:not([data-has-root-accessory="true"]):not(
|
|
1980
|
+
[data-embedded="true"]
|
|
1981
|
+
)
|
|
1982
|
+
)
|
|
1983
|
+
) {
|
|
1984
|
+
display: block;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
/* 独立模式:外层 div 已承载 padding,内层 control 归零避免双重叠加 */
|
|
1988
|
+
:global(
|
|
1989
|
+
.snowui-input:not([data-has-root-accessory="true"]):not(
|
|
1990
|
+
[data-embedded="true"]
|
|
1991
|
+
)
|
|
1992
|
+
> .snowui-input-control
|
|
1993
|
+
) {
|
|
1994
|
+
padding: 0;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
:global(
|
|
1998
|
+
:where(
|
|
1999
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
2000
|
+
> .snowui-input-stepper
|
|
2001
|
+
)
|
|
2002
|
+
> .snowui-input-control,
|
|
2003
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
2004
|
+
> .snowui-input-stepper
|
|
2005
|
+
)
|
|
2006
|
+
> .snowui-input-color-shell,
|
|
2007
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
2008
|
+
> .snowui-input-stepper
|
|
2009
|
+
)
|
|
2010
|
+
> .snowui-input-date-editor
|
|
2011
|
+
)
|
|
2012
|
+
) {
|
|
2013
|
+
grid-column: 1;
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
:global(
|
|
2017
|
+
:where(
|
|
2018
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
2019
|
+
> .snowui-input-stepper
|
|
2020
|
+
)
|
|
2021
|
+
> .snowui-input-stepper
|
|
2022
|
+
)
|
|
2023
|
+
) {
|
|
2024
|
+
grid-column: 2;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
:global(
|
|
2028
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2029
|
+
:has(> .snowui-input-stepper)
|
|
2030
|
+
)
|
|
2031
|
+
> :is(
|
|
2032
|
+
.snowui-input-control,
|
|
2033
|
+
.snowui-input-color-shell,
|
|
2034
|
+
.snowui-input-date-editor
|
|
2035
|
+
)
|
|
2036
|
+
) {
|
|
2037
|
+
grid-row: 1;
|
|
2038
|
+
grid-column: 1;
|
|
2039
|
+
min-width: 0;
|
|
2040
|
+
padding: 0;
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
:global(
|
|
2044
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2045
|
+
:has(> .snowui-input-stepper)
|
|
2046
|
+
):has(> [data-as="leading"])
|
|
2047
|
+
> :is(
|
|
2048
|
+
.snowui-input-control,
|
|
2049
|
+
.snowui-input-color-shell,
|
|
2050
|
+
.snowui-input-date-editor
|
|
2051
|
+
)
|
|
2052
|
+
) {
|
|
2053
|
+
grid-column: 2;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
:global(
|
|
2057
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2058
|
+
:has(> .snowui-input-stepper)
|
|
2059
|
+
)
|
|
2060
|
+
> [data-as="trailing"]:not(.snowui-input-clear-btn)
|
|
2061
|
+
) {
|
|
2062
|
+
grid-row: 1;
|
|
2063
|
+
grid-column: -2 / -1;
|
|
2064
|
+
display: inline-flex;
|
|
2065
|
+
align-items: center;
|
|
2066
|
+
justify-content: center;
|
|
2067
|
+
gap: var(--snowui-input-gap);
|
|
2068
|
+
min-width: 0;
|
|
2069
|
+
white-space: nowrap;
|
|
2070
|
+
line-height: inherit;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
/* 内建错误图标:红色 */
|
|
2074
|
+
:global(
|
|
2075
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2076
|
+
:has(> .snowui-input-stepper)
|
|
2077
|
+
)
|
|
2078
|
+
> .snowui-icon-wrapper.snowui-input-warning-icon
|
|
2079
|
+
) {
|
|
2080
|
+
color: var(--secondary-red, #ff4747ff);
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
/* 外部 trailing 槽:跟随输入文字颜色 */
|
|
2084
|
+
:global(
|
|
2085
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2086
|
+
:has(> .snowui-input-stepper)
|
|
2087
|
+
)
|
|
2088
|
+
> [data-as="trailing"]:not(.snowui-input-warning-icon):not(.snowui-input-clear-btn)
|
|
2089
|
+
) {
|
|
2090
|
+
color: currentColor;
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
:global(
|
|
2094
|
+
.snowui-input[data-has-root-accessory="true"]:has(
|
|
2095
|
+
> .snowui-input-warning-icon
|
|
2096
|
+
)
|
|
2097
|
+
> [data-as="trailing"]:not(.snowui-input-warning-icon):not(.snowui-input-clear-btn)
|
|
2098
|
+
) {
|
|
2099
|
+
display: none;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
:global(
|
|
2103
|
+
.snowui-input[data-has-root-accessory="true"]:not(
|
|
2104
|
+
:has(> .snowui-input-stepper)
|
|
2105
|
+
)
|
|
2106
|
+
> [data-as="leading"]
|
|
2107
|
+
) {
|
|
2108
|
+
grid-row: 1;
|
|
2109
|
+
grid-column: 1;
|
|
2110
|
+
display: inline-flex;
|
|
2111
|
+
align-items: center;
|
|
2112
|
+
justify-content: center;
|
|
2113
|
+
gap: var(--snowui-input-gap);
|
|
2114
|
+
min-width: 0;
|
|
2115
|
+
white-space: nowrap;
|
|
2116
|
+
color: var(--black-20, #00000033);
|
|
2117
|
+
line-height: inherit;
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
:global(:where(.snowui-input[data-embedded="true"])) {
|
|
2121
|
+
border-radius: 0;
|
|
2122
|
+
background-color: transparent;
|
|
2123
|
+
overflow: visible;
|
|
2124
|
+
--snowui-input-date-trigger-cover-background: var(
|
|
2125
|
+
--snowui-input-background-override,
|
|
2126
|
+
var(--snowui-input-background, var(--surface-1, #ffffffcc))
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
:global(
|
|
2131
|
+
:where(
|
|
2132
|
+
.snowui-input[data-readonly="true"]:not(
|
|
2133
|
+
[data-embedded="true"]
|
|
2134
|
+
)
|
|
2135
|
+
)
|
|
2136
|
+
) {
|
|
2137
|
+
background-color: var(--surface-2, #00000008);
|
|
2138
|
+
box-shadow: none;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
:global(
|
|
2142
|
+
:where(
|
|
2143
|
+
.snowui-field:has(
|
|
2144
|
+
.snowui-input.snowui-field-host[data-readonly="true"]
|
|
2145
|
+
)
|
|
2146
|
+
)
|
|
2147
|
+
) {
|
|
2148
|
+
background-color: var(--surface-2, #00000008);
|
|
2149
|
+
box-shadow: none;
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
:global(
|
|
2153
|
+
:where(
|
|
2154
|
+
.snowui-input[data-invalid="true"]:not(
|
|
2155
|
+
[data-embedded="true"]
|
|
2156
|
+
)
|
|
2157
|
+
)
|
|
2158
|
+
) {
|
|
2159
|
+
--snowui-field-border-color: var(--secondary-red, #ff4747ff);
|
|
2160
|
+
--snowui-field-hover-border-color: var(--secondary-red, #ff4747ff);
|
|
2161
|
+
--snowui-field-focus-border-color: var(--secondary-red, #ff4747ff);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
:global(:where(.snowui-input-control)) {
|
|
2167
|
+
display: block;
|
|
2168
|
+
flex: 1 1 auto;
|
|
2169
|
+
position: relative;
|
|
2170
|
+
z-index: 0;
|
|
2171
|
+
width: 100%;
|
|
2172
|
+
min-width: 0;
|
|
2173
|
+
height: auto;
|
|
2174
|
+
padding: var(
|
|
2175
|
+
--snowui-input-padding-override,
|
|
2176
|
+
var(--snowui-input-padding-y) var(--snowui-input-padding-x)
|
|
2177
|
+
);
|
|
2178
|
+
border: 0;
|
|
2179
|
+
outline: none;
|
|
2180
|
+
background: transparent;
|
|
2181
|
+
color: inherit;
|
|
2182
|
+
font-size: var(
|
|
2183
|
+
--snowui-input-font-size-override,
|
|
2184
|
+
var(--snowui-input-font-size)
|
|
2185
|
+
);
|
|
2186
|
+
line-height: var(
|
|
2187
|
+
--snowui-input-line-height-override,
|
|
2188
|
+
var(--snowui-input-line-height)
|
|
2189
|
+
);
|
|
2190
|
+
caret-color: currentColor;
|
|
2191
|
+
-webkit-appearance: none;
|
|
2192
|
+
appearance: none;
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
:global(:where(.snowui-input-control-native)) {
|
|
2196
|
+
position: absolute;
|
|
2197
|
+
inset: 0;
|
|
2198
|
+
width: 100%;
|
|
2199
|
+
height: 100%;
|
|
2200
|
+
padding: 0;
|
|
2201
|
+
margin: 0;
|
|
2202
|
+
opacity: 0;
|
|
2203
|
+
pointer-events: none;
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
:global(:where(.snowui-input-control-color-native)) {
|
|
2207
|
+
z-index: 1;
|
|
2208
|
+
pointer-events: auto;
|
|
2209
|
+
cursor: pointer;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
:global(:where(.snowui-input-control-color-native:disabled)) {
|
|
2213
|
+
cursor: default;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
:global(
|
|
2217
|
+
:where(
|
|
2218
|
+
.snowui-input-color-shell,
|
|
2219
|
+
.snowui-input-color-display,
|
|
2220
|
+
.snowui-input-date-editor
|
|
2221
|
+
)
|
|
2222
|
+
) {
|
|
2223
|
+
display: flex;
|
|
2224
|
+
align-items: center;
|
|
2225
|
+
flex: 1 1 auto;
|
|
2226
|
+
min-width: 0;
|
|
2227
|
+
width: 100%;
|
|
2228
|
+
position: relative;
|
|
2229
|
+
color: inherit;
|
|
2230
|
+
font-size: var(
|
|
2231
|
+
--snowui-input-font-size-override,
|
|
2232
|
+
var(--snowui-input-font-size)
|
|
2233
|
+
);
|
|
2234
|
+
line-height: var(
|
|
2235
|
+
--snowui-input-line-height-override,
|
|
2236
|
+
var(--snowui-input-line-height)
|
|
2237
|
+
);
|
|
2238
|
+
caret-color: currentColor;
|
|
2239
|
+
user-select: text;
|
|
2240
|
+
box-sizing: border-box;
|
|
2241
|
+
outline: none;
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
:global(:where(.snowui-input-date-editor)) {
|
|
2245
|
+
padding: 0;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
:global(:where(.snowui-input-color-shell)) {
|
|
2249
|
+
position: relative;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
:global(:where(.snowui-input-color-display)) {
|
|
2253
|
+
gap: var(--snowui-input-gap);
|
|
2254
|
+
padding: 0; /* 统一由 Frame 负责 Padding */
|
|
2255
|
+
pointer-events: none;
|
|
2256
|
+
user-select: none;
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
:global(:where(.snowui-input-color-text)) {
|
|
2260
|
+
display: inline-flex;
|
|
2261
|
+
align-items: center;
|
|
2262
|
+
gap: var(--gap-1);
|
|
2263
|
+
min-width: 0;
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
:global(:where(.snowui-input-color-prefix)) {
|
|
2267
|
+
color: var(--black-40, #00000066);
|
|
2268
|
+
-webkit-text-fill-color: var(--black-40, #00000066);
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
:global(:where(.snowui-input-color-value)) {
|
|
2272
|
+
color: var(--black-100, #000000);
|
|
2273
|
+
-webkit-text-fill-color: var(--black-100, #000000);
|
|
2274
|
+
white-space: nowrap;
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
:global(:where(.snowui-input-color-swatch)) {
|
|
2278
|
+
width: var(--size-4);
|
|
2279
|
+
height: var(--size-4);
|
|
2280
|
+
min-width: var(--size-4);
|
|
2281
|
+
min-height: var(--size-4);
|
|
2282
|
+
border-radius: var(--radius-full);
|
|
2283
|
+
background-color: var(--snowui-input-color-swatch, #000000);
|
|
2284
|
+
flex: 0 0 auto;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
:global(:where(.snowui-input-date-editor)) {
|
|
2288
|
+
gap: var(--gap-1);
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
:global(:where(.snowui-input-date-segment-shell)) {
|
|
2292
|
+
position: relative;
|
|
2293
|
+
display: inline-grid;
|
|
2294
|
+
align-items: center;
|
|
2295
|
+
width: max-content;
|
|
2296
|
+
min-width: 0;
|
|
2297
|
+
flex: 0 0 auto;
|
|
2298
|
+
margin: 0;
|
|
2299
|
+
padding: 0;
|
|
2300
|
+
border-radius: calc(var(--radius-1) * 1.5);
|
|
2301
|
+
background-color: transparent;
|
|
2302
|
+
isolation: isolate;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
:global(:where(.snowui-input-date-segment-shell:focus-within)) {
|
|
2306
|
+
background-color: var(
|
|
2307
|
+
--snowui-field-selection-bg,
|
|
2308
|
+
color-mix(
|
|
2309
|
+
in srgb,
|
|
2310
|
+
var(--secondary-indigo, #5856d6ff) 40%,
|
|
2311
|
+
transparent
|
|
2312
|
+
)
|
|
2313
|
+
);
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
:global(:where(.snowui-input-date-segment-shell[data-active="true"])) {
|
|
2317
|
+
background-color: var(
|
|
2318
|
+
--snowui-field-selection-bg,
|
|
2319
|
+
color-mix(
|
|
2320
|
+
in srgb,
|
|
2321
|
+
var(--secondary-indigo, #5856d6ff) 40%,
|
|
2322
|
+
transparent
|
|
2323
|
+
)
|
|
2324
|
+
);
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
:global(:where(.snowui-input-date-segment)) {
|
|
2328
|
+
display: inline-block;
|
|
2329
|
+
position: relative;
|
|
2330
|
+
z-index: 1;
|
|
2331
|
+
min-width: 0;
|
|
2332
|
+
padding: 0 calc(var(--padding-1) / 2);
|
|
2333
|
+
margin: 0;
|
|
2334
|
+
border: 0;
|
|
2335
|
+
background: transparent;
|
|
2336
|
+
color: var(--black-100, #000000);
|
|
2337
|
+
-webkit-text-fill-color: var(--black-100, #000000);
|
|
2338
|
+
text-align: left;
|
|
2339
|
+
border-radius: calc(var(--radius-1) * 1.5);
|
|
2340
|
+
outline: none;
|
|
2341
|
+
white-space: nowrap;
|
|
2342
|
+
user-select: none;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
:global(:where(.snowui-input-date-separator)) {
|
|
2346
|
+
color: var(--black-10, #0000001a);
|
|
2347
|
+
-webkit-text-fill-color: var(--black-10, #0000001a);
|
|
2348
|
+
user-select: none;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
:global(:where(.snowui-input-date-segment:focus)) {
|
|
2352
|
+
color: var(--black-100, #000000);
|
|
2353
|
+
-webkit-text-fill-color: var(--black-100, #000000);
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
:global(
|
|
2357
|
+
:where(.snowui-input-date-segment-shell:focus-within)
|
|
2358
|
+
.snowui-input-date-segment[data-placeholder="true"]
|
|
2359
|
+
) {
|
|
2360
|
+
color: var(--black-100, #000000);
|
|
2361
|
+
-webkit-text-fill-color: var(--black-100, #000000);
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
:global(
|
|
2365
|
+
:where(.snowui-input-date-segment-shell[data-active="true"])
|
|
2366
|
+
.snowui-input-date-segment[data-placeholder="true"]
|
|
2367
|
+
) {
|
|
2368
|
+
color: var(--black-100, #000000);
|
|
2369
|
+
-webkit-text-fill-color: var(--black-100, #000000);
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
:global(:where(.snowui-input-date-segment[data-placeholder="true"])) {
|
|
2373
|
+
color: var(--black-20, #00000033);
|
|
2374
|
+
-webkit-text-fill-color: var(--black-20, #00000033);
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
:global(:where(.snowui-input-date-separator)) {
|
|
2378
|
+
color: var(--black-20, #00000033);
|
|
2379
|
+
user-select: none;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
:global(:where(.snowui-input-date-trigger)) {
|
|
2383
|
+
display: inline-flex;
|
|
2384
|
+
align-items: center;
|
|
2385
|
+
justify-content: center;
|
|
2386
|
+
flex: 0 0 auto;
|
|
2387
|
+
position: absolute;
|
|
2388
|
+
top: 50%;
|
|
2389
|
+
right: 0;
|
|
2390
|
+
transform: translateY(-50%);
|
|
2391
|
+
padding: 0;
|
|
2392
|
+
border: 0;
|
|
2393
|
+
background: transparent;
|
|
2394
|
+
color: var(--black-100, #000000ff);
|
|
2395
|
+
opacity: var(--snowui-state-opacity, 0.4);
|
|
2396
|
+
cursor: pointer;
|
|
2397
|
+
transition:
|
|
2398
|
+
color var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out),
|
|
2399
|
+
opacity var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out);
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
:global(:where(.snowui-input-date-trigger:hover:not(:disabled))) {
|
|
2403
|
+
opacity: var(--snowui-state-opacity, 1);
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
:global(:where(.snowui-input-date-trigger:disabled)) {
|
|
2407
|
+
cursor: default;
|
|
2408
|
+
opacity: 0.48;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
:global(:where(.snowui-input-date-trigger svg)) {
|
|
2412
|
+
width: var(--size-4);
|
|
2413
|
+
height: var(--size-4);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
:global(:where(.snowui-input-warning-icon)) {
|
|
2417
|
+
display: inline-flex;
|
|
2418
|
+
flex: 0 0
|
|
2419
|
+
var(
|
|
2420
|
+
--snowui-input-warning-icon-size-override,
|
|
2421
|
+
var(--snowui-input-warning-icon-size, var(--size-4))
|
|
2422
|
+
);
|
|
2423
|
+
align-items: center;
|
|
2424
|
+
justify-content: center;
|
|
2425
|
+
color: var(
|
|
2426
|
+
--snowui-input-warning-icon-color-override,
|
|
2427
|
+
var(
|
|
2428
|
+
--snowui-input-warning-icon-color,
|
|
2429
|
+
var(--secondary-red, #ff4747ff)
|
|
2430
|
+
)
|
|
2431
|
+
);
|
|
2432
|
+
width: var(
|
|
2433
|
+
--snowui-input-warning-icon-size-override,
|
|
2434
|
+
var(--snowui-input-warning-icon-size, var(--size-4))
|
|
2435
|
+
);
|
|
2436
|
+
height: var(
|
|
2437
|
+
--snowui-input-warning-icon-size-override,
|
|
2438
|
+
var(--snowui-input-warning-icon-size, var(--size-4))
|
|
2439
|
+
);
|
|
2440
|
+
font-size: var(
|
|
2441
|
+
--snowui-input-warning-icon-font-size-override,
|
|
2442
|
+
var(--snowui-input-warning-icon-font-size)
|
|
2443
|
+
);
|
|
2444
|
+
line-height: var(
|
|
2445
|
+
--snowui-input-warning-icon-line-height-override,
|
|
2446
|
+
var(--snowui-input-warning-icon-line-height)
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
:global(:where(.snowui-input[data-has-root-accessory="true"] > .snowui-input-warning-icon)) {
|
|
2451
|
+
grid-row: 1;
|
|
2452
|
+
grid-column: -2 / -1;
|
|
2453
|
+
justify-self: center;
|
|
2454
|
+
align-self: center;
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
:global(:where(.snowui-input-warning-icon svg)) {
|
|
2458
|
+
display: block;
|
|
2459
|
+
width: 100%;
|
|
2460
|
+
height: 100%;
|
|
2461
|
+
flex: 0 0 auto;
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
:global(:where(.snowui-input-control::-webkit-input-placeholder)) {
|
|
2465
|
+
color: var(
|
|
2466
|
+
--snowui-input-placeholder-color-override,
|
|
2467
|
+
var(--snowui-input-placeholder-color)
|
|
2468
|
+
);
|
|
2469
|
+
-webkit-text-fill-color: var(
|
|
2470
|
+
--snowui-input-placeholder-color-override,
|
|
2471
|
+
var(--snowui-input-placeholder-color)
|
|
2472
|
+
);
|
|
2473
|
+
opacity: 1;
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
:global(:where(.snowui-input-control::-moz-placeholder)) {
|
|
2477
|
+
color: var(
|
|
2478
|
+
--snowui-input-placeholder-color-override,
|
|
2479
|
+
var(--snowui-input-placeholder-color)
|
|
2480
|
+
);
|
|
2481
|
+
opacity: 1;
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
:global(:where(.snowui-input-control:-ms-input-placeholder)) {
|
|
2485
|
+
color: var(
|
|
2486
|
+
--snowui-input-placeholder-color-override,
|
|
2487
|
+
var(--snowui-input-placeholder-color)
|
|
2488
|
+
);
|
|
2489
|
+
opacity: 1;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
:global(:where(.snowui-input-control::-ms-input-placeholder)) {
|
|
2493
|
+
color: var(
|
|
2494
|
+
--snowui-input-placeholder-color-override,
|
|
2495
|
+
var(--snowui-input-placeholder-color)
|
|
2496
|
+
);
|
|
2497
|
+
opacity: 1;
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
:global(:where(.snowui-input-control:placeholder-shown)) {
|
|
2501
|
+
color: var(
|
|
2502
|
+
--snowui-input-placeholder-color-override,
|
|
2503
|
+
var(--snowui-input-placeholder-color)
|
|
2504
|
+
);
|
|
2505
|
+
-webkit-text-fill-color: var(
|
|
2506
|
+
--snowui-input-placeholder-color-override,
|
|
2507
|
+
var(--snowui-input-placeholder-color)
|
|
2508
|
+
);
|
|
2509
|
+
caret-color: var(--black-100, #000000);
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
:global(
|
|
2513
|
+
:where(
|
|
2514
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2515
|
+
.snowui-input-control-native
|
|
2516
|
+
)
|
|
2517
|
+
) {
|
|
2518
|
+
color: var(--black-20, #00000033);
|
|
2519
|
+
-webkit-text-fill-color: var(--black-20, #00000033);
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
:global(
|
|
2523
|
+
:where(
|
|
2524
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2525
|
+
.snowui-input-control-native::-webkit-datetime-edit,
|
|
2526
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2527
|
+
.snowui-input-control-native::-webkit-datetime-edit-fields-wrapper,
|
|
2528
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2529
|
+
.snowui-input-control-native::-webkit-datetime-edit-text,
|
|
2530
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2531
|
+
.snowui-input-control-native::-webkit-datetime-edit-year-field,
|
|
2532
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2533
|
+
.snowui-input-control-native::-webkit-datetime-edit-month-field,
|
|
2534
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2535
|
+
.snowui-input-control-native::-webkit-datetime-edit-day-field,
|
|
2536
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2537
|
+
.snowui-input-control-native::-webkit-datetime-edit-week-field,
|
|
2538
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2539
|
+
.snowui-input-control-native::-webkit-datetime-edit-hour-field,
|
|
2540
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2541
|
+
.snowui-input-control-native::-webkit-datetime-edit-minute-field,
|
|
2542
|
+
.snowui-input[data-temporal-empty="true"]
|
|
2543
|
+
.snowui-input-control-native::-webkit-datetime-edit-second-field
|
|
2544
|
+
)
|
|
2545
|
+
) {
|
|
2546
|
+
color: var(--black-20, #00000033);
|
|
2547
|
+
-webkit-text-fill-color: var(--black-20, #00000033);
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
:global(:where(.snowui-input-control[type="search"])::-webkit-search-decoration),
|
|
2551
|
+
:global(:where(.snowui-input-control[type="search"])::-webkit-search-cancel-button),
|
|
2552
|
+
:global(:where(.snowui-input-control[type="search"])::-webkit-search-results-button),
|
|
2553
|
+
:global(:where(.snowui-input-control[type="search"])::-webkit-search-results-decoration) {
|
|
2554
|
+
-webkit-appearance: none;
|
|
2555
|
+
display: none;
|
|
2556
|
+
width: 0;
|
|
2557
|
+
height: 0;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
:global(
|
|
2561
|
+
:where(
|
|
2562
|
+
.snowui-input-control[type="number"]
|
|
2563
|
+
)::-webkit-outer-spin-button
|
|
2564
|
+
),
|
|
2565
|
+
:global(
|
|
2566
|
+
:where(
|
|
2567
|
+
.snowui-input-control[type="number"]
|
|
2568
|
+
)::-webkit-inner-spin-button
|
|
2569
|
+
) {
|
|
2570
|
+
-webkit-appearance: none;
|
|
2571
|
+
appearance: none;
|
|
2572
|
+
margin: 0;
|
|
2573
|
+
display: none;
|
|
2574
|
+
width: 0;
|
|
2575
|
+
height: 0;
|
|
2576
|
+
opacity: 0;
|
|
2577
|
+
pointer-events: none;
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
:global(:where(.snowui-input-control[type="number"])) {
|
|
2581
|
+
-webkit-appearance: textfield;
|
|
2582
|
+
-moz-appearance: textfield;
|
|
2583
|
+
appearance: textfield;
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
:global(:where(.snowui-input-control)::-webkit-calendar-picker-indicator) {
|
|
2587
|
+
opacity: 0.72;
|
|
2588
|
+
cursor: pointer;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/* datalist 绑定时隐藏浏览器默认下拉箭头 */
|
|
2592
|
+
:global(:where(.snowui-input-control[list])::-webkit-calendar-picker-indicator) {
|
|
2593
|
+
display: none;
|
|
2594
|
+
opacity: 0;
|
|
2595
|
+
width: 0;
|
|
2596
|
+
height: 0;
|
|
2597
|
+
-webkit-appearance: none;
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
:global(
|
|
2601
|
+
:where(
|
|
2602
|
+
.snowui-input[data-has-temporal-trigger="true"]
|
|
2603
|
+
.snowui-input-control
|
|
2604
|
+
)::-webkit-calendar-picker-indicator
|
|
2605
|
+
) {
|
|
2606
|
+
opacity: 0;
|
|
2607
|
+
display: none;
|
|
2608
|
+
visibility: hidden;
|
|
2609
|
+
-webkit-appearance: none;
|
|
2610
|
+
pointer-events: none;
|
|
2611
|
+
width: 0;
|
|
2612
|
+
height: 0;
|
|
2613
|
+
margin: 0;
|
|
2614
|
+
padding: 0;
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
:global(
|
|
2618
|
+
:where(
|
|
2619
|
+
.snowui-input[data-temporal-input="true"][data-has-temporal-trigger="true"]::after
|
|
2620
|
+
)
|
|
2621
|
+
) {
|
|
2622
|
+
content: "";
|
|
2623
|
+
position: absolute;
|
|
2624
|
+
top: 0;
|
|
2625
|
+
right: 0;
|
|
2626
|
+
bottom: 0;
|
|
2627
|
+
width: var(--snowui-input-date-trigger-cover-width);
|
|
2628
|
+
background-color: var(--snowui-input-date-trigger-cover-background);
|
|
2629
|
+
pointer-events: none;
|
|
2630
|
+
z-index: 1;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
:global(
|
|
2634
|
+
:where(
|
|
2635
|
+
.snowui-input[data-embedded="true"][data-temporal-input="true"][data-has-temporal-trigger="true"]::after
|
|
2636
|
+
)
|
|
2637
|
+
) {
|
|
2638
|
+
display: none;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
/* ─── Clear (X) 按钮 ─────────────────────────────────────── */
|
|
2642
|
+
|
|
2643
|
+
:global(:where(.snowui-input-clear-btn)) {
|
|
2644
|
+
display: none;
|
|
2645
|
+
grid-row: 1;
|
|
2646
|
+
grid-column: -2 / -1;
|
|
2647
|
+
justify-self: center;
|
|
2648
|
+
align-self: center;
|
|
2649
|
+
flex: 0 0 var(--size-4, 1rem);
|
|
2650
|
+
width: var(--size-4, 1rem);
|
|
2651
|
+
height: var(--size-4, 1rem);
|
|
2652
|
+
padding: 0;
|
|
2653
|
+
border: none;
|
|
2654
|
+
border-radius: var(--radius-full);
|
|
2655
|
+
background: transparent;
|
|
2656
|
+
color: var(--black-100, #000000ff);
|
|
2657
|
+
opacity: var(--snowui-state-opacity, 0.4);
|
|
2658
|
+
cursor: pointer;
|
|
2659
|
+
line-height: inherit;
|
|
2660
|
+
transition:
|
|
2661
|
+
color var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out),
|
|
2662
|
+
opacity var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out);
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
:global(:where(.snowui-input-clear-btn:hover)) {
|
|
2666
|
+
opacity: var(--snowui-state-opacity, 1);
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
:global(:where(.snowui-input-clear-btn svg)) {
|
|
2670
|
+
display: block;
|
|
2671
|
+
width: 100%;
|
|
2672
|
+
height: 100%;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
/* 独立 Input(非嵌入)焦点态 + 有内容 → 显示 X */
|
|
2676
|
+
:global(
|
|
2677
|
+
.snowui-input:not([data-embedded="true"])[data-has-value="true"]:focus-within
|
|
2678
|
+
.snowui-input-clear-btn
|
|
2679
|
+
) {
|
|
2680
|
+
display: inline-flex;
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
/* 嵌入在 Field 内的 Input:Input 焦点态 + 有内容 → 显示 X */
|
|
2684
|
+
:global(
|
|
2685
|
+
.snowui-input[data-embedded="true"][data-has-value="true"]:focus-within
|
|
2686
|
+
.snowui-input-clear-btn
|
|
2687
|
+
) {
|
|
2688
|
+
display: inline-flex;
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
/* X 可见时隐藏外置 trailing 图标(独立模式) */
|
|
2692
|
+
:global(
|
|
2693
|
+
.snowui-input:not([data-embedded="true"])[data-has-value="true"]:focus-within
|
|
2694
|
+
> [data-as="trailing"]:not(.snowui-input-clear-btn)
|
|
2695
|
+
) {
|
|
2696
|
+
display: none;
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/* X 可见时隐藏外置 trailing 图标(嵌入模式) */
|
|
2700
|
+
:global(
|
|
2701
|
+
.snowui-input[data-embedded="true"][data-has-value="true"]:focus-within
|
|
2702
|
+
> [data-as="trailing"]:not(.snowui-input-clear-btn)
|
|
2703
|
+
) {
|
|
2704
|
+
display: none;
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
|
|
2708
|
+
/* X 可见时隐藏内置 Warning 图标(独立模式) */
|
|
2709
|
+
:global(
|
|
2710
|
+
.snowui-input:not([data-embedded="true"])[data-has-value="true"]:focus-within
|
|
2711
|
+
> .snowui-input-warning-icon
|
|
2712
|
+
) {
|
|
2713
|
+
display: none;
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
/* X 可见时隐藏内置 Warning 图标(嵌入模式) */
|
|
2717
|
+
:global(
|
|
2718
|
+
.snowui-input[data-embedded="true"][data-has-value="true"]:focus-within
|
|
2719
|
+
> .snowui-input-warning-icon
|
|
2720
|
+
) {
|
|
2721
|
+
display: none;
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
/*
|
|
2725
|
+
* ─── Listbox 搜索框(as="search")─────────────────────────────────────
|
|
2726
|
+
* Listbox / QuickAction 都使用固定 header + 滚动 body 结构。
|
|
2727
|
+
* 选择器同时覆盖移位前(列表内)与移位后(header 内),确保视觉一致。
|
|
2728
|
+
*/
|
|
2729
|
+
:global(:where(.snowui-listbox-header > .snowui-input, .snowui-listbox > .snowui-input, .snowui-quick-action-header > .snowui-input, .snowui-quick-action-list > .snowui-input)) {
|
|
2730
|
+
--snowui-input-padding-y: var(--padding-2);
|
|
2731
|
+
--snowui-input-padding-x: var(--padding-2);
|
|
2732
|
+
--snowui-input-gap: var(--gap-2);
|
|
2733
|
+
--snowui-input-radius: var(--radius-3);
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
/* 焦点态:仅保留边框颜色变化,移除外扩阴影环 */
|
|
2737
|
+
:global(:where(.snowui-listbox-header > .snowui-input, .snowui-listbox > .snowui-input, .snowui-quick-action-header > .snowui-input, .snowui-quick-action-list > .snowui-input):focus-within) {
|
|
2738
|
+
--snowui-field-focus-ring-width: 0rem;
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
</style>
|