Browse Source

chore: code style optimization (#43458)

pull/43461/head
thinkasany 1 year ago
committed by GitHub
parent
commit
efa427072a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      components/badge/Ribbon.tsx
  2. 20
      components/badge/ScrollNumber.tsx
  3. 11
      components/button/LoadingIcon.tsx
  4. 16
      components/input/TextArea.tsx
  5. 14
      components/typography/Typography.tsx

9
components/badge/Ribbon.tsx

@ -1,10 +1,10 @@
import classNames from 'classnames'; import classNames from 'classnames';
import * as React from 'react'; import * as React from 'react';
import { ConfigContext } from '../config-provider';
import type { PresetColorType } from '../_util/colors'; import type { PresetColorType } from '../_util/colors';
import { isPresetColor } from '../_util/colors';
import type { LiteralUnion } from '../_util/type'; import type { LiteralUnion } from '../_util/type';
import { ConfigContext } from '../config-provider';
import useStyle from './style'; import useStyle from './style';
import { isPresetColor } from '../_util/colors';
type RibbonPlacement = 'start' | 'end'; type RibbonPlacement = 'start' | 'end';
@ -18,7 +18,8 @@ export interface RibbonProps {
placement?: RibbonPlacement; placement?: RibbonPlacement;
} }
const Ribbon: React.FC<RibbonProps> = ({ const Ribbon: React.FC<RibbonProps> = (props) => {
const {
className, className,
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
style, style,
@ -26,7 +27,7 @@ const Ribbon: React.FC<RibbonProps> = ({
children, children,
text, text,
placement = 'end', placement = 'end',
}) => { } = props;
const { getPrefixCls, direction } = React.useContext(ConfigContext); const { getPrefixCls, direction } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('ribbon', customizePrefixCls); const prefixCls = getPrefixCls('ribbon', customizePrefixCls);
const colorInPreset = isPresetColor(color, false); const colorInPreset = isPresetColor(color, false);

20
components/badge/ScrollNumber.tsx

@ -1,7 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import * as React from 'react'; import * as React from 'react';
import { ConfigContext } from '../config-provider';
import { cloneElement } from '../_util/reactNode'; import { cloneElement } from '../_util/reactNode';
import { ConfigContext } from '../config-provider';
import SingleNumber from './SingleNumber'; import SingleNumber from './SingleNumber';
export interface ScrollNumberProps { export interface ScrollNumberProps {
@ -21,9 +21,8 @@ export interface ScrollNumberState {
count?: string | number | null; count?: string | number | null;
} }
const ScrollNumber = React.forwardRef<HTMLElement, ScrollNumberProps>( const ScrollNumber = React.forwardRef<HTMLElement, ScrollNumberProps>((props, ref) => {
( const {
{
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
count, count,
className, className,
@ -34,9 +33,7 @@ const ScrollNumber = React.forwardRef<HTMLElement, ScrollNumberProps>(
component: Component = 'sup', component: Component = 'sup',
children, children,
...restProps ...restProps
}, } = props;
ref,
) => {
const { getPrefixCls } = React.useContext(ConfigContext); const { getPrefixCls } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('scroll-number', customizePrefixCls); const prefixCls = getPrefixCls('scroll-number', customizePrefixCls);
@ -76,11 +73,7 @@ const ScrollNumber = React.forwardRef<HTMLElement, ScrollNumberProps>(
} }
if (children) { if (children) {
return cloneElement(children, (oriProps) => ({ return cloneElement(children, (oriProps) => ({
className: classNames( className: classNames(`${prefixCls}-custom-component`, oriProps?.className, motionClassName),
`${prefixCls}-custom-component`,
oriProps?.className,
motionClassName,
),
})); }));
} }
@ -89,7 +82,6 @@ const ScrollNumber = React.forwardRef<HTMLElement, ScrollNumberProps>(
{numberNodes} {numberNodes}
</Component> </Component>
); );
}, });
);
export default ScrollNumber; export default ScrollNumber;

11
components/button/LoadingIcon.tsx

@ -1,7 +1,7 @@
import LoadingOutlined from '@ant-design/icons/LoadingOutlined'; import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import classNames from 'classnames';
import CSSMotion from 'rc-motion'; import CSSMotion from 'rc-motion';
import React, { forwardRef } from 'react'; import React, { forwardRef } from 'react';
import classNames from 'classnames';
import IconWrapper from './IconWrapper'; import IconWrapper from './IconWrapper';
type InnerLoadingIconProps = { type InnerLoadingIconProps = {
@ -43,13 +43,8 @@ const getRealWidth = (node: HTMLElement): React.CSSProperties => ({
transform: 'scale(1)', transform: 'scale(1)',
}); });
const LoadingIcon: React.FC<LoadingIconProps> = ({ const LoadingIcon: React.FC<LoadingIconProps> = (props) => {
prefixCls, const { prefixCls, loading, existIcon, className, style } = props;
loading,
existIcon,
className,
style,
}) => {
const visible = !!loading; const visible = !!loading;
if (existIcon) { if (existIcon) {

16
components/input/TextArea.tsx

@ -29,9 +29,8 @@ export interface TextAreaRef {
resizableTextArea?: RcTextAreaRef['resizableTextArea']; resizableTextArea?: RcTextAreaRef['resizableTextArea'];
} }
const TextArea = forwardRef<TextAreaRef, TextAreaProps>( const TextArea = forwardRef<TextAreaRef, TextAreaProps>((props, ref) => {
( const {
{
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
bordered = true, bordered = true,
size: customizeSize, size: customizeSize,
@ -41,9 +40,7 @@ const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
showCount, showCount,
classNames: classes, classNames: classes,
...rest ...rest
}, } = props;
ref,
) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext); const { getPrefixCls, direction } = React.useContext(ConfigContext);
// ===================== Size ===================== // ===================== Size =====================
@ -118,14 +115,11 @@ const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
), ),
}} }}
prefixCls={prefixCls} prefixCls={prefixCls}
suffix={ suffix={hasFeedback && <span className={`${prefixCls}-textarea-suffix`}>{feedbackIcon}</span>}
hasFeedback && <span className={`${prefixCls}-textarea-suffix`}>{feedbackIcon}</span>
}
showCount={showCount} showCount={showCount}
ref={innerRef} ref={innerRef}
/>, />,
); );
}, });
);
export default TextArea; export default TextArea;

