Skip to content

Commit 38ea2b6

Browse files
authored
Add clear input button to custom address modal (#844)
1 parent 5c80c9a commit 38ea2b6

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

.changeset/many-pugs-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@relayprotocol/relay-kit-ui': patch
3+
---
4+
5+
Add clear input button to custom address modal

packages/ui/src/components/common/CustomAddressModal.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import type { Token } from '../../types/index.js'
1111
import {
1212
faCircleCheck,
1313
faTriangleExclamation,
14-
faClipboard
14+
faClipboard,
15+
faCircleXmark
1516
} from '@fortawesome/free-solid-svg-icons'
1617
import { AnchorButton } from '../primitives/Anchor.js'
1718
import type { AdaptedWallet, RelayChain } from '@relayprotocol/relay-sdk'
@@ -133,7 +134,7 @@ export const CustomAddressModal: FC<Props> = ({
133134
height: '100%',
134135
gap: '4',
135136
sm: {
136-
width: 370
137+
width: 386
137138
}
138139
}}
139140
>
@@ -155,6 +156,9 @@ export const CustomAddressModal: FC<Props> = ({
155156
width: '100%',
156157
height: 48
157158
}}
159+
inputStyle={{
160+
paddingRight: input.length > 0 ? '42px' : '16px'
161+
}}
158162
placeholder={
159163
!toChain
160164
? 'Enter address'
@@ -167,6 +171,37 @@ export const CustomAddressModal: FC<Props> = ({
167171
setInput((e.target as HTMLInputElement).value)
168172
}}
169173
/>
174+
{input.length > 0 && !isLoading && (
175+
<Button
176+
color="ghost"
177+
size="none"
178+
css={{
179+
position: 'absolute',
180+
right: '8px',
181+
top: '50%',
182+
transform: 'translateY(-50%)',
183+
width: '24px',
184+
height: '24px',
185+
minWidth: '24px',
186+
minHeight: '24px',
187+
padding: '0',
188+
borderRadius: '4px',
189+
display: 'flex',
190+
alignItems: 'center',
191+
justifyContent: 'center',
192+
backgroundColor: 'gray3',
193+
color: 'gray8'
194+
}}
195+
onMouseDown={(e) => {
196+
e.preventDefault() // Prevent input from losing focus
197+
}}
198+
onClick={() => {
199+
setInput('')
200+
}}
201+
>
202+
<FontAwesomeIcon icon={faCircleXmark} width={16} height={16} />
203+
</Button>
204+
)}
170205
{isLoading && (
171206
<LoadingSpinner
172207
css={{

packages/ui/src/components/primitives/Input.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,30 @@ const Input = forwardRef<
6262
iconPosition?: 'left' | 'right'
6363
iconCss?: Styles
6464
containerCss?: Styles
65+
inputStyle?: React.CSSProperties
6566
} & { css?: Styles } & StyledInputCssVariants
6667
>(
6768
(
68-
{ children, icon, iconPosition, iconCss, containerCss, css, ...props },
69+
{
70+
children,
71+
icon,
72+
iconPosition,
73+
iconCss,
74+
containerCss,
75+
inputStyle,
76+
css,
77+
...props
78+
},
6979
ref
7080
) => {
71-
const { size, ellipsify, ...inputProps } = props
81+
const { size, ellipsify, style, ...inputProps } = props
7282

7383
return (
7484
<Flex
7585
css={{
7686
...containerCss
7787
}}
78-
style={{ ...props.style }}
88+
style={{ ...style }}
7989
>
8090
{icon && (
8191
<Flex css={{ position: 'relative' }}>
@@ -99,7 +109,8 @@ const Input = forwardRef<
99109
ref={ref}
100110
style={{
101111
paddingLeft: icon && iconPosition !== 'right' ? 42 : 16,
102-
paddingRight: icon && iconPosition === 'right' ? 42 : 16
112+
paddingRight: icon && iconPosition === 'right' ? 42 : 16,
113+
...inputStyle
103114
}}
104115
className={designCss(
105116
StyledInputCss.raw({ size, ellipsify }),

0 commit comments

Comments
 (0)