@geezee/react-ui
Version:
Modern and minimalist React UI library.
47 lines (43 loc) • 2.25 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _JSXStyle from "styled-jsx/style";
import React, { useMemo } from 'react';
import withDefaults from '../utils/with-defaults';
import useTheme from '../styles/use-theme';
import { useProportions } from '../utils/calculations';
var defaultProps = {
value: 0,
limit: 100,
color: '',
className: ''
};
var getColor = function getColor(val, palette) {
if (val < 33) return palette.cyan;
if (val < 66) return palette.warning;
return palette.errorDark;
};
var Capacity = function Capacity(_ref) {
var value = _ref.value,
limit = _ref.limit,
userColor = _ref.color,
className = _ref.className,
props = _objectWithoutProperties(_ref, ["value", "limit", "color", "className"]);
var theme = useTheme();
var percentValue = useProportions(value, limit);
var color = useMemo(function () {
if (userColor && userColor !== '') return userColor;
return getColor(percentValue, theme.palette);
}, [userColor, percentValue, theme.palette]);
return /*#__PURE__*/React.createElement("div", _extends({
title: "".concat(percentValue, "%")
}, props, {
className: _JSXStyle.dynamic([["3625852684", [theme.expressiveness.R2, theme.palette.accents_2, percentValue, color]]]) + " " + (props && props.className != null && props.className || "capacity ".concat(className))
}), /*#__PURE__*/React.createElement("span", {
className: _JSXStyle.dynamic([["3625852684", [theme.expressiveness.R2, theme.palette.accents_2, percentValue, color]]])
}), /*#__PURE__*/React.createElement(_JSXStyle, {
id: "3625852684",
dynamic: [theme.expressiveness.R2, theme.palette.accents_2, percentValue, color]
}, ".capacity.__jsx-style-dynamic-selector{width:50px;height:10px;border-radius:".concat(theme.expressiveness.R2, ";overflow:hidden;background-color:").concat(theme.palette.accents_2, ";}span.__jsx-style-dynamic-selector{width:").concat(percentValue, "%;background-color:").concat(color, ";height:100%;margin:0;padding:0;display:block;}")));
};
var MemoCapacity = React.memo(Capacity);
export default withDefaults(MemoCapacity, defaultProps);