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

test(Motion): add tests and codemod #2436

Merged
merged 131 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
acef3e9
feat: init motion presets rfc
saurabhdaware Aug 22, 2024
862e960
docs: add poc video
saurabhdaware Aug 22, 2024
06666b6
docs: add comparison table and pocs
saurabhdaware Aug 23, 2024
21c165a
feat: add gsap poc
saurabhdaware Aug 23, 2024
77b16df
add layout animations poc with blade components
saurabhdaware Aug 28, 2024
05fa0c0
feat: add basic API decision
saurabhdaware Aug 30, 2024
ce42837
feat: add api decisions and memes
saurabhdaware Sep 6, 2024
77576da
feat: add api decisions and memes
saurabhdaware Sep 6, 2024
3c8b5c1
feat: remove unrelated changes
saurabhdaware Sep 6, 2024
025d13a
docs: add morph note
saurabhdaware Sep 6, 2024
d345994
feat: add video example
saurabhdaware Sep 6, 2024
5fb0201
docs: add note for previews
saurabhdaware Sep 6, 2024
2ec3383
docs: add more videos
saurabhdaware Sep 6, 2024
bd02463
fix: images
saurabhdaware Sep 6, 2024
c81dc93
fix: code alignments
saurabhdaware Sep 6, 2024
2bbe74d
docs: fix widths of cols
saurabhdaware Sep 6, 2024
f2c541c
feat: add chat interface demo
saurabhdaware Sep 6, 2024
7dff7ab
typo
saurabhdaware Sep 6, 2024
e1303a8
fix: width of previews
saurabhdaware Sep 6, 2024
eb68a9b
feat: update all token values
saurabhdaware Sep 9, 2024
db90fbc
feat: motion, migrate internal motion tokens
saurabhdaware Sep 9, 2024
5c7740a
fix: ts check
saurabhdaware Sep 10, 2024
0b5d024
fix: ts
saurabhdaware Sep 10, 2024
3da4bac
fix: switch delay
saurabhdaware Sep 10, 2024
4ba8b14
feat: add base entry exit presets
saurabhdaware Sep 13, 2024
6cf035f
fix: example card alignment
saurabhdaware Sep 13, 2024
9f39a33
feat: add stagger component
saurabhdaware Sep 13, 2024
6c4947a
feat: add animateInteractions
saurabhdaware Sep 13, 2024
0f30023
refactor: use common BaseMotionBox
saurabhdaware Sep 16, 2024
a50e563
refactor: move stagger and animateinteraction check
saurabhdaware Sep 16, 2024
6a9d293
fix: durations map
saurabhdaware Sep 16, 2024
cb0b3dd
feat: add morph and scale preset
saurabhdaware Sep 17, 2024
6272811
feat: add Slide
saurabhdaware Sep 17, 2024
cfa5f14
refactor: remove unused code add todo
saurabhdaware Sep 17, 2024
5d8ab61
docs: update animationInteractions docs
saurabhdaware Sep 17, 2024
b83a132
fix: merge
saurabhdaware Sep 17, 2024
d24bcdd
feat: add css bezier function
saurabhdaware Sep 18, 2024
3bd86f8
Merge branch 'master' of github.com:razorpay/blade into rfc/motion-pr…
saurabhdaware Nov 6, 2024
77ba279
feat: add view transitions API note
saurabhdaware Nov 11, 2024
dd5c28d
feat: add view transitions API note
saurabhdaware Nov 11, 2024
0a0c1ff
Merge branch 'master' of github.com:razorpay/blade into rfc/motion-pr…
saurabhdaware Nov 12, 2024
8f7a427
fix: merge conflict
saurabhdaware Nov 12, 2024
4cd0a90
Merge branch 'motion/token-refresh' of github.com:razorpay/blade into…
saurabhdaware Nov 12, 2024
92a3f7f
feat: add controled scale, enhancer animateinteraction
saurabhdaware Nov 12, 2024
98d3948
feat: replace framer-motion imports with motion/react
saurabhdaware Nov 13, 2024
ab25c0a
feat: rename framer motion to motion/react
saurabhdaware Nov 13, 2024
b6628f5
feat: add framer motion name change note in library table
saurabhdaware Nov 15, 2024
3938125
docs: add new open questions and conclusions
saurabhdaware Nov 20, 2024
e9a3672
fix: change misleading scale heading
saurabhdaware Nov 20, 2024
38e4c06
Merge branch 'rfc/motion-presets' of github.com:razorpay/blade into m…
saurabhdaware Nov 20, 2024
37ecd35
Merge branch 'motion/token-refresh' of github.com:razorpay/blade into…
saurabhdaware Nov 20, 2024
84b8b9e
feat: add fade token values
saurabhdaware Nov 22, 2024
0e0b52c
fix(AnimateInteractions): a11y focus issues
saurabhdaware Nov 22, 2024
a2662f1
feat: add token valyes for move
saurabhdaware Nov 25, 2024
384a752
feat: add slide tokens
saurabhdaware Nov 25, 2024
d3a2672
fix: stories
saurabhdaware Nov 25, 2024
f872830
fix: typecheck
saurabhdaware Nov 25, 2024
38e08b2
feat: add refs to components till checkbox
saurabhdaware Nov 26, 2024
3bc8972
feat: add refs till radio
saurabhdaware Nov 26, 2024
0d26f59
feat: migration to ref till typography
saurabhdaware Nov 26, 2024
2589469
feat: add withRef story
saurabhdaware Nov 26, 2024
8ffb206
fix: scale box
saurabhdaware Nov 26, 2024
9bc5564
feat: add basic stories
saurabhdaware Nov 27, 2024
0c06a4c
refactor: docs
saurabhdaware Nov 27, 2024
cd35f30
feat: add shouldUnmountWhenHidden
saurabhdaware Nov 27, 2024
5a006a5
fix: merge conflicts
saurabhdaware Nov 27, 2024
58f9d6f
docs: add docs for other entry/exit presets
saurabhdaware Nov 27, 2024
3fef36f
feat: add stagger documentation
saurabhdaware Nov 28, 2024
c4a3d8b
feat: handle no unmount transitions in stagger
saurabhdaware Nov 28, 2024
14e2eca
Merge branch 'motion/presets' of github.com:razorpay/blade into motio…
saurabhdaware Nov 28, 2024
3218d8c
feat: add dashboard example
saurabhdaware Nov 28, 2024
1650cb8
fix: workspace animation on dashboard recipe
saurabhdaware Nov 28, 2024
15161fb
feat: add slideFromOffset prop
saurabhdaware Nov 28, 2024
ee9fe1b
Merge branch 'motion/presets' of github.com:razorpay/blade into motio…
saurabhdaware Nov 28, 2024
55a3455
feat: add loading screen to dashboard example
saurabhdaware Nov 28, 2024
dd1cb4c
refactor: simplify basemotion
saurabhdaware Nov 28, 2024
fb5f30f
fix: resolve conflicts
saurabhdaware Nov 28, 2024
95ffe21
feat: add slide docs fix
saurabhdaware Nov 28, 2024
05cba3c
docs: minor docs changes
saurabhdaware Nov 28, 2024
a0562a9
feat: add memo for variants object
saurabhdaware Nov 28, 2024
c6b1d98
feat: add installation docs, expose overlay colors
saurabhdaware Nov 29, 2024
6d8287d
fix: focus on animate interactions
saurabhdaware Nov 29, 2024
fec7dd3
feat: merge conflicts
saurabhdaware Nov 29, 2024
f5349f9
docs: remove docs page of recipes
saurabhdaware Nov 29, 2024
b01618d
fix: scale performance
saurabhdaware Nov 29, 2024
37a9103
fix: ts
saurabhdaware Nov 29, 2024
5ee41eb
feat: add basic intro page for motion
saurabhdaware Nov 29, 2024
6bfabb7
docs: finish motion intro docs
saurabhdaware Dec 1, 2024
4df5d9d
feat: add tests for basic components
saurabhdaware Dec 1, 2024
73d5e3a
tests: update snapshots
saurabhdaware Dec 1, 2024
325e776
feat: add interaction tests
saurabhdaware Dec 2, 2024
6b82480
feat: add codemod
saurabhdaware Dec 2, 2024
5e86016
feat: add basic upgrade guide info
saurabhdaware Dec 2, 2024
1f96b36
fix: resolve anurag's comments
saurabhdaware Dec 2, 2024
c9d3e7c
feat: add comments for getOuterMotionRef
saurabhdaware Dec 2, 2024
0253405
feat: add delay prop
saurabhdaware Dec 2, 2024
3f0ec89
feat: merge presets branch
saurabhdaware Dec 2, 2024
47f3a14
fix: types
saurabhdaware Dec 2, 2024
09c5e7b
fix: stagger type
saurabhdaware Dec 2, 2024
4524053
Merge branch 'motion/presets' of github.com:razorpay/blade into motio…
saurabhdaware Dec 3, 2024
c4615cb
feat: support framer-motion v4
saurabhdaware Dec 3, 2024
decca47
fix: merge presets branch
saurabhdaware Dec 3, 2024
6dd6414
feat: add version upgrade guide
saurabhdaware Dec 4, 2024
a910370
feat: add jsdoc, pass down boxProps to stagger
saurabhdaware Dec 4, 2024
2a51f03
feat: reuse motion installation mdx
saurabhdaware Dec 4, 2024
ddfe24c
Merge branch 'motion/docs' of github.com:razorpay/blade into motion/t…
saurabhdaware Dec 4, 2024
dea5264
fix: basemotion mock
saurabhdaware Dec 4, 2024
cb3de60
fix: motion/react instances
saurabhdaware Dec 4, 2024
7b678d3
fix: native test
saurabhdaware Dec 4, 2024
f9e84b9
fix: transitions on card
saurabhdaware Dec 4, 2024
1f30f60
fix: snapshot for card
saurabhdaware Dec 4, 2024
c77a7d9
fix: lint issues
saurabhdaware Dec 5, 2024
eaab977
fix: typecheck
saurabhdaware Dec 5, 2024
7fd2b8d
fix: lint
saurabhdaware Dec 5, 2024
5a984ca
fix: regex lint
saurabhdaware Dec 5, 2024
1430ac3
fix: text lint
saurabhdaware Dec 5, 2024
ee905a9
feat: add borderRadius and backgroundColor morph support
saurabhdaware Dec 5, 2024
bf4017c
feat: add note for morph
saurabhdaware Dec 5, 2024
7a808e2
fix: conflicts
saurabhdaware Dec 6, 2024
aee5c71
fix: slide test
saurabhdaware Dec 6, 2024
a01ba30
upgrade guide cleanup
saurabhdaware Dec 6, 2024
7a0ad8a
heading level cleanup in upgrade guide
saurabhdaware Dec 6, 2024
e636d6e
fix: button morph example
saurabhdaware Dec 6, 2024
8f36d3e
fix: morph showcase
saurabhdaware Dec 6, 2024
23821fc
feat: add lazy motion
saurabhdaware Dec 6, 2024
7296539
Merge branch 'motion/docs' of github.com:razorpay/blade into motion/t…
saurabhdaware Dec 9, 2024
263ab4e
fix: conflict
saurabhdaware Dec 9, 2024
add73de
fix: merge motion/docs
saurabhdaware Dec 9, 2024
7cbdb75
fix: conflict
saurabhdaware Dec 9, 2024
4011e94
fix: typecheck
saurabhdaware Dec 9, 2024
c301980
fix: native snapshots
saurabhdaware Dec 9, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { applyTransform } from '@hypermod/utils';
import transformer from '..';

