Skip to content

Commit feca774

Browse files
committed
Added ability to tur off custom scrollbars with saving the API;
Some optimisations;
1 parent b928c45 commit feca774

File tree

7 files changed

+438
-196
lines changed

7 files changed

+438
-196
lines changed

dist/index.js

Lines changed: 201 additions & 103 deletions
Large diffs are not rendered by default.

dist/util/LoopController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function LoopControllerClass() {
6060
isActive = true;
6161
animationFrameId && cancelAnimationFrame(animationFrameId);
6262
requestAnimationFrame(animationFrameCallback);
63+
return _this;
6364
};
6465
/**
6566
* Stop the loop if it is active
@@ -75,6 +76,7 @@ function LoopControllerClass() {
7576
isActive = false;
7677
animationFrameId && cancelAnimationFrame(animationFrameId);
7778
animationFrameId = null;
79+
return _this;
7880
};
7981
/**
8082
* Return the array pf registered scrollbars

dist/util/utilities.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ var scrollbarWidth = null;
2222
*/
2323

2424
function getScrollbarWidth() {
25-
if (!isset(document)) {
26-
return 0;
27-
}
28-
2925
if (scrollbarWidth !== null) {
3026
return scrollbarWidth;
3127
}
3228

29+
if (!isset(document)) {
30+
return scrollbarWidth = 0;
31+
}
32+
3333
var el = document.createElement("div");
3434
el.setAttribute("style", "display:block;position:absolute;width:100px;height:100px;top:-9999px;overflow:scroll;");
3535
document.body.appendChild(el);

examples/app/components/blocks/SandboxBlock.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ export default class SandboxBlock extends React.Component {
2222
this.handleScrollLeftClick = this.handleScrollLeftClick.bind(this);
2323
this.handleScrollRightClick = this.handleScrollRightClick.bind(this);
2424
this.toggleRtl = this.toggleRtl.bind(this);
25+
this.toggleNativeScrollbarClick = this.toggleNativeScrollbarClick.bind(this);
2526

2627
this.state = {
2728
noScroll: false,
2829
noScrollY: false,
2930
noScrollX: false,
3031

32+
nativeScrollbar: false,
33+
3134
rtl: false,
3235

3336
permanentTracks: false,
@@ -43,7 +46,6 @@ export default class SandboxBlock extends React.Component {
4346

4447
toggleNoScroll() {
4548
this.setState({
46-
...this.state,
4749
noScroll: !this.state.noScroll,
4850
noScrollY: !this.state.noScroll,
4951
noScrollX: !this.state.noScroll,
@@ -52,7 +54,6 @@ export default class SandboxBlock extends React.Component {
5254

5355
toggleNoScrollY() {
5456
this.setState({
55-
...this.state,
5657
noScroll: (this.state.noScroll ? true : this.state.noScrollX) && !this.state.noScrollY,
5758
noScrollY: !this.state.noScrollY,
5859
noScrollX: this.state.noScroll ? true : this.state.noScrollX,
@@ -61,7 +62,6 @@ export default class SandboxBlock extends React.Component {
6162

6263
toggleNoScrollX() {
6364
this.setState({
64-
...this.state,
6565
noScroll: !this.state.noScrollX && (this.state.noScroll ? true : this.state.noScrollY),
6666
noScrollX: !this.state.noScrollX,
6767
noScrollY: this.state.noScroll ? true : this.state.noScrollY,
@@ -70,7 +70,6 @@ export default class SandboxBlock extends React.Component {
7070

7171
togglePermanentTracks() {
7272
this.setState({
73-
...this.state,
7473
permanentTracks: !this.state.permanentTracks,
7574
permanentTrackY: !this.state.permanentTracks,
7675
permanentTrackX: !this.state.permanentTracks,
@@ -79,7 +78,6 @@ export default class SandboxBlock extends React.Component {
7978

8079
togglePermanentTrackY() {
8180
this.setState({
82-
...this.state,
8381
permanentTracks:
8482
(this.state.permanentTracks ? true : this.state.permanentTrackX) && !this.state.permanentTrackY,
8583
permanentTrackY: !this.state.permanentTrackY,
@@ -89,7 +87,6 @@ export default class SandboxBlock extends React.Component {
8987

9088
togglePermanentTrackX() {
9189
this.setState({
92-
...this.state,
9390
permanentTracks:
9491
!this.state.permanentTrackX && (this.state.permanentTracks ? true : this.state.permanentTrackY),
9592
permanentTrackX: !this.state.permanentTrackX,
@@ -99,21 +96,24 @@ export default class SandboxBlock extends React.Component {
9996

10097
toggleRtl() {
10198
this.setState({
102-
...this.state,
10399
rtl: !this.state.rtl,
104100
});
105101
}
106102

103+
toggleNativeScrollbarClick() {
104+
this.setState({
105+
nativeScrollbar: !this.state.nativeScrollbar,
106+
});
107+
}
108+
107109
handleAddParagraphClick() {
108110
this.setState({
109-
...this.state,
110111
paragraphsCount: this.state.paragraphsCount + 1,
111112
});
112113
}
113114

114115
handleRemoveParagraphClick() {
115116
this.setState({
116-
...this.state,
117117
paragraphsCount: Math.max(0, this.state.paragraphsCount - 1),
118118
});
119119
}
@@ -140,12 +140,25 @@ export default class SandboxBlock extends React.Component {
140140
}
141141

142142
render() {
143-
const {noScroll, noScrollY, noScrollX, permanentTracks, permanentTrackY, permanentTrackX, rtl} = this.state;
143+
const {
144+
noScroll,
145+
noScrollY,
146+
noScrollX,
147+
permanentTracks,
148+
permanentTrackY,
149+
permanentTrackX,
150+
rtl,
151+
nativeScrollbar,
152+
} = this.state;
144153

145154
return (
146155
<div className="block" id="SandboxBlock">
147156
<div className="title">Sandbox</div>
148157
<div className="description">
158+
<div className="button" key="nativeScrollbar" onClick={this.toggleNativeScrollbarClick}>
159+
{nativeScrollbar ? "Custom scrollbars" : "Native scrollbars"}
160+
</div>
161+
<br />
149162
<div className="button" key="noScroll" onClick={this.toggleNoScroll}>
150163
{noScroll ? "Enable scroll" : "Disable scroll"}
151164
</div>
@@ -196,6 +209,7 @@ export default class SandboxBlock extends React.Component {
196209
</div>
197210
<div className="content" style={{height: 280}}>
198211
<Scrollbar
212+
nativeScrollbars={nativeScrollbar}
199213
defaultStyles={false}
200214
ref={ref => {
201215
this.scrollbar = ref;

examples/app/style.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ body {
378378
width: 8px;
379379
background: rgba(0, 0, 0, 0.1);
380380
grid-area: 1 / 2 / auto / auto;
381-
overflow: hidden;
381+
overflow: hidden;
382382

383383
& > .ScrollbarsCustom-thumb {
384384
cursor: pointer;
@@ -427,7 +427,14 @@ body {
427427

428428
& > .content {
429429
margin: 2rem 0 0;
430-
& > .ScrollbarsCustom-holder {
430+
& > .ScrollbarsCustom-holder.ScrollbarsCustom-native {
431+
p {
432+
display: inline-block;
433+
position: relative;
434+
width: 150%;
435+
}
436+
}
437+
& > .ScrollbarsCustom-holder:not(.ScrollbarsCustom-native) {
431438
display: grid;
432439
width: 100%;
433440
height: 100%;
@@ -452,7 +459,7 @@ body {
452459
width: 8px;
453460
background: rgba(0, 0, 0, 0.1);
454461
grid-area: 1 / 2 / auto / auto;
455-
overflow: hidden;
462+
overflow: hidden;
456463

457464
& > .ScrollbarsCustom-thumb {
458465
cursor: pointer;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
"husky": {
7171
"hooks": {
72-
"pre-commit": "npm run format && git add .",
72+
"pre-commit": "npm run build && npm run format && git add .",
7373
"post-commit": "git update-index -g"
7474
}
7575
},

0 commit comments

Comments
 (0)