From 8365a397ba02ef46102385ca7d66582e8a797f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 6 Dec 2023 14:15:16 +0800 Subject: [PATCH] chore: comment it --- src/NewPicker/PickerInput/SinglePicker.tsx | 38 +++++++------------ .../PickerInput/hooks/useFilledProps.ts | 1 + 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/NewPicker/PickerInput/SinglePicker.tsx b/src/NewPicker/PickerInput/SinglePicker.tsx index d1ceab57a..f9f6c9c6a 100644 --- a/src/NewPicker/PickerInput/SinglePicker.tsx +++ b/src/NewPicker/PickerInput/SinglePicker.tsx @@ -3,7 +3,6 @@ import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; import omit from 'rc-util/lib/omit'; import pickAttrs from 'rc-util/lib/pickAttrs'; import * as React from 'react'; -import useLocale from '../hooks/useLocale'; import useTimeConfig from '../hooks/useTimeConfig'; import type { BaseInfo, @@ -22,6 +21,7 @@ import PickerContext from './context'; import useCellRender from './hooks/useCellRender'; import useDisabledBoundary from './hooks/useDisabledBoundary'; import { useFieldFormat } from './hooks/useFieldFormat'; +import useFilledProps from './hooks/useFilledProps'; import useRangeValue, { useInnerValue } from './hooks/useFlexibleValue'; import useInputReadOnly from './hooks/useInputReadOnly'; import useInvalidate from './hooks/useInvalidate'; @@ -101,11 +101,14 @@ function Picker( props: PickerProps, ref: React.Ref, ) { + // ========================= Prop ========================= + const filledProps = useFilledProps(props); + const { // Style - prefixCls = 'rc-picker', - styles = {}, - classNames = {}, + prefixCls, + styles, + classNames, // Value defaultValue, @@ -128,7 +131,7 @@ function Picker( // Picker locale, generateConfig, - picker = 'date', + picker, showNow, showToday, @@ -164,34 +167,21 @@ function Picker( clearIcon, // Render - components = {}, + components, cellRender, dateRender, monthCellRender, // Native onClick, - } = props; + } = filledProps; // ========================= Refs ========================= const selectorRef = usePickerRef(ref); - // ======================== Locale ======================== - const filledLocale = useLocale(locale); - // ========================= Icon ========================= const mergedClearIcon = useClearIcon(prefixCls, allowClear, clearIcon); - // ========================= Prop ========================= - const filledProps = React.useMemo( - () => ({ - ...props, - locale: filledLocale, - picker, - }), - [props], - ); - // ======================= ShowTime ======================= const mergedShowTime = useTimeConfig(filledProps); @@ -209,7 +199,7 @@ function Picker( const mergedNeedConfirm = needConfirm ?? complexPicker; // ======================== Format ======================== - const [formatList, maskFormat] = useFieldFormat(internalPicker, filledLocale, format); + const [formatList, maskFormat] = useFieldFormat(internalPicker, locale, format); // ======================== Values ======================== const [mergedValue, setInnerValue, getCalendarValue, triggerCalendarChange] = useInnerValue( @@ -345,7 +335,7 @@ function Picker( // ===================== Picker Value ===================== const [currentPickerValue, setCurrentPickerValue] = useRangePickerValue( generateConfig, - filledLocale, + locale, calendarValue, mergedOpen, activeIndex, @@ -613,12 +603,12 @@ function Picker( const context = React.useMemo( () => ({ prefixCls, - locale: filledLocale, + locale, generateConfig, button: components.button, input: components.input, }), - [prefixCls, filledLocale, generateConfig, components.button, components.input], + [prefixCls, locale, generateConfig, components.button, components.input], ); // ======================== Effect ======================== diff --git a/src/NewPicker/PickerInput/hooks/useFilledProps.ts b/src/NewPicker/PickerInput/hooks/useFilledProps.ts index 0bd6edeb7..974b2d18c 100644 --- a/src/NewPicker/PickerInput/hooks/useFilledProps.ts +++ b/src/NewPicker/PickerInput/hooks/useFilledProps.ts @@ -7,6 +7,7 @@ type PickedProps = Pick< 'locale' | 'picker' | 'prefixCls' | 'styles' | 'classNames' | 'order' | 'components' >; +/** Align the outer props with unique typed and fill undefined props */ export default function useFilledProps< DateType extends object = any, InProps extends PickedProps = PickedProps,