Skip to content

Commit

Permalink
add browser offset option
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao Liu committed Aug 23, 2017
1 parent 9342a8c commit b06d248
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ The starting position of the scroll area. Default: "top left".

Options: "bottom", "bottom right", "top right", "right"

### `browserOffset: String`

The browser scroll bar width. Default: "17px". [It should fit for most browsers](https://codepen.io/sambible/post/browser-scrollbar-widths).

## Customization

Adding a custom className to the component will give you power to customize the scrollbar's track and handler. Here is an example:
Expand Down
2 changes: 1 addition & 1 deletion demo/src/entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let Root = React.createClass({
<div className="col-md-6">
<h4>Quick start</h4>
<div className="quick-start">
<FreeScrollBar start={"top"}>
<FreeScrollBar start={"top"} browserOffset={"20px"}>
<div className="inner">{List}{List}{List}{List}{List}{List}{List}</div>
</FreeScrollBar>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-free-scrollbar",
"version": "0.2.5",
"version": "0.2.6",
"description": "A react module for creating customizable scroll area",
"main": "dist/index.js",
"scripts": {
Expand Down
20 changes: 17 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var React = require('react');
var findDOMNode = require('react-dom').findDOMNode;

const { PropTypes } = React;

const VERTICAL = 'vertial';
const HORIZONTAL = 'horizontal';

Expand All @@ -14,8 +16,6 @@ const styles = {
position: 'absolute',
top: '0',
left: '0',
right: '-15px',
bottom: '-15px',
overflow: 'scroll',
boxSizing: 'border-box'
},
Expand Down Expand Up @@ -76,6 +76,17 @@ const styles = {
module.exports = React.createClass({
displayName: 'FreeScrollbar',

propTypes: {
className: PropTypes.string,
style: PropTypes.object,
fixed: PropTypes.bool,
autohide: PropTypes.bool,
timeout: PropTypes.number,
tracksize: PropTypes.string,
start: PropTypes.string,
browserOffset: PropTypes.string
},

getDefaultProps() {
return {
className: '',
Expand All @@ -88,6 +99,7 @@ module.exports = React.createClass({
timeout: 2000,
tracksize: '10px',
start: 'top left',
browserOffset: '17px'
}
},

Expand Down Expand Up @@ -166,7 +178,9 @@ module.exports = React.createClass({
// Dynamic styles
var containerStyles = {
paddingBottom: this.props.fixed ? 0 : (this.state.showHorizontalTrack ? this.props.tracksize : 0),
paddingBottom: this.props.fixed ? 0 : (this.state.showVeriticalTrack ? this.props.tracksize : 0)
paddingBottom: this.props.fixed ? 0 : (this.state.showVeriticalTrack ? this.props.tracksize : 0),
right: `-${this.props.browserOffset}`,
bottom: `-${this.props.browserOffset}`
};
if (this.state.noselect) {
containerStyles.MozUserSelect = 'none';
Expand Down

0 comments on commit b06d248

Please sign in to comment.