Skip to content

Commit

Permalink
Merge pull request #96 from amosproj/revert-76-frontend-dev-#74
Browse files Browse the repository at this point in the history
Revert "Merge of Implementation of #74"
  • Loading branch information
Waldleufer authored Jun 5, 2021
2 parents 0976848 + 61878e8 commit 8e8f823
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 83 deletions.
91 changes: 80 additions & 11 deletions frontend/src/components/details/CompareVariablesComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import theme from 'resources/theme';
import DropDownComponent from 'components/dropdown/DropDownComponent';

/**
a drop down component for selecting variables
Expand All @@ -16,18 +15,72 @@ const CompareVariablesComponent = (props) => {
<h4>Select variables to compare:</h4>
</div>
<div className='w3-col l3 m3 s3 w3-left'>
<DropDownComponent
selectedVariable={state.selectedVariable}
variables={state.variables}
dropDownHandler={props.firstDropDownHandler}
/>
<div className='w3-dropdown-hover '>
<button
className='w3-button w3-2018-sailor-blue'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{state.selectedVariable}
</button>
<div
className='w3-dropdown-content w3-bar-block w3-border'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{state.variables.map((item) => (
<button
onClick={() => props.firstDropDownHandler(item.name)}
className='w3-bar-item w3-button'
key={item.id}
>
{item.name}
</button>
))}
</div>
</div>
</div>
<div className='w3-col l3 m3 s3 w3-left'>
<DropDownComponent
selectedVariable={state.secondVariable}
variables={state.variables}
dropDownHandler={props.secondDropDownHandler}
/>
<div className='w3-dropdown-hover'>
<button
className='w3-button w3-2018-sailor-blue'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{state.secondVariable}
</button>
<div
className='w3-dropdown-content w3-bar-block w3-border'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{state.variables.map((item) => (
<button
onClick={() => props.secondDropDownHandler(item.name)}
className='w3-bar-item w3-button'
key={item.id}
>
{item.name}
</button>
))}
</div>
</div>
</div>
<div className='w3-col l2 m2 s1 w3-right'>
<button
Expand All @@ -47,6 +100,22 @@ const CompareVariablesComponent = (props) => {
</b>
</button>
</div>
<button
onClick={props.submitHandler}
style={{ backgroundColor: theme.uniformStyle.color.sendButtonColor }}
className='w3-button w3-wide'
>
<b
style={{
fontSize: theme.typography.buttonSendtitle.fontSize,
fontWeight: theme.typography.buttonSendtitle.fontWeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing,
lineHeight: theme.typography.buttonSendtitle.lineHeight
}}
>
Send Request
</b>
</button>
</div>
);
};
Expand Down
57 changes: 39 additions & 18 deletions frontend/src/components/details/SelectVariableComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import DropDownComponent from 'components/dropdown/DropDownComponent';
import React, { Component } from 'react';
import theme from 'resources/theme';

Expand Down Expand Up @@ -50,25 +49,47 @@ class SelectVariableComponent extends Component {

return (
<div className='w3-row w3-margin-top'>
<div className='w3-col l4 m3 s3'>
{this.state.variables.length > 1 ? (
<h4>Select your desire variable:</h4>
) : (
<h4>There is only one Model for this product: </h4>
)}
<div className='w3-col l3 m3 s3'>
<h4>Select your desire variable:</h4>
</div>
<div className='w3-col l3 m4 s4 w3-left'>
<DropDownComponent
selectedVariable={this.state.selectedVariable}
variables={this.state.variables}
dropDownHandler={this.onDropDownItemSelectedHandler}
/>
</div>
<div className='w3-col l3 m4 s4 w3-left'>
<button
<div className='w3-col l8 m8 s8 w3-left'>
<div className='w3-dropdown-hover w3-margin-left w3-margin-right'>
<button
className='w3-button w3-2018-sailor-blue'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{this.state.selectedVariable}
</button>
<div
className='w3-dropdown-content w3-bar-block w3-border'
style={{
fontSize: theme.typography.buttontitle.fontSize,
fontWeight: theme.typography.buttontitle.fontWeight,
lineHeight: theme.typography.buttontitle.lineHeight,
letterSpacing: theme.typography.buttonSendtitle.letterSpacing
}}
>
{this.state.variables.map((item) => (
<button
onClick={() => this.onDropDownItemSelectedHandler(item.name)}
className='w3-bar-item w3-button'
key={item.id}
>
{item.name}
</button>
))}
</div>
</div>

{/* <button
style={{ backgroundColor: theme.uniformStyle.color.sendButtonColor }}
onClick={this.handleSubmit}
className='w3-button w3-wide w3-left'
className='w3-button w3-wide'
>
<b
style={{
Expand All @@ -80,7 +101,7 @@ class SelectVariableComponent extends Component {
>
Send Request
</b>
</button>
</button> */}
</div>
</div>
);
Expand Down
54 changes: 0 additions & 54 deletions frontend/src/components/dropdown/DropDownComponent.jsx

