Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mim 1974 fix table component #1263

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/bundle.css
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ a {
font-stretch: normal;
font-weight: normal;
line-height: 1.75rem;
min-width: 992px;
width: 100%;
border-collapse: collapse;
border: 1px solid #274247;
}
Expand All @@ -2257,6 +2257,11 @@ a {
max-width: 998px;
}
}
@media screen and (max-width: 767px) {
.ssb-table-wrapper .ssb-table .caption-text-wrapper {
max-width: none;
}
}
.ssb-table-wrapper .ssb-table th,
.ssb-table-wrapper .ssb-table td {
text-align: left;
Expand Down Expand Up @@ -2307,7 +2312,6 @@ a {
.ssb-table-wrapper .ssb-table caption .caption-wrapper .caption-text-wrapper {
font-weight: bold;
text-align: left;
width: 998px;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
Expand All @@ -2317,10 +2321,6 @@ a {
position: sticky;
right: 40px;
left: 40px;
visibility: hidden;
}
.ssb-table-wrapper .ssb-table caption .caption-wrapper .scroll-icon-wrapper.visible {
visibility: visible;
}
.ssb-table-wrapper .ssb-table caption .caption-wrapper .scroll-icon {
cursor: pointer;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statisticsnorway/ssb-component-library",
"version": "2.2.11",
"version": "2.2.12",
"description": "Component library for SSB (Statistics Norway)",
"main": "lib/bundle.js",
"scripts": {
Expand Down
70 changes: 0 additions & 70 deletions src/components/Table/__snapshots__/table.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,76 +18,6 @@ exports[`Render Table component Matches the snapshot 1`] = `
>
Table caption
</div>
<div
class="scroll-icon-wrapper "
>
<div
aria-label="Scroll left"
class="scroll-icon "
role="button"
tabindex="-1"
>
<svg
fill="none"
height="24"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="12"
cy="12"
r="10"
/>
<polyline
points="12 8 8 12 12 16"
/>
<line
x1="16"
x2="8"
y1="12"
y2="12"
/>
</svg>
</div>
<div
aria-label="Scroll right"
class="scroll-icon "
role="button"
tabindex="-1"
>
<svg
fill="none"
height="24"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="12"
cy="12"
r="10"
/>
<polyline
points="12 16 16 12 12 8"
/>
<line
x1="8"
x2="16"
y1="12"
y2="12"
/>
</svg>
</div>
</div>
</div>
</caption>
<thead>
Expand Down
16 changes: 7 additions & 9 deletions src/components/Table/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.ssb-table {
@include roboto;
line-height: 1.75rem;
min-width: $desktop-screen; // We need a fixed width for overflow-x to work
width: 100%;
border-collapse: collapse;
border: 1px solid variables.$ssb-dark-5;

Expand All @@ -28,10 +28,14 @@
}
}

.caption-text-wrapper{
.caption-text-wrapper {
@media #{$desktop} {
max-width: 998px;
}

@media #{$mobile} {
max-width: none;
}
}

th,
Expand Down Expand Up @@ -87,7 +91,6 @@
.caption-text-wrapper {
font-weight: bold;
text-align: left;
width: 998px;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
Expand All @@ -98,11 +101,6 @@
position: sticky;
right: 40px;
left: 40px;
visibility: hidden;

&.visible {
visibility: visible;
}
}

.scroll-icon {
Expand Down Expand Up @@ -267,4 +265,4 @@
stroke: var(--ssb-dark-5);
transition: stroke 0.16s;
}
}
}
46 changes: 24 additions & 22 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,37 @@ const Table = forwardRef<HTMLTableElement, TableProps>(({ className, caption, da

return (
<div className={`ssb-table-wrapper${isOverflowing ? ' overflowing' : ''}`} ref={tableWrapperRef}>
<table className={`ssb-table${className ? ` ${className}` : ''}`} ref={ref}>
<table className={`ssb-table${className ?? ''}`} ref={ref}>
{caption && (
<caption data-noterefs={dataNoteRefs}>
<div className='caption-wrapper' style={{ position: 'relative' }}>
<div className='caption-text-wrapper' ref={captionRef}>
{caption}
</div>
<div className={`scroll-icon-wrapper ${isOverflowing ? 'visible' : ''}`} ref={iconWrapperRef}>
<div
className={`scroll-icon ${isActive.left ? 'scroll-icon-active' : ''}`}
role='button'
aria-label='Scroll left'
tabIndex={isOverflowing ? 0 : -1}
onClick={() => handleMouseClick('left')}
onKeyDown={(event) => handleKeyPress(event, 'left')}
>
<ArrowLeftCircle />
{isOverflowing && (
<div className='scroll-icon-wrapper' ref={iconWrapperRef}>
<div
className={`scroll-icon ${isActive.left ? 'scroll-icon-active' : ''}`}
role='button'
aria-label='Scroll left'
tabIndex={0}
onClick={() => handleMouseClick('left')}
onKeyDown={(event) => handleKeyPress(event, 'left')}
>
<ArrowLeftCircle />
</div>
<div
className={`scroll-icon ${isActive.right ? 'scroll-icon-active' : ''}`}
role='button'
aria-label='Scroll right'
tabIndex={0}
onClick={() => handleMouseClick('right')}
onKeyDown={(event) => handleKeyPress(event, 'right')}
>
<ArrowRightCircle />
</div>
</div>
<div
className={`scroll-icon ${isActive.right ? 'scroll-icon-active' : ''}`}
role='button'
aria-label='Scroll right'
tabIndex={isOverflowing ? 0 : -1}
onClick={() => handleMouseClick('right')}
onKeyDown={(event) => handleKeyPress(event, 'right')}
>
<ArrowRightCircle />
</div>
</div>
)}
</div>
</caption>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Table/table.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
}

export const Default = () => (
<div style={{ padding: '4rem' }}>
<div style={{ width: '740px', padding: '4rem' }}>
<Table>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -38,7 +38,7 @@ export const Default = () => (
)

export const Statistics = () => (
<div style={{ padding: '4rem' }}>
<div style={{ width: '740px', padding: '4rem' }}>
<Table caption='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non pretium felis. Aenean eu ipsum in magna auctor porta. Donec vestibulum nulla vel laoreet blandit.'>
<TableHead>
<TableRow>
Expand Down