-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reverts 8a555fe to add support for sticky heading. this is added through an optional prop, and exposing a css variable to be able to set the background color of the head. this defaults to the Jøkul background color
- Loading branch information
Jo Emil Holen
committed
Nov 30, 2022
1 parent
63eaa51
commit 604bfd0
Showing
6 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { FC } from "react"; | ||
import { ExampleComponentProps } from "../../../doc-utils"; | ||
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "../src"; | ||
|
||
const columns = ["Dato", "Saksnummer", "Kundenummer", "Kundenavn", "Milepæl", "Følger saken"]; | ||
|
||
const rows = [ | ||
["24.02.2020", "20-1234567", "010203 99887", "Ola Nordmann", "Opprettet", "Siri Saksbehandler"], | ||
["13.04.2019", "20-8382811", "010203 99887", "Kari Nordkvinne", "Opprettet", "Siri Saksbehandler"], | ||
["31.07.2017", "20-1111", "010203 99887", "Kari Nordkvinne", "Opprettet", "Per Persen"], | ||
["24.02.2020", "20-1234567", "010203 99887", "Ola Nordmann", "Opprettet", "Siri Saksbehandler"], | ||
["13.04.2019", "20-8382811", "010203 99887", "Kari Nordkvinne", "Opprettet", "Siri Saksbehandler"], | ||
["31.07.2017", "20-1111", "010203 99887", "Kari Nordkvinne", "Opprettet", "Per Persen"], | ||
["24.02.2020", "20-1234567", "010203 99887", "Ola Nordmann", "Opprettet", "Siri Saksbehandler"], | ||
["13.04.2019", "20-8382811", "010203 99887", "Kari Nordkvinne", "Opprettet", "Siri Saksbehandler"], | ||
["31.07.2017", "20-1111", "010203 99887", "Kari Nordkvinne", "Opprettet", "Per Persen"], | ||
["24.02.2020", "20-1234567", "010203 99887", "Ola Nordmann", "Opprettet", "Siri Saksbehandler"], | ||
["13.04.2019", "20-8382811", "010203 99887", "Kari Nordkvinne", "Opprettet", "Siri Saksbehandler"], | ||
["31.07.2017", "20-1111", "010203 99887", "Kari Nordkvinne", "Opprettet", "Per Persen"], | ||
]; | ||
|
||
const StickyTableExample: FC<ExampleComponentProps> = ({ boolValues, choiceValues }) => { | ||
const headless = boolValues?.["Skjul overskrift"]; | ||
const type = choiceValues?.["Mobilvisning"]; | ||
const props = type === "Liste" ? { "data-collapse": "true", collapseToList: true } : {}; | ||
|
||
return ( | ||
<Table fullWidth {...props} style={{ height: "100px" }}> | ||
<TableCaption srOnly>Overskrift for skjermlesere</TableCaption> | ||
<TableHead srOnly={headless} sticky> | ||
<TableRow> | ||
{columns.map((column, index) => ( | ||
<TableHeader key={index} density="compact" bold> | ||
{column} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, rowIndex) => ( | ||
<TableRow key={rowIndex}> | ||
{row.map((cell, cellIndex) => ( | ||
<TableCell | ||
key={cellIndex} | ||
data-th={columns[cellIndex]} | ||
align={[1, 2].includes(cellIndex) ? "right" : "left"} | ||
> | ||
{cell} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); | ||
}; | ||
|
||
export default StickyTableExample; | ||
|
||
export const stickyTableExampleCode = ({ boolValues, choiceValues }: ExampleComponentProps): string => ` | ||
<Table fullWidth collapseToList={${choiceValues?.["Mobilvisning"] === "Liste"}}> | ||
<TableCaption srOnly>Overskrift for skjermlesere</TableCaption> | ||
<TableHead srOnly={${boolValues?.["Skjul overskrift"]}}> | ||
<TableRow> | ||
{columns.map((header, index) => ( | ||
<TableHeader key={index} density="compact" bold> | ||
{header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, rowIndex) => ( | ||
<TableRow key={rowIndex}> | ||
{row.map((cell, cellIndex) => ( | ||
<TableCell | ||
key={cellIndex} | ||
data-th={columns[cellIndex]} | ||
align={[1, 2].includes(cellIndex) ? "right" : "left"} | ||
> | ||
{cell} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
@use "~@fremtind/jkl-core/jkl"; | ||
|
||
@include jkl.light-mode-variables { | ||
--jkl-table-head-sticky-color: var(--jkl-background-color); | ||
} | ||
|
||
@include jkl.dark-mode-variables { | ||
--jkl-table-head-sticky-color: var(--jkl-background-color); | ||
} | ||
|
||
.jkl-table-head { | ||
&--sr-only { | ||
@include jkl.screenreader-only; | ||
} | ||
|
||
&--sticky { | ||
& > .jkl-table-row { | ||
position: sticky; | ||
top: 0; | ||
z-index: 1; | ||
background-color: var(--jkl-table-head-sticky-color); | ||
} | ||
} | ||
} |