-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented AddQuestions modal (#1170)
* implemented AddQuestions modal * fix styles * added category filter * fix * added no items text to filter * refactored types
- Loading branch information
Showing
31 changed files
with
774 additions
and
164 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,76 @@ | ||
import palette from '~/styles/app-theme/app.pallete' | ||
import { commonHoverShadow } from '~/styles/app-theme/custom-shadows' | ||
import { TypographyVariantEnum } from '~/types' | ||
|
||
export const styles = { | ||
root: { | ||
maxWidth: { xs: '200px', md: '300px' }, | ||
backgroundColor: 'primary.50', | ||
display: 'flex', | ||
alignItems: 'center', | ||
px: '12px', | ||
borderRadius: '100px' | ||
}, | ||
openMenuBtn: { p: 0, ml: '5px' }, | ||
text: { typography: TypographyVariantEnum.Subtitle1 }, | ||
chosenFilters: { | ||
typography: TypographyVariantEnum.Subtitle1, | ||
ml: '4px', | ||
fontWeight: 500, | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
textOverflow: 'ellipsis' | ||
}, | ||
arrowIcon: (open: boolean) => ({ | ||
color: 'primary.900', | ||
transform: `rotate(${open ? 180 : 0}deg)`, | ||
transition: 'transform 0.3s ease' | ||
}), | ||
menu: (loading: boolean) => ({ | ||
'& .simplebar-content': { | ||
...(loading && { height: '216px', display: 'flex' }) | ||
} | ||
}), | ||
menuPaperProps: { | ||
style: { | ||
width: '300px', | ||
marginTop: '8px', | ||
borderRadius: '8px', | ||
boxShadow: commonHoverShadow | ||
} | ||
}, | ||
inputWrapper: { p: '15px 20px 0px 20px' }, | ||
input: { | ||
m: '0 auto', | ||
width: '100%', | ||
borderRadius: '6px', | ||
p: { xs: 0, sm: 0 }, | ||
border: `1px solid ${palette.primary[400]}`, | ||
'& > div': { pl: '10px' } | ||
}, | ||
clearAll: (isSelected: boolean) => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'end', | ||
columnGap: '3px', | ||
typography: TypographyVariantEnum.Subtitle2, | ||
...(!isSelected && { color: 'primary.200' }), | ||
...(isSelected && { cursor: 'pointer' }), | ||
m: '15px 20px 0 0' | ||
}), | ||
clearIcon: { height: '18px', width: '18px' }, | ||
divider: { | ||
border: `1px solid ${palette.primary[200]}`, | ||
mt: '8px' | ||
}, | ||
noMatches: { | ||
typography: TypographyVariantEnum.Subtitle1, | ||
p: '15px 25px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
columnGap: 1 | ||
}, | ||
scrollableContent: { maxHeight: '216px' }, | ||
loader: { color: 'primary.700' }, | ||
noItemsIcon: { color: 'primary.400' } | ||
} |
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,160 @@ | ||
import { useState, ChangeEvent, useMemo, Dispatch, SetStateAction } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import SimpleBar from 'simplebar-react' | ||
import Box from '@mui/material/Box' | ||
import Menu, { MenuProps } from '@mui/material/Menu' | ||
import MenuItem from '@mui/material/MenuItem' | ||
import { PopoverOrigin } from '@mui/material/Popover' | ||
import Divider from '@mui/material/Divider' | ||
import Checkbox from '@mui/material/Checkbox' | ||
import Typography from '@mui/material/Typography' | ||
import IconButton from '@mui/material/IconButton' | ||
import ClearIcon from '@mui/icons-material/Clear' | ||
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline' | ||
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' | ||
|
||
import useAxios from '~/hooks/use-axios' | ||
import Loader from '~/components/loader/Loader' | ||
import InputWithIcon from '~/components/input-with-icon/InputWithIcon' | ||
|
||
import { defaultResponses } from '~/constants' | ||
import { styles } from '~/components/filter-selector/FilterSelector.styles' | ||
import { ServiceFunction } from '~/types' | ||
|
||
interface FilterSelectorProps<T> extends Omit<MenuProps, 'open'> { | ||
title: string | ||
service: ServiceFunction<T[]> | ||
selectedItems: string[] | ||
setSelectedItems: Dispatch<SetStateAction<string[]>> | ||
position?: PopoverOrigin['horizontal'] | ||
} | ||
|
||
const FilterSelector = <T extends string>({ | ||
title, | ||
service, | ||
selectedItems, | ||
setSelectedItems, | ||
position = 'left', | ||
...props | ||
}: FilterSelectorProps<T>) => { | ||
const { t } = useTranslation() | ||
const [menuAnchor, setMenuAnchor] = useState<null | HTMLElement>(null) | ||
const [inputValue, setInputValue] = useState<string>('') | ||
|
||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setInputValue(e.target.value) | ||
} | ||
|
||
const handleInputReset = () => { | ||
setInputValue('') | ||
} | ||
|
||
const handleMenuOpen = () => { | ||
setMenuAnchor(document.getElementById('menu-filter')) | ||
} | ||
|
||
const handleMenuClose = () => { | ||
setMenuAnchor(null) | ||
} | ||
|
||
const onMenuItemClick = (item: string) => { | ||
if (selectedItems.includes(item)) { | ||
setSelectedItems(selectedItems.filter((selected) => selected !== item)) | ||
} else { | ||
setSelectedItems([...selectedItems, item]) | ||
} | ||
} | ||
|
||
const onClearAll = () => { | ||
selectedItems.length && setSelectedItems([]) | ||
} | ||
|
||
const { loading, response } = useAxios<T[]>({ | ||
service, | ||
defaultResponse: defaultResponses.array | ||
}) | ||
|
||
const filteredItems = useMemo( | ||
() => | ||
response.filter((item) => | ||
item.toLowerCase().includes(inputValue.toLowerCase()) | ||
), | ||
[response, inputValue] | ||
) | ||
|
||
const menuItems = filteredItems.map((item) => ( | ||
<MenuItem key={item} onClick={() => onMenuItemClick(item)} sx={styles.text}> | ||
<Checkbox checked={selectedItems.includes(item)} /> | ||
{item} | ||
</MenuItem> | ||
)) | ||
|
||
const scrollableContent = filteredItems.length ? ( | ||
menuItems | ||
) : ( | ||
<Box sx={styles.noMatches}> | ||
<ErrorOutlineIcon sx={styles.noItemsIcon} /> | ||
{t('common.noItems')} | ||
</Box> | ||
) | ||
|
||
const itemsLoad = !response.length && loading | ||
const chosenFiltersText = selectedItems.length | ||
? selectedItems.join(', ') | ||
: t('cooperationsPage.tabs.all') | ||
|
||
return ( | ||
<Box id='menu-filter' sx={styles.root}> | ||
<Typography sx={styles.text}>{title}:</Typography> | ||
<Typography sx={styles.chosenFilters}>{chosenFiltersText}</Typography> | ||
<IconButton | ||
disableRipple | ||
onClick={handleMenuOpen} | ||
sx={styles.openMenuBtn} | ||
> | ||
<KeyboardArrowDownIcon sx={styles.arrowIcon(!!menuAnchor)} /> | ||
</IconButton> | ||
|
||
<Menu | ||
PaperProps={styles.menuPaperProps} | ||
anchorEl={menuAnchor} | ||
anchorOrigin={{ vertical: 'bottom', horizontal: position }} | ||
onClose={handleMenuClose} | ||
open={!!menuAnchor} | ||
sx={styles.menu(itemsLoad)} | ||
transformOrigin={{ vertical: 'top', horizontal: position }} | ||
{...props} | ||
> | ||
<Box sx={styles.inputWrapper}> | ||
<InputWithIcon | ||
onChange={handleInputChange} | ||
onClear={handleInputReset} | ||
placeholder={t('common.search')} | ||
sx={styles.input} | ||
value={inputValue} | ||
/> | ||
</Box> | ||
|
||
<Typography | ||
onClick={onClearAll} | ||
sx={styles.clearAll(!!selectedItems.length)} | ||
> | ||
<ClearIcon sx={styles.clearIcon} /> | ||
{t('header.notifications.clearAll')} | ||
</Typography> | ||
|
||
<Divider sx={styles.divider} /> | ||
|
||
<SimpleBar style={styles.scrollableContent}> | ||
{itemsLoad ? ( | ||
<Loader pageLoad size={20} sx={styles.loader} /> | ||
) : ( | ||
scrollableContent | ||
)} | ||
</SimpleBar> | ||
</Menu> | ||
</Box> | ||
) | ||
} | ||
|
||
export default FilterSelector |
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
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
Oops, something went wrong.