Skip to content

Commit

Permalink
Merge pull request #1473 from TaleLin/develop
Browse files Browse the repository at this point in the history
chore: 升级版本 0.9.7
  • Loading branch information
smileShirmy authored Dec 29, 2021
2 parents 516bc1a + 2527db3 commit e0ba8b7
Show file tree
Hide file tree
Showing 25 changed files with 291 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ yarn-error.log
.vscode
package-lock.json
examples/project.config.json
examples/project.private.config.json
/.run
yarn.lock
3 changes: 2 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ module.exports = {
'TabBar',
'DynamicBuild',
'Calendar',
'Script'
'Script',
'Switch'
]
]
}
Expand Down
1 change: 1 addition & 0 deletions dist/switch/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/switch/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"component":true,"usingComponents":{}}
3 changes: 3 additions & 0 deletions dist/switch/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<view class="switch {{disabled ? 'switch-disabled l-disabled-class' : 'l-class'}} {{ checked === activeValue ? 'switch-on' : '' }}" style="background-color:{{checked === activeValue ? selectColor : color}};font-size:{{size}};" bind:tap="onClick">
<view class="switch-node"></view>
</view>
1 change: 1 addition & 0 deletions dist/switch/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.switch{position:relative;display:inline-block;box-sizing:content-box;width:2em;height:1em;background-color:#fff;border:1px solid rgba(0,0,0,.1);border-radius:1em;transition:background-color .3s}.switch-node{position:absolute;top:0;left:0;border-radius:100%;z-index:1;width:1em;height:1em;background-color:#fff;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);transition:.3s cubic-bezier(.3,1.05,.4,1.05)}.switch-on .switch-node{transform:translateX(calc(1em))}.switch-disabled{opacity:.5}
1 change: 1 addition & 0 deletions examples/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
{
"root": "pages/components/form",
"pages": [
"pages/switch/index",
"pages/input/index",
"pages/radio/index",
"pages/checkbox/index",
Expand Down
67 changes: 67 additions & 0 deletions examples/dist/switch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import eventBus from '../core/utils/event-bus';

Component({
externalClasses: ['l-class', 'l-disabled-class'],
properties: {
checked: {
type: null,
optionalTypes: [Boolean, String, Number],
value: false
},
size: {
type: String,
value: '38rpx'
},
color: {
type: String,
value: '#fff'
},
// 选中后的颜色
selectColor: {
type: String,
value: '#3963BC'
},
activeValue: {
type: null,
value: true,
},
inactiveValue: {
type: null,
value: false,
},
// 不可选状态
disabled: {
type: Boolean,
value: false
},
},
methods: {
onClick() {
const { activeValue, inactiveValue, disabled } = this.data;

if (disabled) {
return;
}

const checked = this.data.checked === activeValue;
const value = checked ? inactiveValue : activeValue;

this.setData({
checked: value
});

this.triggerEvent('linchange', { checked: value });
eventBus.emit(`lin-form-change-${this.id}`, this.id);
},

getValues() {
return this.data.checked;
},

reset() {
this.setData({
checked: this.data.inactiveValue
});
}
}
});
4 changes: 4 additions & 0 deletions examples/dist/switch/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
6 changes: 6 additions & 0 deletions examples/dist/switch/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<view
class="switch {{disabled ? 'switch-disabled l-disabled-class' : 'l-class'}} {{ checked === activeValue ? 'switch-on' : '' }}"
style="background-color:{{checked === activeValue ? selectColor : color}};font-size:{{size}};"
bind:tap="onClick">
<view class="switch-node"></view>
</view>
1 change: 1 addition & 0 deletions examples/dist/switch/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.switch{position:relative;display:inline-block;box-sizing:content-box;width:2em;height:1em;background-color:#fff;border:1px solid rgba(0,0,0,.1);border-radius:1em;transition:background-color .3s}.switch-node{position:absolute;top:0;left:0;border-radius:100%;z-index:1;width:1em;height:1em;background-color:#fff;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);transition:.3s cubic-bezier(.3,1.05,.4,1.05)}.switch-on .switch-node{transform:translateX(calc(1em))}.switch-disabled{opacity:.5}
Binary file added examples/images/component/switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion examples/pages/components/form/pages/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Page({
music: '',
sex: '',
desc: '',
score: ''
score: '',
status: false
},
items: [
{
Expand Down Expand Up @@ -95,6 +96,19 @@ Page({
trigger: 'change'
}
],
statusRules: [
{
validator(rule, value, callback) {
if (value !== true) {
callback(false);
} else {
callback();
}
},
message: '必须启用',
trigger: 'change'
}
],
register: {
loginId: '',
password: '',
Expand Down
1 change: 1 addition & 0 deletions examples/pages/components/form/pages/form/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"l-radio-group": "/dist/radio-group/index",
"l-radio": "/dist/radio/index",
"l-rate": "/dist/rate/index",
"l-switch": "/dist/switch/index",
"l-button": "/dist/button/index"
}
}
3 changes: 3 additions & 0 deletions examples/pages/components/form/pages/form/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
<l-form-item tip-type="{{tipType}}" align-items="{{alignType}}" rules="{{descRules}}" label="性格描述:" name="ruleDesc">
<l-textarea l-class="l-input-container-class" border="{{false}}" id="ruleDesc" value="{{ruleForm.desc}}" />
</l-form-item>
<l-form-item tip-type="{{tipType}}" align-items="{{alignType}}" rules="{{statusRules}}" label="是否启用:" name="ruleStatus">
<l-switch id="ruleStatus" value="{{ruleForm.status}}" />
</l-form-item>

<view slot="submit">
<l-button>提交验证</l-button>
Expand Down
15 changes: 15 additions & 0 deletions examples/pages/components/form/pages/switch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// pages/components/form/pages/switch/index.js
Page({
/**
* 页面的初始数据
*/
data: {
customValue: 0
},

onChange(e) {
this.setData({
customValue: e.detail.checked
});
}
});
7 changes: 7 additions & 0 deletions examples/pages/components/form/pages/switch/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"usingComponents": {
"content-title": "/components/content-title/index",
"content-card": "/components/content-card/index",
"l-switch": "/dist/switch/index"
}
}
42 changes: 42 additions & 0 deletions examples/pages/components/form/pages/switch/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--pages/components/form/pages/switch/index.wxml-->
<view class='container'>
<content-title name="Switch" describe="开关">
<content-card
class="content"
name="基本案例"
>
<l-switch />

</content-card>

<!-- 设置禁用 -->
<content-card
class="content"
name="设置禁用"
>
<l-switch disabled />
</content-card>

<content-card
class="content"
name="自定义大小"
>
<l-switch size="50rpx" />
</content-card>

<content-card
class="content"
name="自定义颜色"
>
<l-switch color="#ccc" select-color="#34BFA3"/>
</content-card>

<content-card
class="content"
name="自定义打开或关闭的值"
>
<l-switch checked="{{ customValue }}" active-value="{{ 1 }}" inactive-value="{{ 0 }}" bind:linchange="onChange"/>
<view>当前选中的值:{{ customValue }}</view>
</content-card>
</content-title>
</view>
1 change: 1 addition & 0 deletions examples/pages/components/form/pages/switch/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* pages/components/form/pages/switch/index.wxss */
6 changes: 6 additions & 0 deletions examples/pages/navigator/content/config/form-navi.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const formNaviConfigs = [
desc: '日历',
componentsPath: '/pages/components/form/pages/calendar/index'
},
{
icon: '/images/component/switch.png',
title: 'Switch',
desc: '开关',
componentsPath: '/pages/components/form/pages/switch/index'
},
{
icon: '/images/component/rules.png',
title: 'Rules',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lin-ui",
"version": "0.9.6",
"version": "0.9.7",
"description": "A high quality UI components library with MiniProgram",
"main": "app.js",
"directories": {
Expand Down
67 changes: 67 additions & 0 deletions src/switch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import eventBus from '../core/utils/event-bus';

Component({
externalClasses: ['l-class', 'l-disabled-class'],
properties: {
checked: {
type: null,
optionalTypes: [Boolean, String, Number],
value: false
},
size: {
type: String,
value: '38rpx'
},
color: {
type: String,
value: '#fff'
},
// 选中后的颜色
selectColor: {
type: String,
value: '#3963BC'
},
activeValue: {
type: null,
value: true,
},
inactiveValue: {
type: null,
value: false,
},
// 不可选状态
disabled: {
type: Boolean,
value: false
},
},
methods: {
onClick() {
const { activeValue, inactiveValue, disabled } = this.data;

if (disabled) {
return;
}

const checked = this.data.checked === activeValue;
const value = checked ? inactiveValue : activeValue;

this.setData({
checked: value
});

this.triggerEvent('linchange', { checked: value });
eventBus.emit(`lin-form-change-${this.id}`, this.id);
},

getValues() {
return this.data.checked;
},

reset() {
this.setData({
checked: this.data.inactiveValue
});
}
}
});
4 changes: 4 additions & 0 deletions src/switch/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
35 changes: 35 additions & 0 deletions src/switch/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.switch {
position: relative;
display: inline-block;
box-sizing: content-box;
width: 2em;
height: 1em;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 1em;
transition: background-color 0.3s;

&-node {
position: absolute;
top: 0;
left: 0;
border-radius: 100%;
z-index: 1;
width: 1em;
height: 1em;
background-color: #fff;
box-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.05),
0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 3px 3px 0 rgba(0, 0, 0, 0.05);
transition: 0.3s cubic-bezier(0.3, 1.05, 0.4, 1.05);
}

&-on {
.switch-node {
transform: translateX(calc(1em));
}
}

&-disabled {
opacity: 0.5;
}
}
6 changes: 6 additions & 0 deletions src/switch/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<view
class="switch {{disabled ? 'switch-disabled l-disabled-class' : 'l-class'}} {{ checked === activeValue ? 'switch-on' : '' }}"
style="background-color:{{checked === activeValue ? selectColor : color}};font-size:{{size}};"
bind:tap="onClick">
<view class="switch-node"></view>
</view>

0 comments on commit e0ba8b7

Please sign in to comment.