From fe2e253f358f08f97cb9e1a5ec7df01f3c9bc3e1 Mon Sep 17 00:00:00 2001 From: 刘汉宸 Date: Wed, 8 Jul 2020 19:49:34 +0800 Subject: [PATCH] feat: 按钮支持主题与自定义颜色 --- examples/styles/variables.scss | 21 ++++++++++----------- examples/views/docs/component/button.md | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 1 + packages/button/index.scss | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------- packages/button/index.vue | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- packages/utils/index.js | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yarn.lock | 2 +- 7 files changed, 462 insertions(+), 108 deletions(-) create mode 100644 packages/utils/index.js diff --git a/examples/styles/variables.scss b/examples/styles/variables.scss index 9697f55..dd901b7 100644 --- a/examples/styles/variables.scss +++ b/examples/styles/variables.scss @@ -20,8 +20,6 @@ $background: #fff; // NEW STYLE -// $color-primary: #F39800; - $color-primary: #FDD108; $color-zy-yellow: #FDD108; @@ -33,6 +31,7 @@ $color-wx: #07c160; $color-blue: #2F86F6; $color-green: #28AA91; $color-red: #FF5257; +$color-yellow: #ffd752; $color-blue-dark: #5878B4; $color-ink: #2D2D2D; $color-grey: #8C8C8C; @@ -61,13 +60,13 @@ $color-disabled: #ccc; $bg-active: #f3f3f3; $bg-disabled: #f5f5f5; -$font-lg: 1.3125rem; -$font-md: 0.9375rem; -$font-sm: 0.6875rem; +$font-lg: 1.25rem; +$font-md: 1rem; +$font-sm: 0.65rem; -$h-gap-lg: 0.625rem; -$h-gap-md: 0.468rem; -$h-gap-sm: 0.3125rem; -$v-gap-lg: 1.4rem; -$v-gap-md: 0.9375rem; -$v-gap-sm: 0.625rem; \ No newline at end of file +$h-gap-lg: 0.65rem; +$h-gap-md: 0.45rem; +$h-gap-sm: 0.3rem; +$v-gap-lg: 1.5rem; +$v-gap-md: 1rem; +$v-gap-sm: 0.65rem; \ No newline at end of file diff --git a/examples/views/docs/component/button.md b/examples/views/docs/component/button.md index dded211..981eacc 100644 --- a/examples/views/docs/component/button.md +++ b/examples/views/docs/component/button.md @@ -11,10 +11,121 @@ ```html +``` + +::: + +## 按钮主题 + +配置`theme`属性改变按钮主题 + +::: snippet 支持`red`、`green`、`blue` + +```html + +``` + +::: + +## 按钮颜色 + +配置`color`属性改变按钮颜色 + +::: snippet 支持任意颜色 + +```html + ``` diff --git a/package.json b/package.json index 967e66b..464373c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "axios": "^0.19.2", + "color": "^3.1.2", "core-js": "^3.6.5", "element-theme-chalk": "^2.13.2", "element-ui": "^2.13.2", diff --git a/packages/button/index.scss b/packages/button/index.scss index 531ec97..fcccd16 100644 --- a/packages/button/index.scss +++ b/packages/button/index.scss @@ -6,32 +6,25 @@ font-weight: normal; font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif; cursor: pointer; - transition: all 70ms ease 20ms; - border-radius: 0.3125rem; + transition: all 70ms ease; + border-radius: 0.35rem; position: relative; display: inline-block; text-align: center; border: none; outline: none; - line-height: 1.5; - &::after { - line-height: 1.5; - padding: 0; - margin: 0; - border: none; - content: ""; - pointer-events: none; /* 防止点击触发 */ - box-sizing: border-box; - position: absolute; - width: 200%; - height: 200%; - left: 0; - top: 0; - border: 1px solid $color-border; - border-radius: 0.625rem; - transform: scale(0.5); - transform-origin: 0 0; - } + line-height: 1.5; + box-sizing: border-box; + border: 1px solid transparent; + &.red { + color: $color-red; + } + &.blue { + color: $color-blue; + } + &.green { + color: $color-green; + } &.block { display: block; width: 100%; @@ -48,99 +41,153 @@ padding: $h-gap-lg $v-gap-lg; font-size: $font-lg; } - &:active { + &.default { + border-color: $color-border; + } + &.button-hover { background-color: $bg-active; - &, &::after { - border-color: $bg-active; + } + @mixin fill-mixin($color) { + &.button-hover { + background-color: $color; } } &.primary { background-color: $color-primary; color: #FFF; - &:active { - background-color: darken($color-primary, 3%); - &, &::after { - border-color: darken($color-primary, 3%); - } + @include fill-mixin(lighten($color-primary, 10%)); + &.red { + background-color: $color-red; + @include fill-mixin(lighten($color-red, 10%)); + } + &.green { + background-color: $color-green; + @include fill-mixin(lighten($color-green, 10%)); } - &, &::after { - border-color: $color-primary; + &.blue { + background-color: $color-blue; + @include fill-mixin(lighten($color-blue, 10%)); } } &.secondary { - background-color: lighten($color-primary, 40%); color: $color-primary; - &:active { - background-color: lighten($color-primary, 30%); - color: darken($color-primary, 3%); - &, &::after { - border-color: lighten($color-primary, 30%); + background-color: hsl(hue($color-primary), saturation($color-primary), 95%); + @include fill-mixin(hsl(hue($color-primary), saturation($color-primary), 90%)); + &.red { + color: $color-red; + background-color: hsl(hue($color-red), saturation($color-red), 95%); + @include fill-mixin(hsl(hue($color-red), saturation($color-red), 90%)); + } + &.green { + color: $color-green; + background-color: hsl(hue($color-green), saturation($color-green), 95%); + @include fill-mixin(hsl(hue($color-green), saturation($color-green), 90%)); + } + &.blue { + color: $color-blue; + background-color: hsl(hue($color-blue), saturation($color-blue), 95%); + @include fill-mixin(hsl(hue($color-blue), saturation($color-blue), 90%)); + } + } + &.plain { + color: $color-primary; + background-color: hsl(hue($color-primary), saturation($color-primary), 95%); + border-color: $color-primary; + &:not(.custom).button-hover { + background-color: hsl(hue($color-primary), saturation($color-primary), 95%); + } + &.red { + color: $color-red; + border-color: $color-red; + background-color: hsl(hue($color-red), saturation($color-red), 95%); + &:not(.custom).button-hover { + background-color: hsl(hue($color-red), saturation($color-red), 90%); } } - &, &::after { - border-color: lighten($color-primary, 40%); - } - } - &.plain { - &.primary { - color: $color-primary; - background-color: transparent; - &:active { - background-color: rgba($color-primary, 0.1); - } - } - &.disabled { - background-color: rgba($bg-disabled, 0.1); - color: $color-disabled; - cursor: not-allowed; - &:active { - color: $color-disabled; - background-color: rgba($bg-disabled, 0.1); - &, &::after { - border-color: $bg-disabled; - } - } - &, &::after { - border-color: $bg-disabled; - } - } - } + &.green { + color: $color-green; + border-color: $color-green; + background-color: hsl(hue($color-green), saturation($color-green), 95%); + &:not(.custom).button-hover { + background-color: hsl(hue($color-green), saturation($color-green), 90%); + } + } + &.blue { + color: $color-blue; + border-color: $color-blue; + background-color: hsl(hue($color-blue), saturation($color-blue), 95%); + &:not(.custom).button-hover { + background-color: hsl(hue($color-blue), saturation($color-blue), 90%); + } + } + } + &.ghost { + color: $color-primary; + background-color: transparent; + border-color: $color-primary; + &:not(.custom).button-hover { + background-color: hsl(hue($color-primary), saturation($color-primary), 95%); + } + &.red { + color: $color-red; + border-color: $color-red; + &:not(.custom).button-hover { + background-color: hsl(hue($color-red), saturation($color-red), 95%); + } + } + &.green { + color: $color-green; + border-color: $color-green; + &:not(.custom).button-hover { + background-color: hsl(hue($color-green), saturation($color-green), 95%); + } + } + &.blue { + color: $color-blue; + border-color: $color-blue; + &:not(.custom).button-hover { + background-color: hsl(hue($color-blue), saturation($color-blue), 95%); + } + } + } &.link { - padding: $h-gap-sm $v-gap-sm; - background: inherit; - border: inherit; + background-color: transparent; + border-color: transparent; color: $color-primary; - &:active { - color: darken($color-primary, 5%); + &.button-hover { + color: lighten($color-primary, 10%); + } + &.red { + color: $color-red; + &.button-hover { + color: lighten($color-red, 10%); + } + } + &.green { + color: $color-green; + &.button-hover { + color: lighten($color-green, 10%); + } + } + &.blue { + color: $color-blue; + &.button-hover { + color: lighten($color-blue, 10%); + } } - &::after { - display: none; - } } &.disabled { background-color: $bg-disabled; color: $color-disabled; cursor: not-allowed; - &:active { + &.button-hover { background-color: $bg-disabled; - &, &::after { - border-color: $bg-disabled; - } - } - &, &::after { - border-color: $bg-disabled; } } &.round { border-radius: 1.5rem; - &::after { - border-radius: 3rem; - } } &.square { border-radius: 0; - &::after { - border-radius: 0; - } } } \ No newline at end of file diff --git a/packages/button/index.vue b/packages/button/index.vue index 10e0b5c..5f14d84 100644 --- a/packages/button/index.vue +++ b/packages/button/index.vue @@ -1,10 +1,12 @@