|
|
|
@ -1,34 +1,55 @@ |
|
|
|
|
import React from 'react'; |
|
|
|
|
import FormControlLabel from '@material-ui/core/FormControlLabel'; |
|
|
|
|
import Checkbox from '@material-ui/core/Checkbox'; |
|
|
|
|
import React from "react"; |
|
|
|
|
import FormControlLabel from "@material-ui/core/FormControlLabel"; |
|
|
|
|
import Checkbox from "@material-ui/core/Checkbox"; |
|
|
|
|
|
|
|
|
|
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; |
|
|
|
|
import CheckBoxIcon from '@material-ui/icons/CheckBox'; |
|
|
|
|
import CloseIcon from '@material-ui/icons/Close'; |
|
|
|
|
import CheckBoxOutlineBlankIcon from "@material-ui/icons/CheckBoxOutlineBlank"; |
|
|
|
|
import CheckBoxIcon from "@material-ui/icons/CheckBox"; |
|
|
|
|
import CloseIcon from "@material-ui/icons/Close"; |
|
|
|
|
|
|
|
|
|
import './index.scss'; |
|
|
|
|
import "./index.scss"; |
|
|
|
|
|
|
|
|
|
const maxDesktopSize = 1250; |
|
|
|
|
|
|
|
|
|
const fontSize = { |
|
|
|
|
h2 : window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85, |
|
|
|
|
h2: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85, |
|
|
|
|
strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
export default class TypicalFilters extends React.Component { |
|
|
|
|
onChange = (name, data) => { |
|
|
|
|
if (name === "subject") { |
|
|
|
|
this.props.parent.setState((prevState) => ({ |
|
|
|
|
selectedFilters: { |
|
|
|
|
...prevState.selectedFilters, |
|
|
|
|
subject: |
|
|
|
|
prevState.selectedFilters.subject.indexOf(data) !== -1 |
|
|
|
|
? prevState.selectedFilters.subject.filter(item => item !== data) |
|
|
|
|
: [...new Set([...prevState.selectedFilters.subject, data])], |
|
|
|
|
}, |
|
|
|
|
})); |
|
|
|
|
}else if(name === "level"){ |
|
|
|
|
this.props.parent.setState((prevState) => ({ |
|
|
|
|
selectedFilters: { |
|
|
|
|
...prevState.selectedFilters, |
|
|
|
|
level: |
|
|
|
|
prevState.selectedFilters.level.indexOf(data) !== -1 |
|
|
|
|
? prevState.selectedFilters.level.filter(item => item !== data) |
|
|
|
|
: [...new Set([...prevState.selectedFilters.level, data])], |
|
|
|
|
}, |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
render() { |
|
|
|
|
const {data, title, theme} = this.props; |
|
|
|
|
return( |
|
|
|
|
const { data, title, theme, name, parent } = this.props; |
|
|
|
|
return ( |
|
|
|
|
<div className="products-filters-typical d-flex flex-column"> |
|
|
|
|
<header className="products-filters-typical__header d-flex align-items-center"> |
|
|
|
|
<span style={{ background : theme }}></span> |
|
|
|
|
<h2 style={{ fontSize : fontSize.h2 }}>{title}</h2> |
|
|
|
|
<span style={{ background: theme }}></span> |
|
|
|
|
<h2 style={{ fontSize: fontSize.h2 }}>{title}</h2> |
|
|
|
|
</header> |
|
|
|
|
<div className="products-filters-typical__items d-flex flex-column"> |
|
|
|
|
{ |
|
|
|
|
data.map((item,i) => ( |
|
|
|
|
<Item data={item} key={i} /> |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
{data.map((item, i) => ( |
|
|
|
|
<Item data={item} key={i} parent={this} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
@ -36,14 +57,30 @@ export default class TypicalFilters extends React.Component { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Item = (props) => { |
|
|
|
|
const {data} = props; |
|
|
|
|
return( |
|
|
|
|
const { data, parent } = props; |
|
|
|
|
const checkHandler = (data, name) => { |
|
|
|
|
var available; |
|
|
|
|
if(name === "subject"){ |
|
|
|
|
available = props.parent.props.parent.state.selectedFilters.subject.indexOf(data) !== -1 ? true : false; |
|
|
|
|
}else if(name === "level"){ |
|
|
|
|
available = props.parent.props.parent.state.selectedFilters.level.indexOf(data) !== -1 ? true : false; |
|
|
|
|
} |
|
|
|
|
return available; |
|
|
|
|
} |
|
|
|
|
return ( |
|
|
|
|
<div className="d-flex align-items-center mt-2"> |
|
|
|
|
<FormControlLabel |
|
|
|
|
control={<Checkbox icon={<CheckBoxOutlineBlankIcon style={{ color: '#EAEAEA' }} />} checkedIcon={<CheckBoxIcon style={{ color: '#00CC69' }} />} name="checkedH" />} |
|
|
|
|
label="" |
|
|
|
|
control={ |
|
|
|
|
<Checkbox |
|
|
|
|
icon={<CheckBoxOutlineBlankIcon style={{ color: "#EAEAEA" }} />} |
|
|
|
|
checkedIcon={<CheckBoxIcon style={{ color: "#00CC69" }} />} |
|
|
|
|
name="checkedH" |
|
|
|
|
/> |
|
|
|
|
} |
|
|
|
|
checked={checkHandler(data,parent.props.name)} |
|
|
|
|
onChange={() => parent.onChange(parent.props.name, data)} |
|
|
|
|
/> |
|
|
|
|
<strong style={{ fontSize: fontSize.strong }}>{data}</strong> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|