Skip to content

Commit

Permalink
feat(example): add sidebars on tasks examples
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolguevara committed Nov 7, 2023
1 parent 2a4dc44 commit 5efc6df
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
export let filterValues: string[] = [];
export let title: string;
export let options = [] as typeof statuses;
export let view: "pill" | "list" = "pill";
let open = false;
const handleSelect = (currentValue: string) => {
Expand All @@ -29,48 +29,9 @@
};
</script>

<Popover.Root bind:open positioning={{ placement: "bottom-start" }}>
<Popover.Trigger asChild let:builder>
<Button
builders={[builder]}
variant="outline"
size="sm"
class="h-8 border-dashed"
>
<PlusCircled class="mr-2 h-4 w-4" />
{title}

{#if filterValues.length > 0}
<Separator orientation="vertical" class="mx-2 h-4" />
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal lg:hidden"
>
{filterValues.length}
</Badge>
<div class="hidden space-x-1 lg:flex">
{#if filterValues.length > 2}
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal"
>
{filterValues.length} Selected
</Badge>
{:else}
{#each filterValues as option}
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal"
>
{option}
</Badge>
{/each}
{/if}
</div>
{/if}
</Button>
</Popover.Trigger>
<Popover.Content class="w-[200px] p-0">
{#if view === "list"}
<div>
<span class="text-xs font-medium">{title}</span>
<Command.Root>
<Command.Input placeholder={title} />
<Command.List>
Expand All @@ -91,26 +52,127 @@
: "opacity-50 [&_svg]:invisible"
)}
>
<Check className={cn("h-4 w-4")} />
<Check class={cn("h-4 w-4")} />
</div>
<span>
{option.label}
</span>
</Command.Item>
{/each}
</Command.Group>

<Command.Separator />
<Command.Item
class="justify-center text-center"
onSelect={() => {
filterValues =
filterValues.length > 0
? []
: options.map(({ value }) => value);
}}
>
{#if filterValues.length > 0}
Clear filters
{:else}
Select all
{/if}
</Command.Item>
</Command.List>
</Command.Root>
</div>
{:else}
<Popover.Root bind:open positioning={{ placement: "bottom-start" }}>
<Popover.Trigger asChild let:builder>
<Button
title={filterValues.length
? `${title}: ${filterValues.join(", ")} selected.`
: `${title}: not selected.`}
builders={[builder]}
variant="outline"
size="sm"
class="h-8 border-dashed"
>
<PlusCircled class="mr-2 h-4 w-4" />
{title}

{#if filterValues.length > 0}
<Separator orientation="vertical" class="mx-2 h-4" />
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal lg:hidden"
>
{filterValues.length}
</Badge>
<div class="hidden space-x-1 lg:flex">
{#if filterValues.length > 2}
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal"
>
{filterValues.length} Selected
</Badge>
{:else}
{#each filterValues as option}
<Badge
variant="secondary"
class="rounded-sm px-1 font-normal"
>
{option}
</Badge>
{/each}
{/if}
</div>
{/if}
</Button>
</Popover.Trigger>
<Popover.Content class="w-[200px] p-0">
<Command.Root>
<Command.Input placeholder={title} />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group>
{#each options as option}
<Command.Item
value={option.value}
onSelect={(currentValue) => {
handleSelect(currentValue);
}}
>
<div
class={cn(
"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
filterValues.includes(option.value)
? "bg-primary text-primary-foreground"
: "opacity-50 [&_svg]:invisible"
)}
>
<Check class={cn("h-4 w-4")} />
</div>
<span>
{option.label}
</span>
</Command.Item>
{/each}
</Command.Group>

<Command.Separator />
<Command.Item
class="justify-center text-center"
onSelect={() => {
filterValues = [];
filterValues =
filterValues.length > 0
? []
: options.map(({ value }) => value);
}}
>
Clear filters
{#if filterValues.length > 0}
Clear filters
{:else}
Select all
{/if}
</Command.Item>
{/if}
</Command.List>
</Command.Root>
</Popover.Content>
</Popover.Root>
</Command.List>
</Command.Root>
</Popover.Content>
</Popover.Root>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<script lang="ts">
import Input from "@/registry/new-york/ui/input/input.svelte";
import type { TableViewModel } from "svelte-headless-table/lib/createViewModel";
import type { AnyPlugins } from "svelte-headless-table/lib/types/TablePlugin";
import type { Writable } from "svelte/store";
import { DataTableFacetedFilter } from ".";
import { priorities, statuses } from "../(data)/data";
import type { Task } from "../(data)/schemas";
export let tableModel: TableViewModel<Task, AnyPlugins>;
const { pluginStates } = tableModel;
const {
filterValue
}: {
filterValue: Writable<string>;
} = pluginStates.filter;
const {
filterValues
}: {
filterValues: Writable<{
status: string[];
priority: string[];
}>;
} = pluginStates.colFilter;
</script>

<aside class="relative col-span-2 border-r border-b p-2">
<div class="sticky top-12">
<div class="flex flex-col space-y-2">
<span class="text-sm font-medium">Filters</span>
<Input
placeholder="Filter tasks..."
class="h-8 w-full"
type="text"
bind:value={$filterValue}
/>

<DataTableFacetedFilter
bind:filterValues={$filterValues.status}
title="Status"
view="list"
options={statuses}
/>

<DataTableFacetedFilter
bind:filterValues={$filterValues.priority}
title="Priority"
view="list"
options={priorities}
/>

<!-- {#if showReset}
<Button
on:click={() => {
$filterValues.status = [];
$filterValues.priority = [];
}}
variant="ghost"
class="h-8 px-2 lg:px-3"
>
Reset
<Cross2 class="ml-2 h-4 w-4" />
</Button>
{/if} -->
</div>
</div>
</aside>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<script lang="ts">
import * as Card from "@/registry/default/ui/card";
import { Label } from "@/registry/default/ui/label";
import * as Select from "@/registry/default/ui/select";
import { Textarea } from "@/registry/default/ui/textarea";
import Button from "@/registry/new-york/ui/button/button.svelte";
import Input from "@/registry/new-york/ui/input/input.svelte";
import type { TableViewModel } from "svelte-headless-table/lib/createViewModel";
import type { AnyPlugins } from "svelte-headless-table/lib/types/TablePlugin";
import { priorities, statuses } from "../(data)/data";
import type { Task } from "../(data)/schemas";
export let tableModel: TableViewModel<Task, AnyPlugins>;
const { pluginStates } = tableModel;
const {
custom: { taskOnEdition, taskIdOnEdition }
} = pluginStates;
$: task = $taskOnEdition || {};
$: selectedStatus = statuses.find(({ value }) => task.status === value);
$: selectedPriority = priorities.find(
({ value }) => task.priority === value
);
</script>

<aside class="relative col-span-3 border-l border-b p-2">
<div class="sticky top-12 flex flex-col h-full">
<Card.Header>
<Card.Title># {task.id}</Card.Title>
<Card.Description>
Here you can edit your task information
</Card.Description>
</Card.Header>
<Card.Content class="grow grid gap-2">
<div class="grid gap-2">
<Label for="title">Title</Label>
<Input
id="title"
placeholder="Task title ..."
bind:value={task.title}
/>
</div>
<div class="grid gap-2">
<Label for="status">Status</Label>
<Select.Root bind:selected={selectedStatus}>
<Select.Trigger id="status">
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Content>
{#each statuses as status}
<Select.Item
value={status.value}
label={status.label}
>
{status.label}
</Select.Item>
{/each}
</Select.Content>
</Select.Root>
</div>
<div class="grid gap-2">
<Label for="priority">Priority</Label>
<Select.Root bind:selected={selectedPriority}>
<Select.Trigger id="priority">
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Content>
{#each priorities as priority}
<Select.Item
value={priority.value}
label={priority.label}
>
{priority.label}
</Select.Item>
{/each}
</Select.Content>
</Select.Root>
</div>
<div class="grid gap-2">
<Label for="description">Description</Label>
<Textarea
id="description"
placeholder="Please include all information relevant to your issue."
bind:value={task.description}
/>
</div>
</Card.Content>
<Card.Footer class="flex flex-1 items-end justify-end space-x-2">
<Button
on:click={() => taskIdOnEdition.set(null)}
variant="secondary"
>
Cancel
</Button>
<Button on:click={() => taskIdOnEdition.set(null)}>Submit</Button>
</Card.Footer>
</div>
</aside>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
const { selectedDataIds } = pluginStates.select;
</script>

<div class="flex items-center justify-between px-2">
<div class="p-2 flex items-center justify-between">
<div class="flex-1 text-sm text-muted-foreground">
{Object.keys($selectedDataIds).length} of{" "}
{$rows.length} row(s) selected.
Expand Down
Loading

0 comments on commit 5efc6df

Please sign in to comment.