Skip to content

Commit 212072b

Browse files
committed
build: switch to microbundle
1 parent 4b0d1a7 commit 212072b

27 files changed

+1543
-655
lines changed

.editorconfig

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/dependabot.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "npm"
9-
directory: "/"
8+
- package-ecosystem: 'npm'
9+
directory: '/'
1010
schedule:
11-
interval: "monthly"
12-
time: "07:00"
11+
interval: 'monthly'
12+
time: '07:00'

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
stories: ['../src/stories/**/*.@(story|stories).@(ts|tsx|js|jsx|mdx)'],
33
addons: ['@storybook/addon-actions', '@storybook/addon-viewport'],
4-
}
4+
};

.storybook/preview-head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<style>
33
body {
44
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
5-
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
5+
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
66
padding: 0;
77
margin: 0;
88
color: #0c0c0c;

.storybook/preview.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React from 'react'
2-
import { addDecorator, addParameters } from '@storybook/react'
3-
import { create } from '@storybook/theming'
4-
import 'intersection-observer'
5-
import { Global } from '@emotion/react'
1+
import React from 'react';
2+
import { addDecorator, addParameters } from '@storybook/react';
3+
import { create } from '@storybook/theming';
4+
import 'intersection-observer';
5+
import { Global } from '@emotion/react';
66

77
addParameters({
88
options: {
@@ -14,7 +14,7 @@ addParameters({
1414
isFullscreen: false,
1515
panelPosition: 'bottom',
1616
},
17-
})
17+
});
1818

1919
addDecorator((storyFn) => (
2020
<>
@@ -32,4 +32,4 @@ addDecorator((storyFn) => (
3232
/>
3333
{storyFn()}
3434
</>
35-
))
35+
));

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 React Intersection Observer authors
3+
Copyright (c) 2020 React Intersection Observer authors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ npm install react-intersection-observer --save
5555
#### `useInView`
5656

5757
```js
58-
const [ref, inView, entry] = useInView(options)
58+
const [ref, inView, entry] = useInView(options);
5959
```
6060

6161
React Hooks make it easy to monitor the `inView` state of your components. Call
@@ -66,21 +66,21 @@ Assign the `ref` to the DOM element you want to monitor, and the hook will
6666
report the status.
6767

6868
```jsx
69-
import React from 'react'
70-
import { useInView } from 'react-intersection-observer'
69+
import React from 'react';
70+
import { useInView } from 'react-intersection-observer';
7171

7272
const Component = () => {
7373
const [ref, inView, entry] = useInView({
7474
/* Optional options */
7575
threshold: 0,
76-
})
76+
});
7777

7878
return (
7979
<div ref={ref}>
8080
<h2>{`Header inside viewport ${inView}.`}</h2>
8181
</div>
82-
)
83-
}
82+
);
83+
};
8484
```
8585

8686
[![Edit react-intersection-observer](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-intersection-observer-ud2vo?fontsize=14&hidenavigation=1&theme=dark)
@@ -99,7 +99,7 @@ on `entry`, giving you access to all the details about the current intersection
9999
state.
100100

101101
```jsx
102-
import { InView } from 'react-intersection-observer'
102+
import { InView } from 'react-intersection-observer';
103103

104104
const Component = () => (
105105
<InView>
@@ -109,9 +109,9 @@ const Component = () => (
109109
</div>
110110
)}
111111
</InView>
112-
)
112+
);
113113

114-
export default Component
114+
export default Component;
115115
```
116116

117117
### Plain children
@@ -122,15 +122,15 @@ state in your own component. Any extra props you add to `<InView>` will be
122122
passed to the HTML element, allowing you set the `className`, `style`, etc.
123123

124124
```jsx
125-
import { InView } from 'react-intersection-observer'
125+
import { InView } from 'react-intersection-observer';
126126

127127
const Component = () => (
128128
<InView as="div" onChange={(inView, entry) => console.log('Inview:', inView)}>
129129
<h2>Plain children are always rendered. Use onChange to monitor state.</h2>
130130
</InView>
131-
)
131+
);
132132

133-
export default Component
133+
export default Component;
134134
```
135135

136136
> ⚠️ When rendering a plain child, make sure you keep your HTML output semantic.
@@ -157,15 +157,15 @@ argument for the hooks.
157157
> avoid the component re-rendering too often. For example:
158158
159159
```js
160-
const THRESHOLD = [0.25, 0.5, 0.75] // Store multiple thresholds in a constant
160+
const THRESHOLD = [0.25, 0.5, 0.75]; // Store multiple thresholds in a constant
161161
const MyComponent = () => {
162-
const [ref, inView, entry] = useInView({ threshold: THRESHOLD })
162+
const [ref, inView, entry] = useInView({ threshold: THRESHOLD });
163163
return (
164164
<div ref={ref}>
165165
Triggered at intersection ratio {entry.intersectionRatio}
166166
</div>
167-
)
168-
}
167+
);
168+
};
169169
```
170170

171171
### InView Props
@@ -195,25 +195,25 @@ few ideas for how you can use it.
195195
You can wrap multiple `ref` assignments in a single `useCallback`:
196196

197197
```js
198-
import React, { useRef } from 'react'
199-
import { useInView } from 'react-intersection-observer'
198+
import React, { useRef } from 'react';
199+
import { useInView } from 'react-intersection-observer';
200200

201201
function Component(props) {
202-
const ref = useRef()
203-
const [inViewRef, inView] = useInView()
202+
const ref = useRef();
203+
const [inViewRef, inView] = useInView();
204204

205205
// Use `useCallback` so we don't recreate the function on each render - Could result in infinite loop
206206
const setRefs = useCallback(
207207
(node) => {
208208
// Ref's from useRef needs to have the node assigned to `current`
209-
ref.current = node
209+
ref.current = node;
210210
// Callback refs, like the one from `useInView`, is a function that takes the node as an argument
211-
inViewRef(node)
211+
inViewRef(node);
212212
},
213213
[inViewRef],
214-
)
214+
);
215215

216-
return <div ref={setRefs}>Shared ref is visible: {inView}</div>
216+
return <div ref={setRefs}>Shared ref is visible: {inView}</div>;
217217
}
218218
```
219219

@@ -258,23 +258,23 @@ Call the `intersectionMockInstance` method with an element, to get the (mocked)
258258
### Test Example
259259

260260
```js
261-
import React from 'react'
262-
import { render } from 'react-testing-library'
263-
import { useInView } from 'react-intersection-observer'
264-
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils'
261+
import React from 'react';
262+
import { render } from 'react-testing-library';
263+
import { useInView } from 'react-intersection-observer';
264+
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils';
265265

266266
const HookComponent = ({ options }) => {
267-
const [ref, inView] = useInView(options)
268-
return <div ref={ref}>{inView.toString()}</div>
269-
}
267+
const [ref, inView] = useInView(options);
268+
return <div ref={ref}>{inView.toString()}</div>;
269+
};
270270

271271
test('should create a hook inView', () => {
272-
const { getByText } = render(<HookComponent />)
272+
const { getByText } = render(<HookComponent />);
273273

274274
// This causes all (existing) IntersectionObservers to be set as intersecting
275-
mockAllIsIntersecting(true)
276-
getByText('true')
277-
})
275+
mockAllIsIntersecting(true);
276+
getByText('true');
277+
});
278278
```
279279

280280
## Intersection Observer
@@ -301,7 +301,7 @@ yarn add intersection-observer
301301
Then import it in your app:
302302

303303
```js
304-
import 'intersection-observer'
304+
import 'intersection-observer';
305305
```
306306

307307
If you are using Webpack (or similar) you could use
@@ -315,7 +315,7 @@ this:
315315
**/
316316
async function loadPolyfills() {
317317
if (typeof window.IntersectionObserver === 'undefined') {
318-
await import('intersection-observer')
318+
await import('intersection-observer');
319319
}
320320
}
321321
```

docs/Recipes.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ build it according to your needs.
3636
> is a small hook that detects support for `loading` as a side effect.
3737
3838
```jsx
39-
import React from 'react'
40-
import useNativeLazyLoading from '@charlietango/use-native-lazy-loading'
41-
import { useInView } from 'react-intersection-observer'
39+
import React from 'react';
40+
import useNativeLazyLoading from '@charlietango/use-native-lazy-loading';
41+
import { useInView } from 'react-intersection-observer';
4242

4343
const LazyImage = ({ width, height, src, ...rest }) => {
44-
const supportsLazyLoading = useNativeLazyLoading()
44+
const supportsLazyLoading = useNativeLazyLoading();
4545
const [ref, inView] = useInView({
4646
triggerOnce: true,
4747
rootMargin: '200px 0px',
48-
})
48+
});
4949

5050
return (
5151
<div
@@ -67,10 +67,10 @@ const LazyImage = ({ width, height, src, ...rest }) => {
6767
/>
6868
) : null}
6969
</div>
70-
)
71-
}
70+
);
71+
};
7272

