bee-switch
Advanced tools
Comparing version
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _react = require('react'); | ||
var _react = require("react"); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactDom = require('react-dom'); | ||
var _reactDom = require("react-dom"); | ||
var _reactDom2 = _interopRequireDefault(_reactDom); | ||
var _classnames = require('classnames'); | ||
var _classnames = require("classnames"); | ||
var _classnames2 = _interopRequireDefault(_classnames); | ||
var _propTypes = require('prop-types'); | ||
var _propTypes = require("prop-types"); | ||
@@ -34,102 +34,113 @@ var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var propTypes = { | ||
clsPrefix: _propTypes2["default"].string, | ||
disabled: _propTypes2["default"].bool, | ||
checkedChildren: _propTypes2["default"].any, | ||
unCheckedChildren: _propTypes2["default"].any, | ||
onChangeHandler: _propTypes2["default"].func | ||
clsPrefix: _propTypes2["default"].string, | ||
disabled: _propTypes2["default"].bool, | ||
checkedChildren: _propTypes2["default"].any, | ||
unCheckedChildren: _propTypes2["default"].any, | ||
onChangeHandler: _propTypes2["default"].func, | ||
onChange: _propTypes2["default"].func | ||
}; | ||
var defaultProps = { | ||
clsPrefix: 'u-switch', | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
defaultChecked: false, | ||
size: '', | ||
disabled: false, | ||
onChangeHandler: function onChangeHandler() {} | ||
clsPrefix: "u-switch", | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
defaultChecked: false, | ||
size: "", | ||
disabled: false, | ||
onChangeHandler: function onChangeHandler() {}, | ||
onChange: function onChange() {} | ||
}; | ||
var Switch = function (_Component) { | ||
_inherits(Switch, _Component); | ||
_inherits(Switch, _Component); | ||
function Switch(props) { | ||
_classCallCheck(this, Switch); | ||
function Switch(props) { | ||
_classCallCheck(this, Switch); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
var checked = false; | ||
if ('checked' in _this.props) { | ||
checked = !!_this.props.checked; | ||
} else { | ||
checked = !!_this.props.defaultChecked; | ||
} | ||
_this.state = { | ||
checked: checked | ||
}; | ||
_this.clickHandler = _this.clickHandler.bind(_this); | ||
return _this; | ||
} | ||
_initialiseProps.call(_this); | ||
Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextState) { | ||
if (nextProps.checked) { | ||
this.setState({ checked: nextProps.checked }); | ||
} else if (nextProps.defaultChecked) { | ||
this.setState({ checked: nextProps.defaultChecked }); | ||
} | ||
}; | ||
var checked = false; | ||
if ("checked" in _this.props) { | ||
checked = !!_this.props.checked; | ||
} else { | ||
checked = !!_this.props.defaultChecked; | ||
} | ||
_this.state = { | ||
checked: checked | ||
}; | ||
return _this; | ||
} | ||
//点击switch改变状态 | ||
Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextState) { | ||
if (nextProps.checked) { | ||
this.setState({ checked: nextProps.checked }); | ||
} else if (nextProps.defaultChecked) { | ||
this.setState({ checked: nextProps.defaultChecked }); | ||
} | ||
}; | ||
//点击switch改变状态 | ||
Switch.prototype.clickHandler = function clickHandler() { | ||
if (this.props.checked != undefined) { | ||
return; | ||
} | ||
var checked = this.state.checked; | ||
this.setState({ | ||
checked: !checked | ||
}); | ||
this.props.onChangeHandler(!checked); | ||
}; | ||
Switch.prototype.render = function render() { | ||
var _props = this.props, | ||
checkedChildren = _props.checkedChildren, | ||
unCheckedChildren = _props.unCheckedChildren, | ||
onChangeHandler = _props.onChangeHandler, | ||
size = _props.size, | ||
className = _props.className, | ||
clsPrefix = _props.clsPrefix, | ||
colors = _props.colors; | ||
//获取checked | ||
Switch.prototype.render = function render() { | ||
var _props = this.props, | ||
checkedChildren = _props.checkedChildren, | ||
unCheckedChildren = _props.unCheckedChildren, | ||
onChangeHandler = _props.onChangeHandler, | ||
size = _props.size, | ||
className = _props.className, | ||
clsPrefix = _props.clsPrefix, | ||
colors = _props.colors; | ||
//获取checked | ||
var checked = this.state.checked; | ||
var classes = { | ||
'is-checked': checked | ||
}; | ||
if (size) { | ||
classes[clsPrefix + '-' + size] = true; | ||
} | ||
if (colors) { | ||
classes[clsPrefix + '-' + colors] = true; | ||
} | ||
var classNames = (0, _classnames2["default"])(clsPrefix, classes); | ||
var checked = this.state.checked; | ||
var classes = { | ||
"is-checked": checked | ||
}; | ||
if (size) { | ||
classes[clsPrefix + "-" + size] = true; | ||
} | ||
if (colors) { | ||
classes[clsPrefix + "-" + colors] = true; | ||
} | ||
var classNames = (0, _classnames2["default"])(clsPrefix, classes); | ||
return _react2["default"].createElement( | ||
'span', | ||
{ onClick: this.clickHandler, className: (0, _classnames2["default"])(className, classNames), tabIndex: '0' }, | ||
_react2["default"].createElement( | ||
'span', | ||
{ | ||
className: clsPrefix + '-inner' }, | ||
checked ? checkedChildren : unCheckedChildren | ||
) | ||
); | ||
}; | ||
return _react2["default"].createElement( | ||
"span", | ||
{ | ||
onClick: this.clickHandler, | ||
className: (0, _classnames2["default"])(className, classNames), | ||
tabIndex: "0" | ||
}, | ||
_react2["default"].createElement( | ||
"span", | ||
{ className: clsPrefix + "-inner" }, | ||
checked ? checkedChildren : unCheckedChildren | ||
) | ||
); | ||
}; | ||
return Switch; | ||
return Switch; | ||
}(_react.Component); | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.clickHandler = function () { | ||
if (_this2.props.checked != undefined) { | ||
return; | ||
} | ||
var checked = _this2.state.checked; | ||
_this2.setState({ | ||
checked: !checked | ||
}); | ||
_this2.props.onChangeHandler(!checked); | ||
_this2.props.onChange(!checked); | ||
}; | ||
}; | ||
Switch.propTypes = propTypes; | ||
Switch.defaultProps = defaultProps; | ||
exports["default"] = Switch; | ||
module.exports = exports['default']; | ||
module.exports = exports["default"]; |
/** | ||
* | ||
* @title 默认开关 | ||
* @description | ||
* @description | ||
* | ||
*/ | ||
import React, { Component } from 'react'; | ||
import Switch from '../../src'; | ||
import React, { Component } from "react"; | ||
import { Row, Col } from "bee-layout"; | ||
import Switch from "../../src"; | ||
class Demo1 extends Component { | ||
render () { | ||
return ( | ||
<div> | ||
<Switch /> | ||
<Switch defaultChecked={true}/> | ||
<Switch checked/> | ||
</div> | ||
) | ||
} | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
defaultChecked: true | ||
}; | ||
} | ||
onChange = () => { | ||
this.setState({ | ||
defaultChecked: !this.state.defaultChecked | ||
}); | ||
}; | ||
render() { | ||
return ( | ||
<Row> | ||
<Col sm={2}> | ||
<Switch /> | ||
</Col> | ||
<Col sm={2}> | ||
<Switch | ||
defaultChecked={this.state.defaultChecked} | ||
onChange={this.onChange} | ||
/> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
} | ||
export default Demo1; | ||
export default Demo1; |
@@ -8,25 +8,24 @@ /** | ||
import React, { Component } from 'react'; | ||
import {Row, Col } from 'bee-layout'; | ||
import Switch from '../../src'; | ||
import React, { Component } from "react"; | ||
import { Row, Col } from "bee-layout"; | ||
import Switch from "../../src"; | ||
class Demo2 extends Component { | ||
render () { | ||
return ( | ||
<Row> | ||
<Col sm={2}> | ||
<Switch checked={true} size='sm' /> | ||
</Col> | ||
<Col sm={2}> | ||
<Switch checked={true} /> | ||
</Col> | ||
<Col sm={2}> | ||
<Switch checked={true} size='lg' /> | ||
</Col> | ||
</Row> | ||
) | ||
} | ||
render() { | ||
return ( | ||
<Row> | ||
<Col sm={2}> | ||
<Switch size="sm" /> | ||
</Col> | ||
<Col sm={2}> | ||
<Switch /> | ||
</Col> | ||
<Col sm={2}> | ||
<Switch size="lg" /> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
} | ||
export default Demo2; | ||
export default Demo2; |
@@ -8,36 +8,40 @@ /** | ||
import React, { Component } from 'react'; | ||
import {Row, Col } from 'bee-layout'; | ||
import Switch from '../../src'; | ||
import React, { Component } from "react"; | ||
import { Row, Col } from "bee-layout"; | ||
import Switch from "../../src"; | ||
class Demo3 extends Component { | ||
constructor(props){ | ||
super(props); | ||
this.state = { | ||
switch : "", | ||
checked: false | ||
}; | ||
this.changeHandle = this.changeHandle.bind(this); | ||
} | ||
changeHandle(e){ | ||
this.setState({ | ||
switch: `${e}`, | ||
checked: !this.state.checked | ||
}) | ||
} | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
switch: "", | ||
checked: false | ||
}; | ||
} | ||
onChange = e => { | ||
this.setState({ | ||
switch: `${e}`, | ||
checked: !this.state.checked | ||
}); | ||
}; | ||
render () { | ||
return ( | ||
<Row> | ||
<Col sm={2}> | ||
<Switch defaultChecked={this.state.checked} onChangeHandler = {this.changeHandle} checkedChildren={'on'} unCheckedChildren={'off'} /> | ||
</Col> | ||
<Col sm={2}> | ||
<span>{ this.state.switch }</span> | ||
</Col> | ||
</Row> | ||
) | ||
} | ||
render() { | ||
return ( | ||
<Row> | ||
<Col sm={2}> | ||
<Switch | ||
defaultChecked={this.state.checked} | ||
onChange={this.onChange} | ||
checkedChildren={"on"} | ||
unCheckedChildren={"off"} | ||
/> | ||
</Col> | ||
<Col sm={2}> | ||
<span>{this.state.switch}</span> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
} | ||
export default Demo3; |
@@ -15,3 +15,3 @@ | ||
var Demo1 = require("./demolist/Demo1");var Demo2 = require("./demolist/Demo2");var Demo3 = require("./demolist/Demo3");var DemoArray = [{"example":<Demo1 />,"title":" 默认开关","code":"/**\n *\n * @title 默认开关\n * @description \n *\n */\nimport React, { Component } from 'react';\nimport Switch from 'bee-switch';\n\nclass Demo1 extends Component {\n render () {\n return (\n <div>\n <Switch />\n <Switch defaultChecked={true}/>\n <Switch checked/>\n </div>\n \n )\n }\n}\n\n","desc":" "},{"example":<Demo2 />,"title":" 不同大小的开关","code":"/**\n *\n * @title 不同大小的开关\n * @description 通过`size`属性控制开关的大小\n *\n */\n\nimport React, { Component } from 'react';\nimport {Row, Col } from 'bee-layout';\nimport Switch from 'bee-switch';\n\nclass Demo2 extends Component {\n\n render () {\n return (\n <Row>\n <Col sm={2}>\n <Switch checked={true} size='sm' />\n </Col>\n <Col sm={2}>\n <Switch checked={true} />\n </Col>\n <Col sm={2}>\n <Switch checked={true} size='lg' />\n </Col>\n </Row>\n )\n }\n}\n\n","desc":" 通过`size`属性控制开关的大小"},{"example":<Demo3 />,"title":" 事件开关","code":"/**\n *\n * @title 事件开关\n * @description 点击开关触发事件\n *\n */\n\nimport React, { Component } from 'react';\nimport {Row, Col } from 'bee-layout';\nimport Switch from 'bee-switch';\n\nclass Demo3 extends Component {\n constructor(props){\n super(props);\n this.state = {\n switch : \"\",\n checked: false\n };\n this.changeHandle = this.changeHandle.bind(this);\n }\n changeHandle(e){\n\t\tthis.setState({\n switch: `${e}`,\n checked: !this.state.checked\n })\n\t}\n\n render () {\n return (\n <Row>\n <Col sm={2}>\n <Switch defaultChecked={this.state.checked} onChangeHandler = {this.changeHandle} checkedChildren={'on'} unCheckedChildren={'off'} />\n </Col>\n <Col sm={2}>\n <span>{ this.state.switch }</span>\n </Col>\n </Row>\n )\n }\n}\n\n\n","desc":" 点击开关触发事件"}] | ||
var Demo1 = require("./demolist/Demo1");var Demo2 = require("./demolist/Demo2");var Demo3 = require("./demolist/Demo3");var DemoArray = [{"example":<Demo1 />,"title":" 默认开关","code":"/**\n *\n * @title 默认开关\n * @description\n *\n */\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo1 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n defaultChecked: true\n };\n }\n onChange = () => {\n this.setState({\n defaultChecked: !this.state.defaultChecked\n });\n };\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch />\n </Col>\n <Col sm={2}>\n <Switch\n defaultChecked={this.state.defaultChecked}\n onChange={this.onChange}\n />\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":""},{"example":<Demo2 />,"title":" 不同大小的开关","code":"/**\n *\n * @title 不同大小的开关\n * @description 通过`size`属性控制开关的大小\n *\n */\n\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo2 extends Component {\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch size=\"sm\" />\n </Col>\n <Col sm={2}>\n <Switch />\n </Col>\n <Col sm={2}>\n <Switch size=\"lg\" />\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":" 通过`size`属性控制开关的大小"},{"example":<Demo3 />,"title":" 事件开关","code":"/**\n *\n * @title 事件开关\n * @description 点击开关触发事件\n *\n */\n\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo3 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n switch: \"\",\n checked: false\n };\n }\n onChange = e => {\n this.setState({\n switch: `${e}`,\n checked: !this.state.checked\n });\n };\n\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch\n defaultChecked={this.state.checked}\n onChange={this.onChange}\n checkedChildren={\"on\"}\n unCheckedChildren={\"off\"}\n />\n </Col>\n <Col sm={2}>\n <span>{this.state.switch}</span>\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":" 点击开关触发事件"}] | ||
@@ -18,0 +18,0 @@ |
@@ -13,3 +13,3 @@ ## Switch 开关 | ||
|defaultChecked |初始是否选中 |Boolean| false | | ||
|onChangeHandler |变化时回调函数,自定义参照demo |Function(checked:Boolean) | | ||
|onChange |变化时回调函数,自定义参照demo |Function(checked:Boolean) | | ||
|checkedChildren |选中时的内容 |React| Node | | ||
@@ -16,0 +16,0 @@ |unCheckedChildren |非选中时的内容 |React| Node |
112
package.json
{ | ||
"name": "bee-switch", | ||
"version": "1.0.1", | ||
"description": "switch ui component for react", | ||
"keywords": [ | ||
"react", | ||
"react-component", | ||
"react-switch", | ||
"iuap-design", | ||
"neoui-react", | ||
"switch" | ||
], | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"homepage": "https://github.com/tinper-bee/switch", | ||
"author": "", | ||
"repository": "http://github.com/tinper-bee/switch", | ||
"bugs": "https://github.com/tinper-bee/switch/issues", | ||
"license": "MIT", | ||
"main": "./build/index", | ||
"config": { | ||
"port": 8000 | ||
}, | ||
"scripts": { | ||
"dev": "bee-tools run start", | ||
"build": "bee-tools run build", | ||
"lint": "bee-tools run lint", | ||
"test": "bee-tools run test", | ||
"chrome": "bee-tools run chrome", | ||
"browsers": "bee-tools run browsers", | ||
"pub": "bee-tools run pub", | ||
"coveralls": "bee-tools run coverage" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.20.0", | ||
"classnames": "^2.2.5", | ||
"tinper-bee-core": "^0.2.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.3.0 || ^16.0", | ||
"react-dom": "^15.3.0 || ^16.0", | ||
"prop-types": "15.6.0" | ||
}, | ||
"devDependencies": { | ||
"bee-button": "latest", | ||
"bee-layout": "latest", | ||
"bee-panel": "latest", | ||
"chai": "^3.5.0", | ||
"console-polyfill": "~0.2.1", | ||
"enzyme": "^2.4.1", | ||
"es5-shim": "~4.1.10", | ||
"react": "15.3.2", | ||
"react-addons-test-utils": "15.3.2", | ||
"react-dom": "15.3.2" | ||
} | ||
} | ||
"name": "bee-switch", | ||
"version": "1.0.2", | ||
"description": "switch ui component for react", | ||
"keywords": [ | ||
"react", | ||
"react-component", | ||
"react-switch", | ||
"iuap-design", | ||
"neoui-react", | ||
"switch" | ||
], | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"homepage": "https://github.com/tinper-bee/switch", | ||
"author": "", | ||
"repository": "http://github.com/tinper-bee/switch", | ||
"bugs": "https://github.com/tinper-bee/switch/issues", | ||
"license": "MIT", | ||
"main": "./build/index", | ||
"config": { | ||
"port": 8000 | ||
}, | ||
"scripts": { | ||
"dev": "bee-tools run start", | ||
"build": "bee-tools run build", | ||
"lint": "bee-tools run lint", | ||
"test": "bee-tools run test", | ||
"chrome": "bee-tools run chrome", | ||
"browsers": "bee-tools run browsers", | ||
"pub": "bee-tools run pub", | ||
"coveralls": "bee-tools run coverage" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.20.0", | ||
"classnames": "^2.2.5", | ||
"tinper-bee-core": "^0.2.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.3.0 || ^16.0", | ||
"react-dom": "^15.3.0 || ^16.0", | ||
"prop-types": "15.6.0" | ||
}, | ||
"devDependencies": { | ||
"bee-button": "latest", | ||
"bee-layout": "latest", | ||
"bee-panel": "latest", | ||
"chai": "^3.5.0", | ||
"console-polyfill": "~0.2.1", | ||
"enzyme": "^2.4.1", | ||
"es5-shim": "~4.1.10", | ||
"react": "15.3.2", | ||
"react-addons-test-utils": "15.3.2", | ||
"react-dom": "15.3.2" | ||
} | ||
} |
@@ -46,3 +46,3 @@ # bee-switch | ||
|defaultChecked |初始是否选中 |Boolean| false | | ||
|onChangeHandler |变化时回调函数,自定义参照demo |Function(checked:Boolean) | | ||
|onChange |变化时回调函数,自定义参照demo |Function(checked:Boolean) | | ||
|checkedChildren |选中时的内容 |React| Node | | ||
@@ -49,0 +49,0 @@ |unCheckedChildren |非选中时的内容 |React| Node |
@@ -1,80 +0,92 @@ | ||
import React, { Component } from 'react' | ||
import ReactDOM from 'react-dom' | ||
import classnames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import React, { Component } from "react"; | ||
import ReactDOM from "react-dom"; | ||
import classnames from "classnames"; | ||
import PropTypes from "prop-types"; | ||
const propTypes = { | ||
clsPrefix: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
checkedChildren: PropTypes.any, | ||
unCheckedChildren: PropTypes.any, | ||
onChangeHandler: PropTypes.func | ||
clsPrefix: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
checkedChildren: PropTypes.any, | ||
unCheckedChildren: PropTypes.any, | ||
onChangeHandler: PropTypes.func, | ||
onChange: PropTypes.func | ||
}; | ||
const defaultProps = { | ||
clsPrefix: 'u-switch', | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
defaultChecked: false, | ||
size:'', | ||
disabled:false, | ||
onChangeHandler: function(){} | ||
clsPrefix: "u-switch", | ||
checkedChildren: null, | ||
unCheckedChildren: null, | ||
defaultChecked: false, | ||
size: "", | ||
disabled: false, | ||
onChangeHandler: function() {}, | ||
onChange: function() {} | ||
}; | ||
class Switch extends Component { | ||
constructor(props) { | ||
super(props); | ||
var checked = false; | ||
if ("checked" in this.props) { | ||
checked = !!this.props.checked; | ||
} else { | ||
checked = !!this.props.defaultChecked; | ||
} | ||
this.state = { | ||
checked: checked | ||
}; | ||
} | ||
componentWillReceiveProps(nextProps, nextState) { | ||
if (nextProps.checked) { | ||
this.setState({ checked: nextProps.checked }); | ||
} else if (nextProps.defaultChecked) { | ||
this.setState({ checked: nextProps.defaultChecked }); | ||
} | ||
} | ||
constructor(props){ | ||
super(props); | ||
var checked = false; | ||
if('checked' in this.props){ | ||
checked = !!this.props.checked; | ||
}else { | ||
checked = !!this.props.defaultChecked; | ||
} | ||
this.state = { | ||
checked: checked | ||
} | ||
this.clickHandler = this.clickHandler.bind(this) | ||
} | ||
componentWillReceiveProps(nextProps,nextState) { | ||
if(nextProps.checked) { | ||
this.setState({checked:nextProps.checked}); | ||
}else if(nextProps.defaultChecked) { | ||
this.setState({checked:nextProps.defaultChecked}); | ||
} | ||
} | ||
//点击switch改变状态 | ||
clickHandler = () => { | ||
if (this.props.checked != undefined) { | ||
return; | ||
} | ||
let checked = this.state.checked; | ||
this.setState({ | ||
checked: !checked | ||
}); | ||
this.props.onChangeHandler(!checked); | ||
this.props.onChange(!checked); | ||
}; | ||
render() { | ||
const { | ||
checkedChildren, | ||
unCheckedChildren, | ||
onChangeHandler, | ||
size, | ||
className, | ||
clsPrefix, | ||
colors | ||
} = this.props; | ||
//获取checked | ||
const checked = this.state.checked; | ||
let classes = { | ||
"is-checked": checked | ||
}; | ||
if (size) { | ||
classes[`${clsPrefix}-${size}`] = true; | ||
} | ||
if (colors) { | ||
classes[`${clsPrefix}-${colors}`] = true; | ||
} | ||
let classNames = classnames(clsPrefix, classes); | ||
//点击switch改变状态 | ||
clickHandler(){ | ||
if(this.props.checked !=undefined) { | ||
return; | ||
} | ||
let checked = this.state.checked; | ||
this.setState({ | ||
checked:!checked | ||
}) | ||
this.props.onChangeHandler(!checked); | ||
} | ||
render(){ | ||
const { checkedChildren,unCheckedChildren,onChangeHandler,size,className,clsPrefix,colors } = this.props; | ||
//获取checked | ||
const checked = this.state.checked; | ||
let classes = { | ||
'is-checked':checked | ||
} | ||
if(size){ | ||
classes[`${clsPrefix}-${size}`] = true; | ||
} | ||
if(colors){ | ||
classes[`${clsPrefix}-${colors}`] = true; | ||
} | ||
let classNames = classnames(clsPrefix,classes); | ||
return( | ||
<span onClick = {this.clickHandler} className={classnames(className,classNames)} tabIndex="0"> | ||
<span | ||
className={`${clsPrefix}-inner`}> | ||
{ checked?checkedChildren : unCheckedChildren} | ||
</span> | ||
</span> | ||
) | ||
} | ||
return ( | ||
<span | ||
onClick={this.clickHandler} | ||
className={classnames(className, classNames)} | ||
tabIndex="0" | ||
> | ||
<span className={`${clsPrefix}-inner`}> | ||
{checked ? checkedChildren : unCheckedChildren} | ||
</span> | ||
</span> | ||
); | ||
} | ||
} | ||
@@ -81,0 +93,0 @@ Switch.propTypes = propTypes; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1369825
0.74%13511
0.47%