Creating Interactive Task Cards

Creating Interactive Task Cards

In our previous lesson, we transformed static column placeholders into dynamic, reusable Column components. Now that we have this flexible container structure in place, it's time to populate these columns with their core content: individual task cards.

Task cards are the building blocks of any Kanban system. Each card represents a single work item that can move between columns as work progresses. A well-designed task card should communicate key information at a glance while being interactive and accessible. In this lesson, we'll create cards that display a title and an optional description, with visual feedback when hovered over or focused.

Building The TaskCard Component

Let's create a new file called TaskCard.svelte in our components directory. This component will represent each individual task in our Kanban board.

Defining Component Props

We'll start by defining the component's props using Svelte 5's $props() function, which you'll remember from our work with the Column component. The key difference here is that we're making the description optional by providing a default empty string value:

<script>
  let { title, description = '' } = $props();
</script>

Building The Component Template

The template portion needs to handle two scenarios: when a description exists and when it doesn't. We'll use Svelte's {#if} block for conditional rendering:

<div class="task-card" tabindex="0">
  <h3>{title}</h3>
  {#if description}
    <p class="description">{description}</p>
  {/if}
</div>

The {#if} block ensures the description paragraph only appears when a description is provided.

Notice we've included tabindex="0" to make the card keyboard-navigable. This is an important accessibility feature that allows users to interact with our cards using keyboard navigation.

Implementing Interactive Styling

For styling, we'll implement several important interaction states:

<style>
  .task-card {
    background: white;
    padding: 0.75rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 0.5rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
  }

  .task-card:hover, .task-card:focus {
    transform: translateY(-2px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
  }

  .task-card:focus {
    outline: 2px solid #4299e1;
    outline-offset: 2px;
  }

  h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1rem;
  }

  .description {
    margin: 0;
    font-size: 0.875rem;
    color: #4a5568;
  }
</style>

The transition property creates smooth animations when the card moves, while the :hover and :focus pseudo-classes provide clear visual feedback to users.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal