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

Remove translateStyle function and export #82

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { deepEqual } from 'fast-equals';
import createAnimateManager from './AnimateManager';
import { configEasing } from './easing';
import configUpdate from './configUpdate';
import { getTransitionVal, identity, translateStyle } from './util';
import { getTransitionVal, identity } from './util';

class Animate extends PureComponent {
constructor(props, context) {
Expand Down Expand Up @@ -254,7 +254,7 @@ class Animate extends PureComponent {
} = this.props;
const count = Children.count(children);
// eslint-disable-next-line react/destructuring-assignment
const stateStyle = translateStyle(this.state.style);
const stateStyle = this.state.style;

if (typeof children === 'function') {
return children(stateStyle);
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Animate from './Animate';
import { configBezier, configSpring } from './easing';
import { translateStyle } from './util';
import AnimateGroup from './AnimateGroup';

export { configSpring, configBezier, AnimateGroup, translateStyle };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this export will break when recharts imports it: https://github.com/recharts/recharts/blob/master/src/component/Tooltip.tsx#L5

which is why I would do a major release.

export { configSpring, configBezier, AnimateGroup };

export default Animate;
54 changes: 0 additions & 54 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint no-console: 0 */
const PREFIX_LIST = ['Webkit', 'Moz', 'O', 'ms'];
const IN_LINE_PREFIX_LIST = ['-webkit-', '-moz-', '-o-', '-ms-'];
const IN_COMPATIBLE_PROPERTY = ['transform', 'transformOrigin', 'transition'];

export const getIntersectionKeys = (preObj, nextObj) =>
[Object.keys(preObj), Object.keys(nextObj)].reduce((a, b) => a.filter(c => b.includes(c)));
Expand All @@ -14,31 +11,6 @@ export const identity = param => param;
*/
export const getDashCase = name => name.replace(/([A-Z])/g, v => `-${v.toLowerCase()}`);

/*
* @description: add compatible style prefix
* (string, string) => object
*/
export const generatePrefixStyle = (name, value) => {
if (IN_COMPATIBLE_PROPERTY.indexOf(name) === -1) {
return { [name]: Number.isNaN(value) ? 0 : value };
}

const isTransition = name === 'transition';
const camelName = name.replace(/(\w)/, v => v.toUpperCase());
let styleVal = value;

return PREFIX_LIST.reduce((result, property, i) => {
if (isTransition) {
styleVal = value.replace(/(transform|transform-origin)/gim, `${IN_LINE_PREFIX_LIST[i]}$1`);
}

return {
...result,
[property + camelName]: styleVal,
};
}, {});
};

export const log = (...args) => {
console.log(...args);
};
Expand Down Expand Up @@ -82,32 +54,6 @@ export const mapObject = (fn, obj) =>
{},
);

/*
* @description: add compatible prefix to style
* object => object
*/
export const translateStyle = style =>
Object.keys(style).reduce(
(res, key) => ({
...res,
...generatePrefixStyle(key, res[key]),
}),
style,
);

export const compose = (...args) => {
if (!args.length) {
return identity;
}

const fns = args.reverse();
// first function can receive multiply arguments
const firstFn = fns[0];
const tailsFn = fns.slice(1);

return (...composeArgs) => tailsFn.reduce((res, fn) => fn(res), firstFn(...composeArgs));
};

export const getTransitionVal = (props, duration, easing) =>
props.map(prop => `${getDashCase(prop)} ${duration}ms ${easing}`).join(',');

Expand Down
20 changes: 2 additions & 18 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import Animate, { translateStyle } from '../src';
import { render } from '@testing-library/react';
import Animate from '../src';

describe('Animate', () => {
it('Should change the style of children', (done) => {
Expand Down Expand Up @@ -96,19 +96,3 @@ describe('Animate', () => {
}, 1400);
});
});

describe('translateStyle', () => {
it('Should get compatible style', () => {
const style = {
transform: 'translateY(20px)',
transition: 'transform .4s ease',
};

const translatedStyle = translateStyle(style);

expect(translatedStyle.WebkitTransform).toEqual('translateY(20px)');
expect(translatedStyle.WebkitTransition).toEqual(
'-webkit-transform .4s ease',
);
});
});
Loading