Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions .storybook/styles/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,32 @@ th {
opacity: 0.4;
}

&:hover:after {
content: '▼';
}
}

.order-ascend {
&:after {
content: '▲';
}

&:hover:after {
content: '▼';
button {
width: 100%;
cursor: pointer;
&:hover:after {
content: '▼';
}
}
}

.order-descend {
&:after {
content: '▼';
&.ascending {
button:after {
content: '▲';
}

button:hover:after {
content: '▼';
}
}

&:hover:after {
content: '▲';

&.descending {
button:after {
content: '▼';
}

button:hover:after {
content: '▲';
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions src/tables/components/table-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ function TableHeader({
onClick,
}) {
const active = sortPath === name
const arrowClass = getArrowClass(active, ascending)
const sortOrder = getSortOrder(active, ascending)
const headerProps = {}

if (active) {
headerProps['aria-sort'] = sortOrder
}

return (
<th
onClick={onClick}
className={classnames(arrowClass, { sortable: !disabled })}
className={classnames(sortOrder, { sortable: !disabled })}
{...headerProps}
>
{label || startCase(name)}
<button onClick={onClick}>{label || startCase(name)}</button>
</th>
)
}

function getArrowClass(active, ascending) {
if (!active) return ''
return ascending ? 'order-ascend' : 'order-descend'
function getSortOrder(active, ascending) {
if (!active) return undefined
return ascending ? 'ascending' : 'descending'
}

TableHeader.propTypes = propTypes
Expand Down