Skip to content

Commit f4ba7b4

Browse files
youlunaguanpu
authored andcommitted
feat(Grid): support rtl
1 parent dcf3eda commit f4ba7b4

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

src/form/item.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default class Item extends React.Component {
1818
* 样式前缀
1919
*/
2020
prefix: PropTypes.string,
21+
rtl: PropTypes.bool,
2122
/**
2223
* label 标签的文本
2324
*/

src/grid/col.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default class Col extends Component {
1414
static propTypes = {
1515
prefix: PropTypes.string,
1616
pure: PropTypes.bool,
17+
rtl: PropTypes.bool,
1718
className: PropTypes.string,
1819
/**
1920
* 列内容
@@ -83,7 +84,7 @@ export default class Col extends Component {
8384
/* eslint-disable no-unused-vars */
8485
const {
8586
prefix, pure, span, offset, fixedSpan, fixedOffset, hidden, align,
86-
xxs, xs, s, m, l, xl, component: Tag, className, children, ...others
87+
xxs, xs, s, m, l, xl, component: Tag, className, children, rtl, ...others
8788
} = this.props;
8889
/* eslint-enable no-unused-vars */
8990

@@ -127,6 +128,7 @@ export default class Col extends Component {
127128

128129
return (
129130
<Tag
131+
dir={rtl ? 'rtl' : 'ltr'}
130132
role="gridcell"
131133
className={classes}
132134
{...others}

src/grid/main.scss

+2
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@
109109

110110
@include visible-hidden-all-points();
111111
@include visible-hidden-all-points-row();
112+
113+
@import "./rtl.scss";

src/grid/row.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class Row extends Component {
1010
static propTypes = {
1111
prefix: PropTypes.string,
1212
pure: PropTypes.bool,
13+
rtl: PropTypes.bool,
1314
className: PropTypes.string,
1415
style: PropTypes.object,
1516
/**
@@ -67,7 +68,7 @@ export default class Row extends Component {
6768
/* eslint-disable no-unused-vars */
6869
const {
6970
prefix, pure, wrap, fixed, gutter, fixedWidth, align, justify,
70-
hidden, className, component: Tag, children, ...others
71+
hidden, className, component: Tag, children, rtl, ...others
7172
} = this.props;
7273
/* eslint-enable no-unused-vars */
7374

@@ -126,6 +127,7 @@ export default class Row extends Component {
126127

127128
return (
128129
<Tag
130+
dir={rtl ? 'rtl' : 'ltr'}
129131
role="row"
130132
className={newClassName}
131133
{...others}

src/grid/rtl.scss

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
// 响应列的水平位置偏移
3+
@mixin make-offset-rtl() {
4+
@for $i from 1 through $grid-columns {
5+
.#{$css-prefix}col-offset-#{$i}[dir="rtl"] {
6+
margin-right: percentage($i / $grid-columns);
7+
margin-left: auto;
8+
}
9+
}
10+
@each $breakpoint in $breakpoints {
11+
$name: #{nth($breakpoint, 1)};
12+
@include breakpoint($name) {
13+
@for $j from 1 through $grid-columns {
14+
.#{$css-prefix}col-#{$name}-offset-#{$j}[dir="rtl"] {
15+
margin-right: percentage($j / $grid-columns);
16+
margin-left: auto;
17+
}
18+
}
19+
}
20+
}
21+
}
22+
23+
// 固定列的水平位置偏移
24+
@mixin make-offset-fixed-rtl() {
25+
@for $i from 1 through $grid-columns-fixed {
26+
.#{$css-prefix}col-offset-fixed-#{$i}[dir="rtl"] {
27+
margin-right: $i * $grid-col-fixed-width;
28+
margin-left: auto;
29+
}
30+
}
31+
@each $breakpoint in $breakpoints {
32+
$name: #{nth($breakpoint, 1)};
33+
@for $j from 1 through $grid-columns-fixed {
34+
.#{$css-prefix}col-offset-fixed-#{$name}-#{$j}[dir="rtl"] {
35+
margin-right: $j * $grid-col-fixed-width;
36+
margin-left: auto;
37+
}
38+
}
39+
}
40+
}
41+
42+
@include make-offset-rtl();
43+
@include make-offset-fixed-rtl();

0 commit comments

Comments
 (0)