ant-design/style/mixins/button.less

287 lines
5.9 KiB
Plaintext
Raw Normal View History

2015-06-09 15:21:44 +08:00
// mixins for button
// ------------------------
.button-size(@padding; @font-size; @border-radius) {
padding: @padding;
font-size: @font-size;
border-radius: @border-radius;
}
.button-variant(@color; @background; @border) {
.button-color(@color; @background; @border);
&:hover {
2015-07-05 17:40:52 +08:00
.button-color(tint(@color, 20%); tint(@background, 20%); tint(@border, 20%));
2015-06-09 15:21:44 +08:00
}
&:active,
&.active {
2015-07-05 17:40:52 +08:00
.button-color(shade(@color, 5%); shade(@background, 5%); shade(@border, 5%));
2015-06-09 15:21:44 +08:00
}
&:active,
&.active {
background-image: none;
}
&.disabled,
&[disabled],
fieldset[disabled] & {
&,
&:hover,
&:active,
&.active {
.button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
}
}
}
.button-color(@color; @background; @border) {
color: @color;
background-color: @background;
border-color: @border;
}
.button-group-base(@btnClassName) {
position: relative;
display: inline-block;
vertical-align: middle;
> .@{btnClassName} {
position: relative;
float: left;
&:hover,
&:focus,
&:active,
&.active {
z-index: 2;
}
}
// size
&-lg > .@{btnClassName} {
.button-size(@btn-padding-lg; @btn-font-size-lg; @btn-border-radius-lg);
> .@{iconfont-css-prefix} {
font-size: @btn-font-size-lg + 2;
}
}
&-sm > .@{btnClassName} {
.button-size(@btn-padding-sm; @font-size-base; @btn-border-radius-sm);
> .@{iconfont-css-prefix} {
font-size: @font-size-base;
}
}
}
// Base styles of buttons
// --------------------------------------------------
.btn() {
display: inline-block;
margin-bottom: 0;
font-weight: @btn-font-weight;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
2015-06-17 18:22:02 +08:00
// outline: none;
2015-06-09 15:21:44 +08:00
white-space: nowrap;
line-height: @line-height-base;
.button-size(@btn-padding-base; @font-size-base; @btn-border-radius-base);
.user-select(none);
2015-06-15 19:33:39 +08:00
.transition(all .3s @ease-in-out);
2015-06-09 15:21:44 +08:00
-webkit-transform: translate3d(0, 0, 0);
> .@{iconfont-css-prefix} {
font-size: @font-size-base + 2;
2015-06-15 19:33:39 +08:00
line-height: 1;
2015-06-09 15:21:44 +08:00
z-index: 2;
}
&,
&:active,
&:focus {
outline: 0;
}
&:not([disabled]):hover {
text-decoration: none;
}
&:not([disabled]):active {
outline: 0;
2015-06-15 19:33:39 +08:00
.transition(none);
2015-06-09 15:21:44 +08:00
}
&.disabled,
&[disabled]{
cursor: @cursor-disabled;
}
&-lg {
.button-size(@btn-padding-lg; @btn-font-size-lg; @btn-border-radius-lg);
> .@{iconfont-css-prefix} {
2015-06-29 18:50:49 +08:00
font-size: @btn-font-size-lg + 2;
2015-06-09 15:21:44 +08:00
}
}
&-sm {
.button-size(@btn-padding-sm; @font-size-base; @btn-border-radius-sm);
> .@{iconfont-css-prefix} {
font-size: @font-size-base;
}
}
}
// primary button style
.btn-primary() {
.button-variant(@btn-primary-color; @btn-primary-bg; @btn-primary-border);
2015-06-11 17:16:32 +08:00
&:hover,
&:active,
&.active {
2015-06-29 18:50:49 +08:00
color: @btn-primary-color;
2015-06-11 17:16:32 +08:00
}
2015-06-09 15:21:44 +08:00
}
// default button style
.btn-default() {
.button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
2015-06-29 18:50:49 +08:00
&:hover {
2015-07-05 17:40:52 +08:00
.button-color(tint(@primary-color, 20%); @white; tint(@primary-color, 20%));
2015-06-29 18:50:49 +08:00
}
2015-06-09 15:21:44 +08:00
&:active,
&.active {
2015-07-05 17:40:52 +08:00
.button-color(shade(@primary-color, 5%); @white; shade(@primary-color, 5%));
2015-06-09 15:21:44 +08:00
}
}
// ghost button style
.btn-ghost() {
.button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
2015-06-29 18:50:49 +08:00
&:hover {
2015-07-05 17:40:52 +08:00
.button-color(tint(@primary-color, 20%); @white; tint(@primary-color, 20%));
2015-06-29 18:50:49 +08:00
}
2015-06-09 15:21:44 +08:00
&:active,
&.active {
2015-07-05 17:40:52 +08:00
.button-color(shade(@primary-color, 5%); @white; shade(@primary-color, 5%));
2015-06-09 15:21:44 +08:00
}
}
// circle button: the content only contains icon
.btn-circle(@btnClassName: btn) {
.square(@btn-circle-size);
.button-size(0; @font-size-base + 2; 50%);
> .@{iconfont-css-prefix} {
top: -1px;
}
&.@{btnClassName}-lg {
.square(@btn-circle-size-lg);
.button-size(0; @btn-font-size-lg + 2; 50%);
}
&.@{btnClassName}-sm {
.square(@btn-circle-size-sm);
.button-size(0; @font-size-base; 50%);
}
}
// circle button with stroke border
.btn-circle-outline() {
position: relative;
&:not([disabled]):before {
position: absolute;
top: 0;
left: 0;
display: inline-block;
.opacity(0);
width: 100%;
height: 100%;
border-radius: 50% 50%;
content: " ";
.scale(0, 0);
2015-06-09 18:09:47 +08:00
.transition(all @duration-300 @ease-in-out);
2015-06-09 15:21:44 +08:00
z-index: 0;
background-color: @primary-color;
}
2015-06-29 18:50:49 +08:00
&:not([disabled]):hover,
&:not([disabled]):active,
&:not([disabled]).active {
2015-06-09 15:21:44 +08:00
> .@{iconfont-css-prefix} {
color: @btn-primary-color;
}
}
2015-06-29 18:50:49 +08:00
&:not([disabled]):hover:before,
&:not([disabled]):active:before,
&:not([disabled]).active:before {
2015-06-09 15:21:44 +08:00
.opacity(1);
.scale(1, 1);
2015-06-29 18:50:49 +08:00
}
2015-06-09 15:21:44 +08:00
2015-06-29 18:50:49 +08:00
&:not([disabled]):active:before,
&:not([disabled]).active:before {
2015-07-05 17:40:52 +08:00
background-color: tint(@primary-color, 20%);
2015-06-09 15:21:44 +08:00
}
}
// Horizontal button groups styl
// --------------------------------------------------
.btn-group(@btnClassName: btn) {
.button-group-base(@btnClassName);
.@{btnClassName} + .@{btnClassName},
.@{btnClassName} + &,
& + .@{btnClassName},
& + & {
margin-left: -1px;
}
.@{btnClassName}:not(:first-child):not(:last-child) {
border-radius: 0;
padding-left: 8px;
padding-right: 8px;
}
> .@{btnClassName}:first-child {
margin-left: 0;
&:not(:last-child) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
padding-right: 8px;
}
}
> .@{btnClassName}:last-child:not(:first-child) {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 8px;
}
> & {
float: left;
}
> &:not(:first-child):not(:last-child) > .@{btnClassName} {
border-radius: 0;
}
> &:first-child:not(:last-child) {
> .@{btnClassName}:last-child {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
padding-right: 8px;
}
}
> &:last-child:not(:first-child) > .@{btnClassName}:first-child {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 8px;
}
}