Skip to content
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

feat(motion): generate <Presence.In> and <Presence.Out> one-way motion components #33930

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
feat(motion): generate <Presence.In> and <Presence.Out> one-way motio…
…n components
  • Loading branch information
robertpenner committed Feb 28, 2025
commit adedefc898952a6ebf5ae07f4abba13c9743c0a3
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import { useIsReducedMotion } from '../hooks/useIsReducedMotion';
import { getChildElement } from '../utils/getChildElement';
import type { MotionParam, PresenceMotion, MotionImperativeRef, PresenceMotionFn, PresenceDirection } from '../types';
import { useMotionBehaviourContext } from '../contexts/MotionBehaviourContext';
import { createMotionComponent, MotionComponentProps } from './createMotionComponent';

/**
* @internal A private symbol to store the motion definition on the component for variants.
@@ -70,6 +71,8 @@ export type PresenceComponentProps = {
export type PresenceComponent<MotionParams extends Record<string, MotionParam> = {}> = {
(props: PresenceComponentProps & MotionParams): React.ReactElement | null;
[MOTION_DEFINITION]: PresenceMotionFn<MotionParams>;
In: React.FC<MotionComponentProps & MotionParams>;
Out: React.FC<MotionComponentProps & MotionParams>;
};

export function createPresenceComponent<MotionParams extends Record<string, MotionParam> = {}>(
@@ -197,5 +200,13 @@ export function createPresenceComponent<MotionParams extends Record<string, Moti
// Always normalize it to a function to simplify types
[MOTION_DEFINITION]: typeof value === 'function' ? value : () => value,
},
{
In: createMotionComponent(
typeof value !== 'function' ? value.enter : (...args: Parameters<typeof value>) => value(...args).enter,
),
Out: createMotionComponent(
typeof value !== 'function' ? value.exit : (...args: Parameters<typeof value>) => value(...args).exit,
),
},
);
}
Loading
Oops, something went wrong.