|
1 | | -import { Component } from 'react'; |
| 1 | +import { useState } from 'react'; |
2 | 2 | import VisibilitySensor from 'react-visibility-sensor'; |
3 | 3 | import SmallIcon from '../../assets/icon-square-small-slack.png'; |
4 | | -import './Contributors.scss'; |
5 | 4 | import PropTypes from 'prop-types'; |
6 | 5 | import { contributorsNotFound } from './404.js'; |
7 | 6 |
|
8 | | -export default class Contributors extends Component { |
9 | | - static propTypes = { |
10 | | - contributors: PropTypes.array, |
11 | | - }; |
12 | | - state = { |
13 | | - inView: false, |
14 | | - }; |
| 7 | +Contributors.propTypes = { |
| 8 | + contributors: PropTypes.array.isRequired, |
| 9 | +}; |
15 | 10 |
|
16 | | - handleInView = (inView) => { |
| 11 | +Contributor.propTypes = { |
| 12 | + contributor: PropTypes.string.isRequired, |
| 13 | + inView: PropTypes.bool.isRequired, |
| 14 | +}; |
| 15 | +function Contributor({ contributor, inView }) { |
| 16 | + return ( |
| 17 | + <a key={contributor} href={`https://github.com/${contributor}`}> |
| 18 | + <img |
| 19 | + width={45} |
| 20 | + height={45} |
| 21 | + alt={contributor} |
| 22 | + title={contributor} |
| 23 | + className="w-full rounded-full shadow" |
| 24 | + src={ |
| 25 | + inView ? `https://github.com/${contributor}.png?size=90` : SmallIcon |
| 26 | + } |
| 27 | + /> |
| 28 | + </a> |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +export default function Contributors({ contributors }) { |
| 33 | + const [inView, setInView] = useState(false); |
| 34 | + const handleInView = (inView) => { |
17 | 35 | if (!inView) { |
18 | 36 | return; |
19 | 37 | } |
20 | | - this.setState({ inView }); |
| 38 | + setInView(inView); |
21 | 39 | }; |
| 40 | + if (!contributors.length) { |
| 41 | + return <noscript />; |
| 42 | + } |
22 | 43 |
|
23 | | - render() { |
24 | | - const { inView } = this.state; |
25 | | - const { contributors } = this.props; |
26 | | - |
27 | | - if (!contributors.length) { |
28 | | - return <noscript />; |
29 | | - } |
30 | | - |
31 | | - return ( |
32 | | - <VisibilitySensor |
33 | | - delayedCall |
34 | | - partialVisibility |
35 | | - intervalDelay={300} |
36 | | - onChange={this.handleInView} |
37 | | - > |
38 | | - <div className="contributors"> |
39 | | - <div className="contributors__list"> |
40 | | - {contributors |
41 | | - .filter((c) => contributorsNotFound.includes(c) === false) |
42 | | - .map((contributor) => ( |
43 | | - <a |
44 | | - key={contributor} |
45 | | - className="contributor" |
46 | | - href={`https://github.com/${contributor}`} |
47 | | - > |
48 | | - <img |
49 | | - width={45} |
50 | | - height={45} |
51 | | - alt={contributor} |
52 | | - src={ |
53 | | - inView |
54 | | - ? `https://github.com/${contributor}.png?size=90` |
55 | | - : SmallIcon |
56 | | - } |
57 | | - /> |
58 | | - <span className="contributor__name"> {contributor}</span> |
59 | | - </a> |
60 | | - ))} |
61 | | - </div> |
| 44 | + return ( |
| 45 | + <VisibilitySensor |
| 46 | + delayedCall |
| 47 | + partialVisibility |
| 48 | + intervalDelay={300} |
| 49 | + onChange={handleInView} |
| 50 | + > |
| 51 | + <div> |
| 52 | + <div className="grid gap-[10px] lg:gap-[15px] grid-cols-contributors"> |
| 53 | + {contributors |
| 54 | + .filter((c) => contributorsNotFound.includes(c) === false) |
| 55 | + .map((contributor) => ( |
| 56 | + <Contributor |
| 57 | + key={contributor} |
| 58 | + contributor={contributor} |
| 59 | + inView={inView} |
| 60 | + /> |
| 61 | + ))} |
62 | 62 | </div> |
63 | | - </VisibilitySensor> |
64 | | - ); |
65 | | - } |
| 63 | + </div> |
| 64 | + </VisibilitySensor> |
| 65 | + ); |
66 | 66 | } |
0 commit comments