Skip to content

Commit 37a346e

Browse files
committed
init
0 parents  commit 37a346e

27 files changed

+7462
-0
lines changed

.all-contributorsrc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"projectName": "@byteclaw/hooks",
3+
"projectOwner": "byteclaw",
4+
"repoType": "github",
5+
"repoHost": "https://github.com",
6+
"files": [
7+
"README.md"
8+
],
9+
"imageSize": 100,
10+
"commit": true,
11+
"contributors": [
12+
{
13+
"login": "michalkvasnicak",
14+
"name": "Michal Kvasničák",
15+
"avatar_url": "https://avatars1.githubusercontent.com/u/174716?v=4",
16+
"profile": "https://github.com/michalkvasnicak",
17+
"contributions": ["question", "code", "design", "doc", "example", "ideas", "review", "test"]
18+
},
19+
{
20+
"login": "jurajhrib",
21+
"name": "Juraj Hríb",
22+
"avatar_url": "https://avatars1.githubusercontent.com/u/373788?v=4",
23+
"profile": "https://github.com/jurajhrib",
24+
"contributions": ["question", "code", "design", "doc", "example", "ideas", "review", "test"]
25+
}
26+
]
27+
}

.circleci/config.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
working_directory: ~/hooks
6+
docker:
7+
- image: circleci/node:10.12.0
8+
environment:
9+
CI: 1
10+
- image: browserless/chrome:release-chrome-stable
11+
steps:
12+
- checkout
13+
- run:
14+
name: Upgrade yarn to 1.12.3
15+
command: sudo npm install -g [email protected]
16+
- run:
17+
name: Installing javascript dependencies
18+
command: yarn install
19+
- run:
20+
name: Linting the source code
21+
command: yarn lint
22+
- run:
23+
name: Build packages
24+
command: yarn build
25+
- run:
26+
name: Typechecking the source code
27+
command: yarn typecheck
28+
- run:
29+
name: Testing the source code
30+
command: yarn test:ci
31+
32+
workflows:
33+
version: 2
34+
test:
35+
jobs:
36+
- build

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
coverage
3+
**/__diff_output__/*
4+
!**/__diff_output__/.gitkeep
5+
*.log
6+
.vscode/*
7+
!.vscode/tasks.json
8+
.idea
9+
.cache
10+
build
11+
packages/**/*.tgz
12+
dist

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"trailingComma": "all",
4+
"singleQuote": true
5+
}

.watchmanconfig

Whitespace-only changes.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 @byteclaw
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Whitespace-only changes.

docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3'
2+
3+
services:
4+
chrome:
5+
image: browserless/chrome:release-chrome-stable
6+
ports:
7+
- '3000:3000'

jest-puppeteer.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
connect: {
3+
browserWSEndpoint: 'ws://localhost:3000',
4+
},
5+
};

jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
// hack because jest does not support global* in project configs
3+
// https://github.com/facebook/jest/issues/5441
4+
// globalSetup: '<rootDir>/node_modules/jest-environment-puppeteer/setup',
5+
// globalTeardown: '<rootDir>/node_modules/jest-environment-puppeteer/teardown',
6+
projects: [
7+
'<rootDir>/packages/use-overlay-scroll-position/jest.config.js',
8+
],
9+
};

jest/setup.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('react-testing-library/cleanup-after-each');
2+
3+
jest.setTimeout(30 * 1000);

lerna.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"packages": [
3+
"packages/*"
4+
],
5+
"npmClient": "yarn",
6+
"useWorkspaces": true,
7+
"version": "0.5.3"
8+
}

