From 8b5b7e54bf33bede2142466554eb846364f8d141 Mon Sep 17 00:00:00 2001 From: zcating Date: Tue, 28 Sep 2021 23:01:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(button):=20=E4=BF=AE=E5=A4=8D=20button?= =?UTF-8?q?=20=E5=AE=BF=E4=B8=BB=E5=85=83=E7=B4=A0=E6=9C=AA=E8=83=BD?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E9=BB=98=E8=AE=A4=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9B=E8=A7=84=E8=8C=83=20button=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devui/button/index.ts | 4 +- devui/button/src/button-types.ts | 54 +++++++++++++++++++++++++++ devui/button/src/button.tsx | 63 ++++---------------------------- 3 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 devui/button/src/button-types.ts diff --git a/devui/button/index.ts b/devui/button/index.ts index 3b094c51..c66bf9a3 100644 --- a/devui/button/index.ts +++ b/devui/button/index.ts @@ -1,10 +1,12 @@ import type { App } from 'vue' import Button from './src/button' -Button.install = function(app: App) { +Button.install = function (app: App) { app.component(Button.name, Button) } +export * from './src/button-types'; + export { Button } export default { diff --git a/devui/button/src/button-types.ts b/devui/button/src/button-types.ts new file mode 100644 index 00000000..2c09d2a6 --- /dev/null +++ b/devui/button/src/button-types.ts @@ -0,0 +1,54 @@ +import { ExtractPropTypes, PropType } from 'vue'; + +export type IButtonType = 'button' | 'submit' | 'reset'; +export type IButtonStyle = 'common' | 'primary' | 'text' | 'text-dark' | 'danger'; +export type IButtonPosition = 'left' | 'right' | 'default'; +export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs'; + +export const buttonProps = { + type: { + type: String as PropType, + default: 'button' + }, + btnStyle: { + type: String as PropType, + default: 'primary' + }, + size: { + type: String as PropType, + default: 'md' + }, + position: { + type: String as PropType, + default: 'default' + }, + bordered: { + type: Boolean, + default: false + }, + icon: { + type: String, + default: '' + }, + showLoading: { + type: Boolean, + default: false + }, + width: { + type: String, + }, + disabled: { + type: Boolean, + default: false + }, + autofocus: { + type: Boolean, + default: false + }, + onClick: { + type: Function as PropType<(event: MouseEvent) => void> + } +} as const; + + +export type ButtonProps = ExtractPropTypes; \ No newline at end of file diff --git a/devui/button/src/button.tsx b/devui/button/src/button.tsx index 8c980b53..080db685 100644 --- a/devui/button/src/button.tsx +++ b/devui/button/src/button.tsx @@ -1,59 +1,12 @@ -import { computed, defineComponent, ref, PropType } from 'vue'; +import { computed, defineComponent, ref } from 'vue'; import { Icon } from '../../icon'; - -export type IButtonType = 'button' | 'submit' | 'reset'; -export type IButtonStyle = 'common' | 'primary' | 'text' | 'text-dark' | 'danger'; -export type IButtonPosition = 'left' | 'right' | 'default'; -export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs'; +import { buttonProps } from './button-types'; import './button.scss'; export default defineComponent({ name: 'DButton', - props: { - type: { - type: String as PropType, - default: 'button' - }, - btnStyle: { - type: String as PropType, - default: 'primary' - }, - size: { - type: String as PropType, - default: 'md' - }, - position: { - type: String as PropType, - default: 'default' - }, - bordered: { - type: Boolean, - default: false - }, - icon: { - type: String, - default: '' - }, - showLoading: { - type: Boolean, - default: false - }, - width: { - type: String, - }, - disabled: { - type: Boolean, - default: false - }, - autofocus: { - type: Boolean, - default: false - }, - onClick: { - type: Function as PropType<(event: MouseEvent) => void> - } - }, + props: buttonProps, setup(props, ctx) { const buttonContent = ref(null); @@ -95,22 +48,22 @@ export default defineComponent({ showLoading, width } = props; - const hasIcon = !!icon; return ( -
+