2020-04-14 11:23:11 -08:00
|
|
|
import React from 'react'
|
|
|
|
|
import PropTypes from 'prop-types'
|
2020-11-10 15:27:28 -09:00
|
|
|
import { formatBytes } from '../utils'
|
2021-07-17 09:15:32 -08:00
|
|
|
import { useRecordContext } from 'react-admin'
|
2020-04-14 11:23:11 -08:00
|
|
|
|
2021-07-17 09:15:32 -08:00
|
|
|
export const SizeField = ({ source, ...rest }) => {
|
|
|
|
|
const record = useRecordContext(rest)
|
2020-04-14 11:23:11 -08:00
|
|
|
return <span>{formatBytes(record[source])}</span>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SizeField.propTypes = {
|
|
|
|
|
label: PropTypes.string,
|
|
|
|
|
record: PropTypes.object,
|
|
|
|
|
source: PropTypes.string.isRequired,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SizeField.defaultProps = {
|
|
|
|
|
addLabel: true,
|
|
|
|
|
}
|