The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
1.8 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. const outerStyle = {
  4. display: 'flex',
  5. cursor: 'pointer',
  6. fontSize: '14px',
  7. border: '1px solid #363c4b',
  8. borderRadius: '4px',
  9. color: '#616b86',
  10. marginTop: '14px',
  11. textDecoration: 'none',
  12. overflow: 'hidden'
  13. };
  14. const contentStyle = {
  15. flex: '2',
  16. padding: '8px',
  17. paddingLeft: '14px'
  18. };
  19. const titleStyle = {
  20. display: 'block',
  21. fontWeight: '500',
  22. marginBottom: '5px',
  23. color: '#d9e1e8'
  24. };
  25. const descriptionStyle = {
  26. color: '#d9e1e8'
  27. };
  28. const imageOuterStyle = {
  29. flex: '1',
  30. background: '#373b4a'
  31. };
  32. const imageStyle = {
  33. display: 'block',
  34. width: '100%',
  35. height: 'auto',
  36. margin: '0',
  37. borderRadius: '4px 0 0 4px'
  38. };
  39. const hostStyle = {
  40. display: 'block',
  41. marginTop: '5px',
  42. fontSize: '13px'
  43. };
  44. const getHostname = url => {
  45. const parser = document.createElement('a');
  46. parser.href = url;
  47. return parser.hostname;
  48. };
  49. const Card = React.createClass({
  50. propTypes: {
  51. card: ImmutablePropTypes.map
  52. },
  53. mixins: [PureRenderMixin],
  54. render () {
  55. const { card } = this.props;
  56. if (card === null) {
  57. return null;
  58. }
  59. let image = '';
  60. if (card.get('image')) {
  61. image = (
  62. <div style={imageOuterStyle}>
  63. <img src={card.get('image')} alt={card.get('title')} style={imageStyle} />
  64. </div>
  65. );
  66. }
  67. return (
  68. <a style={outerStyle} href={card.get('url')} className='status-card'>
  69. {image}
  70. <div style={contentStyle}>
  71. <strong style={titleStyle}>{card.get('title')}</strong>
  72. <p style={descriptionStyle}>{card.get('description')}</p>
  73. <span style={hostStyle}>{getHostname(card.get('url'))}</span>
  74. </div>
  75. </a>
  76. );
  77. }
  78. });
  79. export default Card;