/** * prop type helpers * help us to write less code and reduce bundle size * copy from https://github.com/youzan/vant/blob/main/packages/vant/src/utils/props.ts */ import type { ExtractPropTypes, PropType, StyleValue } from 'vue' export const unknownProp = null as unknown as PropType export const numericProp = [Number, String] export const truthProp = { type: Boolean, default: true as const, } export const nullableBooleanProp = { type: Boolean as PropType, default: undefined, } export function makeRequiredProp(type: T) { return { type, required: true as const, } } export function makeArrayProp(defaultVal: T[] = []) { return { type: Array as PropType, default: () => defaultVal, } } export function makeObjectProp(defaultVal: T) { return { type: Object as PropType, default: () => defaultVal, } } export function makeNumberProp(defaultVal: T) { return { type: Number, default: defaultVal, } } export function makeNumericProp(defaultVal: T) { return { type: numericProp, default: defaultVal, } } export function makeStringProp(defaultVal: T) { return { type: String as unknown as PropType, default: defaultVal, } } export type ClassType = string | object | Array export const commonProps = { /** * @description 自定义类名 */ customClass: { type: [String, Object, Array] as PropType, default: '', }, /** * @description 自定义样式 */ customStyle: { type: [String, Object, Array] as PropType, default: '', }, } export type CommonProps = ExtractPropTypes