ant-design/components/button/style/mixin.less

342 lines
7.8 KiB
Plaintext
Raw Normal View History

2015-06-09 15:21:44 +08:00
// mixins for button
// ------------------------
.button-size(@height; @padding; @font-size; @border-radius) {
2015-06-09 15:21:44 +08:00
padding: @padding;
font-size: @font-size;
border-radius: @border-radius;
height: @height;
2015-06-09 15:21:44 +08:00
}
.button-disabled() {
2015-06-09 15:21:44 +08:00
&.disabled,
&[disabled] {
2015-06-09 15:21:44 +08:00
&,
&:hover,
2016-02-17 15:12:44 +08:00
&:focus,
2015-06-09 15:21:44 +08:00
&:active,
&.active {
.button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
2018-09-08 13:44:21 +08:00
text-shadow: none;
box-shadow: none;
2015-06-09 15:21:44 +08:00
}
}
}
.button-variant-primary(@color; @background) {
.button-color(@color; @background; @background);
2018-09-08 13:44:21 +08:00
text-shadow: 0 -1px 0 rgba(0, 0, 0, .12);
box-shadow: 0 2px 0 rgba(0, 0, 0, .035);
&:hover,
&:focus {
.button-color(@color; ~`colorPalette("@{background}", 5)`; ~`colorPalette("@{background}", 5)`);
}
&:active,
&.active {
.button-color(@color; ~`colorPalette("@{background}", 7)`; ~`colorPalette("@{background}", 7)`);
}
.button-disabled();
}
.button-variant-other(@color; @background; @border) {
.button-color(@color; @background; @border);
&:hover,
&:focus {
.button-color(@primary-5; @background; @primary-5);
}
&:active,
&.active {
.button-color(@primary-7; @background; @primary-7);
}
.button-disabled();
}
.button-variant-danger(@color; @background; @border) {
.button-color(@color; @background; @border);
2018-03-13 18:20:12 +08:00
&:hover {
.button-color(@btn-primary-color; ~`colorPalette("@{color}", 5)`; ~`colorPalette("@{color}", 5)`);
}
2018-03-13 18:20:12 +08:00
&:focus {
.button-color(~`colorPalette("@{color}", 5)`; #fff; ~`colorPalette("@{color}", 5)`);
}
&:active,
&.active {
.button-color(@btn-primary-color; ~`colorPalette("@{color}", 7)`; ~`colorPalette("@{color}", 7)`);
}
.button-disabled();
}
2017-03-18 16:33:55 +08:00
.button-variant-ghost(@color) {
.button-color(@color; transparent; @color);
2018-09-08 13:49:48 +08:00
text-shadow: none;
2017-03-18 16:33:55 +08:00
&:hover,
&:focus {
.button-color(~`colorPalette("@{color}", 5)`; transparent; ~`colorPalette("@{color}", 5)`);
}
&:active,
&.active {
.button-color(~`colorPalette("@{color}", 7)`; transparent; ~`colorPalette("@{color}", 7)`);
}
.button-disabled();
}
2015-06-09 15:21:44 +08:00
.button-color(@color; @background; @border) {
color: @color;
background-color: @background;
border-color: @border;
2016-05-28 15:47:02 +08:00
// a inside Button which only work in Chrome
// http://stackoverflow.com/a/17253457
> a:only-child {
color: currentColor;
&:after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: transparent;
}
}
2015-06-09 15:21:44 +08:00
}
.button-group-base(@btnClassName) {
position: relative;
display: inline-block;
> .@{btnClassName},
> span > .@{btnClassName} {
2015-06-09 15:21:44 +08:00
position: relative;
2015-06-09 15:21:44 +08:00
&:hover,
&:focus,
&:active,
&.active {
z-index: 2;
}
&:disabled {
z-index: 0;
}
2015-06-09 15:21:44 +08:00
}
// size
&-lg > .@{btnClassName},
&-lg > span > .@{btnClassName} {
.button-size(@btn-height-lg; @btn-padding-lg; @btn-font-size-lg; 0);
line-height: @btn-height-lg - 2px;
2015-06-09 15:21:44 +08:00
}
&-sm > .@{btnClassName},
&-sm > span > .@{btnClassName} {
.button-size(@btn-height-sm; @btn-padding-sm; @font-size-base; 0);
line-height: @btn-height-sm - 2px;
2015-06-09 15:21:44 +08:00
> .@{iconfont-css-prefix} {
font-size: @font-size-base;
}
}
}
// Base styles of buttons
// --------------------------------------------------
.btn() {
display: inline-block;
font-weight: @btn-font-weight;
text-align: center;
touch-action: manipulation;
cursor: pointer;
background-image: none;
border: @border-width-base @border-style-base transparent;
2015-06-09 15:21:44 +08:00
white-space: nowrap;
.button-size(@btn-height-base; @btn-padding-base; @font-size-base; @btn-border-radius-base);
2016-04-19 15:15:54 +08:00
user-select: none;
transition: all .3s @ease-in-out;
position: relative;
2018-09-08 13:44:21 +08:00
box-shadow: 0 2px 0 rgba(0, 0, 0, .015);
2015-06-09 15:21:44 +08:00
> .@{iconfont-css-prefix} {
2015-07-09 19:50:47 +08:00
line-height: 1;
vertical-align: -0.19em;
2015-06-09 15:21:44 +08:00
}
&,
&:active,
&:focus {
outline: 0;
}
&:not([disabled]):hover {
text-decoration: none;
}
&:not([disabled]):active {
outline: 0;
2016-04-19 15:15:54 +08:00
transition: none;
2018-09-08 13:44:21 +08:00
box-shadow: none;
2015-06-09 15:21:44 +08:00
}
&.disabled,
2015-11-26 19:32:55 +08:00
&[disabled] {
cursor: not-allowed;
> * {
pointer-events: none;
}
2015-06-09 15:21:44 +08:00
}
&-lg {
.button-size(@btn-height-lg; @btn-padding-lg; @btn-font-size-lg; @btn-border-radius-base);
2015-06-09 15:21:44 +08:00
}
&-sm {
.button-size(@btn-height-sm; @btn-padding-sm; @btn-font-size-sm; @btn-border-radius-sm);
2015-06-09 15:21:44 +08:00
}
}
// primary button style
.btn-primary() {
.button-variant-primary(@btn-primary-color; @btn-primary-bg);
2015-06-09 15:21:44 +08:00
}
// default button style
.btn-default() {
.button-variant-other(@btn-default-color; @btn-default-bg; @btn-default-border);
2016-02-17 15:12:44 +08:00
&:hover,
&:focus,
2015-06-09 15:21:44 +08:00
&:active,
&.active {
background: @btn-default-bg;
text-decoration: none;
2015-06-09 15:21:44 +08:00
}
}
// ghost button style
.btn-ghost() {
.button-variant-other(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
2015-06-09 15:21:44 +08:00
}
// dashed button style
2015-11-30 18:26:44 +08:00
.btn-dashed() {
.button-variant-other(@btn-default-color, @btn-default-bg, @btn-default-border);
2015-11-30 18:26:44 +08:00
border-style: dashed;
}
// danger button style
.btn-danger() {
.button-variant-danger(@btn-danger-color, @btn-danger-bg, @btn-danger-border);
}
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(@btn-circle-size; 0; @font-size-base + 2px; 50%);
2015-06-09 15:21:44 +08:00
&.@{btnClassName}-lg {
.square(@btn-circle-size-lg);
.button-size(@btn-circle-size-lg; 0; @btn-font-size-lg + 2px; 50%);
2015-06-09 15:21:44 +08:00
}
&.@{btnClassName}-sm {
.square(@btn-circle-size-sm);
.button-size(@btn-circle-size-sm; 0; @font-size-base; 50%);
2015-06-09 15:21:44 +08:00
}
}
// Horizontal button groups styl
// --------------------------------------------------
.btn-group(@btnClassName: btn) {
.button-group-base(@btnClassName);
.@{btnClassName} + .@{btnClassName},
.@{btnClassName} + &,
span + .@{btnClassName},
.@{btnClassName} + span,
2018-06-06 11:33:13 +08:00
> span + span,
2015-06-09 15:21:44 +08:00
& + .@{btnClassName},
& + & {
margin-left: -1px;
}
.@{btnClassName}-primary + .@{btnClassName}:not(.@{btnClassName}-primary):not([disabled]) {
2018-05-17 21:36:05 +08:00
border-left-color: transparent;
}
.@{btnClassName} {
2015-06-09 15:21:44 +08:00
border-radius: 0;
}
> .@{btnClassName}:first-child,
> span:first-child > .@{btnClassName} {
2015-06-09 15:21:44 +08:00
margin-left: 0;
}
> .@{btnClassName}:only-child {
border-radius: @btn-border-radius-base;
}
> span:only-child > .@{btnClassName} {
border-radius: @btn-border-radius-base;
}
2015-06-09 15:21:44 +08:00
> .@{btnClassName}:first-child:not(:last-child),
> span:first-child:not(:last-child) > .@{btnClassName} {
border-bottom-left-radius: @btn-border-radius-base;
border-top-left-radius: @btn-border-radius-base;
}
> .@{btnClassName}:last-child:not(:first-child),
> span:last-child:not(:first-child) > .@{btnClassName} {
border-bottom-right-radius: @btn-border-radius-base;
border-top-right-radius: @btn-border-radius-base;
}
&-sm {
> .@{btnClassName}:only-child {
border-radius: @btn-border-radius-sm;
}
> span:only-child > .@{btnClassName} {
border-radius: @btn-border-radius-sm;
}
> .@{btnClassName}:first-child:not(:last-child),
> span:first-child:not(:last-child) > .@{btnClassName} {
border-bottom-left-radius: @btn-border-radius-sm;
border-top-left-radius: @btn-border-radius-sm;
}
> .@{btnClassName}:last-child:not(:first-child),
> span:last-child:not(:first-child) > .@{btnClassName} {
border-bottom-right-radius: @btn-border-radius-sm;
border-top-right-radius: @btn-border-radius-sm;
}
2015-06-09 15:21:44 +08:00
}
2016-03-15 20:13:02 +08:00
& > & {
2015-06-09 15:21:44 +08:00
float: left;
}
2016-03-15 20:13:02 +08:00
& > &:not(:first-child):not(:last-child) > .@{btnClassName} {
2015-06-09 15:21:44 +08:00
border-radius: 0;
}
2016-03-15 20:13:02 +08:00
& > &:first-child:not(:last-child) {
2015-06-09 15:21:44 +08:00
> .@{btnClassName}:last-child {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
2016-02-22 19:48:51 +08:00
padding-right: 8px;
2015-06-09 15:21:44 +08:00
}
}
2016-03-15 20:13:02 +08:00
& > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
2015-06-09 15:21:44 +08:00
border-bottom-left-radius: 0;
border-top-left-radius: 0;
2016-02-22 19:48:51 +08:00
padding-left: 8px;
2015-06-09 15:21:44 +08:00
}
}