@redvars/peacock 3.8.1 → 3.8.2

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 (474) hide show
  1. package/dist/{BaseInput-14YmcfK7.js → BaseInput-CU1zZYKc.js} +3 -3
  2. package/dist/{BaseInput-14YmcfK7.js.map → BaseInput-CU1zZYKc.js.map} +1 -1
  3. package/dist/ButtonConstants-CahP2_NA.js +4 -0
  4. package/dist/ButtonConstants-CahP2_NA.js.map +1 -0
  5. package/dist/{IndividualComponent-DUINtMGK.js → IndividualComponent-Bdwyrvd6.js} +2 -2
  6. package/dist/{IndividualComponent-DUINtMGK.js.map → IndividualComponent-Bdwyrvd6.js.map} +1 -1
  7. package/dist/{NativeHyperlinkMixin-DrYXyfMQ.js → NativeHyperlinkMixin-D9J4aBTy.js} +4 -30
  8. package/dist/NativeHyperlinkMixin-D9J4aBTy.js.map +1 -0
  9. package/dist/accordion-item.js +338 -0
  10. package/dist/accordion-item.js.map +1 -0
  11. package/dist/accordion.js +159 -0
  12. package/dist/accordion.js.map +1 -0
  13. package/dist/alert.js +190 -0
  14. package/dist/alert.js.map +1 -0
  15. package/dist/app-bar.js +324 -0
  16. package/dist/app-bar.js.map +1 -0
  17. package/dist/assets/components.css +1 -1
  18. package/dist/assets/components.css.map +1 -1
  19. package/dist/assets/styles.css +1 -1
  20. package/dist/assets/styles.css.map +1 -1
  21. package/dist/attachable-controller-CAKVrfcG.js +119 -0
  22. package/dist/attachable-controller-CAKVrfcG.js.map +1 -0
  23. package/dist/avatar.js +114 -0
  24. package/dist/avatar.js.map +1 -0
  25. package/dist/badge.js +91 -0
  26. package/dist/badge.js.map +1 -0
  27. package/dist/base-Cl6v8-BZ.js +9 -0
  28. package/dist/base-Cl6v8-BZ.js.map +1 -0
  29. package/dist/bottom-sheet.js +14 -5
  30. package/dist/bottom-sheet.js.map +1 -1
  31. package/dist/breadcrumb-item.js +163 -0
  32. package/dist/breadcrumb-item.js.map +1 -0
  33. package/dist/breadcrumb.js +95 -0
  34. package/dist/breadcrumb.js.map +1 -0
  35. package/dist/button-group.js +87 -137
  36. package/dist/button-group.js.map +1 -1
  37. package/dist/button.js +863 -133
  38. package/dist/button.js.map +1 -1
  39. package/dist/calendar-column-view.js +8 -4
  40. package/dist/calendar-column-view.js.map +1 -1
  41. package/dist/calendar-month-view.js +8 -4
  42. package/dist/calendar-month-view.js.map +1 -1
  43. package/dist/calendar.js +8 -4
  44. package/dist/calendar.js.map +1 -1
  45. package/dist/canvas.js +8 -4
  46. package/dist/canvas.js.map +1 -1
  47. package/dist/card-content.js +1 -1
  48. package/dist/card.js +23 -45
  49. package/dist/card.js.map +1 -1
  50. package/dist/cb-compound-expression.js +6 -2
  51. package/dist/cb-compound-expression.js.map +1 -1
  52. package/dist/cb-divider.js +7 -3
  53. package/dist/cb-divider.js.map +1 -1
  54. package/dist/cb-expression.js +6 -2
  55. package/dist/cb-expression.js.map +1 -1
  56. package/dist/cb-predicate.js +7 -3
  57. package/dist/cb-predicate.js.map +1 -1
  58. package/dist/{chart-bar-cn6rrna-.js → chart-bar-CYoGNXnK.js} +6 -2
  59. package/dist/{chart-bar-cn6rrna-.js.map → chart-bar-CYoGNXnK.js.map} +1 -1
  60. package/dist/chart-bar.js +7 -6
  61. package/dist/chart-bar.js.map +1 -1
  62. package/dist/chart-doughnut.js +8 -3
  63. package/dist/chart-doughnut.js.map +1 -1
  64. package/dist/chart-pie.js +8 -3
  65. package/dist/chart-pie.js.map +1 -1
  66. package/dist/chart-stacked-bar.js +7 -6
  67. package/dist/chart-stacked-bar.js.map +1 -1
  68. package/dist/checkbox.js +526 -0
  69. package/dist/checkbox.js.map +1 -0
  70. package/dist/chip.js +459 -0
  71. package/dist/chip.js.map +1 -0
  72. package/dist/{class-map-YU7g0o3B.js → class-map-DG7CA1et.js} +2 -2
  73. package/dist/{class-map-YU7g0o3B.js.map → class-map-DG7CA1et.js.map} +1 -1
  74. package/dist/clock.js +6 -2
  75. package/dist/clock.js.map +1 -1
  76. package/dist/code-editor.js +45 -30
  77. package/dist/code-editor.js.map +1 -1
  78. package/dist/code-highlighter.js +9 -5
  79. package/dist/code-highlighter.js.map +1 -1
  80. package/dist/condition-builder.js +5 -1
  81. package/dist/condition-builder.js.map +1 -1
  82. package/dist/container.js +141 -0
  83. package/dist/container.js.map +1 -0
  84. package/dist/custom-elements-jsdocs.json +721 -769
  85. package/dist/custom-elements.json +3213 -1979
  86. package/dist/datasource-B2eRh6Or.js +108 -0
  87. package/dist/datasource-B2eRh6Or.js.map +1 -0
  88. package/dist/dispatch-event-utils-CuEqjlPT.js.map +1 -1
  89. package/dist/divider.js +135 -0
  90. package/dist/divider.js.map +1 -0
  91. package/dist/dropdown-button.js +11 -6
  92. package/dist/dropdown-button.js.map +1 -1
  93. package/dist/element-internals-2CMts_0M.js +290 -0
  94. package/dist/element-internals-2CMts_0M.js.map +1 -0
  95. package/dist/elevation.js +94 -0
  96. package/dist/elevation.js.map +1 -0
  97. package/dist/empty-state.js +194 -0
  98. package/dist/empty-state.js.map +1 -0
  99. package/dist/{event-manager-D-QCmUgR.js → event-manager-DTyX2uYD.js} +2 -2
  100. package/dist/{event-manager-D-QCmUgR.js.map → event-manager-DTyX2uYD.js.map} +1 -1
  101. package/dist/fab.js +138 -145
  102. package/dist/fab.js.map +1 -1
  103. package/dist/field.js +461 -0
  104. package/dist/field.js.map +1 -0
  105. package/dist/{popover-DUPmMVWS.js → floating-controller-CnUZnOhK.js} +2 -171
  106. package/dist/floating-controller-CnUZnOhK.js.map +1 -0
  107. package/dist/{flow-designer-node-BWrPuxAR.js → flow-designer-node-DsVwQTac.js} +7 -3
  108. package/dist/{flow-designer-node-BWrPuxAR.js.map → flow-designer-node-DsVwQTac.js.map} +1 -1
  109. package/dist/flow-designer-node.js +3 -3
  110. package/dist/flow-designer.js +19 -12
  111. package/dist/flow-designer.js.map +1 -1
  112. package/dist/focus-ring.js +126 -0
  113. package/dist/focus-ring.js.map +1 -0
  114. package/dist/form-associated-BXADnjOB.js +388 -0
  115. package/dist/form-associated-BXADnjOB.js.map +1 -0
  116. package/dist/html-editor.js +21 -9
  117. package/dist/html-editor.js.map +1 -1
  118. package/dist/hyperlink-DLvb6MXE.js +98 -0
  119. package/dist/hyperlink-DLvb6MXE.js.map +1 -0
  120. package/dist/icon-button.js +1064 -0
  121. package/dist/icon-button.js.map +1 -0
  122. package/dist/icon.js +170 -0
  123. package/dist/icon.js.map +1 -0
  124. package/dist/if-defined-BXZpRQ4P.js +10 -0
  125. package/dist/if-defined-BXZpRQ4P.js.map +1 -0
  126. package/dist/image.js +201 -0
  127. package/dist/image.js.map +1 -0
  128. package/dist/index.js +73 -20
  129. package/dist/index.js.map +1 -1
  130. package/dist/is-dark-mode-DOcaw4Yq.js.map +1 -1
  131. package/dist/is-link-Dk2OV3PM.js +6 -0
  132. package/dist/is-link-Dk2OV3PM.js.map +1 -0
  133. package/dist/item.js +212 -0
  134. package/dist/item.js.map +1 -0
  135. package/dist/link.js +75 -0
  136. package/dist/link.js.map +1 -0
  137. package/dist/list-D6JLh1uh.js +352 -0
  138. package/dist/list-D6JLh1uh.js.map +1 -0
  139. package/dist/list.js +14 -0
  140. package/dist/list.js.map +1 -0
  141. package/dist/{peacock-loader.js → loader.js} +83 -22
  142. package/dist/loader.js.map +1 -0
  143. package/dist/menu-item.js +318 -0
  144. package/dist/menu-item.js.map +1 -0
  145. package/dist/menu.js +534 -0
  146. package/dist/menu.js.map +1 -0
  147. package/dist/modal.js +9 -5
  148. package/dist/modal.js.map +1 -1
  149. package/dist/navigation-rail-item.js +385 -0
  150. package/dist/navigation-rail-item.js.map +1 -0
  151. package/dist/navigation-rail.js +217 -0
  152. package/dist/navigation-rail.js.map +1 -0
  153. package/dist/notification-manager.js +8 -4
  154. package/dist/notification-manager.js.map +1 -1
  155. package/dist/notification.js +8 -4
  156. package/dist/notification.js.map +1 -1
  157. package/dist/number-counter.js +7 -3
  158. package/dist/number-counter.js.map +1 -1
  159. package/dist/{observe-slot-change-D8Xg-kSS.js → observe-slot-change-DPxaZrZF.js} +3 -4
  160. package/dist/observe-slot-change-DPxaZrZF.js.map +1 -0
  161. package/dist/option.js +121 -0
  162. package/dist/option.js.map +1 -0
  163. package/dist/pagination.js +255 -0
  164. package/dist/pagination.js.map +1 -0
  165. package/dist/popover-content.js +7 -3
  166. package/dist/popover-content.js.map +1 -1
  167. package/dist/popover.js +175 -3
  168. package/dist/popover.js.map +1 -1
  169. package/dist/{property-1psGvXOq.js → property-B49QQ8pS.js} +2 -2
  170. package/dist/{property-1psGvXOq.js.map → property-B49QQ8pS.js.map} +1 -1
  171. package/dist/query-CHb9Ft_d.js +10 -0
  172. package/dist/query-CHb9Ft_d.js.map +1 -0
  173. package/dist/query-assigned-elements-BJaGSqM0.js +10 -0
  174. package/dist/query-assigned-elements-BJaGSqM0.js.map +1 -0
  175. package/dist/radio.js +476 -0
  176. package/dist/radio.js.map +1 -0
  177. package/dist/ripple.js +506 -0
  178. package/dist/ripple.js.map +1 -0
  179. package/dist/search.js +12 -7
  180. package/dist/search.js.map +1 -1
  181. package/dist/segmented-button-group.js +137 -0
  182. package/dist/segmented-button-group.js.map +1 -0
  183. package/dist/segmented-button.js +289 -0
  184. package/dist/segmented-button.js.map +1 -0
  185. package/dist/select-Dwtk0RIU.js +3937 -0
  186. package/dist/select-Dwtk0RIU.js.map +1 -0
  187. package/dist/side-sheet.js +8 -4
  188. package/dist/side-sheet.js.map +1 -1
  189. package/dist/skeleton.js +122 -0
  190. package/dist/skeleton.js.map +1 -0
  191. package/dist/slider.js +346 -0
  192. package/dist/slider.js.map +1 -0
  193. package/dist/snackbar.js +335 -0
  194. package/dist/snackbar.js.map +1 -0
  195. package/dist/spinner.js +100 -0
  196. package/dist/spinner.js.map +1 -0
  197. package/dist/split-button.js +10 -5
  198. package/dist/split-button.js.map +1 -1
  199. package/dist/spread-B5cgadZl.js +32 -0
  200. package/dist/spread-B5cgadZl.js.map +1 -0
  201. package/dist/src/__internal/aria/aria.d.ts +98 -0
  202. package/dist/src/__internal/aria/delegate.d.ts +54 -0
  203. package/dist/src/__internal/events/dispatch-hooks.d.ts +80 -0
  204. package/dist/src/__internal/mixins/element-internals.d.ts +40 -0
  205. package/dist/src/__internal/mixins/form-associated.d.ts +174 -0
  206. package/dist/src/__internal/mixins/form-submitter.d.ts +59 -0
  207. package/dist/src/__internal/mixins/hyperlink.d.ts +42 -0
  208. package/dist/src/__internal/mixins/mixin.d.ts +49 -0
  209. package/dist/src/{__utils → __internal/utils}/observe-slot-change.d.ts +1 -0
  210. package/dist/src/accordion/accordion-item.d.ts +3 -1
  211. package/dist/src/accordion/accordion.d.ts +1 -1
  212. package/dist/src/alert/alert.d.ts +43 -0
  213. package/dist/src/alert/index.d.ts +1 -0
  214. package/dist/src/app-bar/app-bar.d.ts +92 -0
  215. package/dist/src/app-bar/index.d.ts +1 -0
  216. package/dist/src/avatar/avatar.d.ts +2 -0
  217. package/dist/src/bottom-sheet/bottom-sheet.d.ts +1 -1
  218. package/dist/src/breadcrumb/breadcrumb-item/breadcrumb-item.d.ts +1 -0
  219. package/dist/src/button/ButtonTypes.d.ts +5 -0
  220. package/dist/src/button/base-button/base-button.d.ts +18 -0
  221. package/dist/src/button/button/button.d.ts +29 -37
  222. package/dist/src/button/button-group/button-group.d.ts +17 -18
  223. package/dist/src/{fab → button/fab}/fab.d.ts +8 -26
  224. package/dist/src/button/icon-button/icon-button.d.ts +20 -27
  225. package/dist/src/button/index.d.ts +1 -0
  226. package/dist/src/calendar/calendar.d.ts +1 -1
  227. package/dist/src/canvas/canvas.d.ts +1 -1
  228. package/dist/src/card/card.d.ts +5 -6
  229. package/dist/src/chart-bar/chart-bar.d.ts +1 -1
  230. package/dist/src/chart-bar/chart-stacked-bar.d.ts +1 -1
  231. package/dist/src/checkbox/checkbox.d.ts +5 -1
  232. package/dist/src/chip/chip/chip.d.ts +9 -8
  233. package/dist/src/container/container.d.ts +5 -1
  234. package/dist/src/divider/divider.d.ts +2 -0
  235. package/dist/src/empty-state/empty-state.d.ts +1 -0
  236. package/dist/src/field/field.d.ts +19 -1
  237. package/dist/src/focus-ring/focus-ring.d.ts +3 -7
  238. package/dist/src/html-editor/html-editor.d.ts +1 -1
  239. package/dist/src/icon/icon.d.ts +9 -4
  240. package/dist/src/image/image.d.ts +4 -0
  241. package/dist/src/index.d.ts +7 -6
  242. package/dist/src/item/item.d.ts +20 -29
  243. package/dist/src/link/link.d.ts +1 -1
  244. package/dist/src/list/list-item.d.ts +7 -5
  245. package/dist/src/list/list.d.ts +3 -2
  246. package/dist/src/menu/menu/menu.d.ts +14 -0
  247. package/dist/src/menu/menu-item/menu-item.d.ts +10 -2
  248. package/dist/src/modal/modal.d.ts +1 -1
  249. package/dist/src/navigation-rail/navigation-rail-item.d.ts +5 -4
  250. package/dist/src/navigation-rail/navigation-rail.d.ts +1 -1
  251. package/dist/src/radio/radio.d.ts +5 -0
  252. package/dist/src/ripple/ripple.d.ts +10 -1
  253. package/dist/src/search/search.d.ts +1 -1
  254. package/dist/src/segmented-button/segmented-button-group.d.ts +2 -2
  255. package/dist/src/segmented-button/segmented-button.d.ts +2 -0
  256. package/dist/src/side-sheet/side-sheet.d.ts +1 -1
  257. package/dist/src/skeleton/skeleton.d.ts +1 -0
  258. package/dist/src/slider/slider.d.ts +1 -0
  259. package/dist/src/snackbar/snackbar.d.ts +12 -2
  260. package/dist/src/svg/svg.d.ts +5 -0
  261. package/dist/src/table/table.d.ts +5 -0
  262. package/dist/src/tabs/tab.d.ts +2 -7
  263. package/dist/src/toolbar/toolbar.d.ts +2 -2
  264. package/dist/{state-DwbEjqVk.js → state-DkTK9EGF.js} +2 -2
  265. package/dist/{state-DwbEjqVk.js.map → state-DkTK9EGF.js.map} +1 -1
  266. package/dist/{style-map-DVmWOuYy.js → style-map-BQD5Et1D.js} +2 -2
  267. package/dist/{style-map-DVmWOuYy.js.map → style-map-BQD5Et1D.js.map} +1 -1
  268. package/dist/sub-menu.js +241 -0
  269. package/dist/sub-menu.js.map +1 -0
  270. package/dist/svg.js +273 -0
  271. package/dist/svg.js.map +1 -0
  272. package/dist/tab-group.js +188 -0
  273. package/dist/tab-group.js.map +1 -0
  274. package/dist/tab-panel.js +61 -0
  275. package/dist/tab-panel.js.map +1 -0
  276. package/dist/tab.js +658 -0
  277. package/dist/tab.js.map +1 -0
  278. package/dist/table.js +620 -0
  279. package/dist/table.js.map +1 -0
  280. package/dist/tabs.js +240 -0
  281. package/dist/tabs.js.map +1 -0
  282. package/dist/throttle-C7ZAPqtu.js +24 -0
  283. package/dist/throttle-C7ZAPqtu.js.map +1 -0
  284. package/dist/toolbar.js +9 -5
  285. package/dist/toolbar.js.map +1 -1
  286. package/dist/tooltip.js +270 -0
  287. package/dist/tooltip.js.map +1 -0
  288. package/dist/tsconfig.tsbuildinfo +1 -1
  289. package/dist/{unsafe-html-BsGUjx94.js → unsafe-html-Ct0N2_UU.js} +2 -2
  290. package/dist/{unsafe-html-BsGUjx94.js.map → unsafe-html-Ct0N2_UU.js.map} +1 -1
  291. package/dist/when-DEJm_QN9.js +9 -0
  292. package/dist/when-DEJm_QN9.js.map +1 -0
  293. package/package.json +4 -2
  294. package/readme.md +3 -3
  295. package/scss/mixin.scss +8 -6
  296. package/src/__internal/aria/aria.ts +293 -0
  297. package/src/__internal/aria/delegate.ts +206 -0
  298. package/src/__internal/events/dispatch-hooks.ts +182 -0
  299. package/src/__internal/mixins/element-internals.ts +73 -0
  300. package/src/__internal/mixins/form-associated.ts +295 -0
  301. package/src/__internal/mixins/form-submitter.ts +133 -0
  302. package/src/__internal/mixins/hyperlink.ts +71 -0
  303. package/src/__internal/mixins/mixin.ts +58 -0
  304. package/src/{__utils → __internal/utils}/observe-slot-change.ts +2 -5
  305. package/src/accordion/accordion-item.ts +6 -2
  306. package/src/accordion/accordion.ts +4 -2
  307. package/src/accordion/demo/index.html +95 -90
  308. package/src/alert/alert.scss +82 -0
  309. package/src/{banner/banner.ts → alert/alert.ts} +22 -22
  310. package/src/alert/index.ts +1 -0
  311. package/src/app-bar/app-bar-colors.scss +17 -0
  312. package/src/app-bar/app-bar.scss +165 -0
  313. package/src/app-bar/app-bar.ts +155 -0
  314. package/src/app-bar/index.ts +1 -0
  315. package/src/avatar/avatar.ts +4 -0
  316. package/src/badge/badge.ts +2 -0
  317. package/src/bottom-sheet/bottom-sheet.ts +8 -2
  318. package/src/breadcrumb/breadcrumb/breadcrumb.ts +2 -0
  319. package/src/breadcrumb/breadcrumb-item/breadcrumb-item.ts +3 -0
  320. package/src/button/ButtonTypes.ts +17 -0
  321. package/src/button/base-button/base-button.ts +85 -0
  322. package/src/button/button/button-base.scss +306 -0
  323. package/src/button/button/button-colors.scss +27 -32
  324. package/src/button/button/button-layers.scss +126 -39
  325. package/src/button/button/button-shapes.scss +73 -0
  326. package/src/button/button/button.scss +12 -286
  327. package/src/button/button/button.ts +174 -194
  328. package/src/button/button-group/button-group.scss +43 -36
  329. package/src/button/button-group/button-group.ts +26 -137
  330. package/src/{fab → button/fab}/fab-colors.scss +0 -10
  331. package/src/button/fab/fab-sizes.scss +37 -0
  332. package/src/button/fab/fab.scss +172 -0
  333. package/src/{fab → button/fab}/fab.ts +69 -105
  334. package/src/button/icon-button/icon-button-sizes.scss +18 -3
  335. package/src/button/icon-button/icon-button.scss +5 -0
  336. package/src/button/icon-button/icon-button.ts +111 -141
  337. package/src/button/index.ts +7 -0
  338. package/src/calendar/calendar.ts +2 -2
  339. package/src/canvas/canvas.ts +2 -2
  340. package/src/card/card.scss +3 -3
  341. package/src/card/card.ts +20 -40
  342. package/src/chart-bar/chart-bar.ts +2 -2
  343. package/src/chart-bar/chart-stacked-bar.ts +2 -2
  344. package/src/checkbox/checkbox.ts +12 -4
  345. package/src/chip/chip/chip.scss +1 -1
  346. package/src/chip/chip/chip.ts +35 -55
  347. package/src/chip/demo/index.html +30 -26
  348. package/src/code-editor/code-editor.ts +68 -58
  349. package/src/code-editor/demo/index.html +32 -27
  350. package/src/code-highlighter/code-highlighter.ts +1 -1
  351. package/src/code-highlighter/demo/index.html +24 -21
  352. package/src/container/container.ts +8 -2
  353. package/src/date-picker/date-picker.ts +2 -3
  354. package/src/divider/divider.ts +5 -1
  355. package/src/dropdown-button/demo/index.html +106 -101
  356. package/src/dropdown-button/dropdown-button.ts +1 -1
  357. package/src/elevation/elevation.ts +2 -0
  358. package/src/empty-state/empty-state.ts +3 -0
  359. package/src/field/field.ts +52 -33
  360. package/src/focus-ring/focus-ring.ts +5 -7
  361. package/src/html-editor/html-editor.ts +28 -16
  362. package/src/icon/datasource.ts +1 -1
  363. package/src/icon/icon.ts +27 -15
  364. package/src/image/image.ts +18 -6
  365. package/src/index.ts +24 -6
  366. package/src/input/input.ts +2 -2
  367. package/src/item/item.scss +126 -162
  368. package/src/item/item.ts +70 -323
  369. package/src/link/link.ts +3 -1
  370. package/src/list/list-item.scss +43 -31
  371. package/src/list/list-item.ts +79 -75
  372. package/src/list/list.scss +1 -13
  373. package/src/list/list.ts +6 -3
  374. package/src/{peacock-loader.ts → loader.ts} +91 -79
  375. package/src/menu/menu/menu.scss +14 -11
  376. package/src/menu/menu/menu.ts +20 -8
  377. package/src/menu/menu-item/menu-item.scss +35 -3
  378. package/src/menu/menu-item/menu-item.ts +40 -34
  379. package/src/menu/sub-menu/sub-menu.ts +3 -0
  380. package/src/modal/modal.ts +2 -2
  381. package/src/navigation-rail/navigation-rail-item.ts +21 -36
  382. package/src/navigation-rail/navigation-rail.scss +1 -0
  383. package/src/navigation-rail/navigation-rail.ts +4 -2
  384. package/src/number-field/number-field.ts +2 -2
  385. package/src/pagination/pagination.ts +2 -0
  386. package/src/popover/popover.ts +3 -3
  387. package/src/radio/radio.ts +13 -5
  388. package/src/ripple/ripple.ts +14 -1
  389. package/src/search/search.ts +3 -3
  390. package/src/segmented-button/segmented-button-group.ts +8 -4
  391. package/src/segmented-button/segmented-button.ts +4 -0
  392. package/src/select/option.ts +2 -0
  393. package/src/side-sheet/side-sheet.ts +2 -2
  394. package/src/sidebar-menu/sidebar-menu-item.ts +3 -2
  395. package/src/skeleton/skeleton.ts +3 -0
  396. package/src/slider/slider.ts +4 -1
  397. package/src/snackbar/snackbar.ts +40 -25
  398. package/src/spinner/spinner.ts +2 -0
  399. package/src/svg/svg.ts +27 -9
  400. package/src/switch/switch.ts +1 -1
  401. package/src/table/table.ts +16 -3
  402. package/src/tabs/demo/index.html +79 -79
  403. package/src/tabs/tab-group.ts +2 -0
  404. package/src/tabs/tab-panel.ts +2 -0
  405. package/src/tabs/tab.scss +4 -4
  406. package/src/tabs/tab.ts +16 -39
  407. package/src/tabs/tabs.ts +2 -0
  408. package/src/textarea/textarea.ts +2 -2
  409. package/src/time-picker/time-picker.ts +2 -2
  410. package/src/toolbar/toolbar.ts +3 -3
  411. package/src/tooltip/tooltip.ts +14 -8
  412. package/src/url-field/url-field.ts +2 -3
  413. package/dist/ButtonConstants-D06bY4uy.js +0 -114
  414. package/dist/ButtonConstants-D06bY4uy.js.map +0 -1
  415. package/dist/NativeHyperlinkMixin-DrYXyfMQ.js.map +0 -1
  416. package/dist/banner.js +0 -186
  417. package/dist/banner.js.map +0 -1
  418. package/dist/button-colors-D7sJyPy8.js +0 -586
  419. package/dist/button-colors-D7sJyPy8.js.map +0 -1
  420. package/dist/icon-CueRR7wx.js +0 -260
  421. package/dist/icon-CueRR7wx.js.map +0 -1
  422. package/dist/icon-button-CAzYr_qr.js +0 -318
  423. package/dist/icon-button-CAzYr_qr.js.map +0 -1
  424. package/dist/navigation-rail-CM_svs5_.js +0 -14184
  425. package/dist/navigation-rail-CM_svs5_.js.map +0 -1
  426. package/dist/observe-slot-change-D8Xg-kSS.js.map +0 -1
  427. package/dist/peacock-loader.js.map +0 -1
  428. package/dist/popover-DUPmMVWS.js.map +0 -1
  429. package/dist/query-QBcUV-L_.js +0 -15
  430. package/dist/query-QBcUV-L_.js.map +0 -1
  431. package/dist/src/banner/banner.d.ts +0 -43
  432. package/dist/src/banner/index.d.ts +0 -1
  433. package/dist/src/button/GroupButtonInterface.d.ts +0 -4
  434. package/src/banner/banner.scss +0 -82
  435. package/src/banner/index.ts +0 -1
  436. package/src/button/GroupButtonInterface.ts +0 -4
  437. package/src/button/button/only-button.scss +0 -13
  438. package/src/fab/fab-sizes.scss +0 -37
  439. package/src/fab/fab.scss +0 -143
  440. /package/dist/src/{__controllers → __internal/controllers}/attachable-controller.d.ts +0 -0
  441. /package/dist/src/{__controllers → __internal/controllers}/floating-controller.d.ts +0 -0
  442. /package/dist/src/{__directive → __internal/directive}/spread.d.ts +0 -0
  443. /package/dist/src/{__mixins → __internal/mixins}/MixinConstructor.d.ts +0 -0
  444. /package/dist/src/{__mixins → __internal/mixins}/NativeButtonMixin.d.ts +0 -0
  445. /package/dist/src/{__mixins → __internal/mixins}/NativeHyperlinkMixin.d.ts +0 -0
  446. /package/dist/src/{__utils → __internal/utils}/cache-fetch.d.ts +0 -0
  447. /package/dist/src/{__utils → __internal/utils}/copy-to-clipboard.d.ts +0 -0
  448. /package/dist/src/{__utils → __internal/utils}/dispatch-event-utils.d.ts +0 -0
  449. /package/dist/src/{__utils → __internal/utils}/is-dark-mode.d.ts +0 -0
  450. /package/dist/src/{__utils → __internal/utils}/is-in-viewport.d.ts +0 -0
  451. /package/dist/src/{__utils → __internal/utils}/is-link.d.ts +0 -0
  452. /package/dist/src/{__utils → __internal/utils}/observe-theme-change.d.ts +0 -0
  453. /package/dist/src/{__utils → __internal/utils}/sanitize-svg.d.ts +0 -0
  454. /package/dist/src/{__utils → __internal/utils}/throttle.d.ts +0 -0
  455. /package/dist/src/{fab → button/fab}/index.d.ts +0 -0
  456. /package/dist/src/{peacock-loader.d.ts → loader.d.ts} +0 -0
  457. /package/dist/test/{banner.test.d.ts → alert.test.d.ts} +0 -0
  458. /package/src/{__controllers → __internal/controllers}/attachable-controller.ts +0 -0
  459. /package/src/{__controllers → __internal/controllers}/floating-controller.ts +0 -0
  460. /package/src/{__directive → __internal/directive}/spread.ts +0 -0
  461. /package/src/{__mixins → __internal/mixins}/MixinConstructor.ts +0 -0
  462. /package/src/{__mixins → __internal/mixins}/NativeButtonMixin.ts +0 -0
  463. /package/src/{__mixins → __internal/mixins}/NativeHyperlinkMixin.ts +0 -0
  464. /package/src/{__mixins → __internal/mixins}/README.md +0 -0
  465. /package/src/{__utils → __internal/utils}/cache-fetch.ts +0 -0
  466. /package/src/{__utils → __internal/utils}/copy-to-clipboard.ts +0 -0
  467. /package/src/{__utils → __internal/utils}/dispatch-event-utils.ts +0 -0
  468. /package/src/{__utils → __internal/utils}/is-dark-mode.ts +0 -0
  469. /package/src/{__utils → __internal/utils}/is-in-viewport.ts +0 -0
  470. /package/src/{__utils → __internal/utils}/is-link.ts +0 -0
  471. /package/src/{__utils → __internal/utils}/observe-theme-change.ts +0 -0
  472. /package/src/{__utils → __internal/utils}/sanitize-svg.ts +0 -0
  473. /package/src/{__utils → __internal/utils}/throttle.ts +0 -0
  474. /package/src/{fab → button/fab}/index.ts +0 -0
