design: add a subtle scale animation to buttons

This commit is contained in:
Xylight committed 2024-10-04 14:42:57 -07:00
1 parent 30c25bab22
commit 88e9a91c60
3 files changed
+49 -19

No files matched your search

@@ -131,13 +131,14 @@
/> />
<Button <Button
size="sm" size="custom"
href={postLink(post.post)} href={postLink(post.post)}
class="!text-inherit h-full px-3 relative" class="!text-inherit h-full px-3 relative"
color="ghost" color="ghost"
rounding="pill" rounding="pill"
target={$userSettings.openLinksInNewTab ? '_blank' : ''} target={$userSettings.openLinksInNewTab ? '_blank' : ''}
title={$t('post.actions.comments')} title={$t('post.actions.comments')}
animations={{ scale: true, large: false }}
> >
{@const newComment = {@const newComment =
publishedToDate(post.counts.newest_comment_time).getTime() > publishedToDate(post.counts.newest_comment_time).getTime() >
@@ -163,6 +164,7 @@
color="ghost" color="ghost"
rounding="pill" rounding="pill"
class={buttonSquare} class={buttonSquare}
animations={{ scale: true, large: true }}
> >
<Icon src={BugAnt} micro size="16" slot="prefix" /> <Icon src={BugAnt} micro size="16" slot="prefix" />
</Button> </Button>
@@ -193,6 +195,7 @@
loading={saving} loading={saving}
disabled={saving} disabled={saving}
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')} title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
animations={{ scale: true, large: true }}
> >
<Icon <Icon
src={post.saved ? BookmarkSlash : Bookmark} src={post.saved ? BookmarkSlash : Bookmark}
@@ -217,6 +220,7 @@
rounding="pill" rounding="pill"
size="custom" size="custom"
class={buttonSquare} class={buttonSquare}
animations={{ scale: true, large: true }}
> >
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro /> <Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
</Button> </Button>
@@ -21,7 +21,7 @@
{href} {href}
on:click on:click
on:contextmenu on:contextmenu
class="font-normal block {selected class="font-normal block !origin-left {selected
? 'text-primary-900 dark:!text-primary-100 bg-slate-100 dark:bg-zinc-800' ? 'text-primary-900 dark:!text-primary-100 bg-slate-100 dark:bg-zinc-800'
: 'text-slate-600 dark:text-zinc-400'} {$$props.class}" : 'text-slate-600 dark:text-zinc-400'} {$$props.class}"
> >
+43 -17
View File
@@ -4,9 +4,9 @@
export type ButtonShadow = keyof typeof buttonShadow export type ButtonShadow = keyof typeof buttonShadow
export const buttonAlignment = { export const buttonAlignment = {
left: 'justify-start text-left', left: 'justify-start text-left origin-left',
center: 'justify-center text-center', center: 'justify-center text-center origin-center',
right: 'justify-end text-right', right: 'justify-end text-right origin-right',
} }
export const buttonColor = { export const buttonColor = {
@@ -121,6 +121,10 @@
export let alignment: ButtonAlignment = 'center' export let alignment: ButtonAlignment = 'center'
export let shadow: ButtonShadow = 'none' export let shadow: ButtonShadow = 'none'
export let column: boolean = false export let column: boolean = false
export let animations = {
scale: size != 'sm',
large: size == 'square-sm' || size == 'square-md' || size == 'square-lg',
}
export let loaderWidth: number | undefined = undefined export let loaderWidth: number | undefined = undefined
@@ -139,30 +143,30 @@
on:dragstart on:dragstart
on:dragend on:dragend
class=" class="
{buttonColor[color]} {loading ? buttonColor.secondary : buttonColor[color]}
{buttonSize[size]} {buttonSize[size]}
{buttonRounding[rounding][roundingSide]} {buttonRounding[rounding][roundingSide]}
{buttonShadow[shadow]} {buttonShadow[shadow]}
text-sm transition-all disabled:!opacity-70 disabled:!pointer-events-none text-sm transition-all font-medium cursor-pointer duration-100
disabled:!border disabled:!border-slate-300 disabled:!bg-slate-200 {alignment == 'center'
disabled:dark:!border-zinc-700 disabled:dark:!bg-zinc-800 disabled:text-inherit ? 'origin-center'
font-medium cursor-pointer : alignment == 'left'
{$$props.class} ? 'origin-left'
{loading : 'origin-right'}
? color == 'primary' {$$props.class}"
? '!bg-transparent !text-inherit' class:button-scale={animations.scale}
: '' class:anim-large={animations.large}
: ''}"
type={submit ? 'submit' : 'button'} type={submit ? 'submit' : 'button'}
> >
<div <div
class="flex {column class="flex {column
? 'flex-col justify-center' ? 'flex-col justify-center'
: 'flex-row items-center'} h-full gap-1.5 {buttonAlignment[alignment]}" : 'flex-row items-center'} h-full gap-1.5 button-content {buttonAlignment[
alignment
]}"
> >
{#if loading} {#if loading}
<Spinner width={loaderWidth ?? 16} <Spinner width={loaderWidth ?? 16} />
/>
{:else if $$slots.prefix} {:else if $$slots.prefix}
<slot name="prefix" /> <slot name="prefix" />
{/if} {/if}
@@ -177,3 +181,25 @@
@slot `prefix` -- Will be replaced if `loading` is `true`. @slot `prefix` -- Will be replaced if `loading` is `true`.
@slot `suffix` @slot `suffix`
--> -->
<style>
.button-scale > .button-content {
transition: transform 500ms cubic-bezier(0.075, 0.82, 0.165, 1);
}
.button-scale.origin-left > .button-content {
transform-origin: left;
}
.button-scale:hover > .button-content {
transform: scale(105%);
}
.anim-large.button-scale:hover > .button-content {
transform: scale(110%);
}
.button-scale:active > .button-content {
transform: scale(95%);
}
.button-scale:active.anim-large > .button-content {
transform: scale(95%);
}
</style>