From 62a53e75b8f4b8f0b61d4fecd7ce06aae78c40c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Fri, 14 Oct 2016 09:12:10 +0800 Subject: [PATCH 1/3] refactor: Downsize some style code (#3421) * remove fieldset disabled style * improve button style mixins --- components/button/style/mixin.less | 89 ++++++++++++++---------------- components/form/style/index.less | 9 +-- components/input/style/mixin.less | 5 +- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/components/button/style/mixin.less b/components/button/style/mixin.less index 803d6dc1fe..e46f4cb557 100644 --- a/components/button/style/mixin.less +++ b/components/button/style/mixin.less @@ -6,21 +6,9 @@ border-radius: @border-radius; } -.button-variant(@color; @background; @border) { - .button-color(@color; @background; @border); - - &:hover, - &:focus { - .button-color(tint(@color, 20%); tint(@background, 20%); tint(@border, 20%)); - } - &:active, - &.active { - .button-color(shade(@color, 5%); shade(@background, 5%); shade(@background, 5%)); - } - +.button-disabled() { &.disabled, - &[disabled], - fieldset[disabled] & { + &[disabled] { &, &:hover, &:focus, @@ -31,6 +19,38 @@ } } +.button-variant-primary(@color; @background) { + .button-color(@color; @background; @background); + + &:hover, + &:focus { + .button-color(@color; tint(@background, 20%); tint(@background, 20%)); + } + + &:active, + &.active { + .button-color(@color; shade(@background, 5%); shade(@background, 5%)); + } + + .button-disabled(); +} + +.button-variant-other(@color; @background; @border) { + .button-color(@color; @background; @border); + + &:hover, + &:focus { + .button-color(tint(@primary-color, 20%); @background; tint(@primary-color, 20%)); + } + + &:active, + &.active { + .button-color(shade(@primary-color, 5%); @background; shade(@primary-color, 5%)); + } + + .button-disabled(); +} + .button-color(@color; @background; @border) { color: @color; background-color: @background; @@ -91,7 +111,6 @@ cursor: pointer; background-image: none; border: 1px solid transparent; - // outline: none; white-space: nowrap; line-height: @line-height-base; .button-size(@btn-padding-base; @font-size-base; @btn-border-radius-base); @@ -137,57 +156,29 @@ // primary button style .btn-primary() { - .button-variant(@btn-primary-color; @btn-primary-bg; @primary-color); - - &:hover, - &:focus, - &:active, - &.active { - color: @btn-primary-color; - } + .button-variant-primary(@btn-primary-color; @btn-primary-bg); } // default button style .btn-default() { - .button-variant(@btn-default-color; @btn-default-bg; @btn-default-border); - + .button-variant-other(@btn-default-color; @btn-default-bg; @btn-default-border); &:hover, - &:focus { - .button-color(tint(@primary-color, 20%); white; tint(@primary-color, 20%)); - } + &:focus, &:active, &.active { - .button-color(shade(@primary-color, 5%); white; shade(@primary-color, 5%)); + background: #fff; } } // ghost button style .btn-ghost() { - .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border); - - &:hover, - &:focus { - .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%)); - } - &:active, - &.active { - .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%)); - } + .button-variant-other(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border); } // ghost button style .btn-dashed() { - .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border); + .button-variant-other(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border); border-style: dashed; - - &:hover, - &:focus { - .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%)); - } - &:active, - &.active { - .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%)); - } } // circle button: the content only contains icon diff --git a/components/form/style/index.less b/components/form/style/index.less index b8730b5271..7118111996 100644 --- a/components/form/style/index.less +++ b/components/form/style/index.less @@ -31,8 +31,7 @@ label { input[type="radio"], input[type="checkbox"] { &[disabled], - &.disabled, - fieldset[disabled] & { + &.disabled { cursor: @cursor-disabled; } } @@ -42,8 +41,7 @@ input[type="checkbox"] { .@{ant-prefix}-radio-vertical, .@{ant-prefix}-checkbox-inline, .@{ant-prefix}-checkbox-vertical { - &.disabled, - fieldset[disabled] & { + &.disabled { cursor: @cursor-disabled; } } @@ -51,8 +49,7 @@ input[type="checkbox"] { // These classes are used on elements with