Skip to content

Commit

Permalink
Merge branch 'vuestic_scrollbar'
Browse files Browse the repository at this point in the history
  • Loading branch information
papasikis committed Aug 1, 2017
2 parents d6bf498 + c95a76c commit eab0c99
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bootstrap": "^4.0.0-alpha.6",
"bootstrap-vue": "^0.9.0",
"chart.js": "^2.6.0",
"element-resize-detector": "^1.1.12",
"font-awesome": "^4.7.0",
"gemini-scrollbar": "^1.5.1",
"google-maps": "^3.2.1",
Expand Down
29 changes: 23 additions & 6 deletions src/components/common/vuestic-multi-select/VuesticMultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@
<small v-show="hasErrors()" class="help text-danger">{{ showRequiredError() }}</small>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="dropdown-item"
:class="{'selected': isOptionSelected(option)}" v-for="option in options"
@click="toggleSelection(option)">
<span class="ellipsis">{{option}}</span>
<i class="fa fa-check selected-icon"></i>
</div>
<scrollbar>
<div class="scroll-container">
<div class="dropdown-item"
:class="{'selected': isOptionSelected(option)}" v-for="option in options"
@click="toggleSelection(option)">
<span class="ellipsis">{{option}}</span>
<i class="fa fa-check selected-icon"></i>
</div>
</div>
</scrollbar>
</div>
</div>
</template>

<script>
import Dropdown from 'directives/Dropdown'
import Scrollbar from '../vuestic-scrollbar/VuesticScrollbar.vue'
export default {
components: {
Scrollbar
},
directives: {
dropdown: Dropdown
},
Expand Down Expand Up @@ -101,4 +109,13 @@

<style lang="scss">
@import "../../../sass/_variables.scss";
.multiselect-form-group {
.dropdown-menu {
padding: 0;
.vuestic-scrollbar {
height: $dropdown-item-height * 4;
}
}
}
</style>
137 changes: 137 additions & 0 deletions src/components/common/vuestic-scrollbar/VuesticScrollbar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<template>
<div class="vuestic-scrollbar">
<div class="scrollbar-wrapper">
<div class="scrollbar-content">
<slot></slot>
</div>
<div class="track"><div class="thumb"></div></div>
</div>
</div>
</template>

<script>
let erdMaker = require('element-resize-detector')
let erd = erdMaker()
let vm = {
props: {
speed: {
default: 20
}
},
methods: {
calcSize () {
console.log('test')
this.isDown = this.isUp = false
this.maxHeight = parseInt(this.wrapper.offsetHeight, 10)
this.contentHeight = parseInt(this.content.offsetHeight, 10)
this.trackHeight = parseInt(this.track.offsetHeight, 10)
this.thumb.style.height = this.maxHeight / this.contentHeight < 1
? this.maxHeight / this.contentHeight * this.trackHeight + 'px'
: 0
},
calcThumb () {
let currentMT = this.content.style.marginTop === ''
? 0
: parseInt(this.content.style.marginTop, 10)
this.thumb.style.top = (-currentMT / this.contentHeight * this.trackHeight) + 'px'
},
scroll (e) {
let delta = (e.deltaY * 0.01 * this.speed)
if (this.isDown && delta > 0 || this.isUp && delta < 0 || this.contentHeight <= this.maxHeight) {
e.preventDefault()
return
}
let currentMT = this.content.style.marginTop === ''
? 0
: parseInt(this.content.style.marginTop, 10)
let nextMT = 0
if (this.maxHeight - (currentMT - delta * this.speed) > this.contentHeight && delta > 0) {
nextMT = this.maxHeight - this.contentHeight
this.isDown = true
} else {
this.isDown = false
if (currentMT - delta > 0) {
this.isUp = true
nextMT = 0
} else {
nextMT = currentMT - delta
this.isUp = false
}
}
this.content.style.marginTop = nextMT + 'px'
this.calcThumb()
e.preventDefault()
}
},
mounted () {
this.track = this.$el.getElementsByClassName('track')[0]
this.thumb = this.track.getElementsByClassName('thumb')[0]
this.content = this.$el.getElementsByClassName('scrollbar-content')[0]
this.wrapper = this.$el.getElementsByClassName('scrollbar-wrapper')[0]
let handler = () => {
this.calcSize()
this.calcThumb()
}
erd.listenTo(this.content, handler)
erd.listenTo(this.$el, handler)
this.$el.addEventListener('wheel', this.scroll, false)
},
destroyed () {
erd.removeAllListeners(this.content)
erd.removeAllListeners(this.$el)
this.$el.removeEventListener('wheel', this.scroll, false)
},
data () {
return {
displayedHeight: undefined,
wrapper: undefined,
maxHeight: undefined,
thumb: undefined,
track: undefined,
trackHeight: undefined,
content: undefined,
contentHeight: undefined,
isDown: false,
isUp: true
}
}
}
module.exports = vm
</script>

<style lang="scss">
.vuestic-scrollbar {
position: relative;
height: 100%;
.scrollbar-wrapper {
height: 100%;
overflow: hidden;
}
.track {
position: absolute;
right: 0;
top: 0;
height: 100%;
width: 3px;
.thumb {
position: absolute;
width: 3px;
background-color: black;
opacity: .3;
}
}
&:hover {
.thumb {
opacity: 1 !important;
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@
<small v-show="hasErrors()" class="help text-danger">{{ showRequiredError() }}</small>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="dropdown-item"
:class="{'selected': isOptionSelected(option)}" v-for="option in options"
@click="selectOption(option)">
<span class="ellipsis">{{option}}</span>
</div>
<scrollbar>
<div class="scroll-container">
<div class="dropdown-item"
:class="{'selected': isOptionSelected(option)}" v-for="option in options"
@click="selectOption(option)">
<span class="ellipsis">{{option}}</span>
</div>
</div>
</scrollbar>
</div>
</div>
</template>

<script>
import Dropdown from 'directives/Dropdown'
import Scrollbar from '../vuestic-scrollbar/VuesticScrollbar.vue'
export default {
components: {
Scrollbar
},
directives: {
dropdown: Dropdown
},
Expand Down Expand Up @@ -91,4 +99,12 @@

<style lang="scss">
@import "../../../sass/_variables.scss";
.select-form-group {
.dropdown-menu {
padding: 0;
.vuestic-scrollbar {
height: $dropdown-item-height * 4;
}
}
}
</style>
5 changes: 3 additions & 2 deletions src/components/layout/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@
color: #000;
margin-right: 14px;
&.vuestic-icon {
margin-top: 3px;
&.fa-dashboard { /* Temp fix */
position: relative;
top: -2px
}
}
}
Expand Down

0 comments on commit eab0c99

Please sign in to comment.