nitro-web 0.0.134 → 0.0.135
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/client/index.ts +1 -1
- package/components/partials/element/table.tsx +24 -17
- package/package.json +1 -1
package/client/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ export { Modal } from '../components/partials/element/modal'
|
|
|
34
34
|
export { Sidebar, type SidebarProps } from '../components/partials/element/sidebar'
|
|
35
35
|
export { Tooltip } from '../components/partials/element/tooltip'
|
|
36
36
|
export { Topbar } from '../components/partials/element/topbar'
|
|
37
|
-
export { Table, type TableColumn, type TableProps, type TableRow } from '../components/partials/element/table'
|
|
37
|
+
export { Table, type TableColumn, type TableProps, type TableRow, type TableRowType } from '../components/partials/element/table'
|
|
38
38
|
|
|
39
39
|
// Component Form Elements
|
|
40
40
|
export { Checkbox } from '../components/partials/form/checkbox'
|
|
@@ -2,6 +2,8 @@ import { JSX, useState, useCallback, Fragment } from 'react'
|
|
|
2
2
|
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
|
3
3
|
import { Checkbox, queryObject, queryString, twMerge } from 'nitro-web'
|
|
4
4
|
|
|
5
|
+
export type TableRowType = 'row' | 'loading' | 'empty' | 'thead'
|
|
6
|
+
|
|
5
7
|
export interface TableColumn {
|
|
6
8
|
label: string
|
|
7
9
|
value: string
|
|
@@ -20,7 +22,6 @@ export interface TableColumn {
|
|
|
20
22
|
export type TableRow = {
|
|
21
23
|
_id?: string
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
export type TableProps<T> = {
|
|
25
26
|
columns: TableColumn[]
|
|
26
27
|
rows: T[]
|
|
@@ -30,7 +31,7 @@ export type TableProps<T> = {
|
|
|
30
31
|
rowHeightMin?: number
|
|
31
32
|
rowContentHeightMax?: number
|
|
32
33
|
rowLinesMax?: number
|
|
33
|
-
rowSideColor?: (row
|
|
34
|
+
rowSideColor?: (row: T|undefined, type: TableRowType) => { className: string, width: number }
|
|
34
35
|
rowGap?: number
|
|
35
36
|
rowOnClick?: (row: T) => void
|
|
36
37
|
columnGap?: number
|
|
@@ -123,6 +124,14 @@ export function Table<T extends TableRow>({
|
|
|
123
124
|
navigate(location.pathname + queryStr, { replace: true })
|
|
124
125
|
}, [location.pathname, query, sort, sortBy])
|
|
125
126
|
|
|
127
|
+
const getColumnPadding = useCallback((j: number, row: T|undefined, type: TableRowType) => {
|
|
128
|
+
const sideColor = j == 0 && rowSideColor ? rowSideColor(row, type) : undefined
|
|
129
|
+
const sideColorPadding = sideColor /*&& rows.length > 0*/ ? sideColor.width + 5 : 0
|
|
130
|
+
const pl = sideColorPadding + (j == 0 ? columnPaddingX : columnGap)
|
|
131
|
+
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
132
|
+
return { pl, pr, sideColor }
|
|
133
|
+
}, [rowSideColor, columnPaddingX, columnGap])
|
|
134
|
+
|
|
126
135
|
return (
|
|
127
136
|
<div
|
|
128
137
|
style={{ marginTop: -rowGap }}
|
|
@@ -137,10 +146,7 @@ export function Table<T extends TableRow>({
|
|
|
137
146
|
{
|
|
138
147
|
columns.map((col, j) => {
|
|
139
148
|
const disableSort = col.disableSort || selectedRowIds.length
|
|
140
|
-
const
|
|
141
|
-
const sideColorPadding = sideColor && rows.length > 0 ? sideColor.width + 5 : 0
|
|
142
|
-
const pl = sideColorPadding + (j == 0 ? columnPaddingX : columnGap)
|
|
143
|
-
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
149
|
+
const { pl, pr } = getColumnPadding(j, undefined, 'thead')
|
|
144
150
|
|
|
145
151
|
if (col.isHidden) return <Fragment key={j} />
|
|
146
152
|
return (
|
|
@@ -221,10 +227,7 @@ export function Table<T extends TableRow>({
|
|
|
221
227
|
>
|
|
222
228
|
{
|
|
223
229
|
columns.map((col, j) => {
|
|
224
|
-
const
|
|
225
|
-
const pl = j == 0 ? columnPaddingX : columnGap
|
|
226
|
-
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
227
|
-
|
|
230
|
+
const { pl, pr, sideColor } = getColumnPadding(j, row, 'row')
|
|
228
231
|
if (col.isHidden) return <Fragment key={j} />
|
|
229
232
|
return (
|
|
230
233
|
<div
|
|
@@ -239,10 +242,8 @@ export function Table<T extends TableRow>({
|
|
|
239
242
|
)}
|
|
240
243
|
>
|
|
241
244
|
<div
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
paddingLeft: sideColor ? sideColor.width + 5 : 0,
|
|
245
|
-
}}
|
|
245
|
+
// pl:sideColorPadding was originally here
|
|
246
|
+
style={{ maxHeight: rowContentHeightMax }}
|
|
246
247
|
className={twMerge(
|
|
247
248
|
rowContentHeightMax ? 'overflow-hidden' : '',
|
|
248
249
|
getLineClampClassName(col.rowLinesMax),
|
|
@@ -286,14 +287,20 @@ export function Table<T extends TableRow>({
|
|
|
286
287
|
<div className='table-row relative'>
|
|
287
288
|
{
|
|
288
289
|
columns.map((col, j) => {
|
|
289
|
-
const pl = j
|
|
290
|
-
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
290
|
+
const { pl, pr, sideColor } = getColumnPadding(j, undefined, isLoading ? 'loading' : 'empty')
|
|
291
291
|
return (
|
|
292
292
|
<div
|
|
293
293
|
key={j}
|
|
294
294
|
style={{ height: rowHeightMin, paddingLeft: pl, paddingRight: pr }}
|
|
295
295
|
className={twMerge(_columnClassName, columnClassName, col.className)}
|
|
296
296
|
>
|
|
297
|
+
{
|
|
298
|
+
sideColor &&
|
|
299
|
+
<div
|
|
300
|
+
className={`absolute top-0 left-0 h-full ${sideColor?.className||''}`}
|
|
301
|
+
style={{ width: sideColor.width }}
|
|
302
|
+
/>
|
|
303
|
+
}
|
|
297
304
|
<div
|
|
298
305
|
className={twMerge(
|
|
299
306
|
'absolute top-0 h-full flex items-center justify-center text-sm text-gray-500',
|
|
@@ -321,4 +328,4 @@ function getLineClampClassName(num?: number) {
|
|
|
321
328
|
else if (num == 4) return 'line-clamp-4'
|
|
322
329
|
else if (num == 5) return 'line-clamp-5'
|
|
323
330
|
else if (num == 6) return 'line-clamp-6'
|
|
324
|
-
}
|
|
331
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.135",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|