fix: Progress.Line strokeColor direction in rtl (#27515)

This commit is contained in:
xrkffgg 2020-11-03 16:22:18 +08:00 committed by GitHub
parent 114dde6373
commit 3c157e637d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -8,6 +8,8 @@ export interface CSPConfig {
nonce?: string; nonce?: string;
} }
export type DirectionType = 'ltr' | 'rtl' | undefined;
export interface ConfigConsumerProps { export interface ConfigConsumerProps {
getTargetContainer?: () => HTMLElement; getTargetContainer?: () => HTMLElement;
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement; getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
@ -23,7 +25,7 @@ export interface ConfigConsumerProps {
pageHeader?: { pageHeader?: {
ghost: boolean; ghost: boolean;
}; };
direction?: 'ltr' | 'rtl'; direction?: DirectionType;
space?: { space?: {
size?: SizeType | number; size?: SizeType | number;
}; };

View File

@ -7,13 +7,26 @@ import { ValidateMessages } from 'rc-field-form/lib/interface';
import { RenderEmptyHandler } from './renderEmpty'; import { RenderEmptyHandler } from './renderEmpty';
import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider'; import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { ConfigConsumer, ConfigContext, CSPConfig, ConfigConsumerProps } from './context'; import {
ConfigConsumer,
ConfigContext,
CSPConfig,
DirectionType,
ConfigConsumerProps,
} from './context';
import { SizeType, SizeContextProvider } from './SizeContext'; import { SizeType, SizeContextProvider } from './SizeContext';
import message from '../message'; import message from '../message';
import notification from '../notification'; import notification from '../notification';
import { RequiredMark } from '../form/Form'; import { RequiredMark } from '../form/Form';
export { RenderEmptyHandler, ConfigContext, ConfigConsumer, CSPConfig, ConfigConsumerProps }; export {
RenderEmptyHandler,
ConfigContext,
ConfigConsumer,
CSPConfig,
DirectionType,
ConfigConsumerProps,
};
export const configConsumerProps = [ export const configConsumerProps = [
'getTargetContainer', 'getTargetContainer',
@ -47,7 +60,7 @@ export interface ConfigProviderProps {
ghost: boolean; ghost: boolean;
}; };
componentSize?: SizeType; componentSize?: SizeType;
direction?: 'ltr' | 'rtl'; direction?: DirectionType;
space?: { space?: {
size?: SizeType | number; size?: SizeType | number;
}; };

View File

@ -2,9 +2,11 @@ import * as React from 'react';
import { presetPrimaryColors } from '@ant-design/colors'; import { presetPrimaryColors } from '@ant-design/colors';
import { ProgressGradient, ProgressProps, StringGradients } from './progress'; import { ProgressGradient, ProgressProps, StringGradients } from './progress';
import { validProgress, getSuccessPercent } from './utils'; import { validProgress, getSuccessPercent } from './utils';
import { DirectionType } from '../config-provider';
interface LineProps extends ProgressProps { interface LineProps extends ProgressProps {
prefixCls: string; prefixCls: string;
direction?: DirectionType;
children: React.ReactNode; children: React.ReactNode;
} }
@ -47,11 +49,11 @@ export const sortGradient = (gradients: StringGradients) => {
* And... * And...
* Besides women, there is the code. * Besides women, there is the code.
*/ */
export const handleGradient = (strokeColor: ProgressGradient) => { export const handleGradient = (strokeColor: ProgressGradient, directionConfig: DirectionType) => {
const { const {
from = presetPrimaryColors.blue, from = presetPrimaryColors.blue,
to = presetPrimaryColors.blue, to = presetPrimaryColors.blue,
direction = 'to right', direction = directionConfig === 'rtl' ? 'to left' : 'to right',
...rest ...rest
} = strokeColor; } = strokeColor;
if (Object.keys(rest).length !== 0) { if (Object.keys(rest).length !== 0) {
@ -64,6 +66,7 @@ export const handleGradient = (strokeColor: ProgressGradient) => {
const Line: React.FC<LineProps> = props => { const Line: React.FC<LineProps> = props => {
const { const {
prefixCls, prefixCls,
direction: directionConfig,
percent, percent,
strokeWidth, strokeWidth,
size, size,
@ -76,7 +79,7 @@ const Line: React.FC<LineProps> = props => {
const backgroundProps = const backgroundProps =
strokeColor && typeof strokeColor !== 'string' strokeColor && typeof strokeColor !== 'string'
? handleGradient(strokeColor) ? handleGradient(strokeColor, directionConfig)
: { : {
background: strokeColor, background: strokeColor,
}; };

View File

@ -137,7 +137,7 @@ export default class Progress extends React.Component<ProgressProps> {
{progressInfo} {progressInfo}
</Steps> </Steps>
) : ( ) : (
<Line {...this.props} prefixCls={prefixCls}> <Line {...this.props} prefixCls={prefixCls} direction={direction}>
{progressInfo} {progressInfo}
</Line> </Line>
); );