Skip to content

Commit 1f2fdc7

Browse files
committed
docs: add <Parallax> docs
1 parent 89b910c commit 1f2fdc7

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const MyComponent = mock();
7979
- [UI](./docs/en/UI.md)
8080
- [`<Portal>`](./docs/en/Portal.md), [`<Overlay>`](./docs/en/Overlay.md), and [`<Modal>`](./docs/en/Modal.md)
8181
- [`<Dimmer>`](./docs/en/Dimmer.md) and [`<Dimmable>`](./docs/en/Dimmable.md)
82+
- [`<Parallax>`](./docs/en/Parallax.md)
8283
- [`<FullScreen>`](./docs/en/FullScreen.md)
8384
- [`<Slider>`](./docs/en/Slider.md)
8485
- [`<DropArea>`](./docs/en/DropArea.md)

docs/en/Parallax.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# `<Parallax>`
2+
3+
This component allows you to create [*Parallax effects*](https://en.wikipedia.org/wiki/Parallax).
4+
5+
It supports [React Universal Interace](https://www.npmjs.com/package/react-universal-interface).
6+
7+
8+
## Usage
9+
10+
The below example will slow down the scrolling of your `<img>` element.
11+
12+
```jsx
13+
import {Parallax} from 'libreact/lib/Parallax';
14+
15+
<Parallax>{({value}) =>
16+
<img style={{marginTop: state.value * 300}} src={/* ... */} />
17+
}</Parallax>
18+
```
19+
20+
21+
## Props
22+
23+
- `distance` &mdash; optional, number, maximum distance for parallax effect to take effect, if omitted,
24+
parallax effect will continue thoughout the lenght of your element, if set, the length of the parallax
25+
effect will be capped at `distance`, defaults to `Infinity`.
26+
- `throttle` &mdash; optional, number in milliseconds, used to throttle document `scroll` event, defaults to `50`.
27+
- `margin` &mdash; optional, a 4-tuple `[top, right, bottom, left]` margins in pixels to apply to the viewport.
28+
- `onChange` &mdash; optional, callback triggered every time the state of `<Parallax>` component changes. Receives the
29+
state of the `<Parallax>` component as a single argument.

docs/en/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [UI](./UI.md)
4949
- [`<Portal>`](./Portal.md), [`<Overlay>`](./Overlay.md), and [`<Modal>`](./Modal.md)
5050
- [`<Dimmer>`](./Dimmer.md) and [`<Dimmable>`](./Dimmable.md)
51+
- [`<Parallax>`](./Parallax.md)
5152
- [`<FullScreen>`](./FullScreen.md)
5253
- [`<Slider>`](./Slider.md)
5354
- [`<DropArea>`](./DropArea.md)

docs/en/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* [Modal](Modal.md)
6060
* [Dimmer](Dimmer.md)
6161
* [Dimmable](Dimmable.md)
62+
* [Parallax](Parallax.md)
6263
* [FullScreen](FullScreen.md)
6364
* [Slider](Slider.m
6465
* [DropArea](DropArea.md)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Parallax} from '..';
2+
import {h} from '../../util';
3+
4+
const StoryParallax1 = () => {
5+
return (
6+
<div>
7+
<div style={{
8+
width: 300,
9+
height: 1e3,
10+
border: '1px solid tomato'
11+
}} />
12+
13+
<Parallax onChange={(data) => console.log(data)}>{(state) =>
14+
<pre style={{marginTop: state.value * 300, border: '1px solid black', height: 300}}>{JSON.stringify(state, null, 4)}</pre>
15+
}</Parallax>
16+
17+
<div style={{
18+
width: 300,
19+
height: 1e3,
20+
border: '1px solid tomato'
21+
}} />
22+
</div>
23+
);
24+
};
25+
26+
export default StoryParallax1;

src/Parallax/__story__/story.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import StoryParallax1 from './StoryParallax1';
44
import StoryParallax2 from './StoryParallax2';
55
import StoryParallax3 from './StoryParallax3';
66
import StoryParallax4 from './StoryParallax4';
7+
import StoryParallax5 from './StoryParallax5';
78

89
storiesOf('UI/Parallax', module)
910
.add('Basic example', () => <StoryParallax1 />)
1011
.add('Card', () => <StoryParallax2 />)
1112
.add('With margin', () => <StoryParallax3 />)
12-
.add('Distance', () => <StoryParallax4 />);
13+
.add('Distance', () => <StoryParallax4 />)
14+
.add('Scroll slowdown', () => <StoryParallax5 />);

0 commit comments

Comments
 (0)