package.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"private": true,
3+
"publishConfig": {
4+
"access": "public"
5+
},
6+
"scripts": {
7+
"build": "node ./scripts/build.js",
8+
"contributors:add": "all-contributors add",
9+
"contributors:generate": "all-contributors generate",
10+
"lint": "lerna run lint",
11+
"test": "jest --coverage",
12+
"test:ci": "jest --ci --coverage --runInBand",
13+
"test:watch": "jest --watch",
14+
"storybook:build": "npx lerna run storybook:build",
15+
"storybook:run": "npx lerna run storybook:run",
16+
"typecheck": "npx lerna run typecheck"
17+
},
18+
"lint-staged": {
19+
"src/**/*.json": [
20+
"prettier --write",
21+
"git add"
22+
],
23+
"stories/**/*.{js,jsx,ts,tsx}": [
24+
"prettier --write",
25+
"git add"
26+
]
27+
},
28+
"husky": {
29+
"hooks": {
30+
"pre-commit": "lint-staged"
31+
}
32+
},
33+
"devDependencies": {
34+
"@babel/core": "^7.2.0",
35+
"@types/jest": "^23.3.10",
36+
"@types/react": "^16.7.13",
37+
"@types/react-dom": "^16.0.11",
38+
"@types/react-test-renderer": "^16.0.3",
39+
"all-contributors-cli": "^5.4.1",
40+
"babel-core": "^7.0.0-bridge.0",
41+
"husky": "^1.1.4",
42+
"jest": "^23.6.0",
43+
"lerna": "^3.13.1",
44+
"lint-staged": "^7.2.0",
45+
"prettier": "^1.15.3",
46+
"react": "^16.8.3",
47+
"react-test-renderer": "^16.8.3",
48+
"rimraf": "^2.6.2",
49+
"rollup": "^0.67.3",
50+
"rollup-plugin-babel": "^4.0.3",
51+
"rollup-plugin-commonjs": "^9.1.6",
52+
"rollup-plugin-node-globals": "^1.4.0",
53+
"rollup-plugin-node-resolve": "^3.4.0",
54+
"rollup-plugin-replace": "^2.1.0",
55+
"rollup-plugin-sourcemaps": "^0.4.2",
56+
"rollup-plugin-terser": "^3.0.0",
57+
"shelljs": "^0.8.3",
58+
"ts-jest": "^23.10.5",
59+
"tslint": "^5.11.0",
60+
"tslint-config-prettier": "^1.16.0",
61+
"tslint-react": "^3.6.0",
62+
"typescript": "^3.2.2"
63+
},
64+
"resolutions": {
65+
"babel-core": "^7.0.0-bridge.0"
66+
},
67+
"workspaces": {
68+
"packages": [
69+
"packages/*"
70+
]
71+
}
72+
}

packages/use-overlay-scroll-position/.gitignore

Whitespace-only changes.

