@@ -8,24 +8,14 @@ import {
88} from "vue" ;
99import {
1010 unrefElement ,
11- type MaybeComputedElementRef ,
11+ type MaybeElementOrSelectorRef ,
1212} from "../utils/unrefElement.js" ;
1313
14- /**
15- * Template ref objects for Vue elements used by the Adhesive composable.
16- */
17- export interface UseAdhesiveElements {
18- /** Vue template ref or element that should become sticky */
19- target : MaybeComputedElementRef ;
20- /** Optional Vue template ref or element that defines sticky boundaries */
21- bounding ?: MaybeComputedElementRef ;
22- }
23-
24- /**
25- * Configuration options for the `useAdhesive` composable.
26- * Excludes `targetEl` and `boundingEl` since they're provided via template refs.
27- */
28- export type UseAdhesiveOptions = Partial < Omit < AdhesiveOptions , "targetEl" > > ;
14+ export type UseAdhesiveOptions = Partial <
15+ Omit < AdhesiveOptions , "targetEl" | "boundingEl" >
16+ > & {
17+ boundingEl ?: AdhesiveOptions [ "boundingEl" ] | MaybeElementOrSelectorRef ;
18+ } ;
2919
3020/**
3121 * Vue composable for adding sticky positioning behavior to DOM elements.
@@ -34,8 +24,8 @@ export type UseAdhesiveOptions = Partial<Omit<AdhesiveOptions, "targetEl">>;
3424 * handling initialization, updates, and cleanup. It integrates seamlessly
3525 * with Vue's reactivity system and component lifecycle.
3626 *
37- * @param elements - Object containing Vue refs for target and optional bounding elements
38- * @param options - Reactive configuration options for sticky behavior (excluding element references)
27+ * @param target - Vue template ref for the element that should become sticky
28+ * @param options - Reactive configuration options for sticky behavior
3929 *
4030 * @example
4131 * ```vue
@@ -47,8 +37,8 @@ export type UseAdhesiveOptions = Partial<Omit<AdhesiveOptions, "targetEl">>;
4737 * const boundingEl = useTemplateRef('bounding');
4838 *
4939 * useAdhesive(
50- * { target: targetEl, bounding: boundingEl } ,
51- * { position: 'top' }
40+ * targetEl,
41+ * () => ({ boundingEl: boundingEl.value, position: 'top' })
5242 * );
5343 * </script>
5444 *
@@ -70,24 +60,23 @@ export type UseAdhesiveOptions = Partial<Omit<AdhesiveOptions, "targetEl">>;
7060 * const offset = ref(10);
7161 *
7262 * // Reactive options
73- * useAdhesive({ target: targetEl } , () => ({
74- * position: 'top'
63+ * useAdhesive(targetEl, () => ({
64+ * position: 'top',
7565 * enabled: enabled.value,
7666 * offset: offset.value,
7767 * }));
7868 * </script>
7969 * ```
8070 */
8171export function useAdhesive (
82- elements : UseAdhesiveElements ,
72+ target : MaybeElementOrSelectorRef ,
8373 options ?: MaybeRefOrGetter < UseAdhesiveOptions > ,
8474) {
8575 function getValidatedOptions ( ) {
8676 const optionsValue = toValue ( options ) ;
8777
88- const targetEl = unrefElement ( elements . target ) ;
89- const boundingEl =
90- unrefElement ( elements . bounding ) ?? optionsValue ?. boundingEl ;
78+ const targetEl = unrefElement ( target ) ;
79+ const boundingEl = unrefElement ( optionsValue ?. boundingEl ) ;
9180
9281 if ( ! targetEl ) {
9382 throw new Error ( "@adhesivejs/vue: sticky element is not defined" ) ;
0 commit comments