forked from immich-app/immich
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): single row of items (immich-app#11729)
* fix(web): single row of items * remove filterBoxWidth * slight size adjustment * rewrite action as component
- Loading branch information
1 parent
75da9f8
commit e0dffa6
Showing
4 changed files
with
68 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
web/src/lib/components/shared-components/single-grid-row.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts"> | ||
let className = ''; | ||
export { className as class }; | ||
export let itemCount = 1; | ||
let container: HTMLElement | undefined; | ||
let contentRect: DOMRectReadOnly | undefined; | ||
const getGridGap = (element: Element) => { | ||
const style = getComputedStyle(element); | ||
return { | ||
columnGap: parsePixels(style.columnGap), | ||
}; | ||
}; | ||
const parsePixels = (style: string) => Number.parseInt(style, 10) || 0; | ||
const getItemCount = (container: HTMLElement, containerWidth: number) => { | ||
if (!container.firstElementChild) { | ||
return 1; | ||
} | ||
const childContentRect = container.firstElementChild.getBoundingClientRect(); | ||
const childWidth = Math.floor(childContentRect.width || Infinity); | ||
const { columnGap } = getGridGap(container); | ||
return Math.floor((containerWidth + columnGap) / (childWidth + columnGap)) || 1; | ||
}; | ||
$: if (container && contentRect) { | ||
itemCount = getItemCount(container, contentRect.width); | ||
} | ||
</script> | ||
|
||
<div class={className} bind:this={container} bind:contentRect> | ||
<slot {itemCount} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters