wetrade-design
Version:
一款多语言支持Vue3的UI框架
822 lines (755 loc) • 23.2 kB
text/less
// mixins for button
// ------------------------
.button-size(@height; @padding-horizontal; @font-size; @border-radius) {
// @padding-vertical: max(
// (round(((@height - @font-size * @line-height-base) / 2) * 10) / 10) - @border-width-base,
// 0
// );
@padding-vertical: ((@height - @line-height-base) / 2) - 1px;
height: @height;
padding: @padding-vertical @padding-horizontal;
font-size: @font-size;
border-radius: @border-radius;
}
.button-color(@color; @background; @border) {
color: @color;
border-color: @border; // a inside Button which only work in Chrome
& when not(@background = null) {
background: @background;
}
// http://stackoverflow.com/a/17253457
> a:only-child {
color: currentcolor;
&::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent;
content: '';
}
}
}
.button-disabled(@color: @btn-disable-color; @background: @btn-disable-bg; @border: @btn-disable-border) {
&[disabled] {
&,
&:hover,
// &:focus,
&:active {
.button-color(@color; @background; @border);
text-shadow: none;
box-shadow: none;
}
}
}
.button-variant-primary(@color; @background; @backgroundHover: yellow; @backgroundActive: yellow;) {
.button-color(@color; @background; @background);
// text-shadow: @btn-text-shadow;
// box-shadow: @btn-primary-shadow;
&:hover {
& when (@theme = dark) {
.button-color(@color; @backgroundHover; @backgroundHover);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(@color; @backgroundHover; @backgroundHover);
}
& when (@theme = variable) {
.button-color(@color; @backgroundHover; @backgroundHover);
}
}
// &:focus {
// & when (@theme = variable) {
// .button-color(@color; @background; @background);
// }
// }
&:active {
& when (@theme = dark) {
.button-color(@color; @backgroundActive; @backgroundActive);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(@color; @backgroundActive; @backgroundActive);
}
& when (@theme = variable) {
.button-color(@color; @backgroundActive; @backgroundActive);
}
}
.button-disabled();
}
.button-variant-other(@color; @background; @border) {
.button-color(@color; @background; @border);
// &:focus,
&:hover {
& when (@theme = dark) {
.button-color(@primary-5; @background; @primary-5);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{btn-primary-bg}', 5) `; @background;
~`colorPalette('@{btn-primary-bg}', 5) `
);
}
& when (@theme = variable) {
.button-color(@brand-hover; @background; @brand-hover);
}
}
&:active {
& when (@theme = dark) {
.button-color(@primary-7; @background; @primary-7);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{btn-primary-bg}', 7) `; @background;
~`colorPalette('@{btn-primary-bg}', 7) `
);
}
& when (@theme = variable) {
.button-color(@brand-active; @background; @brand-active);
}
}
.button-disabled();
}
.button-variant-ghost(@color; @border; @borderHover: yellow; @borderActive: yellow) {
.button-color(@color; null; @border);
text-shadow: none;
// &:focus,
&:hover {
& when (@border = transparent) {
& when (@theme = dark) {
.button-color(~`colorPalette('@{color}', 7) `; null; transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(~`colorPalette('@{color}', 5) `; null; transparent);
}
& when (@theme = variable) {
.button-color(@borderActive; transparent; transparent);
}
}
& when not (@border = transparent) {
& when (@theme = dark) {
.button-color(
~`colorPalette('@{color}', 7) `; null; ~`colorPalette('@{color}', 7) `
);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{color}', 5) `; null; ~`colorPalette('@{color}', 5) `
);
}
& when (@theme = variable) {
.button-color(@borderHover; transparent; @borderHover);
}
}
}
&:active {
& when (@border = transparent) {
& when (@theme = dark) {
.button-color(~`colorPalette('@{color}', 5) `; null; transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(~`colorPalette('@{color}', 7) `; null; transparent);
}
& when (@theme = variable) {
.button-color(@borderActive; transparent; transparent);
}
}
& when not (@border = transparent) {
& when (@theme = dark) {
.button-color(
~`colorPalette('@{color}', 5) `; null; ~`colorPalette('@{color}', 5) `
);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{color}', 7) `; null; ~`colorPalette('@{color}', 7) `
);
}
& when (@theme = variable) {
.button-color(@borderActive; transparent; @borderActive);
}
}
}
.button-disabled();
}
.button-group-base(@btnClassName) {
position: relative;
display: inline-flex;
> .@{btnClassName},
> span > .@{btnClassName} {
position: relative;
&:hover,
// &:focus,
&:active {
z-index: 2;
}
&[disabled] {
z-index: 0;
}
}
.@{btnClassName}-icon-only {
font-size: @font-size-base;
}
// size
&-lg > .@{btnClassName},
&-lg > span > .@{btnClassName} {
.button-size(@btn-height-lg; @btn-padding-horizontal-lg; @btn-font-size-lg; 0);
}
&-lg .@{btnClassName}.@{btnClassName}-icon-only {
.square(@btn-height-lg);
padding-right: 0;
padding-left: 0;
}
&-bg > .@{btnClassName},
&-bg > span > .@{btnClassName} {
.button-size(@btn-height-bg; @btn-padding-horizontal-bg; @btn-font-size-bg; @border-radius-sm);
}
&-bg .@{btnClassName}.@{btnClassName}-icon-only {
.square(@btn-height-bg);
padding-right: 0;
padding-left: 0;
}
&-sm > .@{btnClassName},
&-sm > span > .@{btnClassName} {
.button-size(@btn-height-sm; @btn-padding-horizontal-sm; @font-size-sm; 0);
> .@{iconfont-css-prefix} {
font-size: @font-size-sm;
}
}
&-sm .@{btnClassName}.@{btnClassName}-icon-only {
.square(@btn-height-sm);
padding-right: 0;
padding-left: 0;
}
&-xs > .@{btnClassName},
&-xs > span > .@{btnClassName} {
.button-size(@btn-height-xs; @btn-padding-horizontal-xs; @font-size-sm; 0);
> .@{iconfont-css-prefix} {
font-size: @font-size-sm;
}
}
&-xs .@{btnClassName}.@{btnClassName}-icon-only {
.square(@btn-height-xs);
padding-right: 0;
padding-left: 0;
}
}
// Base styles of buttons
// --------------------------------------------------
.btn() {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: @btn-font-weight;
white-space: nowrap;
text-align: center;
background-image: none;
border: @btn-border-width @btn-border-style transparent;
// box-shadow: @btn-shadow;
cursor: pointer;
transition: all 0.3s @ease-in-out;
user-select: none;
touch-action: manipulation;
.button-size(
@btn-height-base; @btn-padding-horizontal-base; @btn-font-size-sm; @btn-border-radius-sm
);
> .@{iconfont-css-prefix} {
line-height: 1;
// vertical-align: middle;
}
&,
&:active,
&:focus {
outline: 0;
}
&:not([disabled]):hover {
text-decoration: none;
}
&:not([disabled]):active {
outline: 0;
box-shadow: none;
}
&[disabled] {
cursor: not-allowed;
> * {
pointer-events: none;
}
}
// 设置button尺寸
&-lg {
.button-size(
@btn-height-lg; @btn-padding-horizontal-lg; @btn-font-size-bg; @btn-border-radius-base
);
}
&-bg {
.button-size(
@btn-height-bg; @btn-padding-horizontal-bg; @btn-font-size-bg; @btn-border-radius-base
);
}
&-sm {
.button-size(
@btn-height-sm; @btn-padding-horizontal-sm; @btn-font-size-sm; @btn-border-radius-sm
);
}
&-xs {
.button-size(
@btn-height-xs; @btn-padding-horizontal-xs; @btn-font-size-xs; @btn-border-radius-sm
);
&.@{btn-prefix-cls} {
// To ensure that a space will be placed between character and `Icon`.
> .@{iconfont-css-prefix} + span,
> span + .@{iconfont-css-prefix} {
margin-left: @margin-xss - 2px;
}
> span[role='img'] {
margin-right: 2px;
}
}
}
}
// primary button style
.btn-primary() {
.button-variant-primary(@btn-primary-color; @btn-primary-bg; @brand-hover; @brand-active);
.button-disabled(@disable-primary-color; @disable-primary-bg; @disable-primary-bg);
}
// default button style
.btn-default() {
.button-variant-other(@btn-default-color; @btn-default-bg; @btn-default-border; );
.button-disabled(@disabled-color; @btn-disable-bg; @disabled-color-border);
&:hover,
// &:focus,
&:active {
text-decoration: none;
background: @btn-default-bg;
}
}
// ghost button style
.btn-ghost() {
.button-variant-other(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
}
// secondary button style
.btn-secondary() {
.button-variant-primary(@btn-secondary-color, @btn-secondary-bg, @brand-lighter, @brand-disable);
.button-disabled(@disable-secondary-color; @disable-secondary-bg; transparent);
border: none;
}
// button icon have bg -- solid
.btn-icon-solid() {
.button-color(@btn-icon-solid-color, @btn-icon-solid-bg, @btn-icon-bg);
.button-disabled(@btn-icon-solid-color-disabled; @btn-icon-solid-bg-disabled; @btn-icon-bg);
&:hover {
.button-color(@btn-icon-solid-color-hover, @btn-icon-solid-bg-hover, @btn-icon-bg);
}
&:active {
.button-color(@btn-icon-solid-color-active, @btn-icon-solid-bg-active, @btn-icon-bg);
}
}
// button icon no bg have border -- primary
.btn-icon-primary() {
.button-color(@btn-icon-primary, @btn-icon-bg, @btn-icon-primary);
.button-disabled(@btn-icon-primary-disabled; @btn-icon-bg; @btn-icon-primary-disabled);
&:hover {
.button-color(@btn-icon-primary-hover, @btn-icon-bg, @btn-icon-primary-hover);
}
&:active {
.button-color(@btn-icon-primary-active, @btn-icon-bg, @btn-icon-primary-active);
}
}
// button icon no bg have border -- neutral
.btn-icon-neutral() {
.button-color(@btn-icon-neutral, @btn-icon-bg, @btn-icon-neutral);
.button-disabled(@btn-icon-neutral-disabled; @btn-icon-bg; @btn-icon-neutral-disabled);
&:hover {
.button-color(@btn-icon-neutral-hover, @btn-icon-bg, @btn-icon-neutral-hover);
}
&:active {
.button-color(@btn-icon-neutral-active, @btn-icon-bg, @btn-icon-neutral-active);
}
}
// button icon no bg no border -- hot
.btn-icon-hot() {
.button-color(@btn-icon-hot-color, @btn-icon-bg, @btn-icon-bg);
.button-disabled(@btn-icon-hot-color-disabled; @btn-icon-bg; @btn-icon-bg);
&:hover {
.button-color(@btn-icon-hot-color-hover, @btn-icon-hot-bg-hover, @btn-icon-bg);
}
// &:focus {
// .button-color(@btn-icon-hot-color, @btn-icon-bg, @btn-icon-bg);
// }
&:active {
.button-color(@btn-icon-hot-color-active, @btn-icon-hot-bg-active, @btn-icon-bg);
}
}
// button icon no bg no border -- default
.btn-icon-default() {
.button-color(@btn-icon-default-color, @btn-icon-bg, @btn-icon-bg);
.button-disabled(@btn-icon-default-color-disabled; @btn-icon-bg; @btn-icon-bg);
&:hover {
.button-color(@btn-icon-default-color-hover, @btn-icon-default-bg-hover, @btn-icon-bg);
}
&:active {
.button-color(@btn-icon-default-color-active, @btn-icon-default-bg-active, @btn-icon-bg);
}
}
// button icon no bg no border -- gray
.btn-icon-gray() {
.button-color(@btn-icon-gray-color, @btn-icon-gray-bg, @btn-icon-gray-bg);
.button-disabled(@btn-icon-gray-color-disabled; @btn-icon-gray-bg; @btn-icon-gray-bg);
&:hover {
.button-color(@btn-icon-gray-color-hover, @btn-icon-gray-bg-hover, @btn-icon-gray-bg);
}
&:active {
.button-color(@btn-icon-gray-color-active, @btn-icon-gray-bg-active, @btn-icon-gray-bg);
}
}
// danger button style
.btn-danger() {
.button-variant-primary(@btn-danger-color, @btn-danger-bg, @fluctuation-rise-hover, @fluctuation-rise-active);
.button-disabled(@btn-danger-color, @btn-danger-disable-bg, @btn-danger-disable-bg);
}
// warning button style
.btn-warning() {
.button-variant-primary(@btn-warning-color, @btn-warning-bg, @btn-warning-hover-bg, @btn-warning-active-bg);
.button-disabled(@btn-warning-color, @btn-warning-disable-bg, @btn-warning-disable-bg);
}
// danger default button style
.btn-danger-default() {
.button-color(@fluctuation-rise-rise, @btn-default-bg, @fluctuation-rise-rise);
// &:focus,
&:hover {
& when (@theme = dark) {
.button-color(
~`colorPalette('@{fluctuation-rise-rise}', 7) `; @btn-default-bg; ~`colorPalette('@{fluctuation-rise-rise}', 7)
`
);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{fluctuation-rise-rise}', 5) `; @btn-default-bg; ~`colorPalette('@{fluctuation-rise-rise}', 5)
`
);
}
& when (@theme = variable) {
.button-color(@fluctuation-rise-hover, @btn-default-bg, @fluctuation-rise-hover);
}
}
&:active {
& when (@theme = dark) {
.button-color(
~`colorPalette('@{fluctuation-rise-rise}', 5) `; @btn-default-bg; ~`colorPalette('@{fluctuation-rise-rise}', 5)
`
);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(
~`colorPalette('@{fluctuation-rise-rise}', 7) `; @btn-default-bg; ~`colorPalette('@{fluctuation-rise-rise}', 7)
`
);
}
& when (@theme = variable) {
.button-color(@fluctuation-rise-active, @btn-default-bg, @fluctuation-rise-active);
}
}
.button-disabled();
}
// danger link button style
.btn-danger-link() {
.button-variant-other(@fluctuation-rise-rise, transparent, transparent);
box-shadow: none;
// &:focus,
&:hover {
& when (@theme = dark) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 7) `; transparent; transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 5) `; transparent; transparent);
}
& when (@theme = variable) {
.button-color(@fluctuation-rise-hover; transparent; transparent);
}
}
&:active {
& when (@theme = dark) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 5) `; transparent; transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 7) `; transparent; transparent);
}
& when (@theme = variable) {
.button-color(@fluctuation-rise-active; transparent; transparent);
}
}
.button-disabled(@disabled-color; transparent; transparent);
}
// link button style
.btn-link() {
.button-variant-other(@link-color, transparent, transparent);
box-shadow: none;
&:hover {
background-color: @btn-link-hover-bg;
}
&:active {
background-color: @btn-link-active-bg;
}
&:hover {
color: @btn-link-hover-color;
border-color: transparent;
}
// &:focus,
&:active {
color: @brand-primary;
border-color: transparent;
}
.button-disabled(@disable-link-color; transparent; transparent);
}
// text button style
.btn-text() {
.button-variant-other(@btn-text-color, transparent, transparent);
box-shadow: none;
&:hover {
color: @btn-text-hover-color;
background: @btn-text-hover-bg;
}
&:active {
color: @btn-text-color;
background: @btn-text-active-bg;
}
// &:focus {
// color: @btn-text-color;
// }
&:hover,
// &:focus,
&:active {
border-color: transparent;
}
.button-disabled(@disabled-color; transparent; transparent);
}
// text button&link button style for no padding
.btn-no-padding(@btnClassName: btn) {
padding: 0;
line-height: @btn-no-padding-height-normal;
height: @btn-no-padding-line-height-normal;
font-size: @btn-no-padding-font-size-normal;
&.@{btnClassName}-xs {
line-height: @line-height-base;
height: @btn-no-padding-height-xs;
font-size: @btn-no-padding-font-size-xs;
}
&.@{btnClassName}-sm {
font-size: @btn-no-padding-font-size-sm;
}
&:hover,
&:active {
background-color: transparent;
}
}
.btn-danger-text() {
.button-variant-other(@fluctuation-rise-rise, transparent, transparent);
box-shadow: none;
// &:focus,
&:hover {
& when (@theme = dark) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 7) `; @btn-text-hover-bg; transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
.button-color(~`colorPalette('@{fluctuation-rise-rise}', 5) `; @btn-text-hover-bg; transparent);
}
& when (@theme = variable) {
.button-color(@fluctuation-rise-hover; @btn-text-hover-bg; transparent);
}
}
&:active {
& when (@theme = dark) {
// .button-color(~`colorPalette('@{fluctuation-rise-rise}', 5) `; fadein(@btn-text-hover-bg, 1%); transparent);
}
& when (not (@theme = dark) and not (@theme = variable)) {
// .button-color(~`colorPalette('@{fluctuation-rise-rise}', 7) `; fadein(@btn-text-hover-bg, 1%); transparent);
}
& when (@theme = variable) {
// .button-color(@fluctuation-rise-active; fadein(@btn-text-hover-bg, 1%); transparent);
}
}
.button-disabled(@disabled-color; transparent; transparent);
}
// round button
.btn-round(@btnClassName: btn) {
.button-size(@btn-circle-size; (@btn-circle-size / 2); @font-size-base; @btn-circle-size);
&.@{btnClassName}-lg {
.button-size(
@btn-circle-size-lg; (@btn-circle-size-lg / 2); @btn-font-size-lg; @btn-circle-size-lg
);
}
&.@{btnClassName}-bg {
.button-size(
@btn-circle-size-bg; (@btn-circle-size-bg / 2); @btn-font-size-bg; @btn-circle-size-bg
);
}
&.@{btnClassName}-sm {
.button-size(
@btn-circle-size-sm; (@btn-circle-size-sm / 2); @font-size-base; @btn-circle-size-sm
);
}
&.@{btnClassName}-xs {
.button-size(
@btn-circle-size-xs; (@btn-circle-size-xs / 2); @font-size-base; @btn-circle-size-xs
);
}
}
// square button: the content only contains icon
.btn-square(@btnClassName: btn) {
.square(@btn-square-size);
.button-size(@btn-square-size; 0; @btn-square-only-icon-size; @btn-border-radius-sm);
& > * {
font-size: @btn-square-only-icon-size;
}
&.@{btnClassName}-lg {
.square(@btn-square-size-lg);
.button-size(@btn-square-size-lg; 0; @btn-square-only-icon-size-lg; @btn-border-radius-base);
& > * {
font-size: @btn-square-only-icon-size-lg;
}
}
&.@{btnClassName}-bg {
.square(@btn-square-size-bg);
.button-size(@btn-square-size-bg; 0; @btn-square-only-icon-size-bg; @btn-border-radius-base);
& > * {
font-size: @btn-square-only-icon-size-bg;
}
}
&.@{btnClassName}-sm {
.square(@btn-square-size-sm);
.button-size(@btn-square-size-sm; 0; @btn-square-only-icon-size-sm; @btn-border-radius-sm);
& > * {
font-size: @btn-square-only-icon-size-sm;
}
}
&.@{btnClassName}-xs {
.square(@btn-square-size-xs);
.button-size(@btn-square-size-xs; 0; @btn-square-only-icon-size-xs; @btn-border-radius-sm);
& > * {
font-size: @btn-square-only-icon-size-xs;
}
}
}
// circle button: the content only contains icon
.btn-circle(@btnClassName: btn) {
min-width: @btn-height-base;
padding-right: 0;
padding-left: 0;
text-align: center;
border-radius: 50%;
&.@{btnClassName}-lg {
min-width: @btn-height-lg;
border-radius: 50%;
}
&.@{btnClassName}-bg {
min-width: @btn-height-bg;
border-radius: 50%;
}
&.@{btnClassName}-sm {
min-width: @btn-height-sm;
border-radius: 50%;
}
&.@{btnClassName}-xs {
min-width: @btn-height-xs;
border-radius: 50%;
}
}
// Horizontal button groups style
// --------------------------------------------------
.btn-group(@btnClassName: btn) {
.button-group-base(@btnClassName);
.@{btnClassName} + .@{btnClassName},
.@{btnClassName} + &,
span + .@{btnClassName},
.@{btnClassName} + span,
> span + span,
& + .@{btnClassName},
& + & {
margin-left: -1px;
}
.@{btnClassName}-primary + .@{btnClassName}:not(.@{btnClassName}-primary):not([disabled]) {
border-left-color: transparent;
}
.@{btnClassName} {
border-radius: 0;
}
> .@{btnClassName}:first-child,
> span:first-child > .@{btnClassName} {
margin-left: 0;
}
> .@{btnClassName}:only-child {
border-radius: @btn-border-radius-base;
}
> span:only-child > .@{btnClassName} {
border-radius: @btn-border-radius-base;
}
> .@{btnClassName}:first-child:not(:last-child),
> span:first-child:not(:last-child) > .@{btnClassName} {
border-top-left-radius: @btn-border-radius-base;
border-bottom-left-radius: @btn-border-radius-base;
}
> .@{btnClassName}:last-child:not(:first-child),
> span:last-child:not(:first-child) > .@{btnClassName} {
border-top-right-radius: @btn-border-radius-base;
border-bottom-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-top-left-radius: @btn-border-radius-sm;
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;
border-bottom-right-radius: @btn-border-radius-sm;
}
}
& > & {
float: left;
}
& > &:not(:first-child):not(:last-child) > .@{btnClassName} {
border-radius: 0;
}
& > &:first-child:not(:last-child) {
> .@{btnClassName}:last-child {
padding-right: 8px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}
& > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
padding-left: 8px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
// 全局图标按钮样式分类
.icon-button(@bg-color, @hover-bg-color, @active-bg-color, @disable-bg-color, @prefix: @wd-prefix) {
@icon-button-disable: 'wd-icon-button__disable';
display: block;
width: @btn-height-base;
height: @btn-height-base;
line-height: @btn-height-base;
text-align: center;
cursor: pointer;
border-radius: 4px;
font-size: @font-size-lg;
background-color: @bg-color;
&:hover {
background-color: @hover-bg-color;
}
&:active {
background-color: @hover-bg-color;
}
.@{icon-button-disable} {
background-color: @disable-bg-color;
}
}