|
@@ -4,56 +4,45 @@
|
|
|
|
|
|
import BN from 'bn.js';
|
|
|
import React from 'react';
|
|
|
-import SUIProgress from 'semantic-ui-react/dist/commonjs/modules/Progress/Progress';
|
|
|
+import styled from 'styled-components';
|
|
|
import { UInt } from '@polkadot/types';
|
|
|
import { bnToBn, isBn, isUndefined } from '@polkadot/util';
|
|
|
|
|
|
-import { classes } from './util';
|
|
|
-
|
|
|
-type BaseColors = 'blue' | 'green' | 'red' | 'orange';
|
|
|
-export type Colors = 'auto' | 'autoReverse' | BaseColors;
|
|
|
-
|
|
|
interface Props {
|
|
|
- color?: Colors;
|
|
|
className?: string;
|
|
|
percent?: BN | number;
|
|
|
total?: UInt | BN | number;
|
|
|
value?: UInt | BN | number;
|
|
|
}
|
|
|
|
|
|
-function Progress ({ className = '', color = 'blue', percent, total, value }: Props): React.ReactElement<Props> | null {
|
|
|
+function Progress ({ className = '', percent, total, value }: Props): React.ReactElement<Props> | null {
|
|
|
const _total = bnToBn(total);
|
|
|
const _value = bnToBn(value);
|
|
|
- const calculated = _total.gtn(0)
|
|
|
+ const width = _total.gtn(0)
|
|
|
? (100.0 * _value.toNumber() / _total.toNumber())
|
|
|
: isBn(percent)
|
|
|
? percent.toNumber()
|
|
|
: percent;
|
|
|
|
|
|
- if (isUndefined(calculated) || calculated < 0) {
|
|
|
+ if (isUndefined(width) || width < 0) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- const rainbow = (color === 'auto' || color === 'autoReverse')
|
|
|
- ? (calculated > 66.6)
|
|
|
- ? color === 'auto'
|
|
|
- ? 'green'
|
|
|
- : 'red'
|
|
|
- : (calculated > 33.3)
|
|
|
- ? 'orange'
|
|
|
- : color === 'auto'
|
|
|
- ? 'red'
|
|
|
- : 'green'
|
|
|
- : color;
|
|
|
-
|
|
|
return (
|
|
|
- <SUIProgress
|
|
|
- className={classes('ui--Progress', className)}
|
|
|
- color={rainbow}
|
|
|
- percent={calculated}
|
|
|
- size='tiny'
|
|
|
- />
|
|
|
+ <div className={`ui--Progress ${className}`}>
|
|
|
+ <div style={{ width: `${width}%` }} />
|
|
|
+ </div>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-export default React.memo(Progress);
|
|
|
+export default React.memo(styled(Progress)`
|
|
|
+ background: rgba(0, 0, 0, 0.05);
|
|
|
+ border-radius: 0.25rem;
|
|
|
+ margin: 1em 0 2.5em;
|
|
|
+ overflow: hidden;
|
|
|
+
|
|
|
+ > div {
|
|
|
+ height: 0.25rem;
|
|
|
+ min-width: 0;
|
|
|
+ }
|
|
|
+`);
|