@govtechsg/sgds-web-component 0.0.10 → 0.0.12

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 (338) hide show
  1. package/README.md +102 -10
  2. package/base/card-element.d.ts +12 -0
  3. package/{lib/utils → base}/dropdown-element.d.ts +38 -37
  4. package/{lib/utils → base}/link-element.d.ts +8 -7
  5. package/{lib/utils → base}/sgds-element.d.ts +6 -5
  6. package/components/Accordion/index.d.ts +2 -0
  7. package/components/Accordion/sgds-accordion-item.d.ts +40 -0
  8. package/components/Accordion/sgds-accordion.d.ts +19 -0
  9. package/components/ActionCard/index.d.ts +1 -0
  10. package/{lib/Card → components/ActionCard}/sgds-action-card.d.ts +21 -20
  11. package/components/Alert/index.d.ts +1 -0
  12. package/components/Alert/sgds-alert.d.ts +37 -0
  13. package/components/Badge/index.d.ts +1 -0
  14. package/components/Badge/sgds-badge.d.ts +10 -0
  15. package/components/Breadcrumb/index.d.ts +2 -0
  16. package/components/Breadcrumb/sgds-breadcrumb-item.d.ts +10 -0
  17. package/components/Breadcrumb/sgds-breadcrumb.d.ts +12 -0
  18. package/components/Button/index.d.ts +1 -0
  19. package/{lib → components}/Button/sgds-button.d.ts +55 -48
  20. package/components/Checkbox/index.d.ts +1 -0
  21. package/{lib → components}/Checkbox/sgds-checkbox.d.ts +36 -36
  22. package/components/CloseButton/index.d.ts +1 -0
  23. package/components/CloseButton/sgds-closebutton.d.ts +9 -0
  24. package/components/Dropdown/index.d.ts +3 -0
  25. package/{lib → components}/Dropdown/sgds-dropdown-item.d.ts +8 -7
  26. package/{lib → components}/Dropdown/sgds-dropdown.d.ts +8 -7
  27. package/components/FileUpload/index.d.ts +1 -0
  28. package/components/FileUpload/sgds-fileupload.d.ts +22 -0
  29. package/components/Footer/index.d.ts +1 -0
  30. package/{lib → components}/Footer/sgds-footer.d.ts +27 -23
  31. package/components/Input/index.d.ts +1 -0
  32. package/{lib → components}/Input/sgds-input.d.ts +42 -42
  33. package/components/Mainnav/index.d.ts +3 -0
  34. package/components/Mainnav/sgds-mainnav-dropdown.d.ts +6 -0
  35. package/components/Mainnav/sgds-mainnav-item.d.ts +8 -0
  36. package/{lib → components}/Mainnav/sgds-mainnav.d.ts +26 -22
  37. package/components/Masthead/index.d.ts +1 -0
  38. package/{lib → components}/Masthead/sgds-masthead.d.ts +9 -12
  39. package/components/Modal/index.d.ts +1 -0
  40. package/{lib → components}/Modal/sgds-modal.d.ts +28 -28
  41. package/components/QuantityToggle/index.d.ts +1 -0
  42. package/{lib/QuantityToggle/sgds-quantitytoggle.d.ts → components/QuantityToggle/sgds-quantity-toggle.d.ts} +30 -30
  43. package/components/Radio/index.d.ts +2 -0
  44. package/{lib/Radio/sgds-radiogroup.d.ts → components/Radio/sgds-radio-group.d.ts} +41 -41
  45. package/{lib → components}/Radio/sgds-radio.d.ts +31 -31
  46. package/components/Sidenav/index.d.ts +3 -0
  47. package/{lib → components}/Sidenav/sgds-sidenav-item.d.ts +36 -28
  48. package/components/Sidenav/sgds-sidenav-link.d.ts +8 -0
  49. package/{lib → components}/Sidenav/sgds-sidenav.d.ts +10 -6
  50. package/components/Stepper/index.d.ts +1 -0
  51. package/components/Stepper/sgds-stepper.d.ts +17 -0
  52. package/components/Tab/index.d.ts +3 -0
  53. package/{lib → components}/Tab/sgds-tab.d.ts +27 -26
  54. package/{lib → components}/Tab/sgds-tabgroup.d.ts +48 -47
  55. package/{lib → components}/Tab/sgds-tabpanel.d.ts +26 -25
  56. package/components/Table/index.d.ts +1 -0
  57. package/components/Table/sgds-table.d.ts +26 -0
  58. package/components/Textarea/index.d.ts +1 -0
  59. package/{lib → components}/Textarea/sgds-textarea.d.ts +53 -53
  60. package/components/Toast/index.d.ts +1 -0
  61. package/components/Toast/sgds-toast.d.ts +22 -0
  62. package/components/Tooltip/index.d.ts +1 -0
  63. package/components/Tooltip/sgds-tooltip.d.ts +30 -0
  64. package/index.d.ts +23 -0
  65. package/index.js +11543 -0
  66. package/index.js.map +1 -0
  67. package/main.d.ts +24 -0
  68. package/package.json +23 -65
  69. package/react/accordion/index.d.ts +3 -0
  70. package/react/accordion-item/index.d.ts +8 -0
  71. package/react/action-card/index.d.ts +3 -0
  72. package/react/alert/index.d.ts +3 -0
  73. package/react/badge/index.d.ts +3 -0
  74. package/react/breadcrumb/index.d.ts +3 -0
  75. package/react/breadcrumb-item/index.d.ts +3 -0
  76. package/react/button/index.d.ts +6 -0
  77. package/react/checkbox/index.d.ts +3 -0
  78. package/react/cjs/index.js +12510 -0
  79. package/react/cjs/index.js.map +1 -0
  80. package/react/closebutton/index.d.ts +5 -0
  81. package/react/dropdown/index.d.ts +3 -0
  82. package/react/dropdown-item/index.d.ts +3 -0
  83. package/react/fileupload/index.d.ts +3 -0
  84. package/react/footer/index.d.ts +3 -0
  85. package/react/index.d.ts +34 -0
  86. package/react/index.js +12453 -0
  87. package/react/index.js.map +1 -0
  88. package/react/input/index.d.ts +3 -0
  89. package/react/mainnav/index.d.ts +3 -0
  90. package/react/mainnav-dropdown/index.d.ts +3 -0
  91. package/react/mainnav-item/index.d.ts +3 -0
  92. package/react/masthead/index.d.ts +3 -0
  93. package/react/modal/index.d.ts +3 -0
  94. package/react/package.json +10 -0
  95. package/react/quantity-toggle/index.d.ts +3 -0
  96. package/react/radio/index.d.ts +3 -0
  97. package/react/radio-group/index.d.ts +3 -0
  98. package/react/sidenav/index.d.ts +3 -0
  99. package/react/sidenav-item/index.d.ts +5 -0
  100. package/react/sidenav-link/index.d.ts +3 -0
  101. package/react/stepper/index.d.ts +3 -0
  102. package/react/tab/index.d.ts +3 -0
  103. package/react/tab-group/index.d.ts +3 -0
  104. package/react/tab-panel/index.d.ts +3 -0
  105. package/react/table/index.d.ts +3 -0
  106. package/react/textarea/index.d.ts +3 -0
  107. package/react/toast/index.d.ts +3 -0
  108. package/react/tooltip/index.d.ts +3 -0
  109. package/umd/index.js +11995 -0
  110. package/umd/index.js.map +1 -0
  111. package/{lib/utils → utils}/animate.d.ts +10 -10
  112. package/{lib/utils → utils}/animation-registry.d.ts +18 -18
  113. package/{lib/utils → utils}/breakpoints.d.ts +5 -5
  114. package/{lib/utils → utils}/defaultvalue.d.ts +2 -2
  115. package/{lib/utils → utils}/event.d.ts +2 -2
  116. package/{lib/utils → utils}/form.d.ts +38 -38
  117. package/{lib/utils → utils}/generateId.d.ts +1 -1
  118. package/{lib/utils → utils}/mergeDeep.d.ts +2 -2
  119. package/{lib/utils → utils}/modal.d.ts +12 -12
  120. package/{lib/utils → utils}/object.d.ts +2 -2
  121. package/{lib/utils → utils}/offset.d.ts +4 -4
  122. package/{lib/utils → utils}/scroll.d.ts +13 -13
  123. package/{lib/utils → utils}/slot.d.ts +22 -22
  124. package/{lib/utils → utils}/tabbable.d.ts +8 -8
  125. package/{lib/utils → utils}/watch.d.ts +14 -14
  126. package/.github/workflows/publish-latest.yml +0 -22
  127. package/.github/workflows/publish-pr.yml +0 -28
  128. package/.husky/commit-msg +0 -4
  129. package/.husky/prepare-commit-msg +0 -8
  130. package/.storybook/main.js +0 -16
  131. package/.storybook/preview-head.html +0 -11
  132. package/.storybook/preview.js +0 -9
  133. package/.vscode/settings.json +0 -7
  134. package/CONTRIBUTING.md +0 -56
  135. package/LICENSE +0 -20
  136. package/amplify.yml +0 -22
  137. package/commitlint.config.js +0 -1
  138. package/coverage/lcov-report/base.css +0 -224
  139. package/coverage/lcov-report/block-navigation.js +0 -87
  140. package/coverage/lcov-report/button-element.scss.html +0 -112
  141. package/coverage/lcov-report/button-element.ts.html +0 -145
  142. package/coverage/lcov-report/favicon.png +0 -0
  143. package/coverage/lcov-report/index.html +0 -116
  144. package/coverage/lcov-report/prettify.css +0 -1
  145. package/coverage/lcov-report/prettify.js +0 -2
  146. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  147. package/coverage/lcov-report/sorter.js +0 -196
  148. package/coverage/lcov.info +0 -32
  149. package/index.html +0 -430
  150. package/lib/Button/index.d.ts +0 -1
  151. package/lib/Button/index.js +0 -6634
  152. package/lib/Button/index.js.map +0 -1
  153. package/lib/Button/package.json +0 -7
  154. package/lib/Card/index.d.ts +0 -1
  155. package/lib/Card/index.js +0 -6150
  156. package/lib/Card/index.js.map +0 -1
  157. package/lib/Card/package.json +0 -7
  158. package/lib/Checkbox/index.d.ts +0 -1
  159. package/lib/Checkbox/index.js +0 -6366
  160. package/lib/Checkbox/index.js.map +0 -1
  161. package/lib/Checkbox/package.json +0 -7
  162. package/lib/Dropdown/index.d.ts +0 -3
  163. package/lib/Dropdown/index.js +0 -13502
  164. package/lib/Dropdown/index.js.map +0 -1
  165. package/lib/Dropdown/package.json +0 -7
  166. package/lib/Footer/index.d.ts +0 -2
  167. package/lib/Footer/index.js +0 -7168
  168. package/lib/Footer/index.js.map +0 -1
  169. package/lib/Footer/package.json +0 -7
  170. package/lib/Input/index.d.ts +0 -1
  171. package/lib/Input/index.js +0 -6656
  172. package/lib/Input/index.js.map +0 -1
  173. package/lib/Input/package.json +0 -7
  174. package/lib/Mainnav/index.d.ts +0 -4
  175. package/lib/Mainnav/index.js +0 -32546
  176. package/lib/Mainnav/index.js.map +0 -1
  177. package/lib/Mainnav/package.json +0 -7
  178. package/lib/Mainnav/sgds-mainnav-dropdown.d.ts +0 -5
  179. package/lib/Mainnav/sgds-mainnav-item.d.ts +0 -4
  180. package/lib/Masthead/index.d.ts +0 -1
  181. package/lib/Masthead/index.js +0 -7371
  182. package/lib/Masthead/index.js.map +0 -1
  183. package/lib/Masthead/package.json +0 -7
  184. package/lib/Modal/index.d.ts +0 -1
  185. package/lib/Modal/index.js +0 -6432
  186. package/lib/Modal/index.js.map +0 -1
  187. package/lib/Modal/package.json +0 -7
  188. package/lib/QuantityToggle/index.d.ts +0 -1
  189. package/lib/QuantityToggle/index.js +0 -7049
  190. package/lib/QuantityToggle/index.js.map +0 -1
  191. package/lib/QuantityToggle/package.json +0 -7
  192. package/lib/Radio/index.d.ts +0 -2
  193. package/lib/Radio/index.js +0 -12607
  194. package/lib/Radio/index.js.map +0 -1
  195. package/lib/Radio/package.json +0 -7
  196. package/lib/Sidenav/index.d.ts +0 -3
  197. package/lib/Sidenav/index.js +0 -18739
  198. package/lib/Sidenav/index.js.map +0 -1
  199. package/lib/Sidenav/package.json +0 -7
  200. package/lib/Sidenav/sgds-sidenav-link.d.ts +0 -4
  201. package/lib/Tab/index.d.ts +0 -3
  202. package/lib/Tab/index.js +0 -13557
  203. package/lib/Tab/index.js.map +0 -1
  204. package/lib/Tab/package.json +0 -7
  205. package/lib/Textarea/index.d.ts +0 -1
  206. package/lib/Textarea/index.js +0 -6696
  207. package/lib/Textarea/index.js.map +0 -1
  208. package/lib/Textarea/package.json +0 -7
  209. package/lib/index.d.ts +0 -16
  210. package/lib/index.js +0 -134580
  211. package/lib/index.js.map +0 -1
  212. package/lib/umd/index.js +0 -134587
  213. package/lib/umd/index.js.map +0 -1
  214. package/lib/utils/card-element.d.ts +0 -11
  215. package/mocks/dropdown.d.ts +0 -4
  216. package/mocks/dropdown.ts +0 -27
  217. package/mocks/link.d.ts +0 -3
  218. package/mocks/link.ts +0 -6
  219. package/rollup.config.js +0 -73
  220. package/rollup.test.config.js +0 -42
  221. package/scripts/buildUtils.js +0 -30
  222. package/scripts/frankBuild.js +0 -49
  223. package/src/Button/index.ts +0 -1
  224. package/src/Button/sgds-button.scss +0 -28
  225. package/src/Button/sgds-button.ts +0 -153
  226. package/src/Card/index.ts +0 -1
  227. package/src/Card/sgds-action-card.scss +0 -27
  228. package/src/Card/sgds-action-card.ts +0 -115
  229. package/src/Checkbox/index.ts +0 -1
  230. package/src/Checkbox/sgds-checkbox.scss +0 -4
  231. package/src/Checkbox/sgds-checkbox.ts +0 -149
  232. package/src/Dropdown/index.ts +0 -3
  233. package/src/Dropdown/sgds-dropdown-item.ts +0 -39
  234. package/src/Dropdown/sgds-dropdown.scss +0 -5
  235. package/src/Dropdown/sgds-dropdown.ts +0 -54
  236. package/src/Footer/index.ts +0 -3
  237. package/src/Footer/sgds-footer.scss +0 -5
  238. package/src/Footer/sgds-footer.ts +0 -121
  239. package/src/Input/index.ts +0 -1
  240. package/src/Input/sgds-input.scss +0 -20
  241. package/src/Input/sgds-input.ts +0 -178
  242. package/src/Mainnav/index.ts +0 -4
  243. package/src/Mainnav/sgds-mainnav-dropdown.scss +0 -13
  244. package/src/Mainnav/sgds-mainnav-dropdown.ts +0 -45
  245. package/src/Mainnav/sgds-mainnav-item.scss +0 -24
  246. package/src/Mainnav/sgds-mainnav-item.ts +0 -8
  247. package/src/Mainnav/sgds-mainnav.scss +0 -39
  248. package/src/Mainnav/sgds-mainnav.ts +0 -183
  249. package/src/Masthead/index.ts +0 -1
  250. package/src/Masthead/sgds-masthead.scss +0 -217
  251. package/src/Masthead/sgds-masthead.ts +0 -189
  252. package/src/Modal/index.ts +0 -1
  253. package/src/Modal/sgds-modal.scss +0 -128
  254. package/src/Modal/sgds-modal.ts +0 -309
  255. package/src/QuantityToggle/index.ts +0 -1
  256. package/src/QuantityToggle/sgds-quantitytoggle.scss +0 -10
  257. package/src/QuantityToggle/sgds-quantitytoggle.ts +0 -130
  258. package/src/Radio/index.ts +0 -2
  259. package/src/Radio/sgds-radio.scss +0 -5
  260. package/src/Radio/sgds-radio.ts +0 -120
  261. package/src/Radio/sgds-radiogroup.scss +0 -22
  262. package/src/Radio/sgds-radiogroup.ts +0 -221
  263. package/src/Sidenav/index.ts +0 -4
  264. package/src/Sidenav/sgds-sidenav-item.scss +0 -73
  265. package/src/Sidenav/sgds-sidenav-item.ts +0 -145
  266. package/src/Sidenav/sgds-sidenav-link.scss +0 -25
  267. package/src/Sidenav/sgds-sidenav-link.ts +0 -8
  268. package/src/Sidenav/sgds-sidenav.scss +0 -6
  269. package/src/Sidenav/sgds-sidenav.ts +0 -33
  270. package/src/Tab/index.ts +0 -3
  271. package/src/Tab/sgds-tab.scss +0 -84
  272. package/src/Tab/sgds-tab.ts +0 -87
  273. package/src/Tab/sgds-tabgroup.scss +0 -198
  274. package/src/Tab/sgds-tabgroup.ts +0 -295
  275. package/src/Tab/sgds-tabpanel.scss +0 -12
  276. package/src/Tab/sgds-tabpanel.ts +0 -55
  277. package/src/Textarea/index.ts +0 -1
  278. package/src/Textarea/sgds-textarea.scss +0 -23
  279. package/src/Textarea/sgds-textarea.ts +0 -201
  280. package/src/index.ts +0 -16
  281. package/src/utils/animate.ts +0 -69
  282. package/src/utils/animation-registry.ts +0 -71
  283. package/src/utils/base.scss +0 -14
  284. package/src/utils/breakpoints.ts +0 -5
  285. package/src/utils/card-element.ts +0 -42
  286. package/src/utils/components.style.scss +0 -531
  287. package/src/utils/defaultvalue.ts +0 -51
  288. package/src/utils/dropdown-element.ts +0 -244
  289. package/src/utils/event.ts +0 -13
  290. package/src/utils/form.ts +0 -183
  291. package/src/utils/generateId.ts +0 -4
  292. package/src/utils/link-element.ts +0 -34
  293. package/src/utils/mergeDeep.ts +0 -22
  294. package/src/utils/modal.ts +0 -64
  295. package/src/utils/object.ts +0 -2
  296. package/src/utils/offset.ts +0 -6
  297. package/src/utils/scroll.ts +0 -57
  298. package/src/utils/sgds-element.ts +0 -18
  299. package/src/utils/slot.ts +0 -102
  300. package/src/utils/tabbable.ts +0 -81
  301. package/src/utils/watch.ts +0 -62
  302. package/stories/ActionCard.stories.mdx +0 -199
  303. package/stories/Button.stories.mdx +0 -194
  304. package/stories/Checkbox.stories.mdx +0 -196
  305. package/stories/Dropdown.stories.mdx +0 -152
  306. package/stories/Footer.stories.mdx +0 -261
  307. package/stories/Input.stories.mdx +0 -236
  308. package/stories/MainNav.stories.mdx +0 -169
  309. package/stories/Masthead.stories.mdx +0 -112
  310. package/stories/Modal.stories.mdx +0 -103
  311. package/stories/QuantityToggle.stories.mdx +0 -97
  312. package/stories/Radio.stories.mdx +0 -262
  313. package/stories/Sample.stories.js +0 -29
  314. package/stories/Sample.stories.mdx +0 -33
  315. package/stories/SideNav.stories.mdx +0 -245
  316. package/stories/common.js +0 -185
  317. package/stories/textarea.stories.mdx +0 -253
  318. package/test/button.element.test.ts +0 -185
  319. package/test/checkbox.test.ts +0 -240
  320. package/test/dropdown.test.ts +0 -637
  321. package/test/footer.test.ts +0 -181
  322. package/test/generateId.test.ts +0 -18
  323. package/test/input.element.test.ts +0 -316
  324. package/test/link-element.test.ts +0 -38
  325. package/test/mainnav.test.ts +0 -313
  326. package/test/masthead.test.ts +0 -116
  327. package/test/modal.test.ts +0 -149
  328. package/test/quantitytoggle.test.ts +0 -76
  329. package/test/radio.test.ts +0 -310
  330. package/test/selectable-card.test.ts +0 -159
  331. package/test/sidenav.test.ts +0 -390
  332. package/test/tab.test.ts +0 -76
  333. package/test/textarea.test.ts +0 -126
  334. package/tsconfig.json +0 -26
  335. package/tsconfig.test.json +0 -24
  336. package/typings/scss.d.ts +0 -5
  337. package/web-dev-server.config.mjs +0 -7
  338. package/web-test-runner.config.mjs +0 -47
