feat: migrate Picker component

This commit is contained in:
chenjiahan 2020-07-26 15:41:09 +08:00
parent 7e47a0721b
commit 9fa7a258d7
5 changed files with 50 additions and 45 deletions

View File

@ -43,4 +43,5 @@ module.exports = [
'tab',
'tabs',
'sticky',
'picker',
];

View File

@ -43,6 +43,8 @@ export default createComponent({
},
},
emits: ['change'],
data() {
return {
offset: 0,
@ -266,28 +268,22 @@ export default createComponent({
const data = {
style: optionStyle,
attrs: {
role: 'button',
tabindex: disabled ? -1 : 0,
},
role: 'button',
tabindex: disabled ? -1 : 0,
class: [
bem('item', {
disabled,
selected: index === this.currentIndex,
}),
],
on: {
click: () => {
this.onClickItem(index);
},
onClick: () => {
this.onClickItem(index);
},
};
const childData = {
class: 'van-ellipsis',
domProps: {
[this.allowHtml ? 'innerHTML' : 'textContent']: text,
},
[this.allowHtml ? 'innerHTML' : 'textContent']: text,
};
return (

View File

@ -62,14 +62,14 @@
<demo-block card v-if="!isWeapp" :title="t('withPopup')">
<van-field
v-model="fieldValue"
readonly
clickable
:label="t('city')"
:value="fieldValue"
:placeholder="t('chooseCity')"
@click="onClickField"
/>
<van-popup v-model="showPicker" round position="bottom">
<van-popup v-model:show="showPicker" round position="bottom">
<van-picker
show-toolbar
:title="t('title')"

View File

@ -32,6 +32,8 @@ export default createComponent({
},
},
emits: ['confirm', 'cancel', 'change'],
data() {
return {
children: [],
@ -62,7 +64,9 @@ export default createComponent({
watch: {
columns: {
handler: 'format',
handler() {
this.format();
},
immediate: true,
},
},
@ -261,10 +265,8 @@ export default createComponent({
},
genTitle() {
const titleSlot = this.slots('title');
if (titleSlot) {
return titleSlot;
if (this.$slots.title) {
return this.$slots.title();
}
if (this.title) {
@ -276,19 +278,25 @@ export default createComponent({
if (this.showToolbar) {
return (
<div class={bem('toolbar')}>
{this.slots() || [
<button type="button" class={bem('cancel')} onClick={this.cancel}>
{this.cancelButtonText || t('cancel')}
</button>,
this.genTitle(),
<button
type="button"
class={bem('confirm')}
onClick={this.confirm}
>
{this.confirmButtonText || t('confirm')}
</button>,
]}
{this.$slots.default
? this.$slots.default()
: [
<button
type="button"
class={bem('cancel')}
onClick={this.cancel}
>
{this.cancelButtonText || t('cancel')}
</button>,
this.genTitle(),
<button
type="button"
class={bem('confirm')}
onClick={this.confirm}
>
{this.confirmButtonText || t('confirm')}
</button>,
]}
</div>
);
}
@ -339,15 +347,15 @@ export default createComponent({
},
},
render(h) {
render() {
return (
<div class={bem()}>
{this.toolbarPosition === 'top' ? this.genToolbar() : h()}
{this.loading ? <Loading class={bem('loading')} /> : h()}
{this.slots('columns-top')}
{this.toolbarPosition === 'top' ? this.genToolbar() : null}
{this.loading ? <Loading class={bem('loading')} /> : null}
{this.$slots['columns-top']?.()}
{this.genColumns()}
{this.slots('columns-bottom')}
{this.toolbarPosition === 'bottom' ? this.genToolbar() : h()}
{this.$slots['columns-bottom']?.()}
{this.toolbarPosition === 'bottom' ? this.genToolbar() : null}
</div>
);
},

View File

@ -143,10 +143,10 @@ module.exports = {
// path: 'password-input',
// title: 'PasswordInput 密码输入框',
// },
// {
// path: 'picker',
// title: 'Picker 选择器',
// },
{
path: 'picker',
title: 'Picker 选择器',
},
// {
// path: 'radio',
// title: 'Radio 单选框',
@ -477,10 +477,10 @@ module.exports = {
// path: 'password-input',
// title: 'PasswordInput',
// },
// {
// path: 'picker',
// title: 'Picker',
// },
{
path: 'picker',
title: 'Picker',
},
// {
// path: 'radio',
// title: 'Radio',