-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
affects: @varlet/ui
- Loading branch information
Showing
22 changed files
with
627 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<template> | ||
<div | ||
class="var-swipe-item" | ||
:style="{ | ||
width: !vertical ? `${size}px` : null, | ||
height: vertical ? `${size}px` : null, | ||
transform: `translate${vertical ? 'Y' : 'X'}(${translate}px)`, | ||
}" | ||
v-bind="$attrs" | ||
> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref, Ref } from 'vue' | ||
import { useAtParentIndex, useParent } from '../utils/components' | ||
import { SWIPE_BIND_SWIPE_ITEM_KEY, SWIPE_COUNT_SWIPE_ITEM_KEY, SwipeProvider } from '../swipe/provide' | ||
import { SwipeItemProvider } from './provide' | ||
export default defineComponent({ | ||
name: 'VarSwipeItem', | ||
inheritAttrs: false, | ||
setup() { | ||
const { bindParent: bindSwipe, parentProvider: swipeProvider } = useParent<SwipeProvider, SwipeItemProvider>( | ||
SWIPE_BIND_SWIPE_ITEM_KEY | ||
) | ||
const { index } = useAtParentIndex(SWIPE_COUNT_SWIPE_ITEM_KEY) | ||
if (!bindSwipe || !swipeProvider || !index) { | ||
throw Error('<var-swipe-item/> must in <var-swipe/>') | ||
} | ||
const translate: Ref<number> = ref(0) | ||
const setTranslate = (x: number) => { | ||
translate.value = x | ||
} | ||
const { size, vertical } = swipeProvider | ||
const swipeItemProvider: SwipeItemProvider = { | ||
index, | ||
setTranslate, | ||
} | ||
bindSwipe(swipeItemProvider) | ||
return { | ||
size, | ||
vertical, | ||
translate, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="less"> | ||
@import './swipeItem'; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const SwipeItem = require('../../../cjs/swipe-item').default | ||
const { render } = require('@testing-library/vue') | ||
|
||
test('test swipeItem', async () => { | ||
const wrapper = render(SwipeItem) | ||
console.log(wrapper) | ||
}) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<var-swipe-item /> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import SwipeItem from '..' | ||
export default defineComponent({ | ||
name: 'SwipeItemExample', | ||
components: { | ||
[SwipeItem.name]: SwipeItem, | ||
}, | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
.example { | ||
background: antiquewhite; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { App } from 'vue' | ||
import SwipeItem from './SwipeItem.vue' | ||
|
||
SwipeItem.install = function (app: App) { | ||
app.component(SwipeItem.name, SwipeItem) | ||
} | ||
|
||
export default SwipeItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ComputedRef } from 'vue' | ||
|
||
export interface SwipeItemProvider { | ||
index: ComputedRef<number> | ||
setTranslate(x: number): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.var-swipe-item { | ||
flex-shrink: 0; | ||
width: 100%; | ||
height: 100%; | ||
} |
Oops, something went wrong.