Commit c1d3a9437106d967a62cd822b35cfd5f933fe2d5

Authored by sedice
Committed by GitHub
1 parent 0eb1275c

refactor: 重构button代码props的引入方式,获取更优雅的类型提示 (#2302)

Co-authored-by: zengqinglong <1107238436@qq.com>
src/components/Button/src/BasicButton.vue
@@ -10,14 +10,15 @@ @@ -10,14 +10,15 @@
10 10
11 <script lang="ts"> 11 <script lang="ts">
12 import { defineComponent } from 'vue'; 12 import { defineComponent } from 'vue';
  13 + import { Button } from 'ant-design-vue';
13 export default defineComponent({ 14 export default defineComponent({
14 name: 'AButton', 15 name: 'AButton',
  16 + extends: Button,
15 inheritAttrs: false, 17 inheritAttrs: false,
16 }); 18 });
17 </script> 19 </script>
18 <script lang="ts" setup> 20 <script lang="ts" setup>
19 import { computed, unref } from 'vue'; 21 import { computed, unref } from 'vue';
20 - import { Button } from 'ant-design-vue';  
21 import Icon from '/@/components/Icon/src/Icon.vue'; 22 import Icon from '/@/components/Icon/src/Icon.vue';
22 import { buttonProps } from './props'; 23 import { buttonProps } from './props';
23 import { useAttrs } from '/@/hooks/core/useAttrs'; 24 import { useAttrs } from '/@/hooks/core/useAttrs';
src/components/Button/src/props.ts
  1 +const validColors = ['error', 'warning', 'success', ''] as const;
  2 +type ButtonColorType = typeof validColors[number];
  3 +
1 export const buttonProps = { 4 export const buttonProps = {
2 - color: { type: String, validator: (v) => ['error', 'warning', 'success', ''].includes(v) }, 5 + color: {
  6 + type: String as PropType<ButtonColorType>,
  7 + validator: (v) => validColors.includes(v),
  8 + default: '',
  9 + },
3 loading: { type: Boolean }, 10 loading: { type: Boolean },
4 disabled: { type: Boolean }, 11 disabled: { type: Boolean },
5 /** 12 /**