Browse Source

refactoring: use hook replace LocaleReceiver (#40870)

* chore: rename useLocaleReceiver => useLocale

* refactoring: use hook replace LocaleReceiver

* fix

* update snap

* fix

* update snap

* fix

* rename
pull/40878/head
lijianan 2 years ago
committed by GitHub
parent
commit
288b10bd10
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 103
      components/calendar/generateCalendar.tsx
  2. 21
      components/config-provider/index.tsx
  3. 100
      components/date-picker/generatePicker/generateRangePicker.tsx
  4. 100
      components/date-picker/generatePicker/generateSinglePicker.tsx
  5. 66
      components/empty/index.tsx
  6. 4
      components/form/FormItemLabel.tsx
  7. 6
      components/locale-provider/LocaleReceiver.ts
  8. 64
      components/locale/LocaleReceiver.ts
  9. 24
      components/locale/useLocale.ts
  10. 82
      components/modal/ConfirmDialog.tsx
  11. 14
      components/modal/Modal.tsx
  12. 82
      components/modal/PurePanel.tsx
  13. 34
      components/modal/useModal/HookModal.tsx
  14. 68
      components/pagination/Pagination.tsx
  15. 76
      components/popconfirm/PurePanel.tsx
  16. 52
      components/qrcode/index.tsx
  17. 86
      components/tour/panelRender.tsx
  18. 73
      components/transfer/ListItem.tsx
  19. 142
      components/transfer/index.tsx
  20. 20
      components/typography/Base/index.tsx
  21. 82
      components/upload/Upload.tsx

103
components/calendar/generateCalendar.tsx

@ -10,7 +10,7 @@ import type {
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import CalendarHeader from './Header';
import enUS from './locale/en_US';
@ -236,60 +236,57 @@ function generateCalendar<DateType>(generateConfig: GenerateConfig<DateType>) {
[monthFullCellRender, monthCellRender],
);
const contextLocale = useLocale('Calendar', getDefaultLocale);
return wrapSSR(
<LocaleReceiver componentName="Calendar" defaultLocale={getDefaultLocale}>
{(contextLocale) => (
<div
className={classNames(
calendarPrefixCls,
{
[`${calendarPrefixCls}-full`]: fullscreen,
[`${calendarPrefixCls}-mini`]: !fullscreen,
[`${calendarPrefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
hashId,
)}
style={style}
>
{headerRender ? (
headerRender({
value: mergedValue,
type: mergedMode,
onChange: onInternalSelect,
onTypeChange: triggerModeChange,
})
) : (
<CalendarHeader
prefixCls={calendarPrefixCls}
value={mergedValue}
generateConfig={generateConfig}
mode={mergedMode}
fullscreen={fullscreen}
locale={contextLocale.lang}
validRange={validRange}
onChange={onInternalSelect}
onModeChange={triggerModeChange}
/>
)}
<RCPickerPanel
value={mergedValue}
prefixCls={prefixCls}
locale={contextLocale.lang}
generateConfig={generateConfig}
dateRender={dateRender}
monthCellRender={(date) => monthRender(date, contextLocale.lang)}
onSelect={onInternalSelect}
mode={panelMode}
picker={panelMode}
disabledDate={mergedDisabledDate}
hideHeader
/>
</div>
<div
className={classNames(
calendarPrefixCls,
{
[`${calendarPrefixCls}-full`]: fullscreen,
[`${calendarPrefixCls}-mini`]: !fullscreen,
[`${calendarPrefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
hashId,
)}
style={style}
>
{headerRender ? (
headerRender({
value: mergedValue,
type: mergedMode,
onChange: onInternalSelect,
onTypeChange: triggerModeChange,
})
) : (
<CalendarHeader
prefixCls={calendarPrefixCls}
value={mergedValue}
generateConfig={generateConfig}
mode={mergedMode}
fullscreen={fullscreen}
locale={contextLocale?.lang}
validRange={validRange}
onChange={onInternalSelect}
onModeChange={triggerModeChange}
/>
)}
</LocaleReceiver>,
<RCPickerPanel
value={mergedValue}
prefixCls={prefixCls}
locale={contextLocale?.lang}
generateConfig={generateConfig}
dateRender={dateRender}
monthCellRender={(date) => monthRender(date, contextLocale?.lang)}
onSelect={onInternalSelect}
mode={panelMode}
picker={panelMode}
disabledDate={mergedDisabledDate}
hideHeader
/>
</div>,
);
};

21
components/config-provider/index.tsx

@ -3,13 +3,14 @@ import IconContext from '@ant-design/icons/lib/components/Context';
import { FormProvider as RcFormProvider } from 'rc-field-form';
import type { ValidateMessages } from 'rc-field-form/lib/interface';
import useMemo from 'rc-util/lib/hooks/useMemo';
import * as React from 'react';
import type { ReactElement } from 'react';
import * as React from 'react';
import type { Options } from 'scroll-into-view-if-needed';
import type { RequiredMark } from '../form/Form';
import type { Locale } from '../locale';
import LocaleProvider, { ANT_MARK } from '../locale';
import LocaleReceiver from '../locale/LocaleReceiver';
import type { LocaleContextProps } from '../locale/context';
import LocaleContext from '../locale/context';
import defaultLocale from '../locale/en_US';
import { DesignTokenContext } from '../theme/internal';
import defaultSeedToken from '../theme/themes/seed';
@ -313,17 +314,11 @@ const ConfigProvider: React.FC<ConfigProviderProps> & {
ConfigContext: typeof ConfigContext;
SizeContext: typeof SizeContext;
config: typeof setGlobalConfig;
} = (props) => (
<LocaleReceiver>
{(_, __, legacyLocale) => (
<ConfigConsumer>
{(context) => (
<ProviderChildren parentContext={context} legacyLocale={legacyLocale} {...props} />
)}
</ConfigConsumer>
)}
</LocaleReceiver>
);
} = (props) => {
const context = React.useContext<ConfigConsumerProps>(ConfigContext);
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
return <ProviderChildren parentContext={context} legacyLocale={antLocale!} {...props} />;
};
ConfigProvider.ConfigContext = ConfigContext;
ConfigProvider.SizeContext = SizeContext;

100
components/date-picker/generatePicker/generateRangePicker.tsx

@ -13,13 +13,13 @@ import { ConfigContext } from '../../config-provider';
import DisabledContext from '../../config-provider/DisabledContext';
import SizeContext from '../../config-provider/SizeContext';
import { FormItemInputContext } from '../../form/context';
import useLocale from '../../locale/useLocale';
import { useCompactItemContext } from '../../space/Compact';
import LocaleReceiver from '../../locale/LocaleReceiver';
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
import warning from '../../_util/warning';
import enUS from '../locale/en_US';
import { getRangePlaceholder, transPlacement2DropdownAlign } from '../util';
import type { CommonPickerMethods, PickerComponentClass } from './interface';
import warning from '../../_util/warning';
import useStyle from '../style';
@ -102,57 +102,53 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
blur: () => innerRef.current?.blur(),
}));
const contextLocale = useLocale('Calendar', enUS);
const locale = { ...contextLocale, ...props.locale! };
return wrapSSR(
<LocaleReceiver componentName="DatePicker" defaultLocale={enUS}>
{(contextLocale) => {
const locale = { ...contextLocale, ...props.locale };
return (
<RCRangePicker<DateType>
separator={
<span aria-label="to" className={`${prefixCls}-separator`}>
<SwapRightOutlined />
</span>
}
disabled={mergedDisabled}
ref={innerRef}
dropdownAlign={transPlacement2DropdownAlign(direction, placement)}
placeholder={getRangePlaceholder(locale, picker, placeholder)}
suffixIcon={suffixNode}
clearIcon={<CloseCircleFilled />}
prevIcon={<span className={`${prefixCls}-prev-icon`} />}
nextIcon={<span className={`${prefixCls}-next-icon`} />}
superPrevIcon={<span className={`${prefixCls}-super-prev-icon`} />}
superNextIcon={<span className={`${prefixCls}-super-next-icon`} />}
allowClear
transitionName={`${rootPrefixCls}-slide-up`}
{...restProps}
{...additionalOverrideProps}
className={classNames(
{
[`${prefixCls}-${mergedSize}`]: mergedSize,
[`${prefixCls}-borderless`]: !bordered,
},
getStatusClassNames(
prefixCls as string,
getMergedStatus(contextStatus, customStatus),
hasFeedback,
),
hashId,
compactItemClassnames,
className,
)}
locale={locale.lang}
prefixCls={prefixCls}
getPopupContainer={customGetPopupContainer || getPopupContainer}
generateConfig={generateConfig}
components={Components}
direction={direction}
dropdownClassName={classNames(hashId, popupClassName || dropdownClassName)}
/>
);
}}
</LocaleReceiver>,
<RCRangePicker<DateType>
separator={
<span aria-label="to" className={`${prefixCls}-separator`}>
<SwapRightOutlined />
</span>
}
disabled={mergedDisabled}
ref={innerRef}
dropdownAlign={transPlacement2DropdownAlign(direction, placement)}
placeholder={getRangePlaceholder(locale, picker, placeholder)}
suffixIcon={suffixNode}
clearIcon={<CloseCircleFilled />}
prevIcon={<span className={`${prefixCls}-prev-icon`} />}
nextIcon={<span className={`${prefixCls}-next-icon`} />}
superPrevIcon={<span className={`${prefixCls}-super-prev-icon`} />}
superNextIcon={<span className={`${prefixCls}-super-next-icon`} />}
allowClear
transitionName={`${rootPrefixCls}-slide-up`}
{...restProps}
{...additionalOverrideProps}
className={classNames(
{
[`${prefixCls}-${mergedSize}`]: mergedSize,
[`${prefixCls}-borderless`]: !bordered,
},
getStatusClassNames(
prefixCls as string,
getMergedStatus(contextStatus, customStatus),
hasFeedback,
),
hashId,
compactItemClassnames,
className,
)}
locale={locale.lang}
prefixCls={prefixCls}
getPopupContainer={customGetPopupContainer || getPopupContainer}
generateConfig={generateConfig}
components={Components}
direction={direction}
dropdownClassName={classNames(hashId, popupClassName || dropdownClassName)}
/>,
);
});

