@ilo-org/twig 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/.browserslistrc +4 -0
  2. package/.editorconfig +12 -0
  3. package/.eslintignore +11 -0
  4. package/.eslintrc.js +66 -0
  5. package/.prettierignore +16 -0
  6. package/.prettierrc.js +13 -0
  7. package/.stylelintignore +9 -0
  8. package/.stylelintrc +23 -0
  9. package/.turbo/turbo-build.log +15313 -0
  10. package/LICENSE +201 -0
  11. package/README.md +23 -0
  12. package/apps/storybook/assets.js +5 -0
  13. package/apps/storybook/config/prefix.yml +1 -0
  14. package/apps/storybook/main.js +16 -0
  15. package/apps/storybook/manager.js +7 -0
  16. package/apps/storybook/patterns/colors.stories.mdx +18 -0
  17. package/apps/storybook/patterns/typeset.stories.mdx +28 -0
  18. package/apps/storybook/patterns/welcome.stories.mdx +24 -0
  19. package/apps/storybook/preview-body.html +4 -0
  20. package/apps/storybook/preview-head.html +11 -0
  21. package/apps/storybook/preview.js +38 -0
  22. package/apps/storybook/styles.scss +2 -0
  23. package/apps/storybook/theme.js +11 -0
  24. package/babel.config.js +16 -0
  25. package/contributing.md +5 -0
  26. package/importprefix.js +18 -0
  27. package/importsvgs.js +5 -0
  28. package/jest.config.js +18 -0
  29. package/outputtwigs.js +54 -0
  30. package/package.json +108 -0
  31. package/postcss.config.js +6 -0
  32. package/src/namespaces.js +14 -0
  33. package/src/patterns/components/accordion/accordion-item.twig +16 -0
  34. package/src/patterns/components/accordion/accordion-item.wingsuit.yml +30 -0
  35. package/src/patterns/components/accordion/accordion.behavior.js +14 -0
  36. package/src/patterns/components/accordion/accordion.js +178 -0
  37. package/src/patterns/components/accordion/accordion.stories.jsx +7 -0
  38. package/src/patterns/components/accordion/accordion.twig +17 -0
  39. package/src/patterns/components/accordion/accordion.wingsuit.yml +59 -0
  40. package/src/patterns/components/accordion/index.js +7 -0
  41. package/src/patterns/components/breadcrumb/breadcrumb.behavior.js +14 -0
  42. package/src/patterns/components/breadcrumb/breadcrumb.js +93 -0
  43. package/src/patterns/components/breadcrumb/breadcrumb.stories.jsx +7 -0
  44. package/src/patterns/components/breadcrumb/breadcrumb.twig +32 -0
  45. package/src/patterns/components/breadcrumb/breadcrumb.wingsuit.yml +35 -0
  46. package/src/patterns/components/breadcrumb/index.js +7 -0
  47. package/src/patterns/components/button/button.stories.jsx +7 -0
  48. package/src/patterns/components/button/button.twig +18 -0
  49. package/src/patterns/components/button/button.wingsuit.yml +104 -0
  50. package/src/patterns/components/button/index.js +6 -0
  51. package/src/patterns/components/callout/callout.behaviors.js +14 -0
  52. package/src/patterns/components/callout/callout.js +121 -0
  53. package/src/patterns/components/callout/callout.stories.jsx +7 -0
  54. package/src/patterns/components/callout/callout.twig +30 -0
  55. package/src/patterns/components/callout/callout.wingsuit.yml +66 -0
  56. package/src/patterns/components/callout/index.js +6 -0
  57. package/src/patterns/components/card/card.stories.jsx +7 -0
  58. package/src/patterns/components/card/card.twig +98 -0
  59. package/src/patterns/components/card/card.wingsuit.yml +300 -0
  60. package/src/patterns/components/card/index.js +6 -0
  61. package/src/patterns/components/cardgroup/cardgroup.stories.jsx +7 -0
  62. package/src/patterns/components/cardgroup/cardgroup.twig +30 -0
  63. package/src/patterns/components/cardgroup/cardgroup.wingsuit.yml +419 -0
  64. package/src/patterns/components/cardgroup/index.js +6 -0
  65. package/src/patterns/components/contextmenu/contextmenu.stories.jsx +7 -0
  66. package/src/patterns/components/contextmenu/contextmenu.twig +12 -0
  67. package/src/patterns/components/contextmenu/contextmenu.wingsuit.yml +23 -0
  68. package/src/patterns/components/contextmenu/index.js +6 -0
  69. package/src/patterns/components/dropdown/dropdown.stories.jsx +7 -0
  70. package/src/patterns/components/dropdown/dropdown.twig +20 -0
  71. package/src/patterns/components/dropdown/dropdown.wingsuit.yml +71 -0
  72. package/src/patterns/components/dropdown/index.js +6 -0
  73. package/src/patterns/components/fieldset/fieldset.twig +43 -0
  74. package/src/patterns/components/footer/footer.stories.jsx +7 -0
  75. package/src/patterns/components/footer/footer.twig +62 -0
  76. package/src/patterns/components/footer/footer.wingsuit.yml +104 -0
  77. package/src/patterns/components/footer/index.js +6 -0
  78. package/src/patterns/components/form/checkbox.twig +13 -0
  79. package/src/patterns/components/form/checkboxgroup.twig +5 -0
  80. package/src/patterns/components/form/datepicker.twig +32 -0
  81. package/src/patterns/components/form/file.twig +14 -0
  82. package/src/patterns/components/form/fileupload.behavior.js +14 -0
  83. package/src/patterns/components/form/fileupload.js +118 -0
  84. package/src/patterns/components/form/form.stories.jsx +7 -0
  85. package/src/patterns/components/form/form.twig +94 -0
  86. package/src/patterns/components/form/form.wingsuit.yml +973 -0
  87. package/src/patterns/components/form/index.js +7 -0
  88. package/src/patterns/components/form/input.twig +13 -0
  89. package/src/patterns/components/form/number.twig +13 -0
  90. package/src/patterns/components/form/radio.twig +4 -0
  91. package/src/patterns/components/form/textarea.twig +13 -0
  92. package/src/patterns/components/hero/hero.stories.jsx +7 -0
  93. package/src/patterns/components/hero/hero.twig +24 -0
  94. package/src/patterns/components/hero/hero.wingsuit.yml +56 -0
  95. package/src/patterns/components/hero/index.js +6 -0
  96. package/src/patterns/components/herocard/herocard.stories.jsx +7 -0
  97. package/src/patterns/components/herocard/herocard.twig +31 -0
  98. package/src/patterns/components/herocard/herocard.wingsuit.yml +43 -0
  99. package/src/patterns/components/herocard/index.js +6 -0
  100. package/src/patterns/components/icon/icon.twig +4 -0
  101. package/src/patterns/components/icon/index.js +6 -0
  102. package/src/patterns/components/image/image.stories.jsx +7 -0
  103. package/src/patterns/components/image/image.twig +19 -0
  104. package/src/patterns/components/image/image.wingsuit.yml +37 -0
  105. package/src/patterns/components/image/index.js +6 -0
  106. package/src/patterns/components/link/index.js +6 -0
  107. package/src/patterns/components/link/link.stories.jsx +7 -0
  108. package/src/patterns/components/link/link.twig +8 -0
  109. package/src/patterns/components/link/link.wingsuit.yml +35 -0
  110. package/src/patterns/components/linklist/index.js +6 -0
  111. package/src/patterns/components/linklist/linklist.stories.jsx +7 -0
  112. package/src/patterns/components/linklist/linklist.twig +26 -0
  113. package/src/patterns/components/linklist/linklist.wingsuit.yml +53 -0
  114. package/src/patterns/components/list/index.js +6 -0
  115. package/src/patterns/components/list/list-item.twig +6 -0
  116. package/src/patterns/components/list/list-item.wingsuit.yml +18 -0
  117. package/src/patterns/components/list/list.stories.jsx +7 -0
  118. package/src/patterns/components/list/list.twig +30 -0
  119. package/src/patterns/components/list/list.wingsuit.yml +48 -0
  120. package/src/patterns/components/loading/index.js +7 -0
  121. package/src/patterns/components/loading/loading.behavior.js +14 -0
  122. package/src/patterns/components/loading/loading.js +102 -0
  123. package/src/patterns/components/loading/loading.stories.jsx +7 -0
  124. package/src/patterns/components/loading/loading.twig +8 -0
  125. package/src/patterns/components/loading/loading.wingsuit.yml +37 -0
  126. package/src/patterns/components/modal/index.js +7 -0
  127. package/src/patterns/components/modal/modal.behavior.js +14 -0
  128. package/src/patterns/components/modal/modal.js +130 -0
  129. package/src/patterns/components/modal/modal.stories.jsx +7 -0
  130. package/src/patterns/components/modal/modal.twig +18 -0
  131. package/src/patterns/components/modal/modal.wingsuit.yml +54 -0
  132. package/src/patterns/components/notification/index.js +7 -0
  133. package/src/patterns/components/notification/notification.behavior.js +15 -0
  134. package/src/patterns/components/notification/notification.js +95 -0
  135. package/src/patterns/components/notification/notification.stories.jsx +7 -0
  136. package/src/patterns/components/notification/notification.twig +18 -0
  137. package/src/patterns/components/notification/notification.wingsuit.yml +58 -0
  138. package/src/patterns/components/pagination/Pagination.stories.jsx +7 -0
  139. package/src/patterns/components/pagination/index.js +6 -0
  140. package/src/patterns/components/pagination/pagination.twig +48 -0
  141. package/src/patterns/components/pagination/pagination.wingsuit.yml +72 -0
  142. package/src/patterns/components/polyfill/index.js +6 -0
  143. package/src/patterns/components/polyfill/polyfill.twig +10 -0
  144. package/src/patterns/components/profile/index.js +6 -0
  145. package/src/patterns/components/profile/profile.stories.jsx +7 -0
  146. package/src/patterns/components/profile/profile.twig +18 -0
  147. package/src/patterns/components/profile/profile.wingsuit.yml +35 -0
  148. package/src/patterns/components/readmore/index.js +7 -0
  149. package/src/patterns/components/readmore/readmore.behavior.js +14 -0
  150. package/src/patterns/components/readmore/readmore.js +119 -0
  151. package/src/patterns/components/readmore/readmore.stories.jsx +7 -0
  152. package/src/patterns/components/readmore/readmore.twig +16 -0
  153. package/src/patterns/components/readmore/readmore.wingsuit.yml +32 -0
  154. package/src/patterns/components/richtext/index.js +6 -0
  155. package/src/patterns/components/richtext/richtext.stories.jsx +7 -0
  156. package/src/patterns/components/richtext/richtext.twig +6 -0
  157. package/src/patterns/components/richtext/richtext.wingsuit.yml +12 -0
  158. package/src/patterns/components/searchfield/index.js +6 -0
  159. package/src/patterns/components/searchfield/searchfield.stories.jsx +7 -0
  160. package/src/patterns/components/searchfield/searchfield.twig +7 -0
  161. package/src/patterns/components/searchfield/searchfield.wingsuit.yml +22 -0
  162. package/src/patterns/components/table/index.js +7 -0
  163. package/src/patterns/components/table/table.behavior.js +14 -0
  164. package/src/patterns/components/table/table.js +279 -0
  165. package/src/patterns/components/table/table.stories.jsx +7 -0
  166. package/src/patterns/components/table/table.twig +36 -0
  167. package/src/patterns/components/table/table.wingsuit.yml +112 -0
  168. package/src/patterns/components/tableofcontents/index.js +6 -0
  169. package/src/patterns/components/tableofcontents/tableofcontents.stories.jsx +7 -0
  170. package/src/patterns/components/tableofcontents/tableofcontents.twig +14 -0
  171. package/src/patterns/components/tableofcontents/tableofcontents.wingsuit.yml +22 -0
  172. package/src/patterns/components/tabs/index.js +7 -0
  173. package/src/patterns/components/tabs/tabs.behavior.js +23 -0
  174. package/src/patterns/components/tabs/tabs.js +209 -0
  175. package/src/patterns/components/tabs/tabs.stories.jsx +7 -0
  176. package/src/patterns/components/tabs/tabs.twig +30 -0
  177. package/src/patterns/components/tabs/tabs.wingsuit.yml +168 -0
  178. package/src/patterns/components/tag/index.js +7 -0
  179. package/src/patterns/components/tag/tag-set.twig +15 -0
  180. package/src/patterns/components/tag/tag.behavior.js +14 -0
  181. package/src/patterns/components/tag/tag.stories.jsx +7 -0
  182. package/src/patterns/components/tag/tag.twig +24 -0
  183. package/src/patterns/components/tag/tag.wingsuit.yml +43 -0
  184. package/src/patterns/components/tag/tagset.js +160 -0
  185. package/src/patterns/components/tag/tagset.wingsuit.yml +43 -0
  186. package/src/patterns/components/tooltip/index.js +7 -0
  187. package/src/patterns/components/tooltip/tooltip.behavior.js +14 -0
  188. package/src/patterns/components/tooltip/tooltip.js +184 -0
  189. package/src/patterns/components/tooltip/tooltip.stories.jsx +7 -0
  190. package/src/patterns/components/tooltip/tooltip.twig +11 -0
  191. package/src/patterns/components/tooltip/tooltip.wingsuit.yml +30 -0
  192. package/src/patterns/components/video/index.js +7 -0
  193. package/src/patterns/components/video/video.behavior.js +14 -0
  194. package/src/patterns/components/video/video.js +114 -0
  195. package/src/patterns/components/video/video.stories.jsx +7 -0
  196. package/src/patterns/components/video/video.twig +17 -0
  197. package/src/patterns/components/video/video.wingsuit.yml +44 -0
  198. package/src/patterns/components/video/videoplayer.twig +10 -0
  199. package/src/tokens/exports/_colors.scss +7 -0
  200. package/src/tokens/exports/_font-families.scss +6 -0
  201. package/src/tokens/exports/_font-sizes-heading.scss +10 -0
  202. package/src/tokens/index.scss +7 -0
  203. package/src/vendorjs/lib.vendor.js +1 -0
  204. package/wingsuit.config.js +27 -0
