-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Table sorting: added change icon when toggling ascending and descending
Adjusted sort data type on IListCell to have parameter for asc and desc sorting Adjusted useHover to be a proper hook
- Loading branch information
Showing
8 changed files
with
36 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
export const ListHeaderCell = () => { | ||
import { useState } from "react"; | ||
import useHover from "../../hooks/useHover"; | ||
import { t } from "../../utils"; | ||
import { SortIcon } from "../Icon"; | ||
|
||
type ListHeaderCellProps = { | ||
width: string | undefined | number | ||
header:string | ||
addSort: boolean, | ||
onSort?: (asc: boolean) => void | ||
} | ||
|
||
export const ListHeaderCell = ({width, header, addSort, onSort}: ListHeaderCellProps) => { | ||
const [hovered, eventHandlers] = useHover(); | ||
const [asc, setAsc] = useState<boolean | undefined>(undefined) | ||
|
||
return ( | ||
<th key={col.key} style={{width}} {...eventHandlers}> | ||
|
||
<th style={{width}} {...eventHandlers}> | ||
{header ? t(header) : <> </>} | ||
{addSort ? <><SortIcon/></> : <> </>} | ||
{addSort && hovered ? <><SortIcon fa={asc ? "fa fa-arrow-up" : "fa fa-arrow-down"} onClick={() => {setAsc(!asc); if(onSort) onSort(!asc);}} size={1}/></> : <> </>} | ||
</th> | ||
) | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
const { useState, useMemo } = React; | ||
import { useState, useMemo } from 'react'; | ||
|
||
const useHover = () => { | ||
const [hovered, setHovered] = useState<boolean>(); | ||
const useHover = () : [boolean, { onMouseOver(): void, onMouseOut(): void}] => { | ||
const [hovered, setHovered] = useState<boolean>(false); | ||
|
||
const eventHandlers = useMemo(() => ({ | ||
onMouseOver() { setHovered(true); }, | ||
onMouseOut() { setHovered(false); } | ||
}), []); | ||
|
||
return {hovered, eventHandlers}; | ||
return [hovered, eventHandlers]; | ||
} | ||
|
||
export default useHover; |
This file contains 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 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