-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventSelector.tsx
More file actions
59 lines (55 loc) · 1.45 KB
/
EventSelector.tsx
File metadata and controls
59 lines (55 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import clsx from 'clsx';
import { IconButton } from '@mui/material';
import { makeStyles } from '@mui/styles';
import { EventId } from '@wca/helpers';
const useStyles = makeStyles(() => ({
root: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
},
iconButtonOn: {
color: 'blue',
},
iconButtonOff: {
color: 'gray',
},
}));
interface EventSelectorProps {
eventIds: EventId[];
value: EventId[];
onChange: (eventIds: EventId[]) => void;
styleOverrides?: {
root?: React.CSSProperties;
};
}
/**
* Shows a list of events and allows the user to checkbox select the events
*/
const EventSelector = ({ eventIds, value, onChange, styleOverrides }: EventSelectorProps) => {
const classes = useStyles();
return (
<div className={classes.root} style={styleOverrides?.root}>
{eventIds.map((eventId) => (
<IconButton
key={eventId}
className={clsx(
`cubing-icon event-${eventId}`,
value.indexOf(eventId) > -1 ? classes.iconButtonOn : classes.iconButtonOff
)}
style={{ fontSize: '1.5em' }}
onClick={() => {
if (value.indexOf(eventId) > -1) {
// toggle off
onChange(value.filter((e) => e !== eventId));
} else {
// toggle on
onChange([...value, eventId]);
}
}}
/>
))}
</div>
);
};
export default EventSelector;