Skip to content

Commit

Permalink
Table cell align right (#182)
Browse files Browse the repository at this point in the history
* Add right alignment for Table data cell content

* Fix th styling for right alignment

* .
  • Loading branch information
johnnadeluy authored Mar 26, 2024
1 parent 2d35e3d commit 5e96e65
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
return <ArrowUp className={selectedColumn ? styles.displayArrowOnSelectedColumn : undefined} size={18} />
}

const alignCell = (alignment?: string) => {
if (alignment === 'center') return styles.alignTextCenter
if (alignment === 'right') return styles.alignTextRight
return ''
}

return (
<div className={styles.tableContainer}>
<table className={styles.table}>
Expand All @@ -131,7 +137,7 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
return (
<th
key={column.id}
className={sortableColumn ? styles.sortableColumn : undefined}
className={`${sortableColumn ? styles.sortableColumn : undefined} ${alignCell(column.align)}`}
onClick={sortableColumn ? () => handleSortBy(column.id) : undefined}
>
{sortableColumn ? (
Expand All @@ -153,7 +159,7 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
return (
<tr key={row.id + index} className={conditionalStyling(index)}>
{columns.map((column) => (
<td key={column.id} className={column.align === 'center' ? styles.centerText : undefined}>
<td key={column.id} className={alignCell(column.align)}>
{row[column.id]}
</td>
))}
Expand Down
20 changes: 16 additions & 4 deletions src/components/Table/table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
span {
display: inline-block;
position: relative;
padding-right: 30px;
padding-right: 2rem;
white-space: nowrap;

svg {
position: absolute;
top: 50%;
right: 5px;
right: .5rem;
transform: translateY(-50%);
display: none;
}
Expand Down Expand Up @@ -117,7 +117,7 @@
padding: .5rem;
border-bottom: 1px inset variables.$ssb-dark-2;

>* {
> * {
display: flex;
flex-direction: column;

Expand All @@ -140,9 +140,21 @@
}
}

.centerText {
.alignTextCenter {
span {
display: flex;
justify-content: center;
}
}

.alignTextRight {
text-align: right !important;

span {
padding-right: 0 !important;

svg {
left: -1.75rem;
}
}
}
2 changes: 1 addition & 1 deletion src/pages/TeamDetail/TeamDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const SHARED_BUCKETS_TAB = {
label: 'Tilgang',
},
// { id: 'delte_data', label: 'Delte data' },
{ id: 'antall_personer', label: 'Antall personer' },
{ id: 'antall_personer', label: 'Antall personer', align: 'right' },
],
}

Expand Down
2 changes: 2 additions & 0 deletions src/pages/TeamMembers/TeamMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ const TeamMembers = () => {
{
id: 'team',
label: 'Team',
align: 'right',
},
{
id: 'data_admin',
label: 'Data-admin roller',
align: 'right',
},
{
id: 'seksjonsleder',
Expand Down
1 change: 1 addition & 0 deletions src/pages/TeamOverview/TeamOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const TeamOverview = () => {
{
id: 'teammedlemmer',
label: 'Teammedlemmer',
align: 'right',
},
{
id: 'managers',
Expand Down

0 comments on commit 5e96e65

Please sign in to comment.