naive-ui/styles/Button.scss
2020-02-27 23:02:58 +08:00

458 lines
15 KiB
SCSS

@import './mixins/mixins.scss';
@mixin button-size-mixin($size) {
@include m($size + '-size') {
$height: map-get($--n-height, $size);
$font-size: map-get($--n-button-font-size, $size);
border-radius: $--n-button-border-radius;
font-size: $font-size;
@include not-m(text) {
height: $height;
line-height: $height;
padding: map-get($--n-button-padding, $size);
}
white-space: nowrap;
@include m(round) {
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) {
display: inline-block;
line-height: inherit;
}
@include e(icon) {
display: inline-block;
position: relative;
$icon-size: map-get($--n-button-icon-size, $size);
line-height: $height;
height: $height;
width: $icon-size;
max-width: $icon-size;
vertical-align: bottom;
@include b(icon) {
font-size: $icon-size;
}
@include b(base-loading) {
height: $icon-size;
width: $icon-size;
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;
font-size: $icon-size;
display: inline-flex;
align-items: center;
vertical-align: bottom;
@include b(icon-slot) {
@include icon-switch-transition($top: 50%, $original-transform: translateY(-50%));
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
display: block;
line-height: $icon-size;
height: $icon-size;
width: $icon-size;
font-size: $icon-size;
}
}
}
@include m(text) {
padding: 0;
font-weight: $--n-strong-weight;
border-radius: 0;
}
}
}
@mixin button-type-mixin ($type) {
@include m($type + '-type') {
color: map-get($--button-text-color, $type);
background-color: map-get($--button-background-color, $type);
box-shadow: map-get($--button-box-shadow, $type);
@include m(text) {
box-shadow: none !important;
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');
}
}
}
}
@include m(ghost) {
background-color: map-get($--button-ghost-typed-background-color, $type);
color: map-get($--button-ghost-typed-text-color, $type);
box-shadow: map-get($--button-ghost-typed-box-shadow, $type);
@include not-m(disabled) {
@include m(enter-pressed) {
background-color: map-get($--button-ghost-typed-background-color, $type + '-active');
color: map-get($--button-ghost-typed-text-color, $type + '-active');
box-shadow: map-get($--button-ghost-typed-box-shadow, $type + '-active');
@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) {
color: map-get($--button-ghost-typed-text-color, $type + '-focus');
background-color: map-get($--button-ghost-typed-background-color, $type + '-focus');
box-shadow: map-get($--button-ghost-typed-box-shadow, $type + '-focus');
@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 {
background-color: map-get($--button-ghost-typed-background-color, $type + '-hover');
color: map-get($--button-ghost-typed-text-color, $type + '-hover');
box-shadow: map-get($--button-ghost-typed-box-shadow, $type + '-hover');
@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 {
background-color: map-get($--button-ghost-typed-background-color, $type + '-active');
color: map-get($--button-ghost-typed-text-color, $type + '-active');
box-shadow: map-get($--button-ghost-typed-box-shadow, $type + '-active');
@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) {
@include b(icon) {
fill: map-get($--button-ghost-typed-text-color, $type) !important;
stroke: map-get($--button-ghost-typed-text-color, $type) !important;
}
@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 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) {
background-color: map-get($--button-background-color, $type + '-active');
color: map-get($--button-text-color, $type + '-active');
box-shadow: map-get($--button-box-shadow, $type + '-active');
@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 {
z-index: 1;
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) {
background-color: map-get($--button-background-color, $type + '-focus');
color: map-get($--button-text-color, $type + '-focus');
box-shadow: map-get($--button-box-shadow, $type + '-focus');
@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;
}
}
}
}
@include not-m(enter-pressed) {
&:hover {
background-color: map-get($--button-background-color, $type + '-hover');
color: map-get($--button-text-color, $type + '-hover');
box-shadow: map-get($--button-box-shadow, $type + '-hover');
@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;
}
}
}
&:active {
background-color: map-get($--button-background-color, $type + '-active');
color: map-get($--button-text-color, $type + '-active');
box-shadow: map-get($--button-box-shadow, $type + '-active');
@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;
}
}
}
}
}
}
}
@mixin button-ripple-mixin($type) {
@keyframes #{$theme}-#{$type}-button-ripple--spread {
from {
box-shadow: map-get($--button-ripple-box-shadow, $type + '-start');
}
to {
box-shadow: map-get($--button-ripple-box-shadow, $type + '-end');
}
}
@keyframes #{$theme}-#{$type}-button-ripple--opacity {
from {
opacity: .4;
}
to {
opacity: 0;
}
}
}
@include themes-mixin() {
@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');
@include b(button) {
@include once {
outline: none;
position: relative;
border: none;
font-family: inherit;
display: inline-block;
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,
box-shadow .3s $--n-ease-in-out-cubic-bezier;
cursor: pointer;
&::after {
content: "";
border-radius: inherit;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
@include e(icon) {
@include fade-in-width-expand-transition();
transition: color .3s $--n-ease-in-out-cubic-bezier;
}
@include e(content-aligner) {
display: inline-block;
line-height: inherit;
height: 100%;
font-size: inherit;
white-space: nowrap;
visibility: hidden;
width: 0;
}
@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;
}
}
@include m(right-icon) {
@include e(icon) {
margin-left: 6px;
}
}
@include m(block) {
display: block;
width: 100%;
}
@include m(loading) {
cursor: default;
opacity: 1;
}
@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');
}
@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');
}
}
@include b(button-group) {
white-space: nowrap;
display: inline-block;
position: relative;
@include not-m(vertical) {
@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;
}
/**
* Not an elegant implementation
*/
@include m(default-type) {
& + {
@include b(button) {
@include m(default-type) {
margin-left: -1px!important;
}
}
}
}
}
}
@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;
}
}
}
}