This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
undefined
committed
May 24, 2021
1 parent
18e528c
commit 8bdaee1
Showing
27 changed files
with
1,513 additions
and
1,515 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { Component, ref, defineComponent } from 'vue'; | ||
import useClickAway from '../index'; | ||
export default defineComponent({ | ||
setup() { | ||
const count = ref(0); | ||
const eleRef = ref(null); | ||
useClickAway(eleRef, () => { | ||
count.value++; | ||
}); | ||
return { eleRef, count }; | ||
}, | ||
render(_ctx) { | ||
return ( | ||
<div> | ||
<button ref="eleRef">click away</button> | ||
<div>count:{_ctx.count}</div> | ||
</div> | ||
); | ||
}, | ||
}) as Component; | ||
import { Component, ref, defineComponent } from 'vue'; | ||
import useClickAway from '../index'; | ||
export default defineComponent({ | ||
setup() { | ||
const count = ref(0); | ||
const eleRef = ref(null); | ||
useClickAway(eleRef, () => { | ||
count.value++; | ||
}); | ||
return { eleRef, count }; | ||
}, | ||
render(_ctx) { | ||
return ( | ||
<div> | ||
<button ref="eleRef">click away</button> | ||
<div>count:{_ctx.count}</div> | ||
</div> | ||
); | ||
}, | ||
}) as Component; |
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import useClickAway from '../index'; | ||
import { ref } from 'vue'; | ||
|
||
describe('useClickAway', () => { | ||
test('should work with custom funtion', async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const fn = jest.fn(() => {}); | ||
const eleRef = ref(null); | ||
const wrapRef = ref(null); | ||
let removeListener!: () => void; | ||
const wrapper = mount({ | ||
setup() { | ||
removeListener = useClickAway(eleRef, fn, 'click', wrapRef); | ||
return { eleRef, wrapRef }; | ||
}, | ||
render() { | ||
return ( | ||
<div ref="wrapRef"> | ||
<h1 ref="eleRef"></h1> | ||
<h2>h2</h2> | ||
</div> | ||
); | ||
}, | ||
}); | ||
await wrapper.vm.$nextTick(); | ||
wrapper.find('h1').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(0); | ||
wrapper.find('h2').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
removeListener(); | ||
wrapper.find('h2').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import useClickAway from '../index'; | ||
import { ref } from 'vue'; | ||
|
||
describe('useClickAway', () => { | ||
test('should work with custom funtion', async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const fn = jest.fn(() => {}); | ||
const eleRef = ref(null); | ||
const wrapRef = ref(null); | ||
let removeListener!: () => void; | ||
const wrapper = mount({ | ||
setup() { | ||
removeListener = useClickAway(eleRef, fn, 'click', wrapRef); | ||
return { eleRef, wrapRef }; | ||
}, | ||
render() { | ||
return ( | ||
<div ref="wrapRef"> | ||
<h1 ref="eleRef"></h1> | ||
<h2>h2</h2> | ||
</div> | ||
); | ||
}, | ||
}); | ||
await wrapper.vm.$nextTick(); | ||
wrapper.find('h1').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(0); | ||
wrapper.find('h2').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
removeListener(); | ||
wrapper.find('h2').trigger('click'); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Component, defineComponent } from 'vue'; | ||
import useDraggable from '../index'; | ||
export default defineComponent({ | ||
setup() { | ||
const [targetRef, handleRef, { delta }] = useDraggable({ controlStyle: true }); | ||
return () => { | ||
return ( | ||
<> | ||
<div style="height:100px;width:100px;background: #999;" ref={targetRef}> | ||
<button ref={handleRef}>handle</button> | ||
</div> | ||
<h2>{delta.value.x}</h2> | ||
<h2>{delta.value.y}</h2> | ||
</> | ||
); | ||
}; | ||
}, | ||
}) as Component; | ||
import { Component, defineComponent } from 'vue'; | ||
import useDraggable from '../index'; | ||
export default defineComponent({ | ||
setup() { | ||
const [targetRef, handleRef, { delta }] = useDraggable({ controlStyle: true }); | ||
return () => { | ||
return ( | ||
<> | ||
<div style="height:100px;width:100px;background: #999;" ref={targetRef}> | ||
<button ref={handleRef}>handle</button> | ||
</div> | ||
<h2>{delta.value.x}</h2> | ||
<h2>{delta.value.y}</h2> | ||
</> | ||
); | ||
}; | ||
}, | ||
}) as Component; |
Oops, something went wrong.