Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit e086a2c

Browse files
author
mtbyk
committed
カウンタ追加
1 parent 8f62ca6 commit e086a2c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Template } from './components/Template'
33
import { Box, Flex } from '@chakra-ui/react'
44
import { HelloWorld } from './components/HelloWorld'
55
import { Home } from './components/Home'
6+
import { Counter } from './components/Counter'
67

78
function App() {
89
return (
@@ -25,6 +26,9 @@ function App() {
2526
<Link to="/hello" color="white">
2627
Hello
2728
</Link>
29+
<Link to="/counter" color="white">
30+
Counter
31+
</Link>
2832
</Flex>
2933

3034
{/* 各ページを表示するエリア */}
@@ -33,6 +37,7 @@ function App() {
3337
<Route path="/" element={<Home />} />
3438
<Route path="/template" element={<Template />} />
3539
<Route path="/hello" element={<HelloWorld />} />
40+
<Route path="/counter" element={<Counter />} />
3641
</Routes>
3742
</Box>
3843
</Box>

src/components/Counter.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useState } from "react";
2+
import { Box, VStack, Text, Center } from "@chakra-ui/react";
3+
4+
export function Counter() {
5+
const [count, setCount] = useState(0);
6+
7+
return (
8+
<Center h="100vh">
9+
<VStack
10+
w="auto"
11+
h="auto"
12+
padding={'40px 80px'}
13+
justifyContent="center"
14+
border="1px solid white"
15+
borderRadius="10px"
16+
gap={'20px'}
17+
>
18+
<Text fontSize="8xl" fontWeight="bold">
19+
{count}
20+
</Text>
21+
<Box
22+
display="flex"
23+
justifyContent="center"
24+
alignItems="center"
25+
gap="20px"
26+
>
27+
<button onClick={() => setCount(count + 1)}>
28+
<Text fontSize="6xl" fontWeight="bold">
29+
+
30+
</Text>
31+
</button>
32+
<button onClick={() => setCount(count - 1)}>
33+
<Text fontSize="6xl" fontWeight="bold">
34+
-
35+
</Text>
36+
</button>
37+
</Box>
38+
</VStack>
39+
</Center>
40+
);
41+
}

0 commit comments

Comments
 (0)