73-
export default LazyImage
73+
export default LazyImage;
7474
```
7575

7676
**See [Codesandbox](https://codesandbox.io/embed/lazy-image-load-mjsgc)**
@@ -88,23 +88,23 @@ for an IntersectionObserver.
8888
have it go inwards. You can also use a percentage value, instead of pixels.
8989

9090
```jsx
91-
import React from 'react'
92-
import { useInView } from 'react-intersection-observer'
93-
import { motion } from 'framer-motion'
91+
import React from 'react';
92+
import { useInView } from 'react-intersection-observer';
93+
import { motion } from 'framer-motion';
9494

9595
const LazyAnimation = () => {
9696
const [ref, inView] = useInView({
9797
rootMargin: '-100px 0px',
98-
})
98+
});
9999

100100
return (
101101
<motion.div ref={ref} style={{ opacity: inView ? 1 : 0 }}>
102102
<span aria-label="Wave">👋</span>
103103
</motion.div>
104-
)
105-
}
104+
);
105+
};
106106

107-
export default LazyAnimation
107+
export default LazyAnimation;
108108
```
109109

110110
## Track impressions
@@ -121,24 +121,27 @@ fire an event on your tracking service.
121121
have it go inwards. You can also use a percentage value, instead of pixels.
122122

123123
```jsx
124-
import React, { useEffect } from 'react'
125-
import { useInView } from 'react-intersection-observer'
124+
import React, { useEffect } from 'react';
125+
import { useInView } from 'react-intersection-observer';
126126

127127
const TrackImpression = () => {
128-
const [ref, inView] = useInView({ triggerOnce: true, rootMargin: '-100px 0' })
128+
const [ref, inView] = useInView({
129+
triggerOnce: true,
130+
rootMargin: '-100px 0',
131+
});
129132
useEffect(() => {
130133
if (inView) {
131134
// Fire a tracking event to your tracking service of choice.
132-
dataLayer.push('Section shown') // Here's a GTM dataLayer push
135+
dataLayer.push('Section shown'); // Here's a GTM dataLayer push
133136
}
134-
}, [inView])
137+
}, [inView]);
135138

136139
return (
137140
<div ref={ref}>
138141
Exemplars sunt zeluss de bassus fuga. Credere velox ducunt ad audax amor.
139142
</div>
140-
)
141-
}
143+
);
144+
};
142145

143-
export default TrackImpression
146+
export default TrackImpression;
144147
```

0 commit comments

Comments
 (0)