@@ -0,0 +1,62 @@
1
+ {#
2
+ FOOTER COMPONENT
3
+ #}
4
+ <footer class="{{prefix}}--footer">
5
+ <div class="{{prefix}}--footer--main">
6
+ <div class="site--info">
7
+ <img class="{{prefix}}--footer--logo" src="{{logo.url}}" alt="{{logo.alt}}" />
8
+ <h3 class="{{prefix}}--footer--headline">{{tagline}}</h3>
9
+ <h4 class="{{prefix}}--footer--subhead">{{subtagline}}</h4>
10
+ </div>
11
+ {% if address %}
12
+ <div class="address">
13
+ {% for line in address %}
14
+ <p class="address--line">{{line}}</p>
15
+ {% endfor %}
16
+ </div>
17
+ {% endif %}
18
+ {% if linkgroup %}
19
+ <nav class="links">
20
+ {% include '@components/linklist/linklist.twig' with {linkgroup: linkgroup, theme: 'dark'} %}
21
+ </nav>
22
+ {% endif %}
23
+ {% if social or subscribe %}
24
+ <div class="connect">
25
+ {% if social %}
26
+ <h5 class="social--headline">{{social.headline}}</h5>
27
+ <ul class="social--links">
28
+ {% for link in social.links %}
29
+ <li class="social--links--item">
30
+ <a href="{{link.url}}" class="social--links--link {{link.type|lower}}">{{link.type|capitalize}}</a>
31
+ </li>
32
+ {% endfor %}
33
+ </ul>
34
+ {% endif %}
35
+ {% if subscribe %}
36
+ {% include '@components/button/button.twig' with {label: subscribe.label, url: subscribe.url, type: 'primary', size: 'large', target: '_blank'} %}
37
+ {% endif %}
38
+ </div>
39
+ {% endif %}
40
+ </div>
41
+ <div class="{{prefix}}--footer--secondary">
42
+ {% if legal %}
43
+ <div class="legal">
44
+ {{legal}}
45
+ </div>
46
+ {% endif %}
47
+ {% if secondarylinks %}
48
+ <nav class="secondarylinks">
49
+ <ul class="secondarylinks--list">
50
+ {% for link in secondarylinks %}
51
+ <li class="secondarylinks--list--item">
52
+ <a href="{{link.url}}" class="secondarylinks--list--link">{{link.label}}</a>
53
+ </li>
54
+ {% endfor %}
55
+ </ul>
56
+ </nav>
57
+ {% endif %}
58
+ {% if anchorlink %}
59
+ <a href="{{anchorlink.href}}" class="anchorlink">{{anchorlink.label}}</a>
60
+ {% endif %}
61
+ </div>
62
+ </footer>
@@ -0,0 +1,104 @@
1
+ footer:
2
+ use: '@components/footer/footer.twig'
3
+ label: Footer
4
+ description: A component for displaying a page's footer
5
+ fields:
6
+ logo:
7
+ type: object
8
+ label: action
9
+ description: A URL and alt text for the site logo
10
+ preview:
11
+ alt: "My alt text"
12
+ url: "https://placekitten.com/g/266/96"
13
+ required: true
14
+ tagline:
15
+ type: string
16
+ label: tagline
17
+ description: the tagline for the site
18
+ preview: "Advancing social justice, promoting decent work"
19
+ subtagline:
20
+ type: string
21
+ label: subtagline
22
+ description: a sub-tagline for the site
23
+ preview: "ILO is a specialized agency of the United Nations"
24
+ address:
25
+ type: object
26
+ label: address
27
+ description: "any number of strings in an address"
28
+ preview:
29
+ - "International Labour Organization"
30
+ - "4 route des Morillons"
31
+ - "CH-1211 Genève 22"
32
+ - "Switzerland"
33
+ linkgroup:
34
+ type: object
35
+ label: links
36
+ description: "up to six links"
37
+ preview:
38
+ - links:
39
+ - label: "Link One"
40
+ url: "http://www.google.com"
41
+ - label: "Link Two"
42
+ url: "http://www.google.com"
43
+ - label: "Link Three"
44
+ url: "http://www.google.com"
45
+ - label: "Link Four"
46
+ url: "http://www.google.com"
47
+ - label: "Link Five"
48
+ url: "http://www.google.com"
49
+ - label: "Link Six"
50
+ url: "http://www.google.com"
51
+ social:
52
+ type: object
53
+ label: social
54
+ description: "Links to social media"
55
+ preview:
56
+ headline: "Social Links Headline"
57
+ links:
58
+ - type: "instagram"
59
+ url: "http://www.google.com"
60
+ - type: "facebook"
61
+ url: "http://www.google.com"
62
+ - type: "twitter"
63
+ url: "http://www.google.com"
64
+ - type: "twitter"
65
+ url: "http://www.google.com"
66
+ - type: "instagram"
67
+ url: "http://www.google.com"
68
+ subscribe:
69
+ type: object
70
+ label: subscribe
71
+ description: "a link to a subscribe form"
72
+ preview:
73
+ label: "Subscribe"
74
+ url: "http://www.google.com"
75
+ legal:
76
+ type: string
77
+ label: legal
78
+ description: "a string with legal information"
79
+ preview: "© 1996-2022 International Labour Organization (ILO)"
80
+ secondarylinks:
81
+ type: object
82
+ label: secondarylinks
83
+ description: "up to six links"
84
+ preview:
85
+ - label: "Link One"
86
+ url: "http://www.google.com"
87
+ - label: "Link Two"
88
+ url: "http://www.google.com"
89
+ - label: "Link Three"
90
+ url: "http://www.google.com"
91
+ - label: "Link Four"
92
+ url: "http://www.google.com"
93
+ - label: "Link Five"
94
+ url: "http://www.google.com"
95
+ - label: "Link Six"
96
+ url: "http://www.google.com"
97
+ anchorlink:
98
+ type: object
99
+ label: anchorlink
100
+ description: "an anchor href and label for navigating to another section on the page"
101
+ preview:
102
+ label: "Back to Top"
103
+ href: "#anchor"
104
+ visibility: storybook
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Footer
3
+ */
4
+ // Module template
5
+ import './footer.twig';
6
+ import './footer.wingsuit.yml';
@@ -0,0 +1,13 @@
1
+ {#
2
+ CHECKBOX COMPONENT
3
+ #}
4
+ {% extends '@components/fieldset/fieldset.twig' %}
5
+ {% set fsinputid = id ? id : name %}
6
+ {% set fslabel = label %}
7
+ {% set fshelper = helper %}
8
+ {% set fserror = error %}
9
+ {% set fstype = type %}
10
+
11
+ {% block formfield %}
12
+ <input id="{{id}}" name="{{name}}" type="checkbox" class="{{prefix}}--checkbox" {% if disabled %}disabled{% endif %} />
13
+ {% endblock %}
@@ -0,0 +1,5 @@
1
+ {#
2
+ GROUPED CHECKBOX COMPONENT
3
+ #}
4
+ <input id="{{id}}" name="{{name}}" type="checkbox" class="{{prefix}}--checkbox" {% if disabled %}disabled{% endif %} />
5
+
@@ -0,0 +1,32 @@
1
+ {#
2
+ DATEPICKER COMPONENT
3
+ #}
4
+ <div class="{{prefix}}--datepicker{% if range %}--range{% endif %}">
5
+ <fieldset class="{{prefix}}--fieldset">
6
+ <div class="{{prefix}}--fieldset--input--date ">
7
+ <label class="{{prefix}}--fieldset--label">{{label}}</label>
8
+ <input name="{{name}}" type="date" class="{{prefix}}--datepicker {{prefix}}--input {% if error %} error{% endif %}" {% if placeholder %}placeholder="{{placeholder}}"{% endif %} {% if required %}required{% endif %}{% if disabled %}disabled{% endif %} id="{% if id %}{{id}}{% else %}{{name}}{% endif %}">
9
+ {% if helper and not error %}
10
+ <span class="ilo--fieldset--helper">{{helper}}</span>
11
+ {% endif %}
12
+ {% if error %}
13
+ <span class="ilo--fieldset--error">{{error}}</span>
14
+ {% endif %}
15
+ </div>
16
+ </fieldset>
17
+ {% if range %}
18
+ <fieldset class="{{prefix}}--fieldset">
19
+ <div class="{{prefix}}--fieldset--input--date ">
20
+ <label class="{{prefix}}--fieldset--label">{{enddata.label}}</label>
21
+ <input name="{{enddata.name}}" type="date" class="{{prefix}}--datepicker {{prefix}}--input{% if enddata['error'] is defined %} error{% endif %}" {% if enddata['placeholder'] is defined %}placeholder="{{enddata.placeholder}}"{% endif %} {% if enddata['required'] is defined %}required{% endif %} {% if enddata['disabled'] is defined %}disabled{% endif %} id="{% if enddata['id'] is defined %}{{enddata.id}}{% else %}{{enddata.name}}{% endif %}">
22
+ </div>
23
+ {% if enddata.helper and not enddata.error %}
24
+ <span class="ilo--fieldset--helper">{{enddata.helper}}</span>
25
+ {% endif %}
26
+ {% if enddata.error %}
27
+ <span class="ilo--fieldset--error">{{enddata.error}}</span>
28
+ {% endif %}
29
+ </div>
30
+ </fieldset>
31
+ {% endif %}
32
+ </div>
@@ -0,0 +1,14 @@
1
+ {#
2
+ FILE UPLOAD COMPONENT
3
+ #}
4
+ {% extends '@components/fieldset/fieldset.twig' %}
5
+ {% set fsinputid = id ? id : name %}
6
+ {% set fslabel = label %}
7
+ {% set fshelper = helper %}
8
+ {% set fserror = error %}
9
+ {% set fstype = "file" %}
10
+ {% set fsclass = "file-upload" %}
11
+
12
+ {% block formfield %}
13
+ <input name="{{name}}" type="file" class="{{prefix}}--file-upload {% if error %} error{% endif %}" {% if placeholder %}placeholder="{{placeholder}}"{% endif %} {% if disabled %}disabled{% endif %} {% if required %}required{% endif %} id="{% if id %}{{id}}{% else %}{{name}}{% endif %}" data-label="{{label}}" data-loadcomponent="FileUpload" />
14
+ {% endblock %}
@@ -0,0 +1,14 @@
1
+ import FileUpload from './fileupload';
2
+
3
+ Drupal.behaviors.fileupload = {
4
+ attach() {
5
+ Array.prototype.forEach.call(
6
+ document.querySelectorAll(`[data-loadcomponent="FileUpload"]`),
7
+ (element) => {
8
+ // eslint-disable-next-line no-console
9
+ console.log('loading FileUpload component....');
10
+ new FileUpload(element);
11
+ }
12
+ );
13
+ },
14
+ };
@@ -0,0 +1,118 @@
1
+ import { getUpdatedItems, EVENTS, ARIA } from '@ilo-org/utils';
2
+
3
+ /**
4
+ * The FileUpload module which handles rendering field labels inline on a form.
5
+ *
6
+ * @class FileUpload
7
+ */
8
+ export default class FileUpload {
9
+ /**
10
+ * FileUpload constructor which assigns the element passed into the constructor
11
+ * to the `this.element` property for later reference
12
+ *
13
+ * @param {HTMLElement} element - REQUIRED - the module's container
14
+ */
15
+ constructor(element) {
16
+ /**
17
+ * Reference to the DOM element that is the root of the component
18
+ * @property {Object}
19
+ */
20
+ this.element = element;
21
+
22
+ // get the theme prefix
23
+ this.prefix = this.element.dataset.prefix;
24
+
25
+ // Initialize the view
26
+ this.init();
27
+ }
28
+
29
+ /**
30
+ * Initializes the view by calling the functions to
31
+ * create DOM references, setup event handlers and
32
+ * then create the event listeners
33
+ *
34
+ * @return {Object} FileUpload A reference to the instance of the class
35
+ * @chainable
36
+ */
37
+ init() {
38
+ this.cacheDomReferences().setupHandlers().enable();
39
+
40
+ return this;
41
+ }
42
+
43
+ /**
44
+ * Find all necessary DOM elements used in the view and cache them
45
+ *
46
+ * @return {Object} FileUpload A reference to the instance of the class
47
+ * @chainable
48
+ */
49
+ cacheDomReferences() {
50
+ /**
51
+ * The button for toggling Read More state
52
+ * @type {Object}
53
+ */
54
+ this.container = this.element.parentElement.parentElement;
55
+
56
+ return this;
57
+ }
58
+
59
+ /**
60
+ * Bind event handlers with the proper context of `this`.
61
+ *
62
+ * @return {Object} FileUpload A reference to the current instance of the class
63
+ * @chainable
64
+ */
65
+ setupHandlers() {
66
+ this.onChange = this.onChange.bind(this);
67
+
68
+ return this;
69
+ }
70
+
71
+ /**
72
+ * Creates event listeners to enable interaction with view
73
+ *
74
+ * @return {Object} FileUpload A reference to the instance of the class
75
+ * @chainable
76
+ */
77
+ enable() {
78
+ this.element.addEventListener(EVENTS.CHANGE, (e) => this.onChange(e));
79
+
80
+ return this;
81
+ }
82
+
83
+ /**
84
+ * onChange interaction with the FileUpload button
85
+ *
86
+ * @return {Object} FileUpload A reference to the instance of the class
87
+ * @chainable
88
+ */
89
+ onChange(e) {
90
+ const oldDiv = this.container.querySelector(`.${this.prefix}--fieldset--input`) !== null;
91
+ if (oldDiv) {
92
+ this.container.remove(oldDiv);
93
+ }
94
+ const newDiv = document.createElement('div');
95
+ newDiv.classList.add(`${this.prefix}--fieldset--input`);
96
+ const fileList = document.createElement('ul');
97
+ fileList.classList.add(`${this.prefix}--file-upload--list`);
98
+ let files = '';
99
+ [...e.target.files].map((file) => {
100
+ files += this.template(file.name);
101
+ });
102
+ fileList.innerHTML = files;
103
+ newDiv.appendChild(fileList);
104
+ this.container.appendChild(newDiv);
105
+
106
+ return this;
107
+ }
108
+
109
+ /**
110
+ * A template for outputting the list item markup
111
+ *
112
+ * @param {String} filename
113
+ * @return {String}
114
+ */
115
+ template(filename) {
116
+ return `<li class="ilo--file-upload--list-item">${filename}</li>`;
117
+ }
118
+ }
@@ -0,0 +1,7 @@
1
+ import './index';
2
+
3
+ const patternDefinition = require('./form.wingsuit.yml');
4
+
5
+ export const wingsuit = {
6
+ patternDefinition,
7
+ };
@@ -0,0 +1,94 @@
1
+ {#
2
+ FORM COMPONENT
3
+ TODO: This could stand to be more DRY
4
+ #}
5
+ <form class="{{prefix}}--form" id="{{formid}}" action="{{action}}" data-loadcomponent="Form">
6
+ {% for item in items %}
7
+ {% if item.type == "formgroup" %}
8
+ <fieldset class="{{prefix}}--formgroup {{prefix}}--fieldset">
9
+ {% if item.field.legend %}
10
+ <legend class="{{prefix}}--formgroup--legend {{item.field.type}}">{{item.field.legend}}
11
+ {% if item.field['grouptooltip'] is defined %}
12
+ {% include '@components/tooltip/tooltip.twig' with {label: item.field.grouptooltip, icon: true, className: prefix ~ "--formgroup--legend--tooltip"} %}
13
+ {% endif %}
14
+ </legend>
15
+ {% endif %}
16
+ {% for i in item.field.items %}
17
+ {% if i.type == "radio" or (i.type == "checkbox" and i.field[0].grouped == true) %}
18
+ <fieldset class="{{prefix}}--choice-group {{prefix}}--fieldset">
19
+ {% if i.legend %}
20
+ <legend class="{{prefix}}--fieldset--legend">{{i.legend}}
21
+ {% if i.grouptooltip is defined %}
22
+ {% include '@components/tooltip/tooltip.twig' with {label: i.grouptooltip.label, icon: i.grouptooltip.icon, theme: i.grouptooltip.theme, className: prefix ~ "--fieldset--legend--tooltip"} %}
23
+ {% endif %}
24
+ </legend>
25
+ {% endif %}
26
+ {% if i.grouphelper and not i.grouperror %}
27
+ <span class="{{prefix}}--fieldset--helper">{{i.grouphelper}}</span>
28
+ {% endif %}
29
+ {% if i.grouperror %}
30
+ <span class="{{prefix}}--fieldset--error">{{i.grouperror}}</span>
31
+ {% endif %}
32
+ {% for f in i.field %}
33
+ <div class="{{prefix}}--fieldset--input--{{i.type}}">
34
+ <label class="{{prefix}}--fieldset--label" for="{% if f.id %}{{f.id}}{% else %}{{f.name}}{% endif %}">{{f.label}}</label>
35
+ {% if i.type == "radio" %}
36
+ {% include '@components/form/radio.twig' with f %}
37
+ {% else %}
38
+ {% include '@components/form/checkboxgroup.twig' with f %}
39
+ {% endif %}
40
+ </div>
41
+ {% endfor %}
42
+ </fieldset>
43
+ {% elseif i.type == "date" %}
44
+ {% include '@components/form/datepicker.twig' with i.field %}
45
+ {% else %}
46
+ {% if i.type == "input" or (i.type == "checkbox" and not i.field[0].grouped) or i.type == "file" or i.type == "number" or i.type == "textarea" %}
47
+ {% include '@components/form/'~ i.type ~'.twig' with i.field %}
48
+ {% endif %}
49
+ {% if i.type == "dropdown" %}
50
+ {% include '@components/dropdown/dropdown.twig' with i.field %}
51
+ {% endif %}
52
+ {% endif %}
53
+ {% endfor %}
54
+ </fieldset>
55
+ {% endif %}
56
+ {% if item.type == "radio" or (item.type == "checkbox" and item.field[0].grouped == true) %}
57
+ <fieldset class="{{prefix}}--choice-group {{prefix}}--fieldset">
58
+ {% if item.legend %}
59
+ <legend class="{{prefix}}--fieldset--legend">{{item.legend}}
60
+ {% if item.grouptooltip is defined %}
61
+ {% include '@components/tooltip/tooltip.twig' with {label: item.grouptooltip.label, icon: item.grouptooltip.icon, theme: item.grouptooltip.theme, className: prefix ~ "--fieldset--legend--tooltip"} %}
62
+ {% endif %}
63
+ </legend>
64
+ {% endif %}
65
+ {% if item.grouphelper and not item.grouperror %}
66
+ <span class="{{prefix}}--fieldset--helper">{{item.grouphelper}}</span>
67
+ {% endif %}
68
+ {% if item.grouperror %}
69
+ <span class="{{prefix}}--fieldset--error">{{item.grouperror}}</span>
70
+ {% endif %}
71
+ {% for f in item.field %}
72
+ <div class="{{prefix}}--fieldset--input--{{item.type}}">
73
+ <label class="{{prefix}}--fieldset--label" for="{% if f.id %}{{f.id}}{% else %}{{f.name}}{% endif %}">{{f.label}}</label>
74
+ {% if item.type == "radio" %}
75
+ {% include '@components/form/radio.twig' with f %}
76
+ {% else %}
77
+ {% include '@components/form/checkboxgroup.twig' with f %}
78
+ {% endif %}
79
+ </div>
80
+ {% endfor %}
81
+ </fieldset>
82
+ {% elseif item.type == "date" %}
83
+ {% include '@components/form/datepicker.twig' with item.field %}
84
+ {% else %}
85
+ {% if item.type == "input" or (item.type == "checkbox" and not item.field[0].grouped) or item.type == "file" or item.type == "number" or item.type == "textarea" %}
86
+ {% include '@components/form/'~ item.type ~'.twig' with item.field %}
87
+ {% endif %}
88
+ {% if item.type == "dropdown" %}
89
+ {% include '@components/dropdown/dropdown.twig' with item.field %}
90
+ {% endif %}
91
+ {% endif %}
92
+ {% endfor %}
93
+ {% include '@components/button/button.twig' with {type: "primary", kind: "submit", size: "large", label: submitlabel} %}
94
+ </form>