[refactor] Capsule: 升级到自定义组件 (#182)

* done

* add example
This commit is contained in:
oConner 2018-04-10 20:41:14 +08:00 committed by Yao
parent 7441e8c39b
commit a05613403b
10 changed files with 77 additions and 58 deletions

View File

@ -1,3 +1,7 @@
{ {
"navigationBarTitleText": "Capsule 胶囊" "navigationBarTitleText": "Capsule 胶囊",
"usingComponents": {
"zan-panel": "/packages/panel/index",
"zan-capsule": "/packages/capsule/index"
}
} }

View File

@ -4,19 +4,13 @@
<view class="doc-title zan-hairline--bottom">CAPSULE</view> <view class="doc-title zan-hairline--bottom">CAPSULE</view>
<view class="zan-panel-title">基本用法</view> <zan-panel title='基本用法'>
<view class="zan-panel"> <zan-capsule leftText="1折扣" rightText="限购一份" />
<view class="zan-cell zan-cell--last-child"> <zan-capsule type="danger" leftText="1折扣" rightText="限购一份" />
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份'}}" /> </zan-panel>
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份', type: 'danger' }}" />
</view>
</view>
<view class="zan-panel-title">自定义颜色</view> <zan-panel title='自定义颜色'>
<view class="zan-panel"> <zan-capsule color="#38f" leftText="1折扣" rightText="限购一份" />
<view class="zan-cell zan-cell--last-child"> </zan-panel>
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份', color: '#38f' }}" />
</view>
</view>
</view> </view>

View File

@ -1,32 +1,23 @@
## Capsule 胶囊 ## Capsule 胶囊
### 使用指南 ### 使用指南
在 app.wxss 中引入组件库所有样式 在 index.json 中引入组件
```css ```json
@import "path/to/zanui-weapp/dist/index.wxss"; {
``` "usingComponents": {
"zan-capsule": "/packages/capsule/index"
在需要使用的模板里引入组件库模板 }
```html }
<import src="path/to/zanui-weapp/dist/capsule/index.wxml" />
``` ```
### 代码演示 ### 代码演示
Panel 提供了一块白色的展示区域,使用方式如下
#### 基础用法
可以用 leftText 和 rightText 控制左右文案
```html ```html
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份'}}" /> <zan-capsule color="#38f" leftText="1折扣" rightText="限购一份" />
```
#### 使用不同类型胶囊
按钮支持额外的三种类型 primary, danger, warn
```html
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份', type: 'danger' }}" />
```
#### 自定义颜色
通过 color 熟悉,可以自定义显示的颜色
```html
<template is="capsule" data="{{ leftText: '1折', rightText: '限购一份', color: '#38f' }}" />
``` ```
| 参数 | 说明 | 类型 | 默认值 | 必须 |
|-----------|-----------|-----------|-------------|-------------|
| type | capsule的主体颜色 | String | ''有danger这个主题色 | |
| color | 自定义capsule颜色 | String | - | |
| leftText | 左侧文案 | String | - | |
| rightText | 右侧文案 | String | - | |

28
packages/capsule/index.js Normal file
View File

@ -0,0 +1,28 @@
Component({
/**
* 组件的属性列表
* 用于组件自定义设置
*/
properties: {
// 颜色状态
type: {
type: String,
value: ''
},
// 自定义颜色
color :{
type : String,
value : ''
},
// 左侧内容
leftText :{
type : String ,
value : ''
},
// 右侧内容
rightText :{
type : String ,
value : ''
}
}
})

View File

@ -1,18 +1,17 @@
<template name="capsule"> <view class="zan-capsule zan-capsule--{{type}}">
<view class="zan-capsule zan-capsule--{{type}}"> <block wx:if="{{color}}">
<block wx:if="{{color}}"> <view
<view class="zan-capsule__left"
class="zan-capsule__left" style="background: {{ color }}; border-color: {{ color }}"
style="background: {{ color }}; border-color: {{ color }}" >{{ leftText }}</view>
>{{ leftText }}</view> <view
<view class="zan-capsule__right"
class="zan-capsule__right" style="color: {{ color }}; border-color: {{ color }}"
style="color: {{ color }}; border-color: {{ color }}" >{{ rightText }}</view>
>{{ rightText }}</view> </block>
</block> <block wx:else>
<block wx:else> <view class="zan-capsule__left">{{ leftText }}</view>
<view class="zan-capsule__left">{{ leftText }}</view> <view class="zan-capsule__right">{{ rightText }}</view>
<view class="zan-capsule__right">{{ rightText }}</view> </block>
</block> </view>
</view>
</template>

View File

@ -5,7 +5,7 @@
```json ```json
{ {
"usingComponents": { "usingComponents": {
"zan-panel": "/packages/Panel/panel" "zan-panel": "/packages/panel/index"
} }
} }
``` ```

View File

@ -0,0 +1,3 @@
{
"component": true
}