Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

80 rader
2.7 KiB

  1. import {createElement, createImage} from "../../_global/scripts/helpers";
  2. import './teaser.scss';
  3. import {createReadingTime} from "../../atoms/reading-time/ReadingTimeComponent";
  4. export const createTeaser = ({
  5. type = 'regular',
  6. link = '#',
  7. imageSrc = 'https://api.unsplash.com/-uHVRvDr7pg/420x280',
  8. copyright = '@ shutterstock.com',
  9. kicker = 'Fachkräfte',
  10. headline = 'Anteil der Frauen im Bereich Engineering steigt',
  11. copy = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita, no sea takimata sanctus est.',
  12. showReadingTime = false,
  13. imageSize = 'large',
  14. chartTitle = 'Chart-Titel des Teasers',
  15. linkType = null,
  16. }) => {
  17. const teaser = createElement('a', ['teaser', type]);
  18. teaser.href = link;
  19. if (linkType) {
  20. teaser.classList.add(linkType);
  21. }
  22. if (kicker && kicker.length > 0) {
  23. createElement('span', ['kicker'], kicker, teaser);
  24. }
  25. if (imageSrc && imageSrc.length > 0 && type !== 'text' && type !== 'chart') {
  26. let imageWidth, imageHeight;
  27. switch (type) {
  28. case 'hero':
  29. imageWidth = 630;
  30. imageHeight = 420;
  31. break;
  32. case 'fullwidth':
  33. if (imageSize === 'large') {
  34. imageWidth = 880;
  35. imageHeight = 484;
  36. } else if (imageSize === 'medium') {
  37. imageWidth = 650;
  38. imageHeight = 433;
  39. } else {
  40. imageWidth = 535;
  41. imageHeight = 535;
  42. }
  43. break;
  44. default:
  45. imageWidth = 420;
  46. imageHeight = 280;
  47. }
  48. const imageBox = createElement('div', ['image-box'], '', teaser);
  49. const src = imageSrc.replace('420', imageWidth).replace('280', imageHeight);
  50. createImage(src, imageWidth, imageHeight, 'Teaser-Bild', [], imageBox);
  51. if (copyright && copyright.length > 0) {
  52. createElement('span', ['copyright'], copyright, imageBox);
  53. }
  54. }
  55. else if ((type === 'chart' && chartTitle && chartTitle.length > 0) || ((!imageSrc || imageSrc.length === 0) && type !== 'text' && chartTitle && chartTitle.length > 0)) {
  56. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  57. createElement('span', ['chart-title'], chartTitle, imageBox);
  58. }
  59. const textBox = createElement('div', ['text-box'], '', teaser);
  60. createElement('h4', ['title'], headline, textBox);
  61. createElement('p', [], copy, textBox);
  62. if (showReadingTime) {
  63. const rt = createReadingTime({minutes: Math.floor(Math.random() * 10) + 2});
  64. teaser.appendChild(rt);
  65. }
  66. if (type === 'fullwidth') {
  67. teaser.dataset.imageSize = imageSize;
  68. }
  69. return teaser;
  70. };