Skip to content

Commit

Permalink
feat(v-btn-plus): added v-btn-plus
Browse files Browse the repository at this point in the history
Added VBtnPlus that integrates VBtn, VHover and VTooltip. It includes unit tests and Storybook
stories. In addition moved to vue-type to make type checking and validation of props more concise.
This has been done for both VBtnPlus and VStatsCard. Also added warning unit tests for both.
  • Loading branch information
nidkil committed Jan 19, 2019
1 parent 41ad049 commit 445074f
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 147 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"vue": "^2.5.21",
"vue-router": "^3.0.1",
"vue-types": "^1.3.4",
"vuetify": "^1.3.0",
"vuex": "^3.0.1"
},
Expand Down
45 changes: 42 additions & 3 deletions src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,49 @@
></v-img>
</v-flex>

<v-flex xs12 my-3>
<v-layout
justify-center
row
wrap
>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus @click="onClick" label="Cool" color="red" type="outline" colorHover="green" />
</v-flex>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus icon="mdi-account" tooltip="Wow!" type="icon" />
</v-flex>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus icon="mdi-account" tooltip="Wow!" type="fab" color="blue" />
</v-flex>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus icon="mdi-account" tooltip="Wow!" type="depressed" color="orange" />
</v-flex>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus icon="mdi-account" tooltip="Wow!" type="flat" color="red" />
</v-flex>
<v-flex xs4 sm3 md2 pa-2>
<v-btn-plus icon="mdi-account" tooltip="Wow!" type="round" color="purple" />
</v-flex>
<v-flex xs4 sm3 md4 pa-2>
<v-btn-plus label="Account" tooltip="Wow!" type="block" color="purple" />
</v-flex>
</v-layout>
</v-flex>

<v-flex xs12 my-3>
<v-layout
justify-center
row
wrap
>
<v-flex xs4 pa-2>
<v-flex xs8 sm7 md4 lg3 pa-2>
<v-stats-card title="1.200" sub-title="assigned credits" color="primary" icon="mdi-plus" />
</v-flex>
<v-flex xs4 pa-2>
<v-flex xs8 sm7 md4 lg3 pa-2>
<v-stats-card title="1.000" sub-title="used credits" color="secondary" icon="mdi-minus" />
</v-flex>
<v-flex xs4 pa-2>
<v-flex xs8 sm7 md4 lg3 pa-2>
<v-stats-card title="200" sub-title="remaining credits" color="accent" icon="mdi-sigma" />
</v-flex>
</v-layout>
Expand Down Expand Up @@ -102,7 +133,9 @@
</template>

<script>
import VBtnPlus from '@/components/common/VBtnPlus'
import VStatsCard from '@/components/common/VStatsCard'
export default {
props: {
msg: {
Expand Down Expand Up @@ -163,7 +196,13 @@ export default {
}
]
}),
methods: {
onClick: function() {
console.log('Clicked!')
}
},
components: {
VBtnPlus,
VStatsCard
}
}
Expand Down
167 changes: 93 additions & 74 deletions src/components/common/VBtnPlus.vue
Original file line number Diff line number Diff line change
@@ -1,74 +1,93 @@
<template>
<div>
<v-hover v-if="tooltip">
<v-tooltip
slot-scope="{ hover }"
bottom
>
<v-btn
slot="activator"
flat
:icon="hasIcon(item)"
:color="hover ? toolbarTextColorHover() : toolbarTextColor()"
:class="{ 'text-capitalize': item.label, 'text-lowercase': item.icon }"
>
<span v-if="item.label">{{ item.label }}</span>
<v-icon v-else>{{ item.icon }}</v-icon>
</v-btn>
<span>{{ item.tooltip }}</span>
</v-tooltip>
</v-hover>
<v-hover v-else>
<v-btn
slot-scope="{ hover }"
flat
:icon="hasIcon(item)"
:color="hover ? toolbarTextColorHover() : toolbarTextColor()"
:class="{ 'text-capitalize': item.label, 'text-lowercase': item.icon }"
>
<span v-if="item.label">{{ item.label }}</span>
<v-icon v-else>{{ item.icon }}</v-icon>
</v-btn>
</v-hover>
</div>
</template>

