Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(timepicker): add tips and status apis #1830

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/time-picker/panel/single-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default defineComponent({
if (value.value) return dayjs(value.value, format.value);

if (isStepsSet) return dayjs().hour(0).minute(0).second(0);

return dayjs();
});

Expand All @@ -68,7 +67,7 @@ export default defineComponent({
watch(
() => dayjsValue.value,
() => {
if (dayjsValue.value) updateTimeScrollPos(true);
if (dayjsValue.value && value.value) updateTimeScrollPos(true);
},
);

Expand Down
15 changes: 9 additions & 6 deletions src/time-picker/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ export default {
presets: {
type: Object as PropType<TdTimePickerProps['presets']>,
},
/** 尺寸 */
size: {
type: String as PropType<TdTimePickerProps['size']>,
default: 'medium' as TdTimePickerProps['size'],
validator(val: TdTimePickerProps['size']): boolean {
/** 输入框状态 */
status: {
type: String as PropType<TdTimePickerProps['status']>,
validator(val: TdTimePickerProps['status']): boolean {
if (!val) return true;
return ['small', 'medium', 'large'].includes(val);
return ['default', 'success', 'warning', 'error'].includes(val);
},
},
/** 时间间隔步数,数组排列 [小时, 分钟, 秒],示例:[2, 1, 1] 或者 ['2', '1', '1'] */
steps: {
type: Array as PropType<TdTimePickerProps['steps']>,
default: (): TdTimePickerProps['steps'] => [1, 1, 1],
},
/** 输入框下方提示文本,会根据不同的 `status` 呈现不同的样式 */
tips: {
type: [String, Function] as PropType<TdTimePickerProps['tips']>,
},
/** 选中值 */
value: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions src/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export default defineComponent({
value: this.isShowPanel ? this.currentValue : this.innerValue ?? undefined,
inputValue: this.isShowPanel ? this.currentValue : this.innerValue ?? undefined,
inputProps: this.inputProps,
status: this.status,
tips: this.tips,
panel: () => (
<TimePickerPanel
{...{
Expand Down
15 changes: 9 additions & 6 deletions src/time-picker/time-range-picker-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ export default {
rangeInputProps: {
type: Object as PropType<TdTimeRangePickerProps['rangeInputProps']>,
},
/** 尺寸 */
size: {
type: String as PropType<TdTimeRangePickerProps['size']>,
default: 'medium' as TdTimeRangePickerProps['size'],
validator(val: TdTimeRangePickerProps['size']): boolean {
/** 输入框状态 */
status: {
type: String as PropType<TdTimeRangePickerProps['status']>,
validator(val: TdTimeRangePickerProps['status']): boolean {
if (!val) return true;
return ['small', 'medium', 'large'].includes(val);
return ['default', 'success', 'warning', 'error'].includes(val);
},
},
/** 时间间隔步数,数组排列 [小时, 分钟, 秒],示例:[2, 1, 1] 或者 ['2', '1', '1'] */
steps: {
type: Array as PropType<TdTimeRangePickerProps['steps']>,
default: (): TdTimeRangePickerProps['steps'] => [1, 1, 1],
},
/** 输入框下方提示文本,会根据不同的 `status` 呈现不同的样式 */
tips: {
type: [String, Function] as PropType<TdTimeRangePickerProps['tips']>,
},
/** 选中值 */
value: {
type: Array as PropType<TdTimeRangePickerProps['value']>,
Expand Down
2 changes: 2 additions & 0 deletions src/time-picker/time-range-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export default defineComponent({
onVisibleChange: this.handleShowPopup,
...this.popupProps,
},
status: this.status,
tips: this.tips,
rangeInputProps: {
size: this.size,
clearable: this.clearable,
Expand Down
19 changes: 13 additions & 6 deletions src/time-picker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { InputProps } from '../input';
import { PopupProps } from '../popup';
import { RangeInputProps } from '../range-input';
import { TNode } from '../common';

export interface TdTimePickerProps {
/**
Expand Down Expand Up @@ -59,15 +60,18 @@ export interface TdTimePickerProps {
*/
presets?: PresetTime;
/**
* 尺寸
* @default medium
* 输入框状态
*/
size?: 'small' | 'medium' | 'large';
status?: 'default' | 'success' | 'warning' | 'error';
/**
* 时间间隔步数,数组排列 [小时, 分钟, 秒],示例:[2, 1, 1] 或者 ['2', '1', '1']
* @default [1, 1, 1]
*/
steps?: Array<string | number>;
/**
* 输入框下方提示文本,会根据不同的 `status` 呈现不同的样式
*/
tips?: string | TNode;
/**
* 选中值
* @default ''
Expand Down Expand Up @@ -160,15 +164,18 @@ export interface TdTimeRangePickerProps {
*/
rangeInputProps?: RangeInputProps;
/**
* 尺寸
* @default medium
* 输入框状态
*/
size?: 'small' | 'medium' | 'large';
status?: 'default' | 'success' | 'warning' | 'error';
/**
* 时间间隔步数,数组排列 [小时, 分钟, 秒],示例:[2, 1, 1] 或者 ['2', '1', '1']
* @default [1, 1, 1]
*/
steps?: Array<string | number>;
/**
* 输入框下方提示文本,会根据不同的 `status` 呈现不同的样式
*/
tips?: string | TNode;
/**
* 选中值
*/
Expand Down