From 8952210ff0063d1c7a10a8bbe837c7c73e4e3648 Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Fri, 11 Mar 2016 18:06:32 +0800 Subject: add button loading animations --- demo/index.html | 28 +++++++++++- dist/spectre.css | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/buttons.less | 104 +++++++++++++++++++++++++++++++++++++++++- src/utilities.less | 6 +++ src/variables.less | 4 ++ 5 files changed, 270 insertions(+), 3 deletions(-) diff --git a/demo/index.html b/demo/index.html index 92ac08b..3767fb8 100644 --- a/demo/index.html +++ b/demo/index.html @@ -6,8 +6,7 @@ @@ -87,6 +86,31 @@ +
+

buttons

+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/dist/spectre.css b/dist/spectre.css index 6b3a9fe..ae8f22e 100644 --- a/dist/spectre.css +++ b/dist/spectre.css @@ -614,6 +614,117 @@ ol ol { width: 8.33333333%; } } +.btn, +button { + display: inline-block; + padding: .7rem 1.5rem; + background-color: transparent; + border-radius: 3px; + color: #5764C6; + font-size: 1.4rem; + line-height: 1.2; + text-align: center; + text-decoration: none; + vertical-align: middle; + border: 1px solid #5764C6; + white-space: nowrap; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + -webkit-appearance: none; + outline: 0; +} +.btn:hover, +button:hover, +.btn:focus, +button:focus { + color: #fff; + background-color: #5764C6; +} +.btn:active, +button:active, +.btn.active, +button.active { + color: #fff; + background-color: #4452c0; +} +.btn.loading, +button.loading { + color: transparent !important; + pointer-events: none; + position: relative; +} +.btn.loading::after, +button.loading::after { + border: 2px solid #5764C6; + border-right-color: transparent; + border-top-color: transparent; + border-radius: 8px; + content: ""; + position: absolute; + left: 50%; + top: 50%; + margin-left: -8px; + margin-top: -8px; + display: block; + width: 16px; + height: 16px; + -webkit-animation: loading 500ms infinite linear; + animation: loading 500ms infinite linear; +} +.btn[disabled], +button[disabled] { + opacity: .5; + cursor: default; +} +.btn.btn-primary, +button.btn-primary { + color: #fff; + border-color: #5764C6; + background-color: #5764C6; +} +.btn.btn-primary:hover, +button.btn-primary:hover, +.btn.btn-primary:focus, +button.btn-primary:focus { + color: #fff; + border-color: #4452c0; + background-color: #4452c0; +} +.btn.btn-primary:active, +button.btn-primary:active, +.btn.btn-primary.active, +button.btn-primary.active { + color: #fff; + border-color: #3b49af; + background-color: #3b49af; +} +.btn.btn-primary.loading::after, +button.btn-primary.loading::after { + border-color: #fff; + border-right-color: transparent; + border-top-color: transparent; +} +.btn.btn-link, +button.btn-link { + color: #5764C6; + border-color: transparent; + background-color: transparent; +} +.btn.btn-link:hover, +button.btn-link:hover, +.btn.btn-link:focus, +button.btn-link:focus { + color: #35419c; +} +.btn.btn-link:active, +button.btn-link:active, +.btn.btn-link.active, +button.btn-link.active { + color: #283176; +} .clearfix::after, .container::after, .columns::after { @@ -712,3 +823,23 @@ ol ol { .circle { border-radius: 50%; } +@-webkit-keyframes loading { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } +} +@keyframes loading { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } +} diff --git a/src/buttons.less b/src/buttons.less index 237eaa8..ae5b7d7 100644 --- a/src/buttons.less +++ b/src/buttons.less @@ -1 +1,103 @@ -// Buttons \ No newline at end of file +// Buttons +.btn, +button { + display: inline-block; + padding: .7rem 1.5rem; + background-color: transparent; + border-radius: 3px; + color: @core-color; + font-size: 1.4rem; + line-height: 1.2; + text-align: center; + text-decoration: none; + vertical-align: middle; + border: 1px solid @core-color; + white-space: nowrap; + cursor: pointer; + user-select: none; + -webkit-appearance: none; + outline: 0; + + &:hover, + &:focus { + color: #fff; + background-color: @core-color; + } + &:active, + &.active { + color: #fff; + background-color: darken(@core-color, 5%); + } + + &.loading { + color: transparent !important; + pointer-events: none; + position: relative; + + &::after { + border: 2px solid @core-color; + border-right-color: transparent; + border-top-color: transparent; + border-radius: 8px; + content: ""; + position: absolute; + left: 50%; + top: 50%; + margin-left: -8px; + margin-top: -8px; + display: block; + width: 16px; + height: 16px; + animation: loading 500ms infinite linear; + } + } + + &[disabled] { + opacity: .5; + cursor: default; + } + + &.btn-primary { + color: #fff; + border-color: @core-color; + background-color: @core-color; + + &:hover, + &:focus { + color: #fff; + border-color: darken(@core-color, 5%); + background-color: darken(@core-color, 5%); + } + &:active, + &.active { + color: #fff; + border-color: darken(@core-color, 10%); + background-color: darken(@core-color, 10%); + } + + &.loading { + &::after { + border-color: #fff; + border-right-color: transparent; + border-top-color: transparent; + } + } + } + + &.btn-link { + color: @core-color; + border-color: transparent; + background-color: transparent; + + &:hover, + &:focus { + color: darken(@core-color, 15%); + } + &:active, + &.active { + color: darken(@core-color, 25%); + } + } + + // TODO: Button with icons +} \ No newline at end of file diff --git a/src/utilities.less b/src/utilities.less index d49fe37..f3b4d89 100644 --- a/src/utilities.less +++ b/src/utilities.less @@ -98,4 +98,10 @@ } .circle { border-radius: 50%; +} + +// Animations +@keyframes loading { + 0%{transform: rotate(0deg);} + 100%{transform: rotate(360deg);} } \ No newline at end of file diff --git a/src/variables.less b/src/variables.less index d4a8cb9..da3b46f 100644 --- a/src/variables.less +++ b/src/variables.less @@ -6,6 +6,10 @@ @body-font-size: 14px; @body-font-family: "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", WenQuanYi Micro Hei, sans-serif; +// Colors +@core-color: #5764C6; + + // Mixins .clearfix() { &::after { -- cgit v1.3.1-26-gb76a