-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the selectable button into its own component.
* While adding in that no highligh of the button appears when it is empty the code in the duplicate-asset got quite crowded. I therefore moved the selectable button that holds the metadata into its own component.
- Loading branch information
Showing
2 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
web/src/lib/components/utilities-page/duplicates/duplicate-asset-selection.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,48 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from 'svelte'; | ||
interface Props { | ||
displayedData: any; | ||
isSelected: boolean; | ||
isSelectedEqualOriginal: boolean; | ||
selectedData: any; | ||
slotHeight?: number; | ||
onClick: () => void; | ||
children?: Snippet; | ||
} | ||
let { displayedData, isSelected, isSelectedEqualOriginal, selectedData, slotHeight, onClick, children }: Props = | ||
$props(); | ||
let button = $state<HTMLButtonElement>(); | ||
export function getHeight(): number { | ||
if (button) { | ||
return button.getBoundingClientRect().height; | ||
} | ||
return 0; | ||
} | ||
const getClasses = () => { | ||
let classes = 'rounded-xl'; | ||
if (displayedData) { | ||
classes += ' dark:hover:bg-gray-300'; | ||
classes += isSelected ? ' hover:bg-gray-300' : ' dark:hover:bg-gray-300 hover:bg-gray-500'; | ||
} | ||
if (isSelected && selectedData !== null && !isSelectedEqualOriginal) { | ||
classes += ' bg-red-300/90'; | ||
} | ||
return classes; | ||
}; | ||
</script> | ||
|
||
<button | ||
bind:this={button} | ||
disabled={!displayedData} | ||
type="button" | ||
style="padding: 3px; {slotHeight ? 'height: ' + slotHeight + 'px' : ''}" | ||
class={getClasses()} | ||
onclick={onClick} | ||
> | ||
{@render children?.()} | ||
</button> |
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