From 317b9c329d528eecba0f098aa6d24663b2af5926 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 2 Mar 2019 11:03:04 +0800 Subject: [PATCH] [improvement] Picker: shared props (#2888) --- packages/area/index.js | 5 ++--- packages/datetime-picker/index.js | 7 +++---- packages/mixins/picker.js | 21 --------------------- packages/picker/index.js | 5 ++--- packages/picker/shared.ts | 25 +++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 31 deletions(-) delete mode 100644 packages/mixins/picker.js create mode 100644 packages/picker/shared.ts diff --git a/packages/area/index.js b/packages/area/index.js index 5cda6cc05..b2848f545 100644 --- a/packages/area/index.js +++ b/packages/area/index.js @@ -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, diff --git a/packages/datetime-picker/index.js b/packages/datetime-picker/index.js index 864a80d56..acc6cffeb 100644 --- a/packages/datetime-picker/index.js +++ b/packages/datetime-picker/index.js @@ -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]; }); diff --git a/packages/mixins/picker.js b/packages/mixins/picker.js deleted file mode 100644 index 4741096a7..000000000 --- a/packages/mixins/picker.js +++ /dev/null @@ -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 - } - } -}; diff --git a/packages/picker/index.js b/packages/picker/index.js index 68309fc74..546706c6b 100644 --- a/packages/picker/index.js +++ b/packages/picker/index.js @@ -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, diff --git a/packages/picker/shared.ts b/packages/picker/shared.ts new file mode 100644 index 000000000..07a963633 --- /dev/null +++ b/packages/picker/shared.ts @@ -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 + } +};