nitro-web 0.0.104 → 0.0.106
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.
|
@@ -58,6 +58,7 @@ export const Filters = forwardRef<FiltersHandleType, FiltersProps>(({
|
|
|
58
58
|
const [state3, setState3] = useState(() => ({ ...queryObject(location.search) }))
|
|
59
59
|
const [state, setState] = [state2 || state3, setState2 || setState3]
|
|
60
60
|
const stateRef = useRef(state)
|
|
61
|
+
const locationRef = useRef(location)
|
|
61
62
|
const count = useMemo(() => Object.keys(state).filter((k) => state[k] && filters?.some((f) => f.name === k)).length, [state, filters])
|
|
62
63
|
|
|
63
64
|
const Elements = {
|
|
@@ -79,6 +80,10 @@ export const Filters = forwardRef<FiltersHandleType, FiltersProps>(({
|
|
|
79
80
|
useEffect(() => {
|
|
80
81
|
stateRef.current = state
|
|
81
82
|
}, [state])
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
locationRef.current = location
|
|
86
|
+
}, [location])
|
|
82
87
|
|
|
83
88
|
useEffect(() => {
|
|
84
89
|
// Only update the state if the filters haven't been input changed in the last 500ms
|
|
@@ -116,7 +121,7 @@ export const Filters = forwardRef<FiltersHandleType, FiltersProps>(({
|
|
|
116
121
|
// Update the URL by replacing the current entry in the history stack
|
|
117
122
|
function submit(includePagination?: boolean) {
|
|
118
123
|
const queryStr = queryString(omit(stateRef.current, includePagination ? [] : ['page']))
|
|
119
|
-
navigate(
|
|
124
|
+
navigate(locationRef.current.pathname + queryStr, { replace: true })
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
return (
|
|
@@ -30,11 +30,13 @@ export type TableProps<T> = {
|
|
|
30
30
|
rowContentHeightMax?: number
|
|
31
31
|
rowLinesMax?: number
|
|
32
32
|
rowSideColor?: (row?: T) => { className: string, width: number }
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
rowGap?: number
|
|
34
|
+
columnGap?: number
|
|
35
|
+
columnPaddingX?: number
|
|
35
36
|
className?: string
|
|
36
37
|
tableClassName?: string
|
|
37
38
|
columnClassName?: string
|
|
39
|
+
columnSelectedClassName?: string
|
|
38
40
|
columnHeaderClassName?: string
|
|
39
41
|
checkboxClassName?: string
|
|
40
42
|
checkboxSize?: number
|
|
@@ -50,18 +52,21 @@ export function Table<T extends TableRow>({
|
|
|
50
52
|
rowContentHeightMax,
|
|
51
53
|
rowLinesMax,
|
|
52
54
|
rowSideColor,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
rowGap=0,
|
|
56
|
+
columnGap=11,
|
|
57
|
+
columnPaddingX=11,
|
|
58
|
+
// Class names
|
|
55
59
|
className,
|
|
56
60
|
tableClassName,
|
|
57
61
|
columnClassName,
|
|
62
|
+
columnSelectedClassName,
|
|
58
63
|
columnHeaderClassName,
|
|
59
64
|
checkboxClassName,
|
|
60
65
|
checkboxSize=16,
|
|
61
66
|
}: TableProps<T>) {
|
|
62
67
|
const location = useLocation()
|
|
63
68
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([])
|
|
64
|
-
const _columnClassName = 'table-cell
|
|
69
|
+
const _columnClassName = 'table-cell py-1 align-middle text-sm border-y border-border ' +
|
|
65
70
|
'first:border-l last:border-r border-t-0 box-border'
|
|
66
71
|
|
|
67
72
|
const columns = useMemo(() => {
|
|
@@ -111,11 +116,11 @@ export function Table<T extends TableRow>({
|
|
|
111
116
|
|
|
112
117
|
return (
|
|
113
118
|
<div
|
|
114
|
-
style={{ marginTop: -
|
|
119
|
+
style={{ marginTop: -rowGap }}
|
|
115
120
|
className={twMerge('overflow-x-auto thin-scrollbar', className)}
|
|
116
121
|
>
|
|
117
122
|
<div
|
|
118
|
-
style={{ borderSpacing: `0 ${
|
|
123
|
+
style={{ borderSpacing: `0 ${rowGap}px` }}
|
|
119
124
|
className={twMerge('table w-full border-separate', tableClassName)}
|
|
120
125
|
>
|
|
121
126
|
{/* Thead row */}
|
|
@@ -124,11 +129,13 @@ export function Table<T extends TableRow>({
|
|
|
124
129
|
columns.map((col, j) => {
|
|
125
130
|
const disableSort = col.disableSort || selectedRowIds.length
|
|
126
131
|
const sideColor = j == 0 && rowSideColor ? rowSideColor(undefined) : undefined
|
|
132
|
+
const pl = j == 0 ? columnPaddingX : columnGap
|
|
133
|
+
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
127
134
|
return (
|
|
128
135
|
<div
|
|
129
136
|
key={j}
|
|
130
137
|
onClick={disableSort ? undefined : () => onSort(col)}
|
|
131
|
-
style={{ height: headerHeightMin, minWidth: col.minWidth }}
|
|
138
|
+
style={{ height: headerHeightMin, minWidth: col.minWidth, paddingLeft: pl, paddingRight: pr }}
|
|
132
139
|
className={twMerge(
|
|
133
140
|
_columnClassName,
|
|
134
141
|
'h-auto text-sm font-medium border-t-1',
|
|
@@ -192,23 +199,27 @@ export function Table<T extends TableRow>({
|
|
|
192
199
|
{/* Tbody rows */}
|
|
193
200
|
{
|
|
194
201
|
rows.map((row: T, i: number) => {
|
|
202
|
+
const isSelected = selectedRowIds.includes(row?._id||'')
|
|
195
203
|
return (
|
|
196
204
|
<div
|
|
197
205
|
key={`${row._id}-${i}`}
|
|
198
|
-
className=
|
|
206
|
+
className="table-row relative"
|
|
199
207
|
>
|
|
200
208
|
{
|
|
201
209
|
columns.map((col, j) => {
|
|
202
210
|
const sideColor = j == 0 && rowSideColor ? rowSideColor(row) : undefined
|
|
211
|
+
const pl = j == 0 ? columnPaddingX : columnGap
|
|
212
|
+
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
203
213
|
return (
|
|
204
214
|
<div
|
|
205
215
|
key={j}
|
|
206
|
-
style={{ height: rowHeightMin }}
|
|
216
|
+
style={{ height: rowHeightMin, paddingLeft: pl, paddingRight: pr }}
|
|
207
217
|
className={twMerge(
|
|
208
218
|
_columnClassName,
|
|
209
219
|
getAlignClass(col.align),
|
|
210
220
|
columnClassName,
|
|
211
|
-
col.className
|
|
221
|
+
col.className,
|
|
222
|
+
isSelected && `bg-gray-50 ${columnSelectedClassName||''}`
|
|
212
223
|
)}
|
|
213
224
|
>
|
|
214
225
|
<div
|
|
@@ -256,22 +267,26 @@ export function Table<T extends TableRow>({
|
|
|
256
267
|
rows.length == 0 &&
|
|
257
268
|
<div className='table-row relative'>
|
|
258
269
|
{
|
|
259
|
-
columns.map((col, j) =>
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
className={twMerge(_columnClassName, columnClassName, col.className)}
|
|
264
|
-
>
|
|
270
|
+
columns.map((col, j) => {
|
|
271
|
+
const pl = j == 0 ? columnPaddingX : columnGap
|
|
272
|
+
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
273
|
+
return (
|
|
265
274
|
<div
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
)}
|
|
275
|
+
key={j}
|
|
276
|
+
style={{ height: rowHeightMin, paddingLeft: pl, paddingRight: pr }}
|
|
277
|
+
className={twMerge(_columnClassName, columnClassName, col.className)}
|
|
270
278
|
>
|
|
271
|
-
|
|
279
|
+
<div
|
|
280
|
+
className={twMerge(
|
|
281
|
+
'absolute top-0 h-full flex items-center justify-center text-sm text-gray-500',
|
|
282
|
+
col.innerClassName
|
|
283
|
+
)}
|
|
284
|
+
>
|
|
285
|
+
{ j == 0 && 'No records found.' }
|
|
286
|
+
</div>
|
|
272
287
|
</div>
|
|
273
|
-
|
|
274
|
-
)
|
|
288
|
+
)
|
|
289
|
+
})
|
|
275
290
|
}
|
|
276
291
|
</div>
|
|
277
292
|
}
|
|
@@ -494,13 +494,14 @@ export function Styleguide({ className, elements, children }: StyleguideProps) {
|
|
|
494
494
|
columns={thead}
|
|
495
495
|
rowLinesMax={1}
|
|
496
496
|
headerHeightMin={35}
|
|
497
|
-
|
|
498
|
-
rowHeightMin={
|
|
497
|
+
rowGap={8}
|
|
498
|
+
rowHeightMin={42}
|
|
499
499
|
rowSideColor={(row) => ({ className: `rounded-l-xl ${statusColors(row?.status as string)}`, width: 10 })}
|
|
500
500
|
generateCheckboxActions={generateCheckboxActions}
|
|
501
501
|
generateTd={generateTd}
|
|
502
502
|
tableClassName="rounded-3px"
|
|
503
503
|
columnClassName="border-t-1 first:rounded-l-xl last:rounded-r-xl"
|
|
504
|
+
columnSelectedClassName="bg-indigo-50 border-indigo-300"
|
|
504
505
|
columnHeaderClassName="text-gray-500 text-2xs uppercase border-none"
|
|
505
506
|
checkboxClassName="rounded-[2px] shadow-none"
|
|
506
507
|
className="mb-5"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.106",
|
|
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 🚀",
|