slate/components/core/DataMeter.js

124 lines
3.0 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
import * as System from "~/components/system";
import { css } from "@emotion/react";
// NOTE(jim): Consolidate if used elsewhere on the client (Not node_common)
const MAX_IN_BYTES = 10737418240 * 4;
const STYLES_CONTAINER = css`
border-radius: 4px;
2020-10-08 01:15:41 +03:00
box-shadow: 0 0 0 1px ${Constants.system.lightBorder} inset, 0 0 40px 0 ${Constants.system.shadow};
2020-09-08 00:45:58 +03:00
padding: 32px;
2020-08-26 07:13:50 +03:00
max-width: 100%;
2020-08-08 03:22:45 +03:00
width: 100%;
2020-10-01 03:41:53 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
padding: 24px;
}
`;
const STYLES_DATA = css`
width: 100%;
display: flex;
align-items: center;
2020-09-08 00:45:58 +03:00
height: 16px;
border-radius: 3px;
2020-09-08 00:45:58 +03:00
background-color: ${Constants.system.foreground};
overflow: hidden;
`;
const STYLES_DATA_METER = css`
flex-shrink: 0;
2020-09-08 00:45:58 +03:00
height: 16px;
2020-11-04 17:53:18 +03:00
background-color: ${Constants.system.brand};
`;
const STYLES_ROW = css`
display: flex;
align-items: flex-end;
justify-content: space-between;
font-family: ${Constants.font.code};
color: ${Constants.system.darkGray};
font-size: 10px;
margin-top: 2px;
text-transform: uppercase;
`;
const STYLES_STATS_ROW = css`
display: flex;
align-items: flex-end;
justify-content: space-between;
2020-09-08 00:45:58 +03:00
font-family: ${Constants.font.text};
color: ${Constants.system.black};
font-size: 12px;
text-transform: uppercase;
`;
const STYLES_LEFT = css`
min-width: 10%;
2020-11-04 17:53:18 +03:00
width: 100% "";
`;
const STYLES_RIGHT = css`
flex-shrink: 0;
`;
const STYLES_TITLE = css`
2020-09-08 00:45:58 +03:00
font-family: ${Constants.font.medium};
font-size: ${Constants.typescale.lvl1};
display: block;
margin-bottom: 4px;
overflow-wrap: break-word;
`;
2020-10-08 01:15:41 +03:00
const STYLES_NOTE = css`
2020-10-08 06:03:57 +03:00
margin-top: 8px;
2020-10-08 01:15:41 +03:00
font-family: ${Constants.font.text};
font-size: ${Constants.typescale.lvl0};
color: ${Constants.system.darkGray};
display: block;
margin-bottom: 4px;
`;
export const DataMeterBar = (props) => {
const percentage = props.bytes / props.maximumBytes;
2020-11-04 17:53:18 +03:00
return (
<React.Fragment>
2020-08-08 03:22:45 +03:00
<div css={STYLES_ROW}>
2020-11-04 17:53:18 +03:00
<div css={STYLES_LEFT} style={{ color: props.failed ? Constants.system.red : null }}>
{props.leftLabel}
</div>
<div css={STYLES_RIGHT}>{props.rightLabel}</div>
2020-08-08 03:22:45 +03:00
</div>
2020-11-04 17:53:18 +03:00
<div
css={STYLES_DATA}
style={{
marginTop: 8,
2020-11-04 17:53:18 +03:00
backgroundColor: props.failed ? Constants.system.red : null,
2020-09-08 00:45:58 +03:00
}}
>
2020-11-04 17:53:18 +03:00
<div css={STYLES_DATA_METER} style={{ width: `${percentage * 100}%` }} />
</div>
</React.Fragment>
);
};
export const DataMeter = (props) => {
return (
<div css={STYLES_CONTAINER} style={props.style}>
<div css={STYLES_TITLE}>
2020-10-08 01:15:41 +03:00
{Strings.bytesToSize(props.stats.bytes)} of {Strings.bytesToSize(props.stats.maximumBytes)}{" "}
used
</div>
2020-11-04 17:53:18 +03:00
<DataMeterBar bytes={props.stats.bytes} maximumBytes={props.stats.maximumBytes} />
2020-10-08 06:03:57 +03:00
<div css={STYLES_NOTE}>50GB coming soon with email verification</div>
</div>
);
};
export default DataMeter;