ghost-portal/packages/react-components/src/ChainImg.tsx
Jaco 4929b1c6fd
Update headers for 2023 (#8665)
* Update headers for 2023

* Adjust env-config
2023-01-01 10:32:05 +02:00

55 lines
1.5 KiB
TypeScript

// Copyright 2017-2023 @polkadot/apps authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { useMemo } from 'react';
import styled from 'styled-components';
import { chainLogos, emptyLogos, namedLogos, nodeLogos, specLogos } from '@polkadot/apps-config';
import { useApi } from '@polkadot/react-hooks';
interface Props {
className?: string;
isInline?: boolean;
logo?: keyof typeof namedLogos;
onClick?: () => any;
withoutHl?: boolean;
}
function sanitize (value?: string): string {
return value?.toLowerCase().replace('-', ' ') || '';
}
function ChainImg ({ className = '', isInline, logo, onClick, withoutHl }: Props): React.ReactElement<Props> {
const { specName, systemChain, systemName } = useApi();
const [isEmpty, img] = useMemo((): [boolean, string] => {
const found = logo && logo !== 'empty'
? namedLogos[logo]
: chainLogos[sanitize(systemChain)] || nodeLogos[sanitize(systemName)] || specLogos[sanitize(specName)];
return [!found || logo === 'empty', (found || emptyLogos.empty) as string];
}, [logo, specName, systemChain, systemName]);
return (
<img
alt='chain logo'
className={`${className}${(isEmpty && !withoutHl) ? ' highlight--bg' : ''}${isInline ? ' isInline' : ''}`}
onClick={onClick}
src={img}
/>
);
}
export default React.memo(styled(ChainImg)`
background: white;
border-radius: 50%;
box-sizing: border-box;
&.isInline {
display: inline-block;
height: 24px;
margin-right: 0.75rem;
vertical-align: middle;
width: 24px;
}
`);