Lib: Allow to manually enable :hover on Button

This commit is contained in:
2024-12-13 14:46:02 +01:00
parent 8060c4971d
commit 5d1ec12d95
2 changed files with 32 additions and 3 deletions

View File

@ -1,3 +1,10 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* This class allows to manually simulate the "hover" class */
.btn-hover {
--tw-brightness: brightness(1.15);
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale)
var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

View File

@ -1,22 +1,44 @@
<script lang="ts">
import { page } from "$app/stores";
const is_at_path = (path: string): boolean => {
const pathname: string = $page.url.pathname;
// console.log(pathname);
return pathname === path;
};
let {
children,
color,
color = undefined,
submit = false,
href = undefined,
fullwidth = false,
activate_href = false,
activate_button = false,
...restProps
} = $props();
</script>
{#if href}
<a {href} class="btn p-2 variant-filled-{color} {fullwidth ? 'w-full' : 'w-auto'}" {...restProps}>
<a
{href}
class="select-none {color ? `btn px-2 variant-filled-${color}` : ''} {fullwidth
? 'w-full'
: 'w-auto'}
{activate_href && is_at_path(href) ? 'btn-hover' : ''}"
draggable="false"
{...restProps}
>
{@render children()}
</a>
{:else}
<button
type={submit ? "submit" : "button"}
class="btn p-2 variant-filled-{color} {fullwidth ? 'w-full' : 'w-auto'}"
class="select-none {color ? `btn px-2 variant-filled-${color}` : ''} {fullwidth
? 'w-full'
: 'w-auto'}
{activate_button ? 'btn-hover' : ''}"
draggable="false"
{...restProps}
>
{@render children()}