mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(web): single row of items (#11729)
* fix(web): single row of items * remove filterBoxWidth * slight size adjustment * rewrite action as component
This commit is contained in:
parent
e384692025
commit
5acdc958b6
4 changed files with 68 additions and 49 deletions
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue