├── .babelrc
├── .eslintrc
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── __tests__
└── index-test.js
├── demo
├── index.html
└── react-toggle-buttonDemo.js
├── lib
└── index.js
├── package.json
├── src
├── colors.js
├── iconExamples.js
├── index.js
├── react-toggle-button.js
├── react-toggle-buttonDemo.js
└── styles.js
├── webpack.config.js
└── webpack.demo.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "react",
4 | "es2015",
5 | "stage-0"
6 | ]
7 | }
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "airbnb",
3 | "plugins": [
4 | "react"
5 | ]
6 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 |
2 | src/
3 | __tests__/
4 | .eslintrc
5 | .babelrc
6 | webpack.config.js
7 | webpack.demo.config.js
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Gavin Owens
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-toggle-button
2 |
3 | ### Getting Started
4 |
5 | #### Step 1
6 | Go here: https://gdowens.github.io/react-toggle-button/
7 |
8 | #### Step 2
9 | 
10 |
11 | ### Credits
12 | Inspired by and loosely based on https://github.com/instructure-react/react-toggle
13 |
--------------------------------------------------------------------------------
/__tests__/index-test.js:
--------------------------------------------------------------------------------
1 | jest.unmock('../src/index');
2 |
3 | import React from 'react';
4 | import ReactDOM from 'react-dom';
5 | import TestUtils from 'react-dom/test-utils';
6 | import index from '../src/index'
7 |
8 | describe('
327 | {description} 328 |329 |
334 | {code} 335 |336 |
360 | {`react-toggle-button`} 361 |362 |
366 | {`// Easy to install and works out-of-the-box 367 | 368 | // Change a few things, or change everything 369 | 370 | // Uses react-motion for animating toggle. 371 | 372 | // Animates hover states too! 373 | 374 | // Quacks like an checkbox, if that's your thing. 375 | 376 | // Sticks to the UI stuff (Redux approved!) 377 | `} 378 |379 |
381 | {`npm install react-toggle-button`} 382 |383 |
384 | {`//ES6 385 | import ToggleButton from 'react-toggle-button' 386 | 387 | //ES5 388 | var ToggleButton = require('react-toggle-button')`} 389 |390 |
397 | {`import ToggleButton from 'react-toggle-button' 398 | 399 | /** 400 | * 'react-toggle-button' PropTypes 401 | */ 402 | ToggleButton.propTypes = { 403 | // 404 | // 405 | // REQUIRED PROPS 406 | // 407 | // 408 | 409 | value: React.PropTypes.bool.isRequired, 410 | /** 411 | * Called during onClick 412 | * 1. triggers 'focus' and 'click' on internal checkbox 413 | * 2. calls onToggle(this.props.active) 414 | */ 415 | onToggle: React.PropTypes.func.isRequired, 416 | 417 | // 418 | // 419 | // OPTIONAL PROPS 420 | // 421 | // 422 | /** 423 | * Object with four properties { active, inactive, activeThumb, inactiveThumb } 424 | * 425 | * each property should have a 'base' key and a 'hover' key 426 | * ( if hover is undefined, that property will use the base value ) 427 | * 428 | */ 429 | colors: React.PropTypes.object, 430 | 431 | 432 | /** 433 | * The label used inside the track, can also take a component 434 | * 435 | * activeLabel (defaultValue: 'ON') 436 | * inactiveLabel (defaultValue: 'OFF') 437 | */ 438 | activeLabel: React.PropTypes.oneOfType([ 439 | React.PropTypes.string, 440 | React.PropTypes.object, 441 | ]), 442 | inactiveLabel: React.PropTypes.oneOfType([ 443 | React.PropTypes.string, 444 | React.PropTypes.object, 445 | ]), 446 | 447 | 448 | /** 449 | * These props specify style, 450 | * hover style is used during mouseOver event 451 | * 452 | * 453 | */ 454 | activeLabelStyle: React.PropTypes.object, 455 | activeLabelStyleHover: React.PropTypes.object, 456 | activeThumbStyle: React.PropTypes.object, 457 | activeThumbStyleHover: React.PropTypes.object, 458 | inactiveLabelStyle: React.PropTypes.object, 459 | inactiveLabelStyleHover: React.PropTypes.object, 460 | thumbStyle: React.PropTypes.object, 461 | thumbStyleHover: React.PropTypes.object, 462 | trackStyle: React.PropTypes.object, 463 | trackStyleHover: React.PropTypes.object, 464 | 465 | 466 | /** 467 | * These props take a function that receives a real number [0, 1] and 468 | * returns an interpolated style. 469 | * 470 | * No Hover -> Hover : 0 -> 1 : No Toggle -> Toggle 471 | */ 472 | animateThumbStyleHover: React.PropTypes.func, 473 | animateTrackStyleHover: React.PropTypes.func, 474 | animateTrackStyleToggle: React.PropTypes.func, 475 | animateThumbStyleToggle: React.PropTypes.func, 476 | 477 | 478 | /** 479 | * passes through internal spring settings for react-motion 480 | * { stiffness, damping } 481 | */ 482 | internalSpringSetting: React.PropTypes.object, 483 | internalHoverSpringSetting: React.PropTypes.object, 484 | 485 | 486 | /** 487 | * Optional if one wants an icon inside the thumb, take a string or component 488 | */ 489 | thumbIcon: React.PropTypes.oneOfType([ 490 | React.PropTypes.string, 491 | React.PropTypes.object, 492 | ]), 493 | 494 | /** 495 | * The range to move the thumb on toggle [starting, ending] 496 | */ 497 | thumbAnimateRange: React.PropTypes.array, 498 | 499 | /** 500 | * If you want to put some props on the underlying element 501 | * you can pass them through this prop. 502 | * 503 | * Example: 504 | * 505 | * passThroughInputProps={{ 506 | * onChange: () => console.log('Hello!') 507 | * }} 508 | * 509 | */ 510 | passThroughInputProps: React.PropTypes.object, 511 | 512 | }`} 513 |514 |