design: add a subtle scale animation to buttons
This commit is contained in:
1 parent
30c25bab22
commit
88e9a91c60
3 files changed
+49
-19
No files matched your search
@@ -131,13 +131,14 @@
|
||||
/>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
size="custom"
|
||||
href={postLink(post.post)}
|
||||
class="!text-inherit h-full px-3 relative"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
|
||||
title={$t('post.actions.comments')}
|
||||
animations={{ scale: true, large: false }}
|
||||
>
|
||||
{@const newComment =
|
||||
publishedToDate(post.counts.newest_comment_time).getTime() >
|
||||
@@ -163,6 +164,7 @@
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon src={BugAnt} micro size="16" slot="prefix" />
|
||||
</Button>
|
||||
@@ -193,6 +195,7 @@
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon
|
||||
src={post.saved ? BookmarkSlash : Bookmark}
|
||||
@@ -217,6 +220,7 @@
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
|
||||
</Button>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
{href}
|
||||
on:click
|
||||
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-slate-600 dark:text-zinc-400'} {$$props.class}"
|
||||
>
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
export type ButtonShadow = keyof typeof buttonShadow
|
||||
|
||||
export const buttonAlignment = {
|
||||
left: 'justify-start text-left',
|
||||
center: 'justify-center text-center',
|
||||
right: 'justify-end text-right',
|
||||
left: 'justify-start text-left origin-left',
|
||||
center: 'justify-center text-center origin-center',
|
||||
right: 'justify-end text-right origin-right',
|
||||
}
|
||||
|
||||
export const buttonColor = {
|
||||
@@ -121,6 +121,10 @@
|
||||
export let alignment: ButtonAlignment = 'center'
|
||||
export let shadow: ButtonShadow = 'none'
|
||||
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
|
||||
|
||||
@@ -139,30 +143,30 @@
|
||||
on:dragstart
|
||||
on:dragend
|
||||
class="
|
||||
{buttonColor[color]}
|
||||
{loading ? buttonColor.secondary : buttonColor[color]}
|
||||
{buttonSize[size]}
|
||||
{buttonRounding[rounding][roundingSide]}
|
||||
{buttonShadow[shadow]}
|
||||
text-sm transition-all disabled:!opacity-70 disabled:!pointer-events-none
|
||||
disabled:!border disabled:!border-slate-300 disabled:!bg-slate-200
|
||||
disabled:dark:!border-zinc-700 disabled:dark:!bg-zinc-800 disabled:text-inherit
|
||||
font-medium cursor-pointer
|
||||
{$$props.class}
|
||||
{loading
|
||||
? color == 'primary'
|
||||
? '!bg-transparent !text-inherit'
|
||||
: ''
|
||||
: ''}"
|
||||
text-sm transition-all font-medium cursor-pointer duration-100
|
||||
{alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
? 'origin-left'
|
||||
: 'origin-right'}
|
||||
{$$props.class}"
|
||||
class:button-scale={animations.scale}
|
||||
class:anim-large={animations.large}
|
||||
type={submit ? 'submit' : 'button'}
|
||||
>
|
||||
<div
|
||||
class="flex {column
|
||||
? '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}
|
||||
<Spinner width={loaderWidth ?? 16}
|
||||
/>
|
||||
<Spinner width={loaderWidth ?? 16} />
|
||||
{:else if $$slots.prefix}
|
||||
<slot name="prefix" />
|
||||
{/if}
|
||||
@@ -177,3 +181,25 @@
|
||||
@slot `prefix` -- Will be replaced if `loading` is `true`.
|
||||
@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>
|
||||
Reference in new issue
Block a user