UNPKG

@razorpay/blade

Version:

The Design System that powers Razorpay

66 lines (62 loc) 2.04 kB
import * as React from 'react'; import { useRef, useLayoutEffect } from 'react'; import { addZAxis, replaceZAxis, removeZAxis } from '../state/cartesianAxisSlice.js'; import { useAppDispatch } from '../state/hooks.js'; import { implicitZAxis } from '../state/selectors/axisSelectors.js'; import { resolveDefaultProps } from '../util/resolveDefaultProps.js'; function SetZAxisSettings(settings) { var dispatch = useAppDispatch(); var prevSettingsRef = useRef(null); useLayoutEffect(() => { if (prevSettingsRef.current === null) { dispatch(addZAxis(settings)); } else if (prevSettingsRef.current !== settings) { dispatch(replaceZAxis({ prev: prevSettingsRef.current, next: settings })); } prevSettingsRef.current = settings; }, [settings, dispatch]); useLayoutEffect(() => { return () => { if (prevSettingsRef.current) { dispatch(removeZAxis(prevSettingsRef.current)); prevSettingsRef.current = null; } }; }, [dispatch]); return null; } var zAxisDefaultProps = { zAxisId: 0, range: implicitZAxis.range, scale: implicitZAxis.scale, type: implicitZAxis.type }; /** * Virtual axis, does not render anything itself. Has no ticks, grid lines, or labels. * Useful for dynamically setting Scatter point size, based on data. * * @consumes CartesianViewBoxContext */ function ZAxis(outsideProps) { var props = resolveDefaultProps(outsideProps, zAxisDefaultProps); return /*#__PURE__*/React.createElement(SetZAxisSettings, { domain: props.domain, id: props.zAxisId, dataKey: props.dataKey, name: props.name, unit: props.unit, range: props.range, scale: props.scale, type: props.type, allowDuplicatedCategory: implicitZAxis.allowDuplicatedCategory, allowDataOverflow: implicitZAxis.allowDataOverflow, reversed: implicitZAxis.reversed, includeHidden: implicitZAxis.includeHidden }); } ZAxis.displayName = 'ZAxis'; export { ZAxis, zAxisDefaultProps }; //# sourceMappingURL=ZAxis.js.map