The code powering m.abunchtell.com https://m.abunchtell.com
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

103 linhas
2.2 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { autoPlayGif } from '../initial_state';
  5. export default class AvatarComposite extends React.PureComponent {
  6. static propTypes = {
  7. accounts: ImmutablePropTypes.list.isRequired,
  8. animate: PropTypes.bool,
  9. size: PropTypes.number.isRequired,
  10. };
  11. static defaultProps = {
  12. animate: autoPlayGif,
  13. };
  14. renderItem (account, size, index) {
  15. const { animate } = this.props;
  16. let width = 50;
  17. let height = 100;
  18. let top = 'auto';
  19. let left = 'auto';
  20. let bottom = 'auto';
  21. let right = 'auto';
  22. if (size === 1) {
  23. width = 100;
  24. }
  25. if (size === 4 || (size === 3 && index > 0)) {
  26. height = 50;
  27. }
  28. if (size === 2) {
  29. if (index === 0) {
  30. right = '1px';
  31. } else {
  32. left = '1px';
  33. }
  34. } else if (size === 3) {
  35. if (index === 0) {
  36. right = '1px';
  37. } else if (index > 0) {
  38. left = '1px';
  39. }
  40. if (index === 1) {
  41. bottom = '1px';
  42. } else if (index > 1) {
  43. top = '1px';
  44. }
  45. } else if (size === 4) {
  46. if (index === 0 || index === 2) {
  47. right = '1px';
  48. }
  49. if (index === 1 || index === 3) {
  50. left = '1px';
  51. }
  52. if (index < 2) {
  53. bottom = '1px';
  54. } else {
  55. top = '1px';
  56. }
  57. }
  58. const style = {
  59. left: left,
  60. top: top,
  61. right: right,
  62. bottom: bottom,
  63. width: `${width}%`,
  64. height: `${height}%`,
  65. backgroundSize: 'cover',
  66. backgroundImage: `url(${account.get(animate ? 'avatar' : 'avatar_static')})`,
  67. };
  68. return (
  69. <div key={account.get('id')} style={style} />
  70. );
  71. }
  72. render() {
  73. const { accounts, size } = this.props;
  74. return (
  75. <div className='account__avatar-composite' style={{ width: `${size}px`, height: `${size}px` }}>
  76. {accounts.take(4).map((account, i) => this.renderItem(account, Math.min(accounts.size, 4), i))}
  77. {accounts.size > 4 && (
  78. <span className='account__avatar-composite__label'>
  79. +{accounts.size - 4}
  80. </span>
  81. )}
  82. </div>
  83. );
  84. }
  85. }