100
components/date-picker/generatePicker/generateSinglePicker.tsx

@ -13,7 +13,7 @@ import { ConfigContext } from '../../config-provider';
import DisabledContext from '../../config-provider/DisabledContext';
import SizeContext from '../../config-provider/SizeContext';
import { FormItemInputContext } from '../../form/context';
import LocaleReceiver from '../../locale/LocaleReceiver';
import useLocale from '../../locale/useLocale';
import { useCompactItemContext } from '../../space/Compact';
import type { InputStatus } from '../../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../../_util/statusUtils';
@ -122,58 +122,54 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
</>
);
const contextLocale = useLocale('DatePicker', enUS);
const locale = { ...contextLocale, ...props.locale! };
return wrapSSR(
<LocaleReceiver componentName="DatePicker" defaultLocale={enUS}>
{(contextLocale) => {
const locale = { ...contextLocale, ...props.locale };
return (
<RCPicker<DateType>
ref={innerRef}
placeholder={getPlaceholder(locale, mergedPicker, placeholder)}
suffixIcon={suffixNode}
dropdownAlign={transPlacement2DropdownAlign(direction, placement)}
clearIcon={<CloseCircleFilled />}
prevIcon={<span className={`${prefixCls}-prev-icon`} />}
nextIcon={<span className={`${prefixCls}-next-icon`} />}
superPrevIcon={<span className={`${prefixCls}-super-prev-icon`} />}
superNextIcon={<span className={`${prefixCls}-super-next-icon`} />}
allowClear
transitionName={`${rootPrefixCls}-slide-up`}
{...additionalProps}
{...restProps}
{...additionalOverrideProps}
locale={locale!.lang}
className={classNames(
{
[`${prefixCls}-${mergedSize}`]: mergedSize,
[`${prefixCls}-borderless`]: !bordered,
},
getStatusClassNames(
prefixCls as string,
getMergedStatus(contextStatus, customStatus),
hasFeedback,
),
hashId,
compactItemClassnames,
className,
rootClassName,
)}
prefixCls={prefixCls}
getPopupContainer={customizeGetPopupContainer || getPopupContainer}
generateConfig={generateConfig}
components={Components}
direction={direction}
disabled={mergedDisabled}
dropdownClassName={classNames(
hashId,
rootClassName,
popupClassName || dropdownClassName,
)}
/>
);
}}
</LocaleReceiver>,
<RCPicker<DateType>
ref={innerRef}
placeholder={getPlaceholder(locale, mergedPicker, placeholder)}
suffixIcon={suffixNode}
dropdownAlign={transPlacement2DropdownAlign(direction, placement)}
clearIcon={<CloseCircleFilled />}
prevIcon={<span className={`${prefixCls}-prev-icon`} />}
nextIcon={<span className={`${prefixCls}-next-icon`} />}
superPrevIcon={<span className={`${prefixCls}-super-prev-icon`} />}
superNextIcon={<span className={`${prefixCls}-super-next-icon`} />}
allowClear
transitionName={`${rootPrefixCls}-slide-up`}
{...additionalProps}
{...restProps}
{...additionalOverrideProps}
locale={locale!.lang}
className={classNames(
{
[`${prefixCls}-${mergedSize}`]: mergedSize,
[`${prefixCls}-borderless`]: !bordered,
},
getStatusClassNames(
prefixCls as string,
getMergedStatus(contextStatus, customStatus),
hasFeedback,
),
hashId,
compactItemClassnames,
className,
rootClassName,
)}
prefixCls={prefixCls}
getPopupContainer={customizeGetPopupContainer || getPopupContainer}
generateConfig={generateConfig}
components={Components}
direction={direction}
disabled={mergedDisabled}
dropdownClassName={classNames(
hashId,
rootClassName,
popupClassName || dropdownClassName,
)}
/>,
);
},
);

