Skip to content

feat!: refactor components and make them consistent #4912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
dbbc913
refactor(UseActiveElement): add props
ilyaliao Jul 24, 2025
61a484f
refactor(UseBattery): enhance component with props and slots support
ilyaliao Jul 27, 2025
5d18600
refactor(UseBrowserLocation): add props and slots support
ilyaliao Jul 27, 2025
bd21313
refactor(UseClipboard): enhance component with props and slots support
ilyaliao Jul 27, 2025
6fd03a7
refactor(OnClickOutside): enhance component with explicit emits type …
ilyaliao Jul 27, 2025
6c25437
refactor(OnLongPress): add explicit emits type definition
ilyaliao Jul 27, 2025
4497e70
refactor(UseActiveElement): enhance component with slots support
ilyaliao Jul 27, 2025
743a7d6
refactor(UseColorMode): enhance component with props and slots support
ilyaliao Jul 27, 2025
705dbfd
refactor(UseDark): enhance component with extended props and slots su…
ilyaliao Jul 27, 2025
5b1a383
refactor(UseDeviceMotion): enhance component with extended props and …
ilyaliao Jul 27, 2025
e862a6c
refactor(UseDeviceOrientation): enhance component with extended props…
ilyaliao Jul 27, 2025
e5ecaee
refactor(UseDevicePixelRatio): enhance component with extended props …
ilyaliao Jul 27, 2025
13161ed
refactor(UseDevicesList): enhance component with extended props and s…
ilyaliao Jul 27, 2025
6c65e84
refactor(UseDocumentVisibility): enhance component with props and slo…
ilyaliao Jul 27, 2025
bc6ed23
refactor(UseElementBounding): enhance component with extended props a…
ilyaliao Jul 27, 2025
e80ba77
refactor(UseElementSize): enhance component with extended props and s…
ilyaliao Jul 27, 2025
5801189
refactor(UseElementVisibility): enhance component with extended props…
ilyaliao Jul 27, 2025
541294e
refactor(UseEyeDropper): enhance component with extended props and sl…
ilyaliao Jul 27, 2025
79c8924
refactor(UseFullscreen): enhance component with extended props and sl…
ilyaliao Jul 27, 2025
6305838
refactor(UseGeolocation): enhance component with extended props and s…
ilyaliao Jul 27, 2025
3650275
Merge branch 'main' into refactor/components
ilyaliao Jul 28, 2025
5279608
refactor(UseIdle): enhance component with extended props and slots su…
ilyaliao Jul 28, 2025
784a202
refactor(UseImage): enhance component with extended props and slots s…
ilyaliao Jul 28, 2025
751d376
refactor(UseMouse): enhance component with extended props and slots s…
ilyaliao Jul 28, 2025
f941ee3
refactor(UseMouseInElement): enhance component with extended props an…
ilyaliao Jul 28, 2025
3ef1923
refactor(UseMousePressed): enhance component with extended props and …
ilyaliao Jul 29, 2025
c7215d6
refactor(UseNetwork): enhance component with extended props and slots…
ilyaliao Jul 29, 2025
9d34ba3
refactor(UseNow): enhance component with extended props and slots sup…
ilyaliao Jul 29, 2025
b7a9da8
refactor(UseObjectUrl): enhance component with improved props handlin…
ilyaliao Jul 29, 2025
5a4e547
refactor(UseOffsetPagination): enhance component with improved props …
ilyaliao Jul 29, 2025
4c18630
refactor(UseOnline): enhance component with improved props handling a…
ilyaliao Jul 29, 2025
61f1892
refactor(UsePageLeave): enhance component with improved props and slo…
ilyaliao Jul 29, 2025
fc39fcd
refactor(UsePointer): enhance component with extended props and slot …
ilyaliao Jul 29, 2025
3ffacd1
refactor(UsePointerLock): enhance component with extended props and s…
ilyaliao Jul 29, 2025
e2ec90b
refactor(UsePreferredColorScheme): enhance component with extended pr…
ilyaliao Jul 29, 2025
f1db478
refactor(UsePreferredContrast): enhance component with extended props…
ilyaliao Jul 29, 2025
e91e747
refactor(UsePreferredDark): enhance component with extended props and…
ilyaliao Jul 29, 2025
c52c32a
refactor(UsePreferredLanguages): enhance component with extended prop…
ilyaliao Jul 29, 2025
7cb5a95
refactor(UsePreferredReducedMotion): enhance component with extended …
ilyaliao Jul 29, 2025
9beee7a
refactor(UseScreenSafeArea): enhance component with improved props de…
ilyaliao Jul 29, 2025
cba9d7d
refactor(UseTimeAgo): enhance component with extended props definitio…
ilyaliao Jul 29, 2025
31c492c
refactor(UseTimestamp): enhance component with extended props definit…
ilyaliao Jul 29, 2025
56dc85e
refactor(UseVirtualList): enhance component with improved props defin…
ilyaliao Jul 29, 2025
0cb418a
refactor(UseWindowFocus): enhance component with extended props defin…
ilyaliao Jul 29, 2025
3bb6411
refactor(UseWindowSize): enhance component with extended props defini…
ilyaliao Jul 29, 2025
e04b7d5
refactor(UseAsyncValidator): enhance component with extended props de…
ilyaliao Jul 29, 2025
8e2120c
refactor(UseFocusTrap): enhance component with updated props definiti…
ilyaliao Jul 29, 2025
d6e0121
refactor(UseSortable): enhance component with updated props definitio…
ilyaliao Jul 29, 2025
3a9c06f
refactor(UseDraggable): enhance component with updated props definiti…
ilyaliao Jul 29, 2025
69af817
fix(components): incorrect import method
ilyaliao Jul 29, 2025
0544c5b
Merge branch 'main' into refactor/components
ilyaliao Aug 9, 2025
c8c58b0
fix(UseBattery): correct import path
ilyaliao Aug 11, 2025
92a89ac
refactor(OnLongPress): enhance component with slot support
ilyaliao Aug 11, 2025
73bf185
fix(UsePageLeave): pass props to usePageLeave for correct functionality
ilyaliao Aug 11, 2025
8bb176a
refactor(UseScreenSafeArea): enhance component with updated props def…
ilyaliao Aug 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions packages/core/onClickOutside/component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type { RenderableComponent } from '../types'
import type { OnClickOutsideOptions } from './index'
import type { OnClickOutsideOptions, RenderableComponent } from '@vueuse/core'
import { onClickOutside } from '@vueuse/core'
import { defineComponent, h, shallowRef } from 'vue'

