Kanban

A project board: workspace sidebar, breadcrumbs and view tabs, filters, and columns of task cards.

Open full screen

Flat · Sidebar. <AppShell direction="flat">: one white surface; lines split the navigation, the page header and the content.

npx wideset add block-kanban

Import the default export from @/blocks/wideset/kanban. The files below are relative to your project's source directory.

Installed with this block
  • app-shell
  • avatar
  • block-styles
  • breadcrumbs
  • button
  • divider
  • filter-button
  • icon-button
  • select
  • sidebar
  • status-badge
  • tabs
  • tag
  • utils
blocks/wideset/kanban/index.tsx
'use client';

import '@/styles/wideset-blocks.css';

import { RiAddLine } from '@remixicon/react';
import { AppShell } from '@/components/ui/wideset/app-shell/AppShell';
import { Button } from '@/components/ui/wideset/button/Button';
import { FilterButton } from '@/components/ui/wideset/filter-button/FilterButton';
import { Select } from '@/components/ui/wideset/select/Select';
import { Tabs } from '@/components/ui/wideset/tabs/Tabs';
import { useState } from 'react';

import { KanbanColumn } from './board';
import { assigneeOptions, columns, sortOptions, teamOptions } from './data';
import { PageHeader } from './header';
import { KanbanSidebar } from './sidebar';

/** Kanban: a project board in the Flat direction, the sidebar and the page on one white surface. */
export default function Kanban() {
  const [teams, setTeams] = useState<string[]>([]);
  const [assignees, setAssignees] = useState<string[]>([]);
  // "Assigned to" narrows every column to the chosen people; a stack keeps its tasks with its person.
  const visibleColumns =
    assignees.length === 0
      ? columns
      : columns.map((column) => {
          const items = column.items.filter(
            (item) => item.assignee != null && assignees.includes(item.assignee.name),
          );
          // The count is of tasks, a stack's hidden ones included, as in the unfiltered column.
          const count = items.reduce(
            (total, item) => total + ('tasks' in item ? item.tasks.length + (item.hidden ?? 0) : 1),
            0,
          );
          return { ...column, items, count };
        });
  const [sort, setSort] = useState('newest');

  return (
    <AppShell className="ws-block-utility" direction="flat">
      <KanbanSidebar />
      <AppShell.Main className="flex flex-col">
        <Tabs defaultValue="board" divider={false} className="min-h-0 flex-1">
          <PageHeader />
          <Tabs.Content value="board" className="gap-ws-9 py-ws-7 flex min-h-0 flex-1 flex-col">
            <div className="gap-ws-5 px-ws-11 flex items-center">
              <FilterButton
                label="Team"
                placeholder="Team"
                options={teamOptions}
                value={teams}
                onChange={setTeams}
              />
              <FilterButton
                label="Assigned to"
                placeholder="Assigned to"
                options={assigneeOptions}
                value={assignees}
                onChange={setAssignees}
              />
              <Select
                size="sm"
                preset="ghost"
                aria-label="Sort tasks"
                options={sortOptions}
                value={sort}
                onValueChange={setSort}
                className="w-auto"
              />
              <Button variant="secondary" preset="border" size="sm" className="ml-auto">
                <Button.Icon icon={RiAddLine} />
                Create
              </Button>
            </div>
            <div className="gap-ws-9 px-ws-11 ws-scrollbar flex min-h-0 flex-1 overflow-x-auto">
              {visibleColumns.map((column) => (
                <KanbanColumn key={column.id} column={column} />
              ))}
            </div>
          </Tabs.Content>
        </Tabs>
      </AppShell.Main>
    </AppShell>
  );
}