1 |
|
2 |
|
3 | export const easing = {
|
4 |
|
5 | easeInOut: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
6 |
|
7 |
|
8 | easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)',
|
9 |
|
10 | easeIn: 'cubic-bezier(0.4, 0, 1, 1)',
|
11 |
|
12 | sharp: 'cubic-bezier(0.4, 0, 0.6, 1)'
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 | export const duration = {
|
18 | shortest: 150,
|
19 | shorter: 200,
|
20 | short: 250,
|
21 |
|
22 | standard: 300,
|
23 |
|
24 | complex: 375,
|
25 |
|
26 | enteringScreen: 225,
|
27 |
|
28 | leavingScreen: 195
|
29 | };
|
30 | function formatMs(milliseconds) {
|
31 | return `${Math.round(milliseconds)}ms`;
|
32 | }
|
33 | function getAutoHeightDuration(height) {
|
34 | if (!height) {
|
35 | return 0;
|
36 | }
|
37 | const constant = height / 36;
|
38 |
|
39 |
|
40 | return Math.min(Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10), 3000);
|
41 | }
|
42 | export default function createTransitions(inputTransitions) {
|
43 | const mergedEasing = {
|
44 | ...easing,
|
45 | ...inputTransitions.easing
|
46 | };
|
47 | const mergedDuration = {
|
48 | ...duration,
|
49 | ...inputTransitions.duration
|
50 | };
|
51 | const create = (props = ['all'], options = {}) => {
|
52 | const {
|
53 | duration: durationOption = mergedDuration.standard,
|
54 | easing: easingOption = mergedEasing.easeInOut,
|
55 | delay = 0,
|
56 | ...other
|
57 | } = options;
|
58 | if (process.env.NODE_ENV !== 'production') {
|
59 | const isString = value => typeof value === 'string';
|
60 | const isNumber = value => !Number.isNaN(parseFloat(value));
|
61 | if (!isString(props) && !Array.isArray(props)) {
|
62 | console.error('MUI: Argument "props" must be a string or Array.');
|
63 | }
|
64 | if (!isNumber(durationOption) && !isString(durationOption)) {
|
65 | console.error(`MUI: Argument "duration" must be a number or a string but found ${durationOption}.`);
|
66 | }
|
67 | if (!isString(easingOption)) {
|
68 | console.error('MUI: Argument "easing" must be a string.');
|
69 | }
|
70 | if (!isNumber(delay) && !isString(delay)) {
|
71 | console.error('MUI: Argument "delay" must be a number or a string.');
|
72 | }
|
73 | if (typeof options !== 'object') {
|
74 | console.error(['MUI: Secong argument of transition.create must be an object.', "Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join('\n'));
|
75 | }
|
76 | if (Object.keys(other).length !== 0) {
|
77 | console.error(`MUI: Unrecognized argument(s) [${Object.keys(other).join(',')}].`);
|
78 | }
|
79 | }
|
80 | return (Array.isArray(props) ? props : [props]).map(animatedProp => `${animatedProp} ${typeof durationOption === 'string' ? durationOption : formatMs(durationOption)} ${easingOption} ${typeof delay === 'string' ? delay : formatMs(delay)}`).join(',');
|
81 | };
|
82 | return {
|
83 | getAutoHeightDuration,
|
84 | create,
|
85 | ...inputTransitions,
|
86 | easing: mergedEasing,
|
87 | duration: mergedDuration
|
88 | };
|
89 | } |
\ | No newline at end of file |