Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte W committed Nov 17, 2015
0 parents commit 7c76064
Show file tree
Hide file tree
Showing 24 changed files with 745 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
"es2015",
"react",
"stage-2"
]
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib
**/node_modules
**/webpack.config.js
examples/**/server.js
19 changes: 19 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "rackt",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"indent": [2, 4],
"comma-dangle": 0,
"semi": 0
},
"plugins": [
"react"
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
*.log
.DS_Store
dist
lib
coverage
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
*.log
src
test
examples
coverage
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "iojs"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
14 changes: 14 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 react-custom-scrollbars

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
178 changes: 178 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
react-custom-scrollbars
=========================

[![npm](https://img.shields.io/badge/npm-react--custom--scrollbars-brightgreen.svg?style=flat-square)]()
[![npm version](https://img.shields.io/npm/v/react-custom-scrollbars.svg?style=flat-square)](https://www.npmjs.com/package/react-custom-scrollbars)
[![npm downloads](https://img.shields.io/npm/dm/react-custom-scrollbars.svg?style=flat-square)](https://www.npmjs.com/package/react-custom-scrollbars)

* lightweight scrollbars made of 100% react goodness
* native scrolling for mobile devices
* no dependencies
* no extra stylesheets
* fully customizable
* IE9+ support
* [email protected]
* **[check out the demo](http://malte-wessel.github.io/react-custom-scrollbars/)**

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Customization](#customization)
- [API](#api)
- [Examples](#examples)
- [License](#license)

## Installation
```bash
npm install react-custom-scrollbars --save
```

## Usage
```javascript
import { Scrollbars } from 'react-custom-scrollbars';

class App extends Component {
render() {
return (
<Scrollbars style={{ width: 500, height: 300 }}>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
</Scrollbars>
);
}
}
```

Don't forget to set the `viewport` meta tag, if you want to support mobile devices

```html
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
```

## Customization
```javascript
import { Scrollbars } from 'react-custom-scrollbars';

class CustomScrollbars extends Component {
render() {
return (
<Scrollbars
className="container"
scrollbarHorizontal={props => <div {...props} className="scrollbar-horizontal" />}
scrollbarVertical={props => <div {...props} className="scrollbar-vertical"/>}
thumbHorizontal={props => <div {...props} className="thumb-horizontal"/>}
thumbVertical={props => <div {...props} className="thumb-vertical"/>}
view={props => <div {...props} className="view"/>}>
{this.props.children}
</Scrollbars>
);
}
}

class App extends Component {
render() {
return (
<CustomScrollbars style={{ width: 500, height: 300 }}>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Lorem ipsum dolor sit amet, ...</p>
</CustomScrollbars>
);
}
}
```

## API

### `<Scrollbars>`

#### Props

* `onScroll`: (Function) Event handler. Will be called with the native scroll event and some handy values about the current position.
* **Signature**: `onScroll(event, values)`
* `event`: (Event) Native onScroll event
* `values`: (Object) Values about the current position
* `values.top`: (Number) scrollTop progess, from 0 to 1
* `values.left`: (Number) scrollLeft progess, from 0 to 1
* `values.clientWidth`: (Number) width of the view
* `values.clientHeight`: (Number) height of the view
* `values.scrollWidth`: (Number) native scrollWidth
* `values.scrollHeight`: (Number) native scrollHeight
* `values.scrollLeft`: (Number) native scrollLeft
* `values.scrollTop`: (Number) native scrollTop
* **The following properties expect a react element to be returned. You can customize the element to your needs.**
* `scrollbarHorizontal`: (Function) Horizontal scrollbar element
* `scrollbarVertical`: (Function) Vertical scrollbar element
* `thumbHorizontal`: (Function) Horizontal thumb element
* `thumbVertical`: (Function) Vertical thumb element
* `view`: (Function) The element your content will be rendered in

**Don't forget to pass the received props to your custom element. Example:**

```javascript
import { Scrollbars } from 'react-custom-scrollbars';

class CustomScrollbars extends Component {
render() {
return (
<Scrollbars
// Set a custom className
scrollbarHorizontal={props => <div {...props} className="scrollbar-vertical"/>}
// Customize inline styles
scrollbarVertical={({ style, ...props}) => {
return <div style={{...style, padding: 20}} {...props}/>;
}}>
{this.props.children}
</Scrollbars>
);
}
}
```

### Receive values about the current position

```javascript
class CustomScrollbars extends Component {
handleScroll(event, values) {
console.log(values);
/*
{
left: 0,
top: 0.21513353115727002
clientWidth: 952
clientHeight: 300
scrollWidth: 952
scrollHeight: 1648
scrollLeft: 0
scrollTop: 290
}
*/
}
render() {
return (
<Scrollbars onScroll={this.handleScroll}>
{this.props.children}
</Scrollbars>
);
}
}
```

## Examples

Run the simple example:
```bash
cd react-custom-scrollbars/examples/simple
npm install
npm start
```

## License

MIT
23 changes: 23 additions & 0 deletions examples/simple/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { createClass } from 'react';
import { Textfit } from 'react-textfit';

export default createClass({

displayName: 'App',

render() {
return (
<div>
<Textfit style={{ height: 100, background: '#eee', border: '1px solid red'}}>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</Textfit>
<Textfit mode="single" style={{ background: '#eee', border: '1px solid red'}}>
Lorem ipsum dolor sit amet
</Textfit>
<Textfit text="Lorem ipsum" max={500} style={{ height: 400, background: '#eee', border: '1px solid red'}}>
{text => text}
</Textfit>
</div>
);
}
});
17 changes: 17 additions & 0 deletions examples/simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
<title>react-textfit simple example</title>
<link rel="stylesheet" href="style.css"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="handheldFriendly" content="true">
</head>
<body>
<div class="container">
<h1>react-textfit</h1>
<div id="root"></div>
</div>
<script src="/static/bundle.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions examples/simple/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';

render(<App />, document.getElementById('root'));
35 changes: 35 additions & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "react-textfit-example",
"version": "0.1.0",
"description": "Simple example",
"main": "server.js",
"scripts": {
"start": "NODE_ENV=development node server.js",
"build": "NODE_ENV=production ./node_modules/.bin/webpack"
},
"repository": {
"type": "git",
"url": "https://github.com/malte-wessel/react-textfit.git"
},
"keywords": [
"scroll",
"scroller",
"scrollbars",
"react"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/malte-wessel/react-textfit/issues"
},
"homepage": "https://github.com/malte-wessel/react-textfit",
"dependencies": {},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"lodash": "^3.10.1",
"node-libs-browser": "^0.5.2",
"react-hot-loader": "^1.2.7",
"webpack": "^1.9.11",
"webpack-dev-server": "^1.9.0"
}
}
15 changes: 15 additions & 0 deletions examples/simple/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true
}
}).listen(3000, 'localhost', function (err) {
if (err) console.log(err);
console.log('Listening at localhost:3000');
});
15 changes: 15 additions & 0 deletions examples/simple/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body {
font-family: sans-serif;
line-height: 1.5;
}

.container {
width: 50%;
margin: 0 auto;
}

@media (max-width: 768px) {
.container {
width: 100%;
}
}
Loading

0 comments on commit 7c76064

Please sign in to comment.