forked from vitest-dev/vitest
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added 'as' prop to renderable components (vitest-dev#742)
- Loading branch information
Showing
9 changed files
with
41 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { h, ref, defineComponent, reactive } from 'vue-demi' | ||
import { useElementBounding } from '@vueuse/core' | ||
import { ResizeObserverOptions } from '../useResizeObserver' | ||
import { RenderableComponent } from '../types' | ||
|
||
export const UseElementBounding = defineComponent<ResizeObserverOptions>({ | ||
export const UseElementBounding = defineComponent<ResizeObserverOptions & RenderableComponent>({ | ||
name: 'UseElementBounding', | ||
props: ['box'] as unknown as undefined, | ||
props: ['box', 'as'] as unknown as undefined, | ||
setup(props, { slots }) { | ||
const target = ref() | ||
const data = reactive(useElementBounding(target, props)) | ||
const data = reactive(useElementBounding(target, { box: props.box, window: props.window })) | ||
|
||
return () => { | ||
if (slots.default) | ||
return h('div', { ref: target }, slots.default(data)) | ||
return h(props.as || 'div', { ref: target }, slots.default(data)) | ||
} | ||
}, | ||
}) |
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { h, ref, defineComponent, reactive } from 'vue-demi' | ||
import { useFullscreen } from '@vueuse/core' | ||
import { RenderableComponent } from '../types' | ||
|
||
export const UseFullscreen = defineComponent({ | ||
export const UseFullscreen = defineComponent<RenderableComponent>({ | ||
name: 'UseFullscreen', | ||
props: ['as'] as unknown as undefined, | ||
setup(props, { slots }) { | ||
const target = ref() | ||
const data = reactive(useFullscreen(target)) | ||
|
||
return () => { | ||
if (slots.default) | ||
return h('div', { ref: target }, slots.default(data)) | ||
return h(props.as || 'div', { ref: target }, slots.default(data)) | ||
} | ||
}, | ||
}) |
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,16 +1,17 @@ | ||
import { h, ref, defineComponent, reactive } from 'vue-demi' | ||
import { useMouseInElement, MouseInElementOptions } from '@vueuse/core' | ||
import { RenderableComponent } from '../types' | ||
|
||
export const UseMouseInElement = defineComponent<MouseInElementOptions>({ | ||
export const UseMouseInElement = defineComponent<MouseInElementOptions & RenderableComponent>({ | ||
name: 'UseMouseElement', | ||
props: ['handleOutside'] as unknown as undefined, | ||
props: ['handleOutside', 'as'] as unknown as undefined, | ||
setup(props, { slots }) { | ||
const target = ref() | ||
const data = reactive(useMouseInElement(target, props)) | ||
|
||
return () => { | ||
if (slots.default) | ||
return h('div', { ref: target }, slots.default(data)) | ||
return h(props.as || 'div', { ref: target }, slots.default(data)) | ||
} | ||
}, | ||
}) |
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,16 +1,17 @@ | ||
import { h, ref, defineComponent, reactive } from 'vue-demi' | ||
import { useMousePressed, MousePressedOptions } from '@vueuse/core' | ||
import { RenderableComponent } from '../types' | ||
|
||
export const UseMousePressed = defineComponent<Omit<MousePressedOptions, 'target'>>({ | ||
export const UseMousePressed = defineComponent<Omit<MousePressedOptions, 'target'> & RenderableComponent>({ | ||
name: 'UseMousePressed', | ||
props: ['touch', 'initialValue'] as unknown as undefined, | ||
props: ['touch', 'initialValue', 'as'] as unknown as undefined, | ||
setup(props, { slots }) { | ||
const target = ref() | ||
const data = reactive(useMousePressed({ ...props, target })) | ||
|
||
return () => { | ||
if (slots.default) | ||
return h('div', { ref: target }, slots.default(data)) | ||
return h(props.as || 'div', { ref: target }, slots.default(data)) | ||
} | ||
}, | ||
}) |