Skip to content

Commit

Permalink
Merge pull request #31 from ModPhoenix/add-otherProps
Browse files Browse the repository at this point in the history
Adds ability to set any props
  • Loading branch information
arve0 authored May 26, 2019
2 parents a2d60ec + 671a6d0 commit d7a9a86
Show file tree
Hide file tree
Showing 21 changed files with 2,338 additions and 12,011 deletions.
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

0 comments on commit d7a9a86

Please sign in to comment.