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

Adds support to pass custom function to replace getNow in generateConfig. #9

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
4 changes: 3 additions & 1 deletion src/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@

export interface PickerProps<DateType extends object = any>
extends BasePickerProps<DateType>,
Omit<SharedTimeProps<DateType>, 'format' | 'defaultValue'> {}
Omit<SharedTimeProps<DateType>, 'format' | 'defaultValue'> {
getNow?: () => string;
}

/** Internal usage. For cross function get same aligned props */
export type ReplacedPickerProps<DateType extends object = any> = {
Expand Down Expand Up @@ -584,7 +586,7 @@
// Legacy compatible. This effect update should not trigger `onPanelChange`
triggerModeChange(null, picker, false);
}
}, [mergedOpen, activeIndex, picker]);

Check warning on line 589 in src/PickerInput/SinglePicker.tsx

View workflow job for this annotation

GitHub Actions / Create Release

React Hook useLayoutEffect has a missing dependency: 'triggerModeChange'. Either include it or remove the dependency array

// >>> For complex picker, we need check if need to focus next one
useLayoutEffect(() => {
Expand All @@ -601,7 +603,7 @@
triggerOpen(true);
triggerConfirm();
}
}, [mergedOpen]);

Check warning on line 606 in src/PickerInput/SinglePicker.tsx

View workflow job for this annotation

GitHub Actions / Create Release

React Hook useLayoutEffect has missing dependencies: 'complexPicker', 'lastOperation', 'needConfirm', 'triggerConfirm', and 'triggerOpen'. Either include them or remove the dependency array

// ======================== Render ========================
return (
Expand Down
5 changes: 5 additions & 0 deletions src/PickerInput/hooks/useFilledProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
defaultValue?: any;
pickerValue?: any;
defaultPickerValue?: any;
getNow?: () => string;
};

type ExcludeBooleanType<T> = T extends boolean ? never : T;
Expand Down Expand Up @@ -161,6 +162,10 @@
const filledProps = React.useMemo(
() => ({
...props,
generateConfig: {
...generateConfig,
getNow: props.getNow || props.generateConfig.getNow,
},
prefixCls,
locale: mergedLocale,
picker,
Expand All @@ -179,7 +184,7 @@
defaultPickerValue: defaultPickerValues,
...updater?.(),
}),
[props],

Check warning on line 187 in src/PickerInput/hooks/useFilledProps.ts

View workflow job for this annotation

GitHub Actions / Create Release

React Hook React.useMemo has missing dependencies: 'allowClear', 'classNames', 'clearIcon', 'components', 'defaultPickerValues', 'defaultValues', 'generateConfig', 'inputRender', 'mergedLocale', 'mergedShowTime', 'order', 'picker', 'pickerValues', 'prefixCls', 'styles', 'updater', and 'values'. Either include them or remove the dependency array. If 'updater' changes too often, find the parent component that defines it and wrap that definition in useCallback
);

// ======================== Format ========================
Expand Down
Loading