Skip to content

Commit 2116765

Browse files
authored
Merge pull request #477 from mashmatrix/support-slds-2-table
Update `Table` for SLDS2
2 parents ba01c75 + e8dfc9d commit 2116765

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

src/scripts/Table.tsx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const TableRow: FC<TableRowProps> = (props) => {
102102
}
103103
const rowClassName = classnames(
104104
className,
105-
header ? 'slds-text-title_caps' : 'slds-hint-parent'
105+
header ? 'slds-line-height_reset' : 'slds-hint-parent'
106106
);
107107
const style = selected
108108
? {
@@ -130,7 +130,7 @@ export type TableHeaderColumnProps = {
130130
sorted?: boolean;
131131
align?: 'left' | 'center' | 'right';
132132
onSort?: () => void;
133-
} & ThHTMLAttributes<HTMLTableHeaderCellElement>;
133+
} & ThHTMLAttributes<HTMLTableCellElement>;
134134

135135
/**
136136
*
@@ -152,7 +152,6 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
152152
const sortable = typeof sortable_ === 'undefined' ? rowSortable : sortable_;
153153
const oClassNames = classnames(
154154
className,
155-
'slds-text-title_caps slds-truncate',
156155
{
157156
'slds-is-sortable': sortable,
158157
'slds-is-resizable': resizable,
@@ -165,8 +164,15 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
165164

166165
const icon = sortDir === 'DESC' ? 'arrowdown' : 'arrowup';
167166

167+
const content = typeof children === 'string' ? children : undefined;
168+
const cellContent = (
169+
<div className='slds-truncate' title={content}>
170+
{children}
171+
</div>
172+
);
173+
168174
return (
169-
<th {...pprops} className={oClassNames} scope='col' style={style}>
175+
<th {...pprops} className={oClassNames} style={style}>
170176
{sortable ? (
171177
<a
172178
onClick={(e) => {
@@ -178,24 +184,18 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
178184
className='slds-th__action slds-text-link_reset'
179185
>
180186
<span className='slds-assistive-text'>Sort </span>
181-
<span className='slds-truncate'>{children}</span>
187+
{cellContent}
182188
<Icon
189+
container
183190
className='slds-is-sortable__icon'
184191
textColor='default'
185-
container
186192
size='x-small'
187193
category='utility'
188194
icon={icon}
189-
style={{ position: 'absolute' }}
190-
/>
191-
<span
192-
className='slds-assistive-text'
193-
aria-live='assertive'
194-
aria-atomic='true'
195195
/>
196196
</a>
197197
) : (
198-
children
198+
cellContent
199199
)}
200200
</th>
201201
);
@@ -207,23 +207,35 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
207207
export type TableRowColumnProps = {
208208
width?: string | number;
209209
truncate?: boolean;
210-
} & TdHTMLAttributes<HTMLTableDataCellElement>;
210+
} & TdHTMLAttributes<HTMLTableCellElement>;
211211

212212
/**
213213
*
214214
*/
215215
export const TableRowColumn: FC<TableRowColumnProps> = (props) => {
216-
const { truncate = true, className, width, children, ...pprops } = props;
217-
const oClassNames = classnames(className, {
218-
'slds-truncate': truncate,
219-
});
216+
const {
217+
truncate = true,
218+
className: oClassNames,
219+
width,
220+
children,
221+
...pprops
222+
} = props;
220223
const style: CSSProperties = {};
221224
if (width !== undefined) style.width = width;
222225
if (!truncate) style.position = 'static';
223226

224-
return (
225-
<td role='gridcell' style={style} className={oClassNames} {...pprops}>
227+
const content = typeof children === 'string' ? children : undefined;
228+
const cellContent = truncate ? (
229+
<div className='slds-truncate' title={content}>
226230
{children}
231+
</div>
232+
) : (
233+
children
234+
);
235+
236+
return (
237+
<td style={style} className={oClassNames} {...pprops}>
238+
{cellContent}
227239
</td>
228240
);
229241
};
@@ -274,17 +286,15 @@ export const Table: FC<TableProps> = (props) => {
274286
...rprops
275287
} = props;
276288

277-
const tableClassNames = classnames(
278-
className,
279-
'slds-table slds-table_cell-buffer',
280-
{
281-
'slds-table_bordered': bordered,
282-
'slds-no-row-hover': noRowHover,
283-
'slds-table_striped': striped,
284-
'slds-table_fixed-layout': fixedLayout,
285-
'slds-table_col-bordered': verticalBorders,
286-
}
287-
);
289+
const tableClassNames = classnames(className, 'slds-table', {
290+
'slds-table_bordered': bordered,
291+
'slds-no-row-hover': noRowHover,
292+
'slds-table_striped': striped,
293+
'slds-table_fixed-layout': fixedLayout,
294+
'slds-table_resizable-cols': sortable,
295+
'slds-table_cell-buffer': !sortable,
296+
'slds-table_col-bordered': verticalBorders,
297+
});
288298

289299
const style: CSSProperties = { ...style_ };
290300
if (autoWidth) {

0 commit comments

Comments
 (0)