Skip to content

Commit

Permalink
Refactors ContentLayout from ResultsList
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Feb 29, 2024
1 parent 924b422 commit a681afe
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 76 deletions.
49 changes: 49 additions & 0 deletions src/lib/components/ContentLayout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="container">
{#if $$slots.header}
<header>
<slot name="header" />
</header>
{/if}
<main>
<slot />
</main>
{#if $$slots.footer}
<footer>
<slot name="footer" />
</footer>
{/if}
</div>

<style>
.container {
display: flex;
padding: 0;
flex-direction: column;
align-items: flex-start;
flex: 1 0 0;
align-self: stretch;
position: relative;
}
header {
flex: 1 0 0;
width: 100%;
position: sticky;
top: 0;
padding: 0.625rem;
}
main {
flex: 1 0 0;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
padding: 0 1.25rem;
}
footer {
flex: 1 0 0;
width: 100%;
position: sticky;
bottom: 0;
padding: 0.625rem;
}
</style>
6 changes: 2 additions & 4 deletions src/lib/components/common/Checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
display: flex;
align-items: center;
gap: 0.5rem;
align-self: stretch;
}
input {
opacity: 0;
position: fixed;
z-index: -10;
display: none;
visibility: hidden;
}
span {
Expand Down
82 changes: 20 additions & 62 deletions src/lib/components/documents/ResultsList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
<script lang="ts">
import { _ } from "svelte-i18n";
import type { DocumentResults } from "$lib/api/types";
import Search from "../Search.svelte";
import PageToolbar from "../common/PageToolbar.svelte";
import DocumentListItem from "./DocumentListItem.svelte";
import Flex from "../common/Flex.svelte";
import Checkbox from "../common/Checkbox.svelte";
import { Search24 } from "svelte-octicons";
import { Hourglass24, Search24 } from "svelte-octicons";
import Empty from "../common/Empty.svelte";
export let results: DocumentResults;
export let results: DocumentResults = undefined;
function updateSelection(event: Event, id: string | number) {
const { checked } = event.target as HTMLInputElement;
Expand All @@ -27,61 +25,21 @@
}
</script>

<div class="container">
<header>
<PageToolbar><Search slot="center" /></PageToolbar>
</header>
<main>
{#each results.results as document (document.id)}
<Flex gap={0.625} align="center">
<Checkbox
value={document.id}
on:change={(event) => updateSelection(event, document.id)}
/>
<DocumentListItem {document} />
</Flex>
{:else}
<Empty icon={Search24}>
<h2>{$_("noDocuments.noSearchResults")}</h2>
<p>{$_("noDocuments.queryNoResults")}</p>
</Empty>
{/each}
</main>
<footer>
<PageToolbar />
</footer>
</div>

<style>
.container {
display: flex;
padding: 0;
flex-direction: column;
align-items: flex-start;
flex: 1 0 0;
align-self: stretch;
position: relative;
}
header {
flex: 1 0 0;
width: 100%;
position: sticky;
top: 0.5rem;
margin: 0.5rem 0;
}
main {
flex: 1 0 0;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
padding: 0.5rem;
}
footer {
flex: 1 0 0;
width: 100%;
position: sticky;
bottom: 0.5rem;
margin: 0.5rem 0;
}
</style>
{#if !results}
<Empty icon={Hourglass24}>Loading…</Empty>
{:else}
{#each results.results as document (document.id)}
<Flex gap={0.625} align="center">
<Checkbox
checked={$selected.includes(document.id)}
on:change={(event) => updateSelection(event, document.id)}
/>
<DocumentListItem {document} />
</Flex>
{:else}
<Empty icon={Search24}>
<h2>{$_("noDocuments.noSearchResults")}</h2>
<p>{$_("noDocuments.queryNoResults")}</p>
</Empty>
{/each}
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
};
</script>

<Story name="yes results">
<Story name="With Results">
<div style="width: 36rem"><ResultsList {results} /></div>
</Story>

<Story name="no results">
<Story name="Empty">
<div style="width: 36rem"><ResultsList results={empty} /></div>
</Story>

<Story name="Loading">
<div style="width: 36rem"><ResultsList /></div>
</Story>
16 changes: 11 additions & 5 deletions src/lib/components/stories/MainLayout.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import SidebarItem from "$lib/components/sidebar/SidebarItem.svelte";
import documents from "../../api/fixtures/documents/documents.json";
import DocumentListItem from "../documents/DocumentListItem.svelte";
import Flex from "../common/Flex.svelte";
import SidebarGroup from "../sidebar/SidebarGroup.svelte";
import Action from "../common/Action.svelte";
import Pin from "@/common/Pin.svelte";
import ResultsList from "../documents/ResultsList.svelte";
import ContentLayout from "../ContentLayout.svelte";
import PageToolbar from "../common/PageToolbar.svelte";
import Search from "../Search.svelte";
let docList = documents as DocumentResults;
let results = documents as DocumentResults;
export const meta = {
title: "Components / Main Layout",
Expand Down Expand Up @@ -72,9 +74,13 @@
</Flex>
</SidebarGroup>
</svelte:fragment>
<svelte:fragment slot="content">
<ResultsList results={docList} />
</svelte:fragment>
<ContentLayout slot="content">
<PageToolbar slot="header">
<Search slot="center" />
</PageToolbar>
<ResultsList {results} />
<PageToolbar slot="footer" />
</ContentLayout>
<svelte:fragment slot="action">
<Button mode="primary"><PlusCircle16 /> Upload Documents</Button>
<Flex direction="column">
Expand Down
13 changes: 10 additions & 3 deletions src/routes/app/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import Action from "$lib/components/common/Action.svelte";
import Pin from "@/common/Pin.svelte";
import ResultsList from "@/lib/components/documents/ResultsList.svelte";
import ContentLayout from "@/lib/components/ContentLayout.svelte";
import PageToolbar from "@/lib/components/common/PageToolbar.svelte";
import Search from "@/lib/components/Search.svelte";
export let data;
Expand Down Expand Up @@ -68,13 +71,17 @@
</Flex>
</SidebarGroup>
</svelte:fragment>
<svelte:fragment slot="content">
<ContentLayout slot="content">
<PageToolbar slot="header">
<Search {query} />
</PageToolbar>
{#await searchResults}
<p class="loading">Loading ...</p>
<ResultsList />
{:then results}
<ResultsList {results} />
{/await}
</svelte:fragment>
<PageToolbar slot="footer" />
</ContentLayout>
<svelte:fragment slot="action">
<Button mode="primary"><PlusCircle16 /> Upload Documents</Button>
<Flex direction="column">
Expand Down

0 comments on commit a681afe

Please sign in to comment.