Material UI Tutorial #2 - Typography

Net Ninja · Beginner ·🌐 Frontend Engineering ·5y ago
Skills: UI Design90%

Key Takeaways

Styles headings and normal text using the Typography component from Material UI

Full Transcript

all right then gang so now we have material ui installed we can go ahead and start using the material ui components now the first one i want to show you is the typography component and generally the first thing i do when i'm using a new component i've never used before is just search for it in the material ui docs up here so if i type typo then it's going to come up typography and if we click on that we can see how this typography component is used if we scroll down so when we're using material ui we generally don't have to use h1 tags h2 tags paragraph tags etc instead we just use a typography component and then we can customize how that typography component is going to look and what tag it should be when it's output to the browser whether it should be an h1 or an h3 or a paragraph tag etc so you can see right here all of these different headings and paragraphs they are all output using the typography component and if we take a look at this show the source and scroll down here first of all you can see we import this typography component like so and if we scroll down further we can see we're using the typography here and here and here for all these different headings and paragraphs as well so all we do is nest our text in between the opening and closing typography component and then inside this component as props we can specify how we want this typography to look you can see we have this variant prop right here and this is us basically telling the typography components what we want it to be do we want it to be an h1 or rather do we want it to be styled like an h1 so it's big or styled like an h2 so it's quite big but not as big etc and there's all these different variants we can use you see we have this for essentially paragraph text but we have two different variants of paragraph tags body one and body two and also we see we have this component thing right here this specifies what tag is going to be output to the browser when we use this typography component so if we want it to look like an h1 which is what this variant thing does for us but we want it to output as an h2 tag we can override this and say the component should be in h2 by default if this wasn't here it would be output as an h1 because that's what we specified the variant to be but this is here to override that if we want to output it as something else so then let's give this a little whirl in our project all right then so i'm going to work inside one of our pages and it's going to be the create page right here and i want to use the typography component inside this react component so the first thing we have to do is import it so to do that i'm going to say import typography that's the components from and it's at material hyphen ui forward slash core forward slash the component name which is typography okay so there's two ways we can import things we can either import them like this or we can take off this part at the end of core and instead we can destructure the different components we need like so now it's entirely up to you which way you prefer this way is slightly less performant but only very slightly than the other way i probably will use a mix of ways i just wanted to let you know so now we're importing the typography components we can go ahead and use it in this page so let me do a few examples what i'm going to do is create a new typography component opening and closing tag and then inside we'll just say create a new note like so okay so now if i get rid of this create page at the top and save this i'm going to go over to the create page in the browser and we can see create a new note now if i inspect this and move this out a little bit you can see that by default it outputs a paragraph tag so that's the default typography tag now what if i want this to be something else for example an h1 well i can just add props so i can say variant is going to be equal to h1 like so and if i save this now and preview we can see that now it's an h1 tag over here and it's much bigger in the browser okay cool so generally when i add props to these different components i might be adding several different props and if i add them all going across this way pretty soon it's going to go off the screen so what i tend to do is move this down to the next line like so and then move this down and what i can do is add them one after another below each other so now we can also change the color of these typography components the text color and to do that we can pass in the colour prop now we can't just pass in any old colour here we can only pass in our different theme colours now we'll talk more about themes and colours later on but for now we'll just use one called primary so if i save that it's going to use the primary theme color which is kind of like this blue color by default this can also be secondary and we'll see that in a second but for now let's try adding another prop it's going to be an align prop this is used to align the text so we could align it to the center for example if i save that then it's going to be in the center cool all right then so let's try another example what i'm going to do is copy this and then i'm going to comment it out so it doesn't show and i'm going to paste it down here and change it so let's now try instead of primary secondary like this so this is another theme color and in fact what i'm going to do is take away this variant because i just want it to be a paragraph tag now and we'll also take away this align thing as well so if i save this and preview we can see now we get this ready pink color that is the secondary theme color now i'm going to get rid of this text and i'm going to use some lorem ipsum instead so let me just add that on and save it and preview and can you see how it goes over several different lines now we can add a no wrap prop to this so if i say no wrap camel case like so and save this take a look what happens you can see it truncates the text so when it reaches the end of the browser over here we get three little dots at the end of the text and it doesn't go over to the next line if i make this a bit bigger we can see it carries on so this is a nice way to truncate the text if you just want to show maybe a little preview or a snippet on one line of the text maybe on a blog preview on the homepage or something like that cool so there's many different things we can do with the typography component and if you want to see all of the different props that you can pass into the typography component you can go to the docs and if we just scroll down here right to the bottom and you'll see this api option click on this typography tag at the bottom and then scroll down and you can see all of the different props that we can pass in right here so we've seen a line we've seen color and these are the different things we can pass into color like i said you can't pass in any old hex code or anything like that just these different things and we'll take a look at these different theme values later in the course we can also pass in display or the component we talked about that before if we want to output the typography component as something else so not for example an h1 that we specify here but we could output it as an h3 instead and if we scroll down we can see we've also got this gutter bottom and if that's true then it's gonna have a bottom margin we've got no wrap loads of different things these are the variants right here so we've seen each one we've also got things like body one body two captions etc so you can have a little play around with those as well what i'm going to do is delete all of this that we've got so far and i'm going to create a new typography component and this is going to be for the header on this page and the header is going to be create a new notes then inside we'll add a few props so the first thing i want this to be is an h6 so i'm going to say variance and set that equal to h6 now if we take a look at this i'm going to save it and preview over here this is the kind of size i want it to be so it's styled like an h6 and also we're outputting an h6 tag right here now it's fine how it looks but i actually want it to be an h2 so what i'm going to do is add in the component prop like so and set that equal instead to h2 now this is still going to look like the h6 because we have the variant set to h6 but the actual html right here is outpoint h2 and that's what i want okay so next i'm going to apply a gutter bottom so let me say gutter bottom like so now i don't need to set it equal to true or anything all i need to do is pass in the prop name and that will set it equal to true automatically and now if we hover over this we can see that orange little margin below the text and then finally i want to change the color of this so let me add in a color prop up here and i'm going to set that equal to text secondary like so oops secondary i spot this correctly yep save that and preview and we can see now this is a grayish color don't get this confused with secondary that's the secondary theme color which is at the minute pink this is text secondary which is kind of like a grayish colour that's the colour that i want for this heading so there we go my friends that is the typography component as you can see it's pretty flexible and i find myself never really needing to use an actual paragraph tag or an h1 or an h2 or anything like that directly i just use this typography component instead so definitely have a play around with the other props that we can pass into this typography component we will be using it a lot as we go forward as well but next up i want to take a look at a different component buttons

