Skip to content

Commit

Permalink
fix(timepicker): change getPopupStyle form timepicker, datepicker to …
Browse files Browse the repository at this point in the history
…util

docs: fix docs layout
  • Loading branch information
luchunyu authored and AngusFu committed Nov 28, 2018
1 parent 488d483 commit 5f0ee33
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/layouts/principle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:to="item.link",
:key="item.title"
) {{item.title}}
c-box-item.content(xs=12 sm=8 md=9 lg=10)
c-box-item.content(xs=12 sm="8 offset-4" md="9 offset-3" lg="10 offset-2")
transition(name='fade')
router-view.c-container.is-lg
c-footer
Expand Down
28 changes: 2 additions & 26 deletions src/components/datepicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
import './index.css'
import validatable from '@scripts/mixins/validatable'
import resettable from '@scripts/mixins/resettable'
import ZIndexManager from '@scripts/utils/zIndexManager.js'
import { getScrollBarSize } from '@util'
import { getPopupStyle } from '@util'
import Icon from '../icon/index.vue'
import Input from '../input/index.vue'
Expand Down Expand Up @@ -305,36 +304,13 @@ export default {
this.close()
},
setDate (date, notClose) {
// this.date = date
console.log(date)
this.showDate = date
this.$emit('change', date)
!notClose && this.close()
},
getStyle () {
const clientRect = this.$el.getBoundingClientRect()
const windowH = window.innerHeight
const windowW = window.innerWidth
const marginTop = 2
const scrollHeight = document.body.scrollWidth > window.innerWidth ? 20 : 0
const droplistHeight = this.datepickerPanel.clientHeight
const droplistWidth = this.datepickerPanel.clientWidth
const defaultTop = clientRect.top + clientRect.height + marginTop + window.pageYOffset
const clientHeight = clientRect.height + marginTop
const clientY = clientRect.y
const compTop = windowH - droplistHeight - scrollHeight
const marginRight = getScrollBarSize() + 5 // scrollbar width
const left = droplistWidth + clientRect.left + marginRight + window.pageXOffset > windowW ? windowW - droplistWidth - marginRight : clientRect.left + window.pageXOffset
const top = droplistHeight + clientHeight + clientY + scrollHeight > windowH ? compTop : defaultTop
const zIndex = ZIndexManager.next()
return `
position: absolute;
top: ${top}px;
left: ${left}px;
z-index: ${zIndex};
`
return getPopupStyle(this.$el, this.datepickerPanel)
},
resize () {
this.$nextTick(() => {
Expand Down
26 changes: 2 additions & 24 deletions src/components/timepicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@

<script>
import './index.css'
import { getScrollBarSize } from '@util'
import ZIndexManager from '../../scripts/utils/zIndexManager.js'
import { getPopupStyle } from '@util'
export default {
name: 'c-timepicker',
Expand Down Expand Up @@ -211,28 +210,7 @@ export default {
this.isOpen = true
},
getStyle () {
const clientRect = this.$el.getBoundingClientRect()
const windowH = window.innerHeight
const windowW = window.innerWidth
const marginTop = 2
const scrollHeight = document.body.scrollWidth > window.innerWidth ? 20 : 0
const droplistHeight = this.timepickerPanel.clientHeight
const droplistWidth = this.timepickerPanel.clientWidth
const defaultTop = clientRect.top + clientRect.height + marginTop + window.pageYOffset
const clientHeight = clientRect.height + marginTop
const clientY = clientRect.y
const compTop = windowH - droplistHeight - scrollHeight
const marginRight = getScrollBarSize() + 5 // scrollbar width
const left = droplistWidth + clientRect.left + marginRight + window.pageXOffset > windowW ? windowW - droplistWidth - marginRight : clientRect.left + window.pageXOffset
const top = droplistHeight + clientHeight + clientY + scrollHeight > windowH ? compTop : defaultTop
const zIndex = ZIndexManager.next()
return `
position: absolute;
top: ${top}px;
left: ${left}px;
z-index: ${zIndex};
`
return getPopupStyle(this.$el, this.timepickerPanel)
},
resize () {
this.$nextTick(() => {
Expand Down
26 changes: 2 additions & 24 deletions src/components/timepicker/timerange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
</template>
<script>
import './index.css'
import { getScrollBarSize } from '@util'
import ZIndexManager from '../../scripts/utils/zIndexManager.js'
import { getPopupStyle } from '@util'
export default {
name: 'c-timerange',
props: {
Expand Down Expand Up @@ -181,28 +180,7 @@ export default {
}
},
getStyle () {
const clientRect = this.$parent.$refs.timepicker.getBoundingClientRect()
const windowH = window.innerHeight
const windowW = window.innerWidth
const marginTop = 2
const scrollHeight = document.body.scrollWidth > window.innerWidth ? 20 : 0
const droplistHeight = this.timerange.clientHeight
const droplistWidth = this.timerange.clientWidth
const defaultTop = clientRect.top + clientRect.height + marginTop + window.pageYOffset
const clientHeight = clientRect.height + marginTop
const clientY = clientRect.y
const compTop = windowH - droplistHeight - scrollHeight
const marginRight = getScrollBarSize() + 5 // scrollbar width
const left = droplistWidth + clientRect.left + marginRight + window.pageXOffset > windowW ? windowW - droplistWidth - marginRight : clientRect.left + window.pageXOffset
const top = droplistHeight + clientHeight + clientY + scrollHeight > windowH ? compTop : defaultTop
const zIndex = ZIndexManager.next()
return `
position: absolute;
top: ${top}px;
left: ${left}px;
z-index: ${zIndex};
`
return getPopupStyle(this.$parent.$refs.timepicker, this.timerange)
},
resize () {
this.$nextTick(() => {
Expand Down
38 changes: 38 additions & 0 deletions src/scripts/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import VueTypes from './vue-types'
import ZIndexManager from './ZIndexManager'
export { VueTypes }

/**
Expand Down Expand Up @@ -111,3 +112,40 @@ export function defer () {
export function contains (elem, target) {
return elem && elem.contains ? elem.contains(target) : false
}

/**
*
*/
export function getPopupStyle (elem, panel) {
if (!elem || !panel) {
return 'position: absolute;'
}
const clientRect = elem.getBoundingClientRect()
const windowH = window.innerHeight
const windowW = window.innerWidth
const marginTop = 4
const scrollBarSize = getScrollBarSize()
const droplistHeight = panel.clientHeight
const droplistWidth = panel.clientWidth
const clientHeight = clientRect.height + marginTop
const defaultTop = clientRect.top + clientHeight + window.pageYOffset

const clientY = clientRect.y
const compTop = clientY + window.pageYOffset - droplistHeight - marginTop
const left =
droplistWidth + clientRect.left + scrollBarSize + window.pageXOffset > windowW
? windowW - droplistWidth - scrollBarSize
: clientRect.left + window.pageXOffset
const top =
droplistHeight + clientHeight + clientY + scrollBarSize > windowH
? compTop
: defaultTop
const zIndex = ZIndexManager.next()

return `
position: absolute;
top: ${top}px;
left: ${left}px;
z-index: ${zIndex};
`
}

0 comments on commit 5f0ee33

Please sign in to comment.