Skip to content

Commit efb8607

Browse files
authored
Refactor components to drop ChakraUI (#336)
1 parent 9cacfa1 commit efb8607

File tree

5 files changed

+76
-37
lines changed

5 files changed

+76
-37
lines changed

.changeset/two-hotels-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web3-ui/components': minor
3+
---
4+
5+
Refactor `Address` component to not use ChakraUI anymore. It uses plain CSS now. The functionality remains unchanged.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.Web3UI_Address__Container {
2+
display: flex;
3+
align-items: center;
4+
gap: 8px;
5+
}
6+
7+
.Web3UI_Address__ErrorMessage {
8+
color: red;
9+
margin-top: 4px;
10+
}

packages/components/src/components/Address/Address.tsx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import {
2-
Box,
3-
Flex,
4-
FormControl,
5-
FormErrorMessage,
6-
Text,
7-
} from '@chakra-ui/react';
81
import { CopyIcon, CheckIcon } from '@chakra-ui/icons';
92
import React, { useState, useEffect } from 'react';
103
import { ethers } from 'ethers';
4+
import './Address.css';
115

126
export interface AddressProps {
137
/**
@@ -30,6 +24,10 @@ export interface AddressProps {
3024
* Set to true for ENS lookup
3125
*/
3226
ens?: boolean;
27+
/**
28+
* className for the container
29+
*/
30+
className?: string;
3331
}
3432

3533
/**
@@ -41,6 +39,7 @@ export const Address: React.FC<AddressProps> = ({
4139
copiable = false,
4240
shortened = false,
4341
ens = false,
42+
className,
4443
}) => {
4544
const [error, setError] = useState<undefined | string>(undefined);
4645
const [copied, setCopied] = useState<boolean>(false);
@@ -98,25 +97,21 @@ export const Address: React.FC<AddressProps> = ({
9897
}, []);
9998

10099
return (
101-
<FormControl isInvalid={!!error}>
102-
<Flex
100+
<>
101+
<div
103102
data-testid="address-container"
104-
alignItems="center"
105-
cursor={copiable ? 'pointer' : 'initial'}
103+
className={`Web3UI_Address__Container ${className}`}
104+
style={{ cursor: copiable ? 'pointer' : 'initial' }}
106105
onClick={handleClick}
107106
>
108-
<Text>{ensName || displayAddress}</Text>
109-
{copiable && (
110-
<Box ml="auto">
111-
{copied ? (
112-
<CheckIcon color="green.500" />
113-
) : (
114-
<CopyIcon color="gray.300" />
115-
)}
116-
</Box>
107+
<p>{ensName || displayAddress}</p>
108+
{copiable && copied ? (
109+
<CheckIcon marginLeft="auto" color="green.500" />
110+
) : (
111+
<CopyIcon marginLeft="auto" color="gray.300" />
117112
)}
118-
</Flex>
119-
<FormErrorMessage>{error}</FormErrorMessage>
120-
</FormControl>
113+
</div>
114+
<p className="Web3UI_Address__Error">{error}</p>
115+
</>
121116
);
122117
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.Web3UI_AddressInput__Container {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
6+
/* .Web3UI_AddressInput__Label {
7+
} */
8+
9+
.Web3UI_AddressInput__Input {
10+
margin-top: 4px;
11+
padding: 8px;
12+
border-radius: 7px;
13+
border: 1px solid #ccc;
14+
}
15+
16+
.Web3UI_AddressInput__ErrorMessage {
17+
color: red;
18+
margin-top: 4px;
19+
}

packages/components/src/components/AddressInput/AddressInput.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import {
2-
FormControl,
3-
FormLabel,
4-
Input,
5-
FormErrorMessage,
6-
InputProps,
7-
} from '@chakra-ui/react';
81
import React, { useEffect, useState } from 'react';
92
import { ethers } from 'ethers';
103
import { useDebounce } from './useDebounce';
114
import { JsonRpcSigner } from '@ethersproject/providers';
5+
import './AddressInput.css';
126

137
export interface AddressInputProps {
148
/**
@@ -27,16 +21,32 @@ export interface AddressInputProps {
2721
* Change handler for the text input
2822
*/
2923
onChange: (value: string) => void;
24+
/**
25+
* className for the container
26+
*/
27+
className?: string;
28+
/**
29+
* className for the input
30+
*/
31+
inputClassName?: string;
3032
}
3133

3234
/**
3335
* A text input component that is used to get ETH addresses. ENS support included. You can also pass all the styling props of the Chakra UI Input component.
3436
*/
35-
export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
37+
export const AddressInput: React.FC<
38+
AddressInputProps &
39+
React.DetailedHTMLProps<
40+
React.InputHTMLAttributes<HTMLInputElement>,
41+
HTMLInputElement
42+
>
43+
> = ({
3644
provider,
3745
value: _value,
3846
onChange,
3947
label,
48+
className,
49+
inputClassName,
4050
...props
4151
}) => {
4252
const [inputValue, setInputValue] = useState('');
@@ -80,15 +90,15 @@ export const AddressInput: React.FC<AddressInputProps & InputProps> = ({
8090
}, [inputValue]);
8191

8292
return (
83-
<FormControl isInvalid={!!error}>
84-
{label && <FormLabel>Input address</FormLabel>}
85-
<Input
86-
isInvalid={!!error}
93+
<div className={`Web3UI_AddressInput__Container ${className}`}>
94+
{label && <label className="Web3UI_AddressInput__Label">{label}</label>}
95+
<input
96+
className={`Web3UI_AddressInput__Input ${inputClassName}`}
8797
value={inputValue}
8898
onChange={(e) => setInputValue(e.target.value)}
8999
{...props}
90100
/>
91-
<FormErrorMessage>{error ? ' ' + error : ''}</FormErrorMessage>
92-
</FormControl>
101+
{error && <p className="Web3UI_AddressInput__ErrorMessage">{error}</p>}
102+
</div>
93103
);
94104
};

0 commit comments

Comments
 (0)