Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shadow on svg element in safari #416

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class="trakt-popup-menu-button"
{...props}
>
<MoreIcon />
<MoreIcon shadowColor="var(--purple-900)" />
</button>

{#if $isOpened}
Expand Down Expand Up @@ -66,13 +66,6 @@

@include popup-button-style();

:global(svg) {
overflow: visible;
:global(circle) {
filter: drop-shadow(0px 0px 2px var(--purple-900));
}
}

&:hover {
background-color: var(--shade-10);
color: var(--purple-900);
Expand Down
38 changes: 35 additions & 3 deletions projects/client/src/lib/components/icons/MoreIcon.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
<script lang="ts">
import { checksum } from "$lib/utils/string/checksum";

type MoreIconProps = {
shadowColor?: string;
};

const { shadowColor }: MoreIconProps = $props();

const filterId = $derived(
shadowColor ? `drop-shadow-${checksum(shadowColor)}` : undefined,
);
</script>

{#snippet circles(filterUrl: string = "")}
<circle cx="8" cy="2" r="2" fill="currentColor" filter={filterUrl} />
<circle cx="8" cy="8" r="2" fill="currentColor" filter={filterUrl} />
<circle cx="8" cy="14" r="2" fill="currentColor" filter={filterUrl} />
{/snippet}

<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
overflow="visible"
>
<circle cx="8" cy="2" r="2" fill="currentColor" />
<circle cx="8" cy="8" r="2" fill="currentColor" />
<circle cx="8" cy="14" r="2" fill="currentColor" />
{#if filterId}
<defs>
<!--
CSS drop shadow filter does not work on SVG elements in Safari,
so we use an SVG filter instead.
-->
<filter id={filterId} x="-100%" y="-100%" width="300%" height="300%">
<feDropShadow dx="0" dy="0" flood-color={shadowColor} />
</filter>
</defs>
{@render circles(`url(#${filterId})`)}
{:else}
{@render circles()}
{/if}
</svg>
Loading