-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement filtered list #120
Open
adaczo
wants to merge
2
commits into
code4romania:master
Choose a base branch
from
adaczo:filtered-list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/components/filtered-list/filtered-list-item/filtered-list-item.js
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,35 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import "./filtered-list-item.styles.scss"; | ||
import CaretSvg from "../../../images/icons/caret.svg"; | ||
|
||
export class FilteredListItem extends React.Component { | ||
render() { | ||
const { listItem } = this.props; | ||
return ( | ||
<div className="__filtered-list-item-container"> | ||
{listItem.label && <div className="label">{listItem.label}</div>} | ||
<div className="__filtered-list-item"> | ||
<div className="content-section"> | ||
{listItem.rows.map((row, index) => ( | ||
<div className="row" key={index}> | ||
{row.value} | ||
</div> | ||
))} | ||
</div> | ||
<div | ||
className="icon-section" | ||
onClick={() => listItem.clickHandler(listItem.data)} | ||
style={{ background: listItem.styles.iconSectionColor }} | ||
> | ||
<CaretSvg /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FilteredListItem.propTypes = { | ||
listItem: PropTypes.object | ||
}; |
35 changes: 35 additions & 0 deletions
35
src/components/filtered-list/filtered-list-item/filtered-list-item.styles.scss
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,35 @@ | ||
|
||
.__filtered-list-item-container { | ||
.label { | ||
margin-bottom: 4px; | ||
margin-left: 4px; | ||
} | ||
} | ||
|
||
.__filtered-list-item { | ||
background-color: white; | ||
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25); | ||
display: flex; | ||
|
||
|
||
|
||
.content-section { | ||
padding: 10px; | ||
flex: 1; | ||
} | ||
|
||
.row { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.icon-section { | ||
width: 50px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
&:hover { | ||
cursor: pointer; | ||
surdu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
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,62 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import "./filtered-list.styles.scss"; | ||
import { FilteredListItem } from "./filtered-list-item/filtered-list-item"; | ||
|
||
export class FilteredList extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
if (this.props.config.filter) { | ||
this.state = { filterValue: props.config.filter.options[0].value }; | ||
} | ||
} | ||
|
||
handleChange = event => { | ||
this.props.config.filter.onSelect(event.target.value); | ||
this.setState({ filterValue: event.target.value }); | ||
}; | ||
|
||
render() { | ||
const { config } = this.props; | ||
return ( | ||
<div className="__filtered-list"> | ||
<section className="filter-section"> | ||
{config.filter && ( | ||
<div className="field"> | ||
<label className="label">{config.filter.label}</label> | ||
<div className="control"> | ||
<div className="select"> | ||
<select | ||
value={this.state.filterValue} | ||
onChange={this.handleChange} | ||
> | ||
{config.filter.options.map((option, index) => ( | ||
<option key={index} value={option.value}> | ||
{option.label} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
{this.props.children} | ||
</section> | ||
<section className="list-section"> | ||
{config.listItems.map((li, index) => ( | ||
surdu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<FilteredListItem listItem={li} key={index}></FilteredListItem> | ||
))} | ||
</section> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FilteredList.defaultProps = { | ||
config: {} | ||
}; | ||
|
||
FilteredList.propTypes = { | ||
config: PropTypes.object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it will be better if we define this as a |
||
children: PropTypes.element | ||
}; |
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,67 @@ | ||
import React from "react"; | ||
import "./../../styles.scss"; | ||
import { FilteredList } from "./filtered-list"; | ||
|
||
export default { title: "FilteredList" }; | ||
|
||
const config = { | ||
filter: { | ||
onSelect: value => console.log("Selected: ", value), | ||
label: "View for:", | ||
placeholder: "Select a person", | ||
options: [ | ||
{ | ||
label: "John Doe", | ||
value: "John Doe" | ||
}, | ||
{ | ||
label: "Bob", | ||
value: "Bob" | ||
} | ||
] | ||
}, | ||
listItems: [ | ||
{ | ||
data: { somedata: "123" }, | ||
clickHandler: data => console.log(data), | ||
styles: { | ||
iconSectionColor: "blue" | ||
}, | ||
label: "28.03.2020", | ||
rows: [ | ||
{ | ||
value: "Rezultat formular - esti in siguratna daca ramai acasa" | ||
}, | ||
{ | ||
value: "Simptome - nu prezinti simptome specifice COVID-19" | ||
} | ||
] | ||
}, | ||
{ | ||
data: { somedata: "234" }, | ||
clickHandler: data => console.log(data), | ||
styles: { | ||
iconSectionColor: "red" | ||
}, | ||
label: "28.03.2020", | ||
rows: [ | ||
{ | ||
value: "Rezultat formular - esti in siguratna daca ramai acasa" | ||
}, | ||
{ | ||
value: "Simptome - nu prezinti simptome specifice COVID-19" | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
|
||
export const example = () => ( | ||
<div style={{ width: "800px" }}> | ||
<FilteredList config={config}> | ||
<button className="button is-warning" style={{ marginBottom: "10px" }}> | ||
Complete form | ||
</button> | ||
</FilteredList> | ||
</div> | ||
); |
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,18 @@ | ||
.__filtered-list { | ||
border: 1px solid black; | ||
padding: 15px 25px 15px 15px; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.__filtered-list-item { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.filter-section { | ||
margin-bottom: 20px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: flex-end; | ||
flex: 1; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All components in here are function components. For the sake of consistency, could you please convert yours to function components as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored FilteredListItem to use a function.
@surdu For FilteredList I need to have local state, do you recommend a different approach?