Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,180 --> 00:00:04,560
So let's work on that modal.
2
00:00:04,560 --> 00:00:08,690
For that in the UI folder, I'll add a modal JS file.
3
00:00:08,690 --> 00:00:10,500
And that hatched unsurprisingly,
4
00:00:10,500 --> 00:00:13,780
you find this styling file for this modal,
5
00:00:13,780 --> 00:00:17,090
the modal module CSS file.
6
00:00:17,090 --> 00:00:21,280
And then here we have that modal, which will receive props.
7
00:00:21,280 --> 00:00:25,473
And of course we export this component, like this.
8
00:00:26,350 --> 00:00:29,150
And then here, we can also import classes
9
00:00:29,150 --> 00:00:32,860
from dot slash modal dot module dot CSS,
10
00:00:32,860 --> 00:00:35,713
and then work on the markup for this modal.
11
00:00:37,000 --> 00:00:41,010
And here I will have a special markup kind of
12
00:00:41,010 --> 00:00:45,700
because I wanna use React Portal for both my backdrop.
13
00:00:45,700 --> 00:00:48,830
So that thing behind the modal overlay
14
00:00:48,830 --> 00:00:52,210
which blocks interaction with the rest of the page.
15
00:00:52,210 --> 00:00:55,190
And I also wanna render the modal overlay itself
16
00:00:55,190 --> 00:01:00,190
with React Portal to use that component wherever I want
17
00:01:00,470 --> 00:01:03,760
by to render the actual HTML elements
18
00:01:03,760 --> 00:01:07,020
in a specific place in the DOM tree.
19
00:01:07,020 --> 00:01:08,880
That is something you learned about
20
00:01:08,880 --> 00:01:11,173
earlier in the course Portals.
21
00:01:12,420 --> 00:01:15,850
And to render a Portal, we first of all need to go
22
00:01:15,850 --> 00:01:19,743
to the public folder and they are the index HTML file.
23
00:01:20,820 --> 00:01:24,580
And here we got this root div where the overall
24
00:01:24,580 --> 00:01:26,910
React application is being rendered.
25
00:01:26,910 --> 00:01:29,070
And above that route div,
26
00:01:29,070 --> 00:01:33,373
I will add a number div with an ID of over lace.
27
00:01:34,220 --> 00:01:39,220
And that is the div where I wanna Portal my modal
28
00:01:39,430 --> 00:01:40,923
and the backdrop too.
29
00:01:41,790 --> 00:01:45,040
So that is a change we need to make to any HTML.
30
00:01:45,040 --> 00:01:48,280
And with that back in the modal JS file
31
00:01:48,280 --> 00:01:50,420
we can create the backdrop
32
00:01:50,420 --> 00:01:53,253
and the overlay and then use the Portal.
33
00:01:54,540 --> 00:01:57,090
Now it will create two separate components for debt.
34
00:01:57,090 --> 00:02:00,000
And since they are really closely tied
35
00:02:00,000 --> 00:02:03,520
to this modal component and both very lean
36
00:02:03,520 --> 00:02:06,060
I will treat them here in the same file.
37
00:02:06,060 --> 00:02:08,240
But if you go for a separate files
38
00:02:08,240 --> 00:02:10,312
that of course would also be fine.
39
00:02:11,430 --> 00:02:12,960
But I will add the backdrop
40
00:02:12,960 --> 00:02:16,900
component function here in this file.
41
00:02:16,900 --> 00:02:21,180
And then also the modal overlay component function
42
00:02:21,180 --> 00:02:25,373
and both received props because both will receive data.
43
00:02:26,450 --> 00:02:30,163
Now for the backdrop, we return a div with a class name
44
00:02:30,163 --> 00:02:34,580
of classes dot backdrop using that backdrop CSS class
45
00:02:36,004 --> 00:02:40,195
which is defined in the modal module CSS file.
46
00:02:40,195 --> 00:02:43,280
And for the overlay, I will return a div
47
00:02:43,280 --> 00:02:46,363
the class name off clauses dot modal.
48
00:02:47,283 --> 00:02:49,993
And inside of that, I'll have a number div
49
00:02:49,993 --> 00:02:53,410
with a class name of Classes dot content.
50
00:02:55,240 --> 00:02:58,920
I simply have these two devs for styling purposes.
51
00:02:58,920 --> 00:03:03,920
And then inside of that inner div I'll put prompts children.
52
00:03:04,100 --> 00:03:07,620
So in the end, this will be the actual content passed
53
00:03:07,620 --> 00:03:10,560
between the modal opening and closing tax by it
54
00:03:10,560 --> 00:03:13,193
a component where the modal is getting used.
55
00:03:14,040 --> 00:03:16,840
It won't work right now, but it will work in the future.
56
00:03:17,860 --> 00:03:19,370
So now we got these components
57
00:03:20,320 --> 00:03:25,290
now here in the modal function which is the main component
58
00:03:25,290 --> 00:03:27,360
which is being exported here.
59
00:03:27,360 --> 00:03:30,180
We now of course all need to return some markup.
60
00:03:30,180 --> 00:03:33,920
And there, I wanna have backdrop and overlay site by site.
61
00:03:33,920 --> 00:03:36,260
And for this we'll need the fragment.
62
00:03:36,260 --> 00:03:39,400
So I'll import fragment from React
63
00:03:40,820 --> 00:03:43,410
and then simply return fragment.
64
00:03:43,410 --> 00:03:48,410
And in there now backdrop and modal overlay
65
00:03:50,290 --> 00:03:54,750
and this is how we could do it, or actually modal overlay
66
00:03:54,750 --> 00:03:59,140
like this to forward the content between the modal tech.
67
00:03:59,140 --> 00:04:00,700
But this is how we could do it
68
00:04:00,700 --> 00:04:03,800
if we would not be using the Portal.
69
00:04:03,800 --> 00:04:06,580
Now we technically don't have to use a Portal
70
00:04:06,580 --> 00:04:10,700
but to ensure that our HTML code is not all over the place
71
00:04:10,700 --> 00:04:14,210
in the final application, I will use Portals here.
72
00:04:14,210 --> 00:04:17,160
And therefore I will output two dynamic expressions here.
73
00:04:17,160 --> 00:04:21,300
Side-by-side and that will call the create Portal method
74
00:04:21,300 --> 00:04:25,420
which is built into React in both these expressions.
75
00:04:25,420 --> 00:04:26,910
For div we need to import it
76
00:04:26,910 --> 00:04:30,020
and it is actually important or it is a way liable
77
00:04:30,020 --> 00:04:33,853
on the React DOM object from React dash DOM.
78
00:04:34,820 --> 00:04:39,380
So not the React library itself, but the React DOM library
79
00:04:39,380 --> 00:04:42,163
which of course also is by the React team though.
80
00:04:43,350 --> 00:04:45,610
And with this import add a day offer
81
00:04:45,610 --> 00:04:49,090
we can access React on create Portal
82
00:04:49,090 --> 00:04:51,350
and create a Portal for the backdrop
83
00:04:52,760 --> 00:04:55,080
and do the same down there.
84
00:04:55,080 --> 00:05:00,080
React on webs, React on create Portal for the modal overlay.
85
00:05:01,920 --> 00:05:05,030
And here we need to pass props children
86
00:05:05,030 --> 00:05:07,170
between the opening and closing tax.
87
00:05:07,170 --> 00:05:09,963
So that in the modal overlaid that can be used.
88
00:05:12,950 --> 00:05:16,600
Now create Portal needs a second argument though.
89
00:05:16,600 --> 00:05:19,840
It does not just need to know what to Portal
90
00:05:19,840 --> 00:05:21,533
but also where to Portal it.
91
00:05:22,370 --> 00:05:25,760
And the effort we should select is div here
92
00:05:25,760 --> 00:05:29,723
with the idea overlays in our index HTML file.
93
00:05:30,850 --> 00:05:33,840
Now, since we will need that in both creative Portal calls
94
00:05:33,840 --> 00:05:36,120
I will create a help or constant here,
95
00:05:36,120 --> 00:05:39,420
which I'll name Portal element.
96
00:05:39,420 --> 00:05:41,600
Obviously the name is up to you
97
00:05:41,600 --> 00:05:44,820
and here we can access document get element by ID
98
00:05:44,820 --> 00:05:47,893
overlays to get access to that overlay stiff.
99
00:05:48,740 --> 00:05:52,720
And then it's this Portal element, which I pass
100
00:05:52,720 --> 00:05:57,300
as a second argument to both create Portal calls.
101
00:05:57,300 --> 00:06:00,800
And that's not a finished code for debt modal
102
00:06:00,800 --> 00:06:01,863
at least for now.
103
00:06:03,430 --> 00:06:05,490
And with that code, we can go back
104
00:06:05,490 --> 00:06:10,020
to the cart component and there replaced
105
00:06:10,020 --> 00:06:13,963
that wrapping div with modal.
106
00:06:16,020 --> 00:06:19,490
Like this, obviously for div we need to import the modal
107
00:06:19,490 --> 00:06:20,930
component first though.
108
00:06:20,930 --> 00:06:25,930
So import modal from going up one level UI modal
109
00:06:27,710 --> 00:06:31,143
not from the CSS Faldo, but from the JS file.
110
00:06:32,380 --> 00:06:36,603
And then we can use modal as our opening and closing tack.
111
00:06:37,890 --> 00:06:40,050
And to see this in action now
112
00:06:40,050 --> 00:06:42,770
we need to use that card component somewhere
113
00:06:43,920 --> 00:06:47,040
and I will use it in the app JS file.
114
00:06:47,040 --> 00:06:51,560
So here I will now import cart
115
00:06:51,560 --> 00:06:55,140
from dot slash components cart
116
00:06:55,140 --> 00:06:58,630
and then the cart JS file like this,
117
00:06:58,630 --> 00:07:00,860
and then maybe above the header,
118
00:07:00,860 --> 00:07:03,600
the exact position doesn't matter too much
119
00:07:03,600 --> 00:07:06,400
since we use a modal with a Portal anyways
120
00:07:06,400 --> 00:07:08,453
but here I will then add cart,
121
00:07:09,600 --> 00:07:12,383
not card, but cart like this.
122
00:07:13,500 --> 00:07:17,240
And if he saved us, we should have this cart modal here.
123
00:07:17,240 --> 00:07:19,100
Now at the moment it's always there
124
00:07:19,100 --> 00:07:21,460
and we can't make it disappear
125
00:07:21,460 --> 00:07:24,000
but that is something we're going to add next
126
00:07:24,000 --> 00:07:26,510
because of course it shouldn't always be there.
127
00:07:26,510 --> 00:07:29,240
It should be data when the, your cart button is clicked.
128
00:07:29,240 --> 00:07:31,870
And of course it should also be closable.
129
00:07:31,870 --> 00:07:34,250
And that is definitely also something you
130
00:07:34,250 --> 00:07:37,240
can try implementing on your own
131
00:07:37,240 --> 00:07:39,320
but of course we're going to do it together
132
00:07:39,320 --> 00:07:40,663
in the next lecture.
10722
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.