Commit f79c40d6 authored by tom's avatar tom

fix Network logo

parent a65cca1d
...@@ -406,6 +406,7 @@ export default tseslint.config( ...@@ -406,6 +406,7 @@ export default tseslint.config(
'boolean': true, 'boolean': true,
string: true, string: true,
} ], } ],
'no-nested-ternary': 'error',
'no-multi-str': 'error', 'no-multi-str': 'error',
'no-spaced-func': 'error', 'no-spaced-func': 'error',
'no-with': 'error', 'no-with': 'error',
......
...@@ -21,30 +21,41 @@ export interface ButtonProps extends ChakraButtonProps, ButtonLoadingProps { ...@@ -21,30 +21,41 @@ export interface ButtonProps extends ChakraButtonProps, ButtonLoadingProps {
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
function Button(props, ref) { function Button(props, ref) {
const { loading, disabled, loadingText, children, active, selected, highlighted, ...rest } = props; const { loading, disabled, loadingText, children, active, selected, highlighted, ...rest } = props;
const content = (() => {
if (loading && !loadingText) {
return ( return (
<ChakraButton
{ ...(active ? { 'data-active': true } : {}) }
{ ...(selected ? { 'data-selected': true } : {}) }
{ ...(highlighted ? { 'data-highlighted': true } : {}) }
disabled={ loading || disabled }
ref={ ref }
{ ...rest }
>
{ loading && !loadingText ? (
<> <>
<AbsoluteCenter display="inline-flex"> <AbsoluteCenter display="inline-flex">
<Spinner size="inherit" color="inherit"/> <Spinner size="inherit" color="inherit"/>
</AbsoluteCenter> </AbsoluteCenter>
<Span opacity={ 0 }>{ children }</Span> <Span opacity={ 0 }>{ children }</Span>
</> </>
) : loading && loadingText ? ( );
}
if (loading && loadingText) {
return (
<> <>
<Spinner size="inherit" color="inherit"/> <Spinner size="inherit" color="inherit"/>
{ loadingText } { loadingText }
</> </>
) : ( );
children }
) }
return children;
})();
return (
<ChakraButton
{ ...(active ? { 'data-active': true } : {}) }
{ ...(selected ? { 'data-selected': true } : {}) }
{ ...(highlighted ? { 'data-highlighted': true } : {}) }
disabled={ loading || disabled }
ref={ ref }
{ ...rest }
>
{ content }
</ChakraButton> </ChakraButton>
); );
}, },
......
import type { ImageProps as ChakraImageProps } from '@chakra-ui/react';
import { Image as ChakraImage } from '@chakra-ui/react';
import React from 'react';
import { Skeleton } from './skeleton';
export interface ImageProps extends ChakraImageProps {
fallback?: React.ReactNode;
}
export const Image = React.forwardRef<HTMLImageElement, ImageProps>(
function Image(props, ref) {
const { fallback, src, ...rest } = props;
const [ loading, setLoading ] = React.useState(true);
const [ error, setError ] = React.useState(false);
const handleLoadError = React.useCallback(() => {
setError(true);
setLoading(false);
}, []);
const handleLoadSuccess = React.useCallback(() => {
setLoading(false);
}, []);
if (!src && fallback) {
return fallback;
}
if (error) {
return fallback;
}
return (
<Skeleton loading={ loading }>
<ChakraImage
ref={ ref }
src={ src }
onError={ handleLoadError }
onLoad={ handleLoadSuccess }
{ ...rest }
/>
</Skeleton>
);
});
import { Image, Skeleton, chakra } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import { route } from 'nextjs-routes'; import { route } from 'nextjs-routes';
import config from 'configs/app'; import config from 'configs/app';
import { useColorModeValue } from 'toolkit/chakra/color-mode'; import { useColorModeValue } from 'toolkit/chakra/color-mode';
import { Image } from 'toolkit/chakra/image';
import IconSvg from 'ui/shared/IconSvg'; import IconSvg from 'ui/shared/IconSvg';
interface Props { interface Props {
...@@ -14,9 +15,6 @@ interface Props { ...@@ -14,9 +15,6 @@ interface Props {
} }
const LogoFallback = ({ isCollapsed, isSmall }: { isCollapsed?: boolean; isSmall?: boolean }) => { const LogoFallback = ({ isCollapsed, isSmall }: { isCollapsed?: boolean; isSmall?: boolean }) => {
const field = isSmall ? 'icon' : 'logo';
const logoColor = useColorModeValue('blue.600', 'white');
const display = isSmall ? { const display = isSmall ? {
base: 'none', base: 'none',
lg: isCollapsed === false ? 'none' : 'block', lg: isCollapsed === false ? 'none' : 'block',
...@@ -27,29 +25,23 @@ const LogoFallback = ({ isCollapsed, isSmall }: { isCollapsed?: boolean; isSmall ...@@ -27,29 +25,23 @@ const LogoFallback = ({ isCollapsed, isSmall }: { isCollapsed?: boolean; isSmall
xl: isCollapsed ? 'none' : 'block', xl: isCollapsed ? 'none' : 'block',
}; };
if (config.UI.navigation[field].default) {
return <Skeleton w="100%" borderRadius="sm" display={ display }/>;
}
return ( return (
<IconSvg <IconSvg
name={ isSmall ? 'networks/icon-placeholder' : 'networks/logo-placeholder' } name={ isSmall ? 'networks/icon-placeholder' : 'networks/logo-placeholder' }
width="auto" width="auto"
height="100%" height="100%"
color={ logoColor } color={{ base: 'blue.600', _dark: 'white' }}
display={ display } display={ display }
/> />
); );
}; };
// TODO @tom2drum implement image with fallback const INVERT_FILTER = 'brightness(0) invert(1)';
const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => { const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => {
const logoSrc = useColorModeValue(config.UI.navigation.logo.default, config.UI.navigation.logo.dark || config.UI.navigation.logo.default); const logoSrc = useColorModeValue(config.UI.navigation.logo.default, config.UI.navigation.logo.dark || config.UI.navigation.logo.default);
const iconSrc = useColorModeValue(config.UI.navigation.icon.default, config.UI.navigation.icon.dark || config.UI.navigation.icon.default); const iconSrc = useColorModeValue(config.UI.navigation.icon.default, config.UI.navigation.icon.dark || config.UI.navigation.icon.default);
const darkModeFilter = { filter: 'brightness(0) invert(1)' };
const logoStyle = useColorModeValue({}, !config.UI.navigation.logo.dark ? darkModeFilter : {});
const iconStyle = useColorModeValue({}, !config.UI.navigation.icon.dark ? darkModeFilter : {});
return ( return (
<chakra.a <chakra.a
...@@ -71,7 +63,7 @@ const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => { ...@@ -71,7 +63,7 @@ const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => {
alt={ `${ config.chain.name } network logo` } alt={ `${ config.chain.name } network logo` }
fallback={ <LogoFallback isCollapsed={ isCollapsed }/> } fallback={ <LogoFallback isCollapsed={ isCollapsed }/> }
display={{ base: 'block', lg: isCollapsed === false ? 'block' : 'none', xl: isCollapsed ? 'none' : 'block' }} display={{ base: 'block', lg: isCollapsed === false ? 'block' : 'none', xl: isCollapsed ? 'none' : 'block' }}
style={ logoStyle } filter={{ _dark: INVERT_FILTER }}
/> />
{ /* small logo */ } { /* small logo */ }
<Image <Image
...@@ -81,7 +73,7 @@ const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => { ...@@ -81,7 +73,7 @@ const NetworkLogo = ({ isCollapsed, onClick, className }: Props) => {
alt={ `${ config.chain.name } network logo` } alt={ `${ config.chain.name } network logo` }
fallback={ <LogoFallback isCollapsed={ isCollapsed } isSmall/> } fallback={ <LogoFallback isCollapsed={ isCollapsed } isSmall/> }
display={{ base: 'none', lg: isCollapsed === false ? 'none' : 'block', xl: isCollapsed ? 'block' : 'none' }} display={{ base: 'none', lg: isCollapsed === false ? 'none' : 'block', xl: isCollapsed ? 'block' : 'none' }}
style={ iconStyle } filter={{ _dark: INVERT_FILTER }}
/> />
</chakra.a> </chakra.a>
); );
......
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