Commit 67f0e1c2 authored by tom's avatar tom

fix offsets of grouped inputs

parent 03c9e582
...@@ -27,10 +27,29 @@ export const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>( ...@@ -27,10 +27,29 @@ export const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
endOffset, endOffset,
...rest ...rest
} = props; } = props;
const startElementRef = React.useRef<HTMLDivElement>(null);
const endElementRef = React.useRef<HTMLDivElement>(null);
const [ inlinePaddings, setInlinePaddings ] = React.useState({
start: 0,
end: 0,
});
React.useEffect(() => {
const { width: endWidth } = endElementRef?.current?.getBoundingClientRect() ?? {};
const { width: startWidth } = startElementRef?.current?.getBoundingClientRect() ?? {};
setInlinePaddings({
start: startWidth ?? 0,
end: endWidth ?? 0,
});
}, []);
return ( return (
<Group ref={ ref } w="100%" { ...rest }> <Group ref={ ref } w="100%" { ...rest }>
{ startElement && ( { startElement && (
<InputElement pointerEvents="none" { ...startElementProps }> <InputElement pointerEvents="none" ref={ startElementRef } { ...startElementProps }>
{ startElement } { startElement }
</InputElement> </InputElement>
) } ) }
...@@ -39,12 +58,12 @@ export const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>( ...@@ -39,12 +58,12 @@ export const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
return child; return child;
} }
return React.cloneElement(child, { return React.cloneElement(child, {
...(startElement && { ps: startOffset ?? `calc(var(--input-height) - 6px)` }), ...(startElement && { ps: startOffset ?? `${ inlinePaddings.start }px` }),
...(endElement && { pe: endOffset ?? `calc(var(--input-height) - 6px)` }), ...(endElement && { pe: endOffset ?? `${ inlinePaddings.end }px` }),
}); });
}) } }) }
{ endElement && ( { endElement && (
<InputElement placement="end" { ...endElementProps }> <InputElement placement="end" ref={ endElementRef } { ...endElementProps }>
{ endElement } { endElement }
</InputElement> </InputElement>
) } ) }
......
...@@ -131,7 +131,7 @@ const ContractMethodFieldInput = ({ data, hideLabel, path: name, className, isDi ...@@ -131,7 +131,7 @@ const ContractMethodFieldInput = ({ data, hideLabel, path: name, className, isDi
const inputEndElement = ( const inputEndElement = (
<Flex alignItems="center"> <Flex alignItems="center">
{ field.value !== undefined && field.value !== '' && <ClearButton onClick={ handleClear } isDisabled={ isDisabled } boxSize={ 6 }/> } <ClearButton onClick={ handleClear } isDisabled={ isDisabled } boxSize={ 6 } isVisible={ field.value !== undefined && field.value !== '' }/>
{ data.type === 'address' && <ContractMethodAddressButton onClick={ handleAddressButtonClick } isDisabled={ isDisabled }/> } { data.type === 'address' && <ContractMethodAddressButton onClick={ handleAddressButtonClick } isDisabled={ isDisabled }/> }
{ argTypeMatchInt && !isNativeCoin && (hasTimestampButton ? ( { argTypeMatchInt && !isNativeCoin && (hasTimestampButton ? (
<Button <Button
......
...@@ -32,7 +32,6 @@ const TokenSelectMenu = ({ erc20sort, erc1155sort, erc404sort, filteredData, onI ...@@ -32,7 +32,6 @@ const TokenSelectMenu = ({ erc20sort, erc1155sort, erc404sort, filteredData, onI
<> <>
<InputGroup <InputGroup
startElement={ <IconSvg name="search" boxSize={ 4 } color={{ _light: 'blackAlpha.600', _dark: 'whiteAlpha.600' }}/> } startElement={ <IconSvg name="search" boxSize={ 4 } color={{ _light: 'blackAlpha.600', _dark: 'whiteAlpha.600' }}/> }
startOffset="38px"
mb={ 5 } mb={ 5 }
> >
<Input placeholder="Search by token name" onChange={ onInputChange } size="sm" bgColor="dialog.bg"/> <Input placeholder="Search by token name" onChange={ onInputChange } size="sm" bgColor="dialog.bg"/>
......
...@@ -18,7 +18,7 @@ const RewardsReadOnlyInputWithCopy = ({ label, value, className, isLoading }: Pr ...@@ -18,7 +18,7 @@ const RewardsReadOnlyInputWithCopy = ({ label, value, className, isLoading }: Pr
return ( return (
<Skeleton loading={ isLoading } className={ className }> <Skeleton loading={ isLoading } className={ className }>
<Field label={ label } floating size="xl" readOnly> <Field label={ label } floating size="xl" readOnly>
<InputGroup endElement={ <CopyToClipboard text={ value }/> } endOffset="40px"> <InputGroup endElement={ <CopyToClipboard text={ value }/> }>
<Input value={ value } fontWeight="500" overflow="hidden" textOverflow="ellipsis"/> <Input value={ value } fontWeight="500" overflow="hidden" textOverflow="ellipsis"/>
</InputGroup> </InputGroup>
</Field> </Field>
......
...@@ -8,17 +8,19 @@ interface Props { ...@@ -8,17 +8,19 @@ interface Props {
onClick: (e: React.SyntheticEvent) => void; onClick: (e: React.SyntheticEvent) => void;
isDisabled?: boolean; isDisabled?: boolean;
className?: string; className?: string;
isVisible?: boolean;
} }
const ClearButton = ({ onClick, isDisabled, className }: Props) => { const ClearButton = ({ onClick, isDisabled, isVisible = true, className }: Props) => {
return ( return (
<IconButton <IconButton
disabled={ isDisabled } disabled={ isDisabled || !isVisible }
className={ className } className={ className }
aria-label="Clear input" aria-label="Clear input"
title="Clear input" title="Clear input"
size="sm" size="sm"
onClick={ onClick } onClick={ onClick }
opacity={ isVisible ? 1 : 0 }
> >
<IconSvg <IconSvg
name="status/error" name="status/error"
......
...@@ -37,7 +37,7 @@ const FilterInput = ({ onChange, size = 'sm', placeholder, initialValue, type, n ...@@ -37,7 +37,7 @@ const FilterInput = ({ onChange, size = 'sm', placeholder, initialValue, type, n
const startElement = <IconSvg name="search" color={{ _light: 'blackAlpha.600', _dark: 'whiteAlpha.600' }} boxSize={ 4 }/>; const startElement = <IconSvg name="search" color={{ _light: 'blackAlpha.600', _dark: 'whiteAlpha.600' }} boxSize={ 4 }/>;
const endElement = filterQuery ? <ClearButton onClick={ handleFilterQueryClear }/> : null; const endElement = <ClearButton onClick={ handleFilterQueryClear } isVisible={ filterQuery.length > 0 }/>;
return ( return (
<Skeleton <Skeleton
...@@ -49,10 +49,8 @@ const FilterInput = ({ onChange, size = 'sm', placeholder, initialValue, type, n ...@@ -49,10 +49,8 @@ const FilterInput = ({ onChange, size = 'sm', placeholder, initialValue, type, n
<InputGroup <InputGroup
startElement={ startElement } startElement={ startElement }
startElementProps={{ px: 2 }} startElementProps={{ px: 2 }}
startOffset="32px"
endElement={ endElement } endElement={ endElement }
endElementProps={{ px: 0, w: '32px' }} endElementProps={{ px: 0, w: '32px' }}
endOffset="32px"
> >
<Input <Input
ref={ inputRef } ref={ inputRef }
......
...@@ -206,7 +206,6 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive, ...@@ -206,7 +206,6 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive,
boxShadow={ isInputStuck ? '0px 6px 3px 0px rgba(0, 0, 0, 0.05)' : 'none' } boxShadow={ isInputStuck ? '0px 6px 3px 0px rgba(0, 0, 0, 0.05)' : 'none' }
endElement={ inputEndElement } endElement={ inputEndElement }
endElementProps={{ height: '26px', pl: '0', pr: '10px', columnGap: '2px' }} endElementProps={{ height: '26px', pl: '0', pr: '10px', columnGap: '2px' }}
endOffset="75px"
> >
<Input <Input
size="xs" size="xs"
......
...@@ -109,15 +109,10 @@ const SearchBarInput = ( ...@@ -109,15 +109,10 @@ const SearchBarInput = (
); );
const endElement = (() => { const endElement = (() => {
if (value) {
return <ClearButton onClick={ onClear }/>;
}
if (isMobile) {
return null;
}
return ( return (
<>
<ClearButton onClick={ onClear } isVisible={ value.length > 0 }/>
{ !isMobile && (
<Center <Center
boxSize="20px" boxSize="20px"
my="2px" my="2px"
...@@ -130,6 +125,8 @@ const SearchBarInput = ( ...@@ -130,6 +125,8 @@ const SearchBarInput = (
> >
/ /
</Center> </Center>
) }
</>
); );
})(); })();
...@@ -157,7 +154,6 @@ const SearchBarInput = ( ...@@ -157,7 +154,6 @@ const SearchBarInput = (
> >
<InputGroup <InputGroup
startElement={ startElement } startElement={ startElement }
startOffset={{ base: isHomepage ? '50px' : '38px', lg: '50px' }}
endElement={ endElement } endElement={ endElement }
> >
<Input <Input
......
import { Box, Flex, Link, Text } from '@chakra-ui/react'; import { Box, Flex, Text } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import { clearRecentSearchKeywords, getRecentSearchKeywords, removeRecentSearchKeyword } from 'lib/recentSearchKeywords'; import { clearRecentSearchKeywords, getRecentSearchKeywords, removeRecentSearchKeyword } from 'lib/recentSearchKeywords';
import { Link } from 'toolkit/chakra/link';
import TextAd from 'ui/shared/ad/TextAd'; import TextAd from 'ui/shared/ad/TextAd';
import ClearButton from 'ui/shared/ClearButton'; import ClearButton from 'ui/shared/ClearButton';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic'; import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
...@@ -84,7 +85,7 @@ const SearchBarSuggest = ({ onClick, onClear }: Props) => { ...@@ -84,7 +85,7 @@ const SearchBarSuggest = ({ onClick, onClear }: Props) => {
) : ) :
<Text overflow="hidden" whiteSpace="nowrap" textOverflow="ellipsis">{ kw }</Text> <Text overflow="hidden" whiteSpace="nowrap" textOverflow="ellipsis">{ kw }</Text>
} }
<ClearButton onClick={ removeKeyword(kw) } flexShrink={ 0 }/> <ClearButton onClick={ removeKeyword(kw) } flexShrink={ 0 } boxSize={ 6 }/>
</Flex> </Flex>
)) } )) }
</Box> </Box>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment