Skip to content

Commit 1753ba3

Browse files
authored
Merge pull request #2 from baseten/expose-transform-hooks
Separate out transformations as hooks and export from library
2 parents 9989643 + 266629b commit 1753ba3

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

src/Transform2d.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ export function apply2dTransforms({
7373
}
7474
}
7575

76-
const Transform2d = ({
77-
children,
76+
export function use2dTransformations({
7877
parentMatrixWorld,
7978
translate,
8079
scale,
8180
rotate,
8281
multiplicationOrder = 'POST',
83-
}: Transform2dProps) => {
82+
}: Omit<Transform2dProps, 'children'>) {
8483
const safeParentMatrixWorld = useFactoryRef<mat2d>(
8584
() => parentMatrixWorld || mat2d.create(),
8685
);
@@ -101,6 +100,28 @@ const Transform2d = ({
101100
rotate,
102101
});
103102

103+
return {
104+
matrix,
105+
matrixWorld,
106+
};
107+
}
108+
109+
const Transform2d = ({
110+
children,
111+
parentMatrixWorld,
112+
translate,
113+
scale,
114+
rotate,
115+
multiplicationOrder = 'POST',
116+
}: Transform2dProps) => {
117+
const { matrixWorld } = use2dTransformations({
118+
parentMatrixWorld,
119+
translate,
120+
scale,
121+
rotate,
122+
multiplicationOrder,
123+
});
124+
104125
const render = useRender<mat2d>({
105126
cssMatrixPrefix: 'matrix',
106127
matrixWorld,

src/Transform3d.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ export function apply3dTransforms({
8080
}
8181
}
8282

83-
const Transform3d = ({
84-
children,
83+
export function use3dTransformations({
8584
parentMatrixWorld,
8685
translate,
8786
scale,
8887
rotate,
8988
rotateAxis,
9089
multiplicationOrder = 'POST',
91-
}: Transform3dProps) => {
90+
}: Omit<Transform3dProps, 'children'>) {
9291
const safeParentMatrixWorld = useFactoryRef<mat4>(
9392
() => parentMatrixWorld || mat4.create(),
9493
);
@@ -112,6 +111,30 @@ const Transform3d = ({
112111
rotateAxis,
113112
});
114113

114+
return {
115+
matrix,
116+
matrixWorld,
117+
};
118+
}
119+
120+
const Transform3d = ({
121+
children,
122+
parentMatrixWorld,
123+
translate,
124+
scale,
125+
rotate,
126+
rotateAxis,
127+
multiplicationOrder = 'POST',
128+
}: Transform3dProps) => {
129+
const { matrixWorld } = use3dTransformations({
130+
parentMatrixWorld,
131+
translate,
132+
scale,
133+
rotate,
134+
rotateAxis,
135+
multiplicationOrder,
136+
});
137+
115138
const render = useRender<mat4>({
116139
cssMatrixPrefix: 'matrix3d',
117140
matrixWorld,

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './propTypes';
22
export { useFactoryRef } from './useFactoryRef';
3-
export { default as Transform2d } from './Transform2d';
4-
export { default as Transform3d } from './Transform3d';
3+
export { default as Transform2d, use2dTransformations } from './Transform2d';
4+
export { default as Transform3d, use3dTransformations } from './Transform3d';
55
export type { Transform2dProps } from './Transform2d';
66
export type { Transform3dProps } from './Transform3d';
7+
export type { GLMatrixType, Vec2Object, Vec3Object } from './types';

test/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ exports[`index export modules for react-css-transform 1`] = `
77
"mat2dGlMatrix": [Function],
88
"mat4GlMatrix": [Function],
99
"mat4GlMatrixValidator": [Function],
10+
"use2dTransformations": [Function],
11+
"use3dTransformations": [Function],
1012
"useFactoryRef": [Function],
1113
"vec2GlMatrix": [Function],
1214
"vec2Obj": [Function],

0 commit comments

Comments
 (0)