Skip to content

Commit

Permalink
Fix table sort icon
Browse files Browse the repository at this point in the history
  • Loading branch information
2-towns committed Nov 6, 2024
1 parent 8894bce commit ef4b081
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 68 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/codex-storage/codex-marketplace-ui-components"
},
"version": "0.0.38",
"version": "0.0.39",
"type": "module",
"scripts": {
"prepack": "npm run build",
Expand Down
19 changes: 19 additions & 0 deletions src/assets/icons/asc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/assets/icons/desc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions src/components/Table/SortIcon.css

This file was deleted.

46 changes: 0 additions & 46 deletions src/components/Table/SortIcon.tsx

This file was deleted.

27 changes: 14 additions & 13 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import "./table.css";
import {
ComponentType,
Fragment,
ReactElement,
ReactNode,
useEffect,
useState,
} from "react";
import { Fragment, ReactElement, ReactNode, useEffect, useState } from "react";
import { classnames } from "../utils/classnames";
import { attributes } from "../utils/attributes";
import AscIcon from "../../assets/icons/asc.svg?react";
import DescIcon from "../../assets/icons/desc.svg?react";

export type TabSortState = "asc" | "desc" | null;

Expand All @@ -29,8 +24,6 @@ type Props = {
className?: string;

rows: ReactElement<RowProps, typeof Row>[];

SortIcon: ComponentType;
};

const nextState = (state: "asc" | "desc" | null) =>
Expand All @@ -39,7 +32,6 @@ const nextState = (state: "asc" | "desc" | null) =>
export function Table({
headers,
rows,
SortIcon,
defaultSortIndex = -1,
className = "",
}: Props) {
Expand Down Expand Up @@ -92,7 +84,11 @@ export function Table({
? {
role: "button",
"aria-sort":
state === "asc" ? "ascending" : "descending",
state === "asc"
? "ascending"
: state == null
? ""
: "descending",
}
: {}
)}
Expand All @@ -104,7 +100,12 @@ export function Table({
>
<div>
<span>{name}</span>
{sort && <SortIcon />}
{sort && (
<span className="sort-icon">
<AscIcon />
<DescIcon />
</span>
)}
</div>
</th>
);
Expand Down
6 changes: 6 additions & 0 deletions src/components/Table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
box-sizing: border-box;
background-color: #232323;

.sort-icon {
display: flex;
flex-direction: column;
gap: 0;
}

&[role="button"] {
cursor: pointer;
}
Expand Down
2 changes: 1 addition & 1 deletion stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const Sort: Story = {
]}
></Row>,
],
headers: [["id"], ["title"], ["other", () => {}], ["actions"]],
headers: [["id"], ["title", () => {}], ["other", () => {}], ["actions"]],
defaultSortIndex: 2,
},
};
Expand Down

0 comments on commit ef4b081

Please sign in to comment.