Lib: Allow to manually enable :hover on Button
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@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);
|
||||||
|
}
|
||||||
|
@ -1,22 +1,44 @@
|
|||||||
<script lang="ts">
|
<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 {
|
let {
|
||||||
children,
|
children,
|
||||||
color,
|
color = undefined,
|
||||||
submit = false,
|
submit = false,
|
||||||
href = undefined,
|
href = undefined,
|
||||||
fullwidth = false,
|
fullwidth = false,
|
||||||
|
activate_href = false,
|
||||||
|
activate_button = false,
|
||||||
...restProps
|
...restProps
|
||||||
} = $props();
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if href}
|
{#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()}
|
{@render children()}
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<button
|
<button
|
||||||
type={submit ? "submit" : "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}
|
{...restProps}
|
||||||
>
|
>
|
||||||
{@render children()}
|
{@render children()}
|
||||||
|
Reference in New Issue
Block a user