├── .github └── workflows │ ├── gh-pages-publish.yml │ └── npm-publish.yml ├── .gitignore ├── .npmignore ├── .storybook ├── ComponentDemo.stories.tsx ├── HookDemo.stories.tsx ├── main.js └── preview.css ├── LICENSE ├── README.md ├── package.json ├── react-visibility.jpg ├── src ├── VisibilityObserver.tsx ├── index.ts └── useVisibility.ts └── tsconfig.json /.github/workflows/gh-pages-publish.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Pages deploy 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | deploy-gh-pages: 9 | runs-on: ubuntu-20.04 10 | steps: 11 | - name: 📚 Checkout 12 | uses: actions/checkout@v2 13 | - name: 🟢 Setup Node 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: 16 17 | registry-url: "https://registry.npmjs.org" 18 | - name: Install dependencies 19 | run: npm install 20 | - name: Build Storybook 21 | run: npm run build:storybook 22 | - name: Deploy to GitHub Pages 23 | uses: Cecilapp/GitHub-Pages-deploy@v3 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} 26 | with: 27 | build_dir: storybook-static 28 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to NPM 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | npm_publish: 9 | runs-on: ubuntu-20.04 10 | steps: 11 | - name: 📚 Checkout 12 | uses: actions/checkout@v2 13 | - name: 🟢 Setup Node 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: 14 17 | registry-url: "https://registry.npmjs.org" 18 | - name: 🔧 Install dependencies and build 19 | run: npm install && npm run build 20 | - name: 📦 Publish package on NPM 21 | run: npm publish 22 | env: 23 | NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Folders 2 | /node_modules 3 | package-lock.json 4 | /storybook-static 5 | /dist 6 | # Output of 'npm pack' 7 | *.tgz -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Folders 2 | node_modules 3 | package-lock.json 4 | .storybook 5 | src 6 | /storybook-static 7 | 8 | # Output of 'npm pack' 9 | *.tgz 10 | 11 | # Files 12 | .gitignore 13 | .github -------------------------------------------------------------------------------- /.storybook/ComponentDemo.stories.tsx: -------------------------------------------------------------------------------- 1 | import classNames from "classnames"; 2 | import { useState } from "react"; 3 | import { VisibilityObserver } from "../src"; 4 | 5 | export default { 6 | title: "reactjs-visibility", 7 | }; 8 | 9 | export const ComponentDemo = () => { 10 | const [visible, setVisible] = useState(false); 11 | 12 | return ( 13 |
The sensor is visible
} 19 |Scroll down
20 |22 | The purpose of lorem ipsum is to create a natural looking block of text 23 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 24 | A practice not without controversy, laying out pages with meaningless 25 | filler text can be very useful when the focus is meant to be on design, 26 | not content. 27 |
28 | 29 |30 | The passage experienced a surge in popularity during the 1960s when 31 | Letraset used it on their dry-transfer sheets, and again during the 90s 32 | as desktop publishers bundled the text with their software. Today it's 33 | seen all around the web; on templates, websites, and stock designs. Use 34 | our generator to get your own, or read on for the authoritative history 35 | of lorem ipsum. 36 |
37 | 38 |39 | Until recently, the prevailing view assumed lorem ipsum was born as a 40 | nonsense text. “It's not Latin, though it looks like it, and it actually 41 | says nothing,” Before & After magazine answered a curious reader, “Its 42 | ‘words’ loosely approximate the frequency with which letters occur in 43 | English, which is why at a glance it looks pretty real.” 44 |
45 | 46 |47 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 48 | credited with discovering the source behind the ubiquitous filler text. 49 | In seeing a sample of lorem ipsum, his interest was piqued by 50 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 51 | dictionary led McClintock to a passage from De Finibus Bonorum et 52 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 53 | from the Roman philosopher Cicero. 54 |
55 |56 | The purpose of lorem ipsum is to create a natural looking block of text 57 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 58 | A practice not without controversy, laying out pages with meaningless 59 | filler text can be very useful when the focus is meant to be on design, 60 | not content. 61 |
62 | 63 |64 | The passage experienced a surge in popularity during the 1960s when 65 | Letraset used it on their dry-transfer sheets, and again during the 90s 66 | as desktop publishers bundled the text with their software. Today it's 67 | seen all around the web; on templates, websites, and stock designs. Use 68 | our generator to get your own, or read on for the authoritative history 69 | of lorem ipsum. 70 |
71 | 72 |73 | Until recently, the prevailing view assumed lorem ipsum was born as a 74 | nonsense text. “It's not Latin, though it looks like it, and it actually 75 | says nothing,” Before & After magazine answered a curious reader, “Its 76 | ‘words’ loosely approximate the frequency with which letters occur in 77 | English, which is why at a glance it looks pretty real.” 78 |
79 | 80 |81 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 82 | credited with discovering the source behind the ubiquitous filler text. 83 | In seeing a sample of lorem ipsum, his interest was piqued by 84 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 85 | dictionary led McClintock to a passage from De Finibus Bonorum et 86 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 87 | from the Roman philosopher Cicero. 88 |
89 |90 | The purpose of lorem ipsum is to create a natural looking block of text 91 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 92 | A practice not without controversy, laying out pages with meaningless 93 | filler text can be very useful when the focus is meant to be on design, 94 | not content. 95 |
96 | 97 |98 | The passage experienced a surge in popularity during the 1960s when 99 | Letraset used it on their dry-transfer sheets, and again during the 90s 100 | as desktop publishers bundled the text with their software. Today it's 101 | seen all around the web; on templates, websites, and stock designs. Use 102 | our generator to get your own, or read on for the authoritative history 103 | of lorem ipsum. 104 |
105 | 106 |107 | Until recently, the prevailing view assumed lorem ipsum was born as a 108 | nonsense text. “It's not Latin, though it looks like it, and it actually 109 | says nothing,” Before & After magazine answered a curious reader, “Its 110 | ‘words’ loosely approximate the frequency with which letters occur in 111 | English, which is why at a glance it looks pretty real.” 112 |
113 | 114 |115 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 116 | credited with discovering the source behind the ubiquitous filler text. 117 | In seeing a sample of lorem ipsum, his interest was piqued by 118 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 119 | dictionary led McClintock to a passage from De Finibus Bonorum et 120 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 121 | from the Roman philosopher Cicero. 122 |
123 | 124 |131 | The purpose of lorem ipsum is to create a natural looking block of text 132 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 133 | A practice not without controversy, laying out pages with meaningless 134 | filler text can be very useful when the focus is meant to be on design, 135 | not content. 136 |
137 | 138 |139 | The passage experienced a surge in popularity during the 1960s when 140 | Letraset used it on their dry-transfer sheets, and again during the 90s 141 | as desktop publishers bundled the text with their software. Today it's 142 | seen all around the web; on templates, websites, and stock designs. Use 143 | our generator to get your own, or read on for the authoritative history 144 | of lorem ipsum. 145 |
146 | 147 |148 | Until recently, the prevailing view assumed lorem ipsum was born as a 149 | nonsense text. “It's not Latin, though it looks like it, and it actually 150 | says nothing,” Before & After magazine answered a curious reader, “Its 151 | ‘words’ loosely approximate the frequency with which letters occur in 152 | English, which is why at a glance it looks pretty real.” 153 |
154 | 155 |156 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 157 | credited with discovering the source behind the ubiquitous filler text. 158 | In seeing a sample of lorem ipsum, his interest was piqued by 159 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 160 | dictionary led McClintock to a passage from De Finibus Bonorum et 161 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 162 | from the Roman philosopher Cicero. 163 |
164 |The sensor is visible
} 19 | 20 |Scroll down
21 |23 | The purpose of lorem ipsum is to create a natural looking block of text 24 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 25 | A practice not without controversy, laying out pages with meaningless 26 | filler text can be very useful when the focus is meant to be on design, 27 | not content. 28 |
29 | 30 |31 | The passage experienced a surge in popularity during the 1960s when 32 | Letraset used it on their dry-transfer sheets, and again during the 90s 33 | as desktop publishers bundled the text with their software. Today it's 34 | seen all around the web; on templates, websites, and stock designs. Use 35 | our generator to get your own, or read on for the authoritative history 36 | of lorem ipsum. 37 |
38 | 39 |40 | Until recently, the prevailing view assumed lorem ipsum was born as a 41 | nonsense text. “It's not Latin, though it looks like it, and it actually 42 | says nothing,” Before & After magazine answered a curious reader, “Its 43 | ‘words’ loosely approximate the frequency with which letters occur in 44 | English, which is why at a glance it looks pretty real.” 45 |
46 | 47 |48 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 49 | credited with discovering the source behind the ubiquitous filler text. 50 | In seeing a sample of lorem ipsum, his interest was piqued by 51 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 52 | dictionary led McClintock to a passage from De Finibus Bonorum et 53 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 54 | from the Roman philosopher Cicero. 55 |
56 |57 | The purpose of lorem ipsum is to create a natural looking block of text 58 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 59 | A practice not without controversy, laying out pages with meaningless 60 | filler text can be very useful when the focus is meant to be on design, 61 | not content. 62 |
63 | 64 |65 | The passage experienced a surge in popularity during the 1960s when 66 | Letraset used it on their dry-transfer sheets, and again during the 90s 67 | as desktop publishers bundled the text with their software. Today it's 68 | seen all around the web; on templates, websites, and stock designs. Use 69 | our generator to get your own, or read on for the authoritative history 70 | of lorem ipsum. 71 |
72 | 73 |74 | Until recently, the prevailing view assumed lorem ipsum was born as a 75 | nonsense text. “It's not Latin, though it looks like it, and it actually 76 | says nothing,” Before & After magazine answered a curious reader, “Its 77 | ‘words’ loosely approximate the frequency with which letters occur in 78 | English, which is why at a glance it looks pretty real.” 79 |
80 | 81 |82 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 83 | credited with discovering the source behind the ubiquitous filler text. 84 | In seeing a sample of lorem ipsum, his interest was piqued by 85 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 86 | dictionary led McClintock to a passage from De Finibus Bonorum et 87 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 88 | from the Roman philosopher Cicero. 89 |
90 |91 | The purpose of lorem ipsum is to create a natural looking block of text 92 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 93 | A practice not without controversy, laying out pages with meaningless 94 | filler text can be very useful when the focus is meant to be on design, 95 | not content. 96 |
97 | 98 |99 | The passage experienced a surge in popularity during the 1960s when 100 | Letraset used it on their dry-transfer sheets, and again during the 90s 101 | as desktop publishers bundled the text with their software. Today it's 102 | seen all around the web; on templates, websites, and stock designs. Use 103 | our generator to get your own, or read on for the authoritative history 104 | of lorem ipsum. 105 |
106 | 107 |108 | Until recently, the prevailing view assumed lorem ipsum was born as a 109 | nonsense text. “It's not Latin, though it looks like it, and it actually 110 | says nothing,” Before & After magazine answered a curious reader, “Its 111 | ‘words’ loosely approximate the frequency with which letters occur in 112 | English, which is why at a glance it looks pretty real.” 113 |
114 | 115 |116 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 117 | credited with discovering the source behind the ubiquitous filler text. 118 | In seeing a sample of lorem ipsum, his interest was piqued by 119 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 120 | dictionary led McClintock to a passage from De Finibus Bonorum et 121 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 122 | from the Roman philosopher Cicero. 123 |
124 | 125 |130 | The purpose of lorem ipsum is to create a natural looking block of text 131 | (sentence, paragraph, page, etc.) that doesn't distract from the layout. 132 | A practice not without controversy, laying out pages with meaningless 133 | filler text can be very useful when the focus is meant to be on design, 134 | not content. 135 |
136 | 137 |138 | The passage experienced a surge in popularity during the 1960s when 139 | Letraset used it on their dry-transfer sheets, and again during the 90s 140 | as desktop publishers bundled the text with their software. Today it's 141 | seen all around the web; on templates, websites, and stock designs. Use 142 | our generator to get your own, or read on for the authoritative history 143 | of lorem ipsum. 144 |
145 | 146 |147 | Until recently, the prevailing view assumed lorem ipsum was born as a 148 | nonsense text. “It's not Latin, though it looks like it, and it actually 149 | says nothing,” Before & After magazine answered a curious reader, “Its 150 | ‘words’ loosely approximate the frequency with which letters occur in 151 | English, which is why at a glance it looks pretty real.” 152 |
153 | 154 |155 | Richard McClintock, a Latin scholar from Hampden-Sydney College, is 156 | credited with discovering the source behind the ubiquitous filler text. 157 | In seeing a sample of lorem ipsum, his interest was piqued by 158 | consectetur—a genuine, albeit rare, Latin word. Consulting a Latin 159 | dictionary led McClintock to a passage from De Finibus Bonorum et 160 | Malorum (“On the Extremes of Good and Evil”), a first-century B.C. text 161 | from the Roman philosopher Cicero. 162 |
163 |