@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.
- package/README.md +45 -0
- package/package.json +191 -16
- package/src/all.css +7 -0
- package/src/controls/button/button.stories.js +35 -15
- package/src/controls/button/index.js +1 -3
- package/src/controls/button/style.css +80 -37
- package/src/controls/button/template.js +23 -26
- package/src/controls/button-group/button-group.stories.js +19 -15
- package/src/controls/button-group/index.js +1 -2
- package/src/controls/button-group/style.css +0 -7
- package/src/controls/button-group/template.js +46 -56
- package/src/controls/checkbox/checkbox.stories.js +16 -13
- package/src/controls/checkbox/index.js +1 -2
- package/src/controls/checkbox/style.css +23 -2
- package/src/controls/checkbox/template.js +20 -18
- package/src/controls/combobox/combobox.stories.js +92 -0
- package/src/controls/{select → combobox}/handlers.js +8 -5
- package/src/controls/combobox/helpers.js +91 -0
- package/src/controls/combobox/index.js +43 -0
- package/src/controls/combobox/style.css +203 -0
- package/src/controls/combobox/template.js +340 -0
- package/src/controls/controls.css +12 -0
- package/src/controls/fab/fab.stories.js +11 -11
- package/src/controls/fab/index.js +1 -2
- package/src/controls/fab/template.js +21 -19
- package/src/controls/icon-button/icon-button.stories.js +8 -10
- package/src/controls/icon-button/index.js +1 -2
- package/src/controls/icon-button/template.js +13 -19
- package/src/controls/input/index.js +1 -2
- package/src/controls/input/input.stories.js +24 -23
- package/src/controls/input/style.css +9 -7
- package/src/controls/input/template.js +28 -31
- package/src/controls/radio-group/index.js +1 -2
- package/src/controls/radio-group/radio-group.stories.js +11 -8
- package/src/controls/radio-group/style.css +22 -1
- package/src/controls/radio-group/template.js +20 -15
- package/src/controls/rating/index.js +1 -2
- package/src/controls/rating/rating.stories.js +7 -10
- package/src/controls/rating/style.css +1 -2
- package/src/controls/rating/template.js +20 -17
- package/src/controls/select/helpers.js +2 -21
- package/src/controls/select/index.js +1 -13
- package/src/controls/select/select.stories.js +68 -64
- package/src/controls/select/style.css +66 -189
- package/src/controls/select/template.js +77 -406
- package/src/controls/slider/index.js +1 -2
- package/src/controls/slider/slider.stories.js +15 -12
- package/src/controls/slider/style.css +24 -3
- package/src/controls/slider/template.js +30 -23
- package/src/controls/switch/index.js +1 -2
- package/src/controls/switch/style.css +23 -2
- package/src/controls/switch/switch.stories.js +14 -11
- package/src/controls/switch/template.js +18 -16
- package/src/data-display/avatar/avatar.stories.js +106 -0
- package/src/data-display/avatar/index.js +3 -0
- package/src/data-display/avatar/style.css +64 -0
- package/src/data-display/avatar/template.js +81 -0
- package/src/data-display/badge/badge.stories.js +64 -0
- package/src/data-display/badge/index.js +3 -0
- package/src/data-display/badge/style.css +84 -0
- package/src/data-display/badge/template.js +46 -0
- package/src/data-display/chip/chip.stories.js +57 -0
- package/src/data-display/chip/index.js +3 -0
- package/src/data-display/chip/style.css +84 -0
- package/src/data-display/chip/template.js +32 -0
- package/src/data-display/data-display.css +11 -0
- package/src/data-display/data-grid/base.css +58 -0
- package/src/data-display/data-grid/data-grid.stories.js +158 -0
- package/src/data-display/data-grid/filters/helpers.js +8 -0
- package/src/data-display/data-grid/filters/index.js +21 -0
- package/src/data-display/data-grid/filters/input.js +24 -0
- package/src/data-display/data-grid/filters/range.js +48 -0
- package/src/data-display/data-grid/filters/select.js +17 -0
- package/src/data-display/data-grid/handlers.js +523 -0
- package/src/data-display/data-grid/helpers.js +248 -0
- package/src/data-display/data-grid/index.js +64 -0
- package/src/data-display/data-grid/style.css +14 -0
- package/src/data-display/data-grid/template.js +458 -0
- package/src/data-display/data-grid/theme.css +148 -0
- package/src/data-display/divider/divider.stories.js +48 -0
- package/src/data-display/divider/index.js +3 -0
- package/src/data-display/divider/style.css +18 -0
- package/src/data-display/divider/template.js +17 -0
- package/src/data-display/icon/icon-implementations.mdx +160 -0
- package/src/data-display/icon/icon-utf8.stories.js +156 -0
- package/src/data-display/icon/icon.stories.js +38 -0
- package/src/data-display/icon/index.js +3 -0
- package/src/data-display/icon/style.css +17 -0
- package/src/data-display/icon/template.js +19 -0
- package/src/data-display/list/handlers.js +25 -0
- package/src/data-display/list/index.js +4 -0
- package/src/data-display/list/list.stories.js +187 -0
- package/src/data-display/list/style.css +119 -0
- package/src/data-display/list/template.js +302 -0
- package/src/data-display/material-icon/index.js +3 -0
- package/src/data-display/material-icon/material-icon.stories.js +99 -0
- package/src/data-display/material-icon/style.css +27 -0
- package/src/data-display/material-icon/template.js +21 -0
- package/src/data-display/table/index.js +1 -0
- package/src/data-display/table/style.css +42 -0
- package/src/data-display/table/table.stories.js +40 -0
- package/src/data-display/table/template.js +114 -0
- package/src/data-display/tooltip/index.js +3 -0
- package/src/data-display/tooltip/style.css +57 -0
- package/src/data-display/tooltip/template.js +58 -0
- package/src/data-display/tooltip/tooltip.stories.js +44 -0
- package/src/data-display/typography/index.js +3 -0
- package/src/data-display/typography/style.css +49 -0
- package/src/data-display/typography/template.js +110 -0
- package/src/data-display/typography/typography.stories.js +48 -0
- package/src/data-display/virtual-list/handlers.js +68 -0
- package/src/data-display/virtual-list/index.js +4 -0
- package/src/data-display/virtual-list/template.js +101 -0
- package/src/examples/dashboard/app-drawer.js +255 -0
- package/src/examples/dashboard/app-header.js +149 -0
- package/src/examples/dashboard/dashboard.js +85 -0
- package/src/examples/dashboard/dashboard.stories.js +47 -0
- package/src/examples/dashboard/data.js +205 -0
- package/src/examples/dashboard/mode.js +27 -0
- package/src/examples/dashboard/primitive-content.js +1325 -0
- package/src/examples/dashboard/primitive-section.js +158 -0
- package/src/examples/dashboard/router.js +13 -0
- package/src/examples/dashboard/social-card.js +73 -0
- package/src/examples/dashboard/stat-card.js +84 -0
- package/src/examples/dashboard/style.css +339 -0
- package/src/examples/dashboard/theme-utils.js +95 -0
- package/src/examples/dashboard/theme.js +27 -0
- package/src/examples/dashboard/traffic-card.js +108 -0
- package/src/examples/dashboard/traffic-sales-card.js +267 -0
- package/src/feedback/alert/alert.stories.js +70 -0
- package/src/feedback/alert/index.js +3 -0
- package/src/feedback/alert/style.css +98 -0
- package/src/feedback/alert/template.js +74 -0
- package/src/feedback/backdrop/backdrop.stories.js +21 -0
- package/src/feedback/backdrop/index.js +3 -0
- package/src/feedback/backdrop/style.css +25 -0
- package/src/feedback/backdrop/template.js +31 -0
- package/src/feedback/dialog/dialog.stories.js +27 -0
- package/src/feedback/dialog/index.js +3 -0
- package/src/feedback/dialog/style.css +68 -0
- package/src/feedback/dialog/template.js +64 -0
- package/src/feedback/feedback.css +6 -0
- package/src/feedback/progress/index.js +3 -0
- package/src/feedback/progress/progress.stories.js +54 -0
- package/src/feedback/progress/style.css +95 -0
- package/src/feedback/progress/template.js +88 -0
- package/src/feedback/skeleton/index.js +3 -0
- package/src/feedback/skeleton/skeleton.stories.js +44 -0
- package/src/feedback/skeleton/style.css +41 -0
- package/src/feedback/skeleton/template.js +48 -0
- package/src/feedback/snackbar/index.js +3 -0
- package/src/feedback/snackbar/snackbar.stories.js +25 -0
- package/src/feedback/snackbar/style.css +64 -0
- package/src/feedback/snackbar/template.js +55 -0
- package/src/index.js +32 -1
- package/src/layout/container/container.stories.js +105 -0
- package/src/layout/container/index.js +3 -0
- package/src/layout/container/style.css +34 -0
- package/src/layout/container/template.js +119 -0
- package/src/layout/flex/flex.stories.js +28 -10
- package/src/layout/flex/index.js +1 -2
- package/src/layout/flex/style.css +20 -0
- package/src/layout/flex/template.js +40 -13
- package/src/layout/grid/grid.stories.js +46 -30
- package/src/layout/grid/index.js +1 -2
- package/src/layout/grid/style.css +20 -0
- package/src/layout/grid/template.js +100 -20
- package/src/layout/layout.css +3 -0
- package/src/navigation/bottom-navigation/bottom-navigation.stories.js +33 -0
- package/src/navigation/bottom-navigation/index.js +1 -0
- package/src/navigation/bottom-navigation/style.css +32 -0
- package/src/navigation/bottom-navigation/template.js +74 -0
- package/src/navigation/breadcrumbs/breadcrumbs.stories.js +33 -0
- package/src/navigation/breadcrumbs/index.js +1 -0
- package/src/navigation/breadcrumbs/style.css +27 -0
- package/src/navigation/breadcrumbs/template.js +79 -0
- package/src/navigation/drawer/drawer.stories.js +60 -0
- package/src/navigation/drawer/index.js +3 -0
- package/src/navigation/drawer/style.css +125 -0
- package/src/navigation/drawer/template.js +131 -0
- package/src/navigation/link/index.js +3 -0
- package/src/navigation/link/link.stories.js +53 -0
- package/src/navigation/link/style.css +40 -0
- package/src/navigation/link/template.js +53 -0
- package/src/navigation/menu/index.js +1 -0
- package/src/navigation/menu/menu.stories.js +36 -0
- package/src/navigation/menu/style.css +44 -0
- package/src/navigation/menu/template.js +81 -0
- package/src/navigation/navigation.css +9 -0
- package/src/navigation/pagination/index.js +1 -0
- package/src/navigation/pagination/pagination.stories.js +61 -0
- package/src/navigation/pagination/style.css +29 -0
- package/src/navigation/pagination/template.js +140 -0
- package/src/navigation/speed-dial/index.js +1 -0
- package/src/navigation/speed-dial/speed-dial.stories.js +40 -0
- package/src/navigation/speed-dial/style.css +38 -0
- package/src/navigation/speed-dial/template.js +68 -0
- package/src/navigation/stepper/index.js +1 -0
- package/src/navigation/stepper/stepper.stories.js +35 -0
- package/src/navigation/stepper/style.css +49 -0
- package/src/navigation/stepper/template.js +61 -0
- package/src/navigation/tabs/index.js +1 -0
- package/src/navigation/tabs/style.css +35 -0
- package/src/navigation/tabs/tabs.stories.js +40 -0
- package/src/navigation/tabs/template.js +79 -0
- package/src/overview.mdx +39 -0
- package/src/stories/notifyStory.js +22 -25
- package/src/styles/base.css +2 -0
- package/src/styles/reset.css +15 -0
- package/src/{themes → styles/themes}/bootstrap.css +2 -0
- package/src/{themes → styles/themes}/inglorious.css +9 -1
- package/src/{themes → styles/themes}/material.css +2 -0
- package/src/{tokens/index.css → styles/tokens.css} +9 -0
- package/src/surfaces/accordion/accordion.stories.js +60 -0
- package/src/surfaces/accordion/index.js +1 -0
- package/src/surfaces/accordion/style.css +64 -0
- package/src/surfaces/accordion/template.js +85 -0
- package/src/surfaces/app-bar/app-bar.stories.js +109 -0
- package/src/surfaces/app-bar/index.js +3 -0
- package/src/surfaces/app-bar/style.css +109 -0
- package/src/surfaces/app-bar/template.js +78 -0
- package/src/surfaces/card/card.stories.js +108 -0
- package/src/surfaces/card/index.js +1 -0
- package/src/surfaces/card/style.css +107 -0
- package/src/surfaces/card/template.js +163 -0
- package/src/surfaces/paper/index.js +3 -0
- package/src/surfaces/paper/paper.stories.js +97 -0
- package/src/surfaces/paper/style.css +73 -0
- package/src/surfaces/paper/template.js +76 -0
- package/src/surfaces/surfaces.css +4 -0
- package/types/controls/button-group.d.ts +8 -7
- package/types/controls/button.d.ts +10 -7
- package/types/controls/checkbox.d.ts +8 -6
- package/types/controls/combobox.d.ts +66 -0
- package/types/controls/fab.d.ts +6 -5
- package/types/controls/icon-button.d.ts +8 -7
- package/types/controls/input.d.ts +18 -11
- package/types/controls/radio-group.d.ts +7 -5
- package/types/controls/rating.d.ts +6 -5
- package/types/controls/select.d.ts +11 -34
- package/types/controls/slider.d.ts +8 -6
- package/types/controls/switch.d.ts +7 -5
- package/types/data-display/avatar.d.ts +30 -0
- package/types/data-display/badge.d.ts +20 -0
- package/types/data-display/chip.d.ts +25 -0
- package/types/data-display/data-grid.d.ts +151 -0
- package/types/data-display/divider.d.ts +14 -0
- package/types/data-display/icon.d.ts +16 -0
- package/types/data-display/list.d.ts +66 -0
- package/types/data-display/material-icon.d.ts +15 -0
- package/types/data-display/table.d.ts +45 -0
- package/types/data-display/tooltip.d.ts +20 -0
- package/types/data-display/typography.d.ts +28 -0
- package/types/data-display/virtual-list.d.ts +94 -0
- package/types/feedback/alert.d.ts +22 -0
- package/types/feedback/backdrop.d.ts +17 -0
- package/types/feedback/dialog.d.ts +21 -0
- package/types/feedback/progress.d.ts +18 -0
- package/types/feedback/skeleton.d.ts +18 -0
- package/types/feedback/snackbar.d.ts +19 -0
- package/types/index.d.ts +92 -14
- package/types/layout/container.d.ts +28 -0
- package/types/layout/flex.d.ts +16 -5
- package/types/layout/grid.d.ts +15 -4
- package/types/navigation/bottom-navigation.d.ts +33 -0
- package/types/navigation/breadcrumbs.d.ts +29 -0
- package/types/navigation/drawer.d.ts +23 -0
- package/types/navigation/link.d.ts +22 -0
- package/types/navigation/menu.d.ts +32 -0
- package/types/navigation/pagination.d.ts +50 -0
- package/types/navigation/speed-dial.d.ts +35 -0
- package/types/navigation/stepper.d.ts +26 -0
- package/types/navigation/tabs.d.ts +31 -0
- package/types/surfaces/accordion.d.ts +32 -0
- package/types/surfaces/app-bar.d.ts +25 -0
- package/types/surfaces/card.d.ts +39 -0
- package/types/surfaces/paper.d.ts +28 -0
- package/src/shared/withRenderValidation.js +0 -19
- package/src/widgets/card/card.stories.js +0 -135
- package/src/widgets/card/index.js +0 -4
- package/src/widgets/card/style.css +0 -53
- package/src/widgets/card/template.js +0 -97
- package/types/widgets/card.d.ts +0 -21
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the row key value based on table rowId.
|
|
3
|
+
* @param {TableEntity} entity
|
|
4
|
+
* @param {any} row
|
|
5
|
+
* @returns {string|number}
|
|
6
|
+
*/
|
|
7
|
+
export function getRowKeyValue(entity, row) {
|
|
8
|
+
return row?.[entity.rowId]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Gets the processed rows (filtered, searched, sorted, paginated).
|
|
13
|
+
* @param {TableEntity} entity
|
|
14
|
+
* @returns {any[]}
|
|
15
|
+
*/
|
|
16
|
+
export function getRows(entity) {
|
|
17
|
+
let rows = entity.rows
|
|
18
|
+
rows = applyFilters(entity, rows)
|
|
19
|
+
rows = applySearch(entity, rows)
|
|
20
|
+
rows = applySorts(entity, rows)
|
|
21
|
+
rows = applyPagination(entity, rows)
|
|
22
|
+
|
|
23
|
+
return rows
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Gets the total number of rows after filtering and searching.
|
|
28
|
+
* @param {TableEntity} entity
|
|
29
|
+
* @returns {number}
|
|
30
|
+
*/
|
|
31
|
+
export function getTotalRows(entity) {
|
|
32
|
+
let rows = entity.rows
|
|
33
|
+
rows = applyFilters(entity, rows)
|
|
34
|
+
rows = applySearch(entity, rows)
|
|
35
|
+
return rows.length
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Gets pagination information.
|
|
40
|
+
* @param {TableEntity} entity
|
|
41
|
+
* @returns {object|null}
|
|
42
|
+
*/
|
|
43
|
+
export function getPaginationInfo(entity) {
|
|
44
|
+
if (!entity.pagination) return null
|
|
45
|
+
|
|
46
|
+
const totalRows = getTotalRows(entity)
|
|
47
|
+
const { page, pageSize, pageSizes } = entity.pagination
|
|
48
|
+
const totalPages = Math.ceil(totalRows / pageSize)
|
|
49
|
+
const start = page * pageSize
|
|
50
|
+
const end = Math.min((page + 1) * pageSize, totalRows)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
page,
|
|
54
|
+
pageSize,
|
|
55
|
+
pageSizes,
|
|
56
|
+
totalPages,
|
|
57
|
+
totalRows,
|
|
58
|
+
start,
|
|
59
|
+
end,
|
|
60
|
+
hasNextPage: page < totalPages - 1,
|
|
61
|
+
hasPrevPage: page > 0,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Gets the sort direction for a column.
|
|
67
|
+
* @param {TableEntity} entity
|
|
68
|
+
* @param {string} columnId
|
|
69
|
+
* @returns {"asc"|"desc"|null}
|
|
70
|
+
*/
|
|
71
|
+
export function getSortDirection(entity, columnId) {
|
|
72
|
+
const sort = entity.sorts.find((s) => s.column === columnId)
|
|
73
|
+
return sort?.direction || null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Gets the sort index (priority) for a column.
|
|
78
|
+
* @param {TableEntity} entity
|
|
79
|
+
* @param {string} columnId
|
|
80
|
+
* @returns {number}
|
|
81
|
+
*/
|
|
82
|
+
export function getSortIndex(entity, columnId) {
|
|
83
|
+
return entity.sorts.findIndex((s) => s.column === columnId)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets the filter value for a column.
|
|
88
|
+
* @param {TableEntity} entity
|
|
89
|
+
* @param {string} columnId
|
|
90
|
+
* @returns {any}
|
|
91
|
+
*/
|
|
92
|
+
export function getFilter(entity, columnId) {
|
|
93
|
+
return entity.filters[columnId]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a row is selected.
|
|
98
|
+
* @param {TableEntity} entity
|
|
99
|
+
* @param {string|number} rowId
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
export function isRowSelected(entity, rowId) {
|
|
103
|
+
return entity.selection.includes(rowId)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Checks if all visible rows are selected.
|
|
108
|
+
* @param {TableEntity} entity
|
|
109
|
+
* @returns {boolean}
|
|
110
|
+
*/
|
|
111
|
+
export function isAllSelected(entity) {
|
|
112
|
+
const rows = getRows(entity)
|
|
113
|
+
return (
|
|
114
|
+
rows.length &&
|
|
115
|
+
rows.every((row) => entity.selection.includes(getRowKeyValue(entity, row)))
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Checks if some (but not all) visible rows are selected.
|
|
121
|
+
* @param {TableEntity} entity
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
export function isSomeSelected(entity) {
|
|
125
|
+
const rows = getRows(entity)
|
|
126
|
+
const selectedCount = rows.filter((row) =>
|
|
127
|
+
entity.selection.includes(getRowKeyValue(entity, row)),
|
|
128
|
+
).length
|
|
129
|
+
return selectedCount && selectedCount < rows.length
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Applies filters to the data.
|
|
134
|
+
* @param {TableEntity} entity
|
|
135
|
+
* @param {any[]} rows
|
|
136
|
+
* @returns {any[]}
|
|
137
|
+
*/
|
|
138
|
+
function applyFilters(entity, rows) {
|
|
139
|
+
if (!Object.keys(entity.filters).length) {
|
|
140
|
+
return rows
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return rows.filter((row) => {
|
|
144
|
+
return Object.entries(entity.filters).every(([columnId, filterValue]) => {
|
|
145
|
+
const column = entity.columns.find((c) => c.id === columnId)
|
|
146
|
+
if (!column) return true
|
|
147
|
+
|
|
148
|
+
// Custom filter function
|
|
149
|
+
if (column.filterFn) {
|
|
150
|
+
return column.filterFn(row, filterValue)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Default filters by type
|
|
154
|
+
const value = row[columnId]
|
|
155
|
+
|
|
156
|
+
if (["range", "date", "time", "datetime"].includes(column.filter.type)) {
|
|
157
|
+
const { min, max } = filterValue
|
|
158
|
+
if (min != null && value < min) return false
|
|
159
|
+
if (max != null && value > max) return false
|
|
160
|
+
return true
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (["number", "boolean", "select"].includes(column.filter.type)) {
|
|
164
|
+
return value === filterValue
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// String filtering (case-insensitive contains)
|
|
168
|
+
return String(value)
|
|
169
|
+
.toLowerCase()
|
|
170
|
+
.includes(String(filterValue).toLowerCase())
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Applies search to the data.
|
|
177
|
+
* @param {TableEntity} entity
|
|
178
|
+
* @param {any[]} rows
|
|
179
|
+
* @returns {any[]}
|
|
180
|
+
*/
|
|
181
|
+
function applySearch(entity, rows) {
|
|
182
|
+
if (!entity.search?.value) {
|
|
183
|
+
return rows
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const searchLower = entity.search.value.toLowerCase()
|
|
187
|
+
|
|
188
|
+
return rows.filter((row) =>
|
|
189
|
+
entity.columns.some((column) => {
|
|
190
|
+
const value = row[column.id]
|
|
191
|
+
const formattedValue = column.format?.(value) ?? String(value)
|
|
192
|
+
return formattedValue.toLowerCase().includes(searchLower)
|
|
193
|
+
}),
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Applies sorting to the data.
|
|
199
|
+
* @param {TableEntity} entity
|
|
200
|
+
* @param {any[]} rows
|
|
201
|
+
* @returns {any[]}
|
|
202
|
+
*/
|
|
203
|
+
function applySorts(entity, rows) {
|
|
204
|
+
if (!entity.sorts.length) {
|
|
205
|
+
return rows
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return [...rows].sort((a, b) => {
|
|
209
|
+
for (const { column: columnId, direction } of entity.sorts) {
|
|
210
|
+
const column = entity.columns.find((c) => c.id === columnId)
|
|
211
|
+
let aVal = a[columnId]
|
|
212
|
+
let bVal = b[columnId]
|
|
213
|
+
|
|
214
|
+
// Custom sort function
|
|
215
|
+
if (column?.sortFn) {
|
|
216
|
+
const result =
|
|
217
|
+
direction === "asc" ? column.sortFn(a, b) : column.sortFn(b, a)
|
|
218
|
+
if (result !== 0) return result
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Default sorting
|
|
223
|
+
if (aVal === bVal) continue
|
|
224
|
+
if (aVal == null) return 1
|
|
225
|
+
if (bVal == null) return -1
|
|
226
|
+
|
|
227
|
+
const comparison = aVal < bVal ? -1 : 1
|
|
228
|
+
return direction === "asc" ? comparison : -comparison
|
|
229
|
+
}
|
|
230
|
+
return 0
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Applies pagination to the data.
|
|
236
|
+
* @param {TableEntity} entity
|
|
237
|
+
* @param {any[]} rows
|
|
238
|
+
* @returns {any[]}
|
|
239
|
+
*/
|
|
240
|
+
function applyPagination(entity, rows) {
|
|
241
|
+
if (!entity.pagination) {
|
|
242
|
+
return rows
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const { page, pageSize } = entity.pagination
|
|
246
|
+
const start = page * pageSize
|
|
247
|
+
return rows.slice(start, start + pageSize)
|
|
248
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as handlers from "./handlers.js"
|
|
2
|
+
import * as helpers from "./helpers.js"
|
|
3
|
+
import { dataGrid as renderers } from "./template.js"
|
|
4
|
+
|
|
5
|
+
export const dataGrid = {
|
|
6
|
+
...handlers,
|
|
7
|
+
...renderers,
|
|
8
|
+
render(entity, api) {
|
|
9
|
+
const id = entity.id
|
|
10
|
+
const props = {
|
|
11
|
+
...entity,
|
|
12
|
+
onSortChange: (columnId) => api.notify(`#${id}:sortChange`, columnId),
|
|
13
|
+
onFilterChange: (payload) => api.notify(`#${id}:filterChange`, payload),
|
|
14
|
+
onSearchChange: (value) => api.notify(`#${id}:searchChange`, value),
|
|
15
|
+
onColumnResizeStart: (payload) => startColumnResize(api, id, payload),
|
|
16
|
+
onRowClick: (payload) => api.notify(`#${id}:rowClick`, payload),
|
|
17
|
+
onPageChange: (page) => api.notify(`#${id}:pageChange`, page),
|
|
18
|
+
onPageNext: () => api.notify(`#${id}:pageNext`),
|
|
19
|
+
onPagePrev: () => api.notify(`#${id}:pagePrev`),
|
|
20
|
+
onPageSizeChange: (pageSize) =>
|
|
21
|
+
api.notify(`#${id}:pageSizeChange`, pageSize),
|
|
22
|
+
onVirtualMount: (containerEl) =>
|
|
23
|
+
api.notify(`#${id}:virtualMount`, containerEl),
|
|
24
|
+
onVirtualScroll: (containerEl) =>
|
|
25
|
+
api.notify(`#${id}:virtualScroll`, containerEl),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this.renderDataGrid(props)
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const {
|
|
33
|
+
getPaginationInfo,
|
|
34
|
+
getRows,
|
|
35
|
+
isSomeSelected,
|
|
36
|
+
isAllSelected,
|
|
37
|
+
getSortDirection,
|
|
38
|
+
getTotalRows,
|
|
39
|
+
} = helpers
|
|
40
|
+
|
|
41
|
+
const MIN_COLUMN_WIDTH = 72
|
|
42
|
+
|
|
43
|
+
function startColumnResize(api, id, { columnId, event, width }) {
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
event.stopPropagation()
|
|
46
|
+
|
|
47
|
+
const startX = event.clientX
|
|
48
|
+
const startWidth = Math.max(MIN_COLUMN_WIDTH, Math.round(width))
|
|
49
|
+
|
|
50
|
+
const handleMove = (moveEvent) => {
|
|
51
|
+
api.notify(`#${id}:columnResize`, {
|
|
52
|
+
columnId,
|
|
53
|
+
width: startWidth + moveEvent.clientX - startX,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleEnd = () => {
|
|
58
|
+
window.removeEventListener("pointermove", handleMove)
|
|
59
|
+
window.removeEventListener("pointerup", handleEnd)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
window.addEventListener("pointermove", handleMove)
|
|
63
|
+
window.addEventListener("pointerup", handleEnd, { once: true })
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@import "../../controls/input/style.css";
|
|
2
|
+
@import "../../controls/select/style.css";
|
|
3
|
+
@import "../../controls/button/style.css";
|
|
4
|
+
@import "../../navigation/pagination/style.css";
|
|
5
|
+
|
|
6
|
+
@import "./base";
|
|
7
|
+
@import "./theme";
|
|
8
|
+
|
|
9
|
+
.iw-datagrid {
|
|
10
|
+
color: var(--iw-color-text);
|
|
11
|
+
background: var(--iw-color-surface);
|
|
12
|
+
padding: var(--iw-space-3);
|
|
13
|
+
border-radius: var(--iw-radius-md);
|
|
14
|
+
}
|