Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
url: 'http://localhost/',
customExportConditions: ["node", "node-addons"],
},

coverageProvider: 'v8',
Expand Down
2 changes: 2 additions & 0 deletions components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import navigation from './widgets/navigation/widget.vue';
import status from './widgets/status/widget.vue';
import textfield from './widgets/textfield/widget.vue';
import table from './widgets/table/widget.vue';
import button from './widgets/button/widget.vue';

import _store from './core/store';
import _bus from './core/eventBus';
Expand All @@ -28,6 +29,7 @@ export const Navigation = navigation;
export const Status = status;
export const Textfield = textfield;
export const Table = table;
export const Button = button;

export const bus = _bus;
export const store = _store;
Expand Down
29 changes: 29 additions & 0 deletions components/src/stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Button from '~widgets/button/widget.vue';
import registerWidget from '~core/registerWidget';

registerWidget('ui-button', Button);


export const Component = {
render: (args) => ({
setup() {
return { args };
},
template: `<ui-button disabled v-bind="args"></ui-button>`,
}),

args: {
text: 'Text',
},
};

export default {
title: 'Components/Button',
component: Button,
parameters: {
layout: 'centered',
},
argTypes: {
text: 'text',
},
};
34 changes: 34 additions & 0 deletions components/src/widgets/button/widget.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { mount } from '@vue/test-utils'
import Button from './widget';


describe('Button widget', () => {
let result;

describe('computed', () => {
describe('#style', () => {
it('returns the styles', () => {
const wrapper = mount(Button)

result = wrapper.vm.style;

expect(result).toEqual(`
background-color: #2C98F0;
color: #FFF;
`);
});
});
});

describe('methods', () => {
describe('#onClick', () => {
it('emits clicked event if it is not disabled', async () => {
const wrapper = mount(Button)

result = wrapper.vm.onClick();

expect(wrapper.emitted('clicked')).toBeTruthy()
});
});
});
});
74 changes: 74 additions & 0 deletions components/src/widgets/button/widget.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<button
:disabled="disabled"
:style="style"
@click="onClick"
>
<slot>
{{ text }}
</slot>
</button>
</template>

<script setup>
import { computed } from 'vue'

const emit = defineEmits(['clicked']);

const props = defineProps({
text: {
type: String,
default: '',
},
disabled: {
type: Boolean,
default: false,
},
backgroundColor: {
type: String,
default: '#2C98F0',
},
color: {
type: String,
default: '#FFF',
},
});

const style = computed(() => `
background-color: ${props.backgroundColor};
color: ${props.color};
`);

const onClick = () => {
if (!props.disabled) emit('clicked');
};

</script>

<style lang="stylus">
button {
text-transform: uppercase;
overflow: hidden;
padding-left: 8px;
padding-right: 8px;
border-radius: 2px;
cursor: pointer;
border-style: none;
font-family: Roboto, "Helvetica Neue", sans-serif;

&:hover {
opacity: 0.8;
}

&:disabled {
background-color: #f2f2f2 !important;
color: #BDBDBD !important;
opacity: 0.5;
cursor: default;
pointer-events: none;
}
}
</style>


Loading