Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,291 --> 00:00:03,960
[Maximilian Schwarzm�ller] So now that we use CSS modules,
2
00:00:03,960 --> 00:00:05,510
let's also use the concept here
3
00:00:05,510 --> 00:00:07,520
in the course input component.
4
00:00:07,520 --> 00:00:09,600
We got the course input CSS file,
5
00:00:09,600 --> 00:00:11,520
and as you learned, you need to change the name
6
00:00:11,520 --> 00:00:13,830
to .module.css
7
00:00:13,830 --> 00:00:15,740
With that, I mean the file name.
8
00:00:15,740 --> 00:00:17,973
So CourseInput.module.css.
9
00:00:19,540 --> 00:00:22,550
In the course input component, you then import
10
00:00:22,550 --> 00:00:24,360
from CourseInput.module.
11
00:00:24,360 --> 00:00:28,220
And as you learned, you import something from there.
12
00:00:28,220 --> 00:00:29,860
Again, the name is totally up to you.
13
00:00:29,860 --> 00:00:32,580
Typically you name it styles or classes
14
00:00:32,580 --> 00:00:34,510
or anything like that.
15
00:00:34,510 --> 00:00:37,470
We can remove the styled import from styled components
16
00:00:37,470 --> 00:00:41,460
because I'm going to comment out this form control
17
00:00:41,460 --> 00:00:42,293
like this.
18
00:00:42,293 --> 00:00:44,270
I'm not going to use it anymore.
19
00:00:44,270 --> 00:00:47,790
Instead down there, I'll go back to my good old div,
20
00:00:47,790 --> 00:00:51,550
and on that div, I will add class name
21
00:00:51,550 --> 00:00:53,127
to styles dot
22
00:00:53,127 --> 00:00:54,940
form
23
00:00:54,940 --> 00:00:55,773
control.
24
00:00:55,773 --> 00:00:57,200
And now we have a problem.
25
00:00:57,200 --> 00:00:58,907
This is an invalid property name,
26
00:00:58,907 --> 00:01:02,003
but I named my class form control in here.
27
00:01:03,040 --> 00:01:04,260
Well, it's not a problem.
28
00:01:04,260 --> 00:01:06,010
We just have to use a different syntax
29
00:01:06,010 --> 00:01:07,700
for accessing the property.
30
00:01:07,700 --> 00:01:10,580
We use the square brackets and wrap this name
31
00:01:10,580 --> 00:01:13,090
into single quotes.
32
00:01:13,090 --> 00:01:16,000
This is how we can also access properties in JavaScript.
33
00:01:16,000 --> 00:01:18,280
And with that, we can also access properties
34
00:01:18,280 --> 00:01:19,313
with such a name,
35
00:01:21,600 --> 00:01:25,350
because strings are valid keys in JavaScript objects.
36
00:01:25,350 --> 00:01:28,540
Alternatively, of course, you pick different CSS class names
37
00:01:28,540 --> 00:01:29,913
without dashes in them.
38
00:01:30,906 --> 00:01:32,840
Here, however, I'll stick to that.
39
00:01:32,840 --> 00:01:35,830
And there, for now, we got our styling back.
40
00:01:35,830 --> 00:01:39,800
Now, of course the invalid style is not getting applied.
41
00:01:39,800 --> 00:01:41,016
And the reason for that is simple.
42
00:01:41,016 --> 00:01:43,490
For that invalid style to be applied,
43
00:01:43,490 --> 00:01:46,440
we need to make sure that the invalid CSS class
44
00:01:46,440 --> 00:01:48,610
is added on the element.
45
00:01:48,610 --> 00:01:50,240
And currently that's never happening.
46
00:01:50,240 --> 00:01:53,640
We're only adding foreign control, only adding this class
47
00:01:53,640 --> 00:01:56,840
or the transfer in CSS modules version of that class,
48
00:01:56,840 --> 00:01:57,830
to be precise.
49
00:01:57,830 --> 00:02:01,403
We're never adding the transformed invalid class version.
50
00:02:02,740 --> 00:02:05,360
It is something we can also do easily though.
51
00:02:05,360 --> 00:02:09,229
We can go back to that backtick syntax
52
00:02:09,229 --> 00:02:11,400
to create a string where we inject values.
53
00:02:11,400 --> 00:02:13,270
And the first value I want to inject
54
00:02:13,270 --> 00:02:16,933
is that resolved class name here.
55
00:02:18,480 --> 00:02:21,720
So I inject this converted class name,
56
00:02:21,720 --> 00:02:22,553
which we're in the end,
57
00:02:22,553 --> 00:02:25,800
extracting from that styles object here into this string.
58
00:02:25,800 --> 00:02:28,403
With that, if we save this, nothing should change.
59
00:02:29,330 --> 00:02:30,990
And now, of course, just as before,
60
00:02:30,990 --> 00:02:33,740
we can add an additional clause here.
61
00:02:33,740 --> 00:02:35,750
We can check if not is valid,
62
00:02:35,750 --> 00:02:40,410
and if that's the case, I add styles.invalid here
63
00:02:40,410 --> 00:02:44,890
referring to that converted version of that invalid class.
64
00:02:44,890 --> 00:02:48,450
Converted because that's what the CSS module process
65
00:02:48,450 --> 00:02:49,823
will do behind the scenes.
66
00:02:50,930 --> 00:02:55,930
And invalid because the CSS class name is invalid in here.
67
00:02:56,050 --> 00:02:58,350
So with that, we're adding this converted version
68
00:02:58,350 --> 00:03:02,750
of our own class, this scoped version of this CSS styling,
69
00:03:02,750 --> 00:03:03,740
so to say,
70
00:03:03,740 --> 00:03:07,620
to this div if isValid is false.
71
00:03:07,620 --> 00:03:09,810
If we now save us and we go back,
72
00:03:09,810 --> 00:03:11,680
if I click add goal, it's red.
73
00:03:11,680 --> 00:03:13,890
If I type, it's no longer red,
74
00:03:13,890 --> 00:03:16,260
it gets red again and so on.
75
00:03:16,260 --> 00:03:17,544
So this now works again,
76
00:03:17,544 --> 00:03:22,544
but now we're adding dynamic classes here with CSS modules.
77
00:03:23,150 --> 00:03:26,800
It's not really that different from normal classes
78
00:03:26,800 --> 00:03:29,470
because these are normal classes.
79
00:03:29,470 --> 00:03:32,700
We just extract the converted class names
80
00:03:32,700 --> 00:03:36,350
as they were generated by CSS modules, that's all.
81
00:03:36,350 --> 00:03:38,463
And then we combine them as needed.
82
00:03:39,350 --> 00:03:41,660
Last but not least, let's see how media queries
83
00:03:41,660 --> 00:03:44,070
are set up in CSS modules.
84
00:03:44,070 --> 00:03:46,870
And for that, let's go back to the button.
85
00:03:46,870 --> 00:03:50,320
There I had a media query in my styled components,
86
00:03:50,320 --> 00:03:53,170
so we can copy that and go to the CSS file
87
00:03:53,170 --> 00:03:54,810
which we're using now.
88
00:03:54,810 --> 00:03:58,480
And here you just add a media query as you would always
89
00:03:58,480 --> 00:04:00,253
add it, maybe here at the bottom.
90
00:04:01,160 --> 00:04:04,023
Let me get rid of these slashes.
91
00:04:05,030 --> 00:04:07,540
The important difference to styled components, of course,
92
00:04:07,540 --> 00:04:10,020
is that now you need your selector again.
93
00:04:10,020 --> 00:04:12,380
You always need that in CSS.
94
00:04:12,380 --> 00:04:15,830
The non selector syntax here in styled components
95
00:04:15,830 --> 00:04:17,950
is really just a styled components feature
96
00:04:17,950 --> 00:04:20,740
because it processes your CSS code.
97
00:04:20,740 --> 00:04:24,283
This is not CSS code that would work like this in a browser
98
00:04:24,283 --> 00:04:26,850
because CSS always needs a selector.
99
00:04:26,850 --> 00:04:29,800
And that's why we need to add a selector here.
100
00:04:29,800 --> 00:04:31,670
With that, however, we got everything we need.
101
00:04:31,670 --> 00:04:36,040
We set the width here to 100% on small devices,
102
00:04:36,040 --> 00:04:39,820
and then on bigger screens, we reset it to auto,
103
00:04:39,820 --> 00:04:41,360
and that should be all that's needed.
104
00:04:41,360 --> 00:04:43,920
No other changes are required because I'm working
105
00:04:43,920 --> 00:04:47,152
on the same CSS class, which I'm already adding
106
00:04:47,152 --> 00:04:48,943
to the component here.
107
00:04:50,260 --> 00:04:53,540
So with that, you'll see, I have the big button there,
108
00:04:53,540 --> 00:04:55,990
and on bigger screens, it's a smaller one.
109
00:04:55,990 --> 00:05:00,740
So that all works and it also works with CSS modules.
110
00:05:00,740 --> 00:05:03,240
Now, ultimately, it's absolutely up to you
111
00:05:03,240 --> 00:05:05,130
which approach you prefer.
112
00:05:05,130 --> 00:05:07,210
I showed you the CSS only,
113
00:05:07,210 --> 00:05:10,400
the styled components, and the CSS modules approach
114
00:05:10,400 --> 00:05:12,870
and then mentioned the different pros and cons.
115
00:05:12,870 --> 00:05:16,110
And you can simply use the approach you like.
116
00:05:16,110 --> 00:05:17,470
For the rest of this course,
117
00:05:17,470 --> 00:05:21,380
I will use CSS modules because I liked that scoping.
118
00:05:21,380 --> 00:05:23,320
and I like having my CSS code
119
00:05:23,320 --> 00:05:25,200
and my JavaScript code separated.
120
00:05:25,200 --> 00:05:27,250
But if you prefer a different approach,
121
00:05:27,250 --> 00:05:29,363
that's, of course, also perfectly fine.
9400
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.