Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

123 řádky
4.5 KiB

  1. import {createElement, createImage} from "../../_global/scripts/helpers";
  2. import './teaser.scss';
  3. import {createReadingTime} from "../../atoms/reading-time/ReadingTimeComponent";
  4. import {createLinkList} from "../linklist/LinkListComponent";
  5. export const createTeaser = ({
  6. type = 'regular',
  7. link = '#',
  8. imageSrc = './dummy/placeholder-3-2.svg',
  9. copyright = '@ shutterstock.com',
  10. kicker = 'Fachkräfte',
  11. headline = 'Anteil der Frauen im Bereich Engineering steigt',
  12. 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.',
  13. showReadingTime = false,
  14. imageSize = 'large',
  15. chartTitle = 'Chart-Titel des Teasers',
  16. picto = null,
  17. pictoText = false,
  18. linkType = null,
  19. linklistData = null,
  20. }) => {
  21. const teaser = createElement('div', ['teaser', type]);
  22. if (kicker && kicker.length > 0) {
  23. createElement('span', ['kicker'], kicker, teaser);
  24. }
  25. if (imageSrc && imageSrc.length > 0 && type !== 'text' && type !== 'chart' && type !== 'picto' && type !== 'pictoHero') {
  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. const copy = createElement('span', ['copyright'], copyright, imageBox);
  53. copy.setAttribute("aria-hidden", "true");
  54. createElement('span', ['sr-only'], copyright, imageBox);
  55. }
  56. }
  57. else if ((type === 'chart' && chartTitle && chartTitle.length > 0) || ((!imageSrc || imageSrc.length === 0) && type !== 'text' && chartTitle && chartTitle.length > 0)) {
  58. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  59. createElement('span', ['chart-title'], chartTitle, imageBox);
  60. }
  61. else if (type === 'picto' || type === 'pictoHero') {
  62. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  63. const pictoBox = createElement('div', ['picto-box', ...(type === 'pictoHero' ? ['hero'] : [])], null, imageBox);
  64. const iconBox = createElement('div', ['icon'], null, pictoBox);
  65. iconBox.classList.add(picto);
  66. if (pictoText) {
  67. createElement('span', ['picto-title'], chartTitle, pictoBox);
  68. }
  69. }
  70. else if (type === 'picto' || type === 'pictoHero') {
  71. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  72. const pictoBox = createElement('div', ['picto-box', ...(type === 'pictoHero' ? ['hero'] : [])], null, imageBox);
  73. const iconBox = createElement('div', ['icon'], null, pictoBox);
  74. iconBox.classList.add(picto);
  75. if (pictoText) {
  76. createElement('span', ['picto-title'], chartTitle, pictoBox);
  77. }
  78. }
  79. const textBox = createElement('div', ['text-box'], '', teaser);
  80. if (linklistData) {
  81. // Mit Linkliste: KEINE "title" Klasse, KEIN Link in Headline
  82. createElement('div', ['like-h4'], headline, textBox);
  83. textBox.appendChild(createLinkList({links: linklistData}));
  84. } else {
  85. // Ohne Linkliste: normale Variante MIT "title" Klasse
  86. createElement('div', ['title','like-h4'], headline, textBox);
  87. createElement('p', [], copy, textBox);
  88. }
  89. if (showReadingTime) {
  90. const rt = createReadingTime({minutes: Math.floor(Math.random() * 10) + 2});
  91. teaser.appendChild(rt);
  92. }
  93. if (type === 'fullwidth') {
  94. const imageSizeMap = {
  95. 'large': 'l',
  96. 'medium': 'm',
  97. 'small': 's'
  98. };
  99. teaser.dataset.imageSize = imageSizeMap[imageSize] || imageSize;
  100. }
  101. // teaserLink nur OHNE linklistData
  102. if (!linklistData) {
  103. const teaserLink = createElement('a', ['teaser--link', type], '', teaser);
  104. teaserLink.href = link;
  105. teaserLink.setAttribute('aria-label', 'Beschreibender Link-Text');
  106. if (linkType) {
  107. teaser.classList.add(linkType);
  108. }
  109. }
  110. return teaser;
  111. };