|
1 |
| -import type { RenderableComponent } from '../types' |
2 |
| -import type { OnLongPressOptions } from './index' |
| 1 | +import type { OnLongPressOptions, RenderableComponent, UseOnLongPressReturn } from '@vueuse/core' |
| 2 | +import type { SlotsType } from 'vue' |
| 3 | +import { onLongPress } from '@vueuse/core' |
3 | 4 | import { defineComponent, h, shallowRef } from 'vue'
|
4 |
| -import { onLongPress } from './index' |
5 | 5 |
|
6 | 6 | export interface OnLongPressProps extends RenderableComponent {
|
7 | 7 | options?: OnLongPressOptions
|
8 | 8 | }
|
| 9 | +// eslint-disable-next-line ts/consistent-type-definitions |
| 10 | +export type OnLongPressEmits = { |
| 11 | + trigger: (event: PointerEvent) => void |
| 12 | +} |
| 13 | + |
| 14 | +interface OnLongPressSlots { |
| 15 | + default: (data: UseOnLongPressReturn) => any |
| 16 | +} |
9 | 17 |
|
10 |
| -export const OnLongPress = /* #__PURE__ */ defineComponent<OnLongPressProps>({ |
11 |
| - name: 'OnLongPress', |
12 |
| - props: ['as', 'options'] as unknown as undefined, |
13 |
| - emits: ['trigger'], |
14 |
| - setup(props, { slots, emit }) { |
| 18 | +export const OnLongPress = /* #__PURE__ */ defineComponent< |
| 19 | + OnLongPressProps, |
| 20 | + OnLongPressEmits, |
| 21 | + string, |
| 22 | + SlotsType<OnLongPressSlots> |
| 23 | +>( |
| 24 | + (props, { slots, emit }) => { |
15 | 25 | const target = shallowRef<HTMLElement>()
|
16 |
| - onLongPress( |
| 26 | + const data = onLongPress( |
17 | 27 | target,
|
18 | 28 | (e) => {
|
19 | 29 | emit('trigger', e)
|
20 | 30 | },
|
21 | 31 | props.options,
|
22 | 32 | )
|
| 33 | + |
23 | 34 | return () => {
|
24 | 35 | if (slots.default)
|
25 |
| - return h(props.as || 'div', { ref: target }, slots.default()) |
| 36 | + return h(props.as || 'div', { ref: target }, slots.default(data)) |
26 | 37 | }
|
27 | 38 | },
|
28 |
| -}) |
| 39 | + { |
| 40 | + name: 'OnLongPress', |
| 41 | + props: ['as', 'options'], |
| 42 | + emits: ['trigger'], |
| 43 | + }, |
| 44 | +) |
0 commit comments