Skip to content

Commit 558ba9b

Browse files
committed
feat: add switch
0 parents  commit 558ba9b

26 files changed

+463
-0
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"env",
4+
"react",
5+
"stage-0"
6+
]
7+
}

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": ["standard", "standard-react"],
4+
"plugins": ["jest"],
5+
"rules": {
6+
"react/prop-types": false
7+
},
8+
"env": {
9+
"jest/globals": true
10+
}
11+
}

.gitignore

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# dist dir
61+
lib
62+
63+
package-lock.json

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.gitignore
2+
.editorconfig
3+
4+
node_modules/
5+
npm-debug.log
6+
7+
tests/
8+
examples/
9+
coverage/
10+
11+
.travis.yml
12+
*.config.js
13+
.eslintrc.json

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: node_js
2+
cache:
3+
directories:
4+
- ~/.npm
5+
- node_modules
6+
notifications:
7+
email: false
8+
node_js:
9+
- '8'
10+
before_script:
11+
- npm prune
12+
after_success:
13+
- npm run build
14+
- npm run coveralls
15+
- npm run semantic-release
16+
branches:
17+
only:
18+
- master

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Yuki Zhang
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.

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-angular']}

examples/.storybook/.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://storybook.js.org/configurations/custom-babel-config/
2+
{
3+
"presets": [
4+
"env",
5+
"react",
6+
"stage-0"
7+
]
8+
}

examples/.storybook/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@storybook/addon-options/register'

examples/.storybook/config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { configure } from '@storybook/react'
2+
import { setOptions } from '@storybook/addon-options'
3+
4+
function loadStories() {
5+
require('../stories')
6+
// You can require as many stories as you need.
7+
}
8+
9+
setOptions({
10+
name: 'One React',
11+
url: '#'
12+
})
13+
14+
configure(loadStories, module)

examples/.storybook/manager-head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
document.title = "One React"
3+
</script>
4+
<link rel="icon" type="image/ico" href="favicon.ico" />

examples/.storybook/webpack.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
module: {
5+
rules: [
6+
{
7+
test: /\.scss$/,
8+
use: ['style-loader', 'css-loader', 'sass-loader'],
9+
},
10+
{
11+
test: /\.jsx?$/,
12+
use: {
13+
loader: 'babel-loader',
14+
options: {
15+
cacheDirectory: true,
16+
}
17+
},
18+
exclude: /node_modules/,
19+
}
20+
]
21+
},
22+
resolve: {
23+
extensions: ['.js', '.jsx'],
24+
modules: ['node_modules', '../node_modules']
25+
},
26+
}

examples/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "examples",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"dev": "start-storybook -p 9001 -c .storybook",
9+
"build-storybook": "build-storybook -s public",
10+
"deploy": "storybook-to-ghpages"
11+
},
12+
"storybook-deployer": {
13+
"gitUsername": "Yuki Bot",
14+
"gitEmail": "zhangjihong1993@gmail.com",
15+
"commitMessage": "Deploy Storybook"
16+
},
17+
"author": "",
18+
"license": "MIT",
19+
"devDependencies": {
20+
"@storybook/addon-options": "^3.2.17",
21+
"@storybook/react": "^3.2.15",
22+
"css-loader": "^0.28.7",
23+
"node-sass": "^4.7.2",
24+
"sass-loader": "^6.0.6",
25+
"style-loader": "^0.19.0"
26+
},
27+
"dependencies": {
28+
"react": "^16.1.1",
29+
"react-dom": "^16.1.1",
30+
"react-scripts": "^1.0.17"
31+
}
32+
}

examples/public/favicon.ico

561 Bytes
Binary file not shown.

examples/stories/controlled.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { Component } from 'react'
2+
3+
import { Switch } from '../../src'
4+
5+
class Controlled extends Component {
6+
state = {
7+
value: false
8+
}
9+
10+
render () {
11+
return (
12+
<div>
13+
<Switch checked={this.state.value} onChange={this.handleChange} />
14+
<button onClick={this.handleSubmit}>submit</button>
15+
</div>
16+
)
17+
}
18+
19+
handleChange = checked => {
20+
this.setState({
21+
value: checked
22+
})
23+
}
24+
25+
handleSubmit = e => {
26+
e.preventDefault()
27+
window.alert('switch is ' + this.state.value)
28+
}
29+
}
30+
31+
export default Controlled

