選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

111 行
4.1 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. createElement('div', ['title','like-h4'], headline, textBox);
  81. if (linklistData) {
  82. textBox.appendChild(createLinkList({links: linklistData}));
  83. } else {
  84. createElement('p', [], copy, textBox);
  85. }
  86. if (showReadingTime) {
  87. const rt = createReadingTime({minutes: Math.floor(Math.random() * 10) + 2});
  88. teaser.appendChild(rt);
  89. }
  90. if (type === 'fullwidth') {
  91. teaser.dataset.imageSize = imageSize;
  92. }
  93. const teaserLink = createElement('a', ['teaser--link', type], '', teaser);
  94. teaserLink.href = link;
  95. teaserLink.setAttribute('aria-label', 'Beschreibender Link-Text');
  96. if (linkType) {
  97. teaserLink.classList.add(linkType);
  98. }
  99. return teaser;
  100. };