export interface OnClickOutsideProps extends RenderableComponent {
options?: Omit<OnClickOutsideOptions, 'controls'>
}
// eslint-disable-next-line ts/consistent-type-definitions
export type OnClickOutsideEmits = {
trigger: (event: Event) => void
}

export const OnClickOutside = /* #__PURE__ */ defineComponent<OnClickOutsideProps>({
name: 'OnClickOutside',
props: ['as', 'options'] as unknown as undefined,
emits: ['trigger'],
setup(props, { slots, emit }) {
export const OnClickOutside = /* #__PURE__ */ defineComponent<
OnClickOutsideProps,
OnClickOutsideEmits
>(
(props, { slots, emit }) => {
const target = shallowRef<HTMLDivElement>()
onClickOutside(target, (e) => {
emit('trigger', e)
Expand All @@ -22,4 +25,9 @@ export const OnClickOutside = /* #__PURE__ */ defineComponent<OnClickOutsideProp
return h(props.as || 'div', { ref: target }, slots.default())
}
},
})
{
name: 'OnClickOutside',
props: ['as', 'options'],
emits: ['trigger'],
},
)
4 changes: 2 additions & 2 deletions packages/core/onClickOutside/directive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OnClickOutsideHandler, OnClickOutsideOptions } from '@vueuse/core'
import type { Fn } from '@vueuse/shared'
import type { ObjectDirective } from 'vue'
import type { OnClickOutsideHandler, OnClickOutsideOptions } from './index'
import { onClickOutside } from './index'
import { onClickOutside } from '@vueuse/core'

type StopHandle = Fn | { stop: Fn, cancel: Fn, trigger: (event: Event) => void }

Expand Down
4 changes: 2 additions & 2 deletions packages/core/onKeyStroke/directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { OnKeyStrokeOptions } from '@vueuse/core'
import type { ObjectDirective } from 'vue'
import type { OnKeyStrokeOptions } from './index'
import { onKeyStroke } from './index'
import { onKeyStroke } from '@vueuse/core'

type BindingValueFunction = (event: KeyboardEvent) => void

Expand Down
38 changes: 27 additions & 11 deletions packages/core/onLongPress/component.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
import type { RenderableComponent } from '../types'
import type { OnLongPressOptions } from './index'
import type { OnLongPressOptions, RenderableComponent, UseOnLongPressReturn } from '@vueuse/core'
import type { SlotsType } from 'vue'
import { onLongPress } from '@vueuse/core'
import { defineComponent, h, shallowRef } from 'vue'
import { onLongPress } from './index'

export interface OnLongPressProps extends RenderableComponent {
options?: OnLongPressOptions
}
// eslint-disable-next-line ts/consistent-type-definitions
export type OnLongPressEmits = {
trigger: (event: PointerEvent) => void
}

interface OnLongPressSlots {
default: (data: UseOnLongPressReturn) => any
}

export const OnLongPress = /* #__PURE__ */ defineComponent<OnLongPressProps>({
name: 'OnLongPress',
props: ['as', 'options'] as unknown as undefined,
emits: ['trigger'],
setup(props, { slots, emit }) {
export const OnLongPress = /* #__PURE__ */ defineComponent<
OnLongPressProps,
OnLongPressEmits,
string,
SlotsType<OnLongPressSlots>
>(
(props, { slots, emit }) => {
const target = shallowRef<HTMLElement>()
onLongPress(
const data = onLongPress(
target,
(e) => {
emit('trigger', e)
},
props.options,
)

return () => {
if (slots.default)
return h(props.as || 'div', { ref: target }, slots.default())
return h(props.as || 'div', { ref: target }, slots.default(data))
}
},
})
{
name: 'OnLongPress',
props: ['as', 'options'],
emits: ['trigger'],
},
)
5 changes: 2 additions & 3 deletions packages/core/onLongPress/directive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { OnLongPressOptions } from '@vueuse/core'
import type { ObjectDirective } from 'vue'
import type { OnLongPressOptions } from './index'

import { onLongPress } from './index'
import { onLongPress } from '@vueuse/core'

type BindingValueFunction = (evt: PointerEvent) => void

Expand Down
2 changes: 2 additions & 0 deletions packages/core/onLongPress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ export function onLongPress(

return stop
}

export type UseOnLongPressReturn = ReturnType<typeof onLongPress>
30 changes: 25 additions & 5 deletions packages/core/useActiveElement/component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import type { UseActiveElementOptions, UseActiveElementReturn } from '@vueuse/core'
import type { Reactive, SlotsType } from 'vue'
import { useActiveElement } from '@vueuse/core'
import { defineComponent, reactive } from 'vue'

export const UseActiveElement = /* #__PURE__ */ defineComponent({
name: 'UseActiveElement',
setup(props, { slots }) {
export interface UseActiveElementProps extends UseActiveElementOptions {}
interface UseActiveElementSlots {
default: (data: Reactive<{ element: UseActiveElementReturn }>) => any
}

export const UseActiveElement = /* #__PURE__ */ defineComponent<
UseActiveElementProps,
Record<string, never>,
string,
SlotsType<UseActiveElementSlots>
>(
(props, { slots }) => {
const data = reactive({
element: useActiveElement(),
element: useActiveElement(props),
})

return () => {
if (slots.default)
return slots.default(data)
}
},
})
{
name: 'UseActiveElement',
props: [
'deep',
'triggerOnRemoval',
'window',
'document',
],
},
)
2 changes: 1 addition & 1 deletion packages/core/useActiveElement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ watch(activeElement, (el) => {
```vue
<template>
<UseActiveElement v-slot="{ element }">
Active element is {{ element.dataset.id }}
Active element is {{ element?.dataset.id }}
</UseActiveElement>
</template>
```
2 changes: 2 additions & 0 deletions packages/core/useActiveElement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ export function useActiveElement<T extends HTMLElement>(

return activeElement
}

export type UseActiveElementReturn = ReturnType<typeof useActiveElement>
23 changes: 19 additions & 4 deletions packages/core/useBattery/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import type { ConfigurableNavigator, UseBatteryReturn } from '@vueuse/core'
import type { Reactive, SlotsType } from 'vue'
import { useBattery } from '@vueuse/core'
import { defineComponent, reactive } from 'vue'

export const UseBattery = /* #__PURE__ */ defineComponent({
name: 'UseBattery',
setup(props, { slots }) {
export interface UseBatteryProps extends ConfigurableNavigator {}
interface UseBatterySlots {
default: (data: Reactive<UseBatteryReturn>) => any
}

export const UseBattery = /* #__PURE__ */ defineComponent<
UseBatteryProps,
Record<string, never>,
string,
SlotsType<UseBatterySlots>
>(
(props, { slots }) => {
const data = reactive(useBattery(props))

return () => {
if (slots.default)
return slots.default(data)
}
},
})
{
name: 'UseBattery',
props: ['navigator'],
},
)
25 changes: 20 additions & 5 deletions packages/core/useBrowserLocation/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import type { ConfigurableWindow, UseBrowserLocationReturn } from '@vueuse/core'
import type { Reactive, SlotsType } from 'vue'
import { useBrowserLocation } from '@vueuse/core'
import { defineComponent, reactive } from 'vue'

export const UseBrowserLocation = /* #__PURE__ */ defineComponent({
name: 'UseBrowserLocation',
setup(props, { slots }) {
const data = reactive(useBrowserLocation())
interface UseBrowserLocationProps extends ConfigurableWindow {}
interface UseBrowserLocationSlots {
default: (data: Reactive<UseBrowserLocationReturn>) => any
}

export const UseBrowserLocation = /* #__PURE__ */ defineComponent<
UseBrowserLocationProps,
Record<string, never>,
string,
SlotsType<UseBrowserLocationSlots>
>(
(props, { slots }) => {
const data = reactive(useBrowserLocation(props))

return () => {
if (slots.default)
return slots.default(data)
}
},
})
{
name: 'UseBrowserLocation',
props: ['window'],
},
)
2 changes: 1 addition & 1 deletion packages/core/useBrowserLocation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const location = useBrowserLocation()
## Component Usage

```vue
<UseBrowserLocation v-slot="{ location }">
<UseBrowserLocation v-slot="location">
Browser Location: {{ location }}
</UseBrowserLocation>
```
43 changes: 28 additions & 15 deletions packages/core/useClipboard/component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import type { UseClipboardOptions } from '@vueuse/core'
import type { UseClipboardOptions, UseClipboardReturn } from '@vueuse/core'
import type { Reactive, SlotsType } from 'vue'
import { useClipboard } from '@vueuse/core'
import { defineComponent, reactive } from 'vue'

interface UseClipboardProps<Source = string> extends UseClipboardOptions<Source> {}
export interface UseClipboardProps<Source = string> extends UseClipboardOptions<Source> {}
interface UseClipboardSlots {
default: (data: Reactive<UseClipboardReturn<true>>) => any
}

export const UseClipboard = /* #__PURE__ */ defineComponent<UseClipboardProps>({
name: 'UseClipboard',
props: [
'source',
'read',
'navigator',
'copiedDuring',
'legacy',
] as unknown as undefined,

setup(props, { slots }) {
export const UseClipboard = /* #__PURE__ */ defineComponent<
UseClipboardProps,
Record<string, never>,
string,
SlotsType<UseClipboardSlots>
>(
(props, { slots }) => {
const data = reactive(useClipboard(props))

return () => slots.default?.(data)
return () => {
if (slots.default)
return slots.default(data)
}
},
{
name: 'UseClipboard',
props: [
'source',
'read',
'navigator',
'copiedDuring',
'legacy',
],
},
})
)
53 changes: 46 additions & 7 deletions packages/core/useColorMode/component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import type { UseColorModeOptions } from './index'
import type { BasicColorMode, UseColorModeOptions, UseColorModeReturn } from '@vueuse/core'
import type { Reactive, SlotsType } from 'vue'
import { useColorMode } from '@vueuse/core'
import { defineComponent, reactive } from 'vue'
import { useColorMode } from './index'

export const UseColorMode = /* #__PURE__ */ defineComponent<UseColorModeOptions>({
name: 'UseColorMode',
props: ['selector', 'attribute', 'modes', 'onChanged', 'storageKey', 'storage', 'emitAuto'] as unknown as undefined,
setup(props, { slots }) {
export interface UseColorModeProps extends UseColorModeOptions {}
interface UseColorModeSlots {
default: (data: Reactive<{
mode: UseColorModeReturn<BasicColorMode>
system: UseColorModeReturn['system']
store: UseColorModeReturn['store']
}>) => any
}

export const UseColorMode = /* #__PURE__ */ defineComponent<
UseColorModeProps,
Record<string, never>,
string,
SlotsType<UseColorModeSlots>
>(
(props, { slots }) => {
const mode = useColorMode(props)
const data = reactive({
mode,
Expand All @@ -18,4 +31,30 @@ export const UseColorMode = /* #__PURE__ */ defineComponent<UseColorModeOptions>
return slots.default(data)
}
},
})
{
name: 'UseColorMode',
props: [
'attribute',
'deep',
'disableTransition',
'emitAuto',
'eventFilter',
'flush',
'initOnMounted',
'initialValue',
'listenToStorageChanges',
'mergeDefaults',
'modes',
'onChanged',
'onError',
'selector',
'serializer',
'shallow',
'storage',
'storageKey',
'storageRef',
'window',
'writeDefaults',
],
},
)
6 changes: 3 additions & 3 deletions packages/core/useColorMode/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const myColorMode = computed(() => store.value === 'auto' ? system.value : store

```vue
<template>
<UseColorMode v-slot="{ mode }">
<button @click="mode = mode === 'dark' ? 'light' : 'dark'">
Mode {{ mode }}
<UseColorMode v-slot="color">
<button @click="color.mode = color.mode === 'dark' ? 'light' : 'dark'">
Mode {{ color.mode }}
</button>
</UseColorMode>
</template>
Expand Down
Loading