Skip to content

Commit

Permalink
Merge pull request #69 from tmg0/feat/better-type
Browse files Browse the repository at this point in the history
Feat/better type
  • Loading branch information
tmg0 authored May 27, 2024
2 parents 06eb5c9 + 56f0ceb commit d61a4a3
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 141 deletions.
15 changes: 1 addition & 14 deletions src/components/hero-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { type ExtractPropTypes, type PropType, defineComponent, ref } from 'vue'
import { type HeroContext, useProvideHeroContext } from '../composables/use-hero-context'

interface Transition {
delay: number
repeat: number
repeatDelay: number
repeatType: 'loop' | 'mirror' | 'reverse'
type: 'spring' | 'keyframes'
stiffness: number
damping: number
mass: number
bounce: number
duration: number
ease: string
}
import type { Transition } from '../types'

const props = {
transition: { type: Object as PropType<Partial<Transition>>, default: undefined },
Expand Down
125 changes: 1 addition & 124 deletions src/components/hero.tsx
Original file line number Diff line number Diff line change
@@ -1,129 +1,6 @@
import { type ExtractPropTypes, type PropType, defineComponent, ref } from 'vue'
import { useHero } from '../composables/use-hero'

interface Transition {
delay: number
repeat: number
repeatDelay: number
repeatType: 'loop' | 'mirror' | 'reverse'
type: 'spring' | 'keyframes'
stiffness: number
damping: number
mass: number
bounce: number
duration: number
ease: string
}

type HTMLTag =
| 'a'
| 'abbr'
| 'address'
| 'area'
| 'article'
| 'aside'
| 'audio'
| 'b'
| 'base'
| 'bdi'
| 'bdo'
| 'blockquote'
| 'body'
| 'br'
| 'button'
| 'canvas'
| 'caption'
| 'cite'
| 'code'
| 'col'
| 'colgroup'
| 'data'
| 'datalist'
| 'dd'
| 'del'
| 'details'
| 'dfn'
| 'dialog'
| 'div'
| 'dl'
| 'dt'
| 'em'
| 'embed'
| 'fieldset'
| 'figcaption'
| 'figure'
| 'footer'
| 'form'
| 'h1'
| 'h2'
| 'h3'
| 'h4'
| 'h5'
| 'h6'
| 'head'
| 'header'
| 'hr'
| 'html'
| 'i'
| 'iframe'
| 'img'
| 'input'
| 'ins'
| 'kbd'
| 'label'
| 'legend'
| 'li'
| 'link'
| 'main'
| 'map'
| 'mark'
| 'meta'
| 'meter'
| 'nav'
| 'noscript'
| 'object'
| 'ol'
| 'optgroup'
| 'option'
| 'output'
| 'p'
| 'picture'
| 'pre'
| 'progress'
| 'q'
| 'rp'
| 'rt'
| 'ruby'
| 's'
| 'samp'
| 'script'
| 'section'
| 'select'
| 'small'
| 'source'
| 'span'
| 'strong'
| 'style'
| 'sub'
| 'summary'
| 'sup'
| 'table'
| 'tbody'
| 'td'
| 'template'
| 'textarea'
| 'tfoot'
| 'th'
| 'thead'
| 'time'
| 'title'
| 'tr'
| 'track'
| 'u'
| 'ul'
| 'var'
| 'video'
| 'wbr'
import type { HTMLTag, Transition } from '../types'

const props = {
as: { type: String as PropType<HTMLTag>, default: 'div' },
Expand Down
8 changes: 5 additions & 3 deletions src/composables/use-hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { defu } from 'defu'
import omit from 'lodash.omit'
import type { HeroProps } from '../components/hero'
import { useHeroContext } from '../composables/use-hero-context'
import type { Transition } from '../types'

export type UseHeroProps = Omit<HeroProps, 'as'>

export const defaultTransition = {
type: 'keyframes',
duration: 300,
type: 'spring',
stiffness: 600,
damping: 35,
}

export function useHero(domRef: Ref<any>, props: UseHeroProps) {
Expand Down Expand Up @@ -58,7 +60,7 @@ export function useHero(domRef: Ref<any>, props: UseHeroProps) {

motionInstance = useMotion(domRef, {
initial: omit(initial, props.ignore),
enter: omit(enter, props.ignore),
enter: omit(enter, props.ignore) as Transition,
})
})

Expand Down
133 changes: 133 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
export interface SpringTransition {
delay: number
repeat: number
repeatDelay: number
repeatType: 'loop' | 'mirror' | 'reverse'
type: 'spring'
stiffness: number
damping: number
mass: number
bounce: number
ease: string
}

export interface KeyframesTransition {
delay: number
repeat: number
repeatDelay: number
repeatType: 'loop' | 'mirror' | 'reverse'
type: 'keyframes'
duration: number
}

export type Transition = SpringTransition | KeyframesTransition

export type HTMLTag =
| 'a'
| 'abbr'
| 'address'
| 'area'
| 'article'
| 'aside'
| 'audio'
| 'b'
| 'base'
| 'bdi'
| 'bdo'
| 'blockquote'
| 'body'
| 'br'
| 'button'
| 'canvas'
| 'caption'
| 'cite'
| 'code'
| 'col'
| 'colgroup'
| 'data'
| 'datalist'
| 'dd'
| 'del'
| 'details'
| 'dfn'
| 'dialog'
| 'div'
| 'dl'
| 'dt'
| 'em'
| 'embed'
| 'fieldset'
| 'figcaption'
| 'figure'
| 'footer'
| 'form'
| 'h1'
| 'h2'
| 'h3'
| 'h4'
| 'h5'
| 'h6'
| 'head'
| 'header'
| 'hr'
| 'html'
| 'i'
| 'iframe'
| 'img'
| 'input'
| 'ins'
| 'kbd'
| 'label'
| 'legend'
| 'li'
| 'link'
| 'main'
| 'map'
| 'mark'
| 'meta'
| 'meter'
| 'nav'
| 'noscript'
| 'object'
| 'ol'
| 'optgroup'
| 'option'
| 'output'
| 'p'
| 'picture'
| 'pre'
| 'progress'
| 'q'
| 'rp'
| 'rt'
| 'ruby'
| 's'
| 'samp'
| 'script'
| 'section'
| 'select'
| 'small'
| 'source'
| 'span'
| 'strong'
| 'style'
| 'sub'
| 'summary'
| 'sup'
| 'table'
| 'tbody'
| 'td'
| 'template'
| 'textarea'
| 'tfoot'
| 'th'
| 'thead'
| 'time'
| 'title'
| 'tr'
| 'track'
| 'u'
| 'ul'
| 'var'
| 'video'
| 'wbr'

0 comments on commit d61a4a3

Please sign in to comment.