UNPKG

@shopgate/engage

Version:
30 lines (29 loc) 710 B
import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import { formatFloat } from "../QuantityInput/helper"; /** * @param {Object} props The component props. * @returns {JSX} */ import { jsx as _jsx } from "react/jsx-runtime"; const QuantityLabel = ({ value, maxDecimals, unit, className }) => { const output = useMemo(() => { const formatted = formatFloat(value, maxDecimals); return unit ? `${formatted} ${unit}` : formatted; }, [maxDecimals, unit, value]); return /*#__PURE__*/_jsx("span", { className: className, children: output }); }; QuantityLabel.defaultProps = { className: '', maxDecimals: 2, unit: null }; export default QuantityLabel;