Files
explore/ui/tokenInfo/fields/TokenInfoFieldIconUrl.tsx
tom goriunovandGitHub f6725649da UI toolkit package (#2691)
* first version of the pack

* single entry point

* add custom components to the package

* move form components to toolkit

* add more utils and hooks to the package

* minor fixes

* add CI workflow

* update readme and package.json

* fix ts

* fix build of env-validator

* fix docker build

* fix icons size

* test fixes

* more test fixes
2025-04-21 19:44:22 +02:00

46 lines
1.5 KiB
TypeScript

import { Flex } from '@chakra-ui/react';
import React from 'react';
import type { Fields } from '../types';
import type { FieldProps } from 'toolkit/chakra/field';
import { FormFieldUrl } from 'toolkit/components/forms/fields/FormFieldUrl';
import { FormFieldImagePreview } from 'toolkit/components/forms/fields/image/FormFieldImagePreview';
import { useImageField } from 'toolkit/components/forms/fields/image/useImageField';
import { times } from 'toolkit/utils/htmlEntities';
import TokenLogoPlaceholder from 'ui/shared/TokenLogoPlaceholder';
import TokenInfoIconPreview from '../TokenInfoIconPreview';
interface Props {
readOnly?: boolean;
size?: FieldProps['size'];
}
const TokenInfoFieldIconUrl = ({ readOnly, size }: Props) => {
const imageField = useImageField({ name: 'icon_url', isRequired: true });
return (
<Flex columnGap={ 5 }>
<FormFieldUrl<Fields>
name="icon_url"
placeholder={ `Link to icon URL, link to download a SVG or 48${ times }48 PNG icon logo` }
readOnly={ readOnly }
size={ size }
{ ...imageField.input }
/>
<TokenInfoIconPreview url={ imageField.preview.src } isInvalid={ imageField.preview.isInvalid }>
<FormFieldImagePreview
{ ...imageField.preview }
fallback={ <TokenLogoPlaceholder boxSize={ 10 }/> }
boxSize={ 10 }
borderRadius="base"
/>
</TokenInfoIconPreview>
</Flex>
);
};
export default React.memo(TokenInfoFieldIconUrl);