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

Fix for https://github.com/felippenardi/lottie-react-web/issues/24 #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ Lottie.propTypes = {
ariaRole: PropTypes.string,
ariaLabel: PropTypes.string,
title: PropTypes.string,
style: PropTypes.string,
style: PropTypes.objectOf(PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
])),
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

Expand Down
64 changes: 64 additions & 0 deletions src/stories/StyledLottie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import Lottie from '../index';
import * as animationData from './TwitterHeart.json';

export default class StyledLottie extends React.Component {

constructor(props) {
super(props);

this.state = {
transformInput: 0,
opacityInput: 100,
styles: {},
};
}

handleStyleChanges(cssProperty) {
this.setState(prev => ({
...prev,
styles: {
...prev.styles,
[cssProperty.name]: cssProperty.value,
},
}));
}

render() {
const centerStyle = {
display: 'block',
margin: '10px auto',
textAlign: 'center',
};
const { transformInput, opacityInput } = this.state;
const defaultOptions = { animationData };

return (<div>
<Lottie
options={defaultOptions}
height={400}
width={400}
style={this.state.styles}
/>

<p style={centerStyle}>Rotate: {transformInput}°</p>
<input
style={centerStyle}
type="range" value={transformInput} min="0" max="360" step="5"
onChange={(e) => {
this.setState({ transformInput: e.currentTarget.value });
this.handleStyleChanges({ name: 'transform', value: `rotate(${e.currentTarget.value}deg)` });
}}
/>
<p style={centerStyle}>Opacity: {opacityInput}</p>
<input
style={centerStyle}
type="range" value={opacityInput} min="0" max="100" step="10"
onChange={(e) => {
this.setState({ opacityInput: +e.currentTarget.value });
this.handleStyleChanges({ name: 'opacity', value: +e.currentTarget.value / 100 });
}}
/>
</div>);
}
}
4 changes: 3 additions & 1 deletion src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import LottieControlSegments from './lottie-control-segments';
import ToggleLike from './toggle-like';
import TransitionLoop from './TransitionLoop';
import TransitionWithOptions from './TransitionWithOptions';
import StyledLottie from './StyledLottie';

storiesOf('Lottie Animation View', module)
.add('with control', () => <LottieControl />)
.add('toggle like', () => <ToggleLike />)
.add('transitions & loops', () => <TransitionLoop />)
.add('transitions with options', () => <TransitionWithOptions />)
.add('with segments', () => <LottieControlSegments />);
.add('with segments', () => <LottieControlSegments />)
.add('styling', () => <StyledLottie />);