Skip to content

Commit

Permalink
Merge pull request #12 from solidjs-community/extend-options-type
Browse files Browse the repository at this point in the history
Extend motionone's Options interface with `exit`
  • Loading branch information
thetarnav authored Sep 23, 2024
2 parents 81376f7 + 874b9dc commit 8ddc0e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/presence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
type Accessor,
} from "solid-js"

import type {Options} from "./types.js"

export type PresenceContextState = {
initial: boolean
mount: Accessor<boolean>
Expand Down Expand Up @@ -55,7 +53,7 @@ export const Presence: FlowComponent<{
onExit(el, done) {
batch(() => {
setMount(false)
;(mountedStates.get(el)?.getOptions() as Options).exit
mountedStates.get(el)?.getOptions().exit
? el.addEventListener("motioncomplete", done)
: done()
})
Expand Down
26 changes: 16 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as motionone from "@motionone/dom"
import type {PropertiesHyphen} from "csstype"
import type {JSX, ParentProps} from "solid-js"

export type VariantDefinition = motionone.VariantDefinition
export type {VariantDefinition, Options} from "@motionone/dom"

export interface MotionEventHandlers {
onMotionStart?: (event: motionone.MotionEvent) => void
Expand All @@ -15,19 +15,25 @@ export interface MotionEventHandlers {
onViewLeave?: (event: motionone.ViewEvent) => void
}

/*
Solid style attribute supports only kebab-case properties.
While @motionone/dom supports both camelCase and kebab-case,
but provides only camelCase properties in the types.
*/
declare module "@motionone/dom" {
/*
Solid style attribute supports only kebab-case properties.
While @motionone/dom supports both camelCase and kebab-case,
but provides only camelCase properties in the types.
*/
interface CSSStyleDeclarationWithTransform
extends Omit<PropertiesHyphen, "direction" | "transition"> {}

/*
exit is missing in types in motionone core
because it is only used in the Presence implementations
*/
interface Options {
exit?: motionone.VariantDefinition

Check warning on line 32 in src/types.ts

View workflow job for this annotation

GitHub Actions / Build and Test

Qualifier is unnecessary since 'VariantDefinition' is in scope
}
}

export type Options = motionone.Options & {exit?: VariantDefinition}

export type MotionComponentProps = ParentProps<MotionEventHandlers & Options>
export type MotionComponentProps = ParentProps<MotionEventHandlers & motionone.Options>

export type MotionComponent = {
// <Motion />
Expand All @@ -48,7 +54,7 @@ export type MotionProxy = MotionComponent & {
declare module "solid-js" {
namespace JSX {
interface Directives {
motion: Options
motion: motionone.Options
}
}
}
Expand Down

0 comments on commit 8ddc0e2

Please sign in to comment.