使用import { TimePicker } from 'antd'; |
当用户需要输入一个时间,可以点击标准输入框,弹出时间面板进行选择。
通用属性参考:通用属性
import dayjs from 'dayjs';import customParseFormat from 'dayjs/plugin/customParseFormat'dayjs.extend(customParseFormat)<TimePicker defaultValue={dayjs('13:30:56', 'HH:mm:ss')} />;
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| allowClear | 自定义清除按钮 | boolean | { clearIcon?: ReactNode } | true | 5.8.0: 支持对象类型 |
TimePicker 面板底部的附加内容渲染函数,请使用 renderExtraFooter 替代 | () => ReactNode | - | - | |
| cellRender | 自定义单元格的内容 | (current: number, info: { originNode: React.ReactNode, today: dayjs, range?: 'start' | 'end', subType: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode | - | 5.4.0 |
| changeOnScroll | 在滚动时改变选择值 | boolean | false | 5.14.0 |
| className | 选择器类名 | string | - | |
| classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | |
| defaultValue | 默认时间 | dayjs | - | |
| disabled | 禁用全部操作 | boolean | false | |
| disabledTime | 不可选择的时间 | DisabledTime | - | 4.19.0 |
| format | 展示的时间格式 | string | HH:mm:ss | |
| getPopupContainer | 定义浮层的容器,默认为 body 上新建 div | function(trigger) | - | |
| hideDisabledOptions | 隐藏禁止选择的选项 | boolean | false | |
| hourStep | 小时选项间隔 | number | 1 | |
| inputReadOnly | 设置输入框为只读(避免在移动设备上打开虚拟键盘) | boolean | false | |
| minuteStep | 分钟选项间隔 | number | 1 | |
| needConfirm | 是否需要确认按钮,为 false 时失去焦点即代表选择 | boolean | - | 5.14.0 |
| open | 面板是否打开 | boolean | false | |
| placeholder | 没有值的时候显示的内容 | string | [string, string] | 请选择时间 | |
| placement | 选择框弹出的位置 | bottomLeft bottomRight topLeft topRight | bottomLeft | |
弹出层类名,请使用 classNames.popup 替换 | string | - | ||
弹出层样式对象, 请使用 styles.popup 替换 | object | - | ||
| prefix | 自定义前缀 | ReactNode | - | 5.22.0 |
| previewValue | 当用户选择时间悬停选项时,输入字段的值会发生临时更改 | false | hover | hover | 6.0.0 |
| renderExtraFooter | 选择框底部显示自定义的内容 | () => ReactNode | - | |
| secondStep | 秒选项间隔 | number | 1 | |
| showNow | 面板是否显示“此刻”按钮 | boolean | - | 4.4.0 |
| size | 输入框大小,large 高度为 40px,small 为 24px,默认是 32px | large | medium | small | - | |
| status | 设置校验状态 | 'error' | 'warning' | - | 4.19.0 |
| styles | 用于自定义组件内部各语义化结构的行内 style,支持对象或函数 | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | |
| suffixIcon | 自定义的选择框后缀图标 | ReactNode | - | |
| use12Hours | 使用 12 小时制,为 true 时 format 默认为 h:mm:ss a | boolean | false | |
| value | 当前时间 | dayjs | - | |
| variant | 形态变体 | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 |
| onCalendarChange | 待选日期发生变化的回调。info 参数自 4.4.0 添加 | function(dates: [dayjs, dayjs], dateStrings: [string, string], info: { range:start|end }) | - | |
| onChange | 时间发生变化的回调 | function(time: dayjs, timeString: string): void | - | |
| onOpenChange | 面板打开/关闭时的回调 | (open: boolean) => void | - |
type DisabledTime = (now: Dayjs) => {disabledHours?: () => number[];disabledMinutes?: (selectedHour: number) => number[];disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];disabledMilliseconds?: (selectedHour: number,selectedMinute: number,selectedSecond: number,) => number[];};
注意:disabledMilliseconds 为 5.14.0 新增。
| 名称 | 描述 | 版本 |
|---|---|---|
| blur() | 移除焦点 | |
| focus() | 获取焦点 |
属性与 DatePicker 的 RangePicker 相同。还包含以下属性:
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| disabledTime | 不可选择的时间 | RangeDisabledTime | - | 4.19.0 |
| order | 始末时间是否自动排序 | boolean | true | 4.1.0 |
type RangeDisabledTime = (now: Dayjs,type = 'start' | 'end',) => {disabledHours?: () => number[];disabledMinutes?: (selectedHour: number) => number[];disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];};
| Token 名称 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| activeBg | 输入框激活状态时背景颜色 | string | #ffffff |
| activeBorderColor | 激活态边框色 | string | #1677ff |
| activeShadow | 激活态阴影 | string | 0 0 0 2px rgba(5,145,255,0.1) |
| addonBg | 前/后置标签背景色 | string | rgba(0,0,0,0.02) |
| cellActiveWithRangeBg | 选取范围内的单元格背景色 | string | #e6f4ff |
| cellBgDisabled | 单元格禁用态背景色 | string | rgba(0,0,0,0.04) |
| cellHeight | 单元格高度 | number | 24 |
| cellHoverBg | 单元格悬浮态背景色 | string | rgba(0,0,0,0.04) |
| cellHoverWithRangeBg | 选取范围内的单元格悬浮态背景色 | string | #cbe0fd |
| cellRangeBorderColor | 选取范围时单元格边框色 | string | #82b4f9 |
| cellWidth | 单元格宽度 | number | 36 |
| errorActiveShadow | 错误状态时激活态阴影 | string | 0 0 0 2px rgba(255,38,5,0.06) |
| hoverBg | 输入框hover状态时背景颜色 | string | #ffffff |
| hoverBorderColor | 悬浮态边框色 | string | #4096ff |
| inputFontSize | 字体大小 | number | 14 |
| inputFontSizeLG | 大号字体大小 | number | 16 |
| inputFontSizeSM | 小号字体大小 | number | 14 |
| multipleItemBg | 多选标签背景色 | string | rgba(0,0,0,0.06) |
| multipleItemBorderColor | 多选标签边框色 | string | transparent |
| multipleItemBorderColorDisabled | 多选标签禁用边框色 | string | transparent |
| multipleItemColorDisabled | 多选标签禁用文本颜色 | string | rgba(0,0,0,0.25) |
| multipleItemHeight | 多选标签高度 | number | 24 |
| multipleItemHeightLG | 大号多选标签高度 | number | 32 |
| multipleItemHeightSM | 小号多选标签高度 | number | 16 |
| multipleSelectorBgDisabled | 多选框禁用背景 | string | rgba(0,0,0,0.04) |
| paddingBlock | 输入框纵向内边距 | number | 4 |
| paddingBlockLG | 大号输入框纵向内边距 | number | 7 |
| paddingBlockSM | 小号输入框纵向内边距 | number | 0 |
| paddingInline | 输入框横向内边距 | number | 11 |
| paddingInlineLG | 大号输入框横向内边距 | number | 11 |
| paddingInlineSM | 小号输入框横向内边距 | number | 7 |
| presetsMaxWidth | 预设区域最大宽度 | number | 200 |
| presetsWidth | 预设区域宽度 | number | 120 |
| textHeight | 单元格文本高度 | number | 40 |
| timeCellHeight | 时间单元格高度 | number | 28 |
| timeColumnHeight | 时间列高度 | number | 224 |
| timeColumnWidth | 时间列宽度 | number | 56 |
| warningActiveShadow | 警告状态时激活态阴影 | string | 0 0 0 2px rgba(255,215,5,0.1) |
| withoutTimeCellHeight | 十年/年/季/月/周单元格高度 | number | 66 |
| zIndexPopup | 弹窗 z-index | number | 1050 |
| Token 名称 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| colorBgContainer | 组件的容器背景色,例如:默认按钮、输入框等。务必不要将其与 `colorBgElevated` 混淆。 | string | #ffffff |
| colorBgContainerDisabled | 控制容器在禁用状态下的背景色。 | string | rgba(0,0,0,0.04) |
| colorBgElevated | 浮层容器背景色,在暗色模式下该 token 的色值会比 `colorBgContainer` 要亮一些。例如:模态框、弹出框、菜单等。 | string | #ffffff |
| colorBorder | 默认使用的边框颜色, 用于分割不同的元素,例如:表单的分割线、卡片的分割线等。 | string | #d9d9d9 |
| colorBorderDisabled | 控制元素在禁用状态下的边框颜色。 | string | #d9d9d9 |
| colorError | 用于表示操作失败的 Token 序列,如失败按钮、错误状态提示(Result)组件等。 | string | #ff4d4f |
| colorErrorAffix | 控制表单控件前后缀在错误状态下的颜色。 | string | #ff4d4f |
| colorErrorBg | 错误色的浅色背景颜色 | string | #fff2f0 |
| colorErrorBgHover | 错误色的浅色背景色悬浮态 | string | #fff1f0 |
| colorErrorBorderHover | 错误色的描边色悬浮态 | string | #ffa39e |
| colorErrorText | 错误色的文本默认态 | string | #ff4d4f |
| colorFillSecondary | 二级填充色可以较为明显地勾勒出元素形体,如 Rate、Skeleton 等。也可以作为三级填充色的 Hover 状态,如 Table 等。 | string | rgba(0,0,0,0.06) |
| colorFillTertiary | 三级填充色用于勾勒出元素形体的场景,如 Slider、Segmented 等。如无强调需求的情况下,建议使用三级填色作为默认填色。 | string | rgba(0,0,0,0.04) |
| colorIcon | 控制弱操作图标的颜色,例如 allowClear 或 Alert 关闭按钮。 * | string | rgba(0,0,0,0.45) |
| colorIconHover | 控制弱操作图标在悬浮状态下的颜色,例如 allowClear 或 Alert 关闭按钮。 | string | rgba(0,0,0,0.88) |
| colorPrimary | 品牌色是体现产品特性和传播理念最直观的视觉元素之一。在你完成品牌主色的选取之后,我们会自动帮你生成一套完整的色板,并赋予它们有效的设计语义 | string | #1677ff |
| colorPrimaryBorder | 主色梯度下的描边用色,用在 Slider 等组件的描边上。 | string | #91caff |
| colorSplit | 用于作为分割线的颜色,此颜色和 colorBorderSecondary 的颜色一致,但是用的是透明色。 | string | rgba(5,5,5,0.06) |
| colorText | 最深的文本色。为了符合W3C标准,默认的文本颜色使用了该色,同时这个颜色也是最深的中性色。 | string | rgba(0,0,0,0.88) |
| colorTextDisabled | 控制禁用状态下的字体颜色。 | string | rgba(0,0,0,0.25) |
| colorTextHeading | 控制标题字体颜色。 | string | rgba(0,0,0,0.88) |
| colorTextLightSolid | 控制带背景色的文本,例如 Primary Button 组件中的文本高亮颜色。 | string | #fff |
| colorTextPlaceholder | 控制占位文本的颜色。 | string | rgba(0,0,0,0.25) |
| colorTextQuaternary | 第四级文本色是最浅的文本色,例如表单的输入提示文本、禁用色文本等。 | string | rgba(0,0,0,0.25) |
| colorTextTertiary | 第三级文本色一般用于描述性文本,例如表单的中的补充说明文本、列表的描述性文本等场景。 | string | rgba(0,0,0,0.45) |
| colorWarning | 用于表示操作警告的 Token 序列,如 Notification、 Alert等警告类组件或 Input 输入类等组件会使用该组梯度变量。 | string | #faad14 |
| colorWarningAffix | 控制表单控件前后缀在警告状态下的颜色。 | string | #faad14 |
| colorWarningBg | 警戒色的浅色背景颜色 | string | #fffbe6 |
| colorWarningBgHover | 警戒色的浅色背景色悬浮态 | string | #fff1b8 |
| colorWarningBorderHover | 警戒色的描边色悬浮态 | string | #ffd666 |
| colorWarningText | 警戒色的文本默认态 | string | #faad14 |
| borderRadius | 基础组件的圆角大小,例如按钮、输入框、卡片等 | number | 6 |
| borderRadiusLG | LG号圆角,用于组件中的一些大圆角,如 Card、Modal 等一些组件样式。 | number | 8 |
| borderRadiusSM | SM号圆角,用于组件小尺寸下的圆角,如 Button、Input、Select 等输入类控件在 small size 下的圆角 | number | 4 |
| borderRadiusXS | XS号圆角,用于组件中的一些小圆角,如 Segmented 、Arrow 等一些内部圆角的组件样式中。 | number | 2 |
| boxShadowSecondary | 控制元素二级阴影样式。 | string | 0 6px 16px 0 rgba(0,0,0,0.08), 0 3px 6px -4px rgba(0,0,0,0.12), 0 9px 28px 8px rgba(0,0,0,0.05) |
| controlHeight | Ant Design 中按钮和输入框等基础控件的高度 | number | 32 |
| controlHeightLG | 较高的组件高度 | number | 40 |
| controlHeightSM | 较小的组件高度 | number | 24 |
| controlItemBgActive | 控制组件项在激活状态下的背景颜色。 | string | #e6f4ff |
| fontFamily | Ant Design 的字体家族中优先使用系统默认的界面字体,同时提供了一套利于屏显的备用字体库,来维护在不同平台以及浏览器的显示下,字体始终保持良好的易读性和可读性,体现了友好、稳定和专业的特性。 | string | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji' |
| fontSize | 设计系统中使用最广泛的字体大小,文本梯度也将基于该字号进行派生。 | number | 14 |
| fontSizeLG | 大号字体大小 | number | 16 |
| fontSizeSM | 小号字体大小 | number | 12 |
| fontWeightStrong | 控制标题类组件(如 h1、h2、h3)或选中项的字体粗细。 | number | 600 |
| lineHeight | 文本行高 | number | 1.5714285714285714 |
| lineHeightLG | 大型文本行高 | number | 1.5 |
| lineType | 用于控制组件边框、分割线等的样式,默认是实线 | string | solid |
| lineWidth | 用于控制组件边框、分割线等的宽度 | number | 1 |
| lineWidthBold | 描边类组件的默认线宽,如 Button、Input、Select 等输入类控件。 | number | 2 |
| marginXS | 控制元素外边距,小尺寸。 | number | 8 |
| marginXXS | 控制元素外边距,最小尺寸。 | number | 4 |
| motionDurationMid | 动效播放速度,中速。用于中型元素动画交互 | string | 0.2s |
| motionDurationSlow | 动效播放速度,慢速。用于大型元素如面板动画交互 | string | 0.3s |
| motionEaseInOutCirc | 预设动效曲率 | string | |
| motionEaseInQuint | 预设动效曲率 | string | |
| motionEaseOutCirc | 预设动效曲率 | string | |
| motionEaseOutQuint | 预设动效曲率 | string | |
| padding | 控制元素的内间距。 | number | 16 |
| paddingSM | 控制元素的小内间距。 | number | 12 |
| paddingXS | 控制元素的特小内间距。 | number | 8 |
| paddingXXS | 控制元素的极小内间距。 | number | 4 |
| sizePopupArrow | 组件箭头的尺寸 | number | 16 |