Skip to content

Commit 5e96e65

Browse files
authored
Table cell align right (#182)
* Add right alignment for Table data cell content * Fix th styling for right alignment * .
1 parent 2d35e3d commit 5e96e65

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

src/components/Table/Table.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
121121
return <ArrowUp className={selectedColumn ? styles.displayArrowOnSelectedColumn : undefined} size={18} />
122122
}
123123

124+
const alignCell = (alignment?: string) => {
125+
if (alignment === 'center') return styles.alignTextCenter
126+
if (alignment === 'right') return styles.alignTextRight
127+
return ''
128+
}
129+
124130
return (
125131
<div className={styles.tableContainer}>
126132
<table className={styles.table}>
@@ -131,7 +137,7 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
131137
return (
132138
<th
133139
key={column.id}
134-
className={sortableColumn ? styles.sortableColumn : undefined}
140+
className={`${sortableColumn ? styles.sortableColumn : undefined} ${alignCell(column.align)}`}
135141
onClick={sortableColumn ? () => handleSortBy(column.id) : undefined}
136142
>
137143
{sortableColumn ? (
@@ -153,7 +159,7 @@ const TableDesktopView = ({ columns, data, activeTab }: TableDesktopViewProps) =
153159
return (
154160
<tr key={row.id + index} className={conditionalStyling(index)}>
155161
{columns.map((column) => (
156-
<td key={column.id} className={column.align === 'center' ? styles.centerText : undefined}>
162+
<td key={column.id} className={alignCell(column.align)}>
157163
{row[column.id]}
158164
</td>
159165
))}

src/components/Table/table.module.scss

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@
7878
span {
7979
display: inline-block;
8080
position: relative;
81-
padding-right: 30px;
81+
padding-right: 2rem;
8282
white-space: nowrap;
8383

8484
svg {
8585
position: absolute;
8686
top: 50%;
87-
right: 5px;
87+
right: .5rem;
8888
transform: translateY(-50%);
8989
display: none;
9090
}
@@ -117,7 +117,7 @@
117117
padding: .5rem;
118118
border-bottom: 1px inset variables.$ssb-dark-2;
119119

120-
>* {
120+
> * {
121121
display: flex;
122122
flex-direction: column;
123123

@@ -140,9 +140,21 @@
140140
}
141141
}
142142

143-
.centerText {
143+
.alignTextCenter {
144144
span {
145145
display: flex;
146146
justify-content: center;
147147
}
148+
}
149+
150+
.alignTextRight {
151+
text-align: right !important;
152+
153+
span {
154+
padding-right: 0 !important;
155+
156+
svg {
157+
left: -1.75rem;
158+
}
159+
}
148160
}

src/pages/TeamDetail/TeamDetail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const SHARED_BUCKETS_TAB = {
8585
label: 'Tilgang',
8686
},
8787
// { id: 'delte_data', label: 'Delte data' },
88-
{ id: 'antall_personer', label: 'Antall personer' },
88+
{ id: 'antall_personer', label: 'Antall personer', align: 'right' },
8989
],
9090
}
9191

src/pages/TeamMembers/TeamMembers.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ const TeamMembers = () => {
111111
{
112112
id: 'team',
113113
label: 'Team',
114+
align: 'right',
114115
},
115116
{
116117
id: 'data_admin',
117118
label: 'Data-admin roller',
119+
align: 'right',
118120
},
119121
{
120122
id: 'seksjonsleder',

src/pages/TeamOverview/TeamOverview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const TeamOverview = () => {
9898
{
9999
id: 'teammedlemmer',
100100
label: 'Teammedlemmer',
101+
align: 'right',
101102
},
102103
{
103104
id: 'managers',

0 commit comments

Comments
 (0)