Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,140 --> 00:00:04,030
So, time for a button.
2
00:00:04,030 --> 00:00:08,070
Just like a card, a button is a default UI element
3
00:00:08,070 --> 00:00:08,903
which we're going to use
4
00:00:08,903 --> 00:00:10,870
in different parts of the application.
5
00:00:10,870 --> 00:00:13,660
Therefore, here I'll add a Button.js file,
6
00:00:13,660 --> 00:00:15,470
and I already mentioned it,
7
00:00:15,470 --> 00:00:18,820
attached, you find a Button.Module.css file
8
00:00:18,820 --> 00:00:21,360
which I'll again download and drag and drop
9
00:00:21,360 --> 00:00:25,193
into that UI folder next to the Button.js file.
10
00:00:26,730 --> 00:00:28,710
Now inside of the Button.js file,
11
00:00:28,710 --> 00:00:30,360
we can import React from React
12
00:00:30,360 --> 00:00:32,689
because we're going to write some JSX code.
13
00:00:32,689 --> 00:00:34,100
We can import classes
14
00:00:34,100 --> 00:00:39,100
from dot slash Button.Module.css already.
15
00:00:39,400 --> 00:00:42,030
And we can then define our button constant,
16
00:00:42,030 --> 00:00:45,610
which is our functional component, and export,
17
00:00:45,610 --> 00:00:49,290
whoops, export this as a default.
18
00:00:49,290 --> 00:00:51,580
And now in here, I simply want to return
19
00:00:51,580 --> 00:00:53,280
the built-in button component,
20
00:00:53,280 --> 00:00:55,670
but of course, with my default styling applied
21
00:00:55,670 --> 00:00:58,113
and with some configuration options.
22
00:00:58,950 --> 00:01:00,290
To start with the styling,
23
00:01:00,290 --> 00:01:04,569
I'll add class name and point at classes.button
24
00:01:04,569 --> 00:01:06,930
because in the Button.Module.css file,
25
00:01:06,930 --> 00:01:08,800
you'll find that button class
26
00:01:08,800 --> 00:01:11,370
so we can use it thanks to CSS Modules
27
00:01:11,370 --> 00:01:13,043
to apply a little styling here.
28
00:01:14,230 --> 00:01:15,380
I also want to make sure
29
00:01:15,380 --> 00:01:17,320
that the type of the button can be set,
30
00:01:17,320 --> 00:01:20,380
and I want to make sure it can be set from outside,
31
00:01:20,380 --> 00:01:21,580
so from the place
32
00:01:21,580 --> 00:01:24,500
where we use our accustomed button component.
33
00:01:24,500 --> 00:01:27,030
They offer the value assigned to the type prop
34
00:01:27,030 --> 00:01:29,960
on the built in button component will be dynamic,
35
00:01:29,960 --> 00:01:34,210
and I will simply access props.type here,
36
00:01:34,210 --> 00:01:35,970
but also provide a fallback
37
00:01:35,970 --> 00:01:39,450
in case that should not be set with the or operator.
38
00:01:39,450 --> 00:01:41,303
The alternative is button.
39
00:01:42,160 --> 00:01:44,150
So if props.type is undefined,
40
00:01:44,150 --> 00:01:47,440
this button value will be used as a fallback type
41
00:01:47,440 --> 00:01:48,693
for the built in button.
42
00:01:50,040 --> 00:01:52,210
Now, in addition, I'll add onClick,
43
00:01:52,210 --> 00:01:56,490
and here, I expect to get a handler function
44
00:01:56,490 --> 00:01:58,920
via props on my own button component,
45
00:01:58,920 --> 00:02:03,170
so I'll simply forward this to props onClick.
46
00:02:03,170 --> 00:02:05,380
Now that name here is totally up to you.
47
00:02:05,380 --> 00:02:07,680
You don't have to name it onClick, but again,
48
00:02:07,680 --> 00:02:10,669
I want to make my own button basically usable
49
00:02:10,669 --> 00:02:12,100
like the built in button,
50
00:02:12,100 --> 00:02:14,590
and therefore I use the same naming.
51
00:02:14,590 --> 00:02:18,400
So I will have a onClick prop on my button component,
52
00:02:18,400 --> 00:02:20,470
and any function received there
53
00:02:20,470 --> 00:02:23,320
is just passed onto the built in button component
54
00:02:23,320 --> 00:02:25,223
through its onClick prop.
55
00:02:26,350 --> 00:02:28,640
And last but not least here,
56
00:02:28,640 --> 00:02:30,090
I also want to be able to output
57
00:02:30,090 --> 00:02:32,480
some content between the button tags,
58
00:02:32,480 --> 00:02:34,670
and I expect to get that content
59
00:02:34,670 --> 00:02:36,660
between the tags of my own button,
60
00:02:36,660 --> 00:02:40,143
and therefore we use the special children prop here.
61
00:02:41,620 --> 00:02:43,480
That should be all.
62
00:02:43,480 --> 00:02:46,950
Now we can go to add user where we have a button,
63
00:02:46,950 --> 00:02:49,340
and use our own custom button.
64
00:02:49,340 --> 00:02:52,360
And hopefully I can now just replace built in button,
65
00:02:52,360 --> 00:02:54,820
which is lowercase, with my custom button,
66
00:02:54,820 --> 00:02:56,650
which starts with a capital B
67
00:02:56,650 --> 00:02:58,980
per the convention that your components
68
00:02:58,980 --> 00:03:01,720
should always start with capital characters.
69
00:03:01,720 --> 00:03:04,730
And we now just need to import it because as I mentioned,
70
00:03:04,730 --> 00:03:06,770
you need to import all things
71
00:03:06,770 --> 00:03:08,630
you want to use from other files.
72
00:03:08,630 --> 00:03:11,190
So here, I'll import button from,
73
00:03:11,190 --> 00:03:14,933
going up one level, UI Button like this.
74
00:03:16,200 --> 00:03:17,850
And if we now save that,
75
00:03:17,850 --> 00:03:19,410
we get this nice looking button
76
00:03:19,410 --> 00:03:21,870
which should work just like the built in button
77
00:03:21,870 --> 00:03:22,703
because in the end,
78
00:03:22,703 --> 00:03:25,660
it just wraps the built in button, of course.
79
00:03:25,660 --> 00:03:27,900
But that's the idea behind all React components.
80
00:03:27,900 --> 00:03:29,640
In the end, you always compose them all
81
00:03:29,640 --> 00:03:31,910
from the building and HTML components,
82
00:03:31,910 --> 00:03:33,660
but you structure them in a certain way
83
00:03:33,660 --> 00:03:35,450
and maybe attach certain logic
84
00:03:35,450 --> 00:03:37,890
so that you have your own components.
85
00:03:37,890 --> 00:03:40,060
And with that, that looks quite well.
86
00:03:40,060 --> 00:03:42,880
Now let's make sure we actually fetch user input,
87
00:03:42,880 --> 00:03:46,450
and we then kind of start rendering a list of users
88
00:03:46,450 --> 00:03:48,193
below that input form here.
6713
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.