@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,458 @@
1
+ /**
2
+ * @typedef {import('../../../types/data-display/data-grid').Column} Column
3
+ * @typedef {import('../../../types/data-display/data-grid').DataGridProps} DataGridProps
4
+ * @typedef {import('../../../types/data-display/data-grid').Row} Row
5
+ * @typedef {import('@inglorious/web').TemplateResult} TemplateResult
6
+ */
7
+
8
+ import { classMap, html, repeat, when } from "@inglorious/web"
9
+
10
+ import { input } from "../../controls/input/index.js"
11
+ import { select } from "../../controls/select/index.js"
12
+ import { pagination } from "../../navigation/pagination/index.js"
13
+ import { virtualList } from "../virtual-list/index.js"
14
+ import { filters } from "./filters"
15
+ import {
16
+ getPaginationInfo,
17
+ getRowKeyValue,
18
+ getRows,
19
+ getSortDirection,
20
+ } from "./helpers.js"
21
+
22
+ const DIVISOR = 2
23
+
24
+ const PRETTY_PAGE = 1
25
+ const FIRST_PAGE = 0
26
+ const LAST_PAGE = 1
27
+
28
+ export const dataGrid = {
29
+ /**
30
+ * Main entrypoint. Allows override to wire to the store.
31
+ * @param {DataGridProps} props The data grid props.
32
+ * @returns {TemplateResult} The rendered data grid.
33
+ */
34
+ render(props) {
35
+ return this.renderDataGrid(props)
36
+ },
37
+
38
+ /**
39
+ * Renders the data grid component.
40
+ * @param {DataGridProps} props The data grid props.
41
+ * @returns {TemplateResult} The rendered data grid.
42
+ */
43
+ renderDataGrid(props) {
44
+ const { isStriped = false } = props
45
+
46
+ const classes = {
47
+ "iw-data-grid": true,
48
+ "iw-data-grid-striped": isStriped,
49
+ }
50
+
51
+ return html`<div class=${classMap(classes)}>
52
+ ${this.renderHeader?.(props)} ${this.renderBody?.(props)}
53
+ ${this.renderFooter?.(props)}
54
+ </div> `
55
+ },
56
+
57
+ /**
58
+ * Renders the data grid header.
59
+ * @param {DataGridProps} props The data grid props.
60
+ * @returns {TemplateResult} The rendered header.
61
+ */
62
+ renderHeader(props) {
63
+ return html`<div class="iw-data-grid-header">
64
+ ${props.search && this.renderToolbar?.(props)}
65
+ <div class="iw-data-grid-header-row">
66
+ ${repeat(
67
+ props.columns,
68
+ (column) => column.id,
69
+ (column, index) =>
70
+ this.renderHeaderColumn?.(props, { column, index }),
71
+ )}
72
+ </div>
73
+ </div>`
74
+ },
75
+
76
+ /**
77
+ * Renders the toolbar above the header row.
78
+ * @param {DataGridProps} props The data grid props.
79
+ * @returns {TemplateResult}
80
+ */
81
+ renderToolbar(props) {
82
+ return html`<div class="iw-data-grid-toolbar">
83
+ ${this.renderSearchbar?.(props)}
84
+ </div>`
85
+ },
86
+
87
+ /**
88
+ * Renders a single column in the header.
89
+ * @param {DataGridProps} props The data grid props.
90
+ * @param {object} payload The payload.
91
+ * @param {Column} payload.column The column definition.
92
+ * @returns {TemplateResult} The rendered header column.
93
+ */
94
+ renderHeaderColumn(props, { column }) {
95
+ return html`<div
96
+ class="iw-data-grid-header-column"
97
+ style=${getColumnStyle(column)}
98
+ >
99
+ <div
100
+ @click=${() => column.isSortable && props.onSortChange?.(column.id)}
101
+ class="iw-data-grid-header-title"
102
+ >
103
+ ${column.title} ${getSortIcon(getSortDirection(props, column.id))}
104
+ </div>
105
+
106
+ ${column.isFilterable && filters.render(props, column)}
107
+
108
+ <div
109
+ class="iw-data-grid-column-resizer"
110
+ @pointerdown=${(event) =>
111
+ props.onColumnResizeStart?.({
112
+ columnId: column.id,
113
+ event,
114
+ width: getRenderedColumnWidth(column, event),
115
+ })}
116
+ ></div>
117
+ </div>`
118
+ },
119
+
120
+ /**
121
+ * Renders the search bar.
122
+ * @param {DataGridProps} props The data grid props.
123
+ * @returns {TemplateResult} The rendered search bar.
124
+ */
125
+ renderSearchbar(props) {
126
+ return html`<div class="iw-data-grid-searchbar">
127
+ ${input.render({
128
+ size: "sm",
129
+ isFullWidth: true,
130
+ name: "search",
131
+ inputType: "text",
132
+ placeholder: props.search.placeholder ?? "Fuzzy search...",
133
+ value: props.search.value,
134
+ onChange: (value) => props.onSearchChange?.(value),
135
+ })}
136
+ </div>`
137
+ },
138
+
139
+ /**
140
+ * Renders the data grid body with rows.
141
+ * @param {DataGridProps} props The data grid props.
142
+ * @returns {TemplateResult} The rendered data grid body.
143
+ */
144
+ renderBody(props) {
145
+ const rows = getRows(props)
146
+
147
+ if (!props.isVirtualized) {
148
+ return html`<div class="iw-data-grid-body">
149
+ ${repeat(
150
+ rows,
151
+ (row) => getRowKeyValue(props, row),
152
+ (row, index) => this.renderRow?.(props, { row, index }),
153
+ )}
154
+ </div>`
155
+ }
156
+
157
+ const virtualState = getVirtualizationState(props, rows.length)
158
+ const virtualEntity = {
159
+ id: props.id,
160
+ type: "dataGridVirtualRows",
161
+ items: rows,
162
+ className: "iw-data-grid-body",
163
+ scrollTop: virtualState.scrollTop,
164
+ visibleRange: virtualState.visibleRange,
165
+ viewportHeight: virtualState.viewportHeight,
166
+ bufferSize: virtualState.bufferSize,
167
+ itemHeight: virtualState.itemHeight,
168
+ estimatedHeight: virtualState.estimatedHeight,
169
+ }
170
+
171
+ const virtualApi = {
172
+ notify: (target, payload) => {
173
+ if (target === `#${props.id}:scroll`) {
174
+ props.onVirtualScroll?.(payload)
175
+ }
176
+ if (target === `#${props.id}:mount`) {
177
+ props.onVirtualMount?.(payload)
178
+ }
179
+ },
180
+ getType: () => ({
181
+ renderItem: (_entity, { item, index }) =>
182
+ this.renderRow?.(props, { row: item, index }),
183
+ }),
184
+ }
185
+
186
+ return virtualList.render(virtualEntity, virtualApi)
187
+ },
188
+
189
+ /**
190
+ * Renders a single row in the data grid body.
191
+ * @param {DataGridProps} props The data grid props.
192
+ * @param {object} payload The payload.
193
+ * @param {Row} payload.row The row data.
194
+ * @param {number} payload.index The row index.
195
+ * @returns {TemplateResult} The rendered row.
196
+ */
197
+ renderRow(props, { row, index }) {
198
+ const rowId = getRowKeyValue(props, row)
199
+
200
+ return html`<div
201
+ @click=${(event) =>
202
+ props.onRowClick?.({
203
+ rowId,
204
+ shiftKey: event.shiftKey,
205
+ metaKey: event.metaKey,
206
+ ctrlKey: event.ctrlKey,
207
+ })}
208
+ class="iw-data-grid-row ${classMap({
209
+ "iw-data-grid-row-even": index % DIVISOR,
210
+ "iw-data-grid-row-selected": props.selection?.includes(rowId),
211
+ })}"
212
+ >
213
+ ${repeat(
214
+ props.columns,
215
+ (column) => column.id,
216
+ (column, index) =>
217
+ this.renderCell?.(props, { cell: row[column.id], index }),
218
+ )}
219
+ </div>`
220
+ },
221
+
222
+ /**
223
+ * Renders a single cell within a row.
224
+ * @param {DataGridProps} props The data grid props.
225
+ * @param {object} payload The payload.
226
+ * @param {any} payload.cell The cell data.
227
+ * @param {number} payload.index The column index.
228
+ * @returns {TemplateResult} The rendered cell.
229
+ */
230
+ renderCell(props, { cell, index }) {
231
+ const column = props.columns[index]
232
+
233
+ return html`<div
234
+ class="iw-data-grid-cell ${classMap({
235
+ "iw-data-grid-cell-number": column.type === "number",
236
+ "iw-data-grid-cell-date": column.type === "date",
237
+ "iw-data-grid-cell-boolean": column.type === "boolean",
238
+ })}"
239
+ style=${getColumnStyle(column)}
240
+ >
241
+ ${this.renderValue?.(props, { value: cell, column, index })}
242
+ </div>`
243
+ },
244
+
245
+ /**
246
+ * Renders the value within a cell. This can be overridden for custom formatting.
247
+ * @param {DataGridProps} _props The data grid props (ignored).
248
+ * @param {object} payload The payload.
249
+ * @param {any} payload.value The value to render.
250
+ * @returns {any} The value to be rendered.
251
+ */
252
+ renderValue(_props, { value }) {
253
+ return value
254
+ },
255
+
256
+ /**
257
+ * Renders the data grid footer.
258
+ * @param {DataGridProps} props The data grid props.
259
+ * @returns {TemplateResult} The rendered footer.
260
+ */
261
+ renderFooter(props) {
262
+ const pagination = getPaginationInfo(props)
263
+
264
+ if (!pagination) {
265
+ return null
266
+ }
267
+
268
+ return html`<div class="iw-data-grid-footer">
269
+ <div class="iw-data-grid-footer-row">
270
+ <div>
271
+ ${pagination.start + PRETTY_PAGE} to ${pagination.end} of
272
+ ${pagination.totalRows} entries
273
+ </div>
274
+
275
+ ${this.renderPagination?.(props, pagination)}
276
+ ${when(pagination.pageSizes, () =>
277
+ this.renderPageSize?.(props, pagination),
278
+ )}
279
+ </div>
280
+ </div>`
281
+ },
282
+
283
+ /**
284
+ * Renders the pagination controls.
285
+ * @param {DataGridProps} props The data grid props.
286
+ * @param {object} pagination The pagination info object from `getPaginationInfo`.
287
+ * @returns {TemplateResult} The rendered pagination controls.
288
+ */
289
+ renderPagination(props, paginationInfo) {
290
+ return html`<div class="iw-data-grid-row">
291
+ ${pagination.renderControl(
292
+ {
293
+ buttonSize: "sm",
294
+ buttonVariant: "outline",
295
+ itemClassName: "iw-data-grid-pagination-button",
296
+ },
297
+ {
298
+ label: "«",
299
+ target: FIRST_PAGE + PRETTY_PAGE,
300
+ isDisabled: !paginationInfo.hasPrevPage,
301
+ onChange: () => props.onPageChange?.(FIRST_PAGE),
302
+ },
303
+ )}
304
+ ${pagination.renderControl(
305
+ {
306
+ buttonSize: "sm",
307
+ buttonVariant: "outline",
308
+ itemClassName: "iw-data-grid-pagination-button",
309
+ },
310
+ {
311
+ label: "‹",
312
+ target: Math.max(PRETTY_PAGE, paginationInfo.page),
313
+ isDisabled: !paginationInfo.hasPrevPage,
314
+ onChange: () => props.onPagePrev?.(),
315
+ },
316
+ )}
317
+ ${input.render({
318
+ name: "page",
319
+ size: "sm",
320
+ inputType: "number",
321
+ min: 1,
322
+ max: paginationInfo.totalPages,
323
+ value: paginationInfo.page + PRETTY_PAGE,
324
+ onChange: (value) => props.onPageChange?.(Number(value) - PRETTY_PAGE),
325
+ })}
326
+ /
327
+ <span>${paginationInfo.totalPages}</span>
328
+ ${pagination.renderControl(
329
+ {
330
+ buttonSize: "sm",
331
+ buttonVariant: "outline",
332
+ itemClassName: "iw-data-grid-pagination-button",
333
+ },
334
+ {
335
+ label: "›",
336
+ target: Math.min(paginationInfo.totalPages, paginationInfo.page + 2),
337
+ isDisabled: !paginationInfo.hasNextPage,
338
+ onChange: () => props.onPageNext?.(),
339
+ },
340
+ )}
341
+ ${pagination.renderControl(
342
+ {
343
+ buttonSize: "sm",
344
+ buttonVariant: "outline",
345
+ itemClassName: "iw-data-grid-pagination-button",
346
+ },
347
+ {
348
+ label: "»",
349
+ target: paginationInfo.totalPages,
350
+ isDisabled: !paginationInfo.hasNextPage,
351
+ onChange: () =>
352
+ props.onPageChange?.(paginationInfo.totalPages - LAST_PAGE),
353
+ },
354
+ )}
355
+ </div>`
356
+ },
357
+
358
+ renderPageSize(props, pagination) {
359
+ return html`<div class="iw-data-grid-footer-row">
360
+ <div>Page size:</div>
361
+ ${select.render({
362
+ size: "sm",
363
+ value: pagination.pageSize,
364
+ options: pagination.pageSizes,
365
+ onChange: (value) => props.onPageSizeChange?.(Number(value)),
366
+ })}
367
+ </div>`
368
+ },
369
+ }
370
+
371
+ /**
372
+ * Generates the style string for a column.
373
+ * @param {Column} column The column definition.
374
+ * @returns {string} The style string.
375
+ */
376
+ function getColumnStyle(column) {
377
+ if (column.width == null || column.width === "auto") {
378
+ return "flex: 1 1 0; min-width: 0"
379
+ }
380
+
381
+ if (typeof column.width === "string") {
382
+ if (column.width.endsWith("fr")) {
383
+ const fraction = Number(column.width.slice(0, -2))
384
+ const normalizedFraction =
385
+ Number.isFinite(fraction) && fraction > 0 ? fraction : 1
386
+
387
+ return `flex: ${normalizedFraction} 1 0; min-width: 0`
388
+ }
389
+
390
+ if (column.width.endsWith("%")) {
391
+ const percentage = Number(column.width.slice(0, -1))
392
+ if (Number.isFinite(percentage) && percentage >= 100) {
393
+ return "flex: 1 1 0; min-width: 0"
394
+ }
395
+
396
+ return `flex: 0 0 ${column.width}; width: ${column.width}`
397
+ }
398
+
399
+ return `flex: 0 0 ${column.width}; width: ${column.width}`
400
+ }
401
+
402
+ return `flex: 0 0 ${column.width}px; width: ${column.width}px`
403
+ }
404
+
405
+ /**
406
+ * Gets the current rendered width of a header column.
407
+ * @param {Column} column
408
+ * @param {PointerEvent} event
409
+ * @returns {number}
410
+ */
411
+ function getRenderedColumnWidth(column, event) {
412
+ if (typeof column.width === "number") {
413
+ return column.width
414
+ }
415
+
416
+ return event.currentTarget?.parentElement?.offsetWidth ?? 0
417
+ }
418
+
419
+ /**
420
+ * Gets the appropriate sort icon for a given direction.
421
+ * @param {"asc"|"desc"|null} direction The sort direction.
422
+ * @returns {string} The sort icon.
423
+ */
424
+ function getSortIcon(direction) {
425
+ switch (direction) {
426
+ case "asc":
427
+ return "▲"
428
+ case "desc":
429
+ return "▼"
430
+ default:
431
+ return "▲▼"
432
+ }
433
+ }
434
+
435
+ function getVirtualizationState(props, totalItems) {
436
+ const fallback = {
437
+ scrollTop: 0,
438
+ visibleRange: { start: 0, end: Math.min(20, totalItems) },
439
+ viewportHeight: 600,
440
+ bufferSize: 5,
441
+ itemHeight: null,
442
+ estimatedHeight: 50,
443
+ }
444
+
445
+ const virtualState = props.virtualization ?? fallback
446
+ const visibleRange = virtualState.visibleRange ?? fallback.visibleRange
447
+ const start = Math.max(0, Math.min(visibleRange.start ?? 0, totalItems))
448
+ const end = Math.max(
449
+ start,
450
+ Math.min(visibleRange.end ?? totalItems, totalItems),
451
+ )
452
+
453
+ return {
454
+ ...fallback,
455
+ ...virtualState,
456
+ visibleRange: { start, end },
457
+ }
458
+ }
@@ -0,0 +1,148 @@
1
+ .iw-data-grid {
2
+ border: 1px solid var(--iw-color-border);
3
+ background: var(--iw-color-surface);
4
+ color: var(--iw-color-text);
5
+
6
+ .iw-data-grid-header {
7
+ border-bottom: 1px solid var(--iw-color-border);
8
+ padding: var(--iw-space-4) var(--iw-space-0);
9
+ row-gap: var(--iw-space-3);
10
+ }
11
+
12
+ .iw-data-grid-toolbar {
13
+ padding: 0 var(--iw-space-4);
14
+ padding-bottom: var(--iw-space-3);
15
+ }
16
+
17
+ .iw-data-grid-header-row {
18
+ align-items: flex-start;
19
+ column-gap: var(--iw-space-4);
20
+ }
21
+
22
+ .iw-data-grid-header-column {
23
+ padding: 0 var(--iw-space-5) 0 var(--iw-space-4);
24
+ row-gap: var(--iw-space-2);
25
+ }
26
+
27
+ .iw-data-grid-header-title {
28
+ font-weight: var(--iw-font-weight-bold);
29
+ white-space: nowrap;
30
+ }
31
+
32
+ .iw-data-grid-column-resizer {
33
+ &::after {
34
+ content: "";
35
+ position: absolute;
36
+ top: 0;
37
+ bottom: 0;
38
+ right: calc(50% - 0.5px);
39
+ border-right: 1px solid transparent;
40
+ }
41
+
42
+ &:hover {
43
+ &::after {
44
+ border-right-color: var(--iw-color-border-focus);
45
+ }
46
+ }
47
+ }
48
+
49
+ .iw-data-grid-body {
50
+ max-height: 35em;
51
+ overflow: auto;
52
+ border-bottom: 1px solid var(--iw-color-border);
53
+ }
54
+
55
+ .iw-data-grid-row {
56
+ align-items: center;
57
+ column-gap: var(--iw-space-4);
58
+ }
59
+
60
+ &.iw-data-grid-striped {
61
+ .iw-data-grid-row-even {
62
+ background: color-mix(
63
+ in srgb,
64
+ var(--iw-color-surface) 88%,
65
+ var(--iw-color-primary)
66
+ );
67
+ }
68
+ }
69
+
70
+ .iw-data-grid-row-selected {
71
+ box-shadow:
72
+ inset 1px 0 0 var(--iw-color-primary),
73
+ inset -1px 0 0 var(--iw-color-primary);
74
+
75
+ &:first-child,
76
+ .iw-data-grid-row:not(.iw-data-grid-row-selected) + & {
77
+ box-shadow:
78
+ inset 1px 0 0 var(--iw-color-primary),
79
+ inset -1px 0 0 var(--iw-color-primary),
80
+ inset 0 1px 0 var(--iw-color-primary);
81
+ }
82
+
83
+ &:last-child,
84
+ &:not(:has(+ .iw-data-grid-row-selected)) {
85
+ box-shadow:
86
+ inset 1px 0 0 var(--iw-color-primary),
87
+ inset -1px 0 0 var(--iw-color-primary),
88
+ inset 0 -1px 0 var(--iw-color-primary);
89
+ }
90
+
91
+ &:first-child:last-child,
92
+ &:first-child:not(:has(+ .iw-data-grid-row-selected)),
93
+ .iw-data-grid-row:not(.iw-data-grid-row-selected) + &:last-child,
94
+ .iw-data-grid-row:not(.iw-data-grid-row-selected)
95
+ + &:not(:has(+ .iw-data-grid-row-selected)) {
96
+ box-shadow:
97
+ inset 1px 0 0 var(--iw-color-primary),
98
+ inset -1px 0 0 var(--iw-color-primary),
99
+ inset 0 1px 0 var(--iw-color-primary),
100
+ inset 0 -1px 0 var(--iw-color-primary);
101
+ }
102
+ }
103
+
104
+ .iw-data-grid-cell {
105
+ padding: var(--iw-space-4);
106
+ }
107
+
108
+ .iw-data-grid-cell-number,
109
+ .iw-data-grid-cell-date {
110
+ text-align: right;
111
+ }
112
+
113
+ .iw-data-grid-cell-boolean {
114
+ text-align: center;
115
+ }
116
+
117
+ .iw-data-grid-footer {
118
+ padding: var(--iw-space-4);
119
+ }
120
+
121
+ .iw-data-grid-footer-row {
122
+ justify-content: space-between;
123
+ align-items: center;
124
+ column-gap: var(--iw-space-4);
125
+ }
126
+
127
+ .iw-data-grid-page-input {
128
+ min-width: var(--iw-space-16);
129
+ text-align: right;
130
+ }
131
+
132
+ .iw-button.iw-button-outline.iw-data-grid-pagination-button {
133
+ white-space: nowrap;
134
+ --iw-button-color: var(--iw-color-text);
135
+ border-color: var(--iw-color-border);
136
+ color: var(--iw-color-text);
137
+
138
+ &:hover:not(:disabled) {
139
+ border-color: var(--iw-color-border);
140
+ color: var(--iw-color-text);
141
+ background: color-mix(
142
+ in srgb,
143
+ var(--iw-color-surface-hover) 80%,
144
+ transparent
145
+ );
146
+ }
147
+ }
148
+ }
@@ -0,0 +1,48 @@
1
+ import { render } from "@inglorious/web/test"
2
+
3
+ import { createRender } from "../../stories/notifyStory.js"
4
+ import { divider } from "."
5
+
6
+ export default {
7
+ title: "Data Display/Divider",
8
+ tags: ["autodocs"],
9
+ render: createRender(divider),
10
+ argTypes: {
11
+ orientation: {
12
+ control: "select",
13
+ options: ["horizontal", "vertical"],
14
+ description: "Divider direction.",
15
+ },
16
+ isInset: {
17
+ control: "boolean",
18
+ description: "Applies start inset for sectional separators.",
19
+ },
20
+ },
21
+ parameters: {
22
+ docs: {
23
+ description: {
24
+ component: "Visual separator for grouping related content blocks.",
25
+ },
26
+ },
27
+ },
28
+ }
29
+
30
+ export const Default = {
31
+ args: {},
32
+ }
33
+
34
+ export const Vertical = {
35
+ args: {
36
+ ...Default.args,
37
+ orientation: "vertical",
38
+ },
39
+ decorators: [
40
+ (story) => {
41
+ const container = document.createElement("div")
42
+ container.style.height = "100px"
43
+ container.style.display = "flex"
44
+ render(story(), container)
45
+ return container
46
+ },
47
+ ],
48
+ }
@@ -0,0 +1,3 @@
1
+ import * as renderers from "./template.js"
2
+
3
+ export const divider = { ...renderers }
@@ -0,0 +1,18 @@
1
+ .iw-divider {
2
+ border: 0;
3
+ border-top: 1px solid var(--iw-color-border);
4
+ margin: var(--iw-space-2) 0;
5
+
6
+ &.iw-divider-inset {
7
+ margin-left: var(--iw-space-4);
8
+ margin-right: var(--iw-space-4);
9
+ }
10
+
11
+ &.iw-divider-vertical {
12
+ border-top: 0;
13
+ border-left: 1px solid var(--iw-color-border);
14
+ width: 0;
15
+ height: 100%;
16
+ margin: 0 var(--iw-space-2);
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @typedef {import('../../../types/data-display/divider').DividerProps} DividerProps
3
+ */
4
+
5
+ import { classMap, html } from "@inglorious/web"
6
+
7
+ export function render(props) {
8
+ const { orientation = "horizontal", isInset = false } = props
9
+
10
+ return html`<hr
11
+ class=${classMap({
12
+ "iw-divider": true,
13
+ "iw-divider-vertical": orientation === "vertical",
14
+ "iw-divider-inset": isInset,
15
+ })}
16
+ />`
17
+ }