naive-ui/styles/Button.scss

578 lines
18 KiB
SCSS
Raw Normal View History

2019-06-18 14:53:24 +08:00
@import './mixins/mixins.scss';
2020-02-11 14:44:29 +08:00
@mixin button-size-mixin($size) {
2020-02-23 11:00:31 +08:00
@include m($size + '-size') {
2020-02-22 20:25:10 +08:00
$height: map-get($--n-height, $size);
2020-02-22 14:11:34 +08:00
$font-size: map-get($--n-button-font-size, $size);
$icon-size: map-get($--n-button-icon-size, $size);
2020-02-21 14:59:17 +08:00
border-radius: $--n-button-border-radius;
font-size: $font-size;
2019-12-08 17:21:44 +08:00
@include not-m(text) {
height: $height;
line-height: $height - 2px;
2020-02-22 14:11:34 +08:00
padding: map-get($--n-button-padding, $size);
2019-12-08 17:21:44 +08:00
}
2019-09-17 23:42:03 +08:00
white-space: nowrap;
@include m(round) {
2020-02-22 14:11:34 +08:00
padding: map-get($--n-button-round-padding, $size);
border-radius: $height / 2;
}
@include m(circle) {
border-radius: $height / 2;
width: $height;
padding: 0!important;
}
@include e(content) {
2019-09-17 23:42:03 +08:00
display: inline-block;
2019-12-08 17:21:44 +08:00
line-height: inherit;
}
@include e(icon) {
2019-09-17 23:42:03 +08:00
display: inline-block;
position: relative;
line-height: $height - 2px;
height: $height - 2px;
width: $icon-size;
max-width: $icon-size;
2019-09-17 23:42:03 +08:00
vertical-align: bottom;
2019-10-24 18:04:31 +08:00
@include b(icon) {
font-size: $icon-size;
2019-09-17 23:42:03 +08:00
}
2020-01-31 21:58:21 +08:00
@include b(base-loading) {
height: $icon-size - 2px;
width: $icon-size - 2px;
2019-09-17 23:42:03 +08:00
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
display: block;
@include icon-switch-transition($top: 50%, $original-transform: translateY(-50%));
}
@include m(slot) {
width: $icon-size;
2019-09-17 23:42:03 +08:00
font-size: $icon-size;
display: inline-flex;
align-items: center;
vertical-align: bottom;
2019-10-24 18:04:31 +08:00
@include b(icon-slot) {
@include icon-switch-transition($top: 50%, $original-transform: translateY(-50%));
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
2019-09-17 23:42:03 +08:00
display: block;
line-height: $icon-size;
height: $icon-size;
width: $icon-size;
font-size: $icon-size;
}
}
}
2019-12-08 17:21:44 +08:00
@include m(text) {
padding: 0;
border-radius: 0;
@include e(icon) {
height: $icon-size;
line-height: $icon-size;
}
2019-12-08 17:21:44 +08:00
}
}
}
@mixin button-type-mixin ($type) {
2020-02-23 11:00:31 +08:00
@include m($type + '-type') {
color: map-get($--button-text-color, $type);
2020-02-22 14:11:34 +08:00
background-color: map-get($--button-background-color, $type);
border: 1px solid map-get($--button-border-color, $type);
@include m(ghost, text) {
2020-02-23 11:00:31 +08:00
background-color: map-get($--button-ghost-typed-background-color, $type);
color: map-get($--button-ghost-typed-text-color, $type);
border: 1px solid map-get($--button-ghost-typed-border-color, $type);
@include not-m(disabled) {
@include m(enter-pressed) {
2020-02-23 11:00:31 +08:00
background-color: map-get($--button-ghost-typed-background-color, $type + '-active');
color: map-get($--button-ghost-typed-text-color, $type + '-active');
@include e(border-mask) {
box-shadow: map-get($--button-ghost-typed-border-mask-box-shadow, $type + '-active');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
}
@include b(base-loading) {
fill: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
}
}
}
&:not(:active):focus {
@include not-m(enter-pressed) {
2020-02-23 11:00:31 +08:00
color: map-get($--button-ghost-typed-text-color, $type + '-focus');
background-color: map-get($--button-ghost-typed-background-color, $type + '-focus');
@include e(border-mask) {
box-shadow: map-get($--button-ghost-typed-border-mask-box-shadow, $type + '-focus');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-ghost-typed-text-color, $type + '-focus') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-focus') !important;
}
@include b(base-loading) {
fill: map-get($--button-ghost-typed-text-color, $type + '-focus') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-focus') !important;
}
}
}
}
@include not-m(enter-pressed) {
&:hover {
2020-02-23 11:00:31 +08:00
background-color: map-get($--button-ghost-typed-background-color, $type + '-hover');
color: map-get($--button-ghost-typed-text-color, $type + '-hover');
@include e(border-mask) {
box-shadow: map-get($--button-ghost-typed-border-mask-box-shadow, $type + '-hover');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-ghost-typed-text-color, $type + '-hover') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-hover') !important;
}
@include b(base-loading) {
fill: map-get($--button-ghost-typed-text-color, $type + '-hover') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-hover') !important;
}
}
}
&:active {
2020-02-23 11:00:31 +08:00
background-color: map-get($--button-ghost-typed-background-color, $type + '-active');
color: map-get($--button-ghost-typed-text-color, $type + '-active');
@include e(border-mask) {
box-shadow: map-get($--button-ghost-typed-border-mask-box-shadow, $type + '-active');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
}
@include b(base-loading) {
fill: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
stroke: map-get($--button-ghost-typed-text-color, $type + '-active') !important;
}
}
}
}
}
@include e(icon) {
2019-11-29 15:34:37 +08:00
@include b(icon) {
2020-02-23 11:00:31 +08:00
fill: map-get($--button-ghost-typed-text-color, $type) !important;
stroke: map-get($--button-ghost-typed-text-color, $type) !important;
2019-10-24 18:04:31 +08:00
}
2020-02-23 11:00:31 +08:00
@include b(base-loading) {
fill: map-get($--button-ghost-typed-text-color, $type) !important;
stroke: map-get($--button-ghost-typed-text-color, $type) !important;
}
}
}
@include m(text) {
@include e(border-mask) {
box-shadow: none !important;
}
border: none;
background-color: transparent;
color: map-get($--button-text-typed-text-color, $type);
@include not-m(disabled) {
@include m(rippling) {
&::after {
display: none;
}
}
@include m(enter-pressed) {
background-color: transparent;
color: map-get($--button-text-typed-text-color, $type + '-active');
}
&:not(:active):focus {
@include not-m(enter-pressed) {
background-color: transparent;
color: map-get($--button-text-typed-text-color, $type + '-focus');
}
}
@include not-m(enter-pressed) {
&:hover {
background-color: transparent;
color: map-get($--button-text-typed-text-color, $type + '-hover');
}
&:active {
background-color: transparent;
color: map-get($--button-text-typed-text-color, $type + '-active');
}
}
}
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-text-color, $type) !important;
stroke: map-get($--button-text-color, $type) !important;
}
@include b(base-loading) {
fill: map-get($--button-text-color, $type) !important;
stroke: map-get($--button-text-color, $type) !important;
}
}
@include not-m(disabled) {
@include m(enter-pressed) {
2020-02-22 14:11:34 +08:00
background-color: map-get($--button-background-color, $type + '-active');
2020-02-23 11:00:31 +08:00
color: map-get($--button-text-color, $type + '-active');
@include e(border-mask) {
box-shadow: map-get($--button-border-mask-box-shadow, $type + '-active');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-text-color, $type + '-active') !important;
stroke: map-get($--button-text-color, $type + '-active') !important;
}
@include b(base-loading) {
fill: map-get($--button-text-color, $type + '-active') !important;
stroke: map-get($--button-text-color, $type + '-active') !important;
}
}
}
@include m(rippling) {
&::after {
2019-10-10 00:07:24 +08:00
z-index: 1;
2019-09-17 19:28:07 +08:00
animation-name: #{$theme}-#{$type}-button-ripple--spread, #{$theme}-#{$type}-button-ripple--opacity;
animation-duration: .6s;
animation-timing-function: cubic-bezier(0, .4, .5, .9), cubic-bezier(.5, .2, .8, .5);
}
}
&:not(:active):focus {
@include not-m(enter-pressed) {
2020-02-23 11:00:31 +08:00
background-color: map-get($--button-background-color, $type + '-focus');
color: map-get($--button-text-color, $type + '-focus');
@include e(border-mask) {
box-shadow: map-get($--button-border-mask-box-shadow, $type + '-focus');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-text-color, $type + '-focus') !important;
stroke: map-get($--button-text-color, $type + '-focus') !important;
}
@include b(base-loading) {
fill: map-get($--button-text-color, $type + '-focus') !important;
stroke: map-get($--button-text-color, $type + '-focus') !important;
}
}
}
}
2019-09-17 23:42:03 +08:00
@include not-m(enter-pressed) {
&:hover {
2020-02-22 14:11:34 +08:00
background-color: map-get($--button-background-color, $type + '-hover');
2020-02-23 11:00:31 +08:00
color: map-get($--button-text-color, $type + '-hover');
@include e(border-mask) {
box-shadow: map-get($--button-border-mask-box-shadow, $type + '-hover');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-text-color, $type + '-hover') !important;
stroke: map-get($--button-text-color, $type + '-hover') !important;
}
@include b(base-loading) {
fill: map-get($--button-text-color, $type + '-hover') !important;
stroke: map-get($--button-text-color, $type + '-hover') !important;
}
}
2019-09-17 23:42:03 +08:00
}
&:active {
2020-02-22 14:11:34 +08:00
background-color: map-get($--button-background-color, $type + '-active');
2020-02-23 11:00:31 +08:00
color: map-get($--button-text-color, $type + '-active');
@include e(border-mask) {
box-shadow: map-get($--button-border-mask-box-shadow, $type + '-active');
}
2020-02-23 11:00:31 +08:00
@include e(icon) {
@include b(icon) {
fill: map-get($--button-text-color, $type + '-active') !important;
stroke: map-get($--button-text-color, $type + '-active') !important;
}
@include b(base-loading) {
fill: map-get($--button-text-color, $type + '-active') !important;
stroke: map-get($--button-text-color, $type + '-active') !important;
}
}
}
}
}
}
}
2020-02-23 11:00:31 +08:00
@mixin button-ripple-mixin($type) {
2019-09-17 19:28:07 +08:00
@keyframes #{$theme}-#{$type}-button-ripple--spread {
from {
2020-02-23 11:00:31 +08:00
box-shadow: map-get($--button-ripple-box-shadow, $type + '-start');
}
to {
2020-02-23 11:00:31 +08:00
box-shadow: map-get($--button-ripple-box-shadow, $type + '-end');
}
}
2019-09-17 19:28:07 +08:00
@keyframes #{$theme}-#{$type}-button-ripple--opacity {
from {
opacity: .4;
}
to {
opacity: 0;
}
}
}
2019-09-17 19:28:07 +08:00
@include themes-mixin() {
2020-02-23 11:00:31 +08:00
@include button-ripple-mixin('default');
@include button-ripple-mixin('primary');
@include button-ripple-mixin('error');
@include button-ripple-mixin('success');
@include button-ripple-mixin('warning');
@include button-ripple-mixin('info');
2019-09-17 19:28:07 +08:00
@include b(button) {
@include once {
box-sizing: border-box;
2019-09-17 19:28:07 +08:00
outline: none;
position: relative;
z-index: auto;
2019-09-17 19:28:07 +08:00
border: none;
2020-02-22 14:11:34 +08:00
font-family: inherit;
2019-09-17 23:42:03 +08:00
display: inline-block;
2019-09-17 19:28:07 +08:00
align-items: center;
justify-content: center;
user-select: none;
text-align: center;
transition:
background-color .3s $--n-ease-in-out-cubic-bezier,
opacity .3s $--n-ease-in-out-cubic-bezier,
border-color .3s $--n-ease-in-out-cubic-bezier;
2019-09-17 19:28:07 +08:00
cursor: pointer;
&::after {
content: "";
border-radius: inherit;
position: absolute;
left: -1px;
top: -1px;
right: -1px;
bottom: -1px;
}
@include e(border-mask) {
position: absolute;
left: -1px;
top: -1px;
right: -1px;
bottom: -1px;
border-radius: inherit;
box-shadow: inset 0 0 0 1px transparent;
transition: box-shadow .3s $--n-ease-in-out-cubic-bezier;
2019-09-17 19:28:07 +08:00
}
@include e(icon) {
@include fade-in-width-expand-transition();
transition: color .3s $--n-ease-in-out-cubic-bezier;
}
2019-09-17 19:28:07 +08:00
@include e(content) {
white-space: nowrap;
transition: color .3s $--n-ease-in-out-cubic-bezier;
}
@include m(left-icon) {
@include e(icon) {
margin-right: 6px;
}
2019-09-17 19:28:07 +08:00
}
@include m(right-icon) {
@include e(icon) {
margin-left: 6px;
}
}
2019-09-17 19:28:07 +08:00
@include m(block) {
display: block;
width: 100%;
}
@include m(loading) {
cursor: default;
opacity: 1;
2019-09-17 19:28:07 +08:00
}
@include m(disabled) {
cursor: not-allowed;
}
&::-moz-focus-inner {
border: 0;
}
@include button-size-mixin('tiny');
@include button-size-mixin('small');
@include button-size-mixin('medium');
@include button-size-mixin('large');
2019-07-04 10:41:59 +08:00
}
2020-02-20 15:26:12 +08:00
@include m(disabled) {
opacity: $--button-disabled-opacity;
}
@include button-type-mixin('default');
@include button-type-mixin('primary');
@include button-type-mixin('info');
@include button-type-mixin('success');
@include button-type-mixin('warning');
@include button-type-mixin('error');
2019-06-18 14:53:24 +08:00
}
2019-09-18 19:19:22 +08:00
}
@include b(button-group) {
white-space: nowrap;
2019-10-09 17:38:08 +08:00
display: inline-block;
2019-10-10 00:07:24 +08:00
position: relative;
@include not-m(vertical) {
2019-11-13 00:02:42 +08:00
@include m(block) {
display: flex;
flex-wrap: nowrap;
@include b(button) {
flex-grow: 1;
}
}
@include b(button) {
&:first-child:not(:last-child) {
margin-right: 0!important;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
&:last-child:not(:first-child) {
margin-left: 0!important;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
&:not(:first-child):not(:last-child) {
margin-left: 0!important;
margin-right: 0!important;
border-radius: 0!important;
}
2019-10-09 17:38:08 +08:00
/**
* Not an perfect implementation,
* since their border is not really "shared"
2019-10-09 17:38:08 +08:00
*/
2020-02-11 17:19:00 +08:00
@include m(default-type) {
& + {
@include b(button) {
@include m(default-type) {
border-left-width: 0px;
}
}
}
}
@include m(ghost) {
@include m(primary-type) {
& + {
@include b(button) {
@include m(primary-type) {
border-left-width: 0px;
}
}
}
}
@include m(success-type) {
& + {
@include b(button) {
@include m(success-type) {
border-left-width: 0px;
}
}
}
}
@include m(error-type) {
& + {
@include b(button) {
@include m(error-type) {
border-left-width: 0px;
}
}
}
}
@include m(info-type) {
& + {
@include b(button) {
@include m(info-type) {
border-left-width: 0px;
}
2020-02-11 17:19:00 +08:00
}
}
}
2019-10-09 17:38:08 +08:00
}
2019-09-18 19:19:22 +08:00
}
}
@include m(vertical) {
display: inline-flex;
flex-direction: column;
@include b(button) {
&:first-child {
margin-bottom: 0!important;
margin-left: 0!important;
margin-right: 0!important;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
&:last-child {
margin-top: 0!important;
margin-left: 0!important;
margin-right: 0!important;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
&:not(:first-child):not(:last-child) {
margin: 0!important;
border-radius: 0!important;
}
@include m(default-type) {
& + {
@include b(button) {
@include m(default-type) {
border-top-width: 0px;
}
}
}
}
@include m(ghost) {
@include m(info-type) {
& + {
@include b(button) {
@include m(info-type) {
border-top-width: 0px;
}
}
}
}
@include m(success-type) {
& + {
@include b(button) {
@include m(success-type) {
border-top-width: 0px;
}
}
}
}
@include m(warning-type) {
& + {
@include b(button) {
@include m(warning-type) {
border-top-width: 0px;
}
}
}
}
@include m(error-type) {
& + {
@include b(button) {
@include m(error-type) {
border-top-width: 0px;
}
}
}
}
@include m(primary-type) {
& + {
@include b(button) {
@include m(primary-type) {
border-top-width: 0px;
}
}
}
}
}
2019-09-18 19:19:22 +08:00
}
}
2019-06-18 14:53:24 +08:00
}