Merged in feat/SW-2847-table (pull request #2665)
fix(SW-2847): move ScrollWrapper to design system and Table component * fix(SW-2847): move ScrollWrapper to design system and Table component Approved-by: Erik Tiekstra
This commit is contained in:
@@ -12,7 +12,6 @@ import Table from "@scandic-hotels/design-system/Table"
|
||||
|
||||
import SectionContainer from "@/components/Section/Container"
|
||||
import SectionHeader from "@/components/Section/Header"
|
||||
import ScrollWrapper from "@/components/TempDesignSystem/ScrollWrapper"
|
||||
import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
|
||||
|
||||
import styles from "./table.module.css"
|
||||
@@ -56,50 +55,45 @@ export default function TableBlock({ data }: TableBlockProps) {
|
||||
<SectionContainer>
|
||||
<SectionHeader preamble={preamble} title={heading} />
|
||||
<div className={styles.tableWrapper}>
|
||||
<ScrollWrapper>
|
||||
<Table
|
||||
width={`${totalWidth}%`}
|
||||
variant="content"
|
||||
intent="striped"
|
||||
layout="fixed"
|
||||
borderRadius="none"
|
||||
>
|
||||
{hasHeader ? (
|
||||
<Table.THead>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<Table.TR key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<Table.TH
|
||||
key={header.id}
|
||||
width={`${header.column.columnDef.size}%`}
|
||||
>
|
||||
{flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</Table.TH>
|
||||
))}
|
||||
</Table.TR>
|
||||
))}
|
||||
</Table.THead>
|
||||
) : null}
|
||||
|
||||
<Table.TBody>
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<Table.TR key={row.id}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<Table.TD key={cell.id}>
|
||||
<Table
|
||||
width={`${totalWidth}%`}
|
||||
variant="content"
|
||||
intent="striped"
|
||||
layout="fixed"
|
||||
borderRadius="none"
|
||||
>
|
||||
{hasHeader ? (
|
||||
<Table.THead>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<Table.TR key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<Table.TH
|
||||
key={header.id}
|
||||
width={`${header.column.columnDef.size}%`}
|
||||
>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext()
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</Table.TD>
|
||||
</Table.TH>
|
||||
))}
|
||||
</Table.TR>
|
||||
))}
|
||||
</Table.TBody>
|
||||
</Table>
|
||||
</ScrollWrapper>
|
||||
</Table.THead>
|
||||
) : null}
|
||||
|
||||
<Table.TBody>
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<Table.TR key={row.id}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<Table.TD key={cell.id}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</Table.TD>
|
||||
))}
|
||||
</Table.TR>
|
||||
))}
|
||||
</Table.TBody>
|
||||
</Table>
|
||||
{showMoreVisible ? (
|
||||
<ShowMoreButton
|
||||
loadMoreData={handleShowMore}
|
||||
|
||||
@@ -11,11 +11,11 @@ import {
|
||||
useState,
|
||||
} from "react"
|
||||
|
||||
import useScrollShadows from "@scandic-hotels/common/hooks/useScrollShadows"
|
||||
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
|
||||
import { StickyElementNameEnum } from "@scandic-hotels/common/stores/sticky-position"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import useScrollShadows from "@/hooks/useScrollShadows"
|
||||
import useScrollSpy from "@/hooks/useScrollSpy"
|
||||
import { trackHotelTabClick } from "@/utils/tracking"
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import { cx } from "class-variance-authority"
|
||||
|
||||
import useScrollShadows from "@scandic-hotels/common/hooks/useScrollShadows"
|
||||
import { ChipButton } from "@scandic-hotels/design-system/ChipButton"
|
||||
import IconByCSSelect from "@scandic-hotels/design-system/Icons/IconByCSSelect"
|
||||
|
||||
import useScrollShadows from "@/hooks/useScrollShadows"
|
||||
|
||||
import styles from "./tabFilters.module.css"
|
||||
|
||||
interface Filter {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export interface ScrollWrapperProps
|
||||
extends React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>> {}
|
||||
@@ -1,17 +1,15 @@
|
||||
"use client"
|
||||
'use client'
|
||||
|
||||
import { useMemo } from "react"
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import useScrollShadows from "@/hooks/useScrollShadows"
|
||||
import styles from './scrollWrapper.module.css'
|
||||
|
||||
import styles from "./scrollWrapper.module.css"
|
||||
|
||||
import type { ScrollWrapperProps } from "./scrollWrapper"
|
||||
import useScrollShadows from '@scandic-hotels/common/hooks/useScrollShadows'
|
||||
|
||||
export default function ScrollWrapper({
|
||||
className,
|
||||
children,
|
||||
}: ScrollWrapperProps) {
|
||||
}: React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>) {
|
||||
const { containerRef, showLeftShadow, showRightShadow } =
|
||||
useScrollShadows<HTMLDivElement>()
|
||||
|
||||
@@ -23,7 +21,7 @@ export default function ScrollWrapper({
|
||||
if (showRightShadow) {
|
||||
cls.push(styles.rightShadow)
|
||||
}
|
||||
return cls.join(" ")
|
||||
return cls.join(' ')
|
||||
}, [showLeftShadow, showRightShadow, className])
|
||||
|
||||
return (
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
.scrollWrapper::before,
|
||||
.scrollWrapper::after {
|
||||
content: "";
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
@@ -6,6 +6,7 @@ import TR from './TR'
|
||||
import { tableVariants } from './variants'
|
||||
|
||||
import type { TableProps } from './table'
|
||||
import ScrollWrapper from './ScrollWrapper'
|
||||
|
||||
function Table({
|
||||
className,
|
||||
@@ -26,9 +27,11 @@ function Table({
|
||||
})
|
||||
|
||||
return (
|
||||
<table className={classNames} style={{ width }} {...props}>
|
||||
{children}
|
||||
</table>
|
||||
<ScrollWrapper>
|
||||
<table className={classNames} style={{ width }} {...props}>
|
||||
{children}
|
||||
</table>
|
||||
</ScrollWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
}
|
||||
|
||||
.tr:not(:last-of-type) {
|
||||
border-bottom: 1px solid var(--Base-Border-Subtle);
|
||||
border-bottom: 1px solid var(--Border-Default);
|
||||
}
|
||||
|
||||
.th {
|
||||
padding: var(--Spacing-x2);
|
||||
padding: var(--Space-x2);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.td {
|
||||
padding: var(--Spacing-x2);
|
||||
padding: var(--Space-x2);
|
||||
}
|
||||
|
||||
.fixed {
|
||||
@@ -41,26 +41,26 @@
|
||||
}
|
||||
|
||||
.content .thead {
|
||||
background-color: var(--Base-Surface-Subtle-Hover);
|
||||
background-color: var(--Surface-Secondary-Hover);
|
||||
}
|
||||
|
||||
.content .tbody {
|
||||
background-color: var(--Background-Primary);
|
||||
background-color: var(--Surface-Primary-OnSurface-Default);
|
||||
}
|
||||
|
||||
.content.striped .tbody .tr:nth-child(odd) {
|
||||
background-color: var(--Base-Surface-Subtle-Normal);
|
||||
background-color: var(--Surface-Secondary-Default);
|
||||
}
|
||||
.content.striped .tbody .tr:nth-child(even) {
|
||||
background-color: var(--Background-Primary);
|
||||
background-color: var(--Surface-Primary-OnSurface-Default);
|
||||
}
|
||||
|
||||
@media screen and (min-width: 768px) {
|
||||
.th {
|
||||
padding: var(--Spacing-x2) var(--Spacing-x3);
|
||||
padding: var(--Space-x2) var(--Space-x3);
|
||||
}
|
||||
|
||||
.td {
|
||||
padding: var(--Spacing-x3);
|
||||
padding: var(--Space-x3);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user