it('should update token for dashboard sidebar example', async () => {
const result = await applyTransform(
transformer,
`
export const SidebarContainer = styled.div<SidebarContainerProps>(
({ theme, isRTUXHomepage, isVisible, isMobile }) => \`
display: flex;
flex-direction: column;
position: fixed;
top: 0;
bottom: 0;
background-color: \${
isRTUXHomepage
? isMobile
? theme.colors.surface.background.cloud.subtle
: 'transparent'
: '#2e3345'
};
transform: translate(-100%,0);
transition: transform \${makeMotionTime(theme.motion.delay.short)} \${
theme.motion.easing.standard.effective
};
\`);
`,
{ parser: 'tsx' },
);

expect(result).toMatchInlineSnapshot(`
"export const SidebarContainer = styled.div<SidebarContainerProps>(
({ theme, isRTUXHomepage, isVisible, isMobile }) => \`
display: flex;
flex-direction: column;
position: fixed;
top: 0;
bottom: 0;
background-color: \${
isRTUXHomepage
? isMobile
? theme.colors.surface.background.cloud.subtle
: 'transparent'
: '#2e3345'
};
transform: translate(-100%,0);
transition: transform \${makeMotionTime(theme.motion.delay.short)} \${
theme.motion.easing.standard
};
\`);"
`);
});

