Skip to content
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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import PropTypes from "prop-types";
import "./filtered-list-item.styles.scss";
import CaretSvg from "../../../images/icons/caret.svg";

export const FilteredListItem = ({ listItem }) => (
<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
};
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
}
}
}
63 changes: 63 additions & 0 deletions src/components/filtered-list/filtered-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 &&
config.listItems.map((li, index) => (
<FilteredListItem listItem={li} key={index} />
))}
</section>
</div>
);
}
}

FilteredList.defaultProps = {
config: {}
};

FilteredList.propTypes = {
config: PropTypes.object,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it will be better if we define this as a PropTypes.shape. Please see here for an example.

children: PropTypes.element
};
67 changes: 67 additions & 0 deletions src/components/filtered-list/filtered-list.stories.js
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>
);
18 changes: 18 additions & 0 deletions src/components/filtered-list/filtered-list.styles.scss
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;
}
}
3 changes: 3 additions & 0 deletions src/images/icons/caret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.