This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored feature toggles table (#951)
* refactor: simplify table toolbar * refactor: table links and padding * fix: header icons colors * fix: minor table style changes
- Loading branch information
Showing
34 changed files
with
598 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { FC } from 'react'; | ||
import { Box, Table as MUITable } from '@mui/material'; | ||
|
||
export const Table: FC = ({ children }) => ( | ||
<Box sx={{ p: 4, pb: 0 }}> | ||
<MUITable>{children}</MUITable> | ||
</Box> | ||
); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { makeStyles } from 'tss-react/mui'; | ||
|
||
export const useStyles = makeStyles()(theme => ({ | ||
tableCell: { | ||
padding: 0, | ||
}, | ||
})); |
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,9 @@ | ||
import { FC } from 'react'; | ||
import { TableCell as MUITableCell, TableCellProps } from '@mui/material'; | ||
import { useStyles } from './TableCell.styles'; | ||
|
||
export const TableCell: FC<TableCellProps> = ({ ...props }) => { | ||
const { classes: styles } = useStyles(); | ||
|
||
return <MUITableCell className={styles.tableCell} {...props} />; | ||
}; |
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
15 changes: 15 additions & 0 deletions
15
src/component/common/Table/TableContainer/TableContainer.tsx
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 @@ | ||
import { forwardRef } from 'react'; | ||
import { Paper, PaperProps } from '@mui/material'; | ||
import { useStyles } from './TableContainer.styles'; | ||
|
||
export const TableContainer = forwardRef<HTMLDivElement, PaperProps>( | ||
({ children, ...props }, ref) => { | ||
const { classes } = useStyles(); | ||
|
||
return ( | ||
<Paper ref={ref} className={classes.panel} {...props}> | ||
{children} | ||
</Paper> | ||
); | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
src/component/common/Table/TableSearch/TableSearch.styles.ts
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,59 @@ | ||
import { makeStyles } from 'tss-react/mui'; | ||
|
||
export const useStyles = makeStyles()(theme => ({ | ||
searchField: { | ||
width: '45px', | ||
'& .search-icon': { | ||
marginRight: 0, | ||
}, | ||
'& .input-container, .clear-container': { | ||
width: 0, | ||
}, | ||
'& input::placeholder': { | ||
color: 'transparent', | ||
transition: 'color 0.6s', | ||
}, | ||
'& input:focus-within::placeholder': { | ||
color: theme.palette.text.primary, | ||
}, | ||
}, | ||
searchFieldEnter: { | ||
width: '250px', | ||
transition: 'width 0.6s', | ||
'& .search-icon': { | ||
marginRight: '8px', | ||
}, | ||
'& .input-container': { | ||
width: '100%', | ||
transition: 'width 0.6s', | ||
}, | ||
'& .clear-container': { | ||
width: '30px', | ||
transition: 'width 0.6s', | ||
}, | ||
'& .search-container': { | ||
borderColor: theme.palette.grey[300], | ||
}, | ||
}, | ||
searchFieldLeave: { | ||
width: '45px', | ||
transition: 'width 0.6s', | ||
'& .search-icon': { | ||
marginRight: 0, | ||
transition: 'margin-right 0.6s', | ||
}, | ||
'& .input-container, .clear-container': { | ||
width: 0, | ||
transition: 'width 0.6s', | ||
}, | ||
'& .search-container': { | ||
borderColor: 'transparent', | ||
}, | ||
}, | ||
searchButton: { | ||
marginTop: '-4px', | ||
marginBottom: '-4px', | ||
marginRight: '-4px', | ||
marginLeft: '-4px', | ||
}, | ||
})); |
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,75 @@ | ||
import { FC, useState } from 'react'; | ||
import { IconButton, Tooltip } from '@mui/material'; | ||
import { Search } from '@mui/icons-material'; | ||
import { useAsyncDebounce } from 'react-table'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import AnimateOnMount from 'component/common/AnimateOnMount/AnimateOnMount'; | ||
import { TableSearchField } from './TableSearchField/TableSearchField'; | ||
import { useStyles } from './TableSearch.styles'; | ||
|
||
interface ITableSearchProps { | ||
initialValue?: string; | ||
onChange?: (value: string) => void; | ||
placeholder?: string; | ||
} | ||
|
||
export const TableSearch: FC<ITableSearchProps> = ({ | ||
initialValue, | ||
onChange = () => {}, | ||
placeholder = 'Search', | ||
}) => { | ||
const [searchInputState, setSearchInputState] = useState(initialValue); | ||
const [isSearchExpanded, setIsSearchExpanded] = useState( | ||
Boolean(initialValue) | ||
); | ||
const [isAnimating, setIsAnimating] = useState(false); | ||
const debouncedOnSearch = useAsyncDebounce(onChange, 200); | ||
|
||
const { classes: styles } = useStyles(); | ||
|
||
const onBlur = (clear = false) => { | ||
if (!searchInputState || clear) { | ||
setIsSearchExpanded(false); | ||
} | ||
}; | ||
|
||
const onSearchChange = (value: string) => { | ||
debouncedOnSearch(value); | ||
setSearchInputState(value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<AnimateOnMount | ||
mounted={isSearchExpanded} | ||
start={styles.searchField} | ||
enter={styles.searchFieldEnter} | ||
leave={styles.searchFieldLeave} | ||
onStart={() => setIsAnimating(true)} | ||
onEnd={() => setIsAnimating(false)} | ||
> | ||
<TableSearchField | ||
value={searchInputState!} | ||
onChange={onSearchChange} | ||
placeholder={`${placeholder}…`} | ||
onBlur={onBlur} | ||
/> | ||
</AnimateOnMount> | ||
<ConditionallyRender | ||
condition={!isSearchExpanded && !isAnimating} | ||
show={ | ||
<Tooltip title={placeholder} arrow> | ||
<IconButton | ||
aria-label={placeholder} | ||
onClick={() => setIsSearchExpanded(true)} | ||
size="large" | ||
className={styles.searchButton} | ||
> | ||
<Search /> | ||
</IconButton> | ||
</Tooltip> | ||
} | ||
/> | ||
</> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/component/common/Table/TableSearch/TableSearchField/TableSearchField.styles.ts
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 { makeStyles } from 'tss-react/mui'; | ||
|
||
export const useStyles = makeStyles()(theme => ({ | ||
container: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexWrap: 'wrap', | ||
gap: '1rem', | ||
}, | ||
search: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
backgroundColor: theme.palette.background.paper, | ||
border: `1px solid ${theme.palette.grey[300]}`, | ||
borderRadius: '25px', | ||
padding: '3px 5px 3px 12px', | ||
maxWidth: '450px', | ||
[theme.breakpoints.down('sm')]: { | ||
width: '100%', | ||
}, | ||
'&.search-container:focus-within': { | ||
borderColor: theme.palette.primary.light, | ||
boxShadow: theme.boxShadows.main, | ||
}, | ||
}, | ||
searchIcon: { | ||
marginRight: 8, | ||
color: theme.palette.grey[600], | ||
}, | ||
clearContainer: { | ||
width: '30px', | ||
'& > button': { | ||
padding: '7px', | ||
}, | ||
}, | ||
clearIcon: { | ||
color: theme.palette.grey[600], | ||
fontSize: '18px', | ||
}, | ||
inputRoot: { | ||
width: '100%', | ||
}, | ||
})); |
73 changes: 73 additions & 0 deletions
73
src/component/common/Table/TableSearch/TableSearchField/TableSearchField.tsx
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,73 @@ | ||
import { IconButton, InputBase, Tooltip } from '@mui/material'; | ||
import { Search, Close } from '@mui/icons-material'; | ||
import classnames from 'classnames'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import { useStyles } from './TableSearchField.styles'; | ||
|
||
interface ITableSearchFieldProps { | ||
value: string; | ||
onChange: (value: string) => void; | ||
className?: string; | ||
placeholder: string; | ||
onBlur?: (clear?: boolean) => void; | ||
} | ||
|
||
export const TableSearchField = ({ | ||
value = '', | ||
onChange, | ||
className, | ||
placeholder, | ||
onBlur, | ||
}: ITableSearchFieldProps) => { | ||
const { classes: styles } = useStyles(); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div | ||
className={classnames( | ||
styles.search, | ||
className, | ||
'search-container' | ||
)} | ||
> | ||
<Search | ||
className={classnames(styles.searchIcon, 'search-icon')} | ||
/> | ||
<InputBase | ||
autoFocus | ||
placeholder={placeholder} | ||
classes={{ | ||
root: classnames(styles.inputRoot, 'input-container'), | ||
}} | ||
inputProps={{ 'aria-label': placeholder }} | ||
value={value} | ||
onChange={e => onChange(e.target.value)} | ||
onBlur={() => onBlur?.()} | ||
/> | ||
<div | ||
className={classnames( | ||
styles.clearContainer, | ||
'clear-container' | ||
)} | ||
> | ||
<ConditionallyRender | ||
condition={Boolean(value)} | ||
show={ | ||
<Tooltip title="Clear search query" arrow> | ||
<IconButton | ||
size="small" | ||
onClick={() => { | ||
onChange(''); | ||
onBlur?.(true); | ||
}} | ||
> | ||
<Close className={styles.clearIcon} /> | ||
</IconButton> | ||
</Tooltip> | ||
} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.