input.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { buildProps, definePropType } from '@kankan/utils'
  2. import { checkboxInputProps } from './checkbox/checkbox'
  3. import { checkRadioProps } from './checkRadio/checkRadio'
  4. import { fileProps } from './file/file'
  5. import { radioProps } from './radio/radio'
  6. import { numberProps } from './number/number'
  7. import { rangProps } from './range/range'
  8. import { richTextProps } from './richtext/richtext'
  9. import { searchProps } from './search/search'
  10. import { selectProps } from './select/select'
  11. import { switchProps } from './switch/switch'
  12. import { textInputProps } from './text/text'
  13. import { textareaProps } from './textarea/textarea'
  14. import radio from './radio/radio.vue'
  15. import * as UISwitch from './switch/switch.vue'
  16. import text from './text/text.vue'
  17. import checkbox from './checkbox/checkbox.vue'
  18. import select from './select/select.vue'
  19. import range from './range/range.vue'
  20. import textarea from './textarea/textarea.vue'
  21. import number from './number/number.vue'
  22. import file from './file/file.vue'
  23. import search from './search/search.vue'
  24. import richtext from './richtext/richtext.vue'
  25. import type { ExtractPropTypes, VNode } from 'vue'
  26. export type InputType = 'checkbox' | 'text' | 'select' | 'radio' | 'range' | 'number' | 'switch' | 'textarea' | 'search' | 'richtext' | 'file'
  27. // import type { PropType } from 'vue'
  28. export const inputProps = buildProps({
  29. ...checkboxInputProps,
  30. ...checkRadioProps,
  31. ...radioProps,
  32. ...fileProps,
  33. ...numberProps,
  34. ...rangProps,
  35. ...richTextProps,
  36. ...searchProps,
  37. ...selectProps,
  38. ...switchProps,
  39. ...textInputProps,
  40. ...textareaProps,
  41. type: {
  42. type: definePropType<InputType>(String),
  43. },
  44. })
  45. export type InputProps = ExtractPropTypes<typeof inputProps>
  46. type InputComponentsType = {
  47. [propsName in InputType]: InputComponentsPropType
  48. }
  49. interface InputComponentsPropType {
  50. component: VNode
  51. props: InputProps | unknown
  52. }
  53. export const InputComponents: InputComponentsType = {
  54. radio: {
  55. props: radioProps,
  56. component: radio,
  57. },
  58. text: {
  59. props: textInputProps,
  60. component: text,
  61. },
  62. number: {
  63. props: numberProps,
  64. component: number,
  65. },
  66. checkbox: {
  67. props: checkRadioProps,
  68. component: checkbox,
  69. },
  70. select: {
  71. props: selectProps,
  72. component: select,
  73. },
  74. range: {
  75. props: rangProps,
  76. component: range,
  77. },
  78. switch: {
  79. props: switchProps,
  80. component: UISwitch,
  81. },
  82. textarea: {
  83. props: textareaProps,
  84. component: textarea,
  85. },
  86. search: {
  87. props: searchProps,
  88. component: search,
  89. },
  90. richtext: {
  91. props: richTextProps,
  92. component: richtext,
  93. },
  94. file: {
  95. props: fileProps,
  96. component: file,
  97. },
  98. }
  99. // export type
  100. export * from './checkbox/checkbox'
  101. export * from './richtext/richtext'
  102. export * from './checkRadio/checkRadio'
  103. export * from './file/file'
  104. export * from './radio/radio'