Skip to content

Commit 8e70b89

Browse files
committed
chore: Extend input component
1 parent bab3df1 commit 8e70b89

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

src/__tests__/components/input.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ it("renders correctly", () => {
99
expect(asFragment()).toMatchInlineSnapshot(`
1010
<DocumentFragment>
1111
<div
12-
class="css-1u137ur"
12+
class="css-qxbvaj"
1313
>
1414
<input
15-
class="css-1spk4n4"
15+
class="css-waj1w6"
1616
type="text"
1717
value="input"
1818
/>

src/components/Input/Input.tsx

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@ import { Input as ThemeUIInput, Box } from "theme-ui";
33
import { InputProps, sizes, iconSizes } from "./types";
44
import { Svg } from "../Svg";
55

6-
const Input: React.FC<InputProps> = ({ size = sizes.MD, icon, width, sx, ...props }) => {
7-
return (
8-
<Box
9-
sx={{
10-
position: "relative",
11-
width: "fit-content",
12-
}}
13-
>
14-
<ThemeUIInput
15-
{...props}
6+
const Input = React.forwardRef<HTMLInputElement, InputProps>(
7+
({ size = sizes.MD, icon, width = "200px", ...props }, ref) => {
8+
return (
9+
<Box
1610
sx={{
11+
position: "relative",
12+
display: "inline-block",
1713
width,
18-
pl: "15px",
19-
pr: icon ? "40px" : "15px",
20-
variant: `forms.input.${size}`,
21-
color: "text",
22-
outline: "none",
2314
}}
24-
/>
25-
{icon && (
26-
<Box
15+
>
16+
<ThemeUIInput
17+
{...props}
18+
ref={ref}
2719
sx={{
28-
position: "absolute",
29-
top: "50%",
30-
transform: "translateY(-50%)",
31-
right: "15px",
20+
pl: "15px",
21+
pr: icon ? "40px" : "15px",
22+
variant: `forms.input.${size}`,
23+
color: "text",
24+
outline: "none",
25+
width: "100%",
3226
}}
33-
>
34-
<Svg icon={icon} width={iconSizes[size]} />
35-
</Box>
36-
)}
37-
</Box>
38-
);
39-
};
27+
/>
28+
{icon && (
29+
<Box
30+
sx={{
31+
position: "absolute",
32+
top: "50%",
33+
transform: "translateY(-50%)",
34+
right: "15px",
35+
}}
36+
>
37+
<Svg icon={icon} width={iconSizes[size]} />
38+
</Box>
39+
)}
40+
</Box>
41+
);
42+
}
43+
);
4044

4145
export default Input;

src/theme/Apeswap/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,16 @@ const Apeswap: Theme = {
9292
background: "white3",
9393
borderRadius: 10,
9494
height: "32px",
95-
width: "200px",
9695
},
9796
md: {
9897
background: "white3",
9998
borderRadius: 10,
10099
height: "36px",
101-
width: "200px",
102100
},
103101
lg: {
104102
background: "white3",
105103
borderRadius: 14,
106104
height: "48px",
107-
width: "200px",
108105
},
109106
},
110107
textarea: {

0 commit comments

Comments
 (0)