props.ts 1012 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import type { PropType } from 'vue'
  2. export const unknownProp = null as unknown as PropType<unknown>
  3. export const numericProp = [Number, String]
  4. export const truthProp = {
  5. type: Boolean,
  6. default: true as const
  7. }
  8. export const makeRequiredProp = <T>(type: T) => ({
  9. type,
  10. required: true as const
  11. })
  12. export const makeArrayProp = <T>() => ({
  13. type: Array as PropType<T[]>,
  14. default: () => []
  15. })
  16. export const makeBooleanProp = <T>(defaultVal: T) => ({
  17. type: Boolean,
  18. default: defaultVal
  19. })
  20. export const makeNumberProp = <T>(defaultVal: T) => ({
  21. type: Number,
  22. default: defaultVal
  23. })
  24. export const makeNumericProp = <T>(defaultVal: T) => ({
  25. type: numericProp,
  26. default: defaultVal
  27. })
  28. export const makeStringProp = <T>(defaultVal: T) => ({
  29. type: String as unknown as PropType<T>,
  30. default: defaultVal
  31. })
  32. export const baseProps = {
  33. /**
  34. * 自定义根节点样式
  35. */
  36. customStyle: makeStringProp(''),
  37. /**
  38. * 自定义根节点样式类
  39. */
  40. customClass: makeStringProp('')
  41. }