feat(SW-216): Added heading and preamble text to table block

This commit is contained in:
Erik Tiekstra
2024-10-08 11:06:33 +02:00
committed by Pontus Dreij
parent 5c10d36745
commit 23953aeb61
5 changed files with 67 additions and 50 deletions

View File

@@ -8,6 +8,8 @@ import {
} from "@tanstack/react-table" } from "@tanstack/react-table"
import { useState } from "react" import { useState } from "react"
import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header"
import ScrollWrapper from "@/components/TempDesignSystem/ScrollWrapper" import ScrollWrapper from "@/components/TempDesignSystem/ScrollWrapper"
import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton" import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
import Table from "@/components/TempDesignSystem/Table" import Table from "@/components/TempDesignSystem/Table"
@@ -17,7 +19,7 @@ import styles from "./table.module.css"
import type { TableBlockProps } from "@/types/components/blocks/table" import type { TableBlockProps } from "@/types/components/blocks/table"
export default function TableBlock({ data }: TableBlockProps) { export default function TableBlock({ data }: TableBlockProps) {
const { columns, rows, totalWidth } = data const { columns, rows, totalWidth, heading, preamble } = data
const initialPageSize = 5 const initialPageSize = 5
const [pageSize, setPageSize] = useState(initialPageSize) const [pageSize, setPageSize] = useState(initialPageSize)
const showMoreVisible = rows.length > initialPageSize const showMoreVisible = rows.length > initialPageSize
@@ -46,6 +48,10 @@ export default function TableBlock({ data }: TableBlockProps) {
} }
return ( return (
<SectionContainer>
{heading ? (
<SectionHeader preamble={data.preamble} title={heading} />
) : null}
<div className={styles.tableWrapper}> <div className={styles.tableWrapper}>
<ScrollWrapper> <ScrollWrapper>
<Table <Table
@@ -77,7 +83,10 @@ export default function TableBlock({ data }: TableBlockProps) {
<Table.TR key={row.id}> <Table.TR key={row.id}>
{row.getVisibleCells().map((cell) => ( {row.getVisibleCells().map((cell) => (
<Table.TD key={cell.id}> <Table.TD key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())} {flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</Table.TD> </Table.TD>
))} ))}
</Table.TR> </Table.TR>
@@ -93,5 +102,6 @@ export default function TableBlock({ data }: TableBlockProps) {
/> />
) : null} ) : null}
</div> </div>
</SectionContainer>
) )
} }

View File

@@ -4,10 +4,10 @@ import { useMemo } from "react"
import useScrollShadows from "@/hooks/useScrollShadows" import useScrollShadows from "@/hooks/useScrollShadows"
import { ScrollWrapperProps } from "./scrollWrapper"
import styles from "./scrollWrapper.module.css" import styles from "./scrollWrapper.module.css"
import type { ScrollWrapperProps } from "./scrollWrapper"
export default function ScrollWrapper({ export default function ScrollWrapper({
className, className,
children, children,

View File

@@ -1,4 +1,3 @@
import { TableProps } from "./table"
import TBody from "./TBody" import TBody from "./TBody"
import TD from "./TD" import TD from "./TD"
import TH from "./TH" import TH from "./TH"
@@ -6,6 +5,8 @@ import THead from "./THead"
import TR from "./TR" import TR from "./TR"
import { tableVariants } from "./variants" import { tableVariants } from "./variants"
import type { TableProps } from "./table"
function Table({ function Table({
className, className,
intent, intent,

View File

@@ -1,6 +1,8 @@
fragment Table_ContentPage on ContentPageBlocksTable { fragment Table_ContentPage on ContentPageBlocksTable {
__typename __typename
table { table {
heading
preamble
column_widths column_widths
table table
} }

View File

@@ -9,6 +9,8 @@ export const tableSchema = z.object({
.default(BlocksEnums.block.Table), .default(BlocksEnums.block.Table),
table: z table: z
.object({ .object({
heading: z.string().optional(),
preamble: z.string().optional().default(""),
column_widths: z.array(z.number()), column_widths: z.array(z.number()),
table: z.object({ table: z.object({
tableState: z.object({ tableState: z.object({
@@ -46,6 +48,8 @@ export const tableSchema = z.object({
) )
return { return {
heading: data.heading,
preamble: data.preamble,
columns, columns,
rows, rows,
totalWidth, totalWidth,