Skip to content

Commit c292a6c

Browse files
author
Prafful Kumar
committed
input
1 parent 483d245 commit c292a6c

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

src/App.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Button from "./components/Button";
2+
import Input from "./components/Input";
23

34
function App() {
45
return (
@@ -7,16 +8,26 @@ function App() {
78
// background: 'rgb(47 116 192)',
89
height: '100vh',
910
padding: '20px',
11+
display: 'flex',
12+
flexDirection: 'column',
13+
width: '20%',
1014
}}
1115
>
1216
<Button
1317
raise
1418
>
1519
Click me please
16-
</Button><br /><br />
20+
</Button>
21+
<br />
1722
<Button>
1823
Hello
1924
</Button>
25+
<br />
26+
<Input
27+
placeholder="Input"
28+
error="This field is required."
29+
/>
30+
<br />
2031
</div>
2132
);
2233
}

src/components/Button.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ function Button({
4343
letter-spacing: 0.3px;
4444
text-transform: ${uppercase ? 'uppercase' : ''};
4545
cursor: pointer;
46+
4647
&:focus{
4748
outline: none;
4849
}
50+
4951
&:active{
5052
outline: none;
5153
box-shadow: 0 3px 0 rgb(9 30 66 / 10 %);
5254
top: 3px;
5355
}
56+
5457
&:hover{
5558
box-shadow: ${boxShadow ? '0 3px 5px rgb(9 30 66 / 10%), 0 0 1px rgb(9 30 66 / 31%)' : ''};
5659
transform: ${raise ? 'translate3d(0px, -2px, 0px)' : 'none'};
@@ -65,4 +68,5 @@ function Button({
6568
</StyledButton>
6669
)
6770
}
71+
6872
export default Button;

src/components/Input.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { InputHTMLAttributes } from "react";
2+
import styled from "styled-components";
3+
4+
interface Props extends InputHTMLAttributes<HTMLInputElement> {
5+
error?: string,
6+
}
7+
8+
function Input({
9+
error,
10+
...props
11+
}: Props) {
12+
const StyledInput = styled.input`
13+
padding: 8px;
14+
border: none;
15+
background: #fff;
16+
border: 1px solid ${error ? 'red' : '#c8c8c8'};
17+
letter-spacing: 0.3px;
18+
line-height: 1;
19+
&:focus{
20+
outline: none;
21+
}
22+
&::placeholder{
23+
color: #c8c8c8s;
24+
}
25+
`
26+
const ErrorWrapper = styled.small`
27+
margin: 5px 0;
28+
color: red;
29+
font-size: 13px;
30+
`
31+
32+
return (
33+
<>
34+
<StyledInput
35+
{...props}
36+
/>
37+
{
38+
error
39+
?
40+
<ErrorWrapper>
41+
{error}
42+
</ErrorWrapper>
43+
: ''
44+
}
45+
</>
46+
)
47+
}
48+
49+
export default Input;

src/theme.ts

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

0 commit comments

Comments
 (0)