|
1 | 1 | import merge from 'lodash.merge';
|
2 |
| -import React, { PureComponent } from 'react'; |
3 |
| -import { getParams } from '../../utils'; |
4 |
| -import { tsParticles } from 'tsparticles'; |
| 2 | +import React, {PureComponent} from 'react'; |
| 3 | +import {getParams} from '../../utils'; |
| 4 | +import {tsParticles} from 'tsparticles'; |
5 | 5 |
|
6 | 6 | interface ParticlesProps {
|
7 |
| - /** |
8 |
| - * Determines wheter to render Particles |
9 |
| - * |
10 |
| - * @default "particles-js" |
11 |
| - */ |
12 |
| - id?: string; |
13 |
| - /** |
14 |
| - * Determines the configuration for Particles JS |
15 |
| - */ |
16 |
| - params: any; |
17 |
| - /** |
18 |
| - * Determines the styles for the Particles container |
19 |
| - * |
20 |
| - * @default {} |
21 |
| - */ |
22 |
| - style?: any; |
23 |
| - /** |
24 |
| - * Determines the width for the Particles container |
25 |
| - * |
26 |
| - * @default "auto" |
27 |
| - */ |
28 |
| - width?: string; |
29 |
| - /** |
30 |
| - * Determines the height for the Particles container |
31 |
| - * |
32 |
| - * @default "100vh" |
33 |
| - */ |
34 |
| - height?: string; |
35 |
| - /** |
36 |
| - * Determines a custom className to apply to Particles container |
37 |
| - */ |
38 |
| - className?: string; |
39 |
| - /** |
40 |
| - * Determines if should merge values from params with lib defaults |
41 |
| - * |
42 |
| - * @default true |
43 |
| - */ |
44 |
| - withDefaults?: boolean; |
| 7 | + /** |
| 8 | + * Determines wheter to render Particles |
| 9 | + * |
| 10 | + * @default "particles-js" |
| 11 | + */ |
| 12 | + id?: string; |
| 13 | + /** |
| 14 | + * Determines the configuration for Particles JS |
| 15 | + */ |
| 16 | + params: any; |
| 17 | + /** |
| 18 | + * Determines the styles for the Particles container |
| 19 | + * |
| 20 | + * @default {} |
| 21 | + */ |
| 22 | + style?: any; |
| 23 | + /** |
| 24 | + * Determines the width for the Particles container |
| 25 | + * |
| 26 | + * @default "auto" |
| 27 | + */ |
| 28 | + width?: string; |
| 29 | + /** |
| 30 | + * Determines the height for the Particles container |
| 31 | + * |
| 32 | + * @default "100vh" |
| 33 | + */ |
| 34 | + height?: string; |
| 35 | + /** |
| 36 | + * Determines a custom className to apply to Particles container |
| 37 | + */ |
| 38 | + className?: string; |
| 39 | + /** |
| 40 | + * Determines if should merge values from params with lib defaults |
| 41 | + * |
| 42 | + * @default true |
| 43 | + */ |
| 44 | + withDefaults?: boolean; |
45 | 45 | }
|
46 | 46 |
|
47 | 47 | export class Particles extends PureComponent<ParticlesProps> {
|
48 |
| - static displayName = 'Particles'; |
| 48 | + static displayName = 'Particles'; |
49 | 49 |
|
50 |
| - static defaultProps = { |
51 |
| - style: {}, |
52 |
| - width: 'auto', |
53 |
| - height: '100vh', |
54 |
| - id: 'particles-js', |
55 |
| - withDefaults: true, |
56 |
| - }; |
| 50 | + static defaultProps = { |
| 51 | + style: {}, |
| 52 | + width: 'auto', |
| 53 | + height: '100vh', |
| 54 | + id: 'particles-js', |
| 55 | + withDefaults: true, |
| 56 | + }; |
57 | 57 |
|
58 |
| - componentDidMount() { |
59 |
| - tsParticles.load(this.props.id ?? "tsparticles", this.getParticles()); |
60 |
| - } |
| 58 | + componentDidMount() { |
| 59 | + tsParticles.load(this.props.id ?? "tsparticles", this.getParticles()); |
| 60 | + } |
61 | 61 |
|
62 |
| - componentDidUpdate(prevProps: ParticlesProps) { |
63 |
| - tsParticles.load(this.props.id ?? "tsparticles", this.getParticles()); |
64 |
| - } |
| 62 | + componentDidUpdate(prevProps: ParticlesProps) { |
| 63 | + tsParticles.load(this.props.id ?? "tsparticles", this.getParticles()); |
| 64 | + } |
65 | 65 |
|
66 |
| - componentWillUnmount() { |
67 |
| - tsParticles.dom().forEach((container) => container.destroy()); |
68 |
| - } |
| 66 | + componentWillUnmount() { |
| 67 | + tsParticles.dom().forEach((container) => container.destroy()); |
| 68 | + } |
69 | 69 |
|
70 |
| - render() { |
71 |
| - const { className, style, width, height, id } = this.props; |
| 70 | + render() { |
| 71 | + const {className, style, width, height, id} = this.props; |
72 | 72 |
|
73 |
| - return ( |
74 |
| - <div |
75 |
| - id={ id } |
76 |
| - className={ className } |
77 |
| - style={ { |
78 |
| - ...style, |
79 |
| - width: width, |
80 |
| - height: height, |
81 |
| - } } |
82 |
| - /> |
83 |
| - ); |
84 |
| - } |
| 73 | + return ( |
| 74 | + <div |
| 75 | + id={id} |
| 76 | + className={className} |
| 77 | + style={{ |
| 78 | + ...style, |
| 79 | + width: width, |
| 80 | + height: height, |
| 81 | + }} |
| 82 | + /> |
| 83 | + ); |
| 84 | + } |
85 | 85 |
|
86 |
| - getParticles = () => { |
87 |
| - if (this.props.withDefaults) { |
88 |
| - return merge({}, getParams(), this.props.params); |
89 |
| - } else { |
90 |
| - return this.props.params; |
91 |
| - } |
92 |
| - }; |
| 86 | + getParticles = () => { |
| 87 | + if (this.props.withDefaults) { |
| 88 | + return merge({}, getParams(), this.props.params); |
| 89 | + } else { |
| 90 | + return this.props.params; |
| 91 | + } |
| 92 | + }; |
93 | 93 | }
|
94 | 94 |
|
95 | 95 | export default Particles;
|
0 commit comments