@mui/x-charts
Version:
The community edition of the Charts components (MUI X).
50 lines (49 loc) • 2.72 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BarClipPath = BarClipPath;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _web = require("@react-spring/web");
var _getRadius = require("./getRadius");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["style", "maskId"];
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 && {}.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 buildInset = corners => `inset(0px round ${corners.topLeft}px ${corners.topRight}px ${corners.bottomRight}px ${corners.bottomLeft}px)`;
function BarClipRect(props) {
const radiusData = props.ownerState;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web.animated.rect, {
style: (0, _extends2.default)({}, props.style, {
clipPath: (props.ownerState.layout === 'vertical' ? props.style?.height : props.style?.width).to(value => buildInset({
topLeft: Math.min(value, (0, _getRadius.getRadius)('top-left', radiusData)),
topRight: Math.min(value, (0, _getRadius.getRadius)('top-right', radiusData)),
bottomRight: Math.min(value, (0, _getRadius.getRadius)('bottom-right', radiusData)),
bottomLeft: Math.min(value, (0, _getRadius.getRadius)('bottom-left', radiusData))
}))
})
});
}
/**
* @ignore - internal component.
*/
function BarClipPath(props) {
const {
style,
maskId
} = props,
rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
if (!props.borderRadius || props.borderRadius <= 0) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)("clipPath", {
id: maskId,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(BarClipRect, {
ownerState: rest,
style: style
})
});
}
;