Skip to content

Commit

Permalink
fix: add rtl space (ant-design#22809)
Browse files Browse the repository at this point in the history
* fix: add Space rtl

* fix: restore test

* fix: restore test

* add

* fix: fix lint

* fix: use original api

* fix: add rtl less
  • Loading branch information
xrkffgg authored Apr 1, 2020
1 parent 06f29d0 commit a91506c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
28 changes: 4 additions & 24 deletions components/space/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,8 @@ describe('Space', () => {
</Space>,
);

expect(
wrapper
.find('.ant-space-item')
.at(0)
.prop('style').marginRight,
).toBe(10);
expect(
wrapper
.find('.ant-space-item')
.at(1)
.prop('style').marginRight,
).toBeUndefined();
expect(wrapper.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', () => {
Expand All @@ -64,18 +54,8 @@ describe('Space', () => {
</Space>,
);

expect(
wrapper
.find('.ant-space-item')
.at(0)
.prop('style').marginBottom,
).toBe(10);
expect(
wrapper
.find('.ant-space-item')
.at(1)
.prop('style').marginBottom,
).toBeUndefined();
expect(wrapper.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', () => {
Expand Down
17 changes: 13 additions & 4 deletions components/space/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import classnames from 'classnames';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import { ConfigConsumerProps, ConfigContext } from '../config-provider';
import { SizeType } from '../config-provider/SizeContext';
Expand All @@ -19,7 +19,9 @@ const spaceSize = {
};

const Space: React.FC<SpaceProps> = props => {
const { getPrefixCls, space }: ConfigConsumerProps = React.useContext(ConfigContext);
const { getPrefixCls, space, direction: directionConfig }: ConfigConsumerProps = React.useContext(
ConfigContext,
);

const {
size = space?.size || 'small',
Expand All @@ -38,10 +40,17 @@ const Space: React.FC<SpaceProps> = props => {
}

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 marginDirection = directionConfig === 'rtl' ? 'marginLeft' : 'marginRight';

return (
<div className={cn} {...otherProps}>
{items.map((child, i) => (
Expand All @@ -53,7 +62,7 @@ const Space: React.FC<SpaceProps> = props => {
i === len - 1
? {}
: {
[direction === 'vertical' ? 'marginBottom' : 'marginRight']:
[direction === 'vertical' ? 'marginBottom' : marginDirection]:
typeof size === 'string' ? spaceSize[size] : size,
}
}
Expand Down
2 changes: 2 additions & 0 deletions components/space/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
flex-direction: column;
}
}

@import './rtl';
10 changes: 10 additions & 0 deletions components/space/style/rtl.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';

@space-prefix-cls: ~'@{ant-prefix}-space';

.@{space-prefix-cls} {
&-rtl {
direction: rtl;
}
}

0 comments on commit a91506c

Please sign in to comment.