mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
scm-ui: new repository layout
This commit is contained in:
27
scm-ui/ui-components/src/FileSize.js
Normal file
27
scm-ui/ui-components/src/FileSize.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
bytes: number
|
||||
};
|
||||
|
||||
class FileSize extends React.Component<Props> {
|
||||
static format(bytes: number) {
|
||||
if (!bytes) {
|
||||
return "0 B";
|
||||
}
|
||||
|
||||
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1000));
|
||||
|
||||
const size = i === 0 ? bytes : (bytes / 1000 ** i).toFixed(2);
|
||||
return `${size} ${units[i]}`;
|
||||
}
|
||||
|
||||
render() {
|
||||
const formattedBytes = FileSize.format(this.props.bytes);
|
||||
return <span>{formattedBytes}</span>;
|
||||
}
|
||||
}
|
||||
|
||||
export default FileSize;
|
||||
Reference in New Issue
Block a user