Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,760 --> 00:00:08,080
By now we should be getting pretty familiar with the material UI theming system and what the default
2
00:00:08,110 --> 00:00:15,490
theme provides for us but what about when you don't actually need a theme.
3
00:00:15,490 --> 00:00:22,000
You're not trying to change all of the types of components across your application but you just want
4
00:00:22,000 --> 00:00:27,330
to apply styling to one component within your application.
5
00:00:27,340 --> 00:00:35,640
Well that is exactly what inline styling is and material UI provides a great system for doing this.
6
00:00:35,650 --> 00:00:44,400
The ties into the theming system so let's go take a look at how we can get started with inline styles
7
00:00:44,700 --> 00:00:52,290
and then we're going to use that to finally fix that margin problem with our app a bar that is covering
8
00:00:52,290 --> 00:01:02,140
up our little Hello underneath it here on the material UI documentation page you can see under the styles
9
00:01:02,140 --> 00:01:10,390
tab and then we're on the basics if you scroll down here to where it says getting started it shows you
10
00:01:10,420 --> 00:01:17,190
a simple example of how it's using inline styles to create this little button right here.
11
00:01:17,880 --> 00:01:26,130
So if you walk through it you'll notice the first to it after importing react imports this make styles
12
00:01:26,220 --> 00:01:35,520
from material UI styles and then imports the button from the material UI core and it uses that make
13
00:01:35,580 --> 00:01:42,470
styles import which is actually a function which we pass our styles in.
14
00:01:42,480 --> 00:01:51,000
J SS as an object inside this object you'll notice the a lot of the properties are going to be extremely
15
00:01:51,000 --> 00:01:59,970
familiar to you because J SS is essentially exactly the same as a C Ss with only a few functionality
16
00:01:59,970 --> 00:02:07,500
differences but the main difference being that these styles instead of being border dash radius you
17
00:02:07,500 --> 00:02:12,300
see that it's border radius in camel case with the capital R.
18
00:02:12,510 --> 00:02:18,570
So all you really need to remember is that all the CSF properties that you're used to you're just going
19
00:02:18,570 --> 00:02:26,670
to need to kind of squish them together into this format for J SS Another difference is that we do have
20
00:02:26,670 --> 00:02:30,710
to put our strings in quotations.
21
00:02:30,750 --> 00:02:35,760
We can't just put the word white right there or the hexadecimal color.
22
00:02:35,790 --> 00:02:38,430
We have to actually put that in the quotes as well.
23
00:02:38,430 --> 00:02:40,170
Unlike CSX.
24
00:02:40,620 --> 00:02:47,400
So those are a few differences but besides that you'll find it almost identical to rail or CSX when
25
00:02:47,400 --> 00:02:56,290
you are including your properties in J SS then we save this makes Dale's call with our style object
26
00:02:56,290 --> 00:03:02,900
here to the use styles constant then down in our functional component.
27
00:03:02,900 --> 00:03:11,600
Here we call use styles as a function since it's a hook actually which now gives us access to these
28
00:03:11,600 --> 00:03:18,590
styles under our classes and constant by the time our components are actually rendered.
29
00:03:18,750 --> 00:03:28,890
This J SS is compiled into actual C Ss and so having it here on the classes constant lets us just access
30
00:03:28,950 --> 00:03:38,070
this classes dot root class name you see this syntax we set our class name equal to classes dot root
31
00:03:38,400 --> 00:03:47,320
so classes being this constant here and Dot root because that is the style that we specified here.
32
00:03:47,610 --> 00:03:56,070
So make styles generates our styles and then use styles gives us access to them on our classes.
33
00:03:56,070 --> 00:03:57,630
Constant.
34
00:03:57,820 --> 00:04:06,510
So now we understand how to set up our J SS styles and then get access to them within our component.
35
00:04:06,560 --> 00:04:14,890
Let's go ahead and go into our code editor and see if we can't get this hooked up so here in our header
36
00:04:14,890 --> 00:04:16,030
component.
37
00:04:16,030 --> 00:04:23,230
I'm going to go up to the top and I'm going to import and we're going to d structure this out and that's
38
00:04:23,230 --> 00:04:38,290
the make styles hook make styles from app material dash UI slash styles then we can come down here and
39
00:04:38,290 --> 00:04:46,780
create our constant of use styles and set that equal to our Make styles.
40
00:04:46,780 --> 00:04:52,930
And here we're actually going to use a slightly different syntax than the documentation example which
41
00:04:52,930 --> 00:04:56,920
is going to give us access to the theme inside of our styles.
42
00:04:57,950 --> 00:05:05,380
We'll need a property from the theme to fix our problem with the header sitting on top of our Hello
43
00:05:05,390 --> 00:05:17,150
text so here we'll pull out the theme and begin an arrow function with parentheses.
44
00:05:17,440 --> 00:05:26,050
And then our object in this first style that I want to create I'm going to call the class toolbar margin
45
00:05:26,680 --> 00:05:34,720
and then we'll open this up and inside of here we're going to use the spread operator to copy over some
46
00:05:34,720 --> 00:05:47,110
properties out of our theme the property that we want specifically is theme dot mix ins dot toolbar.
47
00:05:47,350 --> 00:05:54,790
Now to show you what that's doing here let's actually head on over back to the material UI documentation
48
00:05:55,180 --> 00:06:01,150
and come down here to customization and go back to the default theme.
49
00:06:01,150 --> 00:06:04,570
And here you can see the mix ins object.
50
00:06:04,570 --> 00:06:06,270
So I'm going to open that up.
51
00:06:06,760 --> 00:06:13,280
And here you can see the toolbar object that we just referenced inside of there.
52
00:06:13,280 --> 00:06:21,260
You'll see we just have a couple properties first being the mean height of 56 and then a couple of these
53
00:06:21,260 --> 00:06:26,990
media queries which each have a different height by using the spread operator.
54
00:06:27,230 --> 00:06:34,620
We have now copied all of these styles over to where we can now apply them to a component or in this
55
00:06:34,620 --> 00:06:38,730
case actually just a regular h t AML element.
56
00:06:38,770 --> 00:06:46,240
So what we're going to do is go back onto the code and first we need to come right underneath the header
57
00:06:46,240 --> 00:06:55,780
function above the return statement and create our concept classes which is equal to calling our use
58
00:06:55,870 --> 00:07:05,850
styles hook this now gives us access to the tool margin toolbar margin style on our class constant.
59
00:07:05,900 --> 00:07:15,500
And so right below our elevation scroll we can make a div with a class name of remember from the example
60
00:07:15,530 --> 00:07:25,970
that is classes dot toolbar margin classes two reference classes here into a bar margin to give us access
61
00:07:25,970 --> 00:07:33,410
to the style that we created we can go ahead and make this a self closing div because that is all it
62
00:07:33,410 --> 00:07:39,650
needs to do but you can see that I've got a little area right here and that's telling me the adjacent
63
00:07:39,650 --> 00:07:45,500
J OSX elements must be wrapped in an enclosing tag so you can see obviously we cannot have these two
64
00:07:45,500 --> 00:07:47,310
just sitting right next to each other.
65
00:07:47,510 --> 00:07:52,460
And so I actually just want to wrap this in a react fragment
66
00:08:05,620 --> 00:08:12,250
the react fragment just makes it so that I can have those two elements sitting side by side each other
67
00:08:12,310 --> 00:08:18,590
without actually rendering anything else to the page like a wrapper div or something like that.
68
00:08:18,610 --> 00:08:28,120
Now what that div with the toolbar margin class is doing is provided from material UI they give us that
69
00:08:28,130 --> 00:08:33,940
is toolbar mix in so that we can solve this exact problem.
70
00:08:33,940 --> 00:08:42,550
This contains the height of our app bar and when we apply it to this div what it does is it creates
71
00:08:42,580 --> 00:08:50,110
a little cushion under the app bar since the app bar is floating fixed in place at the top of the screen
72
00:08:50,440 --> 00:08:58,090
and then pushes the hidden content underneath it out to where it can be seen on the screen if we go
73
00:08:58,090 --> 00:09:05,950
ahead and save this and then head back over to our application you can see now they are hello is not
74
00:09:05,950 --> 00:09:12,940
being covered up and if you actually go back and you want to get rid of this and save again you flip
75
00:09:12,940 --> 00:09:14,560
back and you see it's gone.
76
00:09:14,800 --> 00:09:19,030
We'll go back and undo save and there it is again.
77
00:09:19,300 --> 00:09:27,130
So like I said that is just putting a little invisible cushion underneath our app bar and making sure
78
00:09:27,130 --> 00:09:33,120
that our content is being pushed out below it to where the user can see it on the screen.
79
00:09:33,310 --> 00:09:39,460
With that in place we'll be ready to actually start putting content on the screen but we still have
80
00:09:39,460 --> 00:09:45,760
plenty of work to do on the header and getting all the navigation setup which we haven't even touched
81
00:09:45,760 --> 00:09:46,160
yet.
82
00:09:46,180 --> 00:09:53,170
So let's go ahead and start working on that and using our new inline styling skills in the next video.
10120
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.