Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

time-picker: simple optimization #8342

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

Open
chenth-chn wants to merge 1 commit into vueComponent:main
base: main
Choose a base branch
Loading
from chenth-chn:feature/add-function
Open
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
112 changes: 54 additions & 58 deletions components/time-picker/time-picker.tsx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ function createTimePicker<
});

const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker as any;

const usePickerExpose = (pickerRef: Ref) => ({
focus: () => pickerRef.value?.focus?.(),
blur: () => pickerRef.value?.blur?.(),
});

const useFormItemEvents = (emit: any, formItemContext: any) => ({
onChange: (value: any, dateString: any) => {
emit('update:value', value);
emit('change', value, dateString);
formItemContext.onFieldChange();
},
onBlur: (e: FocusEvent) => {
emit('blur', e);
formItemContext.onFieldBlur();
}
});

const useCommonEvents = (emit: any) => ({
onOpenChange: (open: boolean) => {
emit('update:open', open);
emit('openChange', open);
},
onFocus: (e: FocusEvent) => {
emit('focus', e);
}
});

const TimePicker = defineComponent<DTimePickerProps>({
name: 'ATimePicker',
inheritAttrs: false,
Expand All @@ -96,53 +124,37 @@ function createTimePicker<
setup(p, { slots, expose, emit, attrs }) {
const props = p as unknown as DTimePickerProps;
const formItemContext = useInjectFormItemContext();
const pickerRef = ref();

devWarning(
!(slots.addon || props.addon),
'TimePicker',
'`addon` is deprecated. Please use `v-slot:renderExtraFooter` instead.',
);
const pickerRef = ref();
expose({
focus: () => {
pickerRef.value?.focus();
},
blur: () => {
pickerRef.value?.blur();
},
});
const onChange = (value: DateType | string, dateString: string) => {
emit('update:value', value);
emit('change', value, dateString);
formItemContext.onFieldChange();
};
const onOpenChange = (open: boolean) => {
emit('update:open', open);
emit('openChange', open);
};
const onFocus = (e: FocusEvent) => {
emit('focus', e);
};
const onBlur = (e: FocusEvent) => {
emit('blur', e);
formItemContext.onFieldBlur();
};

expose(usePickerExpose(pickerRef));

const { onChange, onBlur } = useFormItemEvents(emit, formItemContext);
const { onOpenChange, onFocus } = useCommonEvents(emit);

const onOk = (value: DateType) => {
emit('ok', value);
};

return () => {
const { id = formItemContext.id.value } = props;
//restProps.addon
const renderExtraFooter = props.addon || slots.addon || props.renderExtraFooter || slots.renderExtraFooter;
const omittedProps = omit(props, ['onUpdate:value', 'onUpdate:open']);

return (
<InternalTimePicker
{...attrs}
{...omit(props, ['onUpdate:value', 'onUpdate:open'])}
{...omittedProps}
id={id}
dropdownClassName={props.popupClassName}
mode={undefined}
ref={pickerRef}
renderExtraFooter={
props.addon || slots.addon || props.renderExtraFooter || slots.renderExtraFooter
}
renderExtraFooter={renderExtraFooter}
onChange={onChange}
onOpenChange={onOpenChange}
onFocus={onFocus}
Expand Down Expand Up @@ -174,55 +186,39 @@ function createTimePicker<
const props = p as unknown as DTimeRangePickerProps;
const pickerRef = ref();
const formItemContext = useInjectFormItemContext();
expose({
focus: () => {
pickerRef.value?.focus();
},
blur: () => {
pickerRef.value?.blur();
},
});
const onChange = (
values: RangeValue<string> | RangeValue<DateType>,
dateStrings: [string, string],
) => {
emit('update:value', values);
emit('change', values, dateStrings);
formItemContext.onFieldChange();
};
const onOpenChange = (open: boolean) => {
emit('update:open', open);
emit('openChange', open);
};
const onFocus = (e: FocusEvent) => {
emit('focus', e);
};
const onBlur = (e: FocusEvent) => {
emit('blur', e);
formItemContext.onFieldBlur();
};

expose(usePickerExpose(pickerRef));

const { onChange, onBlur } = useFormItemEvents(emit, formItemContext);
const { onOpenChange, onFocus } = useCommonEvents(emit);

const onPanelChange = (
values: RangeValue<string> | RangeValue<DateType>,
modes: [PanelMode, PanelMode],
) => {
emit('panelChange', values, modes);
};

const onOk = (values: RangeValue<string | DateType>) => {
emit('ok', values);
};

const onCalendarChange: RangePickerSharedProps<DateType>['onCalendarChange'] = (
values: RangeValue<string> | RangeValue<DateType>,
dateStrings: [string, string],
info,
) => {
emit('calendarChange', values, dateStrings, info);
};

return () => {
const { id = formItemContext.id.value } = props;
const omittedProps = omit(props, ['onUpdate:open', 'onUpdate:value'] as any);

return (
<InternalRangePicker
{...attrs}
{...omit(props, ['onUpdate:open', 'onUpdate:value'] as any)}
{...omittedProps}
id={id}
dropdownClassName={props.popupClassName}
picker="time"
Expand Down

AltStyle によって変換されたページ (->オリジナル) /