slate/components/core/DataMeter.js

110 lines
2.5 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
const STYLES_CONTAINER = css`
border-radius: 4px;
2021-08-04 02:02:42 +03:00
box-shadow: 0 0 0 1px ${Constants.semantic.borderGrayLight} inset, ${Constants.shadow.lightSmall};
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-11-08 05:32:17 +03:00
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;
2021-07-07 22:58:14 +03:00
background-color: ${Constants.semantic.bgLight};
overflow: hidden;
`;
const STYLES_DATA_METER = css`
flex-shrink: 0;
2020-09-08 00:45:58 +03:00
height: 16px;
2021-07-07 22:14:51 +03:00
background-color: ${Constants.system.blue};
`;
const STYLES_ROW = css`
display: flex;
align-items: flex-end;
justify-content: space-between;
font-family: ${Constants.font.code};
2021-07-07 22:58:14 +03:00
color: ${Constants.system.grayLight2};
font-size: 10px;
margin-top: 2px;
text-transform: uppercase;
`;
const STYLES_LEFT = css`
min-width: 10%;
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};
2021-07-07 22:58:14 +03:00
color: ${Constants.system.grayLight2};
2020-10-08 01:15:41 +03:00
display: block;
margin-bottom: 4px;
`;
export const DataMeterBar = (props) => {
const percentage = props.bytes / props.maximumBytes;
return (
<React.Fragment>
2020-08-08 03:22:45 +03:00
<div css={STYLES_ROW}>
2020-10-08 01:15:41 +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>
<div
css={STYLES_DATA}
style={{
marginTop: 8,
backgroundColor: props.failed ? Constants.system.red : null,
2020-09-08 00:45:58 +03:00
}}
>
2020-10-08 01:15:41 +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-10-08 01:15:41 +03:00
<DataMeterBar bytes={props.stats.bytes} maximumBytes={props.stats.maximumBytes} />
</div>
);
};
export default DataMeter;