@@ -0,0 +1,182 @@
1
+ /**
2
+ * A symbol used to access dispatch hooks on an event.
3
+ */
4
+ const dispatchHooks = Symbol('dispatchHooks');
5
+
6
+ /**
7
+ * An `Event` with additional symbols for dispatch hooks.
8
+ */
9
+ interface EventWithDispatchHooks extends Event {
10
+ [dispatchHooks]: EventTarget;
11
+ }
12
+
13
+ /**
14
+ * Add a hook for an event that is called after the event is dispatched and
15
+ * propagates to other event listeners.
16
+ *
17
+ * This is useful for behaviors that need to check if an event is canceled.
18
+ *
19
+ * The callback is invoked synchronously, which allows for better integration
20
+ * with synchronous platform APIs (like `<form>` or `<label>` clicking).
21
+ *
22
+ * Note: `setupDispatchHooks()` must be called on the element before adding any
23
+ * other event listeners. Call it in the constructor of an element or
24
+ * controller.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * class MyControl extends LitElement {
29
+ * constructor() {
30
+ * super();
31
+ * setupDispatchHooks(this, 'click');
32
+ * this.addEventListener('click', event => {
33
+ * afterDispatch(event, () => {
34
+ * if (event.defaultPrevented) {
35
+ * return
36
+ * }
37
+ *
38
+ * // ... perform logic
39
+ * });
40
+ * });
41
+ * }
42
+ * }
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * class MyController implements ReactiveController {
48
+ * constructor(host: ReactiveElement) {
49
+ * // setupDispatchHooks() may be called multiple times for the same
50
+ * // element and events, making it safe for multiple controllers to use it.
51
+ * setupDispatchHooks(host, 'click');
52
+ * host.addEventListener('click', event => {
53
+ * afterDispatch(event, () => {
54
+ * if (event.defaultPrevented) {
55
+ * return;
56
+ * }
57
+ *
58
+ * // ... perform logic
59
+ * });
60
+ * });
61
+ * }
62
+ * }
63
+ * ```
64
+ *
65
+ * @param event The event to add a hook to.
66
+ * @param callback A hook that is called after the event finishes dispatching.
67
+ */
68
+ export function afterDispatch(event: Event, callback: () => void) {
69
+ const hooks = (event as EventWithDispatchHooks)[dispatchHooks];
70
+ if (!hooks) {
71
+ throw new Error(`'${event.type}' event needs setupDispatchHooks().`);
72
+ }
73
+
74
+ hooks.addEventListener('after', callback, { once: true });
75
+ }
76
+
77
+ /**
78
+ * A lookup map of elements and event types that have a dispatch hook listener
79
+ * set up. Used to ensure we don't set up multiple hook listeners on the same
80
+ * element for the same event.
81
+ */
82
+ const ELEMENT_DISPATCH_HOOK_TYPES = new WeakMap<Element, Set<string>>();
83
+
84
+ /**
85
+ * Sets up an element to add dispatch hooks to given event types. This must be
86
+ * called before adding any event listeners that need to use dispatch hooks
87
+ * like `afterDispatch()`.
88
+ *
89
+ * This function is safe to call multiple times with the same element or event
90
+ * types. Call it in the constructor of elements, mixins, and controllers to
91
+ * ensure it is set up before external listeners.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * class MyControl extends LitElement {
96
+ * constructor() {
97
+ * super();
98
+ * setupDispatchHooks(this, 'click');
99
+ * this.addEventListener('click', this.listenerUsingAfterDispatch);
100
+ * }
101
+ * }
102
+ * ```
103
+ *
104
+ * @param element The element to set up event dispatch hooks for.
105
+ * @param eventTypes The event types to add dispatch hooks to.
106
+ */
107
+ export function setupDispatchHooks(
108
+ element: Element,
109
+ ...eventTypes: [string, ...string[]]
110
+ ) {
111
+ let typesAlreadySetUp = ELEMENT_DISPATCH_HOOK_TYPES.get(element);
112
+ if (!typesAlreadySetUp) {
113
+ typesAlreadySetUp = new Set();
114
+ ELEMENT_DISPATCH_HOOK_TYPES.set(element, typesAlreadySetUp);
115
+ }
116
+
117
+ for (const eventType of eventTypes) {
118
+ // Don't register multiple dispatch hook listeners. A second registration
119
+ // would lead to the second listener calling `afterDispatch()` hooks twice.
120
+ if (typesAlreadySetUp.has(eventType)) {
121
+ continue;
122
+ }
123
+
124
+ element.addEventListener(
125
+ eventType,
126
+ (event: Event) => {
127
+ // Add hooks onto the event.
128
+ const hooks = new EventTarget();
129
+ (event as EventWithDispatchHooks)[dispatchHooks] = hooks;
130
+
131
+ const cleanupLastNodeListener = new AbortController();
132
+ const callAfterDispatch = () => {
133
+ cleanupLastNodeListener.abort();
134
+ hooks.dispatchEvent(new Event('after'));
135
+ };
136
+
137
+ const patchStopPropagation = (
138
+ superMethod: Event['stopPropagation'],
139
+ ) => {
140
+ return function (this: Event) {
141
+ superMethod.call(this);
142
+ // Synchronously call afterDispatch() hooks when interrupted.
143
+ callAfterDispatch();
144
+ };
145
+ };
146
+
147
+ event.stopPropagation = patchStopPropagation(event.stopPropagation);
148
+ event.stopImmediatePropagation = patchStopPropagation(
149
+ event.stopImmediatePropagation,
150
+ );
151
+
152
+ // Add an event listener to detect the end of the event's propagation.
153
+ const composedPath = event.composedPath();
154
+ let lastNodeForEvent: EventTarget;
155
+ if (event.composed && event.bubbles) {
156
+ lastNodeForEvent = composedPath[composedPath.length - 1];
157
+ } else if (!event.bubbles) {
158
+ lastNodeForEvent = composedPath[0];
159
+ } else {
160
+ lastNodeForEvent = (composedPath[0] as Element).getRootNode();
161
+ }
162
+
163
+ lastNodeForEvent.addEventListener(
164
+ eventType,
165
+ () => {
166
+ // Synchronously call afterDispatch() hooks.
167
+ callAfterDispatch();
168
+ },
169
+ { once: true, signal: cleanupLastNodeListener.signal },
170
+ );
171
+ },
172
+ {
173
+ // Ensure this listener runs before other listeners.
174
+ // `setupDispatchHooks()` should be called in constructors to also
175
+ // ensure they run before any other externally-added capture listeners.
176
+ capture: true,
177
+ },
178
+ );
179
+
180
+ typesAlreadySetUp.add(eventType);
181
+ }
182
+ }
@@ -0,0 +1,73 @@
1
+ import { LitElement } from 'lit';
2
+
3
+ import { MixinBase, MixinReturn } from './mixin.js';
4
+
5
+ /**
6
+ * A unique symbol used for protected access to an instance's
7
+ * `ElementInternals`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * class MyElement extends mixinElementInternals(LitElement) {
12
+ * constructor() {
13
+ * super();
14
+ * this[internals].role = 'button';
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export const internals = Symbol('internals');
20
+
21
+ /**
22
+ * An instance with an `internals` symbol property for the component's
23
+ * `ElementInternals`.
24
+ *
25
+ * Use this when protected access is needed for an instance's `ElementInternals`
26
+ * from other files. A unique symbol is used to access the internals.
27
+ */
28
+ export interface WithElementInternals {
29
+ /**
30
+ * An instance's `ElementInternals`.
31
+ */
32
+ [internals]: ElementInternals;
33
+ }
34
+
35
+ // Private symbols
36
+ const privateInternals = Symbol('privateInternals');
37
+
38
+ /**
39
+ * Mixes in an attached `ElementInternals` instance.
40
+ *
41
+ * This mixin is only needed when other shared code needs access to a
42
+ * component's `ElementInternals`, such as form-associated mixins.
43
+ *
44
+ * @param base The class to mix functionality into.
45
+ * @return The provided class with `WithElementInternals` mixed in.
46
+ */
47
+ export function mixinElementInternals<T extends MixinBase<LitElement>>(
48
+ base: T,
49
+ ): MixinReturn<T, WithElementInternals> {
50
+ abstract class WithElementInternalsElement
51
+ extends base
52
+ implements WithElementInternals
53
+ {
54
+ get [internals]() {
55
+ // Create internals in getter so that it can be used in methods called on
56
+ // construction in `ReactiveElement`, such as `requestUpdate()`.
57
+ if (!this[privateInternals]) {
58
+ // Cast needed for closure
59
+ this[privateInternals] = (this as HTMLElement).attachInternals();
60
+ }
61
+
62
+ return this[privateInternals];
63
+ }
64
+
65
+ // In preparation for ES2022, we need to declare this property to guard
66
+ // against the base class calling [internals] in its constructor prematurely
67
+ // setting this field. Without declare, once this field is defined, it would
68
+ // initialize to undefined and `attachInternals()` could be called again.
69
+ declare [privateInternals]?: ElementInternals;
70
+ }
71
+
72
+ return WithElementInternalsElement;
73
+ }
@@ -0,0 +1,295 @@
1
+ import { LitElement, PropertyDeclaration } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+
4
+ import { internals, WithElementInternals } from './element-internals.js';
5
+ import { MixinBase, MixinReturn } from './mixin.js';
6
+
7
+ /**
8
+ * A form-associated element.
9
+ */
10
+ export interface FormAssociated {
11
+ /**
12
+ * The associated form element with which this element's value will submit.
13
+ */
14
+ readonly form: HTMLFormElement | null;
15
+
16
+ /**
17
+ * The labels this element is associated with.
18
+ */
19
+ readonly labels: NodeList;
20
+
21
+ /**
22
+ * The HTML name to use in form submission.
23
+ */
24
+ name: string;
25
+
26
+ /**
27
+ * Whether or not the element is disabled.
28
+ */
29
+ disabled: boolean;
30
+
31
+ /**
32
+ * Gets the current form value of a component. Defaults to the component's
33
+ * `value` attribute.
34
+ *
35
+ * @return The current form value.
36
+ */
37
+ [getFormValue](): FormValue | null;
38
+
39
+ /**
40
+ * Gets the current form state of a component. Defaults to the component's
41
+ * `[getFormValue]()` result.
42
+ *
43
+ * Use this when the state of an element is different from its value, such as
44
+ * checkboxes (internal boolean state and a user string value).
45
+ *
46
+ * @return The current form state, defaults to the form value.
47
+ */
48
+ [getFormState](): FormValue | null;
49
+
50
+ /**
51
+ * A callback for when a form component should be disabled or enabled. This
52
+ * can be called in a variety of situations, such as disabled `<fieldset>`s.
53
+ *
54
+ * @param disabled Whether or not the form control should be disabled.
55
+ */
56
+ formDisabledCallback(disabled: boolean): void;
57
+
58
+ /**
59
+ * An optional callback for when the form requests to reset its value.
60
+ * Typically, the default value that is reset is represented in the attribute
61
+ * of an element.
62
+ *
63
+ * This means the attribute used for the value should not update as the value
64
+ * changes. For example, a checkbox should not change its default `checked`
65
+ * attribute when selected. Ensure form values do not reflect.
66
+ */
67
+ formResetCallback?(): void;
68
+
69
+ /**
70
+ * An optional callback for when the form restores the state of a component.
71
+ * For example, when a page is reloaded or forms are autofilled.
72
+ *
73
+ * @param state The state to restore, or null to reset the form control's
74
+ * value.
75
+ * @param reason The reason state was restored, either `'restore'` or
76
+ * `'autocomplete'`.
77
+ */
78
+ formStateRestoreCallback?(
79
+ state: FormRestoreState | null,
80
+ reason: FormRestoreReason,
81
+ ): void;
82
+
83
+ /**
84
+ * An optional callback for when the associated form changes.
85
+ *
86
+ * @param form The new associated form, or `null` if there is none.
87
+ */
88
+ formAssociatedCallback?(form: HTMLFormElement | null): void;
89
+ }
90
+
91
+ /**
92
+ * The constructor of a `FormAssociated` element.
93
+ */
94
+ export interface FormAssociatedConstructor {
95
+ /**
96
+ * Indicates that an element is participating in form association.
97
+ */
98
+ readonly formAssociated: true;
99
+ }
100
+
101
+ /**
102
+ * A symbol property to retrieve the form value for an element.
103
+ */
104
+ export const getFormValue = Symbol('getFormValue');
105
+
106
+ /**
107
+ * A symbol property to retrieve the form state for an element.
108
+ */
109
+ export const getFormState = Symbol('getFormState');
110
+
111
+ /**
112
+ * Mixes in form-associated behavior for a class. This allows an element to add
113
+ * values to `<form>` elements.
114
+ *
115
+ * Implementing classes should provide a `[formValue]` to return the current
116
+ * value of the element, as well as reset and restore callbacks.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const base = mixinFormAssociated(mixinElementInternals(LitElement));
121
+ *
122
+ * class MyControl extends base {
123
+ * \@property()
124
+ * value = '';
125
+ *
126
+ * override [getFormValue]() {
127
+ * return this.value;
128
+ * }
129
+ *
130
+ * override formResetCallback() {
131
+ * const defaultValue = this.getAttribute('value');
132
+ * this.value = defaultValue;
133
+ * }
134
+ *
135
+ * override formStateRestoreCallback(state: string) {
136
+ * this.value = state;
137
+ * }
138
+ * }
139
+ * ```
140
+ *
141
+ * Elements may optionally provide a `[formState]` if their values do not
142
+ * represent the state of the component.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const base = mixinFormAssociated(mixinElementInternals(LitElement));
147
+ *
148
+ * class MyCheckbox extends base {
149
+ * \@property()
150
+ * value = 'on';
151
+ *
152
+ * \@property({type: Boolean})
153
+ * checked = false;
154
+ *
155
+ * override [getFormValue]() {
156
+ * return this.checked ? this.value : null;
157
+ * }
158
+ *
159
+ * override [getFormState]() {
160
+ * return String(this.checked);
161
+ * }
162
+ *
163
+ * override formResetCallback() {
164
+ * const defaultValue = this.hasAttribute('checked');
165
+ * this.checked = defaultValue;
166
+ * }
167
+ *
168
+ * override formStateRestoreCallback(state: string) {
169
+ * this.checked = Boolean(state);
170
+ * }
171
+ * }
172
+ * ```
173
+ *
174
+ * @param base The class to mix functionality into. The base class must use
175
+ * `mixinElementInternals()`.
176
+ * @return The provided class with `FormAssociated` mixed in.
177
+ */
178
+ export function mixinFormAssociated<
179
+ T extends MixinBase<LitElement & WithElementInternals>,
180
+ >(base: T): MixinReturn<T & FormAssociatedConstructor, FormAssociated> {
181
+ abstract class FormAssociatedElement extends base implements FormAssociated {
182
+ /** @nocollapse */
183
+ static readonly formAssociated = true;
184
+
185
+ get form() {
186
+ return this[internals].form;
187
+ }
188
+
189
+ get labels() {
190
+ return this[internals].labels;
191
+ }
192
+
193
+ // Use @property for the `name` and `disabled` properties to add them to the
194
+ // `observedAttributes` array and trigger `attributeChangedCallback()`.
195
+ //
196
+ // We don't use Lit's default getter/setter (`noAccessor: true`) because
197
+ // the attributes need to be updated synchronously to work with synchronous
198
+ // form APIs, and Lit updates attributes async by default.
199
+ @property({ noAccessor: true })
200
+ get name() {
201
+ return this.getAttribute('name') ?? '';
202
+ }
203
+ set name(name: string) {
204
+ // Note: setting name to null or empty does not remove the attribute.
205
+ this.setAttribute('name', name);
206
+ // We don't need to call `requestUpdate()` since it's called synchronously
207
+ // in `attributeChangedCallback()`.
208
+ }
209
+
210
+ @property({ type: Boolean, noAccessor: true })
211
+ get disabled() {
212
+ return this.hasAttribute('disabled');
213
+ }
214
+ set disabled(disabled: boolean) {
215
+ // Coerce `disabled` in `Boolean()` to ensure that setting to `null` or
216
+ // `undefined` sets the attribute to `false`.
217
+ this.toggleAttribute('disabled', Boolean(disabled));
218
+ // We don't need to call `requestUpdate()` since it's called synchronously
219
+ // in `attributeChangedCallback()`.
220
+ }
221
+
222
+ override attributeChangedCallback(
223
+ name: string,
224
+ old: string | null,
225
+ value: string | null,
226
+ ) {
227
+ // Manually `requestUpdate()` for `name` and `disabled` when their
228
+ // attribute or property changes.
229
+ // The properties update their attributes, so this callback is invoked
230
+ // immediately when the properties are set. We call `requestUpdate()` here
231
+ // instead of letting Lit set the properties from the attribute change.
232
+ // That would cause the properties to re-set the attribute and invoke this
233
+ // callback again in a loop. This leads to stale state when Lit tries to
234
+ // determine if a property changed or not.
235
+ if (name === 'name' || name === 'disabled') {
236
+ // Disabled's value is only false if the attribute is missing and null.
237
+ const oldValue = name === 'disabled' ? old !== null : old;
238
+ // Trigger a lit update when the attribute changes.
239
+ this.requestUpdate(name, oldValue);
240
+ return;
241
+ }
242
+
243
+ super.attributeChangedCallback(name, old, value);
244
+ }
245
+
246
+ override requestUpdate(
247
+ name?: PropertyKey,
248
+ oldValue?: unknown,
249
+ options?: PropertyDeclaration,
250
+ ) {
251
+ super.requestUpdate(name, oldValue, options);
252
+ // If any properties change, update the form value, which may have changed
253
+ // as well.
254
+ // Update the form value synchronously in `requestUpdate()` rather than
255
+ // `update()` or `updated()`, which are async. This is necessary to ensure
256
+ // that form data is updated in time for synchronous event listeners.
257
+ this[internals].setFormValue(this[getFormValue](), this[getFormState]());
258
+ }
259
+
260
+ [getFormValue](): FormValue | null {
261
+ return this.getAttribute('value');
262
+ }
263
+
264
+ [getFormState](): FormValue | null {
265
+ return this[getFormValue]();
266
+ }
267
+
268
+ formDisabledCallback(disabled: boolean) {
269
+ this.disabled = disabled;
270
+ }
271
+ }
272
+
273
+ return FormAssociatedElement;
274
+ }
275
+
276
+ /**
277
+ * A value that can be provided for form submission and state.
278
+ */
279
+ export type FormValue = File | string | FormData;
280
+
281
+ /**
282
+ * A value to be restored for a component's form value. If a component's form
283
+ * state is a `FormData` object, its entry list of name and values will be
284
+ * provided.
285
+ */
286
+ export type FormRestoreState =
287
+ | File
288
+ | string
289
+ | Array<[string, FormDataEntryValue]>;
290
+
291
+ /**
292
+ * The reason a form component is being restored for, either `'restore'` for
293
+ * browser restoration or `'autocomplete'` for restoring user values.
294
+ */
295
+ export type FormRestoreReason = 'restore' | 'autocomplete';
@@ -0,0 +1,133 @@
1
+ import { isServer, LitElement } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+
4
+ import { afterDispatch, setupDispatchHooks } from '../events/dispatch-hooks.js';
5
+ import { internals, WithElementInternals } from './element-internals.js';
6
+ import { MixinBase, MixinReturn } from './mixin.js';
7
+
8
+ /**
9
+ * A string indicating the form submission behavior of the element.
10
+ *
11
+ * - submit: The element submits the form. This is the default value if the
12
+ * attribute is not specified, or if it is dynamically changed to an empty or
13
+ * invalid value.
14
+ * - reset: The element resets the form.
15
+ * - button: The element does nothing.
16
+ */
17
+ export type FormSubmitterType = 'button' | 'submit' | 'reset';
18
+
19
+ /**
20
+ * An element that can submit or reset a `<form>`, similar to
21
+ * `<button type="submit">`.
22
+ */
23
+ export interface FormSubmitter {
24
+ /**
25
+ * A string indicating the form submission behavior of the element.
26
+ *
27
+ * - submit: The element submits the form. This is the default value if the
28
+ * attribute is not specified, or if it is dynamically changed to an empty or
29
+ * invalid value.
30
+ * - reset: The element resets the form.
31
+ * - button: The element does nothing.
32
+ */
33
+ type: string;
34
+
35
+ /**
36
+ * The HTML name to use in form submission. When combined with a `value`, the
37
+ * submitting button's name/value will be added to the form.
38
+ *
39
+ * Names must reflect to a `name` attribute for form integration.
40
+ */
41
+ name: string;
42
+
43
+ /**
44
+ * The value of the button. When combined with a `name`, the submitting
45
+ * button's name/value will be added to the form.
46
+ */
47
+ value: string;
48
+ }
49
+
50
+ /**
51
+ * Mixes in form submitter behavior for a class.
52
+ *
53
+ * A click listener is added to each element instance. If the click is not
54
+ * default prevented, it will submit the element's form, if any.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const base = mixinFormSubmitter(mixinElementInternals(LitElement));
59
+ * class MyButton extends base {
60
+ * static formAssociated = true;
61
+ * }
62
+ * ```
63
+ *
64
+ * @param base The class to mix functionality into.
65
+ * @return The provided class with `FormSubmitter` mixed in.
66
+ */
67
+ export function mixinFormSubmitter<
68
+ T extends MixinBase<LitElement & WithElementInternals>,
69
+ >(base: T): MixinReturn<T, FormSubmitter> {
70
+ abstract class FormSubmitterElement extends base implements FormSubmitter {
71
+ @property() type = 'submit';
72
+
73
+ @property({ reflect: true }) value = '';
74
+
75
+ // Name attribute must reflect synchronously for form integration.
76
+ get name() {
77
+ return this.getAttribute('name') ?? '';
78
+ }
79
+
80
+ set name(name: string) {
81
+ this.setAttribute('name', name);
82
+ }
83
+
84
+ // Mixins must have a constructor with `...args: any[]`
85
+ // tslint:disable-next-line:no-any
86
+ constructor(...args: any[]) {
87
+ super(...args);
88
+ if (isServer) return;
89
+ setupDispatchHooks(this, 'click');
90
+ this.addEventListener('click', async (event: Event) => {
91
+ const isReset = this.type === 'reset';
92
+ const isSubmit = this.type === 'submit';
93
+ const elementInternals = this[internals];
94
+ const { form } = elementInternals;
95
+ if (!form || !(isSubmit || isReset)) {
96
+ return;
97
+ }
98
+
99
+ afterDispatch(event, () => {
100
+ if (event.defaultPrevented) {
101
+ return;
102
+ }
103
+
104
+ if (isReset) {
105
+ form.reset();
106
+ return;
107
+ }
108
+
109
+ // form.requestSubmit(submitter) does not work with form associated custom
110
+ // elements. This patches the dispatched submit event to add the correct
111
+ // `submitter`.
112
+ // See https://github.com/WICG/webcomponents/issues/814
113
+ form.addEventListener(
114
+ 'submit',
115
+ (submitEvent: Event) => {
116
+ Object.defineProperty(submitEvent, 'submitter', {
117
+ configurable: true,
118
+ enumerable: true,
119
+ get: () => this,
120
+ });
121
+ },
122
+ { capture: true, once: true },
123
+ );
124
+
125
+ elementInternals.setFormValue(this.value);
126
+ form.requestSubmit();
127
+ });
128
+ });
129
+ }
130
+ }
131
+
132
+ return FormSubmitterElement;
133
+ }