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

Created TabbedList with subcomponents, missing API calls #46

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": false,
"dependencies": {
"bulma": "^0.8.0",
"date-fns": "^2.11.0",
surdu marked this conversation as resolved.
Show resolved Hide resolved
"react-share": "^4.1.0"
},
"peerDependencies": {
Expand Down
118 changes: 118 additions & 0 deletions src/components/tabbed-list/family-member-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React, { useState, useEffect, useCallback } from "react";
import PropTypes from "prop-types";
import "./../../styles.scss";
import "./tabbed-list.scss";
import classNames from "classnames";
import { TabbedListItem } from "./tabbed-list-item";

export const FamilyMemberPage = () => {
const [members, setMembers] = useState([]);
const [listItems, setListItems] = useState([]);
const [dropdownActive, setDropdownActive] = useState(false);
const [selected, setSelected] = useState(null);

useEffect(() => {
//TODO make api call --- mocked result
const result = [
{ id: 1, name: "Camelia Nistor" },
{ id: 2, name: "Andrei Nistor" }
];
setMembers(result);
setSelected(result[0]);
}, []);

useEffect(() => {
//TODO make api call --- mocked result
const result = [
{
id: 1,
color: "#0000ff",
date: new Date(),
resultText: "Rezultat Formular - esti in siguranta daca ramai in casa",
symptomText: "Simptome - nu prezinti simptome specifice COVID-19",
onClick: () => {
alert("hello");
}
},
{
id: 2,
color: "#ff0000",
date: new Date(),
resultText: "Rezultat Formular - esti in siguranta daca ramai in casa",
symptomText: "Simptome - prezinti simptome specifice COVID-19",
onClick: () => {
alert("hello");
}
}
];

setListItems(result);
}, [selected]);

const triggerDropdown = useCallback(() => {
setDropdownActive(true);
}, []);

const handleSelect = useCallback(m => {
setSelected(m);
setDropdownActive(false);
}, []);

return (
<div className="tab-page">
<div className="tli-dropdown-container">
<div className="vis-text">Vizualizeaza pentru:</div>
<div className="action-container">
<div
className={classNames("dropdown", { "is-active": dropdownActive })}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use a select element for the dropdown? I think it would be easier to have all the functionality built in by default, like closing itself when clicking outside

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a select tag is better for accessibility too.

>
<div className="dropdown-trigger">
<button
className="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
onClick={triggerDropdown}
>
{selected && selected.name}
</button>
</div>
<div className="dropdown-menu" id="dropdown-menu" role="menu">
<div className="dropdown-content ">
{members.length &&
Copy link
Member

Choose a reason for hiding this comment

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

Does .map() need guard against empty lists ?

members.map(m => (
<div
key={m.id}
className="dropdown-item"
onClick={() => handleSelect(m)}
>
{m.name}
</div>
))}
</div>
</div>
</div>
<button
className="complete-form-button"
onClick={() => {
/* TODO*/
alert("implement me");
}}
>
Completeaza formular
</button>
</div>
</div>

<div>
{listItems.map(item => (
<TabbedListItem key={item.id} {...item} />
))}
</div>
</div>
);
};

FamilyMemberPage.propTypes = {
familyMembers: PropTypes.array,
onClick: PropTypes.func
};
36 changes: 36 additions & 0 deletions src/components/tabbed-list/tabbed-list-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";
import PropTypes from "prop-types";
import format from "date-fns/format";
import "./tabbed-list.scss";
import CaretSvg from "../../icons/caret.svg";

export const TabbedListItem = ({
color,
date,
resultText,
symptomText,
onClick
}) => {
return (
<div className={"tli-container"}>
<div className={"tli-date"}>{format(date, "dd.MM.yyyy")}</div>
<div className={"tli-text-wrapper"} onClick={onClick}>
<div className={"tli-text"} onClick={onClick}>
Copy link
Member

Choose a reason for hiding this comment

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

can we trigger the onClick only when clicking on the blue/red button? I think it's unexpected that when I select text the alert pops up (also for some reason it pops up twice when i click on a list item)

<div className={"tli-result"}>{resultText}</div>
<div className={"tli-symptom"}>{symptomText}</div>
</div>
<div className={"tli-icon"} style={{ backgroundColor: color }}>
<CaretSvg />
</div>
</div>
</div>
);
};

TabbedListItem.propTypes = {
color: PropTypes.string,
Copy link
Member

@surdu surdu Mar 19, 2020

Choose a reason for hiding this comment

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

I presume that the colors will be a limited set of colors (as I've seen in other PRs). We might be better of if we make this a set of colors like ['primary', 'danger'] or ['blue', 'red'] and defined a hex color constant for each. @moonflare ?

date: PropTypes.instanceOf(Date),
resultText: PropTypes.string,
symptomText: PropTypes.string,
onClick: PropTypes.func
};
15 changes: 15 additions & 0 deletions src/components/tabbed-list/tabbed-list-item.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import "./../../styles.scss";
import { TabbedListItem } from "./tabbed-list-item";

export default { title: "TabbedListItem" };

export const Blue = () => (
<TabbedListItem
color={"blue"}
onClick={() => {}}
date={new Date()}
resultText={"Rezultat Formular - esti in siguranta daca ramai in casa"}
symptomText={"Simptome - nu prezinti simptome specifice COVID-19"}
/>
);
82 changes: 82 additions & 0 deletions src/components/tabbed-list/tabbed-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useState, useEffect, useCallback } from "react";
import "./tabbed-list.scss";
import "./../../styles.scss";
import { FamilyMemberPage } from "./family-member-page";
import { TabbedListItem } from "./tabbed-list-item";
import classNames from "classnames";

export const TabbedList = () => {
const [showMyForms, setShowMyForms] = useState(true);
const [showFamilyForms, setShowFamilyForms] = useState(false);
const [listItems, setListItems] = useState([]);

const handleMyFormsClick = useCallback(() => {
setShowMyForms(true);
setShowFamilyForms(false);
}, []);
const handleFamilyFormsClick = useCallback(() => {
setShowMyForms(false);
setShowFamilyForms(true);
}, []);

useEffect(() => {
//TODO make api call
const result = [
{
id: 1,
color: "#0000ff",
date: new Date(),
resultText: "Rezultat Formular - esti in siguranta daca ramai in casa",
symptomText: "Simptome - nu prezinti simptome specifice COVID-19",
onClick: () => {
alert("hello");
}
},
{
id: 2,
color: "#ff0000",
date: new Date(),
resultText: "Rezultat Formular - esti in siguranta daca ramai in casa",
symptomText: "Simptome - prezinti simptome specifice COVID-19",
onClick: () => {
alert("hello");
}
}
];

setListItems(result);
}, []);

return (
<div>
<div className="tabs">
<ul>
<li
className={classNames("tl-tab", { active: showMyForms })}
onClick={handleMyFormsClick}
>
Formularele mele
</li>
<li
className={classNames("tl-tab", { active: showFamilyForms })}
onClick={handleFamilyFormsClick}
>
Membrii familiei
</li>
</ul>
</div>
<div>
{showMyForms && (
<div className="tab-page">
{listItems.map(item => (
<TabbedListItem key={item.id} {...item} />
))}
</div>
)}
{showFamilyForms && <FamilyMemberPage />}
</div>
</div>
);
};

TabbedList.propTypes = {};
105 changes: 105 additions & 0 deletions src/components/tabbed-list/tabbed-list.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
.tabs {
ul {
border-bottom: none;
}

&:not(:last-child){
margin-bottom: 0;
}
}

.tl-tab {
font-size: 18px;
padding: 4px 10px;
color: #989898;

&.active {
color: #1c1080;
}
}

.tli-dropdown-container {
display: flex;
flex-direction: column;
margin-bottom: 35px;

.vis-text {
font-weight: bold;
font-size: 14px;
line-height: 21px;
color: #000000;
margin-bottom: 7px;
}

.action-container {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.dropdown-trigger > button {
display: flex;
justify-content: space-between;
font-size: 14px;
line-height: 21px;
color: #878787;
width: 256px;
}

.dropdown-content {
width: 256px;
}
}

.complete-form-button {
background: #ffbd59;
border-radius: 2px;
color: #fff;
font-size: 15px;
line-height: 23px;
text-align: center;
border: none;
padding: 4px 10px;
font-weight: bold;
}

.tab-page {
border: 1px solid #b7b7b7;
padding: 22px 26px 20px 13px;
}

.tli-container {
margin-bottom: 23px;
}

.tli-date {
font-weight: 600;
font-size: 15px;
margin-bottom: 8px;
color: #6a6a6a;
}

.tli-text-wrapper {
display: flex;
flex-direction: row;
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);

.tli-text {
display: flex;
flex-direction: column;
justify-content: space-around;
font-size: 18px;
width: 100%;
color: #1c1080;

div {
padding: 5px;
}
}
.tli-icon {
width: 45px;
display: flex;
justify-content: space-around;
align-items: center;
}
}
7 changes: 7 additions & 0 deletions src/components/tabbed-list/tabbed-list.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";
import "./../../styles.scss";
import { TabbedList } from "./tabbed-list";

export default { title: "TabbedList" };

export const list = () => <TabbedList />;
3 changes: 3 additions & 0 deletions src/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.
Loading