Skip to content

Commit

Permalink
* datetime-picker: refactor and use readonly property.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Nov 24, 2023
1 parent 3e84e53 commit 627ec4c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/datetime-picker/src/component/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class DatePicker extends Pick<PickState, DatePickerOptions> {
};

setDate = (value: string) => {
const {onInvalid, defaultValue = '', required, disabled, format} = this.props;
if (disabled) {
const {onInvalid, defaultValue = '', required, disabled, readonly, format} = this.props;
if (disabled || readonly) {
return;
}
const date = createDate(value);
Expand Down
8 changes: 4 additions & 4 deletions lib/datetime-picker/src/component/datetime-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export class DatetimePicker extends Pick<PickState, DatetimePickerOptions> {
};

setTime(value: string | {hour?: number, minute?: number}) {
const {onInvalid, required, defaultValue, timeFormat, joiner, disabled, dateFormat} = this.props;
if (disabled) {
const {onInvalid, required, defaultValue, timeFormat, joiner, disabled, readonly, dateFormat} = this.props;
if (disabled || readonly) {
return;
}
let valueString = '';
Expand Down Expand Up @@ -92,8 +92,8 @@ export class DatetimePicker extends Pick<PickState, DatetimePickerOptions> {
}

setDate = (value: string) => {
const {onInvalid, defaultValue = '', required, dateFormat, disabled, joiner} = this.props;
if (disabled) {
const {onInvalid, defaultValue = '', required, dateFormat, disabled, readonly, joiner} = this.props;
if (disabled || readonly) {
return;
}
const date = createDate(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/datetime-picker/src/component/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class TimePicker extends Pick<PickState, TimePickerOptions> {
};

setTime(value: string | {hour?: number, minute?: number}) {
if (this.props.disabled) {
if (this.props.disabled || this.props.readonly) {
return;
}
let valueString = '';
Expand Down
5 changes: 3 additions & 2 deletions lib/datetime-picker/src/types/date-picker-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {IconType} from '@zui/core';
import type {PickOptions} from '@zui/pick';
import type {NavItemOptions, NavOptions} from '@zui/nav';
import type {NavOptions} from '@zui/nav';
import type {Item} from '@zui/common-list';
import type {ToolbarItemOptions, ToolbarOptions} from '@zui/toolbar';
import type {DateLike} from '@zui/helpers/src/date-helper';

Expand All @@ -18,7 +19,7 @@ export interface DatePickerOptions extends PickOptions {
weekStart?: number;
minDate?: DateLike;
maxDate?: DateLike;
menu?: NavItemOptions[] | NavOptions;
menu?: Item[] | NavOptions;
actions?: ToolbarItemOptions[] | ToolbarOptions;
onInvalid?: (value: string) => void;
}
1 change: 0 additions & 1 deletion lib/datetime-picker/src/types/time-picker-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {PickOptions} from '@zui/pick';
export interface TimePickerOptions extends PickOptions {
minuteStep?: number;
placeholder?: string;
readonly?: boolean;
format?: string;
icon?: IconType | boolean;
required?: boolean;
Expand Down

0 comments on commit 627ec4c

Please sign in to comment.