Commit b827b27b authored by tom's avatar tom

noLink prop for entities

parent 98ec03cd
...@@ -95,6 +95,19 @@ test('external link', async({ mount }) => { ...@@ -95,6 +95,19 @@ test('external link', async({ mount }) => {
await expect(component).toHaveScreenshot(); await expect(component).toHaveScreenshot();
}); });
test('no link', async({ mount }) => {
const component = await mount(
<TestApp>
<AddressEntity
address={ addressMock.withoutName }
noLink
/>
</TestApp>,
);
await expect(component).toHaveScreenshot();
});
test('customization', async({ mount }) => { test('customization', async({ mount }) => {
const component = await mount( const component = await mount(
<TestApp> <TestApp>
......
...@@ -14,9 +14,7 @@ import * as EntityBase from 'ui/shared/entities/base/components'; ...@@ -14,9 +14,7 @@ import * as EntityBase from 'ui/shared/entities/base/components';
import { getIconProps } from '../base/utils'; import { getIconProps } from '../base/utils';
interface LinkProps extends Pick<EntityProps, 'className' | 'address' | 'onClick' | 'isLoading' | 'isExternal' | 'href' | 'query'> { type LinkProps = EntityBase.LinkBaseProps & Pick<EntityProps, 'address'>;
children: React.ReactNode;
}
const Link = chakra((props: LinkProps) => { const Link = chakra((props: LinkProps) => {
const defaultHref = route({ pathname: '/address/[hash]', query: { ...props.query, hash: props.address.hash } }); const defaultHref = route({ pathname: '/address/[hash]', query: { ...props.query, hash: props.address.hash } });
......
...@@ -14,17 +14,17 @@ import { getIconProps, type IconSize } from './utils'; ...@@ -14,17 +14,17 @@ import { getIconProps, type IconSize } from './utils';
export type Truncation = 'constant' | 'dynamic' | 'tail' | 'none'; export type Truncation = 'constant' | 'dynamic' | 'tail' | 'none';
// TODO @tom2drum add disabled link props
export interface EntityBaseProps { export interface EntityBaseProps {
className?: string; className?: string;
isLoading?: boolean; href?: string;
iconSize?: IconSize; iconSize?: IconSize;
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
isExternal?: boolean; isExternal?: boolean;
href?: string; isLoading?: boolean;
query?: Record<string, string>;
noIcon?: boolean;
noCopy?: boolean; noCopy?: boolean;
noIcon?: boolean;
noLink?: boolean;
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
query?: Record<string, string>;
tailLength?: number; tailLength?: number;
truncation?: Truncation; truncation?: Truncation;
} }
...@@ -45,21 +45,29 @@ const Container = chakra(({ className, children }: ContainerBaseProps) => { ...@@ -45,21 +45,29 @@ const Container = chakra(({ className, children }: ContainerBaseProps) => {
); );
}); });
export interface LinkBaseProps extends Pick<EntityBaseProps, 'className' | 'onClick' | 'isLoading' | 'isExternal' | 'href'> { export interface LinkBaseProps extends Pick<EntityBaseProps, 'className' | 'onClick' | 'isLoading' | 'isExternal' | 'href' | 'noLink' | 'query'> {
children: React.ReactNode; children: React.ReactNode;
} }
const Link = chakra(({ isLoading, children, isExternal, onClick, href }: LinkBaseProps) => { const Link = chakra(({ isLoading, children, isExternal, onClick, href, noLink }: LinkBaseProps) => {
const styles = {
display: 'inline-flex',
alignItems: 'center',
minWidth: 0, // for content truncation - https://css-tricks.com/flexbox-truncated-text/
};
if (noLink) {
return <Skeleton isLoaded={ !isLoading } { ...styles }>{ children }</Skeleton>;
}
const Component = isExternal ? LinkExternal : LinkInternal; const Component = isExternal ? LinkExternal : LinkInternal;
return ( return (
<Component <Component
{ ...styles }
href={ href } href={ href }
isLoading={ isLoading } isLoading={ isLoading }
onClick={ onClick } onClick={ onClick }
display="inline-flex"
alignItems="center"
minWidth={ 0 } // for content truncation - https://css-tricks.com/flexbox-truncated-text/
> >
{ children } { children }
</Component> </Component>
......
...@@ -13,9 +13,7 @@ import TruncatedTextTooltip from 'ui/shared/TruncatedTextTooltip'; ...@@ -13,9 +13,7 @@ import TruncatedTextTooltip from 'ui/shared/TruncatedTextTooltip';
import { getIconProps } from '../base/utils'; import { getIconProps } from '../base/utils';
interface LinkProps extends Pick<EntityProps, 'className' | 'token' | 'onClick' | 'isLoading' | 'isExternal' | 'href' | 'query'> { type LinkProps = EntityBase.LinkBaseProps & Pick<EntityProps, 'token'>;
children: React.ReactNode;
}
const Link = chakra((props: LinkProps) => { const Link = chakra((props: LinkProps) => {
const defaultHref = route({ pathname: '/token/[hash]', query: { ...props.query, hash: props.token.address } }); const defaultHref = route({ pathname: '/token/[hash]', query: { ...props.query, hash: props.token.address } });
......
...@@ -8,9 +8,7 @@ import { route } from 'nextjs-routes'; ...@@ -8,9 +8,7 @@ import { route } from 'nextjs-routes';
import transactionIcon from 'icons/transactions_slim.svg'; import transactionIcon from 'icons/transactions_slim.svg';
import * as EntityBase from 'ui/shared/entities/base/components'; import * as EntityBase from 'ui/shared/entities/base/components';
interface LinkProps extends Pick<EntityProps, 'className' | 'hash' | 'onClick' | 'isLoading' | 'isExternal' | 'href'> { type LinkProps = EntityBase.LinkBaseProps & Pick<EntityProps, 'hash'>;
children: React.ReactNode;
}
const Link = chakra((props: LinkProps) => { const Link = chakra((props: LinkProps) => {
const defaultHref = route({ pathname: '/tx/[hash]', query: { hash: props.hash } }); const defaultHref = route({ pathname: '/tx/[hash]', query: { hash: props.hash } });
......
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