Skip to content

Commit

Permalink
breaking(react-motions): AtomMotionFn & PresenceMotionFn have an obje…
Browse files Browse the repository at this point in the history
…ct as param
  • Loading branch information
layershifter committed May 29, 2024
1 parent 07d1911 commit 4696308
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "breaking: AtomMotionFn & PresenceMotionFn have an object as param",
"packageName": "@fluentui/react-motions-preview",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export type AtomMotion = {
} & KeyframeEffectOptions;

// @public (undocumented)
export type AtomMotionFn = (element: HTMLElement) => AtomMotion;
export type AtomMotionFn = (params: {
element: HTMLElement;
}) => AtomMotion;

// @public
export function createMotionComponent(motion: AtomMotion | AtomMotionFn): React_2.FC<MotionComponentProps>;
Expand Down Expand Up @@ -95,7 +97,9 @@ export type PresenceMotion = {
};

// @public (undocumented)
export type PresenceMotionFn = (element: HTMLElement) => PresenceMotion;
export type PresenceMotionFn = (params: {
element: HTMLElement;
}) => PresenceMotion;

// (No @packageDocumentation comment for this package)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function createMotionComponent(motion: AtomMotion | AtomMotionFn) {
const element = elementRef.current;

if (element) {
const definition = typeof motion === 'function' ? motion(element) : motion;
const definition = typeof motion === 'function' ? motion({ element }) : motion;
const { keyframes, ...options } = definition;

const animation = animate(element, keyframes, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function createPresenceComponent(motion: PresenceMotion | PresenceMotionF
return;
}

const presenceDefinition = typeof motion === 'function' ? motion(elementRef.current) : motion;
const presenceDefinition = typeof motion === 'function' ? motion({ element: elementRef.current }) : motion;
const { keyframes, ...options } = visible ? presenceDefinition.enter : presenceDefinition.exit;

const animation = animate(elementRef.current, keyframes, {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/react-motions-preview/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type PresenceMotion = {
exit: AtomMotion;
};

export type AtomMotionFn = (element: HTMLElement) => AtomMotion;
export type PresenceMotionFn = (element: HTMLElement) => PresenceMotion;
export type AtomMotionFn = (params: { element: HTMLElement }) => AtomMotion;
export type PresenceMotionFn = (params: { element: HTMLElement }) => PresenceMotion;

export type MotionImperativeRef = {
/** Sets the playback rate of the animation, where 1 is normal speed. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Atoms and presence definitions can be also defined as functions that accept an animated element as an argument. This allows to define more complex animations that depend on the animated element's properties, for example:
Atoms and presence definitions can be also defined as functions that have `params` as argument (includes an animated element). This allows to define more complex animations that depend on the animated element's properties, for example:

```ts
const Grow = createMotionComponent(element => ({
const Grow = createMotionComponent(({ element }) => ({
duration: 300,
keyframes: [
{ opacity: 0, maxHeight: `${element.scrollHeight / 2}px` },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const useClasses = makeStyles({
description: { margin: '5px' },
});

const collapseMotion: PresenceMotionFn = element => {
const collapseMotion: PresenceMotionFn = ({ element }) => {
const duration = 500;
const keyframes = [
{ opacity: 0, maxHeight: '0px', overflow: 'hidden' },
Expand Down

0 comments on commit 4696308

Please sign in to comment.