Skip to content

Commit 79564a7

Browse files
committed
docs: parallax provider doc updates and examples
1 parent d613c4a commit 79564a7

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

documentation/docs/usage/components/parallax-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const SlowAndFast = () => (
2727
);
2828
```
2929

30-
**NOTE:** The `speed` prop simplifies the application of a `translateX` or `translateY` effect based on the `ParallaxController` scroll axis [TODO](#link)
30+
**NOTE:** The `speed` prop simplifies the application of a `translateX` or `translateY` effect based on the `ParallaxController` scroll axis [See <ParallaxProvider\> Props](/docs/usage/components/parallax-provider#parallaxprovider-props)
3131

3232
## Translate Controls
3333

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# ParallaxProvider
22

3-
The `<ParallaxProvider />` component is meant to wrap a top level component in your application and is necessary to provide access through the React context API to the [parallax controller](https://parallax-controller.vercel.app/docs/intro). This component should only be used once in you app, for instance in an `<AppContainer />` component that won't be mounted/unmounted during route changes. Like so:
3+
The `<ParallaxProvider />` component is meant to wrap a root level component in your application and is necessary to provide access through the React context API to the [Parallax Controller](https://parallax-controller.vercel.app/docs/intro).
4+
5+
## Basic Example
6+
7+
This component should only be used once in you app, for instance in an `<AppContainer />` component that won't be mounted/unmounted during route changes. Like so:
8+
9+
```tsx
10+
import { ParallaxProvider } from 'react-scroll-parallax';
411

5-
```jsx
612
const AppContainer = () => (
713
<ParallaxProvider>
814
<Router>
@@ -12,11 +18,38 @@ const AppContainer = () => (
1218
);
1319
```
1420

21+
**NOTE:** You can have multiple providers, however they will all be independent instances of a `ParallaxController`. It's recommended to only use one when possible.
22+
1523
## ParallaxProvider Props
1624

1725
The following props configure the `<ParallaxProvider>` component:
1826

19-
| Name | Type | Default | Description |
20-
| ------------------- | :-----------: | :--------- | ------------------------------------------------------------------------------------------------------------ |
21-
| **scrollAxis** | `string` | `vertical` | Optionally pass the scroll axis for setting horizontal/vertical scrolling. One of `vertical` or `horizontal` |
22-
| **scrollContainer** | `HTMLElement` | `<body>` | Optionally set the container that has overflow and will contain parallax elements. Defaults to the HTML body |
27+
| Name | Type | Default | Description |
28+
| ------------------- | :-----------: | :--------- | ------------------------------------------------------------------------------------------------------------------------ |
29+
| **scrollAxis** | `string` | `vertical` | Optionally pass the scroll axis for setting horizontal/vertical scrolling. One of `vertical` or `horizontal` |
30+
| **scrollContainer** | `HTMLElement` | `<body>` | Optionally set the container that has overflow and will contain parallax elements. Defaults to the document scroll body. |
31+
32+
## Example: Scroll Container
33+
34+
By default the <ParallaxProvider\> defaults to the document scrolling element. If your app's overflow is a unique element you need to provide the element as the `scrollContainer`. Here's how:
35+
36+
```tsx
37+
import * as React from 'react';
38+
import { ParallaxProvider } from 'react-scroll-parallax';
39+
40+
const ScrollContainer = () => {
41+
const [scrollEl, setScrollElement] = React.useState(null);
42+
const ref = React.useRef<HTMLDivElement>();
43+
React.useEffect(() => {
44+
setScrollElement(ref.current);
45+
});
46+
47+
return (
48+
<div className="your-scroll-container" ref={ref}>
49+
<ParallaxProvider scrollContainer={scrollEl}>
50+
{props.children}
51+
</ParallaxProvider>
52+
</div>
53+
);
54+
};
55+
```

0 commit comments

Comments
 (0)