66
components/empty/index.tsx

@ -1,7 +1,7 @@
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import DefaultEmptyImg from './empty';
import SimpleEmptyImg from './simple';
@ -46,43 +46,39 @@ const Empty: CompoundedComponent = ({
const prefixCls = getPrefixCls('empty', customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls);
return wrapSSR(
<LocaleReceiver componentName="Empty">
{(locale: TransferLocale) => {
const des = typeof description !== 'undefined' ? description : locale.description;
const alt = typeof des === 'string' ? des : 'empty';
const locale = useLocale('Empty');
const des = typeof description !== 'undefined' ? description : locale?.description;
const alt = typeof des === 'string' ? des : 'empty';
let imageNode: React.ReactNode = null;
let imageNode: React.ReactNode = null;
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
return (
<div
className={classNames(
hashId,
prefixCls,
{
[`${prefixCls}-normal`]: image === simpleEmptyImg,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
)}
{...restProps}
>
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
{des && <div className={`${prefixCls}-description`}>{des}</div>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>
);
}}
</LocaleReceiver>,
return wrapSSR(
<div
className={classNames(
hashId,
prefixCls,
{
[`${prefixCls}-normal`]: image === simpleEmptyImg,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
)}
{...restProps}
>
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
{des && <div className={`${prefixCls}-description`}>{des}</div>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>,
);
};

4
components/form/FormItemLabel.tsx

@ -3,8 +3,8 @@ import classNames from 'classnames';
import * as React from 'react';
import type { ColProps } from '../grid/col';
import Col from '../grid/col';
import { useLocaleReceiver } from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US';
import useLocale from '../locale/useLocale';
import type { TooltipProps } from '../tooltip';
import Tooltip from '../tooltip';
import type { FormContextProps } from './context';
@ -53,7 +53,7 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required?: boolean; prefixC
requiredMark,
tooltip,
}) => {
const [formLocale] = useLocaleReceiver('Form');
const formLocale = useLocale('Form');
const {
vertical,

6
components/locale-provider/LocaleReceiver.ts

@ -1,6 +1,6 @@
// locale-provider 文件夹的移除需要修改 @ant-design/tools 和 antd-img-crop
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
export * from '../locale/LocaleReceiver';
export * from '../locale/useLocale';
export default LocaleReceiver;
export default useLocale;

64
components/locale/LocaleReceiver.ts

@ -1,64 +0,0 @@
import * as React from 'react';
import type { Locale } from '.';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
import defaultLocaleData from './en_US';
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>;
export interface LocaleReceiverProps<C extends LocaleComponentName = LocaleComponentName> {
componentName?: C;
defaultLocale?: Locale[C] | (() => Locale[C]);
children: (
locale: NonNullable<Locale[C]>,
localeCode: string,
fullLocale: Locale,
) => React.ReactElement;
}
const LocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
props: LocaleReceiverProps<C>,
) => {
const { componentName = 'global' as C, defaultLocale, children } = props;
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(locale instanceof Function ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
const getLocaleCode = React.useMemo<string>(() => {
const localeCode = antLocale && antLocale.locale;
// Had use LocaleProvide but didn't set locale
if (antLocale && antLocale.exist && !localeCode) {
return defaultLocaleData.locale;
}
return localeCode!;
}, [antLocale]);
return children(getLocale, getLocaleCode, antLocale!);
};
export default LocaleReceiver;
export const useLocaleReceiver = <C extends LocaleComponentName = LocaleComponentName>(
componentName: C,
defaultLocale?: Locale[C] | (() => Locale[C]),
): [Locale[C]] => {
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
return [getLocale];
};

24
components/locale/useLocale.ts

@ -0,0 +1,24 @@
import * as React from 'react';
import type { Locale } from '.';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
import defaultLocaleData from './en_US';
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>;
const useLocale = <C extends LocaleComponentName = LocaleComponentName>(
componentName: C,
defaultLocale?: Locale[C] | (() => Locale[C]),
): Locale[C] => {
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
return React.useMemo<NonNullable<Locale[C]>>(() => {
const locale = defaultLocale || defaultLocaleData[componentName];
const localeFromContext = antLocale?.[componentName] ?? {};
return {
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, antLocale]);
};
export default useLocale;

82
components/modal/ConfirmDialog.tsx

@ -5,7 +5,7 @@ import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
import classNames from 'classnames';
import * as React from 'react';
import ConfigProvider from '../config-provider';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import ActionButton from '../_util/ActionButton';
import { getTransitionName } from '../_util/motion';
import warning from '../_util/warning';
@ -81,57 +81,53 @@ export function ConfirmContent(
const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
return (
<LocaleReceiver componentName="Modal">
{(locale) => {
const mergedLocale = staticLocale || locale;
const locale = useLocale('Modal');
const mergedLocale = staticLocale || locale;
const cancelButton = mergedOkCancel && (
<ActionButton
actionFn={onCancel}
close={close}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{cancelText || mergedLocale?.cancelText}
</ActionButton>
);
const cancelButton = mergedOkCancel && (
return (
<div className={`${confirmPrefixCls}-body-wrapper`}>
<div className={`${confirmPrefixCls}-body`}>
{mergedIcon}
{props.title === undefined ? null : (
<span className={`${confirmPrefixCls}-title`}>{props.title}</span>
)}
<div className={`${confirmPrefixCls}-content`}>{props.content}</div>
</div>
{footer !== undefined ? (
footer
) : (
<div className={`${confirmPrefixCls}-btns`}>
{cancelButton}
<ActionButton
actionFn={onCancel}
type={okType}
actionFn={onOk}
close={close}
autoFocus={autoFocusButton === 'cancel'}
buttonProps={cancelButtonProps}
autoFocus={autoFocusButton === 'ok'}
buttonProps={okButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{cancelText || mergedLocale?.cancelText}
{okText || (mergedOkCancel ? mergedLocale?.okText : mergedLocale?.justOkText)}
</ActionButton>
);
return (
<div className={`${confirmPrefixCls}-body-wrapper`}>
<div className={`${confirmPrefixCls}-body`}>
{mergedIcon}
{props.title === undefined ? null : (
<span className={`${confirmPrefixCls}-title`}>{props.title}</span>
)}
<div className={`${confirmPrefixCls}-content`}>{props.content}</div>
</div>
{footer !== undefined ? (
footer
) : (
<div className={`${confirmPrefixCls}-btns`}>
{cancelButton}
<ActionButton
type={okType}
actionFn={onOk}
close={close}
autoFocus={autoFocusButton === 'ok'}
buttonProps={okButtonProps}
prefixCls={`${rootPrefixCls}-btn`}
>
{okText || (mergedOkCancel ? mergedLocale?.okText : mergedLocale?.justOkText)}
</ActionButton>
</div>
)}
</div>
);
}}
</LocaleReceiver>
</div>
)}
</div>
);
}
const ConfirmDialog = (props: ConfirmDialogProps) => {
const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
const {
close,
zIndex,

14
components/modal/Modal.tsx

@ -9,7 +9,7 @@ import { NoCompactStyle } from '../space/Compact';
import { getTransitionName } from '../_util/motion';
import { canUseDocElement } from '../_util/styleChecker';
import warning from '../_util/warning';
import { renderCloseIcon, renderFooter } from './PurePanel';
import { Footer, renderCloseIcon } from './PurePanel';
import useStyle from './style';
type MousePosition = { x: number; y: number } | null;
@ -209,11 +209,13 @@ const Modal: React.FC<ModalProps> = (props) => {
prefixCls={prefixCls}
rootClassName={classNames(hashId, rootClassName)}
wrapClassName={wrapClassNameExtended}
footer={renderFooter({
...props,
onOk: handleOk,
onCancel: handleCancel,
})}
footer={
props.footer === null ? (
props.footer
) : (
<Footer {...props} onOk={handleOk} onCancel={handleCancel} />
)
}
visible={open ?? visible}
mousePosition={restProps.mousePosition ?? mousePosition}
onClose={handleCancel}

82
components/modal/PurePanel.tsx

@ -1,3 +1,4 @@
/* eslint-disable react/jsx-no-useless-fragment */
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import { Panel } from 'rc-dialog';
@ -6,10 +7,10 @@ import * as React from 'react';
import Button from '../button';
import { convertLegacyProps } from '../button/button';
import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import { ConfirmContent } from './ConfirmDialog';
import { getConfirmLocale } from './locale';
import type { ModalProps, ModalFuncProps } from './Modal';
import type { ModalFuncProps, ModalProps } from './Modal';
import useStyle from './style';
export interface PurePanelProps
@ -27,21 +28,24 @@ export function renderCloseIcon(prefixCls: string, closeIcon?: React.ReactNode)
);
}
export function renderFooter(
props: Pick<
ModalProps,
| 'footer'
| 'okText'
| 'okType'
| 'cancelText'
| 'confirmLoading'
| 'okButtonProps'
| 'cancelButtonProps'
> & {
onOk?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
onCancel?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
},
) {
interface FooterProps {
onOk?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
onCancel?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
}
export const Footer: React.FC<
FooterProps &
Pick<
ModalProps,
| 'footer'
| 'okText'
| 'okType'
| 'cancelText'
| 'confirmLoading'
| 'okButtonProps'
| 'cancelButtonProps'
>
> = (props) => {
const {
okText,
okType = 'primary',
@ -54,30 +58,28 @@ export function renderFooter(
footer,
} = props;
const locale = useLocale('Modal', getConfirmLocale());
return footer === undefined ? (
<LocaleReceiver componentName="Modal" defaultLocale={getConfirmLocale()}>
{(locale) => (
<>
<Button onClick={onCancel} {...cancelButtonProps}>
{cancelText || locale!.cancelText}
</Button>
<Button
{...convertLegacyProps(okType)}
loading={confirmLoading}
onClick={onOk}
{...okButtonProps}
>
{okText || locale!.okText}
</Button>
</>
)}
</LocaleReceiver>
<>
<Button onClick={onCancel} {...cancelButtonProps}>
{cancelText || locale?.cancelText}
</Button>
<Button
{...convertLegacyProps(okType)}
loading={confirmLoading}
onClick={onOk}
{...okButtonProps}
>
{okText || locale?.okText}
</Button>
</>
) : (
footer
(footer as React.ReactElement)
);
}
};
export default function PurePanel(props: PurePanelProps) {
const PurePanel: React.FC<PurePanelProps> = (props) => {
const {
prefixCls: customizePrefixCls,
className,
@ -117,7 +119,7 @@ export default function PurePanel(props: PurePanelProps) {
additionalProps = {
closable: closable ?? true,
title,
footer: renderFooter(props),
footer: props.footer === null ? props.footer : <Footer {...props} />,
children,
};
}
@ -138,4 +140,6 @@ export default function PurePanel(props: PurePanelProps) {
{...additionalProps}
/>
);
}
};
export default PurePanel;

34
components/modal/useModal/HookModal.tsx

@ -1,7 +1,7 @@
import * as React from 'react';
import { ConfigContext } from '../../config-provider';
import LocaleReceiver from '../../locale/LocaleReceiver';
import defaultLocale from '../../locale/en_US';
import useLocale from '../../locale/useLocale';
import ConfirmDialog from '../ConfirmDialog';
import type { ModalFuncProps } from '../Modal';
@ -46,24 +46,22 @@ const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> =
const mergedOkCancel = innerConfig.okCancel ?? innerConfig.type === 'confirm';
const contextLocale = useLocale('Modal', defaultLocale.Modal);
return (
<LocaleReceiver componentName="Modal" defaultLocale={defaultLocale.Modal}>
{(contextLocale) => (
<ConfirmDialog
prefixCls={prefixCls}
rootPrefixCls={rootPrefixCls}
{...innerConfig}
close={close}
open={open}
afterClose={afterClose}
okText={
innerConfig.okText || (mergedOkCancel ? contextLocale.okText : contextLocale.justOkText)
}
direction={direction}
cancelText={innerConfig.cancelText || contextLocale.cancelText}
/>
)}
</LocaleReceiver>
<ConfirmDialog
prefixCls={prefixCls}
rootPrefixCls={rootPrefixCls}
{...innerConfig}
close={close}
open={open}
afterClose={afterClose}
okText={
innerConfig.okText || (mergedOkCancel ? contextLocale?.okText : contextLocale?.justOkText)
}
direction={direction}
cancelText={innerConfig.cancelText || contextLocale?.cancelText}
/>
);
};

68
components/pagination/Pagination.tsx

@ -3,13 +3,13 @@ import DoubleRightOutlined from '@ant-design/icons/DoubleRightOutlined';
import LeftOutlined from '@ant-design/icons/LeftOutlined';
import RightOutlined from '@ant-design/icons/RightOutlined';
import classNames from 'classnames';
import type { PaginationProps as RcPaginationProps, PaginationLocale } from 'rc-pagination';
import type { PaginationLocale, PaginationProps as RcPaginationProps } from 'rc-pagination';
import RcPagination from 'rc-pagination';
import enUS from 'rc-pagination/lib/locale/en_US';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import useBreakpoint from '../grid/hooks/useBreakpoint';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import { MiddleSelect, MiniSelect } from './Select';
import useStyle from './style';
@ -90,44 +90,36 @@ const Pagination: React.FC<PaginationProps> = ({
[prevIcon, nextIcon] = [nextIcon, prevIcon];
[jumpPrevIcon, jumpNextIcon] = [jumpNextIcon, jumpPrevIcon];
}
return {
prevIcon,
nextIcon,
jumpPrevIcon,
jumpNextIcon,
};
return { prevIcon, nextIcon, jumpPrevIcon, jumpNextIcon };
};
return (
<LocaleReceiver componentName="Pagination" defaultLocale={enUS}>
{(contextLocale) => {
const locale = { ...contextLocale, ...customLocale };
const isSmall = size === 'small' || !!(xs && !size && responsive);
const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls);
const extendedClassName = classNames(
{
[`${prefixCls}-mini`]: isSmall,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
hashId,
);
return wrapSSR(
<RcPagination
{...getIconsProps()}
{...restProps}
prefixCls={prefixCls}
selectPrefixCls={selectPrefixCls}
className={extendedClassName}
selectComponentClass={selectComponentClass || (isSmall ? MiniSelect : MiddleSelect)}
locale={locale}
showSizeChanger={mergedShowSizeChanger}
/>,
);
}}
</LocaleReceiver>
const contextLocale = useLocale('Pagination', enUS);
const locale = { ...contextLocale, ...customLocale };
const isSmall = size === 'small' || !!(xs && !size && responsive);
const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls);
const extendedClassName = classNames(
{
[`${prefixCls}-mini`]: isSmall,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
hashId,
);
return wrapSSR(
<RcPagination
{...getIconsProps()}
{...restProps}
prefixCls={prefixCls}
selectPrefixCls={selectPrefixCls}
className={extendedClassName}
selectComponentClass={selectComponentClass || (isSmall ? MiniSelect : MiddleSelect)}
locale={locale}
showSizeChanger={mergedShowSizeChanger}
/>,
);
};

76
components/popconfirm/PurePanel.tsx

@ -1,15 +1,15 @@
import * as React from 'react';
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
import classNames from 'classnames';
import * as React from 'react';
import type { PopconfirmProps } from '.';
import Button from '../button';
import { convertLegacyProps } from '../button/button';
import ActionButton from '../_util/ActionButton';
import LocaleReceiver from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US';
import { getRenderPropValue } from '../_util/getRenderPropValue';
import { ConfigContext } from '../config-provider';
import defaultLocale from '../locale/en_US';
import useLocale from '../locale/useLocale';
import PopoverPurePanel from '../popover/PurePanel';
import ActionButton from '../_util/ActionButton';
import { getRenderPropValue } from '../_util/getRenderPropValue';
import useStyle from './style';
@ -56,43 +56,41 @@ export const Overlay: React.FC<OverlayProps> = (props) => {
const { getPrefixCls } = React.useContext(ConfigContext);
const contextLocale = useLocale('Popconfirm', defaultLocale.Popconfirm);
return (
<LocaleReceiver componentName="Popconfirm" defaultLocale={defaultLocale.Popconfirm}>
{(contextLocale) => (
<div className={`${prefixCls}-inner-content`}>
<div className={`${prefixCls}-message`}>
{icon && <span className={`${prefixCls}-message-icon`}>{icon}</span>}
<div
className={classNames(`${prefixCls}-message-title`, {
[`${prefixCls}-message-title-only`]: !!description,
})}
>
{getRenderPropValue(title)}
</div>
</div>
{description && (
<div className={`${prefixCls}-description`}>{getRenderPropValue(description)}</div>
)}
<div className={`${prefixCls}-buttons`}>
{showCancel && (
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
{cancelText ?? contextLocale.cancelText}
</Button>
)}
<ActionButton
buttonProps={{ size: 'small', ...convertLegacyProps(okType), ...okButtonProps }}
actionFn={onConfirm}
close={close}
prefixCls={getPrefixCls('btn')}
quitOnNullishReturnValue
emitEvent
>
{okText ?? contextLocale.okText}
</ActionButton>
</div>
<div className={`${prefixCls}-inner-content`}>
<div className={`${prefixCls}-message`}>
{icon && <span className={`${prefixCls}-message-icon`}>{icon}</span>}
<div
className={classNames(`${prefixCls}-message-title`, {
[`${prefixCls}-message-title-only`]: !!description,
})}
>
{getRenderPropValue(title)}
</div>
</div>
{description && (
<div className={`${prefixCls}-description`}>{getRenderPropValue(description)}</div>
)}
</LocaleReceiver>
<div className={`${prefixCls}-buttons`}>
{showCancel && (
<Button onClick={onCancel} size="small" {...cancelButtonProps}>
{cancelText ?? contextLocale?.cancelText}
</Button>
)}
<ActionButton
buttonProps={{ size: 'small', ...convertLegacyProps(okType), ...okButtonProps }}
actionFn={onConfirm}
close={close}
prefixCls={getPrefixCls('btn')}
quitOnNullishReturnValue
emitEvent
>
{okText ?? contextLocale?.okText}
</ActionButton>
</div>
</div>
);
};

52
components/qrcode/index.tsx

@ -1,16 +1,16 @@
import React, { useMemo, useContext } from 'react';
import { QRCodeCanvas } from 'qrcode.react';
import classNames from 'classnames';
import { ReloadOutlined } from '@ant-design/icons';
import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale/LocaleReceiver';
import classNames from 'classnames';
import { QRCodeCanvas } from 'qrcode.react';
import React, { useContext, useMemo } from 'react';
import Button from '../button';
import type { ConfigConsumerProps } from '../config-provider';
import type { QRCodeProps, QRPropsCanvas } from './interface';
import warning from '../_util/warning';
import useStyle from './style/index';
import { ConfigContext } from '../config-provider';
import useLocale from '../locale/useLocale';
import Spin from '../spin';
import Button from '../button';
import theme from '../theme';
import warning from '../_util/warning';
import type { QRCodeProps, QRPropsCanvas } from './interface';
import useStyle from './style/index';
const { useToken } = theme;
@ -53,6 +53,8 @@ const QRCode: React.FC<QRCodeProps> = (props) => {
};
}, [errorLevel, color, icon, iconSize, size, value]);
const locale = useLocale('QRCode');
if (!value) {
if (process.env.NODE_ENV !== 'production') {
warning(false, 'QRCode', 'need to receive `value` props');
@ -73,28 +75,24 @@ const QRCode: React.FC<QRCodeProps> = (props) => {
});
return wrapSSR(
<LocaleReceiver componentName="QRCode">
{(locale) => (
<div style={{ ...style, width: size, height: size }} className={cls}>
{status !== 'active' && (
<div className={`${prefixCls}-mask`}>
{status === 'loading' && <Spin />}
{status === 'expired' && (
<>
<p className={`${prefixCls}-expired`}>{locale.expired}</p>
{typeof onRefresh === 'function' && (
<Button type="link" icon={<ReloadOutlined />} onClick={onRefresh}>
{locale.refresh}
</Button>
)}
</>
<div style={{ ...style, width: size, height: size }} className={cls}>
{status !== 'active' && (
<div className={`${prefixCls}-mask`}>
{status === 'loading' && <Spin />}
{status === 'expired' && (
<>
<p className={`${prefixCls}-expired`}>{locale?.expired}</p>
{typeof onRefresh === 'function' && (
<Button type="link" icon={<ReloadOutlined />} onClick={onRefresh}>
{locale?.refresh}
</Button>
)}
</div>
</>
)}
<QRCodeCanvas {...qrCodeProps} />
</div>
)}
</LocaleReceiver>,
<QRCodeCanvas {...qrCodeProps} />
</div>,
);
};

86
components/tour/panelRender.tsx

@ -5,7 +5,7 @@ import React from 'react';
import type { ButtonProps } from '../button';
import Button from '../button';
import defaultLocale from '../locale/en_US';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import type { TourStepProps } from './interface';
function isValidNode(node: ReactNode): boolean {
@ -92,52 +92,50 @@ const TourPanel: React.FC<TourPanelProps> = ({ stepProps, current, type, indicat
ghost: mergedType === 'primary',
};
const contextLocale = useLocale('Tour', defaultLocale.Tour);
return (
<LocaleReceiver componentName="Tour" defaultLocale={defaultLocale.Tour}>
{(contextLocale) => (
<div
className={classNames(
mergedType === 'primary' ? `${prefixCls}-primary` : '',
className,
`${prefixCls}-content`,
)}
>
{arrow && <div className={`${prefixCls}-arrow`} key="arrow" />}
<div className={`${prefixCls}-inner`}>
<CloseOutlined className={`${prefixCls}-close`} onClick={onClose} />
{coverNode}
{headerNode}
{descriptionNode}
<div className={`${prefixCls}-footer`}>
{total > 1 && <div className={`${prefixCls}-indicators`}>{mergeIndicatorNode}</div>}
<div className={`${prefixCls}-buttons`}>
{current !== 0 ? (
<Button
{...secondaryBtnProps}
{...prevButtonProps}
onClick={prevBtnClick}
size="small"
className={classNames(`${prefixCls}-prev-btn`, prevButtonProps?.className)}
>
{prevButtonProps?.children ?? contextLocale.Previous}
</Button>
) : null}
<Button
type={mainBtnType}
{...nextButtonProps}
onClick={nextBtnClick}
size="small"
className={classNames(`${prefixCls}-next-btn`, nextButtonProps?.className)}
>
{nextButtonProps?.children ??
(isLastStep ? contextLocale.Finish : contextLocale.Next)}
</Button>
</div>
</div>
<div
className={classNames(
mergedType === 'primary' ? `${prefixCls}-primary` : '',
className,
`${prefixCls}-content`,
)}
>
{arrow && <div className={`${prefixCls}-arrow`} key="arrow" />}
<div className={`${prefixCls}-inner`}>
<CloseOutlined className={`${prefixCls}-close`} onClick={onClose} />
{coverNode}
{headerNode}
{descriptionNode}
<div className={`${prefixCls}-footer`}>
{total > 1 && <div className={`${prefixCls}-indicators`}>{mergeIndicatorNode}</div>}
<div className={`${prefixCls}-buttons`}>
{current !== 0 ? (
<Button
{...secondaryBtnProps}
{...prevButtonProps}
onClick={prevBtnClick}
size="small"
className={classNames(`${prefixCls}-prev-btn`, prevButtonProps?.className)}
>
{prevButtonProps?.children ?? contextLocale?.Previous}
</Button>
) : null}
<Button
type={mainBtnType}
{...nextButtonProps}
onClick={nextBtnClick}
size="small"
className={classNames(`${prefixCls}-next-btn`, nextButtonProps?.className)}
>
{nextButtonProps?.children ??
(isLastStep ? contextLocale?.Finish : contextLocale?.Next)}
</Button>
</div>
</div>
)}
</LocaleReceiver>
</div>
</div>
);
};

73
components/transfer/ListItem.tsx

@ -3,8 +3,8 @@ import classNames from 'classnames';
import * as React from 'react';
import type { KeyWiseTransferItem } from '.';
import Checkbox from '../checkbox';
import LocaleReceiver from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US';
import useLocale from '../locale/useLocale';
import TransButton from '../_util/transButton';
type ListItemProps<RecordType> = {
@ -43,45 +43,42 @@ const ListItem = <RecordType extends KeyWiseTransferItem>(props: ListItemProps<R
title = String(renderedText);
}
return (
<LocaleReceiver componentName="Transfer" defaultLocale={defaultLocale.Transfer}>
{(contextLocale) => {
const liProps: React.HTMLAttributes<HTMLLIElement> = { className, title };
const labelNode = <span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>;
const contextLocale = useLocale('Transfer', defaultLocale.Transfer);
const liProps: React.HTMLAttributes<HTMLLIElement> = { className, title };
const labelNode = <span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>;
// Show remove
if (showRemove) {
return (
<li {...liProps}>
{labelNode}
<TransButton
disabled={disabled || item.disabled}
className={`${prefixCls}-content-item-remove`}
aria-label={contextLocale.remove}
onClick={() => {
onRemove?.(item);
}}
>
<DeleteOutlined />
</TransButton>
</li>
);
}
if (showRemove) {
return (
<li {...liProps}>
{labelNode}
<TransButton
disabled={disabled || item.disabled}
className={`${prefixCls}-content-item-remove`}
aria-label={contextLocale?.remove}
onClick={() => {
onRemove?.(item);
}}
>
<DeleteOutlined />
</TransButton>
</li>
);
}
// Default click to select
liProps.onClick = disabled || item.disabled ? undefined : () => onClick(item);
// Default click to select
liProps.onClick = disabled || item.disabled ? undefined : () => onClick(item);
return (
<li {...liProps}>
<Checkbox
className={`${prefixCls}-checkbox`}
checked={checked}
disabled={disabled || item.disabled}
/>
{labelNode}
</li>
);
}}
</LocaleReceiver>
return (
<li {...liProps}>
<Checkbox
className={`${prefixCls}-checkbox`}
checked={checked}
disabled={disabled || item.disabled}
/>
{labelNode}
</li>
);
};

142
components/transfer/index.tsx

@ -7,7 +7,7 @@ import DefaultRenderEmpty from '../config-provider/defaultRenderEmpty';
import type { FormItemStatusContextProps } from '../form/context';
import { FormItemInputContext } from '../form/context';
import defaultLocale from '../locale/en_US';
import LocaleReceiver from '../locale/LocaleReceiver';
import useLocale from '../locale/useLocale';
import type { InputStatus } from '../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
import { groupDisabledKeysMap, groupKeysMap } from '../_util/transKeys';
@ -367,78 +367,76 @@ const Transfer = <RecordType extends TransferItem = TransferItem>(
hashId,
);
const contextLocale = useLocale('Transfer', defaultLocale.Transfer);
const listLocale = getLocale(contextLocale!);
const [leftTitle, rightTitle] = getTitles(listLocale);
return wrapSSR(
<LocaleReceiver componentName="Transfer" defaultLocale={defaultLocale.Transfer}>
{(contextLocale) => {
const listLocale = getLocale(contextLocale);
const [leftTitle, rightTitle] = getTitles(listLocale);
return (
<div className={cls} style={style}>
<List<KeyWise<RecordType>>
prefixCls={`${prefixCls}-list`}
titleText={leftTitle}
dataSource={leftDataSource}
filterOption={filterOption}
style={handleListStyle('left')}
checkedKeys={sourceSelectedKeys}
handleFilter={leftFilter}
handleClear={handleLeftClear}
onItemSelect={onLeftItemSelect}
onItemSelectAll={onLeftItemSelectAll}
render={render}
showSearch={showSearch}
renderList={children}
footer={footer}
onScroll={handleLeftScroll}
disabled={disabled}
direction={dir === 'rtl' ? 'right' : 'left'}
showSelectAll={showSelectAll}
selectAllLabel={selectAllLabels[0]}
pagination={mergedPagination}
{...listLocale}
/>
<Operation
className={`${prefixCls}-operation`}
rightActive={rightActive}
rightArrowText={operations[0]}
moveToRight={moveToRight}
leftActive={leftActive}
leftArrowText={operations[1]}
moveToLeft={moveToLeft}
style={operationStyle}
disabled={disabled}
direction={dir}
oneWay={oneWay}
/>
<List<KeyWise<RecordType>>
prefixCls={`${prefixCls}-list`}
titleText={rightTitle}
dataSource={rightDataSource}
filterOption={filterOption}
style={handleListStyle('right')}
checkedKeys={targetSelectedKeys}
handleFilter={rightFilter}
handleClear={handleRightClear}
onItemSelect={onRightItemSelect}
onItemSelectAll={onRightItemSelectAll}
onItemRemove={onRightItemRemove}
render={render}
showSearch={showSearch}
renderList={children}
footer={footer}
onScroll={handleRightScroll}
disabled={disabled}
direction={dir === 'rtl' ? 'left' : 'right'}
showSelectAll={showSelectAll}
selectAllLabel={selectAllLabels[1]}
showRemove={oneWay}
pagination={mergedPagination}
{...listLocale}
/>
</div>
);
}}
</LocaleReceiver>,
<div className={cls} style={style}>
<List<KeyWise<RecordType>>
prefixCls={`${prefixCls}-list`}
titleText={leftTitle}
dataSource={leftDataSource}
filterOption={filterOption}
style={handleListStyle('left')}
checkedKeys={sourceSelectedKeys}
handleFilter={leftFilter}
handleClear={handleLeftClear}
onItemSelect={onLeftItemSelect}
onItemSelectAll={onLeftItemSelectAll}
render={render}
showSearch={showSearch}
renderList={children}
footer={footer}
onScroll={handleLeftScroll}
disabled={disabled}
direction={dir === 'rtl' ? 'right' : 'left'}
showSelectAll={showSelectAll}
selectAllLabel={selectAllLabels[0]}
pagination={mergedPagination}
{...listLocale}
/>
<Operation
className={`${prefixCls}-operation`}
rightActive={rightActive}
rightArrowText={operations[0]}
moveToRight={moveToRight}
leftActive={leftActive}
leftArrowText={operations[1]}
moveToLeft={moveToLeft}
style={operationStyle}
disabled={disabled}
direction={dir}
oneWay={oneWay}
/>
<List<KeyWise<RecordType>>
prefixCls={`${prefixCls}-list`}
titleText={rightTitle}
dataSource={rightDataSource}
filterOption={filterOption}
style={handleListStyle('right')}
checkedKeys={targetSelectedKeys}
handleFilter={rightFilter}
handleClear={handleRightClear}
onItemSelect={onRightItemSelect}
onItemSelectAll={onRightItemSelectAll}
onItemRemove={onRightItemRemove}
render={render}
showSearch={showSearch}
renderList={children}
footer={footer}
onScroll={handleRightScroll}
disabled={disabled}
direction={dir === 'rtl' ? 'left' : 'right'}
showSelectAll={showSelectAll}
selectAllLabel={selectAllLabels[1]}
showRemove={oneWay}
pagination={mergedPagination}
{...listLocale}
/>
</div>,
);
};

20
components/typography/Base/index.tsx

@ -12,11 +12,11 @@ import omit from 'rc-util/lib/omit';
import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react';
import { ConfigContext } from '../../config-provider';
import { useLocaleReceiver } from '../../locale/LocaleReceiver';
import TransButton from '../../_util/transButton';
import { isStyleSupport } from '../../_util/styleChecker';
import useLocale from '../../locale/useLocale';
import type { TooltipProps } from '../../tooltip';
import Tooltip from '../../tooltip';
import { isStyleSupport } from '../../_util/styleChecker';
import TransButton from '../../_util/transButton';
import Editable from '../Editable';
import useMergedConfig from '../hooks/useMergedConfig';
import useUpdatedEffect from '../hooks/useUpdatedEffect';
@ -135,7 +135,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
...restProps
} = props;
const { getPrefixCls, direction } = React.useContext(ConfigContext);
const textLocale = useLocaleReceiver('Text')[0]!; // Force TS get this
const textLocale = useLocale('Text');
const typographyRef = React.useRef<HTMLElement>(null);
const editIconRef = React.useRef<HTMLDivElement>(null);
@ -408,7 +408,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
if (symbol) {
expandContent = symbol;
} else {
expandContent = textLocale.expand;
expandContent = textLocale?.expand;
}
return (
@ -416,7 +416,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
key="expand"
className={`${prefixCls}-expand`}
onClick={onExpandClick}
aria-label={textLocale.expand}
aria-label={textLocale?.expand}
>
{expandContent}
</a>
@ -429,7 +429,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
const { icon, tooltip } = editConfig;
const editTitle = toArray(tooltip)[0] || textLocale.edit;
const editTitle = toArray(tooltip)[0] || textLocale?.edit;
const ariaLabel = typeof editTitle === 'string' ? editTitle : '';
return triggerType.includes('icon') ? (
@ -456,9 +456,9 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
const iconNodes = toList(icon);
const copyTitle = copied
? getNode(tooltipNodes[1], textLocale.copied)
: getNode(tooltipNodes[0], textLocale.copy);
const systemStr = copied ? textLocale.copied : textLocale.copy;
? getNode(tooltipNodes[1], textLocale?.copied)
: getNode(tooltipNodes[0], textLocale?.copy);
const systemStr = copied ? textLocale?.copied : textLocale?.copy;
const ariaLabel = typeof copyTitle === 'string' ? copyTitle : systemStr;
return (

82
components/upload/Upload.tsx

@ -6,8 +6,8 @@ import * as React from 'react';
import { flushSync } from 'react-dom';
import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import LocaleReceiver from '../locale/LocaleReceiver';
import defaultLocale from '../locale/en_US';
import useLocale from '../locale/useLocale';
import warning from '../_util/warning';
import type { RcFile, ShowUploadListInterface, UploadChangeParam, UploadFile } from './interface';
import { UploadProps } from './interface';
@ -339,48 +339,46 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
const [wrapSSR, hashId] = useStyle(prefixCls);
const renderUploadList = (button?: React.ReactNode, buttonVisible?: boolean) =>
showUploadList ? (
<LocaleReceiver componentName="Upload" defaultLocale={defaultLocale.Upload}>
{(contextLocale) => {
const {
showRemoveIcon,
showPreviewIcon,
showDownloadIcon,
removeIcon,
previewIcon,
downloadIcon,
} =
typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList;
return (
<UploadList
prefixCls={prefixCls}
listType={listType}
items={mergedFileList}
previewFile={previewFile}
onPreview={onPreview}
onDownload={onDownload}
onRemove={handleRemove}
showRemoveIcon={!mergedDisabled && showRemoveIcon}
showPreviewIcon={showPreviewIcon}
showDownloadIcon={showDownloadIcon}
removeIcon={removeIcon}
previewIcon={previewIcon}
downloadIcon={downloadIcon}
iconRender={iconRender}
locale={{ ...contextLocale, ...propLocale }}
isImageUrl={isImageUrl}
progress={progress}
appendAction={button}
appendActionVisible={buttonVisible}
itemRender={itemRender}
/>
);
}}
</LocaleReceiver>
) : (
button
const contextLocale = useLocale('Upload', defaultLocale.Upload);
const {
showRemoveIcon,
showPreviewIcon,
showDownloadIcon,
removeIcon,
previewIcon,
downloadIcon,
} = typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList;
const renderUploadList = (button?: React.ReactNode, buttonVisible?: boolean) => {
if (!showUploadList) {
return button;
}
return (
<UploadList
prefixCls={prefixCls}
listType={listType}
items={mergedFileList}
previewFile={previewFile}
onPreview={onPreview}
onDownload={onDownload}
onRemove={handleRemove}
showRemoveIcon={!mergedDisabled && showRemoveIcon}
showPreviewIcon={showPreviewIcon}
showDownloadIcon={showDownloadIcon}
removeIcon={removeIcon}
previewIcon={previewIcon}
downloadIcon={downloadIcon}
iconRender={iconRender}
locale={{ ...contextLocale, ...propLocale }}
isImageUrl={isImageUrl}
progress={progress}
appendAction={button}
appendActionVisible={buttonVisible}
itemRender={itemRender}
/>
);
};
const rtlCls = {
[`${prefixCls}-rtl`]: direction === 'rtl',

Loading…
Cancel
Save