W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋: 自定義搜索框,支持配置多種主題,搜索默認(rèn)文案,容器樣式等
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 |
---|---|---|---|---|
theme | String | 否 | default | 搜索框主題樣式:default 為搜索框灰色填充主題,border 為搜索框描邊主題,white 為搜索框白色填充主題,transparent 為搜索框透明主題 |
placeholder | String | 否 | 搜索關(guān)鍵詞 | 輸入內(nèi)容默認(rèn)文案 |
placeholderStyle | String | 否 | 輸入內(nèi)容默認(rèn)文案的樣式 | |
searchIconColor | String | 否 | #999 | 搜索 icon 的顏色 |
confirmType | String | 否 | search | 鍵盤右下角按鈕文字 |
value | String | 否 | 搜索框內(nèi)容 | |
focus | Boolean | 否 | false | 聚焦,調(diào)起輸入鍵盤 |
presetWord | String | 否 | '' | 搜索預(yù)置詞,如果配置了該詞,則可默認(rèn)搜索預(yù)置詞(預(yù)置詞的展示優(yōu)先級高于placeholder) |
containerStyle | Object | 否 | {'background': '#f4f5f6', 'opacity': 1} | 最外層容器的樣式,但 theme 權(quán)重大于該樣式 |
contentStyle | Object | 否 | {'width': 688.41,'minWidth': 218} | 內(nèi)層搜索容器的樣式 |
<view class="wrap {{theme}}">
<view class="card-panel" s-for="item,index in list">
<view class="mode-title">
<view class="mode-title-line-left"></view>
<view class="mode-title-text">{{item.titleBar}}</view>
<view class="mode-title-line-right"></view>
</view>
<view class="smt-card-area">
<smt-search-bar class="area-content"
searchIconColor="{{searchIconColor}}"
search-bar-class="{{item.theme}}-external-container"
search-bar-content-class="{{item.theme}}-external-content"
search-icon-class="{{item.theme}}-external-icon"
search-input-class="external-search-input"
search-text-class="external-search-text"
placeholder-style="{{placeholderStyle}}"
theme="{{item.theme}}"/>
</view>
</view>
<view class="smt-card-config">
<view class="item-scroll border-bottom">
<text class="switch-text switch-text-before">沉浸式主題</text>
<switch color="{{theme ==='dark' ? '#f5f5f5' : '#ddd'}}" class="init-switch" disabled="false" bind:change="changeTheme"></switch>
</view>
</view>
</view>
Page({
data: {
theme: '',
placeholderStyle: '',
searchIconColor: '#999',
list: [
{
titleBar: '搜索框填充樣式1',
theme: 'default'
},
{
titleBar: '搜索框填充樣式2',
theme: 'white'
},
{
titleBar: '搜索框描邊樣式',
theme: 'border'
},
{
titleBar: '搜索框帶預(yù)置詞',
theme: 'border',
presetWord: "預(yù)置詞"
}
]
},
/**
* 切換主題
*
* @param {Event} e 事件對象
* @param {Object} e.detail 獲取checked值
*/
changeTheme(e) {
const checked = e.detail.checked;
this.setData({
searchIconColor: checked ? 'rgba(255,255,255,.6)' : '#999',
placeholderStyle: checked ? 'color: #8eb4e2;' : '',
theme: checked ? 'dark' : ''
});
swan.nextTick(() => {
swan.setBackgroundColor({
backgroundColor: checked ? '#3670c2' : '#f5f5f5'
});
});
}
});
.wrap {
padding-top: .2rem;
background: #f5f5f5;
}
.wrap .smt-card-area {
margin: 25.36rpx 0 72.46rpx;
background: #fff;
}
.wrap .init-switch {
vertical-align: middle;
margin: 28.986rpx 0;
}
.wrap .switch-text-before {
font-size: 28.986rpx;
color: #333;
display: flex;
align-items: center;
}
.wrap .smt-card-config {
background: #fff;
overflow: hidden;
}
.wrap .item-logo {
display: inline-block;
width: 32.609rpx;
height: 32.609rpx;
margin: 34.005rpx 0;
}
.page-status-hover {
opacity: .2;
}
.wrap.dark {
background-color: #3670c2;
}
.wrap.dark .smt-card-config,
.wrap.dark .border-external-container,
.wrap.dark .white-external-container,
.wrap.dark .default-external-content,
.wrap.dark .border-external-content {
background-color: #4985da;
}
.wrap.dark .border-external-content {
border: 1px solid rgba(255, 255, 255, .3);
}
.wrap.dark .switch-text-before {
color: #fff;
background: #4985da;
}
.wrap.dark .mode-title-line-left {
background-image: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #fff 100%);
opacity: .3;
}
.wrap.dark .mode-title-line-right {
background-image: linear-gradient(-90deg, rgba(255, 255, 255, 0) 0%, #fff 100%);
opacity: .3;
}
.wrap.dark .mode-title-text,
.wrap.dark .external-search-input {
color: #fff;
}
.wrap.dark .border-bottom:after {
transform: scaleY(.5);
background: #73a5eb;
}
.wrap.dark .swan-switch-input:after {
background: #38f;
}
.wrap.dark .default-external-container,
.wrap.dark .white-external-content {
background: #1d69c6;
color: #fff;
}
.wrap.dark .external-search-text {
color: #a4c2ec !important;
}
{
"navigationBarTitleText": "search-bar",
"usingComponents": {
"smt-search-bar": "@smt-ui/component/src/search-bar"
},
"navigationStyle": "custom"
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: