Skip to content

Commit 7079512

Browse files
authored
Merge pull request #39 from cloudblue/button
Add button
2 parents 0c4d54c + c5fdb8e commit 7079512

File tree

7 files changed

+317
-0
lines changed

7 files changed

+317
-0
lines changed

components/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = {
4141
testEnvironment: 'jsdom',
4242
testEnvironmentOptions: {
4343
url: 'http://localhost/',
44+
customExportConditions: ["node", "node-addons"],
4445
},
4546

4647
coverageProvider: 'v8',

components/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import navigation from './widgets/navigation/widget.vue';
1111
import status from './widgets/status/widget.vue';
1212
import textfield from './widgets/textfield/widget.vue';
1313
import table from './widgets/table/widget.vue';
14+
import button from './widgets/button/widget.vue';
1415

1516
import _store from './core/store';
1617
import _bus from './core/eventBus';
@@ -28,6 +29,7 @@ export const Navigation = navigation;
2829
export const Status = status;
2930
export const Textfield = textfield;
3031
export const Table = table;
32+
export const Button = button;
3133

3234
export const bus = _bus;
3335
export const store = _store;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Button from '~widgets/button/widget.vue';
2+
import registerWidget from '~core/registerWidget';
3+
4+
registerWidget('ui-button', Button);
5+
6+
7+
export const Component = {
8+
render: (args) => ({
9+
setup() {
10+
return { args };
11+
},
12+
template: `<ui-button disabled v-bind="args"></ui-button>`,
13+
}),
14+
15+
args: {
16+
text: 'Text',
17+
},
18+
};
19+
20+
export default {
21+
title: 'Components/Button',
22+
component: Button,
23+
parameters: {
24+
layout: 'centered',
25+
},
26+
argTypes: {
27+
text: 'text',
28+
},
29+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { mount } from '@vue/test-utils'
2+
import Button from './widget';
3+
4+
5+
describe('Button widget', () => {
6+
let result;
7+
8+
describe('computed', () => {
9+
describe('#style', () => {
10+
it('returns the styles', () => {
11+
const wrapper = mount(Button)
12+
13+
result = wrapper.vm.style;
14+
15+
expect(result).toEqual(`
16+
background-color: #2C98F0;
17+
color: #FFF;
18+
`);
19+
});
20+
});
21+
});
22+
23+
describe('methods', () => {
24+
describe('#onClick', () => {
25+
it('emits clicked event if it is not disabled', async () => {
26+
const wrapper = mount(Button)
27+
28+
result = wrapper.vm.onClick();
29+
30+
expect(wrapper.emitted('clicked')).toBeTruthy()
31+
});
32+
});
33+
});
34+
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!-- eslint-disable vue/no-v-html -->
2+
<template>
3+
<button
4+
:disabled="disabled"
5+
:style="style"
6+
@click="onClick"
7+
>
8+
<slot>
9+
{{ text }}
10+
</slot>
11+
</button>
12+
</template>
13+
14+
<script setup>
15+
import { computed } from 'vue'
16+
17+
const emit = defineEmits(['clicked']);
18+
19+
const props = defineProps({
20+
text: {
21+
type: String,
22+
default: '',
23+
},
24+
disabled: {
25+
type: Boolean,
26+
default: false,
27+
},
28+
backgroundColor: {
29+
type: String,
30+
default: '#2C98F0',
31+
},
32+
color: {
33+
type: String,
34+
default: '#FFF',
35+
},
36+
});
37+
38+
const style = computed(() => `
39+
background-color: ${props.backgroundColor};
40+
color: ${props.color};
41+
`);
42+
43+
const onClick = () => {
44+
if (!props.disabled) emit('clicked');
45+
};
46+
47+
</script>
48+
49+
<style lang="stylus">
50+
button {
51+
text-transform: uppercase;
52+
overflow: hidden;
53+
padding-left: 8px;
54+
padding-right: 8px;
55+
border-radius: 2px;
56+
cursor: pointer;
57+
border-style: none;
58+
font-family: Roboto, "Helvetica Neue", sans-serif;
59+
60+
&:hover {
61+
opacity: 0.8;
62+
}
63+
64+
&:disabled {
65+
background-color: #f2f2f2 !important;
66+
color: #BDBDBD !important;
67+
opacity: 0.5;
68+
cursor: default;
69+
pointer-events: none;
70+
}
71+
}
72+
</style>
73+
74+

0 commit comments

Comments
 (0)