UNPKG

victory-bar

Version:
86 lines (85 loc) 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Bar = void 0; var _react = _interopRequireWildcard(require("react")); var _defaults = _interopRequireDefault(require("lodash/defaults")); var _victoryCore = require("victory-core"); var _barHelperMethods = require("./bar-helper-methods"); var _pathHelperMethods = require("./path-helper-methods"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const evaluateProps = props => { /** * Potential evaluated props of following must be evaluated in this order: * 1) `style` * 2) `barWidth` * 3) `cornerRadius` * * Everything else does not have to be evaluated in a particular order: * `ariaLabel` * `desc` * `id` * `tabIndex` */ const style = (0, _barHelperMethods.getStyle)(props.style, props); const barWidth = (0, _barHelperMethods.getBarWidth)(props.barWidth, Object.assign({}, props, { style })); const cornerRadius = (0, _barHelperMethods.getCornerRadius)(props.cornerRadius, Object.assign({}, props, { style, barWidth })); const ariaLabel = _victoryCore.Helpers.evaluateProp(props.ariaLabel, props); const desc = _victoryCore.Helpers.evaluateProp(props.desc, props); const id = _victoryCore.Helpers.evaluateProp(props.id, props); const tabIndex = _victoryCore.Helpers.evaluateProp(props.tabIndex, props); return Object.assign({}, props, { ariaLabel, style, barWidth, cornerRadius, desc, id, tabIndex }); }; const defaultProps = { pathComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Path, null), role: "presentation", shapeRendering: "auto" }; const Bar = exports.Bar = /*#__PURE__*/(0, _react.forwardRef)( // eslint-disable-next-line prefer-arrow-callback function Bar(initialProps, ref) { const props = evaluateProps((0, _defaults.default)({}, initialProps, defaultProps)); const { polar, origin, style, barWidth, cornerRadius } = props; const path = polar ? (0, _pathHelperMethods.getPolarBarPath)(props, cornerRadius) : (0, _pathHelperMethods.getBarPath)(props, barWidth, cornerRadius); const defaultTransform = polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined; if (!props.pathComponent) { return null; } return /*#__PURE__*/_react.default.cloneElement(props.pathComponent, { ...props.events, "aria-label": props.ariaLabel, style, d: path, className: props.className, clipPath: props.clipPath, desc: props.desc, index: props.index, role: props.role, shapeRendering: props.shapeRendering, transform: props.transform || defaultTransform, tabIndex: props.tabIndex, ref }); });