feat: focusedChild property for containers

This commit is contained in:
Aleksi Lassila
2024-05-03 22:59:09 +03:00
parent aa1168b6b2
commit 31a442db83
13 changed files with 121 additions and 91 deletions

View File

@@ -4,7 +4,7 @@
import classNames from 'classnames';
import AnimatedSelection from './AnimateScale.svelte';
export let inactive: boolean = false;
export let disabled: boolean = false;
export let focusOnMount: boolean = false;
export let type: 'primary' | 'secondary' = 'primary';
@@ -20,8 +20,8 @@
'selectable bg-secondary-800 px-6': type === 'primary',
'border-2 p-1 hover:border-primary-500': type === 'secondary',
'border-primary-500': type === 'secondary' && $hasFocus,
'cursor-pointer': !inactive,
'cursor-not-allowed pointer-events-none opacity-40': inactive
'cursor-pointer': !disabled,
'cursor-not-allowed pointer-events-none opacity-40': disabled
},
$$restProps.class
)}

View File

@@ -21,7 +21,7 @@
export let rating: number | undefined = undefined;
export let progress = 0;
export let focusable = true;
export let disabled = false;
export let shadow = false;
export let size: 'dynamic' | 'md' | 'lg' | 'sm' = 'md';
export let orientation: 'portrait' | 'landscape' = 'landscape';
@@ -34,7 +34,7 @@
<AnimatedSelection hasFocus={$hasFocus}>
<Container
active={focusable}
{disabled}
on:clickOrSelect={() => {
if (tmdbId || tvdbId) {
navigate(navigateWithType ? `${type}/${tmdbId || tvdbId}` : `${tmdbId || tvdbId}`);

View File

@@ -28,23 +28,23 @@
<Modal {modalId}>
<div class="h-full flex items-center justify-center bg-secondary-950/75">
<div class="bg-secondary-800 rounded-xl max-w-lg p-16">
<div class="text-xl font-semibold tracking-wide mb-2">
<div class="bg-secondary-800 rounded-2xl max-w-lg p-10">
<div class="text-2xl font-semibold tracking-wide mb-2 text-secondary-100">
<slot name="header" />
</div>
<div class="font-medium text-zinc-300 mb-8">
<div class="font-medium text-secondary-300 mb-8">
<slot />
</div>
<Container direction="horizontal" class="flex">
<Button
type="secondary"
inactive={fetching}
disabled={fetching}
on:clickOrSelect={() => handleAction(confirm)}
class="mr-4"
>
Confirm
</Button>
<Button type="secondary" inactive={fetching} on:clickOrSelect={() => handleAction(cancel)}
<Button type="secondary" disabled={fetching} on:clickOrSelect={() => handleAction(cancel)}
>Cancel</Button
>
</Container>

View File

@@ -4,7 +4,7 @@
export let focusOnMount = false;
</script>
<Container class="flex flex-col my-16" canFocusEmpty={false} {focusOnMount}>
<Container class="flex flex-col my-16" {focusOnMount}>
<h1 class="tracking-wide text-2xl font-semibold mb-4">
<slot name="header">Header is missing</slot>
</h1>

View File

@@ -33,7 +33,7 @@
<Button
focusOnMount
on:clickOrSelect={() => handleGrabRelease(release.guid || '', release.indexerId || -1)}
inactive={!!($data || $isFetching || status)}
disabled={!!($data || $isFetching || status)}
>
{#if $data || status === 'downloading'}
Downloading...

View File

@@ -104,9 +104,11 @@
>
<TableHeaderCell />
</TableHeaderRow>
{#each files as file}
<MMLocalFileRow {file} {deleteFile} />
{/each}
<Container class="contents" focusedChild>
{#each files as file}
<MMLocalFileRow {file} {deleteFile} />
{/each}
</Container>
</div>
{#if files?.length}
<Container

View File

@@ -51,7 +51,7 @@
</TableCell>
<TableCell>
<TableButton
active={!didGrab && !fetching}
disabled={didGrab || fetching}
on:clickOrSelect={handleGrabRelease}
on:enter={scrollIntoView({ vertical: 128 })}
>

View File

@@ -89,7 +89,8 @@
>
<TableHeaderCell />
</TableHeaderRow>
<Container class="contents" focusOnMount>
<Container class="contents" focusedChild>
{#each getRecommendedReleases(releases).sort(getSortFn(sortBy, sortDirection)) as release, index}
<MMReleaseListRow {release} {grabRelease} />
{/each}

View File

@@ -2,17 +2,17 @@
import Container from '../../../Container.svelte';
import classNames from 'classnames';
export let active = true;
export let disabled = false;
</script>
<Container let:hasFocus on:clickOrSelect {active} class="float-left" on:enter>
<Container let:hasFocus on:clickOrSelect {disabled} class="float-left" on:enter>
<div
class={classNames(
'border-2 rounded-2xl p-1 cursor-pointer font-medium tracking-wide transition-colors',
{
'border-zinc-400': !hasFocus,
'border-primary-500': hasFocus,
'opacity-50': !active
'opacity-50': disabled
}
)}
>