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:
Matilda Landström
2025-08-20 09:41:54 +00:00
parent 7891ae3ae6
commit fe376c63f7
9 changed files with 58 additions and 66 deletions

View File

@@ -12,7 +12,6 @@ import Table from "@scandic-hotels/design-system/Table"
import SectionContainer from "@/components/Section/Container" import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header" import SectionHeader from "@/components/Section/Header"
import ScrollWrapper from "@/components/TempDesignSystem/ScrollWrapper"
import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton" import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
import styles from "./table.module.css" import styles from "./table.module.css"
@@ -56,50 +55,45 @@ export default function TableBlock({ data }: TableBlockProps) {
<SectionContainer> <SectionContainer>
<SectionHeader preamble={preamble} title={heading} /> <SectionHeader preamble={preamble} title={heading} />
<div className={styles.tableWrapper}> <div className={styles.tableWrapper}>
<ScrollWrapper> <Table
<Table width={`${totalWidth}%`}
width={`${totalWidth}%`} variant="content"
variant="content" intent="striped"
intent="striped" layout="fixed"
layout="fixed" borderRadius="none"
borderRadius="none" >
> {hasHeader ? (
{hasHeader ? ( <Table.THead>
<Table.THead> {table.getHeaderGroups().map((headerGroup) => (
{table.getHeaderGroups().map((headerGroup) => ( <Table.TR key={headerGroup.id}>
<Table.TR key={headerGroup.id}> {headerGroup.headers.map((header) => (
{headerGroup.headers.map((header) => ( <Table.TH
<Table.TH key={header.id}
key={header.id} width={`${header.column.columnDef.size}%`}
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}>
{flexRender( {flexRender(
cell.column.columnDef.cell, header.column.columnDef.header,
cell.getContext() header.getContext()
)} )}
</Table.TD> </Table.TH>
))} ))}
</Table.TR> </Table.TR>
))} ))}
</Table.TBody> </Table.THead>
</Table> ) : null}
</ScrollWrapper>
<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 ? ( {showMoreVisible ? (
<ShowMoreButton <ShowMoreButton
loadMoreData={handleShowMore} loadMoreData={handleShowMore}

View File

@@ -11,11 +11,11 @@ import {
useState, useState,
} from "react" } from "react"
import useScrollShadows from "@scandic-hotels/common/hooks/useScrollShadows"
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition" import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
import { StickyElementNameEnum } from "@scandic-hotels/common/stores/sticky-position" import { StickyElementNameEnum } from "@scandic-hotels/common/stores/sticky-position"
import { Typography } from "@scandic-hotels/design-system/Typography" import { Typography } from "@scandic-hotels/design-system/Typography"
import useScrollShadows from "@/hooks/useScrollShadows"
import useScrollSpy from "@/hooks/useScrollSpy" import useScrollSpy from "@/hooks/useScrollSpy"
import { trackHotelTabClick } from "@/utils/tracking" import { trackHotelTabClick } from "@/utils/tracking"

View File

@@ -2,11 +2,10 @@
import { cx } from "class-variance-authority" import { cx } from "class-variance-authority"
import useScrollShadows from "@scandic-hotels/common/hooks/useScrollShadows"
import { ChipButton } from "@scandic-hotels/design-system/ChipButton" import { ChipButton } from "@scandic-hotels/design-system/ChipButton"
import IconByCSSelect from "@scandic-hotels/design-system/Icons/IconByCSSelect" import IconByCSSelect from "@scandic-hotels/design-system/Icons/IconByCSSelect"
import useScrollShadows from "@/hooks/useScrollShadows"
import styles from "./tabFilters.module.css" import styles from "./tabFilters.module.css"
interface Filter { interface Filter {

View File

@@ -1,2 +0,0 @@
export interface ScrollWrapperProps
extends React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>> {}

View File

@@ -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 useScrollShadows from '@scandic-hotels/common/hooks/useScrollShadows'
import type { ScrollWrapperProps } from "./scrollWrapper"
export default function ScrollWrapper({ export default function ScrollWrapper({
className, className,
children, children,
}: ScrollWrapperProps) { }: React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>) {
const { containerRef, showLeftShadow, showRightShadow } = const { containerRef, showLeftShadow, showRightShadow } =
useScrollShadows<HTMLDivElement>() useScrollShadows<HTMLDivElement>()
@@ -23,7 +21,7 @@ export default function ScrollWrapper({
if (showRightShadow) { if (showRightShadow) {
cls.push(styles.rightShadow) cls.push(styles.rightShadow)
} }
return cls.join(" ") return cls.join(' ')
}, [showLeftShadow, showRightShadow, className]) }, [showLeftShadow, showRightShadow, className])
return ( return (

View File

@@ -5,7 +5,7 @@
.scrollWrapper::before, .scrollWrapper::before,
.scrollWrapper::after { .scrollWrapper::after {
content: ""; content: '';
position: absolute; position: absolute;
top: 0; top: 0;
height: 100%; height: 100%;

View File

@@ -6,6 +6,7 @@ import TR from './TR'
import { tableVariants } from './variants' import { tableVariants } from './variants'
import type { TableProps } from './table' import type { TableProps } from './table'
import ScrollWrapper from './ScrollWrapper'
function Table({ function Table({
className, className,
@@ -26,9 +27,11 @@ function Table({
}) })
return ( return (
<table className={classNames} style={{ width }} {...props}> <ScrollWrapper>
{children} <table className={classNames} style={{ width }} {...props}>
</table> {children}
</table>
</ScrollWrapper>
) )
} }

View File

@@ -14,16 +14,16 @@
} }
.tr:not(:last-of-type) { .tr:not(:last-of-type) {
border-bottom: 1px solid var(--Base-Border-Subtle); border-bottom: 1px solid var(--Border-Default);
} }
.th { .th {
padding: var(--Spacing-x2); padding: var(--Space-x2);
text-align: left; text-align: left;
} }
.td { .td {
padding: var(--Spacing-x2); padding: var(--Space-x2);
} }
.fixed { .fixed {
@@ -41,26 +41,26 @@
} }
.content .thead { .content .thead {
background-color: var(--Base-Surface-Subtle-Hover); background-color: var(--Surface-Secondary-Hover);
} }
.content .tbody { .content .tbody {
background-color: var(--Background-Primary); background-color: var(--Surface-Primary-OnSurface-Default);
} }
.content.striped .tbody .tr:nth-child(odd) { .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) { .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) { @media screen and (min-width: 768px) {
.th { .th {
padding: var(--Spacing-x2) var(--Spacing-x3); padding: var(--Space-x2) var(--Space-x3);
} }
.td { .td {
padding: var(--Spacing-x3); padding: var(--Space-x3);
} }
} }