@inglorious/ui 0.1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/README.md +45 -0
  2. package/package.json +190 -15
  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
@@ -1,44 +1,40 @@
1
1
  /**
2
- * @typedef {import('../../../types/controls/button').ButtonEntity} ButtonEntity
3
- * @typedef {import('@inglorious/web').Api} Api
2
+ * @typedef {import('../../../types/controls/button').ButtonProps} ButtonProps
4
3
  * @typedef {import('@inglorious/web').TemplateResult} TemplateResult
5
4
  */
6
5
 
7
6
  import { classMap, html, ref } from "@inglorious/web"
8
7
 
9
- import { applyElementProps } from "@/shared/applyElementProps.js"
8
+ import { applyElementProps } from "../../shared/applyElementProps.js"
10
9
 
11
10
  /**
12
11
  * Button type for Inglorious Web.
13
12
  *
14
13
  * @example
15
14
  * // Stateless usage
16
- * button.render({ children: 'Click me', variant: 'primary' }, api)
15
+ * button.render({ children: 'Click me', variant: 'primary' })
17
16
  *
18
- * @example
19
- * // Stateful usage with event handling
20
- * // Entity: { type: 'button', id: 'submitBtn', children: 'Submit' }
21
- * // In store: api.render('submitBtn')
22
- *
23
- * @param {ButtonEntity} entity
24
- * @param {Api} api
17
+ * @param {ButtonProps} props
25
18
  * @returns {TemplateResult}
26
19
  */
