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

Adds ability to set any props #31

Merged
merged 6 commits into from
May 26, 2019
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: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ cache:
- node_modules
- test/node_modules
node_js:
- '8'
before_script:
- cd test && npm i
- '10'
9 changes: 8 additions & 1 deletion example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ interface Props {
score: number,
}

function handleClick(): void {
console.log('click!');
}

const AppComponent = ({ diff, score }: Props) =>
<div className='App'>
<AnimateOnChange
baseClassName='Score'
animationClassName='Score--bounce'
animate={diff !== 0}>
animate={diff !== 0}
id="example-id"
onClick={handleClick}
>
Score: {score}
</AnimateOnChange>
</div>
Expand Down
27 changes: 19 additions & 8 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface AnimateOnChange {
* @prop {string} animationClassName - Class added when `animate == true`.
* @prop {bool} animate - Wheter to animate component.
*/
class AnimateOnChange extends Component<Props, State> implements AnimateOnChange {
class AnimateOnChange extends Component<Props & any, State> implements AnimateOnChange {
constructor (props: Props) {
super(props)
this.state = { animating: false, clearAnimationClass: false }
Expand Down Expand Up @@ -116,16 +116,27 @@ class AnimateOnChange extends Component<Props, State> implements AnimateOnChange
}

render () {
let className = this.props.baseClassName

if (this.props.animate && !this.state.clearAnimationClass) {
className += ` ${this.props.animationClassName}`
const { clearAnimationClass } = this.state;
const {
baseClassName,
animate,
animationClassName,
customTag,
children,
onAnimationEnd, // unpack, such that otherProps does not contain it
...otherProps
} = this.props;

let className = baseClassName

if (animate && !clearAnimationClass) {
className += ` ${animationClassName}`
}

let Tag = this.props.customTag || 'span';
let Tag = customTag || 'span';

return <Tag ref={this.setElementRef} className={className}>
{this.props.children}
return <Tag ref={this.setElementRef} className={className} {...otherProps}>
{children}
</Tag>
}
}
Expand Down
Loading