ghost-portal/packages/react-params/src/Param/Static.tsx
Jaco Greeff c60ba8708a
Bumps w/ eslint (#2802)
* Bumps w/ eslint

* Additional

* Additional

* Additional

* Additional

* Remove style props

* Additional

* Additional

* Additional

* Additional (< 100)

* eslint passes, tsc next

* tsc fixes

* Update deps

* Update i18n
2020-05-24 19:41:14 +02:00

54 lines
1.5 KiB
TypeScript

// Copyright 2017-2020 @polkadot/react-components authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Codec } from '@polkadot/types/types';
import { Props as BareProps, RawParam } from '../types';
import React from 'react';
import styled from 'styled-components';
import { Static } from '@polkadot/react-components';
import { useTranslation } from '../translate';
import Bare from './Bare';
interface Props extends BareProps {
asHex?: boolean;
children?: React.ReactNode;
defaultValue: RawParam;
withLabel?: boolean;
}
function StaticParam ({ asHex, children, className = '', defaultValue, label }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const value = defaultValue && defaultValue.value && (
asHex
? (defaultValue.value as Codec).toHex()
: JSON.stringify(
(defaultValue.value as { toHuman?: () => unknown }).toHuman
? (defaultValue.value as Codec).toHuman()
: defaultValue.value,
null, 2
).replace(/"/g, '').replace(/\\/g, '').replace(/\],\[/g, '],\n[')
);
return (
<Bare className={className}>
<Static
className='full'
label={label}
value={<pre>{value || t<string>('<empty>')}</pre>}
/>
{children}
</Bare>
);
}
export default React.memo(styled(StaticParam)`
pre {
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
}
`);