diff --git a/components.json b/components.json
index d0dd619e8..1c29279de 100644
--- a/components.json
+++ b/components.json
@@ -1,4 +1,5 @@
{
"sample": "./packages/sample/index.js",
- "button": "./packages/button/index.js"
+ "button": "./packages/button/index.js",
+ "switch": "./packages/switch/index.js"
}
diff --git a/docs/examples/switch.md b/docs/examples/switch.md
new file mode 100644
index 000000000..56a9c27b6
--- /dev/null
+++ b/docs/examples/switch.md
@@ -0,0 +1,80 @@
+
+
+
+## Switch组件
+
+### 基础用法
+
+:::demo 样例代码
+```html
+
+ Switch state: {{switchStateText}}
+
+
+
+```
+
+
+```javascript
+export default {
+ data() {
+ return {
+ switchState: false
+ };
+ },
+ computed: {
+ switchStateText() {
+ return this.switchState ? 'on' : 'off';
+ }
+ },
+ methods: {
+ updateState(newState) {
+ console.log('changing');
+ this.switchState = newState;
+ }
+ }
+};
+```
+:::
+
+### API
+
+| 参数 | 说明 | 类型 | 默认值 | 可选值 |
+|-----------|-----------|-----------|-------------|-------------|
+| checked | 开关状态 | boolean | false | true,false |
+| loading | loading状态 | boolean | false | true,false |
+| disabled | 禁用状态 | boolean | false | true,false |
+| onChange | 回调 | function | function(){} | - |
diff --git a/docs/nav.config.json b/docs/nav.config.json
index 3e62d423e..401945ae3 100644
--- a/docs/nav.config.json
+++ b/docs/nav.config.json
@@ -13,6 +13,10 @@
{
"path": "/button",
"title": "Button组件"
+ },
+ {
+ "path": "/switch",
+ "title": "Switch组件"
}
]
}
diff --git a/package.json b/package.json
index aae753ff4..2cb92d122 100644
--- a/package.json
+++ b/package.json
@@ -100,6 +100,7 @@
"prismjs": "^1.5.1",
"rimraf": "^2.5.4",
"run-sequence": "^1.2.2",
+ "saladcss-bem":"^0.0.1",
"sass-loader": "^3.2.3",
"style-loader": "^0.13.1",
"theaterjs": "^3.0.0",
diff --git a/packages/switch/CHANGELOG.md b/packages/switch/CHANGELOG.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/switch/README.md b/packages/switch/README.md
new file mode 100644
index 000000000..4c6172563
--- /dev/null
+++ b/packages/switch/README.md
@@ -0,0 +1,26 @@
+# @youzan/<%= name %>
+
+!!! 请在此处填写你的文档最简单描述 !!!
+
+[![version][version-image]][download-url]
+[![download][download-image]][download-url]
+
+[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square
+[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square
+[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %>
+
+## Demo
+
+## Usage
+
+## API
+
+| 参数 | 说明 | 类型 | 默认值 | 可选值 |
+|-----------|-----------|-----------|-------------|-------------|
+| className | 自定义额外类名 | string | '' | '' |
+
+
+
+
+## License
+[MIT](https://opensource.org/licenses/MIT)
diff --git a/packages/switch/index.js b/packages/switch/index.js
new file mode 100644
index 000000000..0b5d5cf84
--- /dev/null
+++ b/packages/switch/index.js
@@ -0,0 +1,3 @@
+import Switch from './src/switch';
+
+export default Switch;
diff --git a/packages/switch/index.pcss b/packages/switch/index.pcss
new file mode 100644
index 000000000..617bc489f
--- /dev/null
+++ b/packages/switch/index.pcss
@@ -0,0 +1 @@
+@import "./src/switch.pcss";
diff --git a/packages/switch/package.json b/packages/switch/package.json
new file mode 100644
index 000000000..46d58abc4
--- /dev/null
+++ b/packages/switch/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "@youzan/o2-switch",
+ "version": "0.0.1",
+ "description": "switch component",
+ "main": "./lib/index.js",
+ "author": "jiangruowei",
+ "license": "MIT",
+ "devDependencies": {},
+ "dependencies": {}
+}
diff --git a/packages/switch/src/switch.pcss b/packages/switch/src/switch.pcss
new file mode 100644
index 000000000..0ac3f03e4
--- /dev/null
+++ b/packages/switch/src/switch.pcss
@@ -0,0 +1,48 @@
+
+@component-namespace o2{
+ @component switch {
+ height: 29px;
+ width: 49px;
+ display: inline-block;
+ border-radius: 16px;
+ position: relative;
+ border: 1px solid;
+
+ @descendent node {
+ width: 27px;
+ height: 27px;
+ border-radius: 100%;
+ background-color: #fff;
+ border: .5px solid rgba(0, 0, 0, .1);
+ position: absolute;
+ box-shadow: 0 3px 1px 0 rgba(0, 0, 0, .05), 0 2px 2px 0 rgba(0, 0, 0, .1), 0 3px 3px 0 rgba(0, 0, 0, .05);
+ @when on {
+ left: 0;
+ }
+
+ @when off {
+ right: 0;
+ }
+
+ }
+
+ @when on {
+ background-color: #44db5e;
+ border-color: #44db5e;
+ }
+
+ @when off {
+ background-color: #fff;
+ border-color: rgba(0, 0, 0, .1);
+ }
+
+ @when loading {
+ /* TODO */
+ }
+
+ @when disabled {
+ background-color: #f2f2f2;
+ border-color: rgba(0, 0, 0, .1);
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/switch/src/switch.vue b/packages/switch/src/switch.vue
new file mode 100644
index 000000000..cb92c5fda
--- /dev/null
+++ b/packages/switch/src/switch.vue
@@ -0,0 +1,71 @@
+
+
+
+
+
diff --git a/packages/zenui/src/index.pcss b/packages/zenui/src/index.pcss
index a8955749d..15f7ab28b 100644
--- a/packages/zenui/src/index.pcss
+++ b/packages/zenui/src/index.pcss
@@ -2,3 +2,4 @@
css组件库 入口,从各个地方拿css文件,组装成css组件库
*/
@import '../../button/index.pcss';
+@import '../../switch/index.pcss';
diff --git a/src/index.js b/src/index.js
index a8eff59db..805add4f5 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,5 +1,6 @@
import Sample from '../packages/sample/index.js';
import Button from '../packages/button/index.js';
+import Switch from '../packages/switch/index.js';
import 'es6-promise/auto';
import axios from 'axios';
import foreach from 'lodash/foreach';
@@ -14,6 +15,7 @@ const install = function(Vue) {
Vue.component(Sample.name, Sample);
Vue.component(Button.name, Button);
+ Vue.component(Switch.name, Switch);
};
// auto install
@@ -32,5 +34,6 @@ module.exports = {
map
},
Sample,
- Button
+ Button,
+ Switch
};