Skip to content

Commit

Permalink
feat(button): fixed the icon abnormality caused by setting the size i…
Browse files Browse the repository at this point in the history
…n the loading state
  • Loading branch information
qianmoQ committed Nov 25, 2024
1 parent ba29ece commit 6d4bd4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

Button
</ShadcnButton>
<ShadcnButton circle size="large" loading />
<ShadcnButton round loading>Round</ShadcnButton>
<ShadcnButton size="small" loading>Small</ShadcnButton>
<ShadcnButton size="default" loading>Default</ShadcnButton>
<ShadcnButton size="large" loading>Large</ShadcnButton>
</ShadcnSpace>
</template>

Expand Down
16 changes: 11 additions & 5 deletions src/ui/button/ShadcnButton.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<template>
<component :is="to ? ShadcnLink : 'button'"
v-bind="buttonProps">
<div class="inline-flex items-center justify-center gap-1.5">
<div class="inline-flex items-center justify-center" :class="{'gap-1.5': !circle}">
<!-- Loading State -->
<div v-if="loading" class="mr-1.5">
<div v-if="loading" :class="{'mr-1.5': !circle && (text || $slots.default)}">
<slot name="loading">
<Loader2 class="animate-spin"/>
<Loader2 :class="['animate-spin',
{
'w-3 h-3': finalSize === 'small',
'w-4 h-4': finalSize === 'default',
'w-5 h-5': finalSize === 'large',
}
]"/>
</slot>
</div>

<!-- Icon -->
<slot v-if="!loading && $slots.icon" name="icon"/>

<!-- Text Content -->
<span v-if="text" :class="{'ml-0': !$slots.icon && !loading}">{{ text }}</span>
<slot v-else/>
<span v-if="text && !circle" :class="{'ml-0': !$slots.icon && !loading}">{{ text }}</span>
<slot v-if="!circle"/>
</div>
</component>
</template>
Expand Down

0 comments on commit 6d4bd4f

Please sign in to comment.