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
[Material You] Add motion design tokens #35384
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
67f924a
[Material You] Add motion design tokens
mnajdova 6f7f426
Merge branch 'master' into md3/add-motion-tokens
mnajdova 2a2a4d7
Resolve review comments
mnajdova 41a88d4
prettier
mnajdova a90b908
Update packages/mui-material-next/src/styles/CssVarsProvider.tsx
mnajdova ab6bf14
Merge branch 'master' into md3/add-motion-tokens
mnajdova File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { expect } from 'chai'; | ||
import { extendTheme } from '@mui/material-next/styles'; | ||
import createMotion, { easing, duration } from './motion'; | ||
|
||
describe('motion', () => { | ||
const motion = createMotion({}); | ||
const create = motion.create; | ||
const getAutoHeightDuration = motion.getAutoHeightDuration; | ||
|
||
it('should allow to customize the default duration', () => { | ||
const theme = extendTheme({ | ||
sys: { | ||
motion: { | ||
duration: { | ||
medium1: '310ms', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(theme.sys.motion.create('color')).to.equal(`color 310ms ${easing.standard} 0ms`); | ||
}); | ||
|
||
describe('create() function', () => { | ||
describe('warnings', () => { | ||
it('should warn when first argument is of bad type', () => { | ||
expect(() => create(5554)).toErrorDev('MUI: Argument "props" must be a string or Array'); | ||
expect(() => create({})).toErrorDev('MUI: Argument "props" must be a string or Array'); | ||
}); | ||
|
||
it('should warn when bad "duration" option type', () => { | ||
expect(() => create('font', { duration: null })).toErrorDev( | ||
'MUI: Argument "duration" must be a number or a string but found null', | ||
); | ||
expect(() => create('font', { duration: {} })).toErrorDev( | ||
'MUI: Argument "duration" must be a number or a string but found [object Object]', | ||
); | ||
}); | ||
|
||
it('should warn when bad "easing" option type', () => { | ||
expect(() => create('transform', { easing: 123 })).toErrorDev( | ||
'MUI: Argument "easing" must be a string', | ||
); | ||
expect(() => create('transform', { easing: {} })).toErrorDev( | ||
'MUI: Argument "easing" must be a string', | ||
); | ||
}); | ||
|
||
it('should warn when bad "delay" option type', () => { | ||
expect(() => create('size', { delay: null })).toErrorDev( | ||
'MUI: Argument "delay" must be a number or a string', | ||
); | ||
expect(() => create('size', { delay: {} })).toErrorDev( | ||
'MUI: Argument "delay" must be a number or a string', | ||
); | ||
}); | ||
|
||
it('should warn when passed unrecognized option', () => { | ||
expect(() => create('size', { fffds: 'value' })).toErrorDev( | ||
'MUI: Unrecognized argument(s) [fffds]', | ||
); | ||
}); | ||
}); | ||
|
||
it('should create default transition without arguments', () => { | ||
const transition = create(); | ||
expect(transition).to.equal(`all ${duration.medium1} ${easing.standard} 0ms`); | ||
}); | ||
|
||
it('should take string props as a first argument', () => { | ||
const transition = create('color'); | ||
expect(transition).to.equal(`color ${duration.medium1} ${easing.standard} 0ms`); | ||
}); | ||
|
||
it('should also take array of props as first argument', () => { | ||
const options = { delay: 20 }; | ||
const multiple = create(['color', 'size'], options); | ||
const single1 = create('color', options); | ||
const single2 = create('size', options); | ||
const expected = `${single1},${single2}`; | ||
expect(multiple).to.equal(expected); | ||
}); | ||
|
||
it('should optionally accept number "duration" option in second argument', () => { | ||
const transition = create('font', { duration: 500 }); | ||
expect(transition).to.equal(`font 500ms ${easing.standard} 0ms`); | ||
}); | ||
|
||
it('should optionally accept string "duration" option in second argument', () => { | ||
const transition = create('font', { duration: '500ms' }); | ||
expect(transition).to.equal(`font 500ms ${easing.standard} 0ms`); | ||
}); | ||
|
||
it('should round decimal digits of "duration" prop to whole numbers', () => { | ||
const transition = create('font', { duration: 12.125 }); | ||
expect(transition).to.equal(`font 12ms ${easing.standard} 0ms`); | ||
}); | ||
|
||
it('should optionally accept string "easing" option in second argument', () => { | ||
const transition = create('transform', { easing: easing.linear }); | ||
expect(transition).to.equal(`transform ${duration.medium1} ${easing.linear} 0ms`); | ||
}); | ||
|
||
it('should optionally accept number "delay" option in second argument', () => { | ||
const transition = create('size', { delay: 150 }); | ||
expect(transition).to.equal(`size ${duration.medium1} ${easing.standard} 150ms`); | ||
}); | ||
|
||
it('should optionally accept string "delay" option in second argument', () => { | ||
const transition = create('size', { delay: '150ms' }); | ||
expect(transition).to.equal(`size ${duration.medium1} ${easing.standard} 150ms`); | ||
}); | ||
|
||
it('should round decimal digits of "delay" prop to whole numbers', () => { | ||
const transition = create('size', { delay: 1.547 }); | ||
expect(transition).to.equal(`size ${duration.medium1} ${easing.standard} 2ms`); | ||
}); | ||
|
||
it('should return zero when not passed arguments', () => { | ||
const zeroHeightDuration = getAutoHeightDuration(); | ||
expect(zeroHeightDuration).to.equal(0); | ||
}); | ||
|
||
it('should return zero when passed undefined', () => { | ||
const zeroHeightDuration = getAutoHeightDuration(undefined); | ||
expect(zeroHeightDuration).to.equal(0); | ||
}); | ||
|
||
it('should return zero when passed null', () => { | ||
const zeroHeightDuration = getAutoHeightDuration(null); | ||
expect(zeroHeightDuration).to.equal(0); | ||
}); | ||
|
||
it('should return NaN when passed a negative number', () => { | ||
const zeroHeightDurationNegativeOne = getAutoHeightDuration(-1); | ||
// eslint-disable-next-line no-restricted-globals | ||
expect(isNaN(zeroHeightDurationNegativeOne)).to.equal(true); | ||
const zeroHeightDurationSmallNegative = getAutoHeightDuration(-0.000001); | ||
// eslint-disable-next-line no-restricted-globals | ||
expect(isNaN(zeroHeightDurationSmallNegative)).to.equal(true); | ||
const zeroHeightDurationBigNegative = getAutoHeightDuration(-100000); | ||
// eslint-disable-next-line no-restricted-globals | ||
expect(isNaN(zeroHeightDurationBigNegative)).to.equal(true); | ||
}); | ||
|
||
it('should return values for pre-calculated positive examples', () => { | ||
let zeroHeightDuration = getAutoHeightDuration(14); | ||
expect(zeroHeightDuration).to.equal(159); | ||
zeroHeightDuration = getAutoHeightDuration(100); | ||
expect(zeroHeightDuration).to.equal(239); | ||
zeroHeightDuration = getAutoHeightDuration(0.0001); | ||
expect(zeroHeightDuration).to.equal(46); | ||
zeroHeightDuration = getAutoHeightDuration(100000); | ||
expect(zeroHeightDuration).to.equal(6685); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function will be skipped by default, no need to put them here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't know that, alright then I will just not add the
motion
key anywhere :)