From 1aeb748802774d52d0c3c88715b92606363a502e Mon Sep 17 00:00:00 2001 From: tmg0 Date: Mon, 27 May 2024 10:50:57 +0800 Subject: [PATCH] refactor: use hero context --- src/components/hero-provider.tsx | 2 +- src/{components => composables}/use-hero-context.ts | 2 +- src/composables/use-hero.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/{components => composables}/use-hero-context.ts (85%) diff --git a/src/components/hero-provider.tsx b/src/components/hero-provider.tsx index bf79c1f..ac166e7 100644 --- a/src/components/hero-provider.tsx +++ b/src/components/hero-provider.tsx @@ -1,5 +1,5 @@ import { type ExtractPropTypes, type PropType, defineComponent, ref } from 'vue' -import { type HeroContext, useProvideHeroContext } from './use-hero-context' +import { type HeroContext, useProvideHeroContext } from '../composables/use-hero-context' interface Transition { delay: number diff --git a/src/components/use-hero-context.ts b/src/composables/use-hero-context.ts similarity index 85% rename from src/components/use-hero-context.ts rename to src/composables/use-hero-context.ts index c4207ee..3a48b55 100644 --- a/src/components/use-hero-context.ts +++ b/src/composables/use-hero-context.ts @@ -1,6 +1,6 @@ import { type Ref, inject, provide, ref } from 'vue' import { PROVIDE_CONTEXT } from '../constants' -import type { HeroProviderProps } from './hero-provider' +import type { HeroProviderProps } from '../components/hero-provider' export interface Layout extends Record {} diff --git a/src/composables/use-hero.ts b/src/composables/use-hero.ts index 0715780..d29a063 100644 --- a/src/composables/use-hero.ts +++ b/src/composables/use-hero.ts @@ -4,7 +4,7 @@ import { useElementTransform, useMotion } from '@vueuse/motion' import { defu } from 'defu' import omit from 'lodash.omit' import type { HeroProps } from '../components/hero' -import { useHeroContext } from '../components/use-hero-context' +import { useHeroContext } from '../composables/use-hero-context' export type UseHeroProps = Omit @@ -26,12 +26,12 @@ export function useHero(domRef: Ref, props: UseHeroProps) { const prev = computed({ get() { - if (!props.layoutId) + if (!props.layoutId) return {} return layouts.value[props.layoutId] ?? {} }, set(value) { - if (!props.layoutId) + if (!props.layoutId) return layouts.value[props.layoutId] = value },