-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored code to reduce number of props for ItemTableSortButtons co…
…mponent; added prop types to ItemTableSortButtons; renamed folder to use same naming convention
- Loading branch information
Showing
6 changed files
with
104 additions
and
61 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
31 changes: 0 additions & 31 deletions
31
src/components/ItemTableSortButtons.js/ItemTableSortButtons.js
This file was deleted.
Oops, something went wrong.
Empty file.
43 changes: 43 additions & 0 deletions
43
src/components/ItemTableSortButtons/ItemTableSortButtons.js
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import PropTypes from "prop-types"; | ||
import { ButtonGroup, IconButton } from "@material-ui/core"; | ||
import { ArrowDownward, ArrowUpward } from "@material-ui/icons"; | ||
|
||
export default function ItemTableSortButtons({ sortDirection, sortAscArrowProps, sortDescArrowProps }) { | ||
return ( | ||
<ButtonGroup orientation="vertical" size="small"> | ||
<IconButton edge="start"> | ||
<ArrowUpward | ||
{...sortAscArrowProps} | ||
// Inherit fontsize from containing element to avoid overflow. | ||
fontSize="inherit" | ||
color={sortDirection === 'asc' ? "secondary" : "default"} | ||
/> | ||
</IconButton> | ||
<IconButton edge="start"> | ||
<ArrowDownward | ||
{...sortDescArrowProps} | ||
// Inherit fontsize from containing element to avoid overflow. | ||
fontSize="inherit" | ||
color={sortDirection === 'desc' ? "secondary" : "default"} | ||
/> | ||
</IconButton> | ||
</ButtonGroup> | ||
) | ||
} | ||
|
||
ItemTableSortButtons.propTypes = { | ||
/** String representing sort direction. */ | ||
"sortDirection": PropTypes.oneOf(['asc', 'desc', undefined ]), | ||
/** Props passed to ArrowUpward component. */ | ||
"sortAscArrowProps": PropTypes.object, | ||
/** Props passed to ArrowDownward component. */ | ||
"sortDescArrowProps": PropTypes.object | ||
}; | ||
|
||
ItemTableSortButtons.defaultProps = { | ||
"sortDirection": undefined, | ||
"sortAscArrowProps": { onClick: _ => alert("No onClick function set. This does nothing.") }, | ||
"sortDescArrowProps": { onClick: _ => alert("No onClick function set. This does nothing.") } | ||
}; | ||
|
15 changes: 15 additions & 0 deletions
15
src/components/ItemTableSortButtons/ItemTableSortButtons.md
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The ItemTableSortButtons are used to sort in ascending or descending order based on which button is selected. It is to be used with the [ItemTable](/#/Components/ItemTable). | ||
|
||
```jsx | ||
import React, { useState, useEffect } from "react"; | ||
|
||
|
||
|
||
|
||
|
||
<ItemTableSortButtons/> | ||
``` | ||
|
||
```jsx static | ||
<ItemTableSortButtons sortDirection="directionOfSort" sortAscArrowProps={someProps} sortDescArrowProps={someProps}/> | ||
``` |
File renamed without changes.