Browse Source

fix: add rtl space (#22809)

* fix: add Space rtl

* fix: restore test

* fix: restore test

* add

* fix: fix lint

* fix: use original api

* fix: add rtl less
pull/22823/head
xrkffgg 5 years ago
committed by GitHub
parent
commit
a91506cb6b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      components/space/__tests__/index.test.js
  2. 17
      components/space/index.tsx
  3. 2
      components/space/style/index.less
  4. 10
      components/space/style/rtl.less

28
components/space/__tests__/index.test.js

@ -42,18 +42,8 @@ describe('Space', () => {
</Space>, </Space>,
); );
expect( expect(wrapper.find('.ant-space-item').at(0).prop('style').marginRight).toBe(10);
wrapper expect(wrapper.find('.ant-space-item').at(1).prop('style').marginRight).toBeUndefined();
.find('.ant-space-item')
.at(0)
.prop('style').marginRight,
).toBe(10);
expect(
wrapper
.find('.ant-space-item')
.at(1)
.prop('style').marginRight,
).toBeUndefined();
}); });
it('should render vertical space width customize size', () => { it('should render vertical space width customize size', () => {
@ -64,18 +54,8 @@ describe('Space', () => {
</Space>, </Space>,
); );
expect( expect(wrapper.find('.ant-space-item').at(0).prop('style').marginBottom).toBe(10);
wrapper expect(wrapper.find('.ant-space-item').at(1).prop('style').marginBottom).toBeUndefined();
.find('.ant-space-item')
.at(0)
.prop('style').marginBottom,
).toBe(10);
expect(
wrapper
.find('.ant-space-item')
.at(1)
.prop('style').marginBottom,
).toBeUndefined();
}); });
it('should render correct with children', () => { it('should render correct with children', () => {

17
components/space/index.tsx

@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import classnames from 'classnames'; import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray'; import toArray from 'rc-util/lib/Children/toArray';
import { ConfigConsumerProps, ConfigContext } from '../config-provider'; import { ConfigConsumerProps, ConfigContext } from '../config-provider';
import { SizeType } from '../config-provider/SizeContext'; import { SizeType } from '../config-provider/SizeContext';
@ -19,7 +19,9 @@ const spaceSize = {
}; };
const Space: React.FC<SpaceProps> = props => { const Space: React.FC<SpaceProps> = props => {
const { getPrefixCls, space }: ConfigConsumerProps = React.useContext(ConfigContext); const { getPrefixCls, space, direction: directionConfig }: ConfigConsumerProps = React.useContext(
ConfigContext,
);
const { const {
size = space?.size || 'small', size = space?.size || 'small',
@ -38,10 +40,17 @@ const Space: React.FC<SpaceProps> = props => {
} }
const prefixCls = getPrefixCls('space', customizePrefixCls); const prefixCls = getPrefixCls('space', customizePrefixCls);
const cn = classnames(prefixCls, `${prefixCls}-${direction}`, className); const cn = classNames(
prefixCls,
`${prefixCls}-${direction}`,
{ [`${prefixCls}-rtl`]: directionConfig === 'rtl' },
className,
);
const itemClassName = `${prefixCls}-item`; const itemClassName = `${prefixCls}-item`;
const marginDirection = directionConfig === 'rtl' ? 'marginLeft' : 'marginRight';
return ( return (
<div className={cn} {...otherProps}> <div className={cn} {...otherProps}>
{items.map((child, i) => ( {items.map((child, i) => (
@ -53,7 +62,7 @@ const Space: React.FC<SpaceProps> = props => {
i === len - 1 i === len - 1
? {} ? {}
: { : {
[direction === 'vertical' ? 'marginBottom' : 'marginRight']: [direction === 'vertical' ? 'marginBottom' : marginDirection]:
typeof size === 'string' ? spaceSize[size] : size, typeof size === 'string' ? spaceSize[size] : size,
} }
} }

2
components/space/style/index.less

@ -12,3 +12,5 @@
flex-direction: column; flex-direction: column;
} }
} }
@import './rtl';

10
components/space/style/rtl.less

@ -0,0 +1,10 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';
@space-prefix-cls: ~'@{ant-prefix}-space';
.@{space-prefix-cls} {
&-rtl {
direction: rtl;
}
}
Loading…
Cancel
Save