Skip to content

Commit 52dc86f

Browse files
committed
Build a button component using bootstrap #7
1 parent 58507c9 commit 52dc86f

File tree

12 files changed

+99
-58
lines changed

12 files changed

+99
-58
lines changed

src/components/Button.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
import { Link } from 'react-router-dom';
3+
4+
const Button = (props) => {
5+
switch (props.btnType) {
6+
case 'success':
7+
return (<button
8+
{...props}
9+
onClick={props.onClick || (() => { })}
10+
className={`btn btn-success ${props.className || ''} ${props.class || ''}`}
11+
type="button">
12+
{props.children}
13+
</button>);
14+
case 'success-as-link':
15+
return (<Link {...props} className={`btn btn-success ${props.className}`}>{props.children}</Link>)
16+
default:
17+
return (<button {...props}>{props.children}</button>);
18+
}
19+
};
20+
21+
export default Button

src/components/footer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import { Link } from 'react-router-dom'
33
import { BsLinkedin, BsTwitter, BsFacebook } from "react-icons/bs";
4+
import Button from './Button';
45

56

67
const Footer = () => {
@@ -73,7 +74,7 @@ const Footer = () => {
7374
<div className="d-flex flex-column flex-sm-row w-100 gap-2">
7475
<label htmlFor="newsletter1" className="visually-hidden">Email address</label>
7576
<input id="newsletter1" type="text" className="form-control" placeholder="Email address" />
76-
<button className="btn btn-success" type="button">Subscribe</button>
77+
<Button btnType="success">Subscribe</Button>
7778
</div>
7879
</form>
7980
</div>

src/components/navbar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import React from 'react';
22
import { Link } from 'react-router-dom';
33
import { images } from '../assets';
4+
import Button from './Button';
45

56

67
const NavBar = () => {
78
return (
89
<nav class="navbar navbar-expand-lg bg-body-tertiary">
910
<div class="container-fluid">
1011
{/* <div class="navbar-brand" href="#">Navbar</div> */}
11-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
12+
<Button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
1213
<span class="navbar-toggler-icon"></span>
13-
</button>
14+
</Button>
1415
<div class="collapse navbar-collapse" id="navbarSupportedContent">
1516
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
1617
<li class="nav-item align-items-center px-2">
@@ -74,7 +75,7 @@ const NavBar = () => {
7475
</ul>
7576
{/* <form className="d-flex" role="search"> */}
7677
{/* <input className="form-control me-2" type="search" placeholder="Search" aria-label="Search" />
77-
<button className="btn btn-outline-success" type="submit">Search</button> */}
78+
<Button className="btn btn-outline-success" type="submit">Search</Button> */}
7879
{/* </form> */}
7980
</div>
8081
</div>

src/containers/FootballClub/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Navbar from '../../components/navbar';
44
import Footer from '../../components/footer';
55
import { BsArrowRight } from 'react-icons/bs';
66
import { images } from '../../assets';
7+
import Button from '../../components/Button';
78

89

910
const players = [
@@ -65,7 +66,7 @@ const FootballClub = () => {
6566
</div>
6667
<nav>
6768
<div className="nav nav-tabs" id="myTab" role="tablist">
68-
<button
69+
<Button
6970
className="nav-link active text-success"
7071
id="nav-home-tab"
7172
data-bs-toggle="tab"
@@ -76,8 +77,8 @@ const FootballClub = () => {
7677
aria-selected="true"
7778
>
7879
Overview
79-
</button>
80-
<button
80+
</Button>
81+
<Button
8182
className="nav-link text-success"
8283
id="nav-profile-tab"
8384
data-bs-toggle="tab"
@@ -88,8 +89,8 @@ const FootballClub = () => {
8889
aria-selected="false"
8990
>
9091
Squad
91-
</button>
92-
<button
92+
</Button>
93+
<Button
9394
className="nav-link text-success"
9495
id="nav-contact-tab"
9596
data-bs-toggle="tab"
@@ -100,8 +101,8 @@ const FootballClub = () => {
100101
aria-selected="false"
101102
>
102103
Fixtures
103-
</button>
104-
<button
104+
</Button>
105+
<Button
105106
className="nav-link text-success"
106107
id="nav-home-tab"
107108
data-bs-toggle="tab"
@@ -112,7 +113,7 @@ const FootballClub = () => {
112113
aria-selected="true"
113114
>
114115
Stats
115-
</button>
116+
</Button>
116117
</div>
117118
</nav>
118119
<div className="tab-content" id="nav-tabContent">

src/containers/HomeScreen/featured.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import { BsCode, BsBicycle, BsBook } from "react-icons/bs";
33
import { Link } from 'react-router-dom';
4+
import Button from '../../components/Button';
45

56
const Featured = () => {
67
return (
@@ -24,7 +25,8 @@ const Featured = () => {
2425
<div>
2526
<h3 class="fs-2">Sports</h3>
2627
<p>Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and probably just keep going until we run out of words.</p>
27-
<Link className='btn btn-success' to="/sports">Learn More</Link>
28+
<Button btnType='success-as-link' to="/sports">Learn More</Button>
29+
2830
</div>
2931
</div>
3032
<div class="col d-flex align-items-start">
@@ -34,7 +36,7 @@ const Featured = () => {
3436
<div>
3537
<h3 class="fs-2">Education</h3>
3638
<p>Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and probably just keep going until we run out of words.</p>
37-
<button className='btn btn-success'>Learn More</button>
39+
<Button btnType='success'>Learn More</Button>
3840
</div>
3941
</div>
4042
</div>

src/containers/HomeScreen/gallery.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { images } from '../../assets';
3+
import Button from '../../components/Button';
34

45

56
const assets = [
@@ -66,14 +67,14 @@ const Gallery = () => {
6667
)
6768
})
6869
}
69-
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="prev">
70+
<Button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="prev">
7071
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
7172
<span class="visually-hidden">Previous</span>
72-
</button>
73-
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="next">
73+
</Button>
74+
<Button class="carousel-control-next" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="next">
7475
<span class="carousel-control-next-icon" aria-hidden="true"></span>
7576
<span class="visually-hidden">Next</span>
76-
</button>
77+
</Button>
7778
</div>
7879
</div>
7980
</div>

src/containers/HomeScreen/top-section.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { images } from '../../assets';
3+
import Button from '../../components/Button';
34

45
const TopSection = () => {
56
return (
@@ -13,7 +14,7 @@ const TopSection = () => {
1314
The organization is looking forward to empowering the community <br />
1415
Through technology, talent, and education
1516
</p>
16-
<button type='button' className='btn btn-success'>Learn More</button>
17+
<Button btnType="success">Learn More</Button>
1718
</div>
1819
</div>
1920
<div className='col-md-5'>

src/containers/LoginScreen/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import { Link } from 'react-router-dom'
33
import { images } from '../../assets'
4+
import Button from '../../components/Button'
45
import Footer from '../../components/footer'
56
import NavBar from '../../components/navbar'
67

@@ -14,18 +15,18 @@ const LoginScreen = () => {
1415
<img className="mb-4" src={images.logo} alt="" width="72" height="57" />
1516
<h1 className="h3 mb-3 fw-normal">Please sign in</h1>
1617
<div className="w-50 form-floating mb-3">
17-
<input
18-
type="email"
19-
className="form-control"
20-
id="floatingInput"
18+
<input
19+
type="email"
20+
className="form-control"
21+
id="floatingInput"
2122
placeholder="[email protected]"
2223
/>
2324
<label htmlFor="floatingInput">Email address</label>
2425
</div>
2526
<div className="w-50 form-floating mb-3">
26-
<input
27-
type="password"
28-
className="form-control"
27+
<input
28+
type="password"
29+
className="form-control"
2930
id="floatingPassword"
3031
placeholder="Password"
3132
/>
@@ -37,12 +38,13 @@ const LoginScreen = () => {
3738
</label>
3839
</div>
3940
<Link to="/dashboard">
40-
<button
41-
className="w-50 btn btn-lg btn-success"
41+
<Button
42+
className="w-50 btn-lg"
43+
btnType="success"
4244
type="submit"
4345
>
4446
Sign in
45-
</button>
47+
</Button>
4648
</Link>
4749
</form>
4850
</div>

src/containers/SignupSoftware/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Navbar from '../../components/navbar';
33
import { Link } from 'react-router-dom';
44
import Footer from '../../components/footer'
5+
import Button from '../../components/Button';
56

67
const RegisterSoftware = () => {
78
return (
@@ -17,7 +18,7 @@ const RegisterSoftware = () => {
1718
Register To Learn Software
1819
</h3>
1920
<p className="col-lg-12 fs-5">
20-
Get the best out of our programs and be an expert in one of the fields below:
21+
Get the best out of our programs and be an expert in one of the fields below:
2122
</p>
2223
<ul>
2324
<li>Full-stack Engineer</li>
@@ -51,7 +52,12 @@ const RegisterSoftware = () => {
5152
<input type="password" className="form-control" id="floatingPassword" placeholder="Password" />
5253
<label htmlFor="floatingPassword">Password</label>
5354
</div>
54-
<button className="w-100 btn btn-lg btn-success" type="submit">Sign up</button>
55+
<Button
56+
btnType="success"
57+
className="w-100 btn-lg"
58+
type="submit">
59+
Sign up
60+
</Button>
5561
<div className='d-flex mt-2'>
5662
<p className='px-2'>Already have an account?</p>
5763
<Link className='link-success' to="/login">Login</Link>

0 commit comments

Comments
 (0)