You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

95 rivejä
3.5 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 = './dummy/placeholder-3-2.svg',
  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. picto = null,
  16. pictoText = false,
  17. linkType = null,
  18. }) => {
  19. const teaser = createElement('div', ['teaser', type]);
  20. if (kicker && kicker.length > 0) {
  21. createElement('span', ['kicker'], kicker, teaser);
  22. }
  23. if (imageSrc && imageSrc.length > 0 && type !== 'text' && type !== 'chart' && type !== 'picto' && type !== 'pictoHero') {
  24. let imageWidth, imageHeight;
  25. switch (type) {
  26. case 'hero':
  27. imageWidth = 630;
  28. imageHeight = 420;
  29. break;
  30. case 'fullwidth':
  31. if (imageSize === 'large') {
  32. imageWidth = 880;
  33. imageHeight = 484;
  34. } else if (imageSize === 'medium') {
  35. imageWidth = 650;
  36. imageHeight = 433;
  37. } else {
  38. imageWidth = 535;
  39. imageHeight = 535;
  40. }
  41. break;
  42. default:
  43. imageWidth = 420;
  44. imageHeight = 280;
  45. }
  46. const imageBox = createElement('div', ['image-box'], '', teaser);
  47. const src = imageSrc.replace('420', imageWidth).replace('280', imageHeight);
  48. createImage(src, imageWidth, imageHeight, 'Teaser-Bild', [], imageBox);
  49. if (copyright && copyright.length > 0) {
  50. const copy = createElement('span', ['copyright'], copyright, imageBox);
  51. copy.setAttribute("aria-hidden", "true");
  52. createElement('span', ['sr-only'], 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. else if (type === 'picto' || type === 'pictoHero') {
  60. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  61. const pictoBox = createElement('div', ['picto-box', ...(type === 'pictoHero' ? ['hero'] : [])], null, imageBox);
  62. const iconBox = createElement('div', ['icon'], null, pictoBox);
  63. iconBox.classList.add(picto);
  64. if (pictoText) {
  65. createElement('span', ['picto-title'], chartTitle, pictoBox);
  66. }
  67. }
  68. const textBox = createElement('div', ['text-box'], '', teaser);
  69. createElement('div', ['title','like-h4'], headline, textBox);
  70. createElement('p', [], copy, textBox);
  71. if (showReadingTime) {
  72. const rt = createReadingTime({minutes: Math.floor(Math.random() * 10) + 2});
  73. teaser.appendChild(rt);
  74. }
  75. if (type === 'fullwidth') {
  76. teaser.dataset.imageSize = imageSize;
  77. }
  78. const teaserLink = createElement('a', ['teaser--link', type], '', teaser);
  79. teaserLink.href = link;
  80. teaserLink.setAttribute('aria-label', 'Beschreibender Link-Text');
  81. if (linkType) {
  82. teaserLink.classList.add(linkType);
  83. }
  84. return teaser;
  85. };