packages/use-overlay-scroll-position/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
displayName: '@byteclaw/use-overlay-scroll-position',
3+
rootDir: __dirname,
4+
globals: {
5+
'ts-jest': {
6+
diagnostics: true,
7+
},
8+
},
9+
setupTestFrameworkScriptFile: '<rootDir>/jest/setup.js',
10+
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
11+
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
12+
testEnvironment: 'jsdom',
13+
testMatch: ['<rootDir>/**/__tests__/*.(test|spec).{js,jsx,ts,tsx}'],
14+
transform: {
15+
'^.+\\.(js|jsx)$': 'babel-jest',
16+
'^.+\\.(ts|tsx)$': 'ts-jest',
17+
}
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('react-testing-library/cleanup-after-each');
2+
3+
jest.setTimeout(30 * 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@byteclaw/use-overlay-scroll-position",
3+
"version": "1.0.0",
4+
"description": "React hook for calculating number of pixels scrolled through in an overflow:scroll enabled container",
5+
"main": "dist/use-overlay-scroll-position.cjs.js",
6+
"umd:main": "dist/use-overlay-scroll-position.umd.js",
7+
"jsnext:main": "dist/use-overlay-scroll-position.m.js",
8+
"module": "dist/use-overlay-scroll-position.m.js",
9+
"typings": "dist/index.d.js",
10+
"scripts": {
11+
"build": "npx tsc && rollup -c",
12+
"lint": "tslint -p .",
13+
"prebuild": "rimraf dist temp",
14+
"prepublishOnly": "npm run build",
15+
"test": "jest",
16+
"test:watch": "jest --watch",
17+
"typecheck": "tsc --noEmit"
18+
},
19+
"peerDependencies": {
20+
"@types/react": "^16.7.13",
21+
"react": "^16.8.3"
22+
},
23+
"devDependencies": {
24+
"react-dom": "^16.8.3",
25+
"react-testing-library": "^5.3.0",
26+
"typescript": "^3.2.2"
27+
},
28+
"sideEffects": false,
29+
"repository": {
30+
"type": "git",
31+
"url": "git+https://github.com/byteclaw/hooks.git"
32+
},
33+
"keywords": [
34+
"react",
35+
"hooks"
36+
],
37+
"license": "MIT",
38+
"bugs": {
39+
"url": "https://github.com/byteclaw/hooks/issues"
40+
},
41+
"homepage": "https://github.com/byteclaw/hooks#readme",
42+
"contributors": [
43+
{
44+
"name": "Michal Kvasničák",
45+
"url": "https://github.com/michalkvasnicak"
46+
},
47+
{
48+
"name": "Juraj Hríb",
49+
"url": "https://github.com/jurajhrib"
50+
}
51+
],
52+
"files": [
53+
"dist"
54+
],
55+
"publishConfig": {
56+
"access": "public"
57+
}
58+
}

packages/use-overlay-scroll-position/rollup.config.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// tslint:disable:jsx-no-lambda
2+
import React, { Fragment, ReactNode, useRef } from 'react';
3+
import { fireEvent, render } from 'react-testing-library';
4+
import useOverlayScrollPosition from '../index';
5+
6+
function BigBox() {
7+
const box = useRef<HTMLDivElement>(null);
8+
const buffer = new Array(99999);
9+
10+
const { current } = box;
11+
12+
if (current != null) {
13+
current.style.overflowY = 'scroll';
14+
current.style.height = '10000px';
15+
current.style.width = '100px';
16+
}
17+
18+
return (
19+
<div data-testid="bigbox" ref={box}>
20+
{buffer.map(i => '∆')}
21+
</div>
22+
);
23+
}
24+
25+
function Box({
26+
children,
27+
onChange,
28+
}: {
29+
children: ReactNode | ReactNode[];
30+
onChange: (val: [number | null, number | null]) => any;
31+
}) {
32+
const box = useRef<HTMLDivElement>(null);
33+
const [position, height] = useOverlayScrollPosition(box);
34+
35+
onChange([position, height]);
36+
37+
const { current } = box;
38+
39+
if (current != null) {
40+
current.style.overflowY = 'scroll';
41+
current.style.height = '100px';
42+
current.style.width = '100px';
43+
}
44+
45+
return (
46+
<Fragment>
47+
<div data-testid="box" ref={box}>
48+
{children}
49+
</div>
50+
</Fragment>
51+
);
52+
}
53+
54+
describe('useOverlayScrollPosition hook', () => {
55+
it('works corretly', async () => {
56+
const onChangeMock = jest.fn();
57+
let values :[number | null, number | null] = [null, null];
58+
const setValues = (val: [number | null, number | null]) => { values = val };
59+
onChangeMock.mockImplementation((val) => setValues(val));
60+
61+
const { getByTestId } = render(
62+
<Box onChange={onChangeMock}>
63+
<BigBox />
64+
</Box>,
65+
);
66+
67+
getByTestId('box').scrollTop = 200;
68+
69+
70+
expect(values[0]).toBe(0);
71+
72+
fireEvent.scroll(getByTestId('box'));
73+
74+
expect(values[0]).toBe(200);
75+
expect(onChangeMock).toHaveBeenCalledTimes(4);
76+
});
77+
});

0 commit comments

Comments
 (0)