Skip to content

Commit

Permalink
feat: Styling React applications for beginners
Browse files Browse the repository at this point in the history
  • Loading branch information
Param-Harrison committed Apr 21, 2020
1 parent 0aa1bd0 commit 088c8b6
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 53 deletions.
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

10 changes: 9 additions & 1 deletion src/components/contact-form.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { useEffect } from "react";
import { useHistory } from "react-router-dom";
import FormInput from "./form-input";
import useContactForm from "./use-contact-form";
import { useGlobalStore } from "./global-state";
import styles from "./contact-form.module.css";

const ContactForm = ({ id, title, ...props }) => {
const history = useHistory();
const { contacts } = useGlobalStore();
const [formValues, dispatchForm] = useContactForm({
name: "",
Expand Down Expand Up @@ -36,6 +39,7 @@ const ContactForm = ({ id, title, ...props }) => {

const onDiscard = () => {
resetForm();
history.push("/");
};

const onChange = (e) => {
Expand Down Expand Up @@ -73,7 +77,11 @@ const ContactForm = ({ id, title, ...props }) => {
required
/>
<button type="submit">Save contact</button>
<button type="button" onClick={onDiscard}>
<button
type="button"
className={styles.discardButton}
onClick={onDiscard}
>
Discard
</button>
</form>
Expand Down
3 changes: 3 additions & 0 deletions src/components/contact-form.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.discardButton {
margin-left: 10px;
}
7 changes: 6 additions & 1 deletion src/components/contact-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const ContactList = () => {

return (
<React.Fragment>
<ol>
<ol
style={{
padding: 0,
listStyle: "none",
}}
>
{contacts.map((contact) => {
return <Contact key={contact.id} {...contact} />;
})}
Expand Down
18 changes: 18 additions & 0 deletions src/components/contact.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.contact {
border: 1px solid #eee;
padding: 10px;
border-radius: 3px;
margin-bottom: 10px;
}
.contact-name {
margin: 0 0 10px 0;
}
.contact-email {
margin-bottom: 10px;
}
.button-group {
margin-top: 10px;
}
.remove-button {
margin-left: 10px;
}
15 changes: 10 additions & 5 deletions src/components/contact.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import "./contact.css";
import { useHistory } from "react-router-dom";
import { useGlobalStore } from "./global-state";
import { deleteContacts } from "../api";

const ContactItem = ({ name, email, phone }) => {
return (
<React.Fragment>
<h3>{name}</h3>
<div>
<h2 className="contact-name">{name}</h2>
<div className="contact-email">
<strong>{email}</strong>
</div>
<div>{phone}</div>
Expand Down Expand Up @@ -39,11 +40,15 @@ const Contact = (props) => {
};

return (
<li>
<li className="contact">
<React.Fragment>
<MemoizedContactItem {...props} />
<button onClick={onEdit}>Edit</button>
<button onClick={onRemove}>Remove</button>
<section className="button-group">
<button onClick={onEdit}>Edit</button>
<button onClick={onRemove} className="remove-button">
Remove
</button>
</section>
</React.Fragment>
</li>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/form-input.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from "react";
import styles from "./form-input.module.css";

const FormInput = ({ label, value, onChange, ...props }) => {
const inputId = label.toLowerCase();

return (
<div>
<label htmlFor={inputId}>{label}</label>
<label htmlFor={inputId} className={styles.label}>
{label}
</label>
<input
className={styles.input}
id={inputId}
name={inputId}
value={value}
Expand Down
11 changes: 11 additions & 0 deletions src/components/form-input.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.label {
font-weight: bold;
font-size: 14px;
display: block;
margin-bottom: 4px;
}
.input {
padding: 10px 8px;
margin-bottom: 10px;
min-width: 300px;
}
50 changes: 43 additions & 7 deletions src/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ import { Link } from "react-router-dom";

const NavLinks = () => {
return (
<ul>
<li>
<ul
style={{
display: "flex",
listStyle: "none",
padding: 0,
}}
>
<li
style={{
margin: "0 10px",
}}
>
<Link to="/">Home</Link>
</li>
<li>
<li
style={{
margin: "0 10px",
}}
>
<Link to="/add">Add contact</Link>
</li>
</ul>
Expand All @@ -16,11 +30,33 @@ const NavLinks = () => {

const Header = () => {
return (
<header>
<h3>
<a href="/">Conpro</a>
<header
style={{
display: "flex",
alignItems: "center",
width: "100%",
}}
>
<h3
style={{
fontSize: "24px",
}}
>
<a
href="/"
style={{
textDecoration: "none",
color: "black",
}}
>
Conpro
</a>
</h3>
<nav>
<nav
style={{
marginLeft: "auto",
}}
>
<NavLinks />
</nav>
</header>
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ body {
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

max-width: 600px;
margin: 0 auto;
padding: 10px 15px;
}

code {
Expand Down

0 comments on commit 088c8b6

Please sign in to comment.