WelcomeTile.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import ReactHtmlParser from 'react-html-parser';
  4. import './WelcomeTile.scss';
  5. import { Multilinetruncatedtext } from 'ca-ui-toolkit';
  6. export class WelcomeTile extends Component {
  7. static propTypes = {
  8. /** Custom class name(s) */
  9. className: PropTypes.string,
  10. /** A copy of the i18n translation object */
  11. stringGetter: PropTypes.object,
  12. /** ID of the icon in the designated tile*/
  13. iconID: PropTypes.string,
  14. /** Key in the translation file (stringGetter) corresponding to the tile title*/
  15. titleKey: PropTypes.string,
  16. /** Key in the translation file (stringGetter) corresponding to the title description*/
  17. descriptionKey: PropTypes.string,
  18. /** Function invoked while the key is pressed (specifically for tab action)*/
  19. onKeyUp: PropTypes.func,
  20. /** Function invoked while the tile is clicked */
  21. onClick: PropTypes.func,
  22. /** Customized style */
  23. style: PropTypes.object,
  24. /** If the tile is the rightmost one or not */
  25. isLast: PropTypes.bool
  26. };
  27. render() {
  28. const { className, stringGetter, iconID, titleKey, descriptionKey, onKeyUp, onClick, style, isLast } = this.props;
  29. const truncatedTitleProps = { numLines: 2, style: { width: '100%' } };
  30. const truncatedDescriptionProps = { numLines: 3, style: { width: '100%' } };
  31. const combinedClassName = isLast ? `welcomeTile ${className}` : `welcomeTile welcomeTileWithBorder ${className}`;
  32. return <div tabIndex='0' onKeyUp={onKeyUp} className={combinedClassName} style={style} onClick={onClick}>
  33. <svg className="welcomeTileIcon">
  34. <use xlinkHref={`#${iconID}`} />
  35. </svg>
  36. <div className="welcomeTileTitle">
  37. <Multilinetruncatedtext value={stringGetter.get(titleKey)} {...truncatedTitleProps}/>
  38. </div>
  39. <div className="welcomeTileDescription">
  40. <Multilinetruncatedtext value={stringGetter.get(descriptionKey)} {...truncatedDescriptionProps}/>
  41. </div>
  42. </div>;
  43. }
  44. }