diff --git a/packages/vant/src/action-sheet/ActionSheet.tsx b/packages/vant/src/action-sheet/ActionSheet.tsx index 3f820cb64..a55035b21 100644 --- a/packages/vant/src/action-sheet/ActionSheet.tsx +++ b/packages/vant/src/action-sheet/ActionSheet.tsx @@ -1,7 +1,13 @@ import { nextTick, PropType, defineComponent } from 'vue'; // Utils -import { pick, extend, truthProp, createNamespace } from '../utils'; +import { + pick, + extend, + truthProp, + makeStringProp, + createNamespace, +} from '../utils'; // Components import { Icon } from '../icon'; @@ -28,16 +34,13 @@ export default defineComponent({ title: String, round: truthProp, actions: Array as PropType, + closeIcon: makeStringProp('cross'), closeable: truthProp, cancelText: String, description: String, closeOnPopstate: Boolean, closeOnClickAction: Boolean, safeAreaInsetBottom: truthProp, - closeIcon: { - type: String, - default: 'cross', - }, }), emits: ['select', 'cancel', 'update:show'], diff --git a/packages/vant/src/badge/Badge.tsx b/packages/vant/src/badge/Badge.tsx index ace79fa8c..f289569d7 100644 --- a/packages/vant/src/badge/Badge.tsx +++ b/packages/vant/src/badge/Badge.tsx @@ -5,6 +5,7 @@ import { isNumeric, truthProp, numericProp, + makeStringProp, createNamespace, } from '../utils'; @@ -16,14 +17,11 @@ export default defineComponent({ props: { dot: Boolean, max: numericProp, + tag: makeStringProp('div'), color: String, offset: Array as unknown as PropType<[string | number, string | number]>, content: numericProp, showZero: truthProp, - tag: { - type: String as PropType, - default: 'div', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/button/Button.tsx b/packages/vant/src/button/Button.tsx index 53aaf7051..8dac97ba2 100644 --- a/packages/vant/src/button/Button.tsx +++ b/packages/vant/src/button/Button.tsx @@ -9,6 +9,7 @@ import { import { extend, numericProp, + makeStringProp, createNamespace, BORDER_SURROUND, } from '../utils'; @@ -29,12 +30,19 @@ export type ButtonType = export type ButtonSize = 'large' | 'normal' | 'small' | 'mini'; +export type ButtonNativeType = NonNullable; + +export type ButtonIconPosition = 'left' | 'right'; + export default defineComponent({ name, props: extend({}, routeProps, { + tag: makeStringProp('button'), text: String, icon: String, + type: makeStringProp('default'), + size: makeStringProp('normal'), color: String, block: Boolean, plain: Boolean, @@ -44,29 +52,11 @@ export default defineComponent({ hairline: Boolean, disabled: Boolean, iconPrefix: String, + nativeType: makeStringProp('button'), loadingSize: numericProp, loadingText: String, loadingType: String as PropType, - tag: { - type: String as PropType, - default: 'button', - }, - type: { - type: String as PropType, - default: 'default', - }, - size: { - type: String as PropType, - default: 'normal', - }, - nativeType: { - type: String as PropType, - default: 'button', - }, - iconPosition: { - type: String as PropType<'left' | 'right'>, - default: 'left', - }, + iconPosition: makeStringProp('left'), }), emits: ['click'], diff --git a/packages/vant/src/calendar/Calendar.tsx b/packages/vant/src/calendar/Calendar.tsx index 342772199..846f7b25e 100644 --- a/packages/vant/src/calendar/Calendar.tsx +++ b/packages/vant/src/calendar/Calendar.tsx @@ -15,6 +15,7 @@ import { truthProp, numericProp, getScrollTop, + makeStringProp, makeNumericProp, } from '../utils'; import { @@ -54,11 +55,14 @@ import type { const props = { show: Boolean, + type: makeStringProp('single'), title: String, color: String, round: truthProp, readonly: Boolean, poppable: truthProp, + maxRange: makeNumericProp(null), + position: makeStringProp('bottom'), teleport: [String, Object] as PropType, showMark: truthProp, showTitle: truthProp, @@ -75,15 +79,6 @@ const props = { confirmDisabledText: String, closeOnClickOverlay: truthProp, safeAreaInsetBottom: truthProp, - type: { - type: String as PropType, - default: 'single', - }, - position: { - type: String as PropType, - default: 'bottom', - }, - maxRange: makeNumericProp(null), minDate: { type: Date, validator: isDate, diff --git a/packages/vant/src/card/Card.tsx b/packages/vant/src/card/Card.tsx index d3c5e62d9..cf97059fc 100644 --- a/packages/vant/src/card/Card.tsx +++ b/packages/vant/src/card/Card.tsx @@ -1,7 +1,7 @@ import { defineComponent } from 'vue'; // Utils -import { isDef, numericProp, createNamespace } from '../utils'; +import { isDef, numericProp, makeStringProp, createNamespace } from '../utils'; // Components import { Tag } from '../tag'; @@ -21,12 +21,9 @@ export default defineComponent({ price: numericProp, centered: Boolean, lazyLoad: Boolean, + currency: makeStringProp('¥'), thumbLink: String, originPrice: numericProp, - currency: { - type: String, - default: '¥', - }, }, emits: ['click-thumb'], diff --git a/packages/vant/src/cascader/Cascader.tsx b/packages/vant/src/cascader/Cascader.tsx index 5a5749ab4..d32711e1a 100644 --- a/packages/vant/src/cascader/Cascader.tsx +++ b/packages/vant/src/cascader/Cascader.tsx @@ -1,5 +1,11 @@ import { nextTick, PropType, reactive, watch, defineComponent } from 'vue'; -import { extend, numericProp, truthProp, createNamespace } from '../utils'; +import { + extend, + truthProp, + numericProp, + makeStringProp, + createNamespace, +} from '../utils'; // Components import { Tab } from '../tab'; @@ -40,6 +46,7 @@ export default defineComponent({ title: String, closeable: truthProp, swipeable: truthProp, + closeIcon: makeStringProp('cross'), modelValue: numericProp, fieldNames: Object as PropType, placeholder: String, @@ -48,10 +55,6 @@ export default defineComponent({ type: Array as PropType, default: () => [], }, - closeIcon: { - type: String, - default: 'cross', - }, }, emits: ['close', 'change', 'finish', 'update:modelValue', 'click-tab'], diff --git a/packages/vant/src/checkbox/Checker.tsx b/packages/vant/src/checkbox/Checker.tsx index ce7ce64ae..65e368e93 100644 --- a/packages/vant/src/checkbox/Checker.tsx +++ b/packages/vant/src/checkbox/Checker.tsx @@ -1,5 +1,12 @@ import { ref, computed, PropType, defineComponent } from 'vue'; -import { extend, addUnit, truthProp, numericProp, unknownProp } from '../utils'; +import { + extend, + addUnit, + truthProp, + numericProp, + unknownProp, + makeStringProp, +} from '../utils'; import { Icon } from '../icon'; export type CheckerShape = 'square' | 'round'; @@ -16,16 +23,13 @@ export type CheckerParent = { export const checkerProps = { name: unknownProp, + shape: makeStringProp('round'), disabled: Boolean, iconSize: numericProp, modelValue: unknownProp, checkedColor: String, labelPosition: String as PropType, labelDisabled: Boolean, - shape: { - type: String as PropType, - default: 'round', - }, }; export default defineComponent({ diff --git a/packages/vant/src/circle/Circle.tsx b/packages/vant/src/circle/Circle.tsx index 86d15932e..585ae31af 100644 --- a/packages/vant/src/circle/Circle.tsx +++ b/packages/vant/src/circle/Circle.tsx @@ -5,6 +5,7 @@ import { truthProp, numericProp, getSizeStyle, + makeStringProp, makeNumericProp, createNamespace, } from '../utils'; @@ -30,6 +31,7 @@ export default defineComponent({ props: { text: String, size: numericProp, + fill: makeStringProp('none'), rate: makeNumericProp(100), speed: makeNumericProp(0), color: [String, Object] as PropType>, @@ -37,18 +39,11 @@ export default defineComponent({ layerColor: String, strokeWidth: makeNumericProp(40), strokeLinecap: String as PropType, + startPosition: makeStringProp('top'), currentRate: { type: Number, default: 0, }, - fill: { - type: String, - default: 'none', - }, - startPosition: { - type: String as PropType, - default: 'top', - }, }, emits: ['update:currentRate'], diff --git a/packages/vant/src/col/Col.tsx b/packages/vant/src/col/Col.tsx index 993fa244a..08846d64b 100644 --- a/packages/vant/src/col/Col.tsx +++ b/packages/vant/src/col/Col.tsx @@ -1,5 +1,10 @@ -import { computed, PropType, defineComponent } from 'vue'; -import { numericProp, createNamespace, makeNumericProp } from '../utils'; +import { computed, defineComponent } from 'vue'; +import { + numericProp, + createNamespace, + makeNumericProp, + makeStringProp, +} from '../utils'; import { useParent } from '@vant/use'; import { ROW_KEY } from '../row/Row'; @@ -9,12 +14,9 @@ export default defineComponent({ name, props: { + tag: makeStringProp('div'), span: makeNumericProp(0), offset: numericProp, - tag: { - type: String as PropType, - default: 'div', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/config-provider/ConfigProvider.tsx b/packages/vant/src/config-provider/ConfigProvider.tsx index 4fc4f3c68..1d381effd 100644 --- a/packages/vant/src/config-provider/ConfigProvider.tsx +++ b/packages/vant/src/config-provider/ConfigProvider.tsx @@ -2,11 +2,11 @@ import { provide, computed, PropType, - CSSProperties, InjectionKey, + CSSProperties, defineComponent, } from 'vue'; -import { createNamespace, kebabCase } from '../utils'; +import { kebabCase, makeStringProp, createNamespace } from '../utils'; const [name, bem] = createNamespace('config-provider'); @@ -29,12 +29,9 @@ export default defineComponent({ name, props: { + tag: makeStringProp('div'), themeVars: Object as PropType>, iconPrefix: String, - tag: { - type: String as PropType, - default: 'div', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/contact-card/ContactCard.tsx b/packages/vant/src/contact-card/ContactCard.tsx index 3ea06a525..52e59c2f0 100644 --- a/packages/vant/src/contact-card/ContactCard.tsx +++ b/packages/vant/src/contact-card/ContactCard.tsx @@ -1,5 +1,5 @@ -import { PropType, defineComponent } from 'vue'; -import { truthProp, createNamespace } from '../utils'; +import { defineComponent } from 'vue'; +import { truthProp, makeStringProp, createNamespace } from '../utils'; import { Cell } from '../cell'; const [name, bem, t] = createNamespace('contact-card'); @@ -12,12 +12,9 @@ export default defineComponent({ props: { tel: String, name: String, + type: makeStringProp('add'), addText: String, editable: truthProp, - type: { - type: String as PropType, - default: 'add', - }, }, emits: ['click'], diff --git a/packages/vant/src/count-down/CountDown.tsx b/packages/vant/src/count-down/CountDown.tsx index 7f144f0cc..00fff1394 100644 --- a/packages/vant/src/count-down/CountDown.tsx +++ b/packages/vant/src/count-down/CountDown.tsx @@ -1,7 +1,12 @@ import { watch, computed, defineComponent, ExtractPropTypes } from 'vue'; // Utils -import { truthProp, createNamespace, makeNumericProp } from '../utils'; +import { + truthProp, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; import { parseFormat } from './utils'; // Composables @@ -12,12 +17,9 @@ const [name, bem] = createNamespace('count-down'); const props = { time: makeNumericProp(0), + format: makeStringProp('HH:mm:ss'), autoStart: truthProp, millisecond: Boolean, - format: { - type: String, - default: 'HH:mm:ss', - }, }; export type CountDownProps = ExtractPropTypes; diff --git a/packages/vant/src/coupon-cell/CouponCell.tsx b/packages/vant/src/coupon-cell/CouponCell.tsx index 2a7a9c748..22615209b 100644 --- a/packages/vant/src/coupon-cell/CouponCell.tsx +++ b/packages/vant/src/coupon-cell/CouponCell.tsx @@ -1,7 +1,13 @@ import { PropType, defineComponent } from 'vue'; // Utils -import { isDef, truthProp, makeNumericProp, createNamespace } from '../utils'; +import { + isDef, + truthProp, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; // Components import { Cell } from '../cell'; @@ -40,15 +46,12 @@ export default defineComponent({ title: String, border: truthProp, editable: truthProp, + currency: makeStringProp('¥'), chosenCoupon: makeNumericProp(-1), coupons: { type: Array as PropType, default: () => [], }, - currency: { - type: String, - default: '¥', - }, }, setup(props) { diff --git a/packages/vant/src/coupon-list/CouponList.tsx b/packages/vant/src/coupon-list/CouponList.tsx index aa207b9bc..e0e33ef20 100644 --- a/packages/vant/src/coupon-list/CouponList.tsx +++ b/packages/vant/src/coupon-list/CouponList.tsx @@ -9,7 +9,7 @@ import { } from 'vue'; // Utils -import { truthProp, createNamespace } from '../utils'; +import { truthProp, makeStringProp, createNamespace } from '../utils'; // Composables import { useRefs } from '../composables/use-refs'; @@ -28,7 +28,10 @@ export default defineComponent({ name, props: { + code: makeStringProp(''), + currency: makeStringProp('¥'), showCount: truthProp, + emptyImage: makeStringProp(EMPTY_IMAGE), enabledTitle: String, disabledTitle: String, showExchangeBar: truthProp, @@ -38,10 +41,6 @@ export default defineComponent({ exchangeButtonText: String, exchangeButtonLoading: Boolean, exchangeButtonDisabled: Boolean, - code: { - type: String, - default: '', - }, exchangeMinLength: { type: Number, default: 1, @@ -62,14 +61,6 @@ export default defineComponent({ type: Number, default: -1, }, - currency: { - type: String, - default: '¥', - }, - emptyImage: { - type: String, - default: EMPTY_IMAGE, - }, }, emits: ['change', 'exchange', 'update:code'], diff --git a/packages/vant/src/coupon/Coupon.tsx b/packages/vant/src/coupon/Coupon.tsx index 7ee657adb..637f2f749 100644 --- a/packages/vant/src/coupon/Coupon.tsx +++ b/packages/vant/src/coupon/Coupon.tsx @@ -1,5 +1,5 @@ import { computed, PropType, defineComponent } from 'vue'; -import { padZero, createNamespace } from '../utils'; +import { padZero, makeStringProp, createNamespace } from '../utils'; import { Checkbox } from '../checkbox'; export type CouponInfo = { @@ -39,14 +39,11 @@ export default defineComponent({ props: { chosen: Boolean, disabled: Boolean, + currency: makeStringProp('¥'), coupon: { type: Object as PropType, required: true, }, - currency: { - type: String, - default: '¥', - }, }, setup(props) { diff --git a/packages/vant/src/datetime-picker/DatePicker.tsx b/packages/vant/src/datetime-picker/DatePicker.tsx index fa0445192..381dbad6a 100644 --- a/packages/vant/src/datetime-picker/DatePicker.tsx +++ b/packages/vant/src/datetime-picker/DatePicker.tsx @@ -4,7 +4,6 @@ import { computed, nextTick, onMounted, - PropType, defineComponent, } from 'vue'; @@ -15,6 +14,7 @@ import { extend, isDate, padZero, + makeStringProp, createNamespace, } from '../utils'; import { @@ -41,11 +41,8 @@ export default defineComponent({ name, props: extend({}, sharedProps, { + type: makeStringProp('datetime'), modelValue: Date, - type: { - type: String as PropType, - default: 'datetime', - }, minDate: { type: Date, default: () => new Date(currentYear - 10, 0, 1), diff --git a/packages/vant/src/dialog/Dialog.tsx b/packages/vant/src/dialog/Dialog.tsx index 4f7ad487e..5a1bddd77 100644 --- a/packages/vant/src/dialog/Dialog.tsx +++ b/packages/vant/src/dialog/Dialog.tsx @@ -11,6 +11,7 @@ import { BORDER_LEFT, unknownProp, numericProp, + makeStringProp, callInterceptor, createNamespace, } from '../utils'; @@ -49,6 +50,7 @@ export default defineComponent({ callback: Function as PropType<(action?: DialogAction) => void>, allowHtml: Boolean, className: unknownProp, + transition: makeStringProp('van-dialog-bounce'), messageAlign: String as PropType, closeOnPopstate: truthProp, showCancelButton: Boolean, @@ -58,10 +60,6 @@ export default defineComponent({ confirmButtonColor: String, showConfirmButton: truthProp, closeOnClickOverlay: Boolean, - transition: { - type: String, - default: 'van-dialog-bounce', - }, }), emits: ['confirm', 'cancel', 'update:show'], diff --git a/packages/vant/src/divider/Divider.tsx b/packages/vant/src/divider/Divider.tsx index 628dc5019..c5c103ddb 100644 --- a/packages/vant/src/divider/Divider.tsx +++ b/packages/vant/src/divider/Divider.tsx @@ -1,5 +1,5 @@ -import { PropType, defineComponent } from 'vue'; -import { truthProp, createNamespace } from '../utils'; +import { defineComponent } from 'vue'; +import { truthProp, makeStringProp, createNamespace } from '../utils'; const [name, bem] = createNamespace('divider'); @@ -11,10 +11,7 @@ export default defineComponent({ props: { dashed: Boolean, hairline: truthProp, - contentPosition: { - type: String as PropType, - default: 'center', - }, + contentPosition: makeStringProp('center'), }, setup(props, { slots }) { diff --git a/packages/vant/src/dropdown-menu/DropdownMenu.tsx b/packages/vant/src/dropdown-menu/DropdownMenu.tsx index eed5ef236..db844a2ef 100644 --- a/packages/vant/src/dropdown-menu/DropdownMenu.tsx +++ b/packages/vant/src/dropdown-menu/DropdownMenu.tsx @@ -1,7 +1,6 @@ import { ref, computed, - PropType, InjectionKey, CSSProperties, defineComponent, @@ -13,8 +12,9 @@ import { isDef, truthProp, numericProp, - createNamespace, + makeStringProp, makeNumericProp, + createNamespace, ComponentInstance, } from '../utils'; @@ -36,13 +36,10 @@ const props = { overlay: truthProp, zIndex: numericProp, duration: makeNumericProp(0.2), + direction: makeStringProp('down'), activeColor: String, closeOnClickOutside: truthProp, closeOnClickOverlay: truthProp, - direction: { - type: String as PropType, - default: 'down', - }, }; export type DropdownMenuProps = ExtractPropTypes; diff --git a/packages/vant/src/empty/Empty.tsx b/packages/vant/src/empty/Empty.tsx index 69787b758..3ece8b73c 100644 --- a/packages/vant/src/empty/Empty.tsx +++ b/packages/vant/src/empty/Empty.tsx @@ -1,5 +1,10 @@ import { defineComponent } from 'vue'; -import { createNamespace, getSizeStyle, numericProp } from '../utils'; +import { + numericProp, + getSizeStyle, + makeStringProp, + createNamespace, +} from '../utils'; import { Network } from './Network'; const [name, bem] = createNamespace('empty'); @@ -10,12 +15,9 @@ export default defineComponent({ name, props: { + image: makeStringProp('default'), imageSize: numericProp, description: String, - image: { - type: String, - default: 'default', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/field/Field.tsx b/packages/vant/src/field/Field.tsx index 86aee1320..6b98fbec1 100644 --- a/packages/vant/src/field/Field.tsx +++ b/packages/vant/src/field/Field.tsx @@ -22,6 +22,7 @@ import { resetScroll, formatNumber, preventDefault, + makeStringProp, makeNumericProp, createNamespace, } from '../utils'; @@ -64,17 +65,20 @@ const [name, bem] = createNamespace('field'); export const fieldSharedProps = { id: String, name: String, - formatter: Function as PropType<(value: string) => string>, leftIcon: String, rightIcon: String, autofocus: Boolean, clearable: Boolean, maxlength: numericProp, + formatter: Function as PropType<(value: string) => string>, + clearIcon: makeStringProp('clear'), modelValue: makeNumericProp(''), inputAlign: String as PropType, placeholder: String, autocomplete: String, errorMessage: String, + clearTrigger: makeStringProp('focus'), + formatTrigger: makeStringProp('onChange'), error: { type: Boolean, default: null, @@ -87,22 +91,11 @@ export const fieldSharedProps = { type: Boolean, default: null, }, - clearIcon: { - type: String, - default: 'clear', - }, - clearTrigger: { - type: String as PropType, - default: 'focus', - }, - formatTrigger: { - type: String as PropType, - default: 'onChange', - }, }; const props = extend({}, cellProps, fieldSharedProps, { rows: numericProp, + type: makeStringProp('text'), rules: Array as PropType, autosize: [Boolean, Object] as PropType, labelWidth: numericProp, @@ -110,10 +103,6 @@ const props = extend({}, cellProps, fieldSharedProps, { labelAlign: String as PropType, showWordLimit: Boolean, errorMessageAlign: String as PropType, - type: { - type: String as PropType, - default: 'text', - }, colon: { type: Boolean, default: null, diff --git a/packages/vant/src/form/Form.tsx b/packages/vant/src/form/Form.tsx index a6ad7d86a..f9f54f8c0 100644 --- a/packages/vant/src/form/Form.tsx +++ b/packages/vant/src/form/Form.tsx @@ -1,7 +1,13 @@ import { PropType, defineComponent, ExtractPropTypes } from 'vue'; // Utils -import { truthProp, FORM_KEY, numericProp, createNamespace } from '../utils'; +import { + FORM_KEY, + truthProp, + numericProp, + makeStringProp, + createNamespace, +} from '../utils'; // Composables import { useChildren } from '@vant/use'; @@ -28,12 +34,9 @@ const props = { scrollToError: Boolean, validateFirst: Boolean, submitOnEnter: truthProp, + validateTrigger: makeStringProp('onBlur'), showErrorMessage: truthProp, errorMessageAlign: String as PropType, - validateTrigger: { - type: String as PropType, - default: 'onBlur', - }, }; export type FormProps = ExtractPropTypes; diff --git a/packages/vant/src/icon/Icon.tsx b/packages/vant/src/icon/Icon.tsx index f5eccd173..75496d49e 100644 --- a/packages/vant/src/icon/Icon.tsx +++ b/packages/vant/src/icon/Icon.tsx @@ -1,5 +1,10 @@ -import { PropType, defineComponent, inject, computed } from 'vue'; -import { addUnit, numericProp, createNamespace } from '../utils'; +import { defineComponent, inject, computed } from 'vue'; +import { + addUnit, + numericProp, + makeStringProp, + createNamespace, +} from '../utils'; import { Badge } from '../badge'; import { CONFIG_PROVIDER_KEY } from '../config-provider/ConfigProvider'; @@ -12,15 +17,12 @@ export default defineComponent({ props: { dot: Boolean, + tag: makeStringProp('i'), name: String, size: numericProp, badge: numericProp, color: String, classPrefix: String, - tag: { - type: String as PropType, - default: 'i', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/image-preview/ImagePreview.tsx b/packages/vant/src/image-preview/ImagePreview.tsx index 2cdc119df..14dab6393 100644 --- a/packages/vant/src/image-preview/ImagePreview.tsx +++ b/packages/vant/src/image-preview/ImagePreview.tsx @@ -16,9 +16,10 @@ import { truthProp, unknownProp, Interceptor, + makeStringProp, + makeNumericProp, callInterceptor, createNamespace, - makeNumericProp, } from '../utils'; // Composables @@ -45,6 +46,7 @@ const props = { closeable: Boolean, showIndex: truthProp, className: unknownProp, + closeIcon: makeStringProp('clear'), transition: String, beforeClose: Function as PropType, overlayStyle: Object as PropType, @@ -52,18 +54,11 @@ const props = { startPosition: makeNumericProp(0), showIndicators: Boolean, closeOnPopstate: truthProp, + closeIconPosition: makeStringProp('top-right'), images: { type: Array as PropType, default: () => [], }, - closeIcon: { - type: String, - default: 'clear', - }, - closeIconPosition: { - type: String as PropType, - default: 'top-right', - }, }; export type ImagePreviewProps = ExtractPropTypes; diff --git a/packages/vant/src/image/Image.tsx b/packages/vant/src/image/Image.tsx index 261ec45f2..ec8a3ccdd 100644 --- a/packages/vant/src/image/Image.tsx +++ b/packages/vant/src/image/Image.tsx @@ -16,6 +16,7 @@ import { inBrowser, truthProp, numericProp, + makeStringProp, createNamespace, } from '../utils'; @@ -40,16 +41,10 @@ export default defineComponent({ lazyLoad: Boolean, iconSize: numericProp, showError: truthProp, + errorIcon: makeStringProp('photo-fail'), iconPrefix: String, showLoading: truthProp, - errorIcon: { - type: String, - default: 'photo-fail', - }, - loadingIcon: { - type: String, - default: 'photo', - }, + loadingIcon: makeStringProp('photo'), }, emits: ['load', 'error'], diff --git a/packages/vant/src/list/List.tsx b/packages/vant/src/list/List.tsx index e137f03cf..8c4e13749 100644 --- a/packages/vant/src/list/List.tsx +++ b/packages/vant/src/list/List.tsx @@ -2,7 +2,6 @@ import { ref, watch, nextTick, - PropType, onUpdated, onMounted, defineComponent, @@ -13,8 +12,9 @@ import { import { isHidden, truthProp, - createNamespace, + makeStringProp, makeNumericProp, + createNamespace, } from '../utils'; // Composables @@ -36,13 +36,10 @@ const props = { loading: Boolean, finished: Boolean, errorText: String, + direction: makeStringProp('down'), loadingText: String, finishedText: String, immediateCheck: truthProp, - direction: { - type: String as PropType, - default: 'down', - }, }; export type ListProps = ExtractPropTypes; diff --git a/packages/vant/src/loading/Loading.tsx b/packages/vant/src/loading/Loading.tsx index aaeadbeb7..8f914117d 100644 --- a/packages/vant/src/loading/Loading.tsx +++ b/packages/vant/src/loading/Loading.tsx @@ -1,9 +1,10 @@ -import { computed, PropType, defineComponent } from 'vue'; +import { computed, defineComponent } from 'vue'; import { extend, addUnit, numericProp, getSizeStyle, + makeStringProp, createNamespace, } from '../utils'; @@ -26,14 +27,11 @@ export default defineComponent({ props: { size: numericProp, + type: makeStringProp('circular'), color: String, vertical: Boolean, textSize: numericProp, textColor: String, - type: { - type: String as PropType, - default: 'circular', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/notify/Notify.tsx b/packages/vant/src/notify/Notify.tsx index 45fe96f8c..e9966d9a3 100644 --- a/packages/vant/src/notify/Notify.tsx +++ b/packages/vant/src/notify/Notify.tsx @@ -1,5 +1,11 @@ -import { PropType, defineComponent } from 'vue'; -import { extend, numericProp, unknownProp, createNamespace } from '../utils'; +import { defineComponent } from 'vue'; +import { + extend, + numericProp, + unknownProp, + makeStringProp, + createNamespace, +} from '../utils'; import { Popup } from '../popup'; import { popupSharedProps } from '../popup/shared'; import type { NotifyType } from './types'; @@ -10,15 +16,12 @@ export default defineComponent({ name, props: extend({}, popupSharedProps, { + type: makeStringProp('danger'), color: String, message: numericProp, className: unknownProp, background: String, lockScroll: Boolean, - type: { - type: String as PropType, - default: 'danger', - }, }), setup(props, { slots }) { diff --git a/packages/vant/src/number-keyboard/NumberKeyboard.tsx b/packages/vant/src/number-keyboard/NumberKeyboard.tsx index e46be72f4..7cf35682e 100644 --- a/packages/vant/src/number-keyboard/NumberKeyboard.tsx +++ b/packages/vant/src/number-keyboard/NumberKeyboard.tsx @@ -15,9 +15,10 @@ import { truthProp, numericProp, getZIndexStyle, + makeStringProp, + makeNumericProp, stopPropagation, createNamespace, - makeNumericProp, } from '../utils'; // Composables @@ -43,9 +44,11 @@ export default defineComponent({ props: { show: Boolean, title: String, + theme: makeStringProp('default'), zIndex: numericProp, teleport: [String, Object] as PropType, maxlength: makeNumericProp(Number.MAX_VALUE), + modelValue: makeStringProp(''), transition: truthProp, blurOnClose: truthProp, showDeleteKey: truthProp, @@ -55,14 +58,6 @@ export default defineComponent({ closeButtonLoading: Boolean, hideOnClickOutside: truthProp, safeAreaInsetBottom: truthProp, - theme: { - type: String as PropType, - default: 'default', - }, - modelValue: { - type: String, - default: '', - }, extraKey: { type: [String, Array] as PropType, default: '', diff --git a/packages/vant/src/pagination/Pagination.tsx b/packages/vant/src/pagination/Pagination.tsx index 36952d713..5533de930 100644 --- a/packages/vant/src/pagination/Pagination.tsx +++ b/packages/vant/src/pagination/Pagination.tsx @@ -1,5 +1,10 @@ -import { computed, watch, PropType, defineComponent } from 'vue'; -import { BORDER, makeNumericProp, createNamespace } from '../utils'; +import { computed, watch, defineComponent } from 'vue'; +import { + BORDER, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; const [name, bem, t] = createNamespace('pagination'); @@ -21,6 +26,7 @@ export default defineComponent({ name, props: { + mode: makeStringProp('multi'), prevText: String, nextText: String, pageCount: makeNumericProp(0), @@ -28,10 +34,6 @@ export default defineComponent({ showPageSize: makeNumericProp(5), itemsPerPage: makeNumericProp(10), forceEllipses: Boolean, - mode: { - type: String as PropType, - default: 'multi', - }, modelValue: { type: Number, default: 0, diff --git a/packages/vant/src/password-input/PasswordInput.tsx b/packages/vant/src/password-input/PasswordInput.tsx index c50c1b46a..cbeb8b04e 100644 --- a/packages/vant/src/password-input/PasswordInput.tsx +++ b/packages/vant/src/password-input/PasswordInput.tsx @@ -4,6 +4,7 @@ import { truthProp, numericProp, BORDER_LEFT, + makeStringProp, BORDER_SURROUND, createNamespace, makeNumericProp, @@ -17,14 +18,11 @@ export default defineComponent({ props: { info: String, mask: truthProp, + value: makeStringProp(''), gutter: numericProp, length: makeNumericProp(6), focused: Boolean, errorInfo: String, - value: { - type: String, - default: '', - }, }, emits: ['focus'], diff --git a/packages/vant/src/picker/Picker.tsx b/packages/vant/src/picker/Picker.tsx index 272e8ed38..474319d88 100644 --- a/packages/vant/src/picker/Picker.tsx +++ b/packages/vant/src/picker/Picker.tsx @@ -13,6 +13,7 @@ import { unitToPx, truthProp, preventDefault, + makeStringProp, createNamespace, makeNumericProp, BORDER_UNSET_TOP_BOTTOM, @@ -61,15 +62,12 @@ export default defineComponent({ // should be removed in next major version valueKey: String, defaultIndex: makeNumericProp(0), + toolbarPosition: makeStringProp('top'), columnsFieldNames: Object as PropType, columns: { type: Array as PropType, default: () => [], }, - toolbarPosition: { - type: String as PropType, - default: 'top', - }, }), emits: ['confirm', 'cancel', 'change'], diff --git a/packages/vant/src/popover/Popover.tsx b/packages/vant/src/popover/Popover.tsx index 649020d97..80246be9f 100644 --- a/packages/vant/src/popover/Popover.tsx +++ b/packages/vant/src/popover/Popover.tsx @@ -19,6 +19,7 @@ import { numericProp, unknownProp, BORDER_BOTTOM, + makeStringProp, createNamespace, ComponentInstance, } from '../utils'; @@ -72,8 +73,11 @@ export default defineComponent({ props: { show: Boolean, + theme: makeStringProp('light'), overlay: Boolean, + trigger: makeStringProp('click'), duration: numericProp, + placement: makeStringProp('bottom'), iconPrefix: String, overlayClass: unknownProp, overlayStyle: Object as PropType, @@ -84,22 +88,10 @@ export default defineComponent({ type: Array as unknown as PropType<[number, number]>, default: () => [0, 8], }, - theme: { - type: String as PropType, - default: 'light', - }, - trigger: { - type: String as PropType, - default: 'click', - }, actions: { type: Array as PropType, default: () => [], }, - placement: { - type: String as PropType, - default: 'bottom', - }, teleport: { type: [String, Object] as PropType, default: 'body', diff --git a/packages/vant/src/popup/Popup.tsx b/packages/vant/src/popup/Popup.tsx index 4339a3e52..23cfd3d96 100644 --- a/packages/vant/src/popup/Popup.tsx +++ b/packages/vant/src/popup/Popup.tsx @@ -4,7 +4,6 @@ import { provide, Teleport, computed, - PropType, onMounted, Transition, onActivated, @@ -15,7 +14,13 @@ import { // Utils import { popupSharedProps } from './shared'; -import { extend, isDef, callInterceptor, createNamespace } from '../utils'; +import { + isDef, + extend, + makeStringProp, + callInterceptor, + createNamespace, +} from '../utils'; // Composables import { useEventListener } from '@vant/use'; @@ -47,23 +52,14 @@ export default defineComponent({ props: extend({}, popupSharedProps, { round: Boolean, + position: makeStringProp('center'), + closeIcon: makeStringProp('cross'), closeable: Boolean, transition: String, iconPrefix: String, closeOnPopstate: Boolean, + closeIconPosition: makeStringProp('top-right'), safeAreaInsetBottom: Boolean, - position: { - type: String as PropType, - default: 'center', - }, - closeIcon: { - type: String, - default: 'cross', - }, - closeIconPosition: { - type: String as PropType, - default: 'top-right', - }, }), emits: [ diff --git a/packages/vant/src/rate/Rate.tsx b/packages/vant/src/rate/Rate.tsx index db630027c..5e7454c6e 100644 --- a/packages/vant/src/rate/Rate.tsx +++ b/packages/vant/src/rate/Rate.tsx @@ -6,8 +6,9 @@ import { truthProp, numericProp, preventDefault, - createNamespace, + makeStringProp, makeNumericProp, + createNamespace, } from '../utils'; // Composables @@ -57,11 +58,13 @@ export default defineComponent({ props: { size: numericProp, + icon: makeStringProp('star'), color: String, count: makeNumericProp(5), gutter: numericProp, readonly: Boolean, disabled: Boolean, + voidIcon: makeStringProp('star-o'), allowHalf: Boolean, voidColor: String, touchable: truthProp, @@ -71,14 +74,6 @@ export default defineComponent({ type: Number, default: 0, }, - icon: { - type: String, - default: 'star', - }, - voidIcon: { - type: String, - default: 'star-o', - }, }, emits: ['change', 'update:modelValue'], diff --git a/packages/vant/src/row/Row.tsx b/packages/vant/src/row/Row.tsx index 4bf4535f0..98fc42130 100644 --- a/packages/vant/src/row/Row.tsx +++ b/packages/vant/src/row/Row.tsx @@ -5,7 +5,12 @@ import { InjectionKey, defineComponent, } from 'vue'; -import { truthProp, makeNumericProp, createNamespace } from '../utils'; +import { + truthProp, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; import { useChildren } from '@vant/use'; const [name, bem] = createNamespace('row'); @@ -31,14 +36,11 @@ export default defineComponent({ name, props: { + tag: makeStringProp('div'), wrap: truthProp, align: String as PropType, gutter: makeNumericProp(0), justify: String as PropType, - tag: { - type: String as PropType, - default: 'div', - }, }, setup(props, { slots }) { diff --git a/packages/vant/src/search/Search.tsx b/packages/vant/src/search/Search.tsx index 3c6085694..50afa39a3 100644 --- a/packages/vant/src/search/Search.tsx +++ b/packages/vant/src/search/Search.tsx @@ -1,4 +1,4 @@ -import { ref, PropType, defineComponent, ExtractPropTypes } from 'vue'; +import { ref, defineComponent, ExtractPropTypes } from 'vue'; // Utils import { @@ -6,6 +6,7 @@ import { extend, truthProp, preventDefault, + makeStringProp, createNamespace, } from '../utils'; import { fieldSharedProps } from '../field/Field'; @@ -23,18 +24,12 @@ const [name, bem, t] = createNamespace('search'); const props = extend({}, fieldSharedProps, { label: String, + shape: makeStringProp('square'), + leftIcon: makeStringProp('search'), clearable: truthProp, actionText: String, background: String, showAction: Boolean, - shape: { - type: String as PropType, - default: 'square', - }, - leftIcon: { - type: String, - default: 'search', - }, }); export type SearchProps = ExtractPropTypes; diff --git a/packages/vant/src/skeleton/Skeleton.tsx b/packages/vant/src/skeleton/Skeleton.tsx index 020a54a7d..10cc41c66 100644 --- a/packages/vant/src/skeleton/Skeleton.tsx +++ b/packages/vant/src/skeleton/Skeleton.tsx @@ -4,14 +4,17 @@ import { truthProp, numericProp, getSizeStyle, - createNamespace, + makeStringProp, makeNumericProp, + createNamespace, } from '../utils'; const [name, bem] = createNamespace('skeleton'); const DEFAULT_ROW_WIDTH = '100%'; const DEFAULT_LAST_ROW_WIDTH = '60%'; +export type SkeletonAvatarShape = 'square' | 'round'; + export default defineComponent({ name, @@ -24,10 +27,7 @@ export default defineComponent({ animate: truthProp, avatarSize: numericProp, titleWidth: numericProp, - avatarShape: { - type: String as PropType<'square' | 'round'>, - default: 'round', - }, + avatarShape: makeStringProp('round'), rowWidth: { type: [Number, String, Array] as PropType< number | string | (number | string)[] diff --git a/packages/vant/src/steps/Steps.tsx b/packages/vant/src/steps/Steps.tsx index 5ad108b62..6d05b4762 100644 --- a/packages/vant/src/steps/Steps.tsx +++ b/packages/vant/src/steps/Steps.tsx @@ -1,5 +1,5 @@ -import { PropType, defineComponent, ExtractPropTypes, InjectionKey } from 'vue'; -import { makeNumericProp, createNamespace } from '../utils'; +import { defineComponent, ExtractPropTypes, InjectionKey } from 'vue'; +import { makeStringProp, makeNumericProp, createNamespace } from '../utils'; import { useChildren } from '@vant/use'; const [name, bem] = createNamespace('steps'); @@ -8,19 +8,13 @@ export type StepsDirection = 'horizontal' | 'vertical'; const props = { active: makeNumericProp(0), + direction: makeStringProp('horizontal'), + activeIcon: makeStringProp('checked'), iconPrefix: String, finishIcon: String, activeColor: String, inactiveIcon: String, inactiveColor: String, - direction: { - type: String as PropType, - default: 'horizontal', - }, - activeIcon: { - type: String, - default: 'checked', - }, }; export type StepsProvide = { diff --git a/packages/vant/src/sticky/Sticky.tsx b/packages/vant/src/sticky/Sticky.tsx index 154b0ad52..b0730042a 100644 --- a/packages/vant/src/sticky/Sticky.tsx +++ b/packages/vant/src/sticky/Sticky.tsx @@ -16,8 +16,9 @@ import { numericProp, getScrollTop, getZIndexStyle, - createNamespace, + makeStringProp, makeNumericProp, + createNamespace, } from '../utils'; // Composables @@ -33,13 +34,10 @@ export default defineComponent({ props: { zIndex: numericProp, + position: makeStringProp('top'), container: Object as PropType, offsetTop: makeNumericProp(0), offsetBottom: makeNumericProp(0), - position: { - type: String as PropType, - default: 'top', - }, }, emits: ['scroll', 'change'], diff --git a/packages/vant/src/submit-bar/SubmitBar.tsx b/packages/vant/src/submit-bar/SubmitBar.tsx index e86ca90a5..21bf2d93e 100644 --- a/packages/vant/src/submit-bar/SubmitBar.tsx +++ b/packages/vant/src/submit-bar/SubmitBar.tsx @@ -1,5 +1,10 @@ import { PropType, CSSProperties, defineComponent } from 'vue'; -import { truthProp, makeNumericProp, createNamespace } from '../utils'; +import { + truthProp, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; // Components import { Icon } from '../icon'; @@ -16,21 +21,15 @@ export default defineComponent({ price: Number, tipIcon: String, loading: Boolean, + currency: makeStringProp('¥'), disabled: Boolean, textAlign: String as PropType, buttonText: String, + buttonType: makeStringProp('danger'), buttonColor: String, suffixLabel: String, decimalLength: makeNumericProp(2), safeAreaInsetBottom: truthProp, - currency: { - type: String, - default: '¥', - }, - buttonType: { - type: String as PropType, - default: 'danger', - }, }, emits: ['submit'], diff --git a/packages/vant/src/tabs/Tabs.tsx b/packages/vant/src/tabs/Tabs.tsx index effadf3b8..cd4e9826b 100644 --- a/packages/vant/src/tabs/Tabs.tsx +++ b/packages/vant/src/tabs/Tabs.tsx @@ -26,6 +26,7 @@ import { Interceptor, getVisibleTop, getElementTop, + makeStringProp, callInterceptor, createNamespace, makeNumericProp, @@ -60,6 +61,7 @@ import type { TabsProvide, TabsType } from './types'; const [name, bem] = createNamespace('tabs'); const props = { + type: makeStringProp('line'), color: String, border: Boolean, sticky: Boolean, @@ -78,10 +80,6 @@ const props = { swipeThreshold: makeNumericProp(5), titleActiveColor: String, titleInactiveColor: String, - type: { - type: String as PropType, - default: 'line', - }, }; export type TabsProps = ExtractPropTypes; diff --git a/packages/vant/src/tag/Tag.tsx b/packages/vant/src/tag/Tag.tsx index f3a638e23..a1b3cc214 100644 --- a/packages/vant/src/tag/Tag.tsx +++ b/packages/vant/src/tag/Tag.tsx @@ -1,5 +1,5 @@ -import { CSSProperties, PropType, Transition, defineComponent } from 'vue'; -import { truthProp, createNamespace } from '../utils'; +import { CSSProperties, Transition, defineComponent } from 'vue'; +import { truthProp, makeStringProp, createNamespace } from '../utils'; import { Icon } from '../icon'; const [name, bem] = createNamespace('tag'); @@ -13,15 +13,12 @@ export default defineComponent({ size: String, mark: Boolean, show: truthProp, + type: makeStringProp('default'), color: String, plain: Boolean, round: Boolean, textColor: String, closeable: Boolean, - type: { - type: String as PropType, - default: 'default', - }, }, emits: ['close'], diff --git a/packages/vant/src/toast/Toast.tsx b/packages/vant/src/toast/Toast.tsx index d22c9ae44..51548e955 100644 --- a/packages/vant/src/toast/Toast.tsx +++ b/packages/vant/src/toast/Toast.tsx @@ -8,7 +8,13 @@ import { } from 'vue'; // Utils -import { isDef, unknownProp, numericProp, createNamespace } from '../utils'; +import { + isDef, + unknownProp, + numericProp, + makeStringProp, + createNamespace, +} from '../utils'; import { lockClick } from './lock-click'; // Components @@ -27,33 +33,24 @@ export default defineComponent({ props: { icon: String, show: Boolean, + type: makeStringProp('text'), overlay: Boolean, message: numericProp, iconSize: numericProp, + position: makeStringProp('middle'), className: unknownProp, iconPrefix: String, + transition: makeStringProp('van-fade'), loadingType: String as PropType, forbidClick: Boolean, overlayClass: unknownProp, overlayStyle: Object as PropType, closeOnClick: Boolean, closeOnClickOverlay: Boolean, - type: { - type: String as PropType, - default: 'text', - }, duration: { type: Number, default: 2000, }, - position: { - type: String as PropType, - default: 'middle', - }, - transition: { - type: String, - default: 'van-fade', - }, }, emits: ['update:show'], diff --git a/packages/vant/src/tree-select/TreeSelect.tsx b/packages/vant/src/tree-select/TreeSelect.tsx index 87647ac14..30a688b3f 100644 --- a/packages/vant/src/tree-select/TreeSelect.tsx +++ b/packages/vant/src/tree-select/TreeSelect.tsx @@ -1,7 +1,12 @@ import { PropType, defineComponent } from 'vue'; // Utils -import { addUnit, createNamespace, makeNumericProp } from '../utils'; +import { + addUnit, + makeStringProp, + makeNumericProp, + createNamespace, +} from '../utils'; // Components import { Icon } from '../icon'; @@ -31,6 +36,7 @@ export default defineComponent({ props: { max: makeNumericProp(Infinity), height: makeNumericProp(300), + selectedIcon: makeStringProp('success'), mainActiveIndex: makeNumericProp(0), items: { type: Array as PropType, @@ -42,10 +48,6 @@ export default defineComponent({ >, default: 0, }, - selectedIcon: { - type: String, - default: 'success', - }, }, emits: [ diff --git a/packages/vant/src/uploader/Uploader.tsx b/packages/vant/src/uploader/Uploader.tsx index 368dbcea4..396af6434 100644 --- a/packages/vant/src/uploader/Uploader.tsx +++ b/packages/vant/src/uploader/Uploader.tsx @@ -15,6 +15,7 @@ import { numericProp, Interceptor, getSizeStyle, + makeStringProp, makeNumericProp, ComponentInstance, } from '../utils'; @@ -50,12 +51,16 @@ import type { const props = { name: makeNumericProp(''), + accept: makeStringProp('image/*'), capture: String, multiple: Boolean, disabled: Boolean, readonly: Boolean, lazyLoad: Boolean, maxCount: makeNumericProp(Number.MAX_VALUE), + imageFit: makeStringProp('cover'), + resultType: makeStringProp('dataUrl'), + uploadIcon: makeStringProp('photograph'), uploadText: String, deletable: truthProp, afterRead: Function as PropType, @@ -66,10 +71,6 @@ const props = { previewImage: truthProp, previewOptions: Object as PropType, previewFullImage: truthProp, - accept: { - type: String, - default: 'image/*', - }, modelValue: { type: Array as PropType, default: () => [], @@ -78,18 +79,6 @@ const props = { type: [Number, String, Function] as PropType, default: Number.MAX_VALUE, }, - imageFit: { - type: String as PropType, - default: 'cover', - }, - resultType: { - type: String as PropType, - default: 'dataUrl', - }, - uploadIcon: { - type: String, - default: 'photograph', - }, }; export type UploaderProps = ExtractPropTypes; diff --git a/packages/vant/src/utils/basic.ts b/packages/vant/src/utils/basic.ts index 7b6054182..e8ea373c3 100644 --- a/packages/vant/src/utils/basic.ts +++ b/packages/vant/src/utils/basic.ts @@ -15,7 +15,11 @@ export const truthProp = { default: true as const, }; export const makeNumericProp = (defaultVal: T) => ({ - type: [Number, String], + type: numericProp, + default: defaultVal, +}); +export const makeStringProp = (defaultVal: T) => ({ + type: String as unknown as PropType, default: defaultVal, });