index.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import Card, {
  3. CardActions,
  4. CardActionButtons,
  5. CardPrimaryContent,
  6. CardMedia,
  7. CardActionIcons
  8. } from "@material/react-card";
  9. import Button from "components/Button";
  10. import '@material/react-card/dist/card.min.css';
  11. import '@material/react-button/dist/button.min.css';
  12. import './styles.scss';
  13. import sample_img from "./sample.png";
  14. type CBKCardProps = {
  15. withImg?: boolean,
  16. title: string,
  17. summary?: string,
  18. img?: string,
  19. noMedia?: boolean,
  20. actions?: {
  21. label: string,
  22. handler: (event: React.MouseEvent) => void,
  23. }[],
  24. icons?: {
  25. icon: string,
  26. handler: (event: React.MouseEvent) => void
  27. }[],
  28. onClick: (event: React.MouseEvent) => void,
  29. className?: string,
  30. }
  31. function CBKCard({onClick, img, title, summary, actions, icons, noMedia = false, className = ''}: CBKCardProps){
  32. return(
  33. <Card outlined className={`cbk-card ${className}`}>
  34. <CardPrimaryContent onClick={onClick}>
  35. { noMedia ? null : <CardMedia square imageUrl={img || sample_img}></CardMedia>}
  36. <div className='cbk-card__main'>
  37. <h6 className='cbk-card__main__title'>{title}</h6>
  38. {
  39. summary ?
  40. <p className='cbk-card__main__summary'>{summary}</p> :
  41. null
  42. }
  43. </div>
  44. </CardPrimaryContent>
  45. {
  46. actions ?
  47. (
  48. <CardActions>
  49. <CardActionButtons>
  50. {
  51. actions.map(({label, handler}, i) => (
  52. <Button key={i} onClick={handler}>
  53. {label}
  54. </Button>
  55. ))
  56. }
  57. </CardActionButtons>
  58. {
  59. icons ? (
  60. <CardActionIcons>
  61. {
  62. icons.map((action, i) => (
  63. <Button
  64. icon={action.icon}
  65. onClick={action.handler}
  66. key={i}
  67. />
  68. ))
  69. }
  70. </CardActionIcons>
  71. ) : null
  72. }
  73. </CardActions>
  74. ) :
  75. null
  76. }
  77. </Card>
  78. )
  79. }
  80. export default CBKCard;