Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

118 lignes
4.3 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. teaser.dataset.imageSize = imageSize;
  95. }
  96. // teaserLink nur OHNE linklistData
  97. if (!linklistData) {
  98. const teaserLink = createElement('a', ['teaser--link', type], '', teaser);
  99. teaserLink.href = link;
  100. teaserLink.setAttribute('aria-label', 'Beschreibender Link-Text');
  101. if (linkType) {
  102. teaserLink.classList.add(linkType);
  103. }
  104. }
  105. return teaser;
  106. };