-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
256 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as React from 'react'; | ||
import { Theme, useTheme } from '@mui/material/styles'; | ||
import OutlinedInput from '@mui/material/OutlinedInput'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import Select, { SelectChangeEvent } from '@mui/material/Select'; | ||
|
||
const ITEM_HEIGHT = 48; | ||
const ITEM_PADDING_TOP = 8; | ||
const MenuProps = { | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, | ||
width: 250, | ||
}, | ||
}, | ||
}; | ||
|
||
const faculties = [ | ||
'Matemaattis-luonnontieteellinen', | ||
'Humanistinen', | ||
'Oikeustieteellinen', | ||
]; | ||
|
||
const getStyles = (faculty: string, facultyName: readonly string[], theme: Theme) => { | ||
return { | ||
fontWeight: facultyName.includes(faculty) | ||
? theme.typography.fontWeightMedium | ||
: theme.typography.fontWeightRegular, | ||
}; | ||
} | ||
|
||
const FacultySelectComponent = () => { | ||
const theme = useTheme(); | ||
const [facultyName, setPersonName] = React.useState<string[]>([]); | ||
|
||
const handleChange = (event: SelectChangeEvent<typeof facultyName>) => { | ||
const { | ||
target: { value }, | ||
} = event; | ||
setPersonName( | ||
// On autofill we get a stringified value. | ||
typeof value === 'string' ? value.split(',') : value, | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormControl sx={{ width: 250 }}> | ||
<Select | ||
multiple | ||
displayEmpty | ||
value={facultyName} | ||
onChange={handleChange} | ||
input={<OutlinedInput />} | ||
renderValue={(selected) => { | ||
if (selected.length === 0) { | ||
return <em>Placeholder</em>; | ||
} | ||
|
||
return selected.join(', '); | ||
}} | ||
MenuProps={MenuProps} | ||
inputProps={{ 'aria-label': 'Without label' }} | ||
> | ||
<MenuItem disabled value=""> | ||
<em>Placeholder</em> | ||
</MenuItem> | ||
{faculties.map((faculty) => ( | ||
<MenuItem | ||
key={faculty} | ||
value={faculty} | ||
style={getStyles(faculty, facultyName, theme)} | ||
> | ||
{faculty} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
|
||
export default FacultySelectComponent |
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,83 @@ | ||
import * as React from 'react'; | ||
import { Theme, useTheme } from '@mui/material/styles'; | ||
import OutlinedInput from '@mui/material/OutlinedInput'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import Select, { SelectChangeEvent } from '@mui/material/Select'; | ||
|
||
const ITEM_HEIGHT = 48; | ||
const ITEM_PADDING_TOP = 8; | ||
const MenuProps = { | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, | ||
width: 250, | ||
}, | ||
}, | ||
}; | ||
|
||
const levels = [ | ||
'Kandi', | ||
'Maisteri', | ||
]; | ||
|
||
const getStyles = (level: string, levelName: readonly string[], theme: Theme) => { | ||
return { | ||
fontWeight: levelName.includes(level) | ||
? theme.typography.fontWeightMedium | ||
: theme.typography.fontWeightRegular, | ||
}; | ||
} | ||
|
||
const LevelSelectComponent = () => { | ||
const theme = useTheme(); | ||
const [levelName, setLevelName] = React.useState<string[]>([]); | ||
|
||
const handleChange = (event: SelectChangeEvent<typeof levelName>) => { | ||
const { | ||
target: { value }, | ||
} = event; | ||
setLevelName( | ||
// On autofill we get a stringified value. | ||
typeof value === 'string' ? value.split(',') : value, | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormControl sx={{ width: 250 }}> | ||
<Select | ||
// multiple | ||
displayEmpty | ||
value={levelName} | ||
onChange={handleChange} | ||
input={<OutlinedInput />} | ||
renderValue={(selected) => { | ||
if (selected.length === 0) { | ||
return <em>Placeholder</em>; | ||
} | ||
|
||
return selected.join(', '); | ||
}} | ||
MenuProps={MenuProps} | ||
inputProps={{ 'aria-label': 'Without label' }} | ||
> | ||
<MenuItem disabled value=""> | ||
<em>Placeholder</em> | ||
</MenuItem> | ||
{levels.map((level) => ( | ||
<MenuItem | ||
key={level} | ||
value={level} | ||
style={getStyles(level, levelName, theme)} | ||
> | ||
{level} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
|
||
export default LevelSelectComponent |
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,83 @@ | ||
import * as React from 'react'; | ||
import { Theme, useTheme } from '@mui/material/styles'; | ||
import OutlinedInput from '@mui/material/OutlinedInput'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import Select, { SelectChangeEvent } from '@mui/material/Select'; | ||
|
||
const ITEM_HEIGHT = 48; | ||
const ITEM_PADDING_TOP = 8; | ||
const MenuProps = { | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, | ||
width: 250, | ||
}, | ||
}, | ||
}; | ||
|
||
const years = [ | ||
'2024', | ||
'2025', | ||
]; | ||
|
||
const getStyles = (year: string, personName: readonly string[], theme: Theme) => { | ||
return { | ||
fontWeight: personName.includes(year) | ||
? theme.typography.fontWeightMedium | ||
: theme.typography.fontWeightRegular, | ||
}; | ||
} | ||
|
||
const YearSelectComponent = () => { | ||
const theme = useTheme(); | ||
const [personName, setPersonName] = React.useState<string[]>([]); | ||
|
||
const handleChange = (event: SelectChangeEvent<typeof personName>) => { | ||
const { | ||
target: { value }, | ||
} = event; | ||
setPersonName( | ||
// On autofill we get a stringified value. | ||
typeof value === 'string' ? value.split(',') : value, | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormControl sx={{ width: 200 }}> | ||
<Select | ||
multiple | ||
displayEmpty | ||
value={personName} | ||
onChange={handleChange} | ||
input={<OutlinedInput />} | ||
renderValue={(selected) => { | ||
if (selected.length === 0) { | ||
return <em>Placeholder</em>; | ||
} | ||
|
||
return selected.join(', '); | ||
}} | ||
MenuProps={MenuProps} | ||
inputProps={{ 'aria-label': 'Without label' }} | ||
> | ||
<MenuItem disabled value=""> | ||
<em>Select year</em> | ||
</MenuItem> | ||
{years.map((year) => ( | ||
<MenuItem | ||
key={year} | ||
value={year} | ||
style={getStyles(year, personName, theme)} | ||
> | ||
{year} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
|
||
export default YearSelectComponent |
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