This file was deleted.

146 changes: 146 additions & 0 deletions frontend/src/components/dropdown/DropdownComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React, { useState } from 'react';
import { arrayOf, element, func, number, oneOfType, shape, string } from 'prop-types';
import { Column } from 'simple-flexbox';
import { createUseStyles, useTheme } from 'react-jss';
import { IconArrowUp } from 'assets/icons';
import SLUGS from 'resources/slugs';
import { Link } from 'react-router-dom';
const useStyles = createUseStyles((theme) => ({
//change thwe arrow position
arrowContainer: {
position: 'absolute',
top: -19,
right: 15
},
// dropdown button reconfiguration
dropdownButton: {
alignItems: 'center',
background: 'transparent',
border: 'none',
cursor: 'pointer',
display: 'flex',
padding: 0,
outline: 'none'
},
dropdownContainer: {
position: 'relative'
},

dropdownItemsContainer: {
background: 'white',
border: `1px solid ${theme.color.lightGrayishBlue2}`,
borderRadius: 5,
minWidth: 100,
padding: 0,
position: 'absolute',
width: '60%',
top: ({ position }) => position.top,
right: ({ position }) => position.right + 52,
bottom: ({ position }) => position.bottom - 10,
left: ({ position }) => position.left,
'& button:first-of-type:hover div > svg > path': {
fill: 'white'
}
},
dropdownItem: {
cursor: 'pointer',
background: 'transparent',
border: 'none',
fontSize: 10,
outline: 'none',
padding: '10px 10px',
//color change of the text on the dropdownbox whhle moving the cursor
'&:hover': {
background: 'green',
color: 'white'
},
//color of the text on the dropdownbox
'&:after': {
content: '" "',
display: 'block',
position: 'relative',
bottom: -10,
width: '100%',
height: 1,
background: theme.color.paleBlue
},
'&:last-child:after': {
content: '',
display: 'none'
}
}
}));

function DropdownComponent({ label, options, position }) {
const [userMenuOpen, setUserMenuOpen] = useState(false);
const theme = useTheme();
const classes = useStyles({ theme, position });

function onDropdownClick() {
setUserMenuOpen((prev) => !prev);
}

function onItemClick(onClick) {
setUserMenuOpen(false);
onClick && onClick();
}

return (
<Column className={classes.dropdownContainer}>
<button className={classes.dropdownButton} onClick={onDropdownClick}>
{label}
</button>
{userMenuOpen && (
<Column className={classes.dropdownItemsContainer}>
{options.map((option, index) => (
// when one of the items in the dropdownbox menu ,navigate the next page !
<Link
to={{
// Link to the next page
pathname: SLUGS.details
}}
>
<button
key={`option-${index}`}
className={classes.dropdownItem}
onClick={() => onItemClick(option.onClick)}
>
{option.label}
{index === 0 && (
<div className={classes.arrowContainer}>
<IconArrowUp />
</div>
)}
</button>
</Link>
))}
</Column>
)}
</Column>
);
}

DropdownComponent.propTypes = {
label: oneOfType([string, element]),
options: arrayOf(
shape({
label: oneOfType([string, arrayOf(element)]),
onClick: func
})
),
position: shape({
top: number,
right: number,
bottom: number,
left: number
})
};

DropdownComponent.defaultProps = {
position: {
top: 100,
right: -3
}
};

export default DropdownComponent;
3 changes: 3 additions & 0 deletions frontend/src/components/dropdown/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import DropdownComponent from './DropdownComponent';

export default DropdownComponent;

0 comments on commit 8e8f823

Please sign in to comment.