style(ui): genre button variants and dropdown alignment
- Add 'control' variant for Favorites style matching other dropdowns - Add 'align' prop: 'left' (Home) or 'right' (Favorites) - FavoritesView uses control variant with right alignment - Control variant shows "Genre: X" with chevron icon
This commit is contained in:
1 parent
2c886fae7a
commit
befe36ce30
3 files changed
+85
-22
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { SlidersHorizontal } from 'lucide-svelte';
|
||||
import { SlidersHorizontal, ChevronDown } from 'lucide-svelte';
|
||||
import GenreFilterPopup from './GenreFilterPopup.svelte';
|
||||
import {
|
||||
hasActiveFilter,
|
||||
@@ -13,12 +13,17 @@
|
||||
type GenreFilterContext
|
||||
} from '$lib/stores/genreFilterStore';
|
||||
|
||||
type ButtonVariant = 'default' | 'control';
|
||||
type DropdownAlign = 'left' | 'right';
|
||||
|
||||
interface Props {
|
||||
onFilterChange?: () => void;
|
||||
context?: GenreFilterContext;
|
||||
variant?: ButtonVariant;
|
||||
align?: DropdownAlign;
|
||||
}
|
||||
|
||||
let { onFilterChange, context = 'home' }: Props = $props();
|
||||
let { onFilterChange, context = 'home', variant = 'default', align = 'left' }: Props = $props();
|
||||
|
||||
let isOpen = $state(false);
|
||||
let buttonEl: HTMLButtonElement | null = null;
|
||||
@@ -69,24 +74,44 @@
|
||||
</script>
|
||||
|
||||
<div class="genre-filter-wrapper">
|
||||
<button
|
||||
class="genre-filter-btn"
|
||||
class:active={hasFilter}
|
||||
bind:this={buttonEl}
|
||||
onclick={togglePopup}
|
||||
type="button"
|
||||
>
|
||||
<SlidersHorizontal size={14} />
|
||||
{#if selectedGenreName}
|
||||
<span class="filter-label">{selectedGenreName}</span>
|
||||
{:else}
|
||||
<span class="filter-label">Filter by genre</span>
|
||||
{/if}
|
||||
</button>
|
||||
{#if variant === 'control'}
|
||||
<button
|
||||
class="control-btn"
|
||||
class:active={hasFilter}
|
||||
bind:this={buttonEl}
|
||||
onclick={togglePopup}
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
{#if selectedGenreName}
|
||||
Genre: {selectedGenreName}
|
||||
{:else}
|
||||
Genre: All
|
||||
{/if}
|
||||
</span>
|
||||
<ChevronDown size={14} />
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
class="genre-filter-btn"
|
||||
class:active={hasFilter}
|
||||
bind:this={buttonEl}
|
||||
onclick={togglePopup}
|
||||
type="button"
|
||||
>
|
||||
<SlidersHorizontal size={14} />
|
||||
{#if selectedGenreName}
|
||||
<span class="filter-label">{selectedGenreName}</span>
|
||||
{:else}
|
||||
<span class="filter-label">Filter by genre</span>
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<GenreFilterPopup
|
||||
{isOpen}
|
||||
{context}
|
||||
{align}
|
||||
onClose={closePopup}
|
||||
anchorEl={buttonEl}
|
||||
/>
|
||||
@@ -97,6 +122,7 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Default variant (Home style) */
|
||||
.genre-filter-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -134,4 +160,28 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Control variant (Favorites style) */
|
||||
.control-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-subtle);
|
||||
color: var(--text-secondary);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.control-btn.active {
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -15,14 +15,17 @@
|
||||
type GenreFilterContext
|
||||
} from '$lib/stores/genreFilterStore';
|
||||
|
||||
type DropdownAlign = 'left' | 'right';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
anchorEl?: HTMLElement | null;
|
||||
context?: GenreFilterContext;
|
||||
align?: DropdownAlign;
|
||||
}
|
||||
|
||||
let { isOpen, onClose, anchorEl = null, context = 'home' }: Props = $props();
|
||||
let { isOpen, onClose, anchorEl = null, context = 'home', align = 'left' }: Props = $props();
|
||||
|
||||
let genres = $state<GenreInfo[]>([]);
|
||||
let selectedIds = $state<Set<number>>(new Set());
|
||||
@@ -62,12 +65,22 @@
|
||||
const anchorRect = anchorEl.getBoundingClientRect();
|
||||
const popupRect = popupEl.getBoundingClientRect();
|
||||
|
||||
// Align right edge of popup with right edge of anchor (extends to the left)
|
||||
let left = anchorRect.right - popupRect.width;
|
||||
let left: number;
|
||||
let top = anchorRect.bottom + 8;
|
||||
|
||||
// Only adjust left if it goes off the LEFT edge of the screen
|
||||
if (left < 8) left = 8;
|
||||
if (align === 'right') {
|
||||
// Align left edge of popup with left edge of anchor (extends to the right)
|
||||
left = anchorRect.left;
|
||||
// Adjust if it goes off the RIGHT edge
|
||||
if (left + popupRect.width > window.innerWidth - 8) {
|
||||
left = window.innerWidth - popupRect.width - 8;
|
||||
}
|
||||
} else {
|
||||
// Align right edge of popup with right edge of anchor (extends to the left)
|
||||
left = anchorRect.right - popupRect.width;
|
||||
// Only adjust left if it goes off the LEFT edge of the screen
|
||||
if (left < 8) left = 8;
|
||||
}
|
||||
|
||||
// Handle vertical overflow
|
||||
if (top + popupRect.height > window.innerHeight - 8) {
|
||||
|
||||
@@ -1255,7 +1255,7 @@
|
||||
<div class="toolbar">
|
||||
{#if activeTab === 'albums'}
|
||||
<div class="toolbar-controls">
|
||||
<GenreFilterButton context={GENRE_CONTEXT} onFilterChange={handleGenreFilterChange} />
|
||||
<GenreFilterButton context={GENRE_CONTEXT} variant="control" align="right" onFilterChange={handleGenreFilterChange} />
|
||||
<div class="dropdown-container">
|
||||
<button class="control-btn" onclick={() => (showAlbumGroupMenu = !showAlbumGroupMenu)}>
|
||||
<span>
|
||||
|
||||
Reference in new issue
Block a user