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.
 
 
 
 

61 rivejä
2.1 KiB

  1. import './survey.scss';
  2. import $ from 'jquery';
  3. import {createElement} from "../../_global/scripts/helpers";
  4. import {SurveyComplex, SurveySimple} from "./SurveyData";
  5. import {createButton} from "../../atoms/button/ButtonComponent";
  6. import IHKSurvey from "./survey";
  7. export const createSurvey = ({
  8. kicker = 'Schnellumfrage',
  9. headline = 'Einführung von 2G im Einzelhandel: Was halten Sie davon?',
  10. copy = 'Hier können Sie abstimmen:',
  11. method = 'get',
  12. data = SurveySimple,
  13. }) => {
  14. const section = createElement('section', ['participation']);
  15. const container = createElement('div', ['container'], null, section);
  16. const survey = createElement('div', ['vot-teaser', 'survey'], null, container);
  17. const textBox = createElement('div', ['text-box'], null, survey);
  18. createElement('p', ['kicker'], kicker, textBox);
  19. createElement('h3', [], headline, textBox);
  20. createElement('p', [], copy, textBox);
  21. const formBox = createElement('div', ['form-box'], null, survey);
  22. const form = createElement('form', ['vot-form'], null, formBox);
  23. form.id = 'voting-form';
  24. form.action = './html/survey-simple.html';
  25. form.dataset.showResultUrl = './html/survey-simple.html';
  26. form.dataset.showResult = 'false';
  27. form.method = method;
  28. data.map((group) => {
  29. const fieldset = createElement('fieldset', [], null, form);
  30. if (group.legend) {
  31. createElement('legend', [], group.legend, fieldset);
  32. }
  33. const choicesWrapper = createElement('div', ['choices-wrapper'], null, fieldset);
  34. const choicesList = createElement('ul', ['choices'], null, choicesWrapper);
  35. group.options.map((option, index) => {
  36. const id = group.name + '-' + index;
  37. const li = createElement('li', ['choice'], null, choicesList);
  38. const input = createElement('input', [], null, li);
  39. const label = createButton({
  40. elementType: 'label',
  41. color: 'secondary-light',
  42. label: option,
  43. size: 'medium',
  44. })
  45. li.appendChild(label);
  46. input.name = group.name;
  47. input.id = id;
  48. input.type = 'radio';
  49. input.value = option;
  50. label.setAttribute('for', id);
  51. })
  52. })
  53. new IHKSurvey($(survey));
  54. return section;
  55. }