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

326 lines
8.3 KiB
Plaintext
Raw Normal View History

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