generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ryanchua00/question-tagging-updated
Add Question Filtering
- Loading branch information
Showing
9 changed files
with
421 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// FilterBar.tsx | ||
import * as React from 'react'; | ||
import FilterSelector from './FilterSelector'; // Import your FilterSelector component | ||
import { Box } from '@mui/material'; | ||
|
||
interface FilterBarProps { | ||
categoryOptions: { value: number; label: string }[]; | ||
difficultyOptions: { value: number; label: string }[]; | ||
onApplyFilters: (selectedCategories: string[], selectedDifficulties: string[]) => void; // Update types here | ||
onResetFilters: () => void; | ||
} | ||
|
||
const FilterBar: React.FC<FilterBarProps> = ({ | ||
categoryOptions, | ||
difficultyOptions, | ||
onApplyFilters, | ||
onResetFilters, | ||
}) => { | ||
const [selectedCategories, setSelectedCategories] = React.useState<string[]>([]); // Update type here | ||
const [selectedDifficulties, setSelectedDifficulties] = React.useState<string[]>([]); // Update type here | ||
|
||
const handleApplyFilters = () => { | ||
onApplyFilters(selectedCategories, selectedDifficulties); | ||
}; | ||
|
||
const handleResetFilters = () => { | ||
setSelectedCategories([]); | ||
setSelectedDifficulties([]); | ||
onResetFilters(); | ||
}; | ||
|
||
return ( | ||
<Box sx={{paddingX: 2, paddingY: 1}}> | ||
<FilterSelector options={categoryOptions} selectedValues={selectedCategories} onChange={setSelectedCategories} /> | ||
<FilterSelector options={difficultyOptions} selectedValues={selectedDifficulties} onChange={setSelectedDifficulties} /> | ||
<button onClick={handleApplyFilters}>Apply Filters</button> | ||
<button onClick={handleResetFilters}>Reset Filters</button> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default FilterBar; |
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,199 @@ | ||
import * as React from 'react'; | ||
import { | ||
Select as BaseSelect, | ||
SelectProps, | ||
selectClasses, | ||
SelectRootSlotProps, | ||
} from '@mui/base/Select'; | ||
import { Option as BaseOption, optionClasses } from '@mui/base/Option'; | ||
import { Popper as BasePopper } from '@mui/base/Popper'; | ||
import { styled } from '@mui/system'; | ||
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; | ||
|
||
interface FilterSelectorProps { | ||
options: { value: number; label: string }[]; | ||
selectedValues: string[]; // Change this line to use string[] | ||
onChange: (value: string[]) => void; // Change this line to use string[] | ||
} | ||
|
||
export default function FilterSelector({ options, selectedValues, onChange }: FilterSelectorProps) { | ||
return ( | ||
<MultiSelect value={selectedValues} onChange={(event, labels) => onChange(labels)}> | ||
{options.map((option) => ( | ||
<Option key={option.value} value={option.label}> | ||
{option.label} | ||
</Option> | ||
))} | ||
</MultiSelect> | ||
); | ||
} | ||
|
||
|
||
const MultiSelect = React.forwardRef(function CustomMultiSelect( | ||
props: SelectProps<string, true>, // Change the type to use string | ||
ref: React.ForwardedRef<any>, | ||
) { | ||
const slots: SelectProps<string, true>['slots'] = { | ||
root: Button, | ||
listbox: Listbox, | ||
popper: Popper, | ||
...props.slots, | ||
}; | ||
|
||
return <BaseSelect {...props} multiple ref={ref} slots={slots} />; | ||
}); | ||
|
||
const blue = { | ||
100: '#DAECFF', | ||
200: '#99CCF3', | ||
400: '#3399FF', | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
900: '#003A75', | ||
}; | ||
|
||
const grey = { | ||
50: '#F3F6F9', | ||
100: '#E5EAF2', | ||
200: '#DAE2ED', | ||
300: '#C7D0DD', | ||
400: '#B0B8C4', | ||
500: '#9DA8B7', | ||
600: '#6B7A90', | ||
700: '#434D5B', | ||
800: '#303740', | ||
900: '#1C2025', | ||
}; | ||
|
||
const Button = React.forwardRef(function Button< | ||
TValue extends {}, | ||
Multiple extends boolean, | ||
>( | ||
props: SelectRootSlotProps<TValue, Multiple>, | ||
ref: React.ForwardedRef<HTMLButtonElement>, | ||
) { | ||
const { ownerState, ...other } = props; | ||
return ( | ||
<StyledButton type="button" {...other} ref={ref}> | ||
{other.children} | ||
<UnfoldMoreRoundedIcon /> | ||
</StyledButton> | ||
); | ||
}); | ||
|
||
const StyledButton = styled('button', { shouldForwardProp: () => true })( | ||
({ theme }) => ` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-size: 0.875rem; | ||
box-sizing: border-box; | ||
min-width: 320px; | ||
padding: 8px 12px; | ||
border-radius: 8px; | ||
text-align: left; | ||
line-height: 1.5; | ||
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; | ||
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; | ||
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; | ||
position: relative; | ||
box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; | ||
transition-property: all; | ||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); | ||
transition-duration: 120ms; | ||
&:hover { | ||
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; | ||
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; | ||
} | ||
&.${selectClasses.focusVisible} { | ||
outline: 0; | ||
border-color: ${blue[400]}; | ||
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; | ||
} | ||
& > svg { | ||
font-size: 1rem; | ||
position: absolute; | ||
height: 100%; | ||
top: 0; | ||
right: 10px; | ||
} | ||
`, | ||
); | ||
|
||
const Listbox = styled('ul')( | ||
({ theme }) => ` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-size: 0.875rem; | ||
box-sizing: border-box; | ||
padding: 6px; | ||
margin: 12px 0; | ||
min-width: 320px; | ||
border-radius: 12px; | ||
overflow: auto; | ||
outline: 0px; | ||
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; | ||
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; | ||
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; | ||
box-shadow: 0px 2px 6px ${ | ||
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' | ||
}; | ||
`, | ||
); | ||
|
||
const Option = styled(BaseOption)( | ||
({ theme }) => ` | ||
list-style: none; | ||
padding: 8px; | ||
border-radius: 8px; | ||
cursor: default; | ||
transition: border-radius 300ms ease; | ||
&:last-of-type { | ||
border-bottom: none; | ||
} | ||
&.${optionClasses.selected} { | ||
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; | ||
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; | ||
} | ||
&.${optionClasses.highlighted} { | ||
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; | ||
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; | ||
} | ||
@supports selector(:has(*)) { | ||
&.${optionClasses.selected} { | ||
& + .${optionClasses.selected} { | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
&:has(+ .${optionClasses.selected}) { | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
} | ||
} | ||
} | ||
&.${optionClasses.highlighted}.${optionClasses.selected} { | ||
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; | ||
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; | ||
} | ||
&.${optionClasses.disabled} { | ||
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; | ||
} | ||
&:hover:not(.${optionClasses.disabled}) { | ||
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; | ||
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; | ||
} | ||
`, | ||
); | ||
|
||
const Popper = styled(BasePopper)` | ||
z-index: 1; | ||
`; |
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.