Skip to content

Commit

Permalink
fix(ui/sticky): 增加scroll事件监听
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Dec 30, 2020
1 parent 8acff00 commit 19e1447
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/varlet-ui/src/sticky/Sticky.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
>
<div
class="var-sticky__wrapper"
ref="scannerEl"
:style="{
position: isFixed ? 'fixed' : null,
left: isFixed ? fixedLeft : null,
Expand Down Expand Up @@ -61,8 +60,12 @@ export default defineComponent({
fixedTop.value = `${scrollerTop + offsetTop.value}px`
fixedLeft.value = `${stickyLeft}px`
isFixed.value = true
props.onScroll?.(offsetTop.value, isFixed.value)
} else {
isFixed.value = false
props.onScroll?.(currentOffsetTop, isFixed.value)
}
}
Expand Down
10 changes: 9 additions & 1 deletion packages/varlet-ui/src/sticky/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</var-sticky>

<div class="scroller">
<var-sticky style="margin-top: 100px" offset-top="50px">
<var-sticky style="margin-top: 100px" offset-top="50px" @scroll="handleScroll">
<var-button>50px</var-button>
</var-sticky>
<div class="i"></div>
Expand All @@ -28,6 +28,14 @@ export default defineComponent({
[Sticky.name]: Sticky,
[Button.name]: Button,
},
setup() {
return {
handleScroll(top, isFixed) {
console.log(top)
console.log(isFixed)
},
}
},
})
</script>

Expand Down
3 changes: 3 additions & 0 deletions packages/varlet-ui/src/sticky/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export const props = {
type: Number,
default: 10,
},
onScroll: {
type: Function,
},
}
17 changes: 17 additions & 0 deletions packages/varlet-ui/src/tabs/Tabs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div class="var-tabs"></div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'VarTabs',
})
</script>

<style lang="less">
.var-tabs {
display: flex;
}
</style>
7 changes: 7 additions & 0 deletions packages/varlet-ui/src/tabs/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Tabs = require('../../../cjs/tabs').default
const { render } = require('@testing-library/vue')

test('test tabs', async () => {
const wrapper = render(Tabs)
console.log(wrapper)
})
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions packages/varlet-ui/src/tabs/example/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<var-tabs />
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import Tabs from '..'
export default defineComponent({
name: 'TabsExample',
components: {
[Tabs.name]: Tabs,
},
})
</script>

<style scoped>
.example {
background: antiquewhite;
}
</style>
8 changes: 8 additions & 0 deletions packages/varlet-ui/src/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { App } from 'vue'
import Tabs from './Tabs.vue'

Tabs.install = function (app: App) {
app.component(Tabs.name, Tabs)
}

export default Tabs

0 comments on commit 19e1447

Please sign in to comment.