tdesign-react
Version:
TDesign Component for React
44 lines (40 loc) • 1.19 kB
JavaScript
/**
* tdesign v1.16.2
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _slicedToArray } from '../../_chunks/dep-10d5731f.js';
import { useRef, useState, useCallback } from 'react';
import '../../_chunks/dep-74a10cfb.js';
var useRotate = function useRotate() {
var rotRef = useRef(0);
var _useState = useState(0),
_useState2 = _slicedToArray(_useState, 2),
rotateZ = _useState2[0],
setRotateZ = _useState2[1];
var onRotate = useCallback(function (ROTATE_COUNT) {
setRotateZ(function (rotateZ2) {
rotRef.current = rotateZ2 + ROTATE_COUNT;
return rotateZ2 + ROTATE_COUNT;
});
}, []);
var onResetRotate = useCallback(function () {
var degreeToRotate = rotRef.current % 360;
if (Math.abs(degreeToRotate) > 180) {
degreeToRotate = (degreeToRotate + 360) % 360;
}
if (degreeToRotate !== 0) {
setRotateZ(function (rotateZ2) {
rotRef.current = rotateZ2 - degreeToRotate;
return rotateZ2 - degreeToRotate;
});
}
}, []);
return {
rotateZ: rotateZ,
onResetRotate: onResetRotate,
onRotate: onRotate
};
};
export { useRotate as default };
//# sourceMappingURL=useRotate.js.map