diff options
add button loading animations
5 files changed, 270 insertions, 3 deletions
| -rw-r--r-- | demo/index.html | 28 | ||||
| -rw-r--r-- | dist/spectre.css | 131 | ||||
| -rw-r--r-- | src/buttons.less | 104 | ||||
| -rw-r--r-- | src/utilities.less | 6 | ||||
| -rw-r--r-- | src/variables.less | 4 |
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 @@ <link rel="stylesheet" href="../dist/spectre.css"> <style> .columns .column { - background-color: #efefef; - border: 1px solid #ddd; + border: 1px solid transparent; } </style> </head> @@ -87,6 +86,31 @@ </div> </div> </section> + <section class="layout"> + <header class="text-center"><h4>buttons</h4></header> + <div class="columns"> + <div class="column"> + <button class="btn">default button</button> + </div> + <div class="column"> + <button class="btn btn-primary">primary button</button> + </div> + <div class="column"> + <button class="btn btn-link">link button</button> + </div> + </div> + <div class="columns"> + <div class="column"> + <button class="btn loading">default button</button> + </div> + <div class="column"> + <button class="btn btn-primary loading">primary button</button> + </div> + <div class="column"> + <button class="btn btn-link loading">link button</button> + </div> + </div> + </section> </section> </body> </html>
\ 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 { |