-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(table): support custom sort icon #5243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
00e60f1
feat(shared-icons): add SortIcon
wingkwong 6e7a18d
feat(table): add CustomSortIcon story
wingkwong f70e93c
feat(table): support custom sort icon
wingkwong 4577504
fix(table): handle functional sortIcon
wingkwong 5744336
chore(changeset): add changeset
wingkwong ed6cf17
Merge branch 'canary' into feat/eng-2436
wingkwong b2206d0
chore(table): update type
wingkwong 7e1a3bc
feat(docs): add sortIcon to table
wingkwong 7093d64
fix(docs): broken object
wingkwong aca3ccb
Merge branch 'canary' into feat/eng-2436
wingkwong b7d7ee7
chore(shared-icons): lint
wingkwong 79ae0d7
Merge branch 'beta/release-next' into feat/eng-2436
wingkwong 343ebe0
feat(docs): add example for sort icon
wingkwong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@heroui/shared-icons": patch | ||
| "@heroui/table": patch | ||
| --- | ||
|
|
||
| support custom sort icon in Table (#5223) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| Table, | ||
| TableHeader, | ||
| TableColumn, | ||
| TableBody, | ||
| TableRow, | ||
| TableCell, | ||
| getKeyValue, | ||
| Spinner, | ||
| } from "@heroui/react"; | ||
| import {SortIcon} from "@heroui/shared-icons"; | ||
| import {useAsyncList} from "@react-stately/data"; | ||
| import {useState} from "react"; | ||
|
|
||
| type SWCharacter = { | ||
| name: string; | ||
| height: string; | ||
| mass: string; | ||
| birth_year: string; | ||
| }; | ||
|
|
||
| export default function Page() { | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| let list = useAsyncList<SWCharacter>({ | ||
| async load({signal}) { | ||
| let res = await fetch(`https://swapi.py4e.com/api/people/?search`, { | ||
| signal, | ||
| }); | ||
| let json = await res.json(); | ||
|
|
||
| setIsLoading(false); | ||
|
|
||
| return { | ||
| items: json.results, | ||
| }; | ||
| }, | ||
| async sort({items, sortDescriptor}) { | ||
| return { | ||
| items: items.sort((a, b) => { | ||
| let first = a[sortDescriptor.column as keyof SWCharacter]; | ||
| let second = b[sortDescriptor.column as keyof SWCharacter]; | ||
| let cmp = (parseInt(first) || first) < (parseInt(second) || second) ? -1 : 1; | ||
|
|
||
| if (sortDescriptor.direction === "descending") { | ||
| cmp *= -1; | ||
| } | ||
|
|
||
| return cmp; | ||
| }), | ||
| }; | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="p-6"> | ||
| <Table | ||
| aria-label="Example table with client side sorting" | ||
| classNames={{ | ||
| table: "min-h-[400px]", | ||
| }} | ||
| sortDescriptor={list.sortDescriptor} | ||
| sortIcon={SortIcon} | ||
| onSortChange={list.sort} | ||
| > | ||
| <TableHeader> | ||
| <TableColumn key="name" allowsSorting> | ||
| Name | ||
| </TableColumn> | ||
| <TableColumn key="height" allowsSorting> | ||
| Height | ||
| </TableColumn> | ||
| <TableColumn key="mass" allowsSorting> | ||
| Mass | ||
| </TableColumn> | ||
| <TableColumn key="birth_year" allowsSorting> | ||
| Birth year | ||
| </TableColumn> | ||
| </TableHeader> | ||
| <TableBody | ||
| isLoading={isLoading} | ||
| items={list.items} | ||
| loadingContent={<Spinner label="Loading..." />} | ||
| > | ||
| {(item) => ( | ||
| <TableRow key={item.name}> | ||
| {(columnKey) => <TableCell>{getKeyValue(item, columnKey)}</TableCell>} | ||
| </TableRow> | ||
| )} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { | ||
| Table, | ||
| TableHeader, | ||
| TableColumn, | ||
| TableBody, | ||
| TableRow, | ||
| TableCell, | ||
| getKeyValue, | ||
| Spinner, | ||
| } from "@heroui/react"; | ||
| import {SortIcon} from "@heroui/shared-icons"; | ||
| import {useAsyncList} from "@react-stately/data"; | ||
|
|
||
| export default function App() { | ||
| const [isLoading, setIsLoading] = React.useState(true); | ||
|
|
||
| let list = useAsyncList({ | ||
| async load({signal}) { | ||
| let res = await fetch("https://swapi.py4e.com/api/people/?search", { | ||
| signal, | ||
| }); | ||
| let json = await res.json(); | ||
|
|
||
| setIsLoading(false); | ||
|
|
||
| return { | ||
| items: json.results, | ||
| }; | ||
| }, | ||
| async sort({items, sortDescriptor}) { | ||
| return { | ||
| items: items.sort((a, b) => { | ||
| let first = a[sortDescriptor.column]; | ||
| let second = b[sortDescriptor.column]; | ||
| let cmp = (parseInt(first) || first) < (parseInt(second) || second) ? -1 : 1; | ||
|
|
||
| if (sortDescriptor.direction === "descending") { | ||
| cmp *= -1; | ||
| } | ||
|
|
||
| return cmp; | ||
| }), | ||
| }; | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <Table | ||
| aria-label="Example table with client side sorting" | ||
| classNames={{ | ||
| table: "min-h-[400px]", | ||
| }} | ||
| sortDescriptor={list.sortDescriptor} | ||
| sortIcon={SortIcon} | ||
| onSortChange={list.sort} | ||
| > | ||
| <TableHeader> | ||
| <TableColumn key="name" allowsSorting> | ||
| Name | ||
| </TableColumn> | ||
| <TableColumn key="height" allowsSorting> | ||
| Height | ||
| </TableColumn> | ||
| <TableColumn key="mass" allowsSorting> | ||
| Mass | ||
| </TableColumn> | ||
| <TableColumn key="birth_year" allowsSorting> | ||
| Birth year | ||
| </TableColumn> | ||
| </TableHeader> | ||
| <TableBody | ||
| isLoading={isLoading} | ||
| items={list.items} | ||
| loadingContent={<Spinner label="Loading..." />} | ||
| > | ||
| {(item) => ( | ||
| <TableRow key={item.name}> | ||
| {(columnKey) => <TableCell>{getKeyValue(item, columnKey)}</TableCell>} | ||
| </TableRow> | ||
| )} | ||
| </TableBody> | ||
| </Table> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./sort-icon.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.