Exercise: React UI Components and Styling
#
ObjectiveYour objective is to continue from the React Routing Exercise to create an individual page view for each film. Additional goals will be to display film stats based on the current filter applied to our list of films.
#
Getting StartedThis is part 7 of TrueCoders' React Exercise Series.
You'll be in the same react repository that you worked in for part 6.
#
StepsReact Series Part 7 has two parts with multiple exercises each.
- Exercise 1: Install Bootstrap
- Exercise 2: Setup Global CSS and Assets
- Exercise 3: Create a Nav Component
- Exercise 4: Create a Main Layout
- Exercise 5: Create a Loader Component
- Exercise 6: Export Components from an Entry Point File
#
Exercise 1: Install Bootstrap- Use npm to install bootstrap and react-bootstrap
#
Exercise 2: Setup Global CSS And AssetsCreate a
global.css
file in yoursrc/
folder if you do not have one alreadyPlace the following code within the file
Change the css file import in your
index.js
toglobal.css
Create a new folder in
src/
calledassets/
- This is where you can store assets, such as images
Feel free to change any of this css to make it your own. The most important statement is the
@import(...)
statement at the top of the file that will load Bootstrap's css class rulesets. I will referencelogo.svg
andTCLogoOnly.png
files later in this exercise. Thelogo.svg
is the react svg that was added to this project when you began in part 1. TheTCLogoOnly.png
will be used as the navbar brand. You can use any image for that step in the exercise.
#
Exercise 3: Create a Nav ComponentCreate a new folder called
layout/
in your existingcomponents/
folderCreate a new folder called
topnav/
in your newlayout/
folderCreate a new file called
topnav.component.jsx
in your newtopnav/
folderAdd the following imports
Create a functional component called
TopNav
and have it return:
I am using a TrueCoders png for the
Navbar.Brand
img
. You will either add a new image or use an existing image in yourassets/
folder.
#
Exercise 4: Create a Main LayoutCreate a new folder in
layout/
calledmainlayout/
Create a new file in
mainlayout/
calledmainlayout.component.jsx
Add the following imports
Create a functional component called
MainLayout
Destructure
className
andchildren
from theprops
parameterHave the component return the following:
This layout component will be used as the universal layout for each view of our React application.
#
Exercise 5: Create a Loader ComponentCreate a generic, reusable Loader component.
Create a new folder in
components/
calledcommon/
Create a new folder in
common/
calledloader/
Create a new file in
loader/
calledloader.css
, and add the following contents:Create a new file in
loader/
calledloader.component.jsx
Import the
loader.css
fileCreate a functional component called
Loader
Destructure
size
from the props parameterReturn the following:
#
Exercise 6: Export Components from an Entry Point FileImport
MainLayout
,TopNav
,Loader
into a newindex.js
file in yourcomponents/
folderExport all components from this entry point file
This entry point file is a common practice. We can now import any of our components from this one file directly inside of the
components/
folder.
#
Add React Bootstrap to the Page ViewsUpdate the
SingleFilmPage
component to return:Update the
FilmsPage
component to return:Update the
HomePage
component to return:
#
Helpful LinksIf you feel stuck, or would like to see the finished code for this exercise to check your work, check out: