@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
124 lines • 7.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var typestyle_1 = require("typestyle");
var theming_1 = require("../../../Common/theming/");
var Currency_1 = require("../Currency");
var Tooltip_1 = require("../Tooltip");
var styles_1 = require("./styles");
var Shadow = (React.createElement("defs", null,
React.createElement("filter", { id: "dropshadow", x: "-40%", y: "-40%", width: "200%", height: "200%", filterUnits: "userSpaceOnUse" },
React.createElement("feGaussianBlur", { stdDeviation: "3" }),
React.createElement("feOffset", { dx: "-2", dy: "6", result: "offsetblur" }),
React.createElement("feFlood", { floodColor: theming_1.UpThemeColorMap.gray2, floodOpacity: "0.50" }),
React.createElement("feComposite", { in2: "offsetblur", operator: "in" }),
React.createElement("feMerge", null,
React.createElement("feMergeNode", null),
React.createElement("feMergeNode", { in: "SourceGraphic" })))));
var DisplayValue = function (_a) {
var value = _a.value, max = _a.max, modeDisplayValue = _a.modeDisplayValue, valueLabelStyle = _a.valueLabelStyle;
switch (modeDisplayValue) {
case 'none':
return null;
case 'fraction':
return (React.createElement("div", { className: typestyle_1.style(valueLabelStyle) },
React.createElement("span", { className: 'up-progress-value' },
React.createElement(Currency_1.default, { value: value })),
React.createElement("span", { className: 'up-progress-value-max' },
" / ",
React.createElement(Currency_1.default, { value: max }))));
case 'percentage':
return (React.createElement("div", { className: typestyle_1.style(valueLabelStyle) },
React.createElement("span", null, Math.ceil(value / max * 100))));
}
return null;
};
var DisplayUnite = function (_a) {
var uniteLabel = _a.uniteLabel, uniteStyle = _a.uniteStyle;
return (uniteLabel ? React.createElement("div", { className: typestyle_1.style(uniteStyle) }, uniteLabel) : null);
};
var getCompletedOffset = function (value, maxValue, size, clockWise) {
var r = size;
var c = Math.PI * (r * 2);
var v = value;
if (value < 0) {
v = 0;
}
if (value > maxValue) {
v = maxValue;
}
var offsetValue = (maxValue - value) / maxValue * c;
return clockWise ? -offsetValue : offsetValue;
};
var getRadius = function (size) {
return Math.abs(size / 2 - 10);
};
var ProgressCircle = (function (_super) {
tslib_1.__extends(ProgressCircle, _super);
function ProgressCircle(props) {
var _this = _super.call(this, props) || this;
_this.state = {
completedDashOffset: getCompletedOffset(0, props.max, getRadius(props.size), props.clockWise),
};
return _this;
}
ProgressCircle.getDerivedStateFromProps = function (props, state) {
return {
completedDashOffset: getCompletedOffset(props.value, props.max, getRadius(props.size), props.clockWise),
};
};
ProgressCircle.prototype.componentDidMount = function () {
var _this = this;
var _a = this.props, value = _a.value, max = _a.max, clockWise = _a.clockWise, size = _a.size;
var r = getRadius(size);
this.completedDashOffset =
setTimeout(function () {
return _this.setState({
completedDashOffset: getCompletedOffset(value, max, r, clockWise),
});
}, 300);
};
ProgressCircle.prototype.componentWillUnmount = function () {
clearTimeout(this.completedDashOffset);
};
ProgressCircle.prototype.render = function () {
var _this = this;
var _a = this.props, completedColor = _a.completedColor, uncompletedColor = _a.uncompletedColor, thickness = _a.thickness, value = _a.value, size = _a.size, backgroundColor = _a.backgroundColor, shadow = _a.shadow, max = _a.max, modeDisplayValue = _a.modeDisplayValue, uniteStyle = _a.uniteStyle, uniteLabel = _a.uniteLabel, valueLabelStyle = _a.valueLabelStyle;
var r = getRadius(size);
var fullDashOffset = Math.PI * 2 * r;
var unCompletedDashOffset = 0;
var renderValue = React.createElement("div", { className: styles_1.LabelCircularProgressStyle(this.props) },
React.createElement(DisplayValue, { value: value, max: max, modeDisplayValue: this.props.size < 80 ? 'percentage' : modeDisplayValue, valueLabelStyle: valueLabelStyle || styles_1.DefaultValueLabelStyle(this.props) }),
React.createElement(DisplayUnite, { uniteLabel: uniteLabel, uniteStyle: uniteStyle || styles_1.DefaultUniteStyle(this.props) }));
var renderTooltip = React.createElement("div", { className: styles_1.TooltipCircularProgressStyle(this.props) },
React.createElement(DisplayValue, { value: value, max: max, modeDisplayValue: modeDisplayValue, valueLabelStyle: valueLabelStyle }),
React.createElement(DisplayUnite, { uniteLabel: uniteLabel, uniteStyle: uniteStyle || styles_1.DefaultUniteStyle(this.props) }));
return (React.createElement(Tooltip_1.default, { content: this.props.size <= 60 ? renderTooltip : null }, function (props) { return (React.createElement("div", { "data-tip": "tooltip", "data-for": props.id, className: styles_1.WrapperCircularProgressStyle },
React.createElement("svg", { width: size + 20, height: size + 20, version: "1.1", xmlns: "http://www.w3.org/2000/svg" },
Shadow,
React.createElement("circle", { x: 10, y: 10, style: shadow ? { filter: 'url(#dropshadow)' } : {}, strokeWidth: thickness, stroke: uncompletedColor, r: r, cx: size / 2, cy: size / 2, fill: backgroundColor, strokeDasharray: fullDashOffset, strokeDashoffset: unCompletedDashOffset }),
React.createElement("circle", { x: 10, y: 10, strokeWidth: thickness, stroke: completedColor, r: r, cx: size / 2, cy: size / 2, fill: "transparent", strokeDasharray: fullDashOffset, strokeDashoffset: _this.state.completedDashOffset })),
_this.props.size > 60 &&
renderValue)); }));
};
ProgressCircle.defaultProps = {
min: 0,
max: 100,
size: 120,
thickness: 5,
value: 0,
completedColor: theming_1.UpThemeColorMap.primary,
uncompletedColor: theming_1.UpThemeColorMap.disabledBg,
backgroundColor: theming_1.UpThemeColorMap.white,
shadow: false,
uniteLabel: '',
modeDisplayValue: 'fraction',
clockWise: true,
theme: theming_1.default,
};
return ProgressCircle;
}(React.PureComponent));
;
exports.default = ProgressCircle;
//# sourceMappingURL=UpProgressCircle.js.map