File tree Expand file tree Collapse file tree 7 files changed +317
-0
lines changed Expand file tree Collapse file tree 7 files changed +317
-0
lines changed Original file line number Diff line number Diff 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' ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import navigation from './widgets/navigation/widget.vue';
1111import status from './widgets/status/widget.vue' ;
1212import textfield from './widgets/textfield/widget.vue' ;
1313import table from './widgets/table/widget.vue' ;
14+ import button from './widgets/button/widget.vue' ;
1415
1516import _store from './core/store' ;
1617import _bus from './core/eventBus' ;
@@ -28,6 +29,7 @@ export const Navigation = navigation;
2829export const Status = status ;
2930export const Textfield = textfield ;
3031export const Table = table ;
32+ export const Button = button ;
3133
3234export const bus = _bus ;
3335export const store = _store ;
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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 : #f2 f2 f2 !important ;
66+ color : #BD BD BD !important ;
67+ opacity : 0.5 ;
68+ cursor : default ;
69+ pointer-events : none ;
70+ }
71+ }
72+ </style >
73+
74+
You can’t perform that action at this time.
0 commit comments