Skip to content

Extend motionone's Options interface with exit #12

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

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 {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 @@
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 @@
declare module "solid-js" {
namespace JSX {
interface Directives {
motion: Options
motion: motionone.Options
}
}
}
Expand Down