@inglorious/ui 0.1.0 → 1.0.0

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 (283) hide show
  1. package/README.md +45 -0
  2. package/package.json +191 -16
  3. package/src/all.css +7 -0
  4. package/src/controls/button/button.stories.js +35 -15
  5. package/src/controls/button/index.js +1 -3
  6. package/src/controls/button/style.css +80 -37
  7. package/src/controls/button/template.js +23 -26
  8. package/src/controls/button-group/button-group.stories.js +19 -15
  9. package/src/controls/button-group/index.js +1 -2
  10. package/src/controls/button-group/style.css +0 -7
  11. package/src/controls/button-group/template.js +46 -56
  12. package/src/controls/checkbox/checkbox.stories.js +16 -13
  13. package/src/controls/checkbox/index.js +1 -2
  14. package/src/controls/checkbox/style.css +23 -2
  15. package/src/controls/checkbox/template.js +20 -18
  16. package/src/controls/combobox/combobox.stories.js +92 -0
  17. package/src/controls/{select → combobox}/handlers.js +8 -5
  18. package/src/controls/combobox/helpers.js +91 -0
  19. package/src/controls/combobox/index.js +43 -0
  20. package/src/controls/combobox/style.css +203 -0
  21. package/src/controls/combobox/template.js +340 -0
  22. package/src/controls/controls.css +12 -0
  23. package/src/controls/fab/fab.stories.js +11 -11
  24. package/src/controls/fab/index.js +1 -2
  25. package/src/controls/fab/template.js +21 -19
  26. package/src/controls/icon-button/icon-button.stories.js +8 -10
  27. package/src/controls/icon-button/index.js +1 -2
  28. package/src/controls/icon-button/template.js +13 -19
  29. package/src/controls/input/index.js +1 -2
  30. package/src/controls/input/input.stories.js +24 -23
  31. package/src/controls/input/style.css +9 -7
  32. package/src/controls/input/template.js +28 -31
  33. package/src/controls/radio-group/index.js +1 -2
  34. package/src/controls/radio-group/radio-group.stories.js +11 -8
  35. package/src/controls/radio-group/style.css +22 -1
  36. package/src/controls/radio-group/template.js +20 -15
  37. package/src/controls/rating/index.js +1 -2
  38. package/src/controls/rating/rating.stories.js +7 -10
  39. package/src/controls/rating/style.css +1 -2
  40. package/src/controls/rating/template.js +20 -17
  41. package/src/controls/select/helpers.js +2 -21
  42. package/src/controls/select/index.js +1 -13
  43. package/src/controls/select/select.stories.js +68 -64
  44. package/src/controls/select/style.css +66 -189
  45. package/src/controls/select/template.js +77 -406
  46. package/src/controls/slider/index.js +1 -2
  47. package/src/controls/slider/slider.stories.js +15 -12
  48. package/src/controls/slider/style.css +24 -3
  49. package/src/controls/slider/template.js +30 -23
  50. package/src/controls/switch/index.js +1 -2
  51. package/src/controls/switch/style.css +23 -2
  52. package/src/controls/switch/switch.stories.js +14 -11
  53. package/src/controls/switch/template.js +18 -16
  54. package/src/data-display/avatar/avatar.stories.js +106 -0
  55. package/src/data-display/avatar/index.js +3 -0
  56. package/src/data-display/avatar/style.css +64 -0
  57. package/src/data-display/avatar/template.js +81 -0
  58. package/src/data-display/badge/badge.stories.js +64 -0
  59. package/src/data-display/badge/index.js +3 -0
  60. package/src/data-display/badge/style.css +84 -0
  61. package/src/data-display/badge/template.js +46 -0
  62. package/src/data-display/chip/chip.stories.js +57 -0
  63. package/src/data-display/chip/index.js +3 -0
  64. package/src/data-display/chip/style.css +84 -0
  65. package/src/data-display/chip/template.js +32 -0
  66. package/src/data-display/data-display.css +11 -0
  67. package/src/data-display/data-grid/base.css +58 -0
  68. package/src/data-display/data-grid/data-grid.stories.js +158 -0
  69. package/src/data-display/data-grid/filters/helpers.js +8 -0
  70. package/src/data-display/data-grid/filters/index.js +21 -0
  71. package/src/data-display/data-grid/filters/input.js +24 -0
  72. package/src/data-display/data-grid/filters/range.js +48 -0
  73. package/src/data-display/data-grid/filters/select.js +17 -0
  74. package/src/data-display/data-grid/handlers.js +523 -0
  75. package/src/data-display/data-grid/helpers.js +248 -0
  76. package/src/data-display/data-grid/index.js +64 -0
  77. package/src/data-display/data-grid/style.css +14 -0
  78. package/src/data-display/data-grid/template.js +458 -0
  79. package/src/data-display/data-grid/theme.css +148 -0
  80. package/src/data-display/divider/divider.stories.js +48 -0
  81. package/src/data-display/divider/index.js +3 -0
  82. package/src/data-display/divider/style.css +18 -0
  83. package/src/data-display/divider/template.js +17 -0
  84. package/src/data-display/icon/icon-implementations.mdx +160 -0
  85. package/src/data-display/icon/icon-utf8.stories.js +156 -0
  86. package/src/data-display/icon/icon.stories.js +38 -0
  87. package/src/data-display/icon/index.js +3 -0
  88. package/src/data-display/icon/style.css +17 -0
  89. package/src/data-display/icon/template.js +19 -0
  90. package/src/data-display/list/handlers.js +25 -0
  91. package/src/data-display/list/index.js +4 -0
  92. package/src/data-display/list/list.stories.js +187 -0
  93. package/src/data-display/list/style.css +119 -0
  94. package/src/data-display/list/template.js +302 -0
  95. package/src/data-display/material-icon/index.js +3 -0
  96. package/src/data-display/material-icon/material-icon.stories.js +99 -0
  97. package/src/data-display/material-icon/style.css +27 -0
  98. package/src/data-display/material-icon/template.js +21 -0
  99. package/src/data-display/table/index.js +1 -0
  100. package/src/data-display/table/style.css +42 -0
  101. package/src/data-display/table/table.stories.js +40 -0
  102. package/src/data-display/table/template.js +114 -0
  103. package/src/data-display/tooltip/index.js +3 -0
  104. package/src/data-display/tooltip/style.css +57 -0
  105. package/src/data-display/tooltip/template.js +58 -0
  106. package/src/data-display/tooltip/tooltip.stories.js +44 -0
  107. package/src/data-display/typography/index.js +3 -0
  108. package/src/data-display/typography/style.css +49 -0
  109. package/src/data-display/typography/template.js +110 -0
  110. package/src/data-display/typography/typography.stories.js +48 -0
  111. package/src/data-display/virtual-list/handlers.js +68 -0
  112. package/src/data-display/virtual-list/index.js +4 -0
  113. package/src/data-display/virtual-list/template.js +101 -0
  114. package/src/examples/dashboard/app-drawer.js +255 -0
  115. package/src/examples/dashboard/app-header.js +149 -0
  116. package/src/examples/dashboard/dashboard.js +85 -0
  117. package/src/examples/dashboard/dashboard.stories.js +47 -0
  118. package/src/examples/dashboard/data.js +205 -0
  119. package/src/examples/dashboard/mode.js +27 -0
  120. package/src/examples/dashboard/primitive-content.js +1325 -0
  121. package/src/examples/dashboard/primitive-section.js +158 -0
  122. package/src/examples/dashboard/router.js +13 -0
  123. package/src/examples/dashboard/social-card.js +73 -0
  124. package/src/examples/dashboard/stat-card.js +84 -0
  125. package/src/examples/dashboard/style.css +339 -0
  126. package/src/examples/dashboard/theme-utils.js +95 -0
  127. package/src/examples/dashboard/theme.js +27 -0
  128. package/src/examples/dashboard/traffic-card.js +108 -0
  129. package/src/examples/dashboard/traffic-sales-card.js +267 -0
  130. package/src/feedback/alert/alert.stories.js +70 -0
  131. package/src/feedback/alert/index.js +3 -0
  132. package/src/feedback/alert/style.css +98 -0
  133. package/src/feedback/alert/template.js +74 -0
  134. package/src/feedback/backdrop/backdrop.stories.js +21 -0
  135. package/src/feedback/backdrop/index.js +3 -0
  136. package/src/feedback/backdrop/style.css +25 -0
  137. package/src/feedback/backdrop/template.js +31 -0
  138. package/src/feedback/dialog/dialog.stories.js +27 -0
  139. package/src/feedback/dialog/index.js +3 -0
  140. package/src/feedback/dialog/style.css +68 -0
  141. package/src/feedback/dialog/template.js +64 -0
  142. package/src/feedback/feedback.css +6 -0
  143. package/src/feedback/progress/index.js +3 -0
  144. package/src/feedback/progress/progress.stories.js +54 -0
  145. package/src/feedback/progress/style.css +95 -0
  146. package/src/feedback/progress/template.js +88 -0
  147. package/src/feedback/skeleton/index.js +3 -0
  148. package/src/feedback/skeleton/skeleton.stories.js +44 -0
  149. package/src/feedback/skeleton/style.css +41 -0
  150. package/src/feedback/skeleton/template.js +48 -0
  151. package/src/feedback/snackbar/index.js +3 -0
  152. package/src/feedback/snackbar/snackbar.stories.js +25 -0
  153. package/src/feedback/snackbar/style.css +64 -0
  154. package/src/feedback/snackbar/template.js +55 -0
  155. package/src/index.js +32 -1
  156. package/src/layout/container/container.stories.js +105 -0
  157. package/src/layout/container/index.js +3 -0
  158. package/src/layout/container/style.css +34 -0
  159. package/src/layout/container/template.js +119 -0
  160. package/src/layout/flex/flex.stories.js +28 -10
  161. package/src/layout/flex/index.js +1 -2
  162. package/src/layout/flex/style.css +20 -0
  163. package/src/layout/flex/template.js +40 -13
  164. package/src/layout/grid/grid.stories.js +46 -30
  165. package/src/layout/grid/index.js +1 -2
  166. package/src/layout/grid/style.css +20 -0
  167. package/src/layout/grid/template.js +100 -20
  168. package/src/layout/layout.css +3 -0
  169. package/src/navigation/bottom-navigation/bottom-navigation.stories.js +33 -0
  170. package/src/navigation/bottom-navigation/index.js +1 -0
  171. package/src/navigation/bottom-navigation/style.css +32 -0
  172. package/src/navigation/bottom-navigation/template.js +74 -0
  173. package/src/navigation/breadcrumbs/breadcrumbs.stories.js +33 -0
  174. package/src/navigation/breadcrumbs/index.js +1 -0
  175. package/src/navigation/breadcrumbs/style.css +27 -0
  176. package/src/navigation/breadcrumbs/template.js +79 -0
  177. package/src/navigation/drawer/drawer.stories.js +60 -0
  178. package/src/navigation/drawer/index.js +3 -0
  179. package/src/navigation/drawer/style.css +125 -0
  180. package/src/navigation/drawer/template.js +131 -0
  181. package/src/navigation/link/index.js +3 -0
  182. package/src/navigation/link/link.stories.js +53 -0
  183. package/src/navigation/link/style.css +40 -0
  184. package/src/navigation/link/template.js +53 -0
  185. package/src/navigation/menu/index.js +1 -0
  186. package/src/navigation/menu/menu.stories.js +36 -0
  187. package/src/navigation/menu/style.css +44 -0
  188. package/src/navigation/menu/template.js +81 -0
  189. package/src/navigation/navigation.css +9 -0
  190. package/src/navigation/pagination/index.js +1 -0
  191. package/src/navigation/pagination/pagination.stories.js +61 -0
  192. package/src/navigation/pagination/style.css +29 -0
  193. package/src/navigation/pagination/template.js +140 -0
  194. package/src/navigation/speed-dial/index.js +1 -0
  195. package/src/navigation/speed-dial/speed-dial.stories.js +40 -0
  196. package/src/navigation/speed-dial/style.css +38 -0
  197. package/src/navigation/speed-dial/template.js +68 -0
  198. package/src/navigation/stepper/index.js +1 -0
  199. package/src/navigation/stepper/stepper.stories.js +35 -0
  200. package/src/navigation/stepper/style.css +49 -0
  201. package/src/navigation/stepper/template.js +61 -0
  202. package/src/navigation/tabs/index.js +1 -0
  203. package/src/navigation/tabs/style.css +35 -0
  204. package/src/navigation/tabs/tabs.stories.js +40 -0
  205. package/src/navigation/tabs/template.js +79 -0
  206. package/src/overview.mdx +39 -0
  207. package/src/stories/notifyStory.js +22 -25
  208. package/src/styles/base.css +2 -0
  209. package/src/styles/reset.css +15 -0
  210. package/src/{themes → styles/themes}/bootstrap.css +2 -0
  211. package/src/{themes → styles/themes}/inglorious.css +9 -1
  212. package/src/{themes → styles/themes}/material.css +2 -0
  213. package/src/{tokens/index.css → styles/tokens.css} +9 -0
  214. package/src/surfaces/accordion/accordion.stories.js +60 -0
  215. package/src/surfaces/accordion/index.js +1 -0
  216. package/src/surfaces/accordion/style.css +64 -0
  217. package/src/surfaces/accordion/template.js +85 -0
  218. package/src/surfaces/app-bar/app-bar.stories.js +109 -0
  219. package/src/surfaces/app-bar/index.js +3 -0
  220. package/src/surfaces/app-bar/style.css +109 -0
  221. package/src/surfaces/app-bar/template.js +78 -0
  222. package/src/surfaces/card/card.stories.js +108 -0
  223. package/src/surfaces/card/index.js +1 -0
  224. package/src/surfaces/card/style.css +107 -0
  225. package/src/surfaces/card/template.js +163 -0
  226. package/src/surfaces/paper/index.js +3 -0
  227. package/src/surfaces/paper/paper.stories.js +97 -0
  228. package/src/surfaces/paper/style.css +73 -0
  229. package/src/surfaces/paper/template.js +76 -0
  230. package/src/surfaces/surfaces.css +4 -0
  231. package/types/controls/button-group.d.ts +8 -7
  232. package/types/controls/button.d.ts +10 -7
  233. package/types/controls/checkbox.d.ts +8 -6
  234. package/types/controls/combobox.d.ts +66 -0
  235. package/types/controls/fab.d.ts +6 -5
  236. package/types/controls/icon-button.d.ts +8 -7
  237. package/types/controls/input.d.ts +18 -11
  238. package/types/controls/radio-group.d.ts +7 -5
  239. package/types/controls/rating.d.ts +6 -5
  240. package/types/controls/select.d.ts +11 -34
  241. package/types/controls/slider.d.ts +8 -6
  242. package/types/controls/switch.d.ts +7 -5
  243. package/types/data-display/avatar.d.ts +30 -0
  244. package/types/data-display/badge.d.ts +20 -0
  245. package/types/data-display/chip.d.ts +25 -0
  246. package/types/data-display/data-grid.d.ts +151 -0
  247. package/types/data-display/divider.d.ts +14 -0
  248. package/types/data-display/icon.d.ts +16 -0
  249. package/types/data-display/list.d.ts +66 -0
  250. package/types/data-display/material-icon.d.ts +15 -0
  251. package/types/data-display/table.d.ts +45 -0
  252. package/types/data-display/tooltip.d.ts +20 -0
  253. package/types/data-display/typography.d.ts +28 -0
  254. package/types/data-display/virtual-list.d.ts +94 -0
  255. package/types/feedback/alert.d.ts +22 -0
  256. package/types/feedback/backdrop.d.ts +17 -0
  257. package/types/feedback/dialog.d.ts +21 -0
  258. package/types/feedback/progress.d.ts +18 -0
  259. package/types/feedback/skeleton.d.ts +18 -0
  260. package/types/feedback/snackbar.d.ts +19 -0
  261. package/types/index.d.ts +92 -14
  262. package/types/layout/container.d.ts +28 -0
  263. package/types/layout/flex.d.ts +16 -5
  264. package/types/layout/grid.d.ts +15 -4
  265. package/types/navigation/bottom-navigation.d.ts +33 -0
  266. package/types/navigation/breadcrumbs.d.ts +29 -0
  267. package/types/navigation/drawer.d.ts +23 -0
  268. package/types/navigation/link.d.ts +22 -0
  269. package/types/navigation/menu.d.ts +32 -0
  270. package/types/navigation/pagination.d.ts +50 -0
  271. package/types/navigation/speed-dial.d.ts +35 -0
  272. package/types/navigation/stepper.d.ts +26 -0
  273. package/types/navigation/tabs.d.ts +31 -0
  274. package/types/surfaces/accordion.d.ts +32 -0
  275. package/types/surfaces/app-bar.d.ts +25 -0
  276. package/types/surfaces/card.d.ts +39 -0
  277. package/types/surfaces/paper.d.ts +28 -0
  278. package/src/shared/withRenderValidation.js +0 -19
  279. package/src/widgets/card/card.stories.js +0 -135
  280. package/src/widgets/card/index.js +0 -4
  281. package/src/widgets/card/style.css +0 -53
  282. package/src/widgets/card/template.js +0 -97
  283. package/types/widgets/card.d.ts +0 -21
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @typedef {import('../../../types/controls/select').SelectOption} SelectOption
3
+ */
4
+
5
+ /**
6
+ * Get the value of an option.
7
+ * @param {SelectOption} option
8
+ * @returns {string|number}
9
+ */
10
+ export function getOptionValue(option) {
11
+ if (typeof option === "object" && option !== null && "value" in option) {
12
+ return option.value
13
+ }
14
+
15
+ return option
16
+ }
17
+
18
+ /**
19
+ * Get the label of an option.
20
+ * @param {SelectOption} option
21
+ * @returns {string}
22
+ */
23
+ export function getOptionLabel(option) {
24
+ if (typeof option === "object" && option !== null && "label" in option) {
25
+ return String(option.label)
26
+ }
27
+
28
+ if (typeof option === "object" && option !== null && "value" in option) {
29
+ return String(option.value)
30
+ }
31
+
32
+ return String(option)
33
+ }
34
+
35
+ /**
36
+ * Filter options based on search term.
37
+ * @param {SelectOption[]} options
38
+ * @param {string} searchTerm
39
+ * @returns {SelectOption[]}
40
+ */
41
+ export function filterOptions(options, searchTerm) {
42
+ if (!searchTerm || searchTerm.trim() === "") {
43
+ return options
44
+ }
45
+
46
+ const searchLower = String(searchTerm).toLowerCase().trim()
47
+
48
+ return options.filter((option) => {
49
+ const label = getOptionLabel(option)
50
+ return label.toLowerCase().includes(searchLower)
51
+ })
52
+ }
53
+
54
+ /**
55
+ * Check whether an option is selected.
56
+ * @param {SelectOption} option
57
+ * @param {string|number|(string|number)[]|null} selectedValue
58
+ * @param {boolean} isMulti
59
+ * @returns {boolean}
60
+ */
61
+ export function isOptionSelected(option, selectedValue, isMulti) {
62
+ const optionValue = getOptionValue(option)
63
+
64
+ if (isMulti && Array.isArray(selectedValue)) {
65
+ return selectedValue.some((value) => value === optionValue)
66
+ }
67
+
68
+ return selectedValue === optionValue
69
+ }
70
+
71
+ /**
72
+ * Normalize option to object shape used in rendering/handlers.
73
+ * @param {SelectOption} option
74
+ * @returns {{ value: string|number, label: string, isDisabled?: boolean }}
75
+ */
76
+ export function formatOption(option) {
77
+ if (typeof option === "string" || typeof option === "number") {
78
+ return { value: option, label: String(option) }
79
+ }
80
+
81
+ if (typeof option === "object" && option !== null) {
82
+ return {
83
+ value: option.value ?? option,
84
+ label: option.label ?? String(option.value ?? option),
85
+ isDisabled: option.isDisabled ?? option.disabled ?? false,
86
+ ...option,
87
+ }
88
+ }
89
+
90
+ return { value: String(option), label: String(option) }
91
+ }
@@ -0,0 +1,43 @@
1
+ import * as handlers from "./handlers.js"
2
+ import * as helpers from "./helpers.js"
3
+ import { combobox as renderers } from "./template.js"
4
+
5
+ export const combobox = {
6
+ ...handlers,
7
+ ...renderers,
8
+ render(entity, api) {
9
+ const id = entity.id
10
+ const props = {
11
+ ...entity,
12
+ onToggle: () => api.notify(`#${id}:toggle`),
13
+ onClear: () => {
14
+ api.notify(`#${id}:clear`)
15
+ entity.onClear?.()
16
+ },
17
+ onClose: () => {
18
+ api.notify(`#${id}:close`)
19
+ entity.onClose?.()
20
+ },
21
+ onSearchChange: (value) => {
22
+ api.notify(`#${id}:searchChange`, value)
23
+ entity.onSearchChange?.(value)
24
+ },
25
+ onFocusSet: (index) => api.notify(`#${id}:focusSet`, index),
26
+ onFocusNext: () => api.notify(`#${id}:focusNext`),
27
+ onFocusPrev: () => api.notify(`#${id}:focusPrev`),
28
+ onFocusFirst: () => api.notify(`#${id}:focusFirst`),
29
+ onFocusLast: () => api.notify(`#${id}:focusLast`),
30
+ onOptionSelect: (option) => api.notify(`#${id}:optionSelect`, option),
31
+ }
32
+
33
+ return renderers.render(props)
34
+ },
35
+ }
36
+
37
+ export const {
38
+ filterOptions,
39
+ formatOption,
40
+ getOptionLabel,
41
+ getOptionValue,
42
+ isOptionSelected,
43
+ } = helpers
@@ -0,0 +1,203 @@
1
+ @import "../../data-display/chip/style.css";
2
+
3
+ .iw-combobox {
4
+ position: relative;
5
+ display: inline-flex;
6
+ flex-direction: column;
7
+ gap: var(--iw-space-1);
8
+ font-family: var(--iw-font-family-sans);
9
+
10
+ &.iw-combobox-full-width {
11
+ width: 100%;
12
+ }
13
+
14
+ .iw-combobox-label {
15
+ font-size: var(--iw-font-size-sm);
16
+ color: var(--iw-color-text);
17
+ line-height: var(--iw-line-height-normal);
18
+ }
19
+
20
+ .iw-combobox-control {
21
+ height: 2.25rem;
22
+ display: flex;
23
+ align-items: center;
24
+ gap: var(--iw-space-2);
25
+ padding: 0 var(--iw-space-10) 0 var(--iw-space-3);
26
+ border: 1px solid var(--iw-input-border);
27
+ border-radius: var(--iw-input-radius);
28
+ background: var(--iw-input-bg);
29
+ color: var(--iw-input-text);
30
+ cursor: pointer;
31
+ user-select: none;
32
+ transition:
33
+ border-color var(--iw-transition-fast),
34
+ box-shadow var(--iw-transition-fast),
35
+ background-color var(--iw-transition-fast);
36
+
37
+ &:hover {
38
+ border-color: var(--iw-input-border-hover);
39
+ background: var(--iw-input-bg-hover);
40
+ }
41
+
42
+ &.iw-combobox-control-open {
43
+ border-color: var(--iw-input-border-focus);
44
+ box-shadow: var(--iw-input-shadow-focus);
45
+ background: var(--iw-input-bg-focus);
46
+ border-bottom-left-radius: 0;
47
+ border-bottom-right-radius: 0;
48
+ }
49
+
50
+ &.iw-combobox-control-disabled {
51
+ opacity: 0.6;
52
+ cursor: not-allowed;
53
+ }
54
+
55
+ .iw-combobox-value,
56
+ .iw-combobox-placeholder,
57
+ .iw-combobox-multi-value {
58
+ flex: 1;
59
+ min-width: 0;
60
+ }
61
+
62
+ .iw-combobox-placeholder {
63
+ color: var(--iw-color-text-muted);
64
+ }
65
+
66
+ .iw-combobox-multi-value {
67
+ display: flex;
68
+ flex-wrap: nowrap;
69
+ align-items: center;
70
+ gap: var(--iw-space-1);
71
+ overflow-x: auto;
72
+ overflow-y: hidden;
73
+ white-space: nowrap;
74
+ scrollbar-width: none;
75
+
76
+ &::-webkit-scrollbar {
77
+ display: none;
78
+ }
79
+
80
+ .iw-combobox-multi-value-tag {
81
+ display: inline-flex;
82
+ flex: 0 0 auto;
83
+ }
84
+ }
85
+
86
+ .iw-combobox-clear {
87
+ border: 0;
88
+ background: transparent;
89
+ color: var(--iw-color-text-muted);
90
+ padding: 0;
91
+ width: 1.25rem;
92
+ height: 1.25rem;
93
+ display: inline-flex;
94
+ align-items: center;
95
+ justify-content: center;
96
+ cursor: pointer;
97
+ right: var(--iw-space-7);
98
+
99
+ &:hover {
100
+ color: var(--iw-color-text);
101
+ }
102
+ }
103
+
104
+ .iw-combobox-arrow {
105
+ width: 1.25rem;
106
+ height: 1.25rem;
107
+ display: inline-flex;
108
+ align-items: center;
109
+ justify-content: center;
110
+ pointer-events: none;
111
+ position: absolute;
112
+ right: var(--iw-space-3);
113
+ color: var(--iw-color-text-muted);
114
+ transition: transform var(--iw-transition-fast);
115
+
116
+ span {
117
+ font-size: 0.65rem;
118
+ line-height: 1;
119
+ }
120
+ }
121
+
122
+ &.iw-combobox-control-open .iw-combobox-arrow {
123
+ transform: rotate(180deg);
124
+ }
125
+ }
126
+
127
+ .iw-combobox-dropdown {
128
+ position: absolute;
129
+ top: 100%;
130
+ left: 0;
131
+ right: 0;
132
+ z-index: 1000;
133
+ display: flex;
134
+ flex-direction: column;
135
+ max-height: 16rem;
136
+ overflow: hidden;
137
+ border: 1px solid var(--iw-color-border);
138
+ border-radius: var(--iw-radius-md);
139
+ border-top-left-radius: 0;
140
+ border-top-right-radius: 0;
141
+ background: var(--iw-color-bg);
142
+ box-shadow: var(--iw-shadow-lg);
143
+ margin-top: -1px;
144
+
145
+ .iw-combobox-dropdown-search {
146
+ width: 100%;
147
+ border: 0;
148
+ border-bottom: 1px solid var(--iw-color-border);
149
+ background: transparent;
150
+ color: var(--iw-color-text);
151
+ padding: var(--iw-space-2) var(--iw-space-3);
152
+ outline: none;
153
+ }
154
+
155
+ .iw-combobox-dropdown-options {
156
+ max-height: 15rem;
157
+ overflow-y: auto;
158
+
159
+ .iw-combobox-dropdown-options-option {
160
+ display: flex;
161
+ align-items: center;
162
+ gap: var(--iw-space-2);
163
+ cursor: pointer;
164
+ user-select: none;
165
+ padding: var(--iw-space-2) var(--iw-space-3);
166
+
167
+ &.iw-combobox-dropdown-options-option-disabled {
168
+ opacity: 0.5;
169
+ cursor: not-allowed;
170
+ }
171
+
172
+ &.iw-combobox-dropdown-options-option-focused {
173
+ background: var(--iw-color-bg-secondary);
174
+ }
175
+
176
+ &.iw-combobox-dropdown-options-option-selected {
177
+ background: color-mix(
178
+ in srgb,
179
+ var(--iw-color-primary) 16%,
180
+ var(--iw-color-bg) 84%
181
+ );
182
+ }
183
+ }
184
+ }
185
+
186
+ .iw-combobox-loading,
187
+ .iw-combobox-no-options {
188
+ padding: var(--iw-space-3);
189
+ text-align: center;
190
+ color: var(--iw-color-text-muted);
191
+ }
192
+ }
193
+
194
+ &.iw-combobox-sm .iw-combobox-control {
195
+ height: 2rem;
196
+ padding: 0 var(--iw-space-8) 0 var(--iw-space-2);
197
+ }
198
+
199
+ &.iw-combobox-lg .iw-combobox-control {
200
+ height: 2.75rem;
201
+ padding: 0 var(--iw-space-12) 0 var(--iw-space-4);
202
+ }
203
+ }
@@ -0,0 +1,340 @@
1
+ /**
2
+ * @typedef {import('../../../types/controls/combobox.js').ComboboxProps} ComboboxProps
3
+ * @typedef {import('../../../types/controls/combobox.js').ComboboxOption} ComboboxOption
4
+ * @typedef {import('@inglorious/web').TemplateResult} TemplateResult
5
+ */
6
+
7
+ import { classMap, html, ref, repeat, when } from "@inglorious/web"
8
+
9
+ import { chip } from "../../data-display/chip/index.js"
10
+ import {
11
+ filterOptions,
12
+ formatOption,
13
+ getOptionLabel,
14
+ getOptionValue,
15
+ isOptionSelected,
16
+ } from "./helpers.js"
17
+
18
+ const NO_FOCUSED_INDEX = -1
19
+
20
+ export const combobox = {
21
+ /**
22
+ * Select control render function.
23
+ * @param {ComboboxProps} props
24
+ * @returns {TemplateResult}
25
+ */
26
+ render(props) {
27
+ return html`<div
28
+ class=${classMap({
29
+ "iw-combobox": true,
30
+ "iw-combobox-full-width": !!props.isFullWidth,
31
+ [`iw-combobox-${props.size}`]: props.size !== "md",
32
+ })}
33
+ >
34
+ ${props.label
35
+ ? html`<label class="iw-combobox-label">${props.label}</label>`
36
+ : null}
37
+ ${this.renderControl?.(props)}
38
+ ${when(props.isOpen, () => this.renderDropdown?.(props))}
39
+ </div>`
40
+ },
41
+
42
+ /**
43
+ * Render trigger control.
44
+ * @param {ComboboxProps} props
45
+ * @returns {TemplateResult}
46
+ */
47
+ renderControl(props) {
48
+ return html`<div
49
+ class="iw-combobox-control ${classMap({
50
+ "iw-combobox-control-open": props.isOpen,
51
+ "iw-combobox-control-disabled": props.isDisabled,
52
+ "iw-combobox-control-selection":
53
+ props.isMulti &&
54
+ Array.isArray(props.selectedValue) &&
55
+ props.selectedValue.length,
56
+ })}"
57
+ @click=${() => !props.isDisabled && props.onToggle?.()}
58
+ >
59
+ ${when(
60
+ props.isMulti,
61
+ () => this.renderMultiValue?.(props),
62
+ () => this.renderSingleValue?.(props),
63
+ )}
64
+ ${when(
65
+ props.isClearable &&
66
+ ((props.isMulti &&
67
+ Array.isArray(props.selectedValue) &&
68
+ props.selectedValue.length) ||
69
+ (!props.isMulti && props.selectedValue !== null)),
70
+ () =>
71
+ html`<button
72
+ class="iw-combobox-clear"
73
+ type="button"
74
+ @click=${(event) => {
75
+ event.stopPropagation()
76
+ props.onClear?.()
77
+ }}
78
+ >
79
+ ×
80
+ </button>`,
81
+ )}
82
+
83
+ <div class="iw-combobox-arrow"><span>▼</span></div>
84
+ </div>`
85
+ },
86
+
87
+ /**
88
+ * Render single selected value.
89
+ * @param {ComboboxProps} props
90
+ * @returns {TemplateResult}
91
+ */
92
+ renderSingleValue(props) {
93
+ if (props.selectedValue === null) {
94
+ return html`<span class="iw-combobox-placeholder"
95
+ >${props.placeholder}</span
96
+ >`
97
+ }
98
+
99
+ const selectedOption = props.options.find(
100
+ (option) => getOptionValue(option) === props.selectedValue,
101
+ )
102
+
103
+ return html`<span class="iw-combobox-value"
104
+ >${selectedOption
105
+ ? getOptionLabel(selectedOption)
106
+ : String(props.selectedValue)}</span
107
+ >`
108
+ },
109
+
110
+ /**
111
+ * Render multi selected value tags.
112
+ * @param {ComboboxProps} props
113
+ * @returns {TemplateResult}
114
+ */
115
+ renderMultiValue(props) {
116
+ if (!Array.isArray(props.selectedValue) || !props.selectedValue.length) {
117
+ return html`<span class="iw-combobox-placeholder"
118
+ >${props.placeholder}</span
119
+ >`
120
+ }
121
+
122
+ return html`<div class="iw-combobox-multi-value">
123
+ ${repeat(
124
+ props.selectedValue,
125
+ (value) => value,
126
+ (value) => this.renderMultiValueTag?.(props, value),
127
+ )}
128
+ </div>`
129
+ },
130
+
131
+ /**
132
+ * Render a selected multi-value tag.
133
+ * @param {ComboboxProps} props
134
+ * @param {string|number} value
135
+ * @returns {TemplateResult}
136
+ */
137
+ renderMultiValueTag(props, value) {
138
+ const option = props.options.find((opt) => getOptionValue(opt) === value)
139
+ const tagId = `${props.id}-tag-${String(value)}`
140
+ const chipSize = props.size === "lg" ? "md" : "sm"
141
+
142
+ return html`<span
143
+ class="iw-combobox-multi-value-tag"
144
+ @click=${(event) => event.stopPropagation()}
145
+ >
146
+ ${chip.render({
147
+ id: tagId,
148
+ children: option ? getOptionLabel(option) : String(value),
149
+ isRemovable: true,
150
+ size: chipSize,
151
+ shape: "rounded",
152
+ onClick: () => {
153
+ props.onOptionSelect?.(option)
154
+ props.onChange?.(option)
155
+ },
156
+ })}
157
+ </span>`
158
+ },
159
+
160
+ /**
161
+ * Render dropdown.
162
+ * @param {ComboboxProps} props
163
+ * @returns {TemplateResult}
164
+ */
165
+ renderDropdown(props) {
166
+ const filteredOptions = filterOptions(props.options, props.searchTerm)
167
+
168
+ return html`<div
169
+ class="iw-combobox-dropdown"
170
+ ${ref((el) => {
171
+ if (el) {
172
+ setTimeout(() => {
173
+ document.addEventListener(
174
+ "click",
175
+ (event) => {
176
+ if (!el.contains(event.target)) {
177
+ props.onClose?.()
178
+ }
179
+ },
180
+ { once: true },
181
+ )
182
+ })
183
+ }
184
+ })}
185
+ >
186
+ ${when(props.isSearchable, () => this.renderSearchInput?.(props))}
187
+ ${when(props.isLoading, () => this.renderLoading?.(props))}
188
+ ${when(!props.isLoading && !filteredOptions.length, () =>
189
+ this.renderNoOptions?.(props),
190
+ )}
191
+ ${when(!props.isLoading && filteredOptions.length, () =>
192
+ this.renderOptions?.(props),
193
+ )}
194
+ </div>`
195
+ },
196
+
197
+ /**
198
+ * Render search input.
199
+ * @param {ComboboxProps} props
200
+ * @returns {TemplateResult}
201
+ */
202
+ renderSearchInput(props) {
203
+ return html`<input
204
+ class="iw-combobox-dropdown-search"
205
+ type="text"
206
+ placeholder="Search..."
207
+ .value=${props.searchTerm ?? ""}
208
+ @input=${(event) => props.onSearchChange?.(event.target.value)}
209
+ @keydown=${(event) => handleKeyDown(props, event)}
210
+ ${ref((el) => {
211
+ if (el && props.isOpen) queueMicrotask(() => el.focus())
212
+ })}
213
+ />`
214
+ },
215
+
216
+ /**
217
+ * Render options list.
218
+ * @param {ComboboxProps} props
219
+ * @returns {TemplateResult}
220
+ */
221
+ renderOptions(props) {
222
+ const filteredOptions = filterOptions(props.options, props.searchTerm)
223
+
224
+ return html`<div class="iw-combobox-dropdown-options">
225
+ ${repeat(
226
+ filteredOptions,
227
+ (option) => getOptionValue(option),
228
+ (option, index) => this.renderOption?.(props, { option, index }),
229
+ )}
230
+ </div>`
231
+ },
232
+
233
+ /**
234
+ * Render an option row.
235
+ * @param {ComboboxProps} props
236
+ * @param {{ option: ComboboxOption, index: number }} payload
237
+ * @returns {TemplateResult}
238
+ */
239
+ renderOption(props, { option, index }) {
240
+ const normalized = formatOption(option)
241
+ const isSelected = isOptionSelected(
242
+ option,
243
+ props.selectedValue,
244
+ props.isMulti,
245
+ )
246
+ const isFocused = index === props.focusedIndex
247
+
248
+ return html`<div
249
+ class="iw-combobox-dropdown-options-option ${classMap({
250
+ "iw-combobox-dropdown-options-option-selected": isSelected,
251
+ "iw-combobox-dropdown-options-option-focused": isFocused,
252
+ "iw-combobox-dropdown-options-option-disabled": !!normalized.isDisabled,
253
+ })}"
254
+ @click=${() => {
255
+ if (normalized.isDisabled) return
256
+ props.onOptionSelect?.(normalized)
257
+ props.onChange?.(normalized)
258
+ }}
259
+ @mouseenter=${() => props.onFocusSet?.(index)}
260
+ >
261
+ ${when(
262
+ props.isMulti,
263
+ () =>
264
+ html`<input
265
+ type="checkbox"
266
+ .checked=${isSelected}
267
+ ?disabled=${!!normalized.isDisabled}
268
+ />`,
269
+ )}
270
+ <span>${getOptionLabel(normalized)}</span>
271
+ </div>`
272
+ },
273
+
274
+ /**
275
+ * Render loading state.
276
+ * @param {ComboboxProps} props
277
+ * @returns {TemplateResult}
278
+ */
279
+ renderLoading(props) {
280
+ return html`<div class="iw-combobox-loading">${props.loadingMessage}</div>`
281
+ },
282
+
283
+ /**
284
+ * Render no options state.
285
+ * @param {ComboboxProps} props
286
+ * @returns {TemplateResult}
287
+ */
288
+ renderNoOptions(props) {
289
+ return html`<div class="iw-combobox-no-options">
290
+ ${props.noOptionsMessage}
291
+ </div>`
292
+ },
293
+ }
294
+
295
+ /**
296
+ * Handle key navigation.
297
+ * @param {ComboboxProps} props
298
+ * @param {KeyboardEvent} event
299
+ */
300
+ function handleKeyDown(props, event) {
301
+ const filteredOptions = filterOptions(props.options, props.searchTerm)
302
+
303
+ switch (event.key) {
304
+ case "ArrowDown":
305
+ event.preventDefault()
306
+ props.onFocusNext?.()
307
+ break
308
+ case "ArrowUp":
309
+ event.preventDefault()
310
+ props.onFocusPrev?.()
311
+ break
312
+ case "Enter":
313
+ event.preventDefault()
314
+ if (
315
+ props.focusedIndex > NO_FOCUSED_INDEX &&
316
+ filteredOptions[props.focusedIndex]
317
+ ) {
318
+ const option = formatOption(filteredOptions[props.focusedIndex])
319
+ if (!option.isDisabled) {
320
+ props.onOptionSelect?.(option)
321
+ props.onChange?.(option)
322
+ }
323
+ }
324
+ break
325
+ case "Escape":
326
+ event.preventDefault()
327
+ props.onClose?.()
328
+ break
329
+ case "Home":
330
+ event.preventDefault()
331
+ props.onFocusFirst?.()
332
+ break
333
+ case "End":
334
+ event.preventDefault()
335
+ props.onFocusLast?.()
336
+ break
337
+ default:
338
+ break
339
+ }
340
+ }
@@ -0,0 +1,12 @@
1
+ @import "./combobox/style.css";
2
+ @import "./button/style.css";
3
+ @import "./button-group/style.css";
4
+ @import "./checkbox/style.css";
5
+ @import "./fab/style.css";
6
+ @import "./icon-button/style.css";
7
+ @import "./input/style.css";
8
+ @import "./radio-group/style.css";
9
+ @import "./rating/style.css";
10
+ @import "./select/style.css";
11
+ @import "./slider/style.css";
12
+ @import "./switch/style.css";