Skip to content

Commit

Permalink
fix: remove scrollbarwidth dependency and use our own (ref #325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grsmto committed Jul 1, 2019
1 parent 1794643 commit e1d8cd7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/simplebar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2",
"lodash.throttle": "^4.1.1",
"resize-observer-polyfill": "^1.5.1",
"scrollbarwidth": "^0.1.3"
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
"css-loader": "^0.28.11",
Expand Down
22 changes: 22 additions & 0 deletions packages/simplebar/src/scrollbar-width.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function scrollbarWidth() {
if (typeof document === 'undefined') {
return 0;
}

const body = document.body;
const box = document.createElement('div');
const boxStyle = box.style;

boxStyle.position = 'fixed';
boxStyle.left = 0;
boxStyle.visibility = 'hidden';
boxStyle.overflowY = 'scroll';

body.appendChild(box);

const width = box.getBoundingClientRect().right;

body.removeChild(box);

return width;
}
2 changes: 1 addition & 1 deletion packages/simplebar/src/simplebar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import scrollbarWidth from 'scrollbarwidth';
import throttle from 'lodash.throttle';
import debounce from 'lodash.debounce';
import memoize from 'lodash.memoize';
import ResizeObserver from 'resize-observer-polyfill';
import canUseDOM from 'can-use-dom';
import scrollbarWidth from './scrollbar-width';

export default class SimpleBar {
constructor(element, options) {
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11080,11 +11080,6 @@ schema-utils@^1.0.0:
ajv-errors "^1.0.0"
ajv-keywords "^3.1.0"

scrollbarwidth@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/scrollbarwidth/-/scrollbarwidth-0.1.3.tgz#1b0de64e288c38c427f4a01fe00a462a04b94fdf"
integrity sha1-Gw3mTiiMOMQn9KAf4ApGKgS5T98=

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down

0 comments on commit e1d8cd7

Please sign in to comment.