ghost-portal/packages/ui-params/src/Param/Code.tsx
Jaco Greeff d93169e172
Rework Params & Params Vector (#581)
* Split Params into ui-params

* Fix Vector value detection/adding

* Update jest config
2019-01-10 15:48:07 +01:00

59 lines
1.4 KiB
TypeScript

// Copyright 2017-2019 @polkadot/ui-app 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 { Props } from '../types';
import React from 'react';
import Bytes from './Bytes';
import BytesFile from './File';
export default class Code extends React.PureComponent<Props> {
render () {
const { className, defaultValue, isDisabled, isError, label, style, withLabel } = this.props;
if (isDisabled) {
return this.renderDisabled();
}
return (
<BytesFile
className={className}
defaultValue={defaultValue}
isError={isError}
label={label}
onChange={this.onChange}
style={style}
withLabel={withLabel}
/>
);
}
private renderDisabled () {
const { className, defaultValue, isError, label, style, type, withLabel } = this.props;
return (
<Bytes
className={className}
defaultValue={defaultValue}
isError={isError}
label={label}
style={style}
type={type}
withLabel={withLabel}
/>
);
}
// TODO: Validate that we have actual proper WASM code
private onChange = (value: Uint8Array): void => {
const { onChange } = this.props;
onChange && onChange({
isValid: value.length !== 0,
value
});
}
}