Skip to content

Commit efb8be2

Browse files
committed
update tableLoader structure
1 parent 6da7113 commit efb8be2

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

src/loaders/tableLoader.tsx

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { component$, $ } from "@builder.io/qwik"
2-
import { TableRecord, ITableLoader } from "../types"
2+
import type { TableRecord, ITableLoader } from "../types"
33
import { param2string } from "../utils"
44

55
export const tableLoader = $(
66
({
77
tData,
88
transformHeads = true,
9-
tailwindClasses = true,
109
tHeadings,
1110
tRows,
1211
tCells,
@@ -21,15 +20,11 @@ export const tableLoader = $(
2120
<th
2221
{...tHeadings?.props}
2322
class={
24-
tHeadings?.props?.class
25-
? tHeadings?.props?.class
26-
: tailwindClasses
27-
? "table-heading border border-slate-600 bg-gray-300 text-left"
28-
: "table-heading"
23+
tHeadings?.props?.class ? tHeadings.props.class : "table-heading"
2924
}
3025
>
31-
{tHeadings?.accessor
32-
? tHeadings?.accessor(heading)
26+
{tHeadings?.element$
27+
? tHeadings.element$(heading)
3328
: transformHeads
3429
? param2string(heading)
3530
: heading}
@@ -39,60 +34,35 @@ export const tableLoader = $(
3934
const renderCell = $((record: TableRecord, param: string) => (
4035
<td
4136
{...tCells?.props}
42-
class={
43-
tCells?.props?.class
44-
? tCells?.props?.class
45-
: tailwindClasses
46-
? "table-cell border border-slate-700"
47-
: "table-cell"
48-
}
37+
class={tCells?.props?.class ? tCells.props.class : "table-cell"}
4938
>
50-
{tCells?.accessor ? tCells?.accessor(record, param) : record[param]}
39+
{tCells?.element$ ? tCells.element$(record, param) : record[param]}
5140
</td>
5241
))
5342

5443
const renderRow = $((record: TableRecord, headings: Array<string>) => (
5544
<tr
5645
{...tRows?.props}
57-
class={
58-
tRows?.props?.class
59-
? tRows?.props?.class
60-
: tailwindClasses
61-
? "table-row border border-slate-600"
62-
: "table-row"
63-
}
46+
class={tRows?.props?.class ? tRows.props.class : "table-row"}
6447
>
6548
{headings.map((param: string) => renderCell(record, param))}
6649
</tr>
6750
))
6851

69-
/* RETURNED COMPONENTS
52+
/* RETURN COMPONENTS
7053
* @type: component$
7154
* @desc: render JSX elements into big element blocks, ie. Head or Body
7255
*/
73-
const Head = component$(() => (
74-
<tr>{headingList.map((heading: string) => renderHeading(heading))}</tr>
75-
))
7656

7757
const THead = component$(() => (
78-
<thead>
79-
<Head />
80-
</thead>
81-
))
82-
83-
const Body = component$(() => (
84-
<>{tData.map((record: TableRecord) => renderRow(record, headingList))}</>
58+
<tr>{headingList.map((heading: string) => renderHeading(heading))}</tr>
8559
))
8660

8761
const TBody = component$(() => (
88-
<tbody>
89-
<Body />
90-
</tbody>
62+
<>{tData.map((record: TableRecord) => renderRow(record, headingList))}</>
9163
))
9264

9365
return {
94-
Head,
95-
Body,
9666
THead,
9767
TBody,
9868
}

0 commit comments

Comments
 (0)