27
- export function render(entity, api) {
20
+ export function render(props) {
28
21
  const {
22
+ type, // eslint-disable-line no-unused-vars
29
23
  children,
30
24
  variant = "default",
31
- color = "primary",
25
+ color = "default",
32
26
  size = "md",
33
27
  shape = "rectangle",
34
- disabled = false,
35
- fullWidth = false,
36
- type = "button",
28
+ isDisabled = false,
29
+ isPressed = false,
30
+ isFullWidth = false,
31
+ buttonType = "button",
37
32
  ariaLabel = "",
38
- ariaPressed = false,
33
+ isAriaPressed = false,
39
34
  className = "",
35
+ onClick,
40
36
  ...rest
41
- } = entity
37
+ } = props
42
38
 
43
39
  const extraClasses = Object.fromEntries(
44
40
  className
@@ -50,22 +46,23 @@ export function render(entity, api) {
50
46
  const classes = {
51
47
  "iw-button": true,
52
48
  [`iw-button-${variant}`]: variant !== "default",
53
- [`iw-button-${color}`]: color !== "primary",
54
- [`iw-button-${size}`]: size !== "md",
49
+ [`iw-button-${color}`]: true,
50
+ [`iw-button-${size}`]: true,
51
+ [`iw-button-pressed`]: isPressed,
55
52
  [`iw-button-shape-${shape}`]: shape !== "rectangle",
56
- "iw-button-full-width": fullWidth,
57
- "iw-button-disabled": disabled,
53
+ "iw-button-full-width": isFullWidth,
54
+ "iw-button-disabled": isDisabled,
58
55
  ...extraClasses,
59
56
  }
60
57
 
61
58
  return html`
62
59
  <button
63
- type=${type}
60
+ type=${buttonType}
64
61
  aria-label=${ariaLabel}
65
- aria-pressed=${ariaPressed}
62
+ aria-pressed=${isAriaPressed}
66
63
  class=${classMap(classes)}
67
- ?disabled=${disabled}
68
- @click=${() => api.notify(`#${entity.id}:click`)}
64
+ ?disabled=${isDisabled}
65
+ @click=${onClick}
69
66
  ${ref((element) => applyElementProps(element, rest))}
70
67
  >
71
68
  ${children}
@@ -1,21 +1,17 @@
1
- import {
2
- makeStoryRender,
3
- notifyActionArgType,
4
- } from "../../stories/notifyStory.js"
1
+ import { createRender } from "../../stories/notifyStory.js"
5
2
  import { buttonGroup } from "."
6
3
 
7
4
  export default {
8
5
  title: "Controls/ButtonGroup",
9
6
  tags: ["autodocs"],
10
- render: makeStoryRender(buttonGroup, "story-button-group"),
7
+ render: createRender(buttonGroup),
11
8
  argTypes: {
12
- ...notifyActionArgType,
13
9
  value: {
14
10
  control: "object",
15
11
  description:
16
12
  "Selected value(s). String for single mode, array for multiple mode.",
17
13
  },
18
- multiple: {
14
+ isMultiple: {
19
15
  control: "boolean",
20
16
  description: "Enable multi-selection mode.",
21
17
  },
@@ -24,7 +20,7 @@ export default {
24
20
  options: ["row", "column"],
25
21
  description: "Group direction.",
26
22
  },
27
- attached: {
23
+ isAttached: {
28
24
  control: "boolean",
29
25
  description: "Visually attach adjacent buttons.",
30
26
  },
@@ -40,10 +36,18 @@ export default {
40
36
  },
41
37
  color: {
42
38
  control: "select",
43
- options: ["primary", "secondary", "success", "warning", "error", "info"],
39
+ options: [
40
+ "default",
41
+ "primary",
42
+ "secondary",
43
+ "success",
44
+ "warning",
45
+ "error",
46
+ "info",
47
+ ],
44
48
  description: "Default color intent for items.",
45
49
  },
46
- disabled: {
50
+ isDisabled: {
47
51
  control: "boolean",
48
52
  description: "Disables all buttons.",
49
53
  },
@@ -51,6 +55,7 @@ export default {
51
55
  control: "object",
52
56
  description: "Items rendered as grouped buttons.",
53
57
  },
58
+ onChange: { action: "onChange" },
54
59
  },
55
60
  parameters: {
56
61
  docs: {
@@ -64,13 +69,12 @@ export default {
64
69
  export const Default = {}
65
70
  Default.args = {
66
71
  value: "",
67
- multiple: false,
72
+ isMultiple: false,
68
73
  direction: "row",
69
- attached: true,
74
+ isAttached: true,
70
75
  size: "md",
71
76
  variant: "outline",
72
- color: "primary",
73
- disabled: false,
77
+ isDisabled: false,
74
78
  buttons: [
75
79
  { id: "left", value: "left", label: "Left" },
76
80
  { id: "center", value: "center", label: "Center" },
@@ -98,7 +102,7 @@ SingleSelection.args = {
98
102
  export const MultiSelection = {}
99
103
  MultiSelection.args = {
100
104
  ...Default.args,
101
- multiple: true,
105
+ isMultiple: true,
102
106
  value: ["left", "right"],
103
107
  buttons: [
104
108
  { id: "left", value: "left", label: "Left" },
@@ -1,4 +1,3 @@
1
- import { withRenderValidation } from "../../shared/withRenderValidation.js"
2
1
  import * as renderers from "./template.js"
3
2
 
4
- export const buttonGroup = [{ ...renderers }, withRenderValidation]
3
+ export const buttonGroup = { ...renderers }
@@ -48,11 +48,4 @@
48
48
  &:not(.iw-button-group-attached) {
49
49
  gap: var(--iw-space-2);
50
50
  }
51
-
52
- &.iw-button-group-selection .iw-button.iw-button-pressed {
53
- background-color: var(--iw-button-bg-active);
54
- border-color: var(--iw-button-bg-active);
55
- color: var(--iw-button-text);
56
- box-shadow: var(--iw-button-shadow-active);
57
- }
58
51
  }
@@ -1,43 +1,43 @@
1
1
  /**
2
- * @typedef {import('../../../types/controls/button-group').ButtonGroupEntity} ButtonGroupEntity
3
- * @typedef {import('@inglorious/web').Api} Api
2
+ * @typedef {import('../../../types/controls/button-group').ButtonGroupProps} ButtonGroupProps
4
3
  * @typedef {import('@inglorious/web').TemplateResult} TemplateResult
5
4
  */
6
5
 
7
6
  import { classMap, html, ref } from "@inglorious/web"
8
- import { applyElementProps } from "@/shared/applyElementProps.js"
9
7
 
10
- import { buttonPrimitive as button } from "../button/index.js"
8
+ import { applyElementProps } from "../../shared/applyElementProps.js"
9
+ import { button } from "../button/index.js"
11
10
 
12
11
  /**
13
12
  * Button group control for grouped actions.
14
13
  *
15
- * @param {ButtonGroupEntity} entity
16
- * @param {Api} api
14
+ * @param {ButtonGroupProps} props
17
15
  * @returns {TemplateResult}
18
16
  */
19
- export function render(entity, api) {
17
+ export function render(props) {
20
18
  const {
19
+ type, // eslint-disable-line no-unused-vars
21
20
  buttons = [],
22
21
  value,
23
- multiple = false,
22
+ isMultiple = false,
24
23
  direction = "row",
25
- attached = true,
24
+ isAttached = true,
26
25
  size = "md",
27
26
  variant = "default",
28
- color = "primary",
29
- disabled = false,
27
+ color = "default",
28
+ isDisabled = false,
29
+ onChange,
30
30
  ...rest
31
- } = entity
31
+ } = props
32
32
 
33
33
  const groupClasses = {
34
34
  "iw-button-group": true,
35
- "iw-button-group-selection": value != null || multiple,
35
+ "iw-button-group-selection": value != null || isMultiple,
36
36
  [`iw-button-group-${direction}`]: true,
37
- "iw-button-group-attached": attached,
37
+ "iw-button-group-attached": isAttached,
38
38
  }
39
39
 
40
- const selectedValues = multiple
40
+ const selectedValues = isMultiple
41
41
  ? new Set(Array.isArray(value) ? value : [])
42
42
  : null
43
43
 
@@ -47,13 +47,13 @@ export function render(entity, api) {
47
47
  role="group"
48
48
  ${ref((element) => applyElementProps(element, rest))}
49
49
  >
50
- ${buttons.map((item, index) => {
50
+ ${buttons.map((item) => {
51
51
  const {
52
52
  id: itemId,
53
53
  value: explicitValue,
54
54
  label,
55
55
  children,
56
- disabled: itemDisabled,
56
+ isDisabled: itemDisabled,
57
57
  variant: itemVariant,
58
58
  color: itemColor,
59
59
  size: itemSize,
@@ -62,55 +62,45 @@ export function render(entity, api) {
62
62
  ...itemRest
63
63
  } = item
64
64
 
65
- const childId = `${entity.id}-btn-${itemId ?? index}`
66
65
  const itemValue = explicitValue ?? itemId
67
- const pressed = multiple
66
+ const isPressed = isMultiple
68
67
  ? selectedValues.has(itemValue)
69
68
  : value != null
70
69
  ? value === itemValue
71
70
  : false
72
71
 
73
- const childApi = {
74
- ...api,
75
- notify(type, payload) {
76
- if (type === `#${childId}:click`) {
77
- api.notify(`#${entity.id}:click`, itemValue)
78
- if (value != null || multiple) {
79
- if (multiple) {
80
- const next = new Set(selectedValues)
81
- if (next.has(itemValue)) next.delete(itemValue)
82
- else next.add(itemValue)
83
- return api.notify(`#${entity.id}:change`, [...next])
84
- }
85
- return api.notify(`#${entity.id}:change`, itemValue)
72
+ return button.render({
73
+ children: html`
74
+ ${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
75
+ ${children ?? label}
76
+ ${iconAfter
77
+ ? html`<span class="iw-button-icon">${iconAfter}</span>`
78
+ : null}
79
+ `,
80
+ variant: itemVariant ?? variant,
81
+ color: itemColor ?? color,
82
+ size: itemSize ?? size,
83
+ isDisabled: isDisabled || !!itemDisabled,
84
+ isPressed,
85
+ isAriaPressed: isPressed ? true : undefined,
86
+ onClick: () => {
87
+ if (!onChange) return
88
+
89
+ if (isMultiple) {
90
+ const next = new Set(selectedValues)
91
+ if (next.has(itemValue)) {
92
+ next.delete(itemValue)
93
+ } else {
94
+ next.add(itemValue)
86
95
  }
87
- return
96
+
97
+ return onChange([...next])
88
98
  }
89
- return api.notify(type, payload)
90
- },
91
- }
92
99
 
93
- return button.render(
94
- {
95
- id: childId,
96
- children: html`
97
- ${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
98
- ${children ?? label}
99
- ${iconAfter
100
- ? html`<span class="iw-button-icon">${iconAfter}</span>`
101
- : null}
102
- `,
103
- variant: itemVariant ?? variant,
104
- color: itemColor ?? color,
105
- size: itemSize ?? size,
106
- disabled: disabled || !!itemDisabled,
107
- ariaPressed: pressed ? true : undefined,
108
- className: pressed ? "iw-button-pressed" : "",
109
- type: "button",
110
- ...itemRest,
100
+ return onChange(itemValue)
111
101
  },
112
- childApi,
113
- )
102
+ ...itemRest,
103
+ })
114
104
  })}
115
105
  </div>
116
106
  `
@@ -1,25 +1,27 @@
1
- import {
2
- makeStoryRender,
3
- notifyActionArgType,
4
- } from "../../stories/notifyStory.js"
1
+ import { createRender } from "../../stories/notifyStory.js"
5
2
  import { checkbox } from "."
6
3
 
7
4
  export default {
8
5
  title: "Controls/Checkbox",
9
6
  tags: ["autodocs"],
10
- render: makeStoryRender(checkbox, "story-checkbox"),
7
+ render: createRender(checkbox),
11
8
  argTypes: {
12
- ...notifyActionArgType,
13
9
  label: { control: "text", description: "Label text." },
14
10
  name: { control: "text", description: "Native HTML name attribute." },
15
- checked: { control: "boolean", description: "Current checked state." },
16
- disabled: { control: "boolean", description: "Disables interaction." },
17
- required: { control: "boolean", description: "Marks input as required." },
11
+ isChecked: { control: "boolean", description: "Current checked state." },
12
+ isDisabled: { control: "boolean", description: "Disables interaction." },
13
+ isRequired: { control: "boolean", description: "Marks input as required." },
14
+ color: {
15
+ control: "select",
16
+ options: ["primary", "secondary", "success", "warning", "error", "info"],
17
+ description: "Semantic accent color.",
18
+ },
18
19
  size: {
19
20
  control: "select",
20
21
  options: ["sm", "md", "lg"],
21
22
  description: "Label size scale.",
22
23
  },
24
+ onChange: { action: "onChange" },
23
25
  },
24
26
  parameters: {
25
27
  docs: {
@@ -34,14 +36,15 @@ export const Default = {}
34
36
  Default.args = {
35
37
  label: "Accept terms",
36
38
  name: "terms",
37
- checked: false,
38
- disabled: false,
39
- required: false,
39
+ isChecked: false,
40
+ isDisabled: false,
41
+ isRequired: false,
42
+ color: "primary",
40
43
  size: "md",
41
44
  }
42
45
 
43
46
  export const Checked = {}
44
47
  Checked.args = {
45
48
  ...Default.args,
46
- checked: true,
49
+ isChecked: true,
47
50
  }
@@ -1,4 +1,3 @@
1
- import { withRenderValidation } from "../../shared/withRenderValidation.js"
2
1
  import * as renderers from "./template.js"
3
2
 
4
- export const checkbox = [{ ...renderers }, withRenderValidation]
3
+ export const checkbox = { ...renderers }
@@ -1,4 +1,5 @@
1
- .iw-checkbox-field {
1
+ .iw-checkbox {
2
+ --iw-checkbox-accent: var(--iw-color-primary);
2
3
  display: inline-flex;
3
4
  align-items: center;
4
5
  gap: var(--iw-space-2);
@@ -10,7 +11,7 @@
10
11
  width: 1rem;
11
12
  height: 1rem;
12
13
  margin: 0;
13
- accent-color: var(--iw-color-primary);
14
+ accent-color: var(--iw-checkbox-accent);
14
15
  }
15
16
 
16
17
  .iw-checkbox-label {
@@ -30,4 +31,24 @@
30
31
  opacity: 0.6;
31
32
  cursor: not-allowed;
32
33
  }
34
+
35
+ &.iw-checkbox-secondary {
36
+ --iw-checkbox-accent: var(--iw-color-gray-600);
37
+ }
38
+
39
+ &.iw-checkbox-success {
40
+ --iw-checkbox-accent: var(--iw-color-success);
41
+ }
42
+
43
+ &.iw-checkbox-warning {
44
+ --iw-checkbox-accent: var(--iw-color-warning);
45
+ }
46
+
47
+ &.iw-checkbox-error {
48
+ --iw-checkbox-accent: var(--iw-color-error);
49
+ }
50
+
51
+ &.iw-checkbox-info {
52
+ --iw-checkbox-accent: var(--iw-color-info);
53
+ }
33
54
  }
@@ -1,36 +1,39 @@
1
1
  /**
2
- * @typedef {import('../../../types/controls/checkbox').CheckboxEntity} CheckboxEntity
3
- * @typedef {import('@inglorious/web').Api} Api
2
+ * @typedef {import('../../../types/controls/checkbox').CheckboxProps} CheckboxProps
4
3
  * @typedef {import('@inglorious/web').TemplateResult} TemplateResult
5
4
  */
6
5
 
7
6
  import { classMap, html, ref } from "@inglorious/web"
8
7
 
9
- import { applyElementProps } from "@/shared/applyElementProps.js"
8
+ import { applyElementProps } from "../../shared/applyElementProps.js"
10
9
 
11
10
  /**
12
11
  * Checkbox control for boolean values.
13
12
  *
14
- * @param {CheckboxEntity} entity
15
- * @param {Api} api
13
+ * @param {CheckboxProps} props
16
14
  * @returns {TemplateResult}
17
15
  */
18
- export function render(entity, api) {
16
+ export function render(props) {
19
17
  const {
18
+ id,
19
+ type, // eslint-disable-line no-unused-vars
20
20
  name = "",
21
21
  label = "",
22
- checked = false,
23
- disabled = false,
24
- required = false,
22
+ isChecked = false,
23
+ isDisabled = false,
24
+ isRequired = false,
25
+ color = "primary",
25
26
  size = "md",
27
+ onChange,
26
28
  ...rest
27
- } = entity
29
+ } = props
28
30
 
29
- const inputId = entity.id || name
31
+ const inputId = id || name
30
32
 
31
33
  const classes = {
32
- "iw-checkbox-field": true,
33
- "iw-checkbox-disabled": disabled,
34
+ "iw-checkbox": true,
35
+ "iw-checkbox-disabled": isDisabled,
36
+ [`iw-checkbox-${color}`]: color !== "primary",
34
37
  [`iw-checkbox-${size}`]: size !== "md",
35
38
  }
36
39
 
@@ -41,11 +44,10 @@ export function render(entity, api) {
41
44
  class="iw-checkbox"
42
45
  type="checkbox"
43
46
  name=${name}
44
- .checked=${checked}
45
- ?disabled=${disabled}
46
- ?required=${required}
47
- @change=${(event) =>
48
- api.notify(`#${entity.id}:change`, event.target.checked)}
47
+ .checked=${isChecked}
48
+ ?disabled=${isDisabled}
49
+ ?required=${isRequired}
50
+ @change=${(event) => onChange?.(event.target.checked)}
49
51
  ${ref((element) => applyElementProps(element, rest))}
50
52
  />
51
53
  <span class="iw-checkbox-label">${label}</span>
@@ -0,0 +1,92 @@
1
+ import {
2
+ createEntityRender,
3
+ notifyActionArgType,
4
+ } from "../../stories/notifyStory.js"
5
+ import { combobox } from "./index.js"
6
+
7
+ const options = [
8
+ { label: "Italy", value: "it" },
9
+ { label: "France", value: "fr" },
10
+ { label: "Spain", value: "es" },
11
+ { label: "Germany", value: "de" },
12
+ ]
13
+
14
+ export default {
15
+ title: "Controls/Combobox",
16
+ tags: ["autodocs"],
17
+ render: createEntityRender({ combobox }),
18
+ argTypes: {
19
+ ...notifyActionArgType,
20
+ label: { control: "text", description: "Field label." },
21
+ selectedValue: {
22
+ control: "object",
23
+ description: "Current selection. Value or array of values in multi mode.",
24
+ },
25
+ isMulti: { control: "boolean", description: "Enable multiple selection." },
26
+ isOpen: {
27
+ control: "boolean",
28
+ description: "Controls dropdown visibility.",
29
+ },
30
+ isSearchable: { control: "boolean", description: "Show search input." },
31
+ isClearable: { control: "boolean", description: "Show clear button." },
32
+ isDisabled: { control: "boolean", description: "Disable the control." },
33
+ isLoading: { control: "boolean", description: "Show loading state." },
34
+ searchTerm: { control: "text", description: "Current search filter." },
35
+ placeholder: { control: "text", description: "Placeholder text." },
36
+ noOptionsMessage: { control: "text", description: "No results message." },
37
+ loadingMessage: { control: "text", description: "Loading message." },
38
+ isFullWidth: {
39
+ control: "boolean",
40
+ description: "Expand to container width.",
41
+ },
42
+ size: {
43
+ control: "select",
44
+ options: ["sm", "md", "lg"],
45
+ description: "Control size.",
46
+ },
47
+ options: { control: "object", description: "Available options." },
48
+ },
49
+ parameters: {
50
+ docs: {
51
+ description: {
52
+ component:
53
+ "Theme-aware custom select with searchable dropdown, clear action, and optional multi-selection.",
54
+ },
55
+ },
56
+ },
57
+ }
58
+
59
+ export const SingleClosed = {}
60
+ SingleClosed.args = {
61
+ id: "combobox",
62
+ type: "combobox",
63
+ label: "Country",
64
+ selectedValue: "it",
65
+ isMulti: false,
66
+ isOpen: false,
67
+ isSearchable: true,
68
+ isClearable: true,
69
+ isDisabled: false,
70
+ isLoading: false,
71
+ searchTerm: "",
72
+ placeholder: "Select...",
73
+ noOptionsMessage: "No options",
74
+ loadingMessage: "Loading...",
75
+ isFullWidth: false,
76
+ size: "md",
77
+ options,
78
+ }
79
+
80
+ export const SingleOpen = {}
81
+ SingleOpen.args = {
82
+ ...SingleClosed.args,
83
+ isOpen: true,
84
+ }
85
+
86
+ export const MultiOpen = {}
87
+ MultiOpen.args = {
88
+ ...SingleClosed.args,
89
+ isMulti: true,
90
+ selectedValue: ["it", "fr"],
91
+ isOpen: true,
92
+ }
@@ -1,7 +1,6 @@
1
- /* eslint-disable no-magic-numbers */
2
1
  /**
3
- * @typedef {import('../../../types/controls/select').SelectEntity} SelectEntity
4
- * @typedef {import('../../../types/controls/select').SelectOption} SelectOption
2
+ * @typedef {import('../../../types/controls/select.js').SelectProps} SelectEntity
3
+ * @typedef {import('../../../types/controls/select.js').SelectOption} SelectOption
5
4
  */
6
5
 
7
6
  import { filterOptions, formatOption, getOptionValue } from "./helpers.js"
@@ -11,6 +10,10 @@ import { filterOptions, formatOption, getOptionValue } from "./helpers.js"
11
10
  * @param {SelectEntity} entity
12
11
  */
13
12
  export function create(entity) {
13
+ entity.size ??= "md"
14
+ entity.isFullWidth ??= false
15
+ entity.label ??= ""
16
+
14
17
  entity.isOpen ??= false
15
18
  entity.searchTerm ??= ""
16
19
  entity.focusedIndex ??= -1
@@ -23,8 +26,8 @@ export function create(entity) {
23
26
 
24
27
  entity.isLoading ??= false
25
28
  entity.isDisabled ??= false
26
- entity.isSearchable ??= true
27
- entity.isClearable ??= true
29
+ entity.isSearchable ??= false
30
+ entity.isClearable ??= false
28
31
 
29
32
  entity.placeholder ??= "Select..."
30
33
  entity.noOptionsMessage ??= "No options"