perf: add stringProp helper (#9603)

This commit is contained in:
neverland 2021-09-30 17:50:09 +08:00 committed by GitHub
parent d111df8dfa
commit 20fc06bf21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 239 additions and 341 deletions

View File

@ -1,7 +1,13 @@
import { nextTick, PropType, defineComponent } from 'vue'; import { nextTick, PropType, defineComponent } from 'vue';
// Utils // Utils
import { pick, extend, truthProp, createNamespace } from '../utils'; import {
pick,
extend,
truthProp,
makeStringProp,
createNamespace,
} from '../utils';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -28,16 +34,13 @@ export default defineComponent({
title: String, title: String,
round: truthProp, round: truthProp,
actions: Array as PropType<ActionSheetAction[]>, actions: Array as PropType<ActionSheetAction[]>,
closeIcon: makeStringProp('cross'),
closeable: truthProp, closeable: truthProp,
cancelText: String, cancelText: String,
description: String, description: String,
closeOnPopstate: Boolean, closeOnPopstate: Boolean,
closeOnClickAction: Boolean, closeOnClickAction: Boolean,
safeAreaInsetBottom: truthProp, safeAreaInsetBottom: truthProp,
closeIcon: {
type: String,
default: 'cross',
},
}), }),
emits: ['select', 'cancel', 'update:show'], emits: ['select', 'cancel', 'update:show'],

View File

