25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

105 lines
3.9 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. else if (type === 'picto' || type === 'pictoHero') {
  69. const imageBox = createElement('div', ['image-box', 'chart'], null, teaser);
  70. const pictoBox = createElement('div', ['picto-box', ...(type === 'pictoHero' ? ['hero'] : [])], null, imageBox);
  71. const iconBox = createElement('div', ['icon'], null, pictoBox);
  72. iconBox.classList.add(picto);
  73. if (pictoText) {
  74. createElement('span', ['picto-title'], chartTitle, pictoBox);
  75. }
  76. }
  77. const textBox = createElement('div', ['text-box'], '', teaser);
  78. createElement('div', ['title','like-h4'], headline, textBox);
  79. createElement('p', [], copy, textBox);
  80. if (showReadingTime) {
  81. const rt = createReadingTime({minutes: Math.floor(Math.random() * 10) + 2});
  82. teaser.appendChild(rt);
  83. }
  84. if (type === 'fullwidth') {
  85. teaser.dataset.imageSize = imageSize;
  86. }
  87. const teaserLink = createElement('a', ['teaser--link', type], '', teaser);
  88. teaserLink.href = link;
  89. teaserLink.setAttribute('aria-label', 'Beschreibender Link-Text');
  90. if (linkType) {
  91. teaserLink.classList.add(linkType);
  92. }
  93. return teaser;
  94. };