Skip to content

Commit 3e37e68

Browse files
committed
add rotation props and stories
1 parent 1cdec24 commit 3e37e68

File tree

5 files changed

+121
-8
lines changed

5 files changed

+121
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
}
7474
],
7575
"dependencies": {
76-
"parallax-controller": "0.1.9"
76+
"parallax-controller": "0.1.10"
7777
},
7878
"devDependencies": {
7979
"@babel/core": "^7.16.0",

src/components/Parallax.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ export interface ParallaxProps {
4141
* Second value is the ending rotation
4242
*/
4343
rotate?: string[] | number[];
44+
/**
45+
* Start and end rotation on x-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed.
46+
*
47+
* Example:
48+
*
49+
* rotateX={['0deg', '360deg']}
50+
*
51+
* First value is the starting rotation
52+
* Second value is the ending rotation
53+
*/
54+
rotateX?: string[] | number[];
55+
/**
56+
* Start and end rotation on y-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed.
57+
*
58+
* Example:
59+
*
60+
* rotateY={['0deg', '360deg']}
61+
*
62+
* First value is the starting rotation
63+
* Second value is the ending rotation
64+
*/
65+
rotateY?: string[] | number[];
66+
/**
67+
* Start and end rotation on z-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed.
68+
*
69+
* Example:
70+
*
71+
* rotateZ={['0deg', '360deg']}
72+
*
73+
* First value is the starting rotation
74+
* Second value is the ending rotation
75+
*/
76+
rotateZ?: string[] | number[];
4477
/**
4578
* Optionally pass additional class names to be added to the outermost parallax element.
4679
*/
@@ -97,6 +130,9 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
97130
translateX: props.x,
98131
translateY: props.y,
99132
rotate: props.rotate,
133+
rotateX: props.rotateX,
134+
rotateY: props.rotateY,
135+
rotateZ: props.rotateZ,
100136
},
101137
};
102138
}
@@ -123,7 +159,15 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
123159
);
124160
}
125161
}
126-
}, [props.disabled, props.x, props.y, props.rotate]);
162+
}, [
163+
props.disabled,
164+
props.x,
165+
props.y,
166+
props.rotate,
167+
props.rotateX,
168+
props.rotateY,
169+
props.rotateZ,
170+
]);
127171

128172
const Outer = props.tagOuter;
129173
const Inner = props.tagInner;
@@ -144,6 +188,4 @@ Parallax.defaultProps = {
144188
disabled: false,
145189
tagInner: 'div',
146190
tagOuter: 'div',
147-
x: [0, 0],
148-
y: [0, 0],
149191
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { Parallax } from '../../src';
3+
import { Element } from '../Element/Element';
4+
import { Container } from '../Container';
5+
import styles from './Parallax.module.scss';
6+
7+
const Template = (args) => {
8+
const props = Object.entries(args).reduce((acc: any, entry: any) => {
9+
console.log(entry);
10+
acc[entry[0]] = entry[1].split(',');
11+
return acc;
12+
}, {} as any);
13+
return (
14+
<Container scrollAxis="vertical" className={styles.elements}>
15+
<Parallax {...props} className={styles.parallax}>
16+
<Element name="A" />
17+
</Parallax>
18+
</Container>
19+
);
20+
};
21+
22+
export const WithRotation = Template.bind({});
23+
WithRotation.args = {
24+
rotate: '0deg,360deg',
25+
};
26+
27+
export const WithRotationX = Template.bind({});
28+
WithRotationX.args = {
29+
rotateX: '0deg,360deg',
30+
};
31+
32+
export const WithRotationY = Template.bind({});
33+
WithRotationY.args = {
34+
rotateY: '0deg,360deg',
35+
};
36+
37+
export const WithRotationZ = Template.bind({});
38+
WithRotationZ.args = {
39+
rotateZ: '0deg,360deg',
40+
};
41+
42+
export const WithRotationXY = Template.bind({});
43+
WithRotationXY.args = {
44+
rotateX: '0deg,360deg',
45+
rotateY: '0deg,360deg',
46+
};
47+
48+
export const WithRotationXZ = Template.bind({});
49+
WithRotationXZ.args = {
50+
rotateX: '0deg,360deg',
51+
rotateZ: '0deg,360deg',
52+
};
53+
54+
export const WithRotationYZ = Template.bind({});
55+
WithRotationYZ.args = {
56+
rotateY: '0deg,360deg',
57+
rotateZ: '0deg,360deg',
58+
};
59+
60+
export const WithRotationXYZ = Template.bind({});
61+
WithRotationXYZ.args = {
62+
rotateX: '0deg,360deg',
63+
rotateY: '0deg,360deg',
64+
rotateZ: '0deg,360deg',
65+
};
66+
67+
export default {
68+
title: '<Parallax> New Transforms',
69+
component: WithRotation,
70+
};

stories/Parallax/Parallax.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.parallax {
22
width: 10rem;
33
height: 10rem;
4+
perspective: 500px;
45
}
56

67
.small {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10153,10 +10153,10 @@ pako@~1.0.5:
1015310153
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
1015410154
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
1015510155

10156-
parallax-controller@0.1.9:
10157-
version "0.1.9"
10158-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.9.tgz#3fb47409a3aded7dc067d8ddde530cab5d622562"
10159-
integrity sha512-czH4ic3IQIerN7Wt3uPgY0UkZYT0BihQroREQel8rBGK2Jj0mltmS6Dvc5io9T38pg6L5AcLVVbnM5F9mw1LrQ==
10156+
parallax-controller@0.1.10:
10157+
version "0.1.10"
10158+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.10.tgz#47071d9ac4bd30ae2a0aabfe8b11fde20616ee64"
10159+
integrity sha512-aV4arXEiKfhbaBtg95t1OHr9fJ+rlhjZUfmbu5BwG1LTVThBQH0ZrTdu1aZVwJv9yUjFThCFuB/vkP9ZquNkzQ==
1016010160

1016110161
parallel-transform@^1.1.0:
1016210162
version "1.2.0"

0 commit comments

Comments
 (0)