From df2ec9c06d6ad7c93b3097f871615da6a7785a5a Mon Sep 17 00:00:00 2001 From: winixt Date: Mon, 14 Apr 2025 20:16:02 +0800 Subject: [PATCH 1/2] feat: button icon placement --- components/button/button.tsx | 12 ++++++++---- components/button/style/index.less | 8 +++++++- docs/.vitepress/components/button/icon.vue | 2 +- docs/.vitepress/components/button/index.md | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index 24db91b23..fb8bc78fb 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -4,6 +4,7 @@ import { computed, defineComponent, ref, + watch, } from 'vue'; import { isNil } from 'lodash-es'; import LoadingOutlined from '../icon/LoadingOutlined'; @@ -48,6 +49,10 @@ export const buttonProps = { type: String as PropType, default: 'default', }, + iconPlacement: { + type: String as PropType<'left' | 'right'>, + default: 'left', + }, } as const satisfies ComponentObjectPropsOptions; export type ButtonProps = ExtractPublicPropTypes; @@ -108,12 +113,11 @@ export default defineComponent({ > {props.loading ? ( - + ) - : ( - slots.icon?.() - )} + : props.iconPlacement !== 'right' && {slots.icon?.()} } {slots.default?.()} + {props.iconPlacement === 'right' && {slots.icon?.()} } ); }, diff --git a/components/button/style/index.less b/components/button/style/index.less index eb426311c..9092d30c1 100644 --- a/components/button/style/index.less +++ b/components/button/style/index.less @@ -238,8 +238,14 @@ &-long { width: 100%; } - & > .@{fes-icon-cls} { + &-icon { + display: inline-flex; + align-items: center; margin-right: 4px; + &.is-right { + margin-right: 0; + margin-left: 4px; + } } &-large { diff --git a/docs/.vitepress/components/button/icon.vue b/docs/.vitepress/components/button/icon.vue index a8c42ef62..dd03c69a1 100644 --- a/docs/.vitepress/components/button/icon.vue +++ b/docs/.vitepress/components/button/icon.vue @@ -8,7 +8,7 @@ Default - + Primary diff --git a/docs/.vitepress/components/button/index.md b/docs/.vitepress/components/button/index.md index f0f705d9d..a02074781 100644 --- a/docs/.vitepress/components/button/index.md +++ b/docs/.vitepress/components/button/index.md @@ -41,6 +41,7 @@ long.vue | long | 按钮按钮宽度为父元素宽度 | boolean | `false` | | throttle | 节流 | number | `300` | | type | 设置按钮类型,可选值为 `primary` `text` `link` `info` `success` `warning` `danger` | string | `default` | +| iconPlacement | icon位置,可选值为 `left` `right` | string | `left` | ## Slots From 75452c113a9a06cefcf678f3e041440c292457db Mon Sep 17 00:00:00 2001 From: winixt Date: Mon, 14 Apr 2025 20:18:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/button/button.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index fb8bc78fb..5ed5667f3 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -4,7 +4,6 @@ import { computed, defineComponent, ref, - watch, } from 'vue'; import { isNil } from 'lodash-es'; import LoadingOutlined from '../icon/LoadingOutlined';