Original Description

Hey gang, in this Material UI tutorial we'll take a look at the Typography component to make/style headings & normal text. 🐱‍💻 🐱‍💻 Course Files: + https://github.com/iamshaunjp/material-ui-tut 🐱‍👤🐱‍👤 JOIN THE GANG - https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join 🐱‍💻 🐱‍💻 My Udemy Courses: + Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript + Vue JS 3 & Firebase - https://www.thenetninja.co.uk/udemy/vue-and-firebase + D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase 🐱‍💻 🐱‍💻 Useful playlists: + Full React tutorial - https://www.youtube.com/watch?v=j942wKiXFu8&list=PL4cUxeGkcC9gZD-Tvwfod2gaISzfRiP9d + JSON Server Tutorial - https://www.youtube.com/watch?v=mAqYJF-yxO8&list=PL4cUxeGkcC9i2v2ZqJgydXIcRq_ZizIdD 🐱‍💻 🐱‍💻 Other links: + Material UI docs - https://material-ui.com/getting-started/installation/ + Get VS Code - https://code.visualstudio.com/ 🐱‍💻 🐱‍💻 Social Links: Facebook - https://www.facebook.com/thenetninjauk Twitter - https://twitter.com/thenetninjauk Instagram - https://www.instagram.com/thenetninja/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related Reads

📰
The Enter key that submits your form while a Japanese user is still typing
Learn how to prevent the Enter key from submitting a form while a Japanese user is still typing, and why it matters for user experience
Dev.to · greymoth
📰
The two-Reacts bug: when packages aren't singletons
Learn to fix the two-Reacts bug by understanding how to handle non-singleton packages in React applications
Dev.to · r9v
📰
🚀 Introducing Prism Guard — An Open Source Frontend Architecture Intelligence Platform
Learn about Prism Guard, an open-source frontend architecture intelligence platform, and how it can help improve codebase quality
Dev.to · Ritumoni Sarma
📰
The Death of the Heavy Hydration Layer
Learn why plain HTML is the new developer flex and how to simplify web development by ditching heavy hydration layers
Dev.to · Amodit Jha
Up next
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks
Watch →