Skip to content

Commit 3905972

Browse files
committed
add basic styles for button component
1 parent a560d01 commit 3905972

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

src/components/Button.module.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@import "../theme/colors.scss";
2+
3+
.button {
4+
background: $theme-link-color;
5+
position: relative;
6+
padding: 8px 20px;
7+
border-top: 0px;
8+
border-left: 0px;
9+
border-right: 0px;
10+
border-bottom: 6px solid $theme-link-color-dark;
11+
color: white;
12+
font-size: 16px;
13+
font-family: Lucida Sans Unicode, sans-serif;
14+
vertical-align: middle;
15+
-webkit-border-radius: 6px;
16+
-moz-border-radius: 6px;
17+
border-radius: 6px;
18+
-webkit-box-shadow: 0px 1px 6px 1px #999999;
19+
box-shadow: 0px 1px 6px 1px #999999;
20+
transition: all 0.1s;
21+
&:hover {
22+
top: -1px;
23+
border-bottom: 7px solid $theme-link-color-dark;
24+
background: $theme-link-color;
25+
}
26+
&:active {
27+
top: 2px;
28+
border-bottom: 4px solid $theme-link-color-dark;
29+
background: $theme-link-color-dark;
30+
-webkit-box-shadow: none;
31+
box-shadow: none;
32+
}
33+
}

src/components/Button.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React from "react";
2+
import styles from "./Button.module.scss";
23

34
// Define an interface for the props of the button component
45
interface ButtonProps {
5-
text: string; // The text to display on the button
66
onClick: () => void; // The handler function for the click event
77
disabled?: boolean; // An optional prop to disable the button
8+
children: React.ReactNode;
89
}
910

1011
// Define a custom button component that renders a button element
11-
const Button: React.FC<ButtonProps> = ({ text, onClick, disabled }) => {
12+
const Button: React.FC<ButtonProps> = ({ onClick, disabled, children }) => {
1213
// Return the JSX element for the button component
1314
return (
14-
<button onClick={onClick} disabled={disabled}>
15-
{text}
15+
<button className={styles.button} onClick={onClick} disabled={disabled}>
16+
{children}
1617
</button>
1718
);
1819
};

src/features/counter/Counter.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from "react";
22
import { useDispatch, useSelector } from "react-redux";
33
import { RootState } from "../../app/rootReducer";
44
import { increment, decrement, incrementByAmount } from "./counterSlice";
5+
import Button from "../../components/Button";
56

67
// Define a counter component that uses the redux state and actions
78
const Counter: React.FC = () => {
@@ -48,10 +49,10 @@ const Counter: React.FC = () => {
4849
<div>
4950
<h1>Counter</h1>
5051
<p>The current counter value is {counter}</p>
51-
<button onClick={handleIncrement}>Increment</button>
52-
<button onClick={handleDecrement}>Decrement</button>
52+
<Button onClick={handleIncrement}>Increment</Button>
53+
<Button onClick={handleDecrement}>Decrement</Button>
5354
<input value={incrementAmount} onChange={handleIncrementAmountChange} />
54-
<button onClick={handleIncrementByAmount}>Increment by amount</button>
55+
<Button onClick={handleIncrementByAmount}>Increment by amount</Button>
5556
</div>
5657
);
5758
};

src/theme/colors.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
$theme-link-color: #ff5733;
1+
$theme-link-color: #ff5733;
2+
$theme-link-color-dark: #fe3e13;
3+
$white: #ffffff;

0 commit comments

Comments
 (0)