<script>
export default {
name: 'v-btn-plus',
props: {
color: {
type: String,
required: false,
default: 'primary'
},
icon: {
type: String,
required: false,
default: null
},
label: {
type: String,
required: false,
default: 'label'
},
tooltip: {
type: String,
required: false,
default: null
}
},
data: () => ({}),
methods: {
onClick() {
this.$emit('click')
},
hasIcon() {
return this.icon && this.icon.length > 0
}
}
}
</script>

<style scoped>
</style>
<template>
<div>
<v-hover v-if="tooltip">
<v-tooltip
slot-scope="{ hover }"
bottom
>
<v-btn
slot="activator"
:theme="theme"
:align="align"
:justify="justify"
:disabled="disabled"
:depressed="type === 'depressed'"
:block="type === 'block'"
:flat="type === 'flat'"
:fab="type === 'fab'"
:icon="type === 'icon'"
:outline="type === 'outline'"
:raised="type === 'raised'"
:round="type === 'round'"
:color="hover ? colorHover : color"
:class="{ 'text-capitalize': label, 'text-lowercase': icon }"
:size="size"
@click="onClick()"
>
<span v-if="label">{{ label }}</span>
<v-icon v-else>{{ icon }}</v-icon>
</v-btn>
<span>{{ tooltip }}</span>
</v-tooltip>
</v-hover>
<v-hover v-else>
<v-btn
slot-scope="{ hover }"
:theme="theme"
:align="align"
:justify="justify"
:disabled="disabled"
:depressed="type === 'depressed'"
:block="type === 'block'"
:flat="type === 'flat'"
:fab="type === 'fab'"
:icon="type === 'icon'"
:outline="type === 'outline'"
:raised="type === 'raised'"
:round="type === 'round'"
:color="hover ? colorHover : color"
:class="{ 'text-capitalize': label, 'text-lowercase': icon }"
:size="size"
@click="onClick()"
>
<span v-if="label">{{ label }}</span>
<v-icon v-else>{{ icon }}</v-icon>
</v-btn>
</v-hover>
</div>
</template>

<script>
import VueTypes from 'vue-types'
export default {
name: 'v-btn-plus',
props: {
align: VueTypes.oneOf(['bottom', 'top']),
justify: VueTypes.oneOf(['left', 'right']),
color: VueTypes.string.def('primary'),
colorHover: VueTypes.string.def('secondary'),
disabled: VueTypes.bool.def(false),
icon: VueTypes.string,
label: VueTypes.string,
position: VueTypes.oneOf(['left', 'right']),
tooltip: VueTypes.string,
size: VueTypes.oneOf(['small', 'medium', 'large']).def('small'),
theme: VueTypes.oneOf(['light', 'dark']),
type: VueTypes.oneOf(['block', 'depressed', 'fab', 'flat', 'icon', 'outline', 'raised', 'round']).def('raised')
},
methods: {
onClick() {
this.$emit('click')
}
},
created: function() {
// Workaround as prop validation on multiple props is not possible
if (!this.icon && !this.label) {
console.error('[Vue warn]: Missing required prop, specify at least one of the following: "label" or "icon"')
}
}
}
</script>

<style scoped>
</style>
23 changes: 5 additions & 18 deletions src/components/common/VStatsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,14 @@
</template>

<script>
import VueTypes from 'vue-types'
export default {
name: 'v-stats-card',
props: {
icon: {
type: String,
required: false,
default: 'mdi-information-outline'
},
title: {
type: String,
required: true
},
subTitle: {
type: String,
required: true
},
color: {
type: String,
required: false,
default: 'grey'
}
icon: VueTypes.string.def('mdi-information-outline'),
title: VueTypes.string.isRequired,
subTitle: VueTypes.string.isRequired,
color: VueTypes.string.def('grey')
}
}
</script>
7 changes: 5 additions & 2 deletions src/plugins/vuetify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from 'vue'
import Vuetify, { VApp, VCard, VCardText, VContainer, VFlex, VIcon, VLayout } from 'vuetify/lib'
import Vuetify, { VApp, VBtn, VCard, VCardText, VContainer, VFlex, VHover, VIcon, VLayout, VTooltip } from 'vuetify/lib'
import 'vuetify/src/stylus/app.styl'

Vue.use(Vuetify, {
Expand All @@ -15,11 +15,14 @@ Vue.use(Vuetify, {
},
components: {
VApp,
VBtn,
VCard,
VCardText,
VContainer,
VFlex,
VHover,
VIcon,
VLayout
VLayout,
VTooltip
}
})
Loading

0 comments on commit 445074f

Please sign in to comment.