Skip to content

Commit 6aaf86b

Browse files
committed
Initial commit
0 parents  commit 6aaf86b

17 files changed

Lines changed: 13480 additions & 0 deletions

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example of Resize Observer API with React
2+
3+
- [Demo](https://example-react-resize-observer.sethcorker.com/)
4+
- My [article describing the Resize Observer API in a bit more detail](https://blog.sethcorker.com/resize-observer-api/)
5+
6+
## What is this?
7+
8+
An example of the Resize Observer API being used in React with a custom hook.
9+
10+
## How can I run it?
11+
12+
Once you've cloned the repo, make sure you have node and npm installed. Then just run the usual:
13+
`npm start`
14+
15+
Runs the app in the development mode.<br>
16+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
17+
18+
The page will reload if you make edits.<br>
19+
You will also see any lint errors in the console.

package-lock.json

Lines changed: 13069 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "example-react-resize-observer",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"react": "^16.10.1",
7+
"react-dom": "^16.10.1",
8+
"react-scripts": "3.1.2"
9+
},
10+
"scripts": {
11+
"start": "react-scripts start",
12+
"build": "react-scripts build",
13+
"test": "react-scripts test",
14+
"eject": "react-scripts eject"
15+
},
16+
"eslintConfig": {
17+
"extends": "react-app"
18+
},
19+
"browserslist": {
20+
"production": [
21+
">0.2%",
22+
"not dead",
23+
"not op_mini all"
24+
],
25+
"development": [
26+
"last 1 chrome version",
27+
"last 1 firefox version",
28+
"last 1 safari version"
29+
]
30+
}
31+
}

public/favicon.ico

24.3 KB
Binary file not shown.

public/index.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<link
8+
rel="stylesheet"
9+
href="https://unpkg.com/papercss@1.6.1/dist/paper.min.css"
10+
/>
11+
<meta name="theme-color" content="#000000" />
12+
<meta
13+
name="description"
14+
content="Example of Resize Observer API with React"
15+
/>
16+
<!--
17+
manifest.json provides metadata used when your web app is installed on a
18+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
19+
-->
20+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
21+
<!--
22+
Notice the use of %PUBLIC_URL% in the tags above.
23+
It will be replaced with the URL of the `public` folder during the build.
24+
Only files inside the `public` folder can be referenced from the HTML.
25+
26+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
27+
work correctly both with client-side routing and a non-root public URL.
28+
Learn how to configure a non-root public URL by running `npm run build`.
29+
-->
30+
<title>Resize Observer API with React</title>
31+
</head>
32+
<body>
33+
<noscript>You need to enable JavaScript to run this app.</noscript>
34+
<div id="root"></div>
35+
<!--
36+
This HTML file is a template.
37+
If you open it directly in the browser, you will see an empty page.
38+
39+
You can add webfonts, meta tags, or analytics to this file.
40+
The build step will place the bundled scripts into the <body> tag.
41+
42+
To begin the development, run `npm start` or `yarn start`.
43+
To create a production bundle, use `npm run build` or `yarn build`.
44+
-->
45+
<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
46+
<script>
47+
(function(f, a, t, h, o, m) {
48+
a[h] =
49+
a[h] ||
50+
function() {
51+
(a[h].q = a[h].q || []).push(arguments);
52+
};
53+
(o = f.createElement("script")),
54+
(m = f.getElementsByTagName("script")[0]);
55+
o.async = 1;
56+
o.src = t;
57+
o.id = "fathom-script";
58+
m.parentNode.insertBefore(o, m);
59+
})(document, window, "//analytics.sethcorker.com/tracker.js", "fathom");
60+
fathom("set", "siteId", "QCRKN");
61+
fathom("trackPageview");
62+
</script>
63+
<!-- / Fathom -->
64+
</body>
65+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "Fullscreen",
3+
"name": "React - Fullscreen",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *

src/App.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.title {
2+
margin-bottom: 0.1rem;
3+
margin-top: 0;
4+
}
5+
6+
.h1 {
7+
margin-top: 0.25rem;
8+
font-size: 1.8rem;
9+
}

src/App.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from "react";
2+
3+
import Info from "./Info";
4+
import Citations from "./Citations";
5+
import Nav from "./Nav";
6+
import Resources from "./Resources";
7+
import useResponsiveBreakpoints from "./utils/useResponsiveBreakpoints";
8+
import "./App.css";
9+
10+
function App() {
11+
const targetRef = React.useRef(null);
12+
const size = useResponsiveBreakpoints(targetRef, [
13+
{ small: 200 },
14+
{ medium: 400 },
15+
{ large: 600 }
16+
]);
17+
18+
return (
19+
<React.Fragment>
20+
<Nav />
21+
<div className="row">
22+
<div className="lg-5 col">
23+
<div className="paper">
24+
<Info />
25+
</div>
26+
<Resources />
27+
<Citations />
28+
</div>
29+
<div className="lg-7 col">
30+
<div className="paper">
31+
<div className="row">
32+
<div className="col-fill col" style={{ overflow: "hidden" }}>
33+
Try horizontally resizing the box below and see the media query
34+
name change between small, medium and large
35+
<div style={{ overflow: "hidden", width: "100%" }}>
36+
<div
37+
ref={targetRef}
38+
className="border"
39+
style={{
40+
backgroundColor: "aliceblue",
41+
padding: "1rem",
42+
resize: "horizontal",
43+
overflow: "hidden",
44+
maxWidth: "100%",
45+
minWidth: "4rem"
46+
}}
47+
>
48+
{size}
49+
</div>
50+
</div>
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
</div>
56+
</React.Fragment>
57+
);
58+
}
59+
60+
export default App;

0 commit comments

Comments
 (0)