From 1b9249c685e34eb2e94b31ee0ec22421c6aa6a73 Mon Sep 17 00:00:00 2001 From: Alina Beck Date: Thu, 9 Jan 2020 13:13:33 +0530 Subject: [PATCH] manage button states and color schemes with mixin --- .../_new/styles/mixins/buttonStates.scss | 69 +++++++++ .../generic/BaseButton/BaseButton.story.js | 43 +++--- .../_new/generic/BaseButton/BaseButton.vue | 133 +++++------------- 3 files changed, 127 insertions(+), 118 deletions(-) create mode 100644 webapp/assets/_new/styles/mixins/buttonStates.scss diff --git a/webapp/assets/_new/styles/mixins/buttonStates.scss b/webapp/assets/_new/styles/mixins/buttonStates.scss new file mode 100644 index 000000000..bce2fc927 --- /dev/null +++ b/webapp/assets/_new/styles/mixins/buttonStates.scss @@ -0,0 +1,69 @@ +@mixin buttonStates($color-scheme: primary, $filled: false) { + $main-color: $color-primary; + $active-color: $color-primary-dark; + $hover-color: $color-primary-light; + + @if $color-scheme == danger { + $main-color: $color-danger; + $active-color: $color-danger-dark; + $hover-color: $color-danger-light; + } + + color: $main-color; + border-color: $main-color; + background-color: transparent; + transition: background-color 0.1s; + + &:focus { + outline: 1px dashed $main-color; + } + + &:enabled { + &:hover { + color: $color-neutral-100; + border-color: $main-color; + background-color: $main-color; + } + + &:active { + color: $color-neutral-100; + border-color: $active-color; + background-color: $active-color; + } + } + + &:disabled { + color: $color-neutral-60; + border-color: $color-neutral-60; + cursor: default; + } + + &.--loading { + color: $color-neutral-80; + } + + @if $filled { + color: $color-neutral-100; + border-color: $main-color; + background-color: $main-color; + + &:enabled { + &:hover { + border-color: $hover-color; + background-color: $hover-color; + } + + &:active { + color: $color-neutral-100; + border-color: $active-color; + background-color: $active-color; + } + } + + &:disabled { + color: $color-neutral-80; + background-color: $color-neutral-60; + border-color: $color-neutral-60; + } + } +} diff --git a/webapp/components/_new/generic/BaseButton/BaseButton.story.js b/webapp/components/_new/generic/BaseButton/BaseButton.story.js index 1621939c0..14674d99e 100644 --- a/webapp/components/_new/generic/BaseButton/BaseButton.story.js +++ b/webapp/components/_new/generic/BaseButton/BaseButton.story.js @@ -40,27 +40,6 @@ storiesOf('Generic/BaseButton', module) `, })) - .add('small', () => ({ - components: { BaseButton }, - template: ` -
- Small - S -
- `, - })) - - .add('primary', () => ({ - components: { BaseButton }, - template: ` -
- Primary - Disabled - Loading -
- `, - })) - .add('danger', () => ({ components: { BaseButton }, template: ` @@ -72,6 +51,28 @@ storiesOf('Generic/BaseButton', module) `, })) + .add('filled', () => ({ + components: { BaseButton }, + template: ` +
+ Filled + Filled Danger + Disabled + Loading +
+ `, + })) + + .add('small', () => ({ + components: { BaseButton }, + template: ` +
+ Small + S +
+ `, + })) + .add('ghost', () => ({ // TODO: add documentation --> ghost button should only be used for very special occasions // e.g. for the ContentMenu + for the EditorMenuBarButtons diff --git a/webapp/components/_new/generic/BaseButton/BaseButton.vue b/webapp/components/_new/generic/BaseButton/BaseButton.vue index fb69a00c0..6b484b9a1 100644 --- a/webapp/components/_new/generic/BaseButton/BaseButton.vue +++ b/webapp/components/_new/generic/BaseButton/BaseButton.vue @@ -1,12 +1,12 @@ @@ -23,20 +23,20 @@ export default { type: Boolean, default: false, }, - icon: { - type: String, + danger: { + type: Boolean, + default: false, + }, + filled: { + type: Boolean, + default: false, }, ghost: { type: Boolean, default: false, }, - primary: { - type: Boolean, - default: false, - }, - danger: { - type: Boolean, - default: false, + icon: { + type: String, }, loading: { type: Boolean, @@ -46,7 +46,7 @@ export default { type: String, default: 'regular', validator(value) { - return value.match(/(small|regular|large)/) + return value.match(/(small|regular)/) }, }, type: { @@ -63,14 +63,12 @@ export default { if (this.$slots.default == null) buttonClass += ' --icon-only' if (this.circle) buttonClass += ' --circle' - if (this.ghost) buttonClass += ' --ghost' + if (this.danger) buttonClass += ' --danger' if (this.loading) buttonClass += ' --loading' - - if (this.primary) buttonClass += ' --primary' - else if (this.danger) buttonClass += ' --danger' - if (this.size === 'small') buttonClass += ' --small' - else if (this.size === 'large') buttonClass += ' --large' + + if (this.filled) buttonClass += ' --filled' + else if (this.ghost) buttonClass += ' --ghost' return buttonClass }, @@ -79,95 +77,32 @@ export default {