Skip to content

Commit

Permalink
feat(Button): support rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Nov 28, 2018
1 parent 8661be2 commit d863787
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/button/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,5 @@
}
}
}

@import './rtl.scss';
121 changes: 121 additions & 0 deletions src/button/rtl.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@mixin next-button-size-rtl(
$padding,
$icon-margin,
$icon-size,
$corner
) {
border-radius: $corner;
& > #{$btn-prefix}-icon#{$btn-icon-prefix}-first {
@include icon-size($icon-size, $icon-margin, 0);
}
& > #{$btn-prefix}-icon#{$btn-icon-prefix}-last {
@include icon-size($icon-size, 0, $icon-margin);
}

&#{$btn-prefix}-loading {
padding-left: $padding;
padding-right: $padding + $icon-size + $icon-margin;

&:after {
right: $padding;
top: 50%;
margin-right: 0;
margin-left: $icon-margin;
}
}
}

/* 组合 */
/* ---------------------------------------- */
#{$btn-prefix}-group[dir="rtl"] {
> #{$btn-prefix} {
float: right;
}

#{$btn-prefix}#{$btn-prefix} {
margin: 0 -1px 0 0;
}

> #{$btn-prefix}:first-child:not(:last-child) {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}

> #{$btn-prefix}:last-child:not(:first-child) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}

> #{$btn-prefix}-primary:not(:first-child) {
border-right-color: transparentize($color-white, .8);

&:hover {
border-right-color: transparent;
}
&.disabled,
&[disabled] {
border-right-color: $color-line1-1;
}
}
}

#{$btn-prefix}[dir="rtl"] {
&#{$btn-prefix} {
/* 尺寸维度 */
/* ---------------------------------------- */
&.#{$css-prefix} {
&small {
@include next-button-size-rtl(
$btn-size-s-padding,
$btn-size-s-icon-margin,
$btn-size-s-icon-size,
$btn-size-s-corner
);
}
&medium {
@include next-button-size-rtl(
$btn-size-m-padding,
$btn-size-m-icon-margin,
$btn-size-m-icon-size,
$btn-size-m-corner,
);
}
&large {
@include next-button-size-rtl(
$btn-size-l-padding,
$btn-size-l-icon-margin,
$btn-size-l-icon-size,
$btn-size-l-corner,
);
}
}

/* 文本按钮 */
&-text {
&.#{$css-prefix}large {
@include next-button-size-rtl(
0,
$btn-text-icon-l-margin,
$btn-size-l-icon-size,
0
);
}
&.#{$css-prefix}medium {
@include next-button-size-rtl(
0,
$btn-text-icon-m-margin,
$btn-size-m-icon-size,
0
);
}
&.#{$css-prefix}small {
@include next-button-size-rtl(
0,
$btn-text-icon-s-margin,
$btn-size-s-icon-size,
0
);
}
}
}
}
5 changes: 3 additions & 2 deletions src/button/view/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function mapIconSize(size) {
export default class Button extends Component {
static propTypes = {
prefix: PropTypes.string,
rtl: PropTypes.bool,
/**
* 按钮的类型
*/
Expand Down Expand Up @@ -91,7 +92,7 @@ export default class Button extends Component {
};

render() {
const { prefix, className, type, size, htmlType, loading, text, warning, ghost, component, iconSize, children, ...others } = this.props;
const { prefix, className, type, size, htmlType, loading, text, warning, ghost, component, iconSize, children, rtl, ...others } = this.props;
const ghostType = ['light', 'dark'].indexOf(ghost) >= 0 ? ghost : 'dark';

const btnCls = classNames({
Expand Down Expand Up @@ -142,7 +143,7 @@ export default class Button extends Component {
}

return (
<TagName {...tagAttrs} onMouseUp={this.onMouseUp} ref={this.buttonRefHandler} role="button">
<TagName {...tagAttrs} dir={rtl ? 'rtl' : undefined} onMouseUp={this.onMouseUp} ref={this.buttonRefHandler} role="button">
{clonedChildren}
</TagName>
);
Expand Down
7 changes: 6 additions & 1 deletion src/button/view/group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ConfigProvider from '../../config-provider';
*/
class ButtonGroup extends Component {
static propTypes = {
rtl: PropTypes.bool,
prefix: PropTypes.string,
/**
* 统一设置 Button 组件的按钮大小
Expand All @@ -23,7 +24,7 @@ class ButtonGroup extends Component {
};

render() {
const { prefix, className, size, children, ...others } = this.props;
const { prefix, className, size, children, rtl, ...others } = this.props;

const groupCls = classNames({
[`${prefix}btn-group`]: true,
Expand All @@ -38,6 +39,10 @@ class ButtonGroup extends Component {
}
});

if (rtl) {
others.dir = 'rtl';
}

return (
<div {...others} className={groupCls}>
{cloneChildren}
Expand Down

0 comments on commit d863787

Please sign in to comment.