Skip to content

Commit 83630e3

Browse files
committed
feat(Rotate): refactor Rotate types
1 parent be095d9 commit 83630e3

File tree

5 files changed

+48
-67
lines changed

5 files changed

+48
-67
lines changed

packages/react-components/react-motion-components-preview/library/src/atoms/rotate-atom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface RotateAtomParams {
1212
}
1313

1414
const createRotateValue = (axis: Axis3D, angle: number): string => {
15-
return `${axis} ${angle}deg`;
15+
return `${axis.toLowerCase()} ${angle}deg`;
1616
};
1717

1818
/**
Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,20 @@
11
import { AtomMotion, createPresenceComponent, motionTokens, PresenceMotionFn } from '@fluentui/react-motion';
22
import { fadeAtom } from '../../atoms/fade-atom';
3-
import { rotateAtom, Axis3D } from '../../atoms/rotate-atom';
3+
import { rotateAtom } from '../../atoms/rotate-atom';
4+
import { RotateParams } from './rotate-types';
45

56
/**
6-
* Parameters for configuring the Rotate motion.
7+
* Define a presence motion for rotate in/out
8+
*
9+
* @param duration - Time (ms) for the enter transition (rotate-in). Defaults to the `durationGentle` value.
10+
* @param easing - Easing curve for the enter transition (rotate-in). Defaults to the `curveDecelerateMax` value.
11+
* @param exitDuration - Time (ms) for the exit transition (rotate-out). Defaults to the `duration` param for symmetry.
12+
* @param exitEasing - Easing curve for the exit transition (rotate-out). Defaults to the `curveAccelerateMax` value.
13+
* @param axis - The axis of rotation: 'x', 'y', or 'z'. Defaults to 'y'.
14+
* @param enterAngle - The starting rotation angle in degrees. Defaults to -90.
15+
* @param exitAngle - The ending rotation angle in degrees. Defaults to the negation of `enterAngle`.
16+
* @param animateOpacity - Whether to animate the opacity during the rotation. Defaults to `true`.
717
*/
8-
export type RotateParams = {
9-
/**
10-
* Time (ms) for the enter transition (rotate-in).
11-
* Defaults to `motionTokens.durationGentle`.
12-
*/
13-
duration?: number;
14-
15-
/**
16-
* Easing curve for the enter transition (rotate-in).
17-
* Defaults to `motionTokens.curveDecelerateMax`.
18-
*/
19-
easing?: string;
20-
21-
/**
22-
* Time (ms) for the exit transition (rotate-out).
23-
* Defaults to the value of `duration`.
24-
*/
25-
exitDuration?: number;
26-
27-
/**
28-
* Easing curve for the exit transition (rotate-out).
29-
* Defaults to `motionTokens.curveAccelerateMax`.
30-
*/
31-
exitEasing?: string;
32-
33-
/**
34-
* The axis of rotation: 'X', 'Y', or 'Z'.
35-
* Defaults to 'Y'.
36-
*/
37-
axis?: Axis3D;
38-
39-
/**
40-
* The starting rotation angle in degrees.
41-
* Defaults to -90.
42-
*/
43-
enterAngle?: number;
44-
45-
/**
46-
* The ending rotation angle in degrees.
47-
* Defaults to the negation of `enterAngle`.
48-
*/
49-
exitAngle?: number;
50-
51-
/**
52-
* Whether to animate the opacity during the rotation.
53-
* Defaults to `true`.
54-
*/
55-
animateOpacity?: boolean;
56-
};
57-
5818
const rotatePresenceFn: PresenceMotionFn<RotateParams> = ({
5919
axis = 'y',
6020
enterAngle = -90,
@@ -98,5 +58,5 @@ const rotatePresenceFn: PresenceMotionFn<RotateParams> = ({
9858
};
9959
};
10060

101-
// Create a presence motion component to rotate an element around a single axis (X, Y, or Z).
61+
// Create a presence motion component to rotate an element around a single axis (x, y, or z).
10262
export const Rotate = createPresenceComponent(rotatePresenceFn);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { PresenceDuration, PresenceEasing, AnimateOpacity } from '../../types';
2+
import type { Axis3D } from '../../atoms/rotate-atom';
3+
4+
export type RotateParams = PresenceDuration &
5+
PresenceEasing &
6+
AnimateOpacity & {
7+
/**
8+
* The axis of rotation: 'x', 'y', or 'z'.
9+
* Defaults to 'y'.
10+
*/
11+
axis?: Axis3D;
12+
13+
/**
14+
* The starting rotation angle in degrees.
15+
* Defaults to -90.
16+
*/
17+
enterAngle?: number;
18+
19+
/**
20+
* The ending rotation angle in degrees.
21+
* Defaults to the negation of `enterAngle`.
22+
*/
23+
exitAngle?: number;
24+
};

packages/react-components/react-motion-components-preview/library/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export { Fade, FadeSnappy, FadeRelaxed } from './components/Fade';
33
export { Scale, ScaleSnappy, ScaleRelaxed } from './components/Scale';
44
export { Slide, SlideSnappy, SlideRelaxed } from './components/Slide';
55
export { Blur } from './components/Blur';
6-
export { Rotate, type RotateParams } from './components/Rotate';
6+
export { Rotate } from './components/Rotate';

packages/react-components/react-motion-components-preview/stories/src/Rotate/RotateDefault.stories.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { Field, makeStyles, tokens, Switch, useId, Label, Slider, RadioGroup, Radio } from '@fluentui/react-components';
3-
import { Rotate, RotateParams } from '@fluentui/react-motion-components-preview';
3+
import { Rotate } from '@fluentui/react-motion-components-preview';
4+
import { Axis3D } from '../../../library/src/atoms/rotate-atom';
45

56
// import description from './ExperimentsRotate.stories.md';
67

@@ -10,6 +11,7 @@ const useClasses = makeStyles({
1011
gridTemplate: `"controls ." "card card" / 1fr 1fr`,
1112
gap: '20px 10px',
1213
// perspective: '1000px',
14+
overflow: 'clip',
1315
},
1416
card: {
1517
gridArea: 'card',
@@ -42,14 +44,13 @@ const LoremIpsum = () => (
4244
</>
4345
);
4446

45-
// export const Default = (props: React.PropsWithChildren<typeof Rotate>) => {
46-
export const Default = (props: RotateParams) => {
47+
export const Default = (props: React.ComponentProps<typeof Rotate>) => {
4748
const classes = useClasses();
4849
const [visible, setVisible] = React.useState<boolean>(false);
4950
const [autoplay, setAutoplay] = React.useState<boolean>(false);
5051
const [perspective, setPerspective] = React.useState<string>('1000px');
5152
const [duration, setDuration] = React.useState<number>(500);
52-
const [axis, setAxis] = React.useState<'X' | 'Y' | 'Z'>('Y');
53+
const [axis, setAxis] = React.useState<Axis3D>('y');
5354
const [enterAngle, setEnterAngle] = React.useState<number>(-90);
5455

5556
const perspectiveSliderId = useId();
@@ -92,14 +93,10 @@ export const Default = (props: RotateParams) => {
9293

9394
<Field className={classes.field}>
9495
<Label>Rotation Axis</Label>
95-
<RadioGroup
96-
value={axis}
97-
onChange={(_, data) => setAxis(data.value as 'X' | 'Y' | 'Z')}
98-
layout="horizontal"
99-
>
100-
<Radio value="X" label="X" />
101-
<Radio value="Y" label="Y" />
102-
<Radio value="Z" label="Z" />
96+
<RadioGroup value={axis} onChange={(_, data) => setAxis(data.value as Axis3D)} layout="horizontal">
97+
<Radio value="x" label="x" />
98+
<Radio value="y" label="y" />
99+
<Radio value="z" label="z" />
103100
</RadioGroup>
104101
</Field>
105102

0 commit comments

Comments
 (0)