@ -5,6 +5,7 @@ import {
isNumeric, isNumeric,
truthProp, truthProp,
numericProp, numericProp,
makeStringProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -16,14 +17,11 @@ export default defineComponent({
props: { props: {
dot: Boolean, dot: Boolean,
max: numericProp, max: numericProp,
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
color: String, color: String,
offset: Array as unknown as PropType<[string | number, string | number]>, offset: Array as unknown as PropType<[string | number, string | number]>,
content: numericProp, content: numericProp,
showZero: truthProp, showZero: truthProp,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'div',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -9,6 +9,7 @@ import {
import { import {
extend, extend,
numericProp, numericProp,
makeStringProp,
createNamespace, createNamespace,
BORDER_SURROUND, BORDER_SURROUND,
} from '../utils'; } from '../utils';
@ -29,12 +30,19 @@ export type ButtonType =
export type ButtonSize = 'large' | 'normal' | 'small' | 'mini'; export type ButtonSize = 'large' | 'normal' | 'small' | 'mini';
export type ButtonNativeType = NonNullable<ButtonHTMLAttributes['type']>;
export type ButtonIconPosition = 'left' | 'right';
export default defineComponent({ export default defineComponent({
name, name,
props: extend({}, routeProps, { props: extend({}, routeProps, {
tag: makeStringProp<keyof HTMLElementTagNameMap>('button'),
text: String, text: String,
icon: String, icon: String,
type: makeStringProp<ButtonType>('default'),
size: makeStringProp<ButtonSize>('normal'),
color: String, color: String,
block: Boolean, block: Boolean,
plain: Boolean, plain: Boolean,
@ -44,29 +52,11 @@ export default defineComponent({
hairline: Boolean, hairline: Boolean,
disabled: Boolean, disabled: Boolean,
iconPrefix: String, iconPrefix: String,
nativeType: makeStringProp<ButtonNativeType>('button'),
loadingSize: numericProp, loadingSize: numericProp,
loadingText: String, loadingText: String,
loadingType: String as PropType<LoadingType>, loadingType: String as PropType<LoadingType>,
tag: { iconPosition: makeStringProp<ButtonIconPosition>('left'),
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'button',
},
type: {
type: String as PropType<ButtonType>,
default: 'default',
},
size: {
type: String as PropType<ButtonSize>,
default: 'normal',
},
nativeType: {
type: String as PropType<ButtonHTMLAttributes['type']>,
default: 'button',
},
iconPosition: {
type: String as PropType<'left' | 'right'>,
default: 'left',
},
}), }),
emits: ['click'], emits: ['click'],

View File

@ -15,6 +15,7 @@ import {
truthProp, truthProp,
numericProp, numericProp,
getScrollTop, getScrollTop,
makeStringProp,
makeNumericProp, makeNumericProp,
} from '../utils'; } from '../utils';
import { import {
@ -54,11 +55,14 @@ import type {
const props = { const props = {
show: Boolean, show: Boolean,
type: makeStringProp<CalendarType>('single'),
title: String, title: String,
color: String, color: String,
round: truthProp, round: truthProp,
readonly: Boolean, readonly: Boolean,
poppable: truthProp, poppable: truthProp,
maxRange: makeNumericProp(null),
position: makeStringProp<PopupPosition>('bottom'),
teleport: [String, Object] as PropType<TeleportProps['to']>, teleport: [String, Object] as PropType<TeleportProps['to']>,
showMark: truthProp, showMark: truthProp,
showTitle: truthProp, showTitle: truthProp,
@ -75,15 +79,6 @@ const props = {
confirmDisabledText: String, confirmDisabledText: String,
closeOnClickOverlay: truthProp, closeOnClickOverlay: truthProp,
safeAreaInsetBottom: truthProp, safeAreaInsetBottom: truthProp,
type: {
type: String as PropType<CalendarType>,
default: 'single',
},
position: {
type: String as PropType<PopupPosition>,
default: 'bottom',
},
maxRange: makeNumericProp(null),
minDate: { minDate: {
type: Date, type: Date,
validator: isDate, validator: isDate,

View File

@ -1,7 +1,7 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
// Utils // Utils
import { isDef, numericProp, createNamespace } from '../utils'; import { isDef, numericProp, makeStringProp, createNamespace } from '../utils';
// Components // Components
import { Tag } from '../tag'; import { Tag } from '../tag';
@ -21,12 +21,9 @@ export default defineComponent({
price: numericProp, price: numericProp,
centered: Boolean, centered: Boolean,
lazyLoad: Boolean, lazyLoad: Boolean,
currency: makeStringProp('¥'),
thumbLink: String, thumbLink: String,
originPrice: numericProp, originPrice: numericProp,
currency: {
type: String,
default: '¥',
},
}, },
emits: ['click-thumb'], emits: ['click-thumb'],

View File

@ -1,5 +1,11 @@
import { nextTick, PropType, reactive, watch, defineComponent } from 'vue'; import { nextTick, PropType, reactive, watch, defineComponent } from 'vue';
import { extend, numericProp, truthProp, createNamespace } from '../utils'; import {
extend,
truthProp,
numericProp,
makeStringProp,
createNamespace,
} from '../utils';
// Components // Components
import { Tab } from '../tab'; import { Tab } from '../tab';
@ -40,6 +46,7 @@ export default defineComponent({
title: String, title: String,
closeable: truthProp, closeable: truthProp,
swipeable: truthProp, swipeable: truthProp,
closeIcon: makeStringProp('cross'),
modelValue: numericProp, modelValue: numericProp,
fieldNames: Object as PropType<CascaderFieldNames>, fieldNames: Object as PropType<CascaderFieldNames>,
placeholder: String, placeholder: String,
@ -48,10 +55,6 @@ export default defineComponent({
type: Array as PropType<CascaderOption[]>, type: Array as PropType<CascaderOption[]>,
default: () => [], default: () => [],
}, },
closeIcon: {
type: String,
default: 'cross',
},
}, },
emits: ['close', 'change', 'finish', 'update:modelValue', 'click-tab'], emits: ['close', 'change', 'finish', 'update:modelValue', 'click-tab'],

View File

@ -1,5 +1,12 @@
import { ref, computed, PropType, defineComponent } from 'vue'; 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'; import { Icon } from '../icon';
export type CheckerShape = 'square' | 'round'; export type CheckerShape = 'square' | 'round';
@ -16,16 +23,13 @@ export type CheckerParent = {
export const checkerProps = { export const checkerProps = {
name: unknownProp, name: unknownProp,
shape: makeStringProp<CheckerShape>('round'),
disabled: Boolean, disabled: Boolean,
iconSize: numericProp, iconSize: numericProp,
modelValue: unknownProp, modelValue: unknownProp,
checkedColor: String, checkedColor: String,
labelPosition: String as PropType<CheckerLabelPosition>, labelPosition: String as PropType<CheckerLabelPosition>,
labelDisabled: Boolean, labelDisabled: Boolean,
shape: {
type: String as PropType<CheckerShape>,
default: 'round',
},
}; };
export default defineComponent({ export default defineComponent({

View File

@ -5,6 +5,7 @@ import {
truthProp, truthProp,
numericProp, numericProp,
getSizeStyle, getSizeStyle,
makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -30,6 +31,7 @@ export default defineComponent({
props: { props: {
text: String, text: String,
size: numericProp, size: numericProp,
fill: makeStringProp('none'),
rate: makeNumericProp(100), rate: makeNumericProp(100),
speed: makeNumericProp(0), speed: makeNumericProp(0),
color: [String, Object] as PropType<string | Record<string, string>>, color: [String, Object] as PropType<string | Record<string, string>>,
@ -37,18 +39,11 @@ export default defineComponent({
layerColor: String, layerColor: String,
strokeWidth: makeNumericProp(40), strokeWidth: makeNumericProp(40),
strokeLinecap: String as PropType<CanvasLineCap>, strokeLinecap: String as PropType<CanvasLineCap>,
startPosition: makeStringProp<CircleStartPosition>('top'),
currentRate: { currentRate: {
type: Number, type: Number,
default: 0, default: 0,
}, },
fill: {
type: String,
default: 'none',
},
startPosition: {
type: String as PropType<CircleStartPosition>,
default: 'top',
},
}, },
emits: ['update:currentRate'], emits: ['update:currentRate'],

View File

@ -1,5 +1,10 @@
import { computed, PropType, defineComponent } from 'vue'; import { computed, defineComponent } from 'vue';
import { numericProp, createNamespace, makeNumericProp } from '../utils'; import {
numericProp,
createNamespace,
makeNumericProp,
makeStringProp,
} from '../utils';
import { useParent } from '@vant/use'; import { useParent } from '@vant/use';
import { ROW_KEY } from '../row/Row'; import { ROW_KEY } from '../row/Row';
@ -9,12 +14,9 @@ export default defineComponent({
name, name,
props: { props: {
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
span: makeNumericProp(0), span: makeNumericProp(0),
offset: numericProp, offset: numericProp,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'div',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -2,11 +2,11 @@ import {
provide, provide,
computed, computed,
PropType, PropType,
CSSProperties,
InjectionKey, InjectionKey,
CSSProperties,
defineComponent, defineComponent,
} from 'vue'; } from 'vue';
import { createNamespace, kebabCase } from '../utils'; import { kebabCase, makeStringProp, createNamespace } from '../utils';
const [name, bem] = createNamespace('config-provider'); const [name, bem] = createNamespace('config-provider');
@ -29,12 +29,9 @@ export default defineComponent({
name, name,
props: { props: {
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
themeVars: Object as PropType<Record<string, string | number>>, themeVars: Object as PropType<Record<string, string | number>>,
iconPrefix: String, iconPrefix: String,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'div',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -1,5 +1,5 @@
import { PropType, defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { truthProp, createNamespace } from '../utils'; import { truthProp, makeStringProp, createNamespace } from '../utils';
import { Cell } from '../cell'; import { Cell } from '../cell';
const [name, bem, t] = createNamespace('contact-card'); const [name, bem, t] = createNamespace('contact-card');
@ -12,12 +12,9 @@ export default defineComponent({
props: { props: {
tel: String, tel: String,
name: String, name: String,
type: makeStringProp<ContactCardType>('add'),
addText: String, addText: String,
editable: truthProp, editable: truthProp,
type: {
type: String as PropType<ContactCardType>,
default: 'add',
},
}, },
emits: ['click'], emits: ['click'],

View File

@ -1,7 +1,12 @@
import { watch, computed, defineComponent, ExtractPropTypes } from 'vue'; import { watch, computed, defineComponent, ExtractPropTypes } from 'vue';
// Utils // Utils
import { truthProp, createNamespace, makeNumericProp } from '../utils'; import {
truthProp,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
import { parseFormat } from './utils'; import { parseFormat } from './utils';
// Composables // Composables
@ -12,12 +17,9 @@ const [name, bem] = createNamespace('count-down');
const props = { const props = {
time: makeNumericProp(0), time: makeNumericProp(0),
format: makeStringProp('HH:mm:ss'),
autoStart: truthProp, autoStart: truthProp,
millisecond: Boolean, millisecond: Boolean,
format: {
type: String,
default: 'HH:mm:ss',
},
}; };
export type CountDownProps = ExtractPropTypes<typeof props>; export type CountDownProps = ExtractPropTypes<typeof props>;

View File

@ -1,7 +1,13 @@
import { PropType, defineComponent } from 'vue'; import { PropType, defineComponent } from 'vue';
// Utils // Utils
import { isDef, truthProp, makeNumericProp, createNamespace } from '../utils'; import {
isDef,
truthProp,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
// Components // Components
import { Cell } from '../cell'; import { Cell } from '../cell';
@ -40,15 +46,12 @@ export default defineComponent({
title: String, title: String,
border: truthProp, border: truthProp,
editable: truthProp, editable: truthProp,
currency: makeStringProp('¥'),
chosenCoupon: makeNumericProp(-1), chosenCoupon: makeNumericProp(-1),
coupons: { coupons: {
type: Array as PropType<CouponInfo[]>, type: Array as PropType<CouponInfo[]>,
default: () => [], default: () => [],
}, },
currency: {
type: String,
default: '¥',
},
}, },
setup(props) { setup(props) {

View File

@ -9,7 +9,7 @@ import {
} from 'vue'; } from 'vue';
// Utils // Utils
import { truthProp, createNamespace } from '../utils'; import { truthProp, makeStringProp, createNamespace } from '../utils';
// Composables // Composables
import { useRefs } from '../composables/use-refs'; import { useRefs } from '../composables/use-refs';
@ -28,7 +28,10 @@ export default defineComponent({
name, name,
props: { props: {
code: makeStringProp(''),
currency: makeStringProp('¥'),
showCount: truthProp, showCount: truthProp,
emptyImage: makeStringProp(EMPTY_IMAGE),
enabledTitle: String, enabledTitle: String,
disabledTitle: String, disabledTitle: String,
showExchangeBar: truthProp, showExchangeBar: truthProp,
@ -38,10 +41,6 @@ export default defineComponent({
exchangeButtonText: String, exchangeButtonText: String,
exchangeButtonLoading: Boolean, exchangeButtonLoading: Boolean,
exchangeButtonDisabled: Boolean, exchangeButtonDisabled: Boolean,
code: {
type: String,
default: '',
},
exchangeMinLength: { exchangeMinLength: {
type: Number, type: Number,
default: 1, default: 1,
@ -62,14 +61,6 @@ export default defineComponent({
type: Number, type: Number,
default: -1, default: -1,
}, },
currency: {
type: String,
default: '¥',
},
emptyImage: {
type: String,
default: EMPTY_IMAGE,
},
}, },
emits: ['change', 'exchange', 'update:code'], emits: ['change', 'exchange', 'update:code'],

View File

@ -1,5 +1,5 @@
import { computed, PropType, defineComponent } from 'vue'; import { computed, PropType, defineComponent } from 'vue';
import { padZero, createNamespace } from '../utils'; import { padZero, makeStringProp, createNamespace } from '../utils';
import { Checkbox } from '../checkbox'; import { Checkbox } from '../checkbox';
export type CouponInfo = { export type CouponInfo = {
@ -39,14 +39,11 @@ export default defineComponent({
props: { props: {
chosen: Boolean, chosen: Boolean,
disabled: Boolean, disabled: Boolean,
currency: makeStringProp('¥'),
coupon: { coupon: {
type: Object as PropType<CouponInfo>, type: Object as PropType<CouponInfo>,
required: true, required: true,
}, },
currency: {
type: String,
default: '¥',
},
}, },
setup(props) { setup(props) {

View File

@ -4,7 +4,6 @@ import {
computed, computed,
nextTick, nextTick,
onMounted, onMounted,
PropType,
defineComponent, defineComponent,
} from 'vue'; } from 'vue';
@ -15,6 +14,7 @@ import {
extend, extend,
isDate, isDate,
padZero, padZero,
makeStringProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
import { import {
@ -41,11 +41,8 @@ export default defineComponent({
name, name,
props: extend({}, sharedProps, { props: extend({}, sharedProps, {
type: makeStringProp<DatetimePickerType>('datetime'),
modelValue: Date, modelValue: Date,
type: {
type: String as PropType<DatetimePickerType>,
default: 'datetime',
},
minDate: { minDate: {
type: Date, type: Date,
default: () => new Date(currentYear - 10, 0, 1), default: () => new Date(currentYear - 10, 0, 1),

View File

@ -11,6 +11,7 @@ import {
BORDER_LEFT, BORDER_LEFT,
unknownProp, unknownProp,
numericProp, numericProp,
makeStringProp,
callInterceptor, callInterceptor,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -49,6 +50,7 @@ export default defineComponent({
callback: Function as PropType<(action?: DialogAction) => void>, callback: Function as PropType<(action?: DialogAction) => void>,
allowHtml: Boolean, allowHtml: Boolean,
className: unknownProp, className: unknownProp,
transition: makeStringProp('van-dialog-bounce'),
messageAlign: String as PropType<DialogMessageAlign>, messageAlign: String as PropType<DialogMessageAlign>,
closeOnPopstate: truthProp, closeOnPopstate: truthProp,
showCancelButton: Boolean, showCancelButton: Boolean,
@ -58,10 +60,6 @@ export default defineComponent({
confirmButtonColor: String, confirmButtonColor: String,
showConfirmButton: truthProp, showConfirmButton: truthProp,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
transition: {
type: String,
default: 'van-dialog-bounce',
},
}), }),
emits: ['confirm', 'cancel', 'update:show'], emits: ['confirm', 'cancel', 'update:show'],

View File

@ -1,5 +1,5 @@
import { PropType, defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { truthProp, createNamespace } from '../utils'; import { truthProp, makeStringProp, createNamespace } from '../utils';
const [name, bem] = createNamespace('divider'); const [name, bem] = createNamespace('divider');
@ -11,10 +11,7 @@ export default defineComponent({
props: { props: {
dashed: Boolean, dashed: Boolean,
hairline: truthProp, hairline: truthProp,
contentPosition: { contentPosition: makeStringProp<DividerContentPosition>('center'),
type: String as PropType<DividerContentPosition>,
default: 'center',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -1,7 +1,6 @@
import { import {
ref, ref,
computed, computed,
PropType,
InjectionKey, InjectionKey,
CSSProperties, CSSProperties,
defineComponent, defineComponent,
@ -13,8 +12,9 @@ import {
isDef, isDef,
truthProp, truthProp,
numericProp, numericProp,
createNamespace, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
@ -36,13 +36,10 @@ const props = {
overlay: truthProp, overlay: truthProp,
zIndex: numericProp, zIndex: numericProp,
duration: makeNumericProp(0.2), duration: makeNumericProp(0.2),
direction: makeStringProp<DropdownMenuDirection>('down'),
activeColor: String, activeColor: String,
closeOnClickOutside: truthProp, closeOnClickOutside: truthProp,
closeOnClickOverlay: truthProp, closeOnClickOverlay: truthProp,
direction: {
type: String as PropType<DropdownMenuDirection>,
default: 'down',
},
}; };
export type DropdownMenuProps = ExtractPropTypes<typeof props>; export type DropdownMenuProps = ExtractPropTypes<typeof props>;

View File

@ -1,5 +1,10 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { createNamespace, getSizeStyle, numericProp } from '../utils'; import {
numericProp,
getSizeStyle,
makeStringProp,
createNamespace,
} from '../utils';
import { Network } from './Network'; import { Network } from './Network';
const [name, bem] = createNamespace('empty'); const [name, bem] = createNamespace('empty');
@ -10,12 +15,9 @@ export default defineComponent({
name, name,
props: { props: {
image: makeStringProp('default'),
imageSize: numericProp, imageSize: numericProp,
description: String, description: String,
image: {
type: String,
default: 'default',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -22,6 +22,7 @@ import {
resetScroll, resetScroll,
formatNumber, formatNumber,
preventDefault, preventDefault,
makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -64,17 +65,20 @@ const [name, bem] = createNamespace('field');
export const fieldSharedProps = { export const fieldSharedProps = {
id: String, id: String,
name: String, name: String,
formatter: Function as PropType<(value: string) => string>,
leftIcon: String, leftIcon: String,
rightIcon: String, rightIcon: String,
autofocus: Boolean, autofocus: Boolean,
clearable: Boolean, clearable: Boolean,
maxlength: numericProp, maxlength: numericProp,
formatter: Function as PropType<(value: string) => string>,
clearIcon: makeStringProp('clear'),
modelValue: makeNumericProp(''), modelValue: makeNumericProp(''),
inputAlign: String as PropType<FieldTextAlign>, inputAlign: String as PropType<FieldTextAlign>,
placeholder: String, placeholder: String,
autocomplete: String, autocomplete: String,
errorMessage: String, errorMessage: String,
clearTrigger: makeStringProp<FieldClearTrigger>('focus'),
formatTrigger: makeStringProp<FieldFormatTrigger>('onChange'),
error: { error: {
type: Boolean, type: Boolean,
default: null, default: null,
@ -87,22 +91,11 @@ export const fieldSharedProps = {
type: Boolean, type: Boolean,
default: null, default: null,
}, },
clearIcon: {
type: String,
default: 'clear',
},
clearTrigger: {
type: String as PropType<FieldClearTrigger>,
default: 'focus',
},
formatTrigger: {
type: String as PropType<FieldFormatTrigger>,
default: 'onChange',
},
}; };
const props = extend({}, cellProps, fieldSharedProps, { const props = extend({}, cellProps, fieldSharedProps, {
rows: numericProp, rows: numericProp,
type: makeStringProp<FieldType>('text'),
rules: Array as PropType<FieldRule[]>, rules: Array as PropType<FieldRule[]>,
autosize: [Boolean, Object] as PropType<boolean | FieldAutosizeConfig>, autosize: [Boolean, Object] as PropType<boolean | FieldAutosizeConfig>,
labelWidth: numericProp, labelWidth: numericProp,
@ -110,10 +103,6 @@ const props = extend({}, cellProps, fieldSharedProps, {
labelAlign: String as PropType<FieldTextAlign>, labelAlign: String as PropType<FieldTextAlign>,
showWordLimit: Boolean, showWordLimit: Boolean,
errorMessageAlign: String as PropType<FieldTextAlign>, errorMessageAlign: String as PropType<FieldTextAlign>,
type: {
type: String as PropType<FieldType>,
default: 'text',
},
colon: { colon: {
type: Boolean, type: Boolean,
default: null, default: null,

View File

@ -1,7 +1,13 @@
import { PropType, defineComponent, ExtractPropTypes } from 'vue'; import { PropType, defineComponent, ExtractPropTypes } from 'vue';
// Utils // Utils
import { truthProp, FORM_KEY, numericProp, createNamespace } from '../utils'; import {
FORM_KEY,
truthProp,
numericProp,
makeStringProp,
createNamespace,
} from '../utils';
// Composables // Composables
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
@ -28,12 +34,9 @@ const props = {
scrollToError: Boolean, scrollToError: Boolean,
validateFirst: Boolean, validateFirst: Boolean,
submitOnEnter: truthProp, submitOnEnter: truthProp,
validateTrigger: makeStringProp<FieldValidateTrigger>('onBlur'),
showErrorMessage: truthProp, showErrorMessage: truthProp,
errorMessageAlign: String as PropType<FieldTextAlign>, errorMessageAlign: String as PropType<FieldTextAlign>,
validateTrigger: {
type: String as PropType<FieldValidateTrigger>,
default: 'onBlur',
},
}; };
export type FormProps = ExtractPropTypes<typeof props>; export type FormProps = ExtractPropTypes<typeof props>;

View File

@ -1,5 +1,10 @@
import { PropType, defineComponent, inject, computed } from 'vue'; import { defineComponent, inject, computed } from 'vue';
import { addUnit, numericProp, createNamespace } from '../utils'; import {
addUnit,
numericProp,
makeStringProp,
createNamespace,
} from '../utils';
import { Badge } from '../badge'; import { Badge } from '../badge';
import { CONFIG_PROVIDER_KEY } from '../config-provider/ConfigProvider'; import { CONFIG_PROVIDER_KEY } from '../config-provider/ConfigProvider';
@ -12,15 +17,12 @@ export default defineComponent({
props: { props: {
dot: Boolean, dot: Boolean,
tag: makeStringProp<keyof HTMLElementTagNameMap>('i'),
name: String, name: String,
size: numericProp, size: numericProp,
badge: numericProp, badge: numericProp,
color: String, color: String,
classPrefix: String, classPrefix: String,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'i',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -16,9 +16,10 @@ import {
truthProp, truthProp,
unknownProp, unknownProp,
Interceptor, Interceptor,
makeStringProp,
makeNumericProp,
callInterceptor, callInterceptor,
createNamespace, createNamespace,
makeNumericProp,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -45,6 +46,7 @@ const props = {
closeable: Boolean, closeable: Boolean,
showIndex: truthProp, showIndex: truthProp,
className: unknownProp, className: unknownProp,
closeIcon: makeStringProp('clear'),
transition: String, transition: String,
beforeClose: Function as PropType<Interceptor>, beforeClose: Function as PropType<Interceptor>,
overlayStyle: Object as PropType<CSSProperties>, overlayStyle: Object as PropType<CSSProperties>,
@ -52,18 +54,11 @@ const props = {
startPosition: makeNumericProp(0), startPosition: makeNumericProp(0),
showIndicators: Boolean, showIndicators: Boolean,
closeOnPopstate: truthProp, closeOnPopstate: truthProp,
closeIconPosition: makeStringProp<PopupCloseIconPosition>('top-right'),
images: { images: {
type: Array as PropType<string[]>, type: Array as PropType<string[]>,
default: () => [], default: () => [],
}, },
closeIcon: {
type: String,
default: 'clear',
},
closeIconPosition: {
type: String as PropType<PopupCloseIconPosition>,
default: 'top-right',
},
}; };
export type ImagePreviewProps = ExtractPropTypes<typeof props>; export type ImagePreviewProps = ExtractPropTypes<typeof props>;

View File

@ -16,6 +16,7 @@ import {
inBrowser, inBrowser,
truthProp, truthProp,
numericProp, numericProp,
makeStringProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -40,16 +41,10 @@ export default defineComponent({
lazyLoad: Boolean, lazyLoad: Boolean,
iconSize: numericProp, iconSize: numericProp,
showError: truthProp, showError: truthProp,
errorIcon: makeStringProp('photo-fail'),
iconPrefix: String, iconPrefix: String,
showLoading: truthProp, showLoading: truthProp,
errorIcon: { loadingIcon: makeStringProp('photo'),
type: String,
default: 'photo-fail',
},
loadingIcon: {
type: String,
default: 'photo',
},
}, },
emits: ['load', 'error'], emits: ['load', 'error'],

View File

@ -2,7 +2,6 @@ import {
ref, ref,
watch, watch,
nextTick, nextTick,
PropType,
onUpdated, onUpdated,
onMounted, onMounted,
defineComponent, defineComponent,
@ -13,8 +12,9 @@ import {
import { import {
isHidden, isHidden,
truthProp, truthProp,
createNamespace, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -36,13 +36,10 @@ const props = {
loading: Boolean, loading: Boolean,
finished: Boolean, finished: Boolean,
errorText: String, errorText: String,
direction: makeStringProp<ListDirection>('down'),
loadingText: String, loadingText: String,
finishedText: String, finishedText: String,
immediateCheck: truthProp, immediateCheck: truthProp,
direction: {
type: String as PropType<ListDirection>,
default: 'down',
},
}; };
export type ListProps = ExtractPropTypes<typeof props>; export type ListProps = ExtractPropTypes<typeof props>;

View File

@ -1,9 +1,10 @@
import { computed, PropType, defineComponent } from 'vue'; import { computed, defineComponent } from 'vue';
import { import {
extend, extend,
addUnit, addUnit,
numericProp, numericProp,
getSizeStyle, getSizeStyle,
makeStringProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
@ -26,14 +27,11 @@ export default defineComponent({
props: { props: {
size: numericProp, size: numericProp,
type: makeStringProp<LoadingType>('circular'),
color: String, color: String,
vertical: Boolean, vertical: Boolean,
textSize: numericProp, textSize: numericProp,
textColor: String, textColor: String,
type: {
type: String as PropType<LoadingType>,
default: 'circular',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -1,5 +1,11 @@
import { PropType, defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { extend, numericProp, unknownProp, createNamespace } from '../utils'; import {
extend,
numericProp,
unknownProp,
makeStringProp,
createNamespace,
} from '../utils';
import { Popup } from '../popup'; import { Popup } from '../popup';
import { popupSharedProps } from '../popup/shared'; import { popupSharedProps } from '../popup/shared';
import type { NotifyType } from './types'; import type { NotifyType } from './types';
@ -10,15 +16,12 @@ export default defineComponent({
name, name,
props: extend({}, popupSharedProps, { props: extend({}, popupSharedProps, {
type: makeStringProp<NotifyType>('danger'),
color: String, color: String,
message: numericProp, message: numericProp,
className: unknownProp, className: unknownProp,
background: String, background: String,
lockScroll: Boolean, lockScroll: Boolean,
type: {
type: String as PropType<NotifyType>,
default: 'danger',
},
}), }),
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -15,9 +15,10 @@ import {
truthProp, truthProp,
numericProp, numericProp,
getZIndexStyle, getZIndexStyle,
makeStringProp,
makeNumericProp,
stopPropagation, stopPropagation,
createNamespace, createNamespace,
makeNumericProp,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -43,9 +44,11 @@ export default defineComponent({
props: { props: {
show: Boolean, show: Boolean,
title: String, title: String,
theme: makeStringProp<NumberKeyboardTheme>('default'),
zIndex: numericProp, zIndex: numericProp,
teleport: [String, Object] as PropType<TeleportProps['to']>, teleport: [String, Object] as PropType<TeleportProps['to']>,
maxlength: makeNumericProp(Number.MAX_VALUE), maxlength: makeNumericProp(Number.MAX_VALUE),
modelValue: makeStringProp(''),
transition: truthProp, transition: truthProp,
blurOnClose: truthProp, blurOnClose: truthProp,
showDeleteKey: truthProp, showDeleteKey: truthProp,
@ -55,14 +58,6 @@ export default defineComponent({
closeButtonLoading: Boolean, closeButtonLoading: Boolean,
hideOnClickOutside: truthProp, hideOnClickOutside: truthProp,
safeAreaInsetBottom: truthProp, safeAreaInsetBottom: truthProp,
theme: {
type: String as PropType<NumberKeyboardTheme>,
default: 'default',
},
modelValue: {
type: String,
default: '',
},
extraKey: { extraKey: {
type: [String, Array] as PropType<string | string[]>, type: [String, Array] as PropType<string | string[]>,
default: '', default: '',

View File

@ -1,5 +1,10 @@
import { computed, watch, PropType, defineComponent } from 'vue'; import { computed, watch, defineComponent } from 'vue';
import { BORDER, makeNumericProp, createNamespace } from '../utils'; import {
BORDER,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
const [name, bem, t] = createNamespace('pagination'); const [name, bem, t] = createNamespace('pagination');
@ -21,6 +26,7 @@ export default defineComponent({
name, name,
props: { props: {
mode: makeStringProp<PaginationMode>('multi'),
prevText: String, prevText: String,
nextText: String, nextText: String,
pageCount: makeNumericProp(0), pageCount: makeNumericProp(0),
@ -28,10 +34,6 @@ export default defineComponent({
showPageSize: makeNumericProp(5), showPageSize: makeNumericProp(5),
itemsPerPage: makeNumericProp(10), itemsPerPage: makeNumericProp(10),
forceEllipses: Boolean, forceEllipses: Boolean,
mode: {
type: String as PropType<PaginationMode>,
default: 'multi',
},
modelValue: { modelValue: {
type: Number, type: Number,
default: 0, default: 0,

View File

@ -4,6 +4,7 @@ import {
truthProp, truthProp,
numericProp, numericProp,
BORDER_LEFT, BORDER_LEFT,
makeStringProp,
BORDER_SURROUND, BORDER_SURROUND,
createNamespace, createNamespace,
makeNumericProp, makeNumericProp,
@ -17,14 +18,11 @@ export default defineComponent({
props: { props: {
info: String, info: String,
mask: truthProp, mask: truthProp,
value: makeStringProp(''),
gutter: numericProp, gutter: numericProp,
length: makeNumericProp(6), length: makeNumericProp(6),
focused: Boolean, focused: Boolean,
errorInfo: String, errorInfo: String,
value: {
type: String,
default: '',
},
}, },
emits: ['focus'], emits: ['focus'],

View File

@ -13,6 +13,7 @@ import {
unitToPx, unitToPx,
truthProp, truthProp,
preventDefault, preventDefault,
makeStringProp,
createNamespace, createNamespace,
makeNumericProp, makeNumericProp,
BORDER_UNSET_TOP_BOTTOM, BORDER_UNSET_TOP_BOTTOM,
@ -61,15 +62,12 @@ export default defineComponent({
// should be removed in next major version // should be removed in next major version
valueKey: String, valueKey: String,
defaultIndex: makeNumericProp(0), defaultIndex: makeNumericProp(0),
toolbarPosition: makeStringProp<PickerToolbarPosition>('top'),
columnsFieldNames: Object as PropType<PickerFieldNames>, columnsFieldNames: Object as PropType<PickerFieldNames>,
columns: { columns: {
type: Array as PropType<PickerOption[] | PickerColumn[]>, type: Array as PropType<PickerOption[] | PickerColumn[]>,
default: () => [], default: () => [],
}, },
toolbarPosition: {
type: String as PropType<PickerToolbarPosition>,
default: 'top',
},
}), }),
emits: ['confirm', 'cancel', 'change'], emits: ['confirm', 'cancel', 'change'],

View File

@ -19,6 +19,7 @@ import {
numericProp, numericProp,
unknownProp, unknownProp,
BORDER_BOTTOM, BORDER_BOTTOM,
makeStringProp,
createNamespace, createNamespace,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
@ -72,8 +73,11 @@ export default defineComponent({
props: { props: {
show: Boolean, show: Boolean,
theme: makeStringProp<PopoverTheme>('light'),
overlay: Boolean, overlay: Boolean,
trigger: makeStringProp<PopoverTrigger>('click'),
duration: numericProp, duration: numericProp,
placement: makeStringProp<PopoverPlacement>('bottom'),
iconPrefix: String, iconPrefix: String,
overlayClass: unknownProp, overlayClass: unknownProp,
overlayStyle: Object as PropType<CSSProperties>, overlayStyle: Object as PropType<CSSProperties>,
@ -84,22 +88,10 @@ export default defineComponent({
type: Array as unknown as PropType<[number, number]>, type: Array as unknown as PropType<[number, number]>,
default: () => [0, 8], default: () => [0, 8],
}, },
theme: {
type: String as PropType<PopoverTheme>,
default: 'light',
},
trigger: {
type: String as PropType<PopoverTrigger>,
default: 'click',
},
actions: { actions: {
type: Array as PropType<PopoverAction[]>, type: Array as PropType<PopoverAction[]>,
default: () => [], default: () => [],
}, },
placement: {
type: String as PropType<PopoverPlacement>,
default: 'bottom',
},
teleport: { teleport: {
type: [String, Object] as PropType<TeleportProps['to']>, type: [String, Object] as PropType<TeleportProps['to']>,
default: 'body', default: 'body',

View File

@ -4,7 +4,6 @@ import {
provide, provide,
Teleport, Teleport,
computed, computed,
PropType,
onMounted, onMounted,
Transition, Transition,
onActivated, onActivated,
@ -15,7 +14,13 @@ import {
// Utils // Utils
import { popupSharedProps } from './shared'; import { popupSharedProps } from './shared';
import { extend, isDef, callInterceptor, createNamespace } from '../utils'; import {
isDef,
extend,
makeStringProp,
callInterceptor,
createNamespace,
} from '../utils';
// Composables // Composables
import { useEventListener } from '@vant/use'; import { useEventListener } from '@vant/use';
@ -47,23 +52,14 @@ export default defineComponent({
props: extend({}, popupSharedProps, { props: extend({}, popupSharedProps, {
round: Boolean, round: Boolean,
position: makeStringProp<PopupPosition>('center'),
closeIcon: makeStringProp('cross'),
closeable: Boolean, closeable: Boolean,
transition: String, transition: String,
iconPrefix: String, iconPrefix: String,
closeOnPopstate: Boolean, closeOnPopstate: Boolean,
closeIconPosition: makeStringProp<PopupCloseIconPosition>('top-right'),
safeAreaInsetBottom: Boolean, safeAreaInsetBottom: Boolean,
position: {
type: String as PropType<PopupPosition>,
default: 'center',
},
closeIcon: {
type: String,
default: 'cross',
},
closeIconPosition: {
type: String as PropType<PopupCloseIconPosition>,
default: 'top-right',
},
}), }),
emits: [ emits: [

View File

@ -6,8 +6,9 @@ import {
truthProp, truthProp,
numericProp, numericProp,
preventDefault, preventDefault,
createNamespace, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -57,11 +58,13 @@ export default defineComponent({
props: { props: {
size: numericProp, size: numericProp,
icon: makeStringProp('star'),
color: String, color: String,
count: makeNumericProp(5), count: makeNumericProp(5),
gutter: numericProp, gutter: numericProp,
readonly: Boolean, readonly: Boolean,
disabled: Boolean, disabled: Boolean,
voidIcon: makeStringProp('star-o'),
allowHalf: Boolean, allowHalf: Boolean,
voidColor: String, voidColor: String,
touchable: truthProp, touchable: truthProp,
@ -71,14 +74,6 @@ export default defineComponent({
type: Number, type: Number,
default: 0, default: 0,
}, },
icon: {
type: String,
default: 'star',
},
voidIcon: {
type: String,
default: 'star-o',
},
}, },
emits: ['change', 'update:modelValue'], emits: ['change', 'update:modelValue'],

View File

@ -5,7 +5,12 @@ import {
InjectionKey, InjectionKey,
defineComponent, defineComponent,
} from 'vue'; } from 'vue';
import { truthProp, makeNumericProp, createNamespace } from '../utils'; import {
truthProp,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
const [name, bem] = createNamespace('row'); const [name, bem] = createNamespace('row');
@ -31,14 +36,11 @@ export default defineComponent({
name, name,
props: { props: {
tag: makeStringProp<keyof HTMLElementTagNameMap>('div'),
wrap: truthProp, wrap: truthProp,
align: String as PropType<RowAlign>, align: String as PropType<RowAlign>,
gutter: makeNumericProp(0), gutter: makeNumericProp(0),
justify: String as PropType<RowJustify>, justify: String as PropType<RowJustify>,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'div',
},
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -1,4 +1,4 @@
import { ref, PropType, defineComponent, ExtractPropTypes } from 'vue'; import { ref, defineComponent, ExtractPropTypes } from 'vue';
// Utils // Utils
import { import {
@ -6,6 +6,7 @@ import {
extend, extend,
truthProp, truthProp,
preventDefault, preventDefault,
makeStringProp,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
import { fieldSharedProps } from '../field/Field'; import { fieldSharedProps } from '../field/Field';
@ -23,18 +24,12 @@ const [name, bem, t] = createNamespace('search');
const props = extend({}, fieldSharedProps, { const props = extend({}, fieldSharedProps, {
label: String, label: String,
shape: makeStringProp<SearchShape>('square'),
leftIcon: makeStringProp('search'),
clearable: truthProp, clearable: truthProp,
actionText: String, actionText: String,
background: String, background: String,
showAction: Boolean, showAction: Boolean,
shape: {
type: String as PropType<SearchShape>,
default: 'square',
},
leftIcon: {
type: String,
default: 'search',
},
}); });
export type SearchProps = ExtractPropTypes<typeof props>; export type SearchProps = ExtractPropTypes<typeof props>;

View File

@ -4,14 +4,17 @@ import {
truthProp, truthProp,
numericProp, numericProp,
getSizeStyle, getSizeStyle,
createNamespace, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace,
} from '../utils'; } from '../utils';
const [name, bem] = createNamespace('skeleton'); const [name, bem] = createNamespace('skeleton');
const DEFAULT_ROW_WIDTH = '100%'; const DEFAULT_ROW_WIDTH = '100%';
const DEFAULT_LAST_ROW_WIDTH = '60%'; const DEFAULT_LAST_ROW_WIDTH = '60%';
export type SkeletonAvatarShape = 'square' | 'round';
export default defineComponent({ export default defineComponent({
name, name,
@ -24,10 +27,7 @@ export default defineComponent({
animate: truthProp, animate: truthProp,
avatarSize: numericProp, avatarSize: numericProp,
titleWidth: numericProp, titleWidth: numericProp,
avatarShape: { avatarShape: makeStringProp<SkeletonAvatarShape>('round'),
type: String as PropType<'square' | 'round'>,
default: 'round',
},
rowWidth: { rowWidth: {
type: [Number, String, Array] as PropType< type: [Number, String, Array] as PropType<
number | string | (number | string)[] number | string | (number | string)[]

View File

@ -1,5 +1,5 @@
import { PropType, defineComponent, ExtractPropTypes, InjectionKey } from 'vue'; import { defineComponent, ExtractPropTypes, InjectionKey } from 'vue';
import { makeNumericProp, createNamespace } from '../utils'; import { makeStringProp, makeNumericProp, createNamespace } from '../utils';
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
const [name, bem] = createNamespace('steps'); const [name, bem] = createNamespace('steps');
@ -8,19 +8,13 @@ export type StepsDirection = 'horizontal' | 'vertical';
const props = { const props = {
active: makeNumericProp(0), active: makeNumericProp(0),
direction: makeStringProp<StepsDirection>('horizontal'),
activeIcon: makeStringProp('checked'),
iconPrefix: String, iconPrefix: String,
finishIcon: String, finishIcon: String,
activeColor: String, activeColor: String,
inactiveIcon: String, inactiveIcon: String,
inactiveColor: String, inactiveColor: String,
direction: {
type: String as PropType<StepsDirection>,
default: 'horizontal',
},
activeIcon: {
type: String,
default: 'checked',
},
}; };
export type StepsProvide = { export type StepsProvide = {

View File

@ -16,8 +16,9 @@ import {
numericProp, numericProp,
getScrollTop, getScrollTop,
getZIndexStyle, getZIndexStyle,
createNamespace, makeStringProp,
makeNumericProp, makeNumericProp,
createNamespace,
} from '../utils'; } from '../utils';
// Composables // Composables
@ -33,13 +34,10 @@ export default defineComponent({
props: { props: {
zIndex: numericProp, zIndex: numericProp,
position: makeStringProp<StickyPosition>('top'),
container: Object as PropType<Element>, container: Object as PropType<Element>,
offsetTop: makeNumericProp(0), offsetTop: makeNumericProp(0),
offsetBottom: makeNumericProp(0), offsetBottom: makeNumericProp(0),
position: {
type: String as PropType<StickyPosition>,
default: 'top',
},
}, },
emits: ['scroll', 'change'], emits: ['scroll', 'change'],

View File

@ -1,5 +1,10 @@
import { PropType, CSSProperties, defineComponent } from 'vue'; import { PropType, CSSProperties, defineComponent } from 'vue';
import { truthProp, makeNumericProp, createNamespace } from '../utils'; import {
truthProp,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -16,21 +21,15 @@ export default defineComponent({
price: Number, price: Number,
tipIcon: String, tipIcon: String,
loading: Boolean, loading: Boolean,
currency: makeStringProp('¥'),
disabled: Boolean, disabled: Boolean,
textAlign: String as PropType<CSSProperties['textAlign']>, textAlign: String as PropType<CSSProperties['textAlign']>,
buttonText: String, buttonText: String,
buttonType: makeStringProp<ButtonType>('danger'),
buttonColor: String, buttonColor: String,
suffixLabel: String, suffixLabel: String,
decimalLength: makeNumericProp(2), decimalLength: makeNumericProp(2),
safeAreaInsetBottom: truthProp, safeAreaInsetBottom: truthProp,
currency: {
type: String,
default: '¥',
},
buttonType: {
type: String as PropType<ButtonType>,
default: 'danger',
},
}, },
emits: ['submit'], emits: ['submit'],

View File

@ -26,6 +26,7 @@ import {
Interceptor, Interceptor,
getVisibleTop, getVisibleTop,
getElementTop, getElementTop,
makeStringProp,
callInterceptor, callInterceptor,
createNamespace, createNamespace,
makeNumericProp, makeNumericProp,
@ -60,6 +61,7 @@ import type { TabsProvide, TabsType } from './types';
const [name, bem] = createNamespace('tabs'); const [name, bem] = createNamespace('tabs');
const props = { const props = {
type: makeStringProp<TabsType>('line'),
color: String, color: String,
border: Boolean, border: Boolean,
sticky: Boolean, sticky: Boolean,
@ -78,10 +80,6 @@ const props = {
swipeThreshold: makeNumericProp(5), swipeThreshold: makeNumericProp(5),
titleActiveColor: String, titleActiveColor: String,
titleInactiveColor: String, titleInactiveColor: String,
type: {
type: String as PropType<TabsType>,
default: 'line',
},
}; };
export type TabsProps = ExtractPropTypes<typeof props>; export type TabsProps = ExtractPropTypes<typeof props>;

View File

@ -1,5 +1,5 @@
import { CSSProperties, PropType, Transition, defineComponent } from 'vue'; import { CSSProperties, Transition, defineComponent } from 'vue';
import { truthProp, createNamespace } from '../utils'; import { truthProp, makeStringProp, createNamespace } from '../utils';
import { Icon } from '../icon'; import { Icon } from '../icon';
const [name, bem] = createNamespace('tag'); const [name, bem] = createNamespace('tag');
@ -13,15 +13,12 @@ export default defineComponent({
size: String, size: String,
mark: Boolean, mark: Boolean,
show: truthProp, show: truthProp,
type: makeStringProp<TagType>('default'),
color: String, color: String,
plain: Boolean, plain: Boolean,
round: Boolean, round: Boolean,
textColor: String, textColor: String,
closeable: Boolean, closeable: Boolean,
type: {
type: String as PropType<TagType>,
default: 'default',
},
}, },
emits: ['close'], emits: ['close'],

View File

@ -8,7 +8,13 @@ import {
} from 'vue'; } from 'vue';
// Utils // Utils
import { isDef, unknownProp, numericProp, createNamespace } from '../utils'; import {
isDef,
unknownProp,
numericProp,
makeStringProp,
createNamespace,
} from '../utils';
import { lockClick } from './lock-click'; import { lockClick } from './lock-click';
// Components // Components
@ -27,33 +33,24 @@ export default defineComponent({
props: { props: {
icon: String, icon: String,
show: Boolean, show: Boolean,
type: makeStringProp<ToastType>('text'),
overlay: Boolean, overlay: Boolean,
message: numericProp, message: numericProp,
iconSize: numericProp, iconSize: numericProp,
position: makeStringProp<ToastPosition>('middle'),
className: unknownProp, className: unknownProp,
iconPrefix: String, iconPrefix: String,
transition: makeStringProp('van-fade'),
loadingType: String as PropType<LoadingType>, loadingType: String as PropType<LoadingType>,
forbidClick: Boolean, forbidClick: Boolean,
overlayClass: unknownProp, overlayClass: unknownProp,
overlayStyle: Object as PropType<CSSProperties>, overlayStyle: Object as PropType<CSSProperties>,
closeOnClick: Boolean, closeOnClick: Boolean,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
type: {
type: String as PropType<ToastType>,
default: 'text',
},
duration: { duration: {
type: Number, type: Number,
default: 2000, default: 2000,
}, },
position: {
type: String as PropType<ToastPosition>,
default: 'middle',
},
transition: {
type: String,
default: 'van-fade',
},
}, },
emits: ['update:show'], emits: ['update:show'],

View File

@ -1,7 +1,12 @@
import { PropType, defineComponent } from 'vue'; import { PropType, defineComponent } from 'vue';
// Utils // Utils
import { addUnit, createNamespace, makeNumericProp } from '../utils'; import {
addUnit,
makeStringProp,
makeNumericProp,
createNamespace,
} from '../utils';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -31,6 +36,7 @@ export default defineComponent({
props: { props: {
max: makeNumericProp(Infinity), max: makeNumericProp(Infinity),
height: makeNumericProp(300), height: makeNumericProp(300),
selectedIcon: makeStringProp('success'),
mainActiveIndex: makeNumericProp(0), mainActiveIndex: makeNumericProp(0),
items: { items: {
type: Array as PropType<TreeSelectItem[]>, type: Array as PropType<TreeSelectItem[]>,
@ -42,10 +48,6 @@ export default defineComponent({
>, >,
default: 0, default: 0,
}, },
selectedIcon: {
type: String,
default: 'success',
},
}, },
emits: [ emits: [

View File

@ -15,6 +15,7 @@ import {
numericProp, numericProp,
Interceptor, Interceptor,
getSizeStyle, getSizeStyle,
makeStringProp,
makeNumericProp, makeNumericProp,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
@ -50,12 +51,16 @@ import type {
const props = { const props = {
name: makeNumericProp(''), name: makeNumericProp(''),
accept: makeStringProp('image/*'),
capture: String, capture: String,
multiple: Boolean, multiple: Boolean,
disabled: Boolean, disabled: Boolean,
readonly: Boolean, readonly: Boolean,
lazyLoad: Boolean, lazyLoad: Boolean,
maxCount: makeNumericProp(Number.MAX_VALUE), maxCount: makeNumericProp(Number.MAX_VALUE),
imageFit: makeStringProp<ImageFit>('cover'),
resultType: makeStringProp<UploaderResultType>('dataUrl'),
uploadIcon: makeStringProp('photograph'),
uploadText: String, uploadText: String,
deletable: truthProp, deletable: truthProp,
afterRead: Function as PropType<UploaderAfterRead>, afterRead: Function as PropType<UploaderAfterRead>,
@ -66,10 +71,6 @@ const props = {
previewImage: truthProp, previewImage: truthProp,
previewOptions: Object as PropType<ImagePreviewOptions>, previewOptions: Object as PropType<ImagePreviewOptions>,
previewFullImage: truthProp, previewFullImage: truthProp,
accept: {
type: String,
default: 'image/*',
},
modelValue: { modelValue: {
type: Array as PropType<UploaderFileListItem[]>, type: Array as PropType<UploaderFileListItem[]>,
default: () => [], default: () => [],
@ -78,18 +79,6 @@ const props = {
type: [Number, String, Function] as PropType<UploaderMaxSize>, type: [Number, String, Function] as PropType<UploaderMaxSize>,
default: Number.MAX_VALUE, default: Number.MAX_VALUE,
}, },
imageFit: {
type: String as PropType<ImageFit>,
default: 'cover',
},
resultType: {
type: String as PropType<UploaderResultType>,
default: 'dataUrl',
},
uploadIcon: {
type: String,
default: 'photograph',
},
}; };
export type UploaderProps = ExtractPropTypes<typeof props>; export type UploaderProps = ExtractPropTypes<typeof props>;

View File

@ -15,7 +15,11 @@ export const truthProp = {
default: true as const, default: true as const,
}; };
export const makeNumericProp = <T>(defaultVal: T) => ({ export const makeNumericProp = <T>(defaultVal: T) => ({
type: [Number, String], type: numericProp,
default: defaultVal,
});
export const makeStringProp = <T>(defaultVal: T) => ({
type: String as unknown as PropType<T>,
default: defaultVal, default: defaultVal,
}); });