Skip to content

Commit

Permalink
feat: legg til støtte for å midtstille tekst i celle og header
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo Emil Holen committed Jan 23, 2024
1 parent 7369e4d commit 9e82d87
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/table-react/src/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface TableCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
* Velg mellom venstrejustering og høyrejustering av innholdet. Typisk skal innholdet være venstrejustert, men for eksempel summer er høyrejustert.
* @default "left"
*/
align?: "left" | "right";
align?: "left" | "center" | "right";
/**
* Velg mellom vertikal sentrering av innholdet eller toppjustering. Typisk skal innholdet være toppjustert, men dersom raden har knapper kan midtstilling fungere bedre.
* @default "top"
Expand All @@ -24,7 +24,8 @@ const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
<td
className={cx("jkl-table-cell", className, {
["jkl-table-cell--align-right"]: align === "right",
["jkl-table-cell--align-center"]: verticalAlign === "center",
["jkl-table-cell--align-center"]: align === "center",
["jkl-table-cell--vertical-align-center"]: verticalAlign === "center",
})}
{...rest}
data-density={density || contextDensity}
Expand Down
3 changes: 2 additions & 1 deletion packages/table-react/src/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TableHeaderProps extends ThHTMLAttributes<HTMLTableCellElement>
* Velg mellom venstrejustering og høyrejustering av innholdet. Typisk skal header følge innholdet i radene.
* @default "left"
*/
align?: "left" | "right";
align?: "left" | "center" | "right";
/**
* Si om headeren gjelder for en kolonne eller en rad
* @default "col"
Expand Down Expand Up @@ -49,6 +49,7 @@ const TableHeader = forwardRef<HTMLTableCellElement, TableHeaderProps>((props, r
className={cn("jkl-table-header", className, {
["jkl-table-header--bold"]: bold,
["jkl-table-header--align-right"]: align === "right",
["jkl-table-header--align-center"]: align === "center",
["jkl-table-header--sr-only"]: srOnly,
["jkl-table-header--sortable"]: typeof sortable !== "undefined",
})}
Expand Down
6 changes: 5 additions & 1 deletion packages/table/_table-cell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
text-align: left;
vertical-align: top;

&--align-center {
&--vertical-align-center {
vertical-align: baseline;
}

&--align-center {
text-align: center;
}

&--align-right {
text-align: right;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/table/_table-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
text-align: left;
white-space: nowrap;

&--align-center {
text-align: center;
}

&--align-right {
text-align: right;
}
Expand Down

0 comments on commit 9e82d87

Please sign in to comment.