examples/stories/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
// import { action } from '@storybook/addon-actions'
4+
5+
import { Switch } from '../../src'
6+
7+
import Controlled from './controlled'
8+
9+
storiesOf('Switch', module)
10+
.add('switch', () => (
11+
<div>
12+
<div>蓝牙?</div>
13+
<Switch checked onChange={(isChecked) => { console.log(isChecked) }} />
14+
<div>开挂模式?</div>
15+
<Switch onChange={(isChecked) => { console.log(isChecked) }} />
16+
</div>
17+
))
18+
.add('Controlled', () => (
19+
<Controlled />
20+
))

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
collectCoverageFrom: [
4+
'src/**',
5+
'!src/*\\.scss',
6+
'!src/index.js'
7+
],
8+
mapCoverage: true,
9+
setupFiles: [
10+
'<rootDir>/tests/setup.js'
11+
],
12+
testPathIgnorePatterns: [
13+
'<rootDir>/node_modules/',
14+
'<rootDir>/src/index.js',
15+
'<rootDir>/src/*\\.scss'
16+
],
17+
testRegex: '/tests/.+\\.test\\.js$'
18+
}

package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "or-switch",
3+
"description": "",
4+
"main": "lib/index.js",
5+
"jsnext:main": "src/index.js",
6+
"scripts": {
7+
"test": "jest -c jest.config.js --bail --coverage",
8+
"build": "babel src --out-dir lib --copy-files",
9+
"watch": "babel src --watch --out-dir lib",
10+
"lint": "eslint src",
11+
"precommit": "npm run lint",
12+
"commitmsg": "commitlint -e $GIT_PARAMS",
13+
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
14+
"commit": "git-cz",
15+
"coveralls": "cat ./coverage/lcov.info | coveralls"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/one-react/switch.git"
20+
},
21+
"author": "One React Org",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/one-react/switch/issues"
25+
},
26+
"homepage": "https://github.com/one-react/switch#readme",
27+
"devDependencies": {
28+
"@commitlint/cli": "^4.3.0",
29+
"@commitlint/config-angular": "^4.3.0",
30+
"babel-cli": "^6.26.0",
31+
"babel-eslint": "^8.0.3",
32+
"babel-preset-env": "^1.6.1",
33+
"babel-preset-react": "^6.24.1",
34+
"babel-preset-stage-0": "^6.24.1",
35+
"commitizen": "^2.9.6",
36+
"coveralls": "^3.0.0",
37+
"cz-conventional-changelog": "^2.1.0",
38+
"enzyme": "^3.2.0",
39+
"enzyme-adapter-react-16": "^1.1.0",
40+
"eslint": "^4.11.0",
41+
"eslint-config-standard": "^10.2.1",
42+
"eslint-config-standard-react": "^5.0.0",
43+
"eslint-plugin-import": "^2.8.0",
44+
"eslint-plugin-jest": "^21.3.2",
45+
"eslint-plugin-node": "^5.2.1",
46+
"eslint-plugin-promise": "^3.6.0",
47+
"eslint-plugin-react": "^7.4.0",
48+
"eslint-plugin-standard": "^3.0.1",
49+
"husky": "^0.14.3",
50+
"jest": "^21.2.1",
51+
"raf": "^3.4.0",
52+
"prop-types": "^15.6.0",
53+
"react": "^16.1.1",
54+
"react-dom": "^16.1.1",
55+
"semantic-release": "^8.2.0"
56+
},
57+
"dependencies": {
58+
"classnames": "^2.2.5",
59+
"or-theme": "^1.1.0"
60+
},
61+
"peerDependencies": {
62+
"react": ">=15.5",
63+
"prop-types": ">=15"
64+
},
65+
"config": {
66+
"commitizen": {
67+
"path": "./node_modules/cz-conventional-changelog"
68+
}
69+
}
70+
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#One More React Component: switch
2+
[![Build Status](https://img.shields.io/travis/one-react/switch.svg)](https://travis-ci.org/one-react/switch)[![Coveralls github](https://img.shields.io/coveralls/github/one-react/switch.svg)](https://coveralls.io/github/one-react/switch)[![Version](https://img.shields.io/npm/v/or-switch.svg)](https://www.npmjs.com/package/or-switch)[![Chat](https://img.shields.io/gitter/room/one-react-org/Lobby.svg)](https://gitter.im/one-react-org/Lobby)[![Code Climate](https://img.shields.io/codeclimate/github/one-react/switch.svg)](https://codeclimate.com/github/one-react/switch)[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

0 commit comments

Comments
 (0)