[improvement] Picker: shared props (#2888)

This commit is contained in:
neverland 2019-03-02 11:03:04 +08:00 committed by GitHub
parent 0245e663d0
commit 317b9c329d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 31 deletions

View File

@ -1,13 +1,12 @@
import { use } from '../utils';
import Picker from '../picker';
import { PickerMixin } from '../mixins/picker';
import { pickerProps } from '../picker/shared';
const [sfc, bem] = use('area');
export default sfc({
mixins: [PickerMixin],
props: {
...pickerProps,
value: String,
areaList: {
type: Object,

View File

@ -1,6 +1,6 @@
import { use, range } from '../utils';
import Picker from '../picker';
import { PickerMixin } from '../mixins/picker';
import { pickerProps } from '../picker/shared';
import {
times,
padZero,
@ -13,9 +13,8 @@ const [sfc, bem] = use('datetime-picker');
const currentYear = new Date().getFullYear();
export default sfc({
mixins: [PickerMixin],
props: {
...pickerProps,
value: null,
minHour: Number,
minMinute: Number,
@ -302,7 +301,7 @@ export default sfc({
render(h) {
const props = {};
Object.keys(PickerMixin.props).forEach(key => {
Object.keys(pickerProps).forEach(key => {
props[key] = this[key];
});

View File

@ -1,21 +0,0 @@
/**
* Common Picker Props
*/
export const PickerMixin = {
props: {
title: String,
loading: Boolean,
showToolbar: Boolean,
cancelButtonText: String,
confirmButtonText: String,
visibleItemCount: {
type: Number,
default: 5
},
itemHeight: {
type: Number,
default: 44
}
}
};

View File

@ -1,16 +1,15 @@
import { use } from '../utils';
import { prevent } from '../utils/event';
import { deepClone } from '../utils/deep-clone';
import { PickerMixin } from '../mixins/picker';
import { pickerProps } from './shared';
import Loading from '../loading';
import PickerColumn from './PickerColumn';
const [sfc, bem, t] = use('picker');
export default sfc({
mixins: [PickerMixin],
props: {
...pickerProps,
columns: Array,
valueKey: {
type: String,

25
packages/picker/shared.ts Normal file
View File

@ -0,0 +1,25 @@
export type SharedPickerProps = {
title?: string;
loading?: boolean;
itemHeight: number;
showToolbar?: boolean;
visibleItemCount: number;
cancelButtonText?: string;
confirmButtonText?: string;
}
export const pickerProps = {
title: String,
loading: Boolean,
showToolbar: Boolean,
cancelButtonText: String,
confirmButtonText: String,
visibleItemCount: {
type: Number,
default: 5
},
itemHeight: {
type: Number,
default: 44
}
};