@@ -1,128 +0,0 @@
1
- @import '../utils/base.scss';
2
-
3
- :host {
4
- --sgds-modal-width: 35rem;
5
- --sgds-modal-z-index: 1055;
6
- --sgds-modal-padding: 1.5rem;
7
- --sgds-modal-border-radius: 5px;
8
-
9
- --sgds-modal-border-width: 1px;
10
- --sgds-modal-overlay-color:rgba(0,0,0,0.5);
11
- display: contents;
12
- }
13
-
14
- [hidden] {
15
- display: none !important;
16
- }
17
-
18
- .modal {
19
- display: flex;
20
- align-items: center;
21
- justify-content: center;
22
- position: fixed;
23
- top: 0;
24
- right: 0;
25
- bottom: 0;
26
- left: 0;
27
- z-index: 1050;
28
- font-family: var(--sgds-body-font-family);
29
- }
30
-
31
- .modal-panel {
32
- display: flex;
33
- flex-direction: column;
34
- z-index: var(--sgds-modal-z-index);
35
- width: var(--sgds-modal-width);
36
- max-width: calc(100% - 2.25rem);
37
- max-height: calc(100% - 2.25rem);
38
- background-color: white;
39
- border-radius: var(--sgds-modal-border-radius);
40
- }
41
-
42
- .modal-panel:focus {
43
- outline: none;
44
- }
45
-
46
- /* Ensure there's enough vertical padding for phones that don't update vh when chrome appears (e.g. iPhone) */
47
- @media screen and (max-width: 420px) {
48
- .modal-panel {
49
- max-height: 80vh;
50
- }
51
- }
52
-
53
- .modal--open .modal-panel {
54
- display: flex;
55
- opacity: 1;
56
- transform: none;
57
- }
58
-
59
- .modal-header {
60
- flex: 0 0 auto;
61
- display: flex;
62
- padding: var(--sgds-modal-padding);
63
- align-items: center;
64
- border-bottom: var(--sgds-modal-border-width) solid var(--sgds-gray-400, #98a2b3);
65
- &.centered{
66
- @extend .border-bottom-0;
67
- @extend .pb-0;
68
- @extend .mb-0;
69
-
70
- }
71
- }
72
-
73
- .modal-title {
74
- flex: 1 1 auto;
75
- @extend .h3;
76
- @extend .gap-3;
77
- margin: 0;
78
- &.centered{
79
- @extend .justify-content-center;
80
- @extend .flex-column;
81
- @extend .text-center;
82
- margin-left: 3rem;
83
- }
84
- }
85
-
86
- .modal-close {
87
- flex: 0 0 auto;
88
- display: flex;
89
- align-items: center;
90
- &.centered{
91
- @extend .align-self-start;
92
- margin-top: -0.5rem;
93
- }
94
- }
95
-
96
- .modal-body {
97
- flex: 1 1 auto;
98
- padding: var(--sgds-modal-padding);
99
- overflow: auto;
100
- -webkit-overflow-scrolling: touch;
101
- }
102
-
103
- .modal-footer {
104
- flex: 0 0 auto;
105
- text-align: right;
106
- padding: var(--sgds-modal-padding);
107
- padding-top:0;
108
- &.centered{
109
- text-align: center;
110
- }
111
- }
112
-
113
- .modal-footer ::slotted(sgds-button) {
114
- margin-inline-start: 0.5rem;
115
- }
116
-
117
- .modal:not(.modal--has-footer) .modal-footer {
118
- display: none;
119
- }
120
-
121
- .modal-overlay {
122
- position: fixed;
123
- top: 0;
124
- right: 0;
125
- bottom: 0;
126
- left: 0;
127
- background-color: var(--sgds-modal-overlay-color);
128
- }
@@ -1,309 +0,0 @@
1
- import { html } from 'lit';
2
- import { customElement, property, query } from 'lit/decorators.js';
3
- import { classMap } from 'lit/directives/class-map.js';
4
- import { ifDefined } from 'lit/directives/if-defined.js';
5
- import { animateTo, stopAnimations } from '../utils/animate';
6
- import { waitForEvent } from '../utils/event';
7
- import Modal from '../utils/modal';
8
- import { lockBodyScrolling, unlockBodyScrolling } from '../utils/scroll';
9
- import SgdsElement from "../utils/sgds-element";
10
- import { HasSlotController } from '../utils/slot';
11
- import { watch } from '../utils/watch';
12
- import { getAnimation, setDefaultAnimation } from '../utils/animation-registry';
13
- import styles from "./sgds-modal.scss";
14
-
15
-
16
- @customElement('sgds-modal')
17
- export class SgdsModal extends SgdsElement {
18
-
19
- static styles = styles;
20
-
21
- @query('.modal') dialog: HTMLElement;
22
- @query('.modal-panel') panel: HTMLElement;
23
- @query('.modal-overlay') overlay: HTMLElement;
24
-
25
- private readonly hasSlotController = new HasSlotController(this, 'footer');
26
- private modal: Modal;
27
- private originalTrigger: HTMLElement | null;
28
-
29
- @property({ type: Boolean, reflect: true }) open = false;
30
- // @property({ type: Boolean, reflect: true }) centeredAlignVariant = false;
31
-
32
- @property({ reflect: true }) title = '';
33
- @property({ reflect: true }) titleIcon = '';
34
- @property({ attribute: 'no-header', type: Boolean, reflect: true }) noHeader = false;
35
-
36
- connectedCallback() {
37
- super.connectedCallback();
38
- this.handleDocumentKeyDown = this.handleDocumentKeyDown.bind(this);
39
- this.modal = new Modal(this);
40
- }
41
-
42
- firstUpdated() {
43
- this.dialog.hidden = !this.open;
44
-
45
- if (this.open) {
46
- this.addOpenListeners();
47
- this.modal.activate();
48
- lockBodyScrolling(this);
49
- }
50
- }
51
-
52
- disconnectedCallback() {
53
- super.disconnectedCallback();
54
- unlockBodyScrolling(this);
55
- }
56
-
57
- /** Shows the dialog. */
58
- async show() {
59
- if (this.open) {
60
- return undefined;
61
- }
62
-
63
- this.open = true;
64
- return waitForEvent(this, 'sgds-after-show');
65
- }
66
-
67
- /** Hides the dialog */
68
- async hide() {
69
- if (!this.open) {
70
- return undefined;
71
- }
72
-
73
- this.open = false;
74
- return waitForEvent(this, 'sgds-after-hide');
75
- }
76
-
77
- private requestClose(source: 'close-button' | 'keyboard' | 'overlay') {
78
- const slRequestClose = this.emit('sgds-request-close', {
79
- cancelable: true,
80
- detail: { source }
81
- });
82
-
83
- if (slRequestClose.defaultPrevented) {
84
- const animation = getAnimation(this, 'modal.denyClose');
85
- animateTo(this.panel, animation.keyframes);
86
- return;
87
- }
88
-
89
- this.hide();
90
- }
91
-
92
- addOpenListeners() {
93
- document.addEventListener('keydown', this.handleDocumentKeyDown);
94
- }
95
-
96
- removeOpenListeners() {
97
- document.removeEventListener('keydown', this.handleDocumentKeyDown);
98
- }
99
-
100
- handleDocumentKeyDown(event: KeyboardEvent) {
101
- if (this.open && event.key === 'Escape') {
102
- event.stopPropagation();
103
- this.requestClose('keyboard');
104
- }
105
- }
106
-
107
- @watch('open', { waitUntilFirstUpdate: true })
108
- async handleOpenChange() {
109
- if (this.open) {
110
- // Show
111
- this.emit('sgds-show');
112
- this.addOpenListeners();
113
- this.originalTrigger = document.activeElement as HTMLElement;
114
- this.modal.activate();
115
-
116
- lockBodyScrolling(this);
117
-
118
- // When the dialog is shown, Safari will attempt to set focus on whatever element has autofocus. This can cause
119
- // the dialogs's animation to jitter (if it starts offscreen), so we'll temporarily remove the attribute, call
120
- // `focus({ preventScroll: true })` ourselves, and add the attribute back afterwards.
121
- //
122
- // Related: https://github.com/shoelace-style/shoelace/issues/693
123
- //
124
- const autoFocusTarget = this.querySelector('[autofocus]');
125
- if (autoFocusTarget) {
126
- autoFocusTarget.removeAttribute('autofocus');
127
- }
128
-
129
- await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]);
130
- this.dialog.hidden = false;
131
-
132
- // Set initial focus
133
- requestAnimationFrame(() => {
134
- const slInitialFocus = this.emit('sgds-initial-focus', { cancelable: true });
135
-
136
- if (!slInitialFocus.defaultPrevented) {
137
- // Set focus to the autofocus target and restore the attribute
138
- if (autoFocusTarget) {
139
- (autoFocusTarget as HTMLInputElement).focus({ preventScroll: true });
140
- } else {
141
- this.panel.focus({ preventScroll: true });
142
- }
143
- }
144
-
145
- // Restore the autofocus attribute
146
- if (autoFocusTarget) {
147
- autoFocusTarget.setAttribute('autofocus', '');
148
- }
149
- });
150
-
151
- const panelAnimation = getAnimation(this, 'modal.show');
152
- const overlayAnimation = getAnimation(this, 'modal.overlay.show');
153
- await Promise.all([
154
- animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options),
155
- animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options)
156
- ]);
157
-
158
- this.emit('sgds-after-show');
159
- } else {
160
- // Hide
161
- this.emit('sgds-hide');
162
- this.removeOpenListeners();
163
- this.modal.deactivate();
164
-
165
- await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]);
166
- const panelAnimation = getAnimation(this, 'modal.hide');
167
- const overlayAnimation = getAnimation(this, 'modal.overlay.hide');
168
-
169
- // Animate the overlay and the panel at the same time. Because animation durations might be different, we need to
170
- // hide each one individually when the animation finishes, otherwise the first one that finishes will reappear
171
- // unexpectedly. We'll unhide them after all animations have completed.
172
- await Promise.all([
173
- animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options).then(() => {
174
- this.overlay.hidden = true;
175
- }),
176
- animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options).then(() => {
177
- this.panel.hidden = true;
178
- })
179
- ]);
180
-
181
- this.dialog.hidden = true;
182
-
183
- // Now that the dialog is hidden, restore the overlay and panel for next time
184
- this.overlay.hidden = false;
185
- this.panel.hidden = false;
186
-
187
- unlockBodyScrolling(this);
188
-
189
- // Restore focus to the original trigger
190
- const trigger = this.originalTrigger;
191
- if (typeof trigger?.focus === 'function') {
192
- setTimeout(() => trigger.focus());
193
- }
194
-
195
- this.emit('sgds-after-hide');
196
- }
197
- }
198
-
199
- render() {
200
- // if label is defined
201
- const withLabelIcon = html`
202
- <sl-icon name=${this.titleIcon} class="pe-2 flex-shrink-0"></sl-icon>`
203
-
204
- return html`
205
- <div
206
- part="base"
207
- class=${classMap({
208
- modal: true,
209
- 'modal--open': this.open,
210
- 'modal--has-footer': this.hasSlotController.test('footer')
211
- })}
212
- >
213
- <div part="overlay" class="modal-overlay" @click=${() => this.requestClose('overlay')} tabindex="-1"></div>
214
-
215
- <div
216
- part="panel"
217
- class="modal-panel"
218
- role="dialog"
219
- aria-modal="true"
220
- aria-hidden=${this.open ? 'false' : 'true'}
221
- aria-label=${ifDefined(this.noHeader ? this.title : undefined)}
222
- aria-labelledby=${ifDefined(!this.noHeader ? 'title' : undefined)}
223
- tabindex="0"
224
- >
225
- ${!this.noHeader
226
- ? html`
227
- <h3 part="header"
228
- class=${classMap({
229
- 'modal-header' : true,
230
- // centered: this.centeredAlignVariant,
231
- })}
232
- >
233
- <div
234
- part="title"
235
- class=${classMap({
236
- 'modal-title d-flex align-items-center': true,
237
- // centered : this.centeredAlignVariant,
238
- })}
239
- id="title"
240
- >
241
- ${this.titleIcon ? withLabelIcon : null}
242
- ${this.title.length > 0 ? this.title : String.fromCharCode(65279)}
243
-
244
- </div>
245
- <sgds-button
246
- part="close-button"
247
- variant="icon"
248
- exportparts="base:close-button__base"
249
- class=${classMap({
250
- 'modal-close': true,
251
- // 'centered': this.centeredAlignVariant,
252
- })}
253
- @click="${() => this.requestClose('close-button')}"
254
- ><sl-icon name="x-lg"></sl-icon></sgds-button>
255
- </h3>
256
- `
257
- : ''}
258
-
259
- <div part="body" class="modal-body">
260
- <slot></slot>
261
- </div>
262
-
263
- <footer
264
- part="footer"
265
- class=${classMap({
266
- 'modal-footer': true,
267
- // centered: this.centeredAlignVariant,
268
- })}
269
- >
270
- <slot name="footer"></slot>
271
- </footer>
272
- </div>
273
- </div>
274
- `;
275
- }
276
- }
277
-
278
- setDefaultAnimation('modal.show', {
279
- keyframes: [
280
- { opacity: 0, transform: 'scale(0.8)' },
281
- { opacity: 1, transform: 'scale(1)' }
282
- ],
283
- options: { duration: 250, easing: 'ease' }
284
- });
285
-
286
- setDefaultAnimation('modal.hide', {
287
- keyframes: [
288
- { opacity: 1, transform: 'scale(1)' },
289
- { opacity: 0, transform: 'scale(0.8)' }
290
- ],
291
- options: { duration: 250, easing: 'ease' }
292
- });
293
-
294
- setDefaultAnimation('modal.denyClose', {
295
- keyframes: [{ transform: 'scale(1)' }, { transform: 'scale(1.02)' }, { transform: 'scale(1)' }],
296
- options: { duration: 250 }
297
- });
298
-
299
- setDefaultAnimation('modal.overlay.show', {
300
- keyframes: [{ opacity: 0 }, { opacity: 1 }],
301
- options: { duration: 250 }
302
- });
303
-
304
- setDefaultAnimation('modal.overlay.hide', {
305
- keyframes: [{ opacity: 1 }, { opacity: 0 }],
306
- options: { duration: 250 }
307
- });
308
-
309
- export default SgdsModal;
@@ -1 +0,0 @@
1
- export { SgdsQuantityToggle } from "./sgds-quantitytoggle";
@@ -1,10 +0,0 @@
1
-
2
- @import '../utils/base.scss';
3
- @import "~@govtechsg/sgds/sass/forms/labels";
4
- @import "~@govtechsg/sgds/sass/forms/form-text";
5
- @import "~@govtechsg/sgds/sass/forms/form-control";
6
- @import "~@govtechsg/sgds/sass/forms/form-control-group";
7
- @import "~@govtechsg/sgds/sass/forms/input-group";
8
- @import "~@govtechsg/sgds/sass/forms/validation";
9
- @import "~@govtechsg/sgds/sass/buttons";
10
-
@@ -1,130 +0,0 @@
1
- import { customElement, property,query, state } from "lit/decorators.js";
2
- import { html } from 'lit/static-html.js';
3
- import { ifDefined } from 'lit/directives/if-defined.js';
4
- import SgdsElement from "../utils/sgds-element";
5
- import { defaultValue } from "../utils/defaultvalue";
6
- import genId from "../utils/generateId";
7
- import { live } from 'lit/directives/live.js';
8
- import { watch } from "../utils/watch";
9
- import {SgdsButton} from "../Button";
10
- import {classMap} from 'lit/directives/class-map.js';
11
- import styles from "./sgds-quantitytoggle.scss";
12
-
13
- @customElement("sgds-quantitytoggle")
14
- export class SgdsQuantityToggle extends SgdsElement {
15
- @query('input.form-control') input: HTMLInputElement;
16
- @query('sgds-button.button-group_button-first') leftBtn: SgdsButton;
17
- @query('sgds-button.button-group_button-last') lastBtn: SgdsButton;
18
- static styles = styles;
19
-
20
-
21
- @property({ reflect: true, type: String}) quantToggleId = genId("quantToggle", "toggle");
22
-
23
- @property({reflect: true}) name : string;
24
- /** The input's minimum value. */
25
- @property() min: number | string;
26
- /** The input's maximum value. */
27
- @property() max: number | string;
28
-
29
- @property() size : 'sm' | 'lg' | "default" = "sm" ;
30
-
31
- @property ({reflect: true}) count : number | string;
32
-
33
- @property({ type: Boolean, reflect: true }) disabled = false;
34
-
35
- @property({ reflect: true }) quantityToggleClasses? : string;
36
-
37
- /**
38
- * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is
39
- * implied, allowing any numeric value.
40
- */
41
- @property() step = 1 ;
42
-
43
- /** Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */
44
- @defaultValue()
45
- defaultValue = '';
46
-
47
- handleChange(event: string){
48
- this.emit(event);
49
- this.count = this.input.value;
50
- }
51
- onPlus(event:MouseEvent){
52
- if (this.disabled) {
53
- event.preventDefault();
54
- event.stopPropagation();
55
- return;
56
- }
57
- this.count = parseInt(this.input.value) + parseInt(this.input.step);
58
- };
59
- onMinus(event:MouseEvent){
60
- if (this.disabled) {
61
- event.preventDefault();
62
- event.stopPropagation();
63
- return;
64
- }
65
- if (this.count < this.step) {
66
- this.count = 0;
67
- }
68
- else {
69
- this.count = parseInt(this.input.value) - parseInt(this.input.step);
70
- }
71
-
72
- };
73
-
74
-
75
-
76
- @watch('count', { waitUntilFirstUpdate: true })
77
-
78
- render() {
79
- return html`
80
- <div
81
- part="base"
82
- class="${classMap(
83
- {
84
- "sgds" : true,
85
- 'disabled': this.disabled,
86
- "input-group" : true,
87
- [`${this.quantityToggleClasses}`]: this.quantityToggleClasses
88
- })}"
89
- variant="quantity-toggle"
90
- id=${this.quantToggleId}
91
- size=${this.size}
92
- >
93
- <sgds-button
94
- part="button"
95
- variant="primary"
96
- class="button-group_button-first"
97
- size=${this.size}
98
- @click=${this.onMinus}
99
- ?disabled=${this.disabled}
100
- >
101
- <sl-icon name="dash-lg"></sl-icon>
102
- </sgds-button>
103
- <input
104
- type="number"
105
- class="form-control ${"form-control-" + this.size} text-center"
106
- name=${ifDefined(this.name)}
107
- step=${ifDefined(this.step as number)}
108
- min=${ifDefined(this.min)}
109
- max=${ifDefined(this.max)}
110
- .value=${live(this.count as string)}
111
- @change=${()=> this.handleChange('sgds-change')}
112
- @input=${()=> this.handleChange('sgds-input')}
113
- ?disabled=${this.disabled}
114
- >
115
- <sgds-button
116
- part="button"
117
- variant="primary"
118
- class="button-group_button-last"
119
- size=${this.size}
120
- @click=${this.onPlus}
121
- ?disabled=${this.disabled}
122
- >
123
- <sl-icon name="plus-lg"></sl-icon>
124
- </sgds-button>
125
- </div>
126
- `;
127
- }
128
- }
129
-
130
- export default SgdsQuantityToggle;
@@ -1,2 +0,0 @@
1
- export { SgdsRadio } from "./sgds-radio";
2
- export { SgdsRadioGroup } from "./sgds-radiogroup";
@@ -1,5 +0,0 @@
1
- @import "../utils/base.scss";
2
- @import "~@govtechsg/sgds/sass/forms/form-check";
3
- @import "~@govtechsg/sgds/sass/forms/labels";
4
-
5
-