diff --git a/src/App.tsx b/src/App.tsx index a53698a..880fe3c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React from "react"; +import { Counter } from "./components"; +import logo from "./logo.svg"; +import "./App.css"; function App() { return ( @@ -19,6 +20,9 @@ function App() { Learn React +
+ +
); } diff --git a/src/components/Counter/Counter.module.css b/src/components/Counter/Counter.module.css new file mode 100644 index 0000000..ed90bc1 --- /dev/null +++ b/src/components/Counter/Counter.module.css @@ -0,0 +1,18 @@ +.button { + margin: 0 8px; + padding: 8px 16px; + font-size: 14px; + background-color: #00cbf0; + color: #ffffff; + font-weight: bold; + border: none; + border-radius: 4px; +} + +.buttonsWrapper { + margin: 8px; +} + +.resetButton { + text-transform: uppercase; +} diff --git a/src/components/Counter/Counter.test.tsx b/src/components/Counter/Counter.test.tsx new file mode 100644 index 0000000..583a30f --- /dev/null +++ b/src/components/Counter/Counter.test.tsx @@ -0,0 +1,12 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; + +import { Counter } from "./Counter"; + +describe(Counter.name, () => { + it("renders correctly", () => { + render(); + const counterValue = screen.getByText("Counter: 0"); + expect(counterValue).toBeInTheDocument(); + }); +}); diff --git a/src/components/Counter/Counter.tsx b/src/components/Counter/Counter.tsx new file mode 100644 index 0000000..ea266c2 --- /dev/null +++ b/src/components/Counter/Counter.tsx @@ -0,0 +1,35 @@ +import React, { useState } from "react"; + +import styles from "./Counter.module.css"; + +type CounterProps = { + initialValue: number; +}; + +const Counter = ({ initialValue = 0 }: CounterProps) => { + const [counter, setCounter] = useState(initialValue); + const increase = () => setCounter(counter + 1); + const decrease = () => setCounter(counter + 1); + const reset = () => setCounter(0); + + return ( + <> +

Counter: {counter}

+
+ + +
+
+ +
+ + ); +}; + +export { Counter }; diff --git a/src/components/Counter/index.ts b/src/components/Counter/index.ts new file mode 100644 index 0000000..f32fe91 --- /dev/null +++ b/src/components/Counter/index.ts @@ -0,0 +1 @@ +export * from "./Counter"; diff --git a/src/components/index.ts b/src/components/index.ts new file mode 100644 index 0000000..f32fe91 --- /dev/null +++ b/src/components/index.ts @@ -0,0 +1 @@ +export * from "./Counter";