Skip to content

Commit 483d245

Browse files
author
Prafful Kumar
committed
button type to interface
1 parent e301663 commit 483d245

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/App.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ function App() {
1414
>
1515
Click me please
1616
</Button><br /><br />
17-
<Button
18-
outline
19-
>
17+
<Button>
2018
Hello
2119
</Button>
2220
</div>

src/components/Button.tsx

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
import { ButtonHTMLAttributes } from 'react';
12
import styled from 'styled-components';
3+
import { PRIMARY_COLOR } from '../theme';
24

3-
type Props = {
4-
children: React.ReactNode,
5-
background?: string,
6-
color?: string,
7-
borderColor?: string,
8-
uppercase?: Boolean,
9-
round?: Boolean,
10-
outline?: Boolean,
11-
raise?: Boolean,
12-
fontWeight?: string | number
13-
boxShadow?: Boolean,
5+
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
6+
children: React.ReactNode;
7+
background?: string;
8+
color?: string;
9+
borderColor?: string;
10+
uppercase?: Boolean;
11+
round?: Boolean;
12+
outline?: Boolean;
13+
raise?: Boolean;
14+
fontWeight?: string | number;
15+
boxShadow?: Boolean;
16+
square?: Boolean;
1417
}
1518

1619
function Button({
1720
children,
18-
background = '#ff5a5f',
21+
background = PRIMARY_COLOR,
1922
color,
2023
borderColor,
21-
uppercase,
22-
round,
23-
outline,
24-
raise,
24+
uppercase = false,
25+
round = false,
26+
outline = false,
27+
raise = false,
2528
fontWeight,
2629
boxShadow = true,
30+
square = false,
2731
...props
2832
}: Props) {
2933

@@ -32,29 +36,26 @@ function Button({
3236
border: ${borderColor || outline ? '1px solid ' + (borderColor || background) : 'none'};
3337
color: ${outline ? color || background : color || '#fff'};
3438
font-size: 14px;
35-
border-radius: ${round ? '20px' : '5px'};
39+
border-radius: ${square ? '0px' : round ? '20px' : '5px'};
3640
font-weight: ${fontWeight || null};
37-
3841
line-height: 15px;
3942
padding: 10px;
40-
4143
letter-spacing: 0.3px;
4244
text-transform: ${uppercase ? 'uppercase' : ''};
4345
cursor: pointer;
44-
4546
&:focus{
4647
outline: none;
4748
}
48-
&:active, {
49+
&:active{
4950
outline: none;
50-
box-shadow: 0 3px 0 rgb(9 30 66 / 10%);
51+
box-shadow: 0 3px 0 rgb(9 30 66 / 10 %);
5152
top: 3px;
5253
}
5354
&:hover{
5455
box-shadow: ${boxShadow ? '0 3px 5px rgb(9 30 66 / 10%), 0 0 1px rgb(9 30 66 / 31%)' : ''};
5556
transform: ${raise ? 'translate3d(0px, -2px, 0px)' : 'none'};
56-
}
57-
`
57+
}
58+
`
5859

5960
return (
6061
<StyledButton

src/theme.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const PRIMARY_COLOR:string='#ff5a5f';

0 commit comments

Comments
 (0)