Skip to content

Commit

Permalink
fix: corrected scrollbar styles to have proper spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Oct 11, 2024
1 parent 2ea3164 commit 0146978
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 77 deletions.
10 changes: 5 additions & 5 deletions src/components/core/GridImage.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import { AppController } from "@controllers";
import { TriangleExclamation } from "@icons";
import { gridType } from "@stores/AppState";
import { IMAGE_FADE_OPTIONS, SMALL_GRID_DIMENSIONS } from "@utils";
import Lazy from "svelte-lazy";
import { AppController } from "@controllers";
import { TriangleExclamation } from "@icons";
import { gridType } from "@stores/AppState";
import { IMAGE_FADE_OPTIONS, SMALL_GRID_DIMENSIONS } from "@utils";
import Lazy from "svelte-lazy";
export let imagePath: string;
export let altText: string;
Expand Down
9 changes: 5 additions & 4 deletions src/components/core/filters/Options.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script lang="ts">
import { LogController } from "@controllers";
import { scrollShadow } from "@directives";
import { isOverflowing, scrollShadow } from "@directives";
import { Toggle } from "@interactables";
import { Accordion } from "@layout";
import { dbFilters, gridType, optionsSize, theme } from "@stores/AppState";
import { Pane } from "svelte-splitpanes";
import Divider from "../Divider.svelte";
import SectionTitle from "../SectionTitle.svelte";
let overflowing = false;
/**
* Creates a function to update the specified filter.
* @param section The section of the filter to update.
Expand Down Expand Up @@ -64,8 +66,8 @@
</div>

<div class="content" style="height: calc(100% - 85px);">
<div class="scroll-container" use:scrollShadow={{ background: "red"}}>
<div class="wrapper">
<div class="scroll-container" use:scrollShadow={{ background: "red"}} use:isOverflowing={{ callback: (o) => overflowing = o }}>
<div class="wrapper" style:width={overflowing ? "calc(100% - 7px)" : "100%"}>
{#each Object.keys($dbFilters[$gridType]) as section}
<Accordion
label="{section === "oneoftag" ? "Tags" : toUpperCaseSplit(section)}"
Expand Down Expand Up @@ -103,7 +105,6 @@
max-height: calc(100% - 65px)
}
.wrapper {
width: 100%;
display: flex;
flex-direction: column;
gap: 7px;
Expand Down
6 changes: 1 addition & 5 deletions src/components/modals/ToolsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<div class="content">
{#each toolsList as tool}
<IconButton label={tool.name} on:click={tool.onClick} height="auto" width="auto" tooltipPosition="bottom">
<svelte:component this={tool.icon} style="height: 18px; width: 18px; padding: 24px;" />
<svelte:component this={tool.icon} style="height: 18px; width: 18px; padding: 28px;" />
</IconButton>
{/each}
</div>
Expand All @@ -93,9 +93,5 @@
padding-top: 14px;
/* max-height: 73vh; */
overflow-y: scroll;
}
</style>
1 change: 0 additions & 1 deletion src/components/modals/game-search/GameSearchEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
height: 20px;
padding: 3px 7px;
margin-bottom: 7px;
border-radius: 4px;
Expand Down
35 changes: 22 additions & 13 deletions src/components/modals/game-search/GameSearchModal.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { AppController, LogController, ToastController } from "@controllers";
import { scrollShadow } from "@directives";
import { isOverflowing, scrollShadow } from "@directives";
import { Refresh } from "@icons";
import { Button, IconButton, SearchBar } from "@interactables";
import { selectedGameName } from "@stores/AppState";
Expand All @@ -12,6 +12,7 @@
import GameSearchEntry from "./GameSearchEntry.svelte";
let open = true;
let overflowing = false;
let loading = true;
let requestTimedOut = false;
let searchQuery = $gameSearchModalDefault;
Expand Down Expand Up @@ -93,18 +94,20 @@
<SearchBar label="Game Search" bind:value={searchQuery} onChange={async (query) => await makeRequest(query)} width="250px" reversed />
</div>
<div class="container">
<div class="scroll-container" use:scrollShadow={{ background: "--background" }}>
{#if loading}
{#each new Array(10) as _}
<EntryLoadingSkeleton />
{/each}
{:else if requestTimedOut}
<div>Request timed out. Check your internet connection or click retry.</div>
{:else}
{#each results as sgdbGame (sgdbGame.id)}
<GameSearchEntry game={sgdbGame} isSelected={selectedGame ? sgdbGame.id === selectedGame.id : sgdbGame.name === $selectedGameName} onSelect={setSelected} />
{/each}
{/if}
<div class="scroll-container" use:scrollShadow={{ background: "--background" }} use:isOverflowing={{ callback: (o) => overflowing = o }}>
<div class="wrapper" style:width={overflowing ? "calc(100% - 7px)" : "100%"}>
{#if loading}
{#each new Array(10) as _}
<EntryLoadingSkeleton />
{/each}
{:else if requestTimedOut}
<div>Request timed out. Check your internet connection or click retry.</div>
{:else}
{#each results as sgdbGame (sgdbGame.id)}
<GameSearchEntry game={sgdbGame} isSelected={selectedGame ? sgdbGame.id === selectedGame.id : sgdbGame.name === $selectedGameName} onSelect={setSelected} />
{/each}
{/if}
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -164,6 +167,12 @@
margin-bottom: 7px;
}
.wrapper {
display: flex;
flex-direction: column;
gap: 7px;
}
.buttons {
width: 100%;
display: flex;
Expand Down
110 changes: 61 additions & 49 deletions src/components/modals/settings/SettingsModal.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { AppController, DialogController, LogController, ToastController } from "@controllers";
import { isOverflowing } from "@directives";
import { Folder } from "@icons";
import { Button, IconButton } from "@interactables";
import { activeUserId, debugMode, loadingGames, needsSGDBAPIKey, needsSteamKey, steamGridDBKey, steamInstallPath, steamKey, steamUsers } from "@stores/AppState";
Expand All @@ -19,6 +20,7 @@
let usersUnsub: Unsubscriber;
let open = true;
let overflowing = false;
let steamApiKeyChanged = false;
/**
Expand Down Expand Up @@ -193,48 +195,52 @@

<ModalBody title={"Settings"} open={open} on:close={() => open = false} on:closeEnd={onClose}>
<div class="content">
<FilePathEntry
label="Steam Install Path"
description={"The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>/home/deck/.steam/steam</b> on Linux. You must restart after changing this."}
value={steamInstallLocation}
onChange={onInstallLocationChange}
useValidator
validPathMessage={"Path is a valid Steam install"}
validator={validateSteamPath}
required
/>
<TextFieldEntry
label="SteamGrid Api Key"
description={"Needed to load art from SteamGridDB.com. To create one, go to <a href=\"https://www.steamgriddb.com\">Steamgrid</a>, sign in and go to preferences, then API."}
value={steamGridKey}
onChange={onGridKeyChange}
useValidator
validator={validateSGDBAPIKey}
required
/>
<TextFieldEntry
label="Steam Api key"
description={"Used to load your games using Steam's web API (It's much faster). To create one, go to Steam's <a href=\"https://steamcommunity.com/dev/apikey\">key registration</a> page, sign in and create an api key."}
notes={"Recommended for large libraries. It does <b>NOT</b> matter what domain you put in, It just needs to be a valid url. When in doubt do \"http://YOUR_STEAM_USERNAME.com\"."}
value={steamAPIKey}
canBeEmpty
onChange={onSteamKeyChange}
useValidator
validator={validateSteamAPIKey}
/>
<DropdownEntry
label="Steam User"
description="Determines which Steam account to edit grids for."
options={(users && users.length > 0) ? users : [ { label: "Loading...", data: "placeholder" } ]}
value={(users && users.length > 0) ? selectedUserId : "placeholder"}
onChange={(id) => {selectedUserId = id; canSave = true;}}
/>
<ToggleFieldEntry
label="Debug Mode"
description={"Enables the inspect element window and automatically opens it on launch."}
value={debugModeSetting}
onChange={onDebugModeChange}
/>
<div class="scroll-container" use:isOverflowing={{ callback: (o) => overflowing = o }}>
<div class="wrapper" style:width={overflowing ? "calc(100% - 7px)" : "100%"}>
<FilePathEntry
label="Steam Install Path"
description={"The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>/home/deck/.steam/steam</b> on Linux. You must restart after changing this."}
value={steamInstallLocation}
onChange={onInstallLocationChange}
useValidator
validPathMessage={"Path is a valid Steam install"}
validator={validateSteamPath}
required
/>
<TextFieldEntry
label="SteamGrid Api Key"
description={"Needed to load art from SteamGridDB.com. To create one, go to <a href=\"https://www.steamgriddb.com\">Steamgrid</a>, sign in and go to preferences, then API."}
value={steamGridKey}
onChange={onGridKeyChange}
useValidator
validator={validateSGDBAPIKey}
required
/>
<TextFieldEntry
label="Steam Api key"
description={"Used to load your games using Steam's web API (It's much faster). To create one, go to Steam's <a href=\"https://steamcommunity.com/dev/apikey\">key registration</a> page, sign in and create an api key."}
notes={"Recommended for large libraries. It does <b>NOT</b> matter what domain you put in, It just needs to be a valid url. When in doubt do \"http://YOUR_STEAM_USERNAME.com\"."}
value={steamAPIKey}
canBeEmpty
onChange={onSteamKeyChange}
useValidator
validator={validateSteamAPIKey}
/>
<DropdownEntry
label="Steam User"
description="Determines which Steam account to edit grids for."
options={(users && users.length > 0) ? users : [ { label: "Loading...", data: "placeholder" } ]}
value={(users && users.length > 0) ? selectedUserId : "placeholder"}
onChange={(id) => {selectedUserId = id; canSave = true;}}
/>
<ToggleFieldEntry
label="Debug Mode"
description={"Enables the inspect element window and automatically opens it on launch."}
value={debugModeSetting}
onChange={onDebugModeChange}
/>
</div>
</div>
</div>

<span slot="buttons" class="buttons">
Expand All @@ -249,18 +255,24 @@
<style>
.content {
width: 600px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 14px;
gap: 14px;
max-height: 73vh;
overflow-y: scroll;
}
.scroll-container {
max-height: calc(73vh - 14px);
width: 100%;
overflow-y: scroll;
}
.wrapper {
display: flex;
flex-direction: column;
gap: 14px;
}
.buttons {
width: 100%;
display: flex;
Expand Down
50 changes: 50 additions & 0 deletions src/lib/directives/IsOverflowing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Action } from "svelte/action";
import { writable } from "svelte/store";

type IsOverflowingParams = {
callback: (isOverflowing: boolean) => void;
}

/**
* A Svelte directive for detecting when an element is overflowing..
*/
export const isOverflowing: Action<HTMLElement, IsOverflowingParams | undefined> = (node: HTMLElement, props = { callback: (isOverflowing: boolean) => {} }) => {
let callback = props.callback;

const isOverflowing = writable(false);
const isOverflowingUnsub = isOverflowing.subscribe((isOverflowing: boolean) => {
callback(isOverflowing);
});

const observer = new ResizeObserver((entries: ResizeObserverEntry[]) => {
const element = entries[0].target;

const overflowingTop = element.scrollTop !== 0;
const overflowingBottom = Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) > 0;
isOverflowing.set(overflowingTop || overflowingBottom);
});

node.addEventListener("scroll", scrollHandler);
observer.observe(node);


function scrollHandler(e: Event) {
const element = e.currentTarget as HTMLDivElement;

const overflowingTop = element.scrollTop !== 0;
const overflowingBottom = Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) > 0;
isOverflowing.set(overflowingTop || overflowingBottom);
}

return {
update(props = { callback: (isOverflowing: boolean) => {} }) {
callback = props.callback;
},
destroy() {
node.removeEventListener("scroll", scrollHandler);
observer.disconnect();

isOverflowingUnsub();
}
}
}
2 changes: 2 additions & 0 deletions src/lib/directives/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./IsOverflowing";
export * from "./ScrollShadow";

0 comments on commit 0146978

Please sign in to comment.