it('should update token when used as prop', async () => {
const result = await applyTransform(
transformer,
`
function App() {
const { theme } = useTheme();

return <Box easing={theme.motion.easing.standard.wary} />
}
`,
{ parser: 'tsx' },
);

expect(result).toMatchInlineSnapshot(`
"function App() {
const { theme } = useTheme();

return <Box easing={theme.motion.easing.shake} />
}"
`);
});

it('should update token as used in X payroll', async () => {
const result = await applyTransform(
transformer,
`
export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => {
return css\`
animation: \${entry} \${makeMotionTime(theme.motion.duration['2xgentle'])}
\${theme.motion.easing.entrance.revealing} forwards;
animation-delay: \${delay}ms;
opacity: 0;
\`;
});
`,
{ parser: 'tsx' },
);

expect(result).toMatchInlineSnapshot(`
"export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => {
return css\`
animation: \${entry} \${makeMotionTime(theme.motion.duration['2xgentle'])}
\${theme.motion.easing.entrance} forwards;
animation-delay: \${delay}ms;
opacity: 0;
\`;
});"
`);
});

it('should update token when variable name is not "theme"', async () => {
const result = await applyTransform(
transformer,
`
export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => {
return css\`
animation: \${entry} \${makeMotionTime(paymentTheme.motion.duration['2xgentle'])}
\${paymentTheme.motion.easing.exit.effective} forwards;
animation-delay: \${delay}ms;
opacity: 0;
\`;
});
`,
{ parser: 'tsx' },
);

expect(result).toMatchInlineSnapshot(`
"export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => {
return css\`
animation: \${entry} \${makeMotionTime(paymentTheme.motion.duration['2xgentle'])}
\${paymentTheme.motion.easing.exit} forwards;
animation-delay: \${delay}ms;
opacity: 0;
\`;
});"
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './migrate-motion';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { FileInfo } from 'jscodeshift';
// eslint-disable-next-line import/extensions
import * as tokenMapping from './motionTokenMapping.json';

const transformer = (file: FileInfo): string => {
// Fairly simple usecases of motion tokens in razorpay files so this works.
// .replace has also worked well during rebranding
// eslint-disable-next-line no-useless-escape
const newSource = file.source.replace(/motion\.easing\.[\w\.]+/g, (matchingToken) => {
const match = Object.entries(tokenMapping).find(
([oldToken, _newToken]) => oldToken === matchingToken,
);

if (match) {
return match[1];
}

return matchingToken;
});

return newSource;
};

export default transformer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"motion.easing.entrance.effective": "motion.easing.entrance",
"motion.easing.standard.effective": "motion.easing.standard",
"motion.easing.exit.effective": "motion.easing.exit",
"motion.easing.entrance.revealing": "motion.easing.entrance",
"motion.easing.standard.revealing": "motion.easing.emphasized",
"motion.easing.exit.revealing": "motion.easing.exit",
"motion.easing.entrance.attentive": "motion.easing.overshoot",
"motion.easing.exit.attentive": "motion.easing.exit",
"motion.easing.standard.wary": "motion.easing.shake"
}
22 changes: 14 additions & 8 deletions packages/blade/docs/migration-docs/upgrade-v12.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Blade v12 introduces `motion` (prev `framer-motion`) as peer dependency and requ

- **Step 1:** Upgrade to latest `@razorpay/blade` package in your project
- **Step 2:** [Perform Tokens Changes](#token-changes) using Codemod or manually
- **Step 3:** Setup `motion/react` (or `framer-motion`)
- **Step 3:** [Setup `motion/react` (or `framer-motion`)](#motion-react-framer-motion-setup)

### Token Changes
## Token Changes

We have codemod to help you do the required token changes. You can run the codemod with following command (Replace `./PATH_TO_YOUR_DIR` with glob path of files / directories you want to migrate)-

Expand All @@ -43,26 +43,26 @@ You can skip this if you've run the codemod but in case not or you see some edge

</details>

### Motion React (Framer Motion) Setup
## Motion React (Framer Motion) Setup

> [!IMPORTANT]
>
> `framer-motion` library is now known as `motion/react`
>
> Checkout the [announcement by creator of framer-motion](https://bsky.app/profile/citizenofnowhe.re/post/3lar365ouuk2v)

### Version Compatibility for Consumers already using Framer Motion's Older Version

<details>
<summary>Version Compatibility Note for consumers already using framer-motion with older version</summary>

#### Version Compatibility Note for consumers already using framer-motion with older version

We realised that several projects in razorpay are already using `framer-motion` and are on older versions.
To give some time to consumers to upgrade to framer-motion v11+, we'll be supporting framer-motion v4+ from blade. Although we will be dropping this support in next major version of blade so we recommend planning out framer-motion upgrade in coming quarter.

- **If you're on React 18**, migrating to framer-motion v11 should be fairly simple and low-effort. Checkout [Migrating from framer-motion v4+ to motion/react v11+](#migrating-from-framer-motion-v4-to-motionreact-aka-framer-motion-v11)
- **For projects not on React 18 yet**, do plan out the upgrade soon to make sure future blade upgrades don't become blocker

### Migrating from `framer-motion` v4+ to `motion/react` (aka `framer-motion` v11)
#### Migrating from `framer-motion` v4+ to `motion/react` (aka `framer-motion` v11)

1. Ensure you're on React 18 as `framer-motion` v7 makes React 18 a minimum supported version.
a. [Checkout React 18 upgrade guide](https://react.dev/blog/2022/03/08/react-18-upgrade-guide) or use [React's official codemod for upgrading](https://github.com/reactjs/react-codemod)
Expand All @@ -73,10 +73,12 @@ These are mostly the changes you'll need if you're using core API. But if you're

</details>

- #### Install `motion
### Setting Up Motion in New Projects

- #### Install `motion`

```sh
yarn add `motion` --dev
yarn add motion --dev # or pnpm install motion --save-dev
```

- #### Setup reduced bundle version of `motion/react
Expand Down Expand Up @@ -131,3 +133,7 @@ These are mostly the changes you'll need if you're using core API. But if you're
);
}
```

---

Got stuck somewhere or have some doubts? reach out to `@blade-developers` on `#design-system` channel
3 changes: 1 addition & 2 deletions packages/blade/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import type { ReactElement } from 'react';
import { useCallback, useMemo, useState, cloneElement, Children } from 'react';
import React, { useCallback, useMemo, useState, cloneElement, Children } from 'react';
import type { AccordionContextState } from './AccordionContext';
import { AccordionContext } from './AccordionContext';
import { MAX_WIDTH } from './styles';
Expand Down
Loading
Loading