14
components/typography/Typography.tsx

@ -1,9 +1,9 @@
import classNames from 'classnames'; import classNames from 'classnames';
import { composeRef } from 'rc-util/lib/ref'; import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react'; import * as React from 'react';
import warning from '../_util/warning';
import type { DirectionType } from '../config-provider'; import type { DirectionType } from '../config-provider';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import warning from '../_util/warning';
import useStyle from './style'; import useStyle from './style';
export interface TypographyProps<C extends keyof JSX.IntrinsicElements> export interface TypographyProps<C extends keyof JSX.IntrinsicElements>
@ -29,9 +29,8 @@ interface InternalTypographyProps<C extends keyof JSX.IntrinsicElements>
const Typography = React.forwardRef< const Typography = React.forwardRef<
HTMLElement, HTMLElement,
InternalTypographyProps<keyof JSX.IntrinsicElements> InternalTypographyProps<keyof JSX.IntrinsicElements>
>( >((props, ref) => {
( const {
{
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
component: Component = 'article', component: Component = 'article',
className, className,
@ -40,9 +39,7 @@ const Typography = React.forwardRef<
children, children,
direction: typographyDirection, direction: typographyDirection,
...restProps ...restProps
}, } = props;
ref,
) => {
const { getPrefixCls, direction: contextDirection } = React.useContext(ConfigContext); const { getPrefixCls, direction: contextDirection } = React.useContext(ConfigContext);
const direction = typographyDirection ?? contextDirection; const direction = typographyDirection ?? contextDirection;
@ -74,8 +71,7 @@ const Typography = React.forwardRef<
{children} {children}
</Component>, </Component>,
); );
}, });
);
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
Typography.displayName = 'Typography'; Typography.displayName = 'Typography';

Loading…
Cancel
Save