Skip to content

Commit

Permalink
feat(button): primary button mode (#53)
Browse files Browse the repository at this point in the history
* feat(button): primary button mode

* test(button): primary mode covered

* docs(button): primary mode example

* fix(button): primary and disabled styling
  • Loading branch information
arturmiz authored Feb 11, 2019
1 parent 56916c5 commit 61957be
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/button.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ exports[`Button by default renders correctly 1`] = `<button type="button" class=

exports[`Button can be disabled renders correctly 1`] = `<button type="button" disabled="disabled" class="vnt-button">Button</button>`;

exports[`Button can be set in a primary mode renders correctly 1`] = `<button type="button" class="vnt-button vnt-button--primary">Button</button>`;

exports[`Button can have content set using slot 1`] = `<button type="button" class="vnt-button"><span>Custom content</span></button>`;
24 changes: 24 additions & 0 deletions __tests__/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ describe('Button', () => {
expect(wrapper.vm.disabled).toBe(false);
});

test('is not in primary mode', () => {
expect(wrapper.vm.primary).toBe(false);
});

test('label text is "Button"', () => {
expect(wrapper.vm.label).toBe('Button');
});
Expand Down Expand Up @@ -85,4 +89,24 @@ describe('Button', () => {
expect(mockClick).toHaveBeenCalled();
});

describe('can be set in a primary mode', () => {

beforeAll(() => {
wrapper = mount(VntButton, {
propsData: {
primary: true
}
});
});

test('sets prop correctly', () => {
expect(wrapper.vm.primary).toBe(true);
});

test('renders correctly', () => {
expect(wrapper).toMatchSnapshot();
});

});

});
16 changes: 16 additions & 0 deletions docs/.vuepress/components/button-primary.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div class="playground">
<vnt-button primary>Primary</vnt-button>
</div>
</template>

<script>
import { VntButton } from '../../../src/components';
export default {
name: 'ButtonPrimary',
components: {
VntButton
}
}
</script>
15 changes: 14 additions & 1 deletion docs/components/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ or
<vnt-button label="Button"></vnt-button>
```

## Primary

<button-primary />

```html
<vnt-button primary>Primary</vnt-button>
```

## Disabled

<button-disabled />
Expand All @@ -39,7 +47,12 @@ Determines whether the button should be in disabled mode or not.
### `label`
Default: `'Button'`

The button's text
The button's text.

### `primary`
Default: `false`

Determines whether the button has primary button styling or not.

### `type`
Default: `button`
Expand Down
28 changes: 25 additions & 3 deletions src/components/button/Button.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<button class="vnt-button"
:class="{'vnt-button--primary': primary}"
:type="type"
:disabled="disabled"
@click="click">
Expand Down Expand Up @@ -27,6 +28,10 @@ export default {
click: {
type: Function,
default: () => {}
},
primary: {
type: Boolean,
default: false
}
}
};
Expand All @@ -35,13 +40,15 @@ export default {
<style lang="scss">
@import '../../scss/mixins/component';
$buttonBaseColor: #ccc;
.vnt-button {
@include component-base();
line-height: 30px;
background: #ccc;
background: $buttonBaseColor;
padding: 0 37px;
border: 1px solid #ccc;
border: 1px solid $buttonBaseColor;
color: #000100;
& ~ & {
Expand All @@ -60,8 +67,23 @@ export default {
color: #7a7a7a;
&:hover {
border-color: #ccc;
border-color: $buttonBaseColor;
}
}
}
.vnt-button--primary {
background: var(--vnt-accent-color, $fallbackAccentColor);
border-color: var(--vnt-accent-color, $fallbackAccentColor);
color: #fff;
&:hover {
border-color: #7a7a7a;
}
&:disabled {
background: $buttonBaseColor;
border-color: $buttonBaseColor;
}
}
</style>
5 changes: 5 additions & 0 deletions src/components/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ The action handler invoked once user clicks the button. Must be a JS function.
Default: `false`

Determines whether the button should be in disabled mode or not.

#### `primary`
Default: `false`

Determines whether the button has primary button styling or not.

0 comments on commit 61957be

Please sign in to comment.