refactor: convertLegacyProps function moved to buttonHelpers (#44777)

This commit is contained in:
Rinku Chaudhari 2023-09-12 09:23:11 +05:45 committed by GitHub
parent bcf7c924e2
commit c9e94c26f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import useState from 'rc-util/lib/hooks/useState';
import * as React from 'react'; import * as React from 'react';
import Button from '../button'; import Button from '../button';
import type { ButtonProps, LegacyButtonType } from '../button/button'; import type { ButtonProps, LegacyButtonType } from '../button/button';
import { convertLegacyProps } from '../button/button'; import { convertLegacyProps } from '../button/buttonHelpers';
export interface ActionButtonProps { export interface ActionButtonProps {
type?: LegacyButtonType; type?: LegacyButtonType;

View File

@ -29,15 +29,6 @@ import CompactCmp from './style/compactCmp';
export type LegacyButtonType = ButtonType | 'danger'; export type LegacyButtonType = ButtonType | 'danger';
export function convertLegacyProps(
type?: LegacyButtonType,
): Pick<BaseButtonProps, 'danger' | 'type'> {
if (type === 'danger') {
return { danger: true };
}
return { type };
}
export interface BaseButtonProps { export interface BaseButtonProps {
type?: ButtonType; type?: ButtonType;
icon?: React.ReactNode; icon?: React.ReactNode;

View File

@ -1,9 +1,19 @@
import React from 'react'; import React from 'react';
import { cloneElement, isFragment } from '../_util/reactNode'; import { cloneElement, isFragment } from '../_util/reactNode';
import type { BaseButtonProps, LegacyButtonType } from './button';
const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/; const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
export const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar); export const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
export function convertLegacyProps(
type?: LegacyButtonType,
): Pick<BaseButtonProps, 'danger' | 'type'> {
if (type === 'danger') {
return { danger: true };
}
return { type };
}
export function isString(str: any): str is string { export function isString(str: any): str is string {
return typeof str === 'string'; return typeof str === 'string';
} }

View File

@ -2,7 +2,7 @@ import type { FC } from 'react';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import Button from '../../button'; import Button from '../../button';
import { convertLegacyProps } from '../../button/button'; import { convertLegacyProps } from '../../button/buttonHelpers';
import { ModalContext } from '../context'; import { ModalContext } from '../context';
import type { ModalProps } from '../interface'; import type { ModalProps } from '../interface';

View File

@ -5,7 +5,7 @@ import type { PopconfirmProps } from '.';
import ActionButton from '../_util/ActionButton'; import ActionButton from '../_util/ActionButton';
import { getRenderPropValue } from '../_util/getRenderPropValue'; import { getRenderPropValue } from '../_util/getRenderPropValue';
import Button from '../button'; import Button from '../button';
import { convertLegacyProps } from '../button/button'; import { convertLegacyProps } from '../button/buttonHelpers';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import { useLocale } from '../locale'; import { useLocale } from '../locale';
import defaultLocale from '../locale/en_US'; import defaultLocale from '../locale/en_US';