---
title: "Create a Vue Component from a Design Brief"
description: "Turn a written design brief into a working Vue 3 component with props, events, styling, and accessibility."
sidebar:
  label: "Create Vue Component"
seo:
  description: "Turn a written design brief into a working Vue 3 component with props, events, styling, and accessibility using Autohand Code."
---

Intermediate · 15 min

```bash
autohand "Create a Vue 3 DataTable component with sortable columns, pagination, row selection, and a search filter. Use Composition API and scoped CSS. Support both light and dark themes."
```

## What you'll learn [#goals]

- How to write a design brief that produces a complete component
- How Autohand matches your existing project patterns
- How to review generated props, events, and accessibility
- How to refine a component with follow-up prompts

## Before you start

- **Autohand Code installed.** Run `autohand --version` to verify. See [Your First Autohand Session](/tutorials/your-first-session) if needed.
- **A Vue 3 project using Composition API.** Created with `npm create vue@latest` or Vite.

If you want the component to use your project's existing design tokens or CSS variables, having at least one other component already written gives Autohand patterns to match.

## Write a clear design brief [#design-brief]

The brief is the prompt. The more precisely you describe the behavior and interface, the less you need to adjust after generation.

A good brief for a component covers these points.

- **What the component does.** Display tabular data with sorting, pagination, row selection, and text search.
- **What props it accepts.**
    - `columns`: array of column definition objects with `key`, `label`, and optional `sortable`.
    - `rows`: array of data objects.
    - `pageSize`: number, default 10.
    - `loading`: boolean, shows a skeleton state.
- **What events it emits.**
    - `update:selected`: emitted when row selection changes, with the array of selected row objects.
    - `sort`: emitted when a column header is clicked, with `{ key, direction }`.
- **Visual requirements.** Striped rows, sticky header, responsive on mobile (horizontal scroll). Support light and dark themes via CSS custom properties.
- **Accessibility.** Keyboard navigable. Sort buttons have `aria-sort`. Checkboxes have accessible labels.

```bash
# A detailed brief in one prompt
autohand "Create a Vue 3 DataTable component. Props: columns (array of {key, label, sortable?}),
rows (array of objects), pageSize (number, default 10), loading (boolean).
Events: update:selected (array of selected rows), sort ({key, direction}).
Features: sortable columns, pagination, row selection via checkboxes, search filter.
Styling: scoped CSS, striped rows, sticky header, mobile horizontal scroll.
Theme: use CSS custom properties for all colors so it works in both light and dark themes.
Accessibility: aria-sort on sortable headers, proper labels on checkboxes, keyboard navigation."
```

## Generate the component [#generate]

Run Autohand from your project root.

```bash
cd my-vue-project
autohand "Create a Vue 3 DataTable component with sortable columns, pagination, row selection, and a search filter. Use Composition API and scoped CSS. Support both light and dark themes."
```

If you have other components in your project, the agent reads them first to match your naming conventions and CSS variable usage.

```bash
# Agent output (abbreviated)
Reading: src/components/Button.vue
Reading: src/components/Input.vue
Reading: src/style.css

Understood patterns:
  - CSS variables follow --color-* naming
  - Components use defineProps with TypeScript-style JSDoc
  - Scoped styles use BEM-ish class names

Generating DataTable.vue to match...
```

## Review the component [#review]

Before integrating it into your app, check the generated component for these things.

**Props definition.** Open `src/components/DataTable.vue` and check the `defineProps` block. Verify the types match what you described.

```js
// Generated props - verify this matches your expectations
const props = defineProps({
  columns: {
    type: Array,
    required: true,
  },
  rows: {
    type: Array,
    required: true,
  },
  pageSize: {
    type: Number,
    default: 10,
  },
  loading: {
    type: Boolean,
    default: false,
  },
});
```

**Emits declaration.** Check that the emits match the events you asked for.

```js
const emit = defineEmits(['update:selected', 'sort']);
```

**Accessibility attributes.** Scan the template for `aria-sort` on the column headers and `aria-label` on the row selection checkboxes. If these are missing, ask Autohand to add them.

**CSS variables.** Check the scoped styles section. All color values should use `var(--your-variable-name)` rather than hardcoded hex values. This is what makes the component theme-compatible.

## Integrate into your app [#integrate]

Import the component and try it with sample data to confirm it renders and behaves correctly.

```vue
<script setup>
import DataTable from '@/components/DataTable.vue';

const columns = [
  { key: 'name', label: 'Name', sortable: true },
  { key: 'email', label: 'Email', sortable: true },
  { key: 'role', label: 'Role' },
];

const rows = [
  { id: 1, name: 'Ada Lovelace', email: 'ada@example.com', role: 'Admin' },
  { id: 2, name: 'Grace Hopper', email: 'grace@example.com', role: 'Engineer' },
  { id: 3, name: 'Margaret Hamilton', email: 'margaret@example.com', role: 'Engineer' },
];

function handleSort({ key, direction }) {
  console.log('Sort by', key, direction);
}

function handleSelection(selected) {
  console.log('Selected rows', selected);
}
</script>

<template>
  <DataTable
    :columns="columns"
    :rows="rows"
    :page-size="10"
    @sort="handleSort"
    @update:selected="handleSelection"
  />
</template>
```

Run the dev server and verify the table renders, sorting responds to header clicks, checkboxes update the selection, and pagination works with more than 10 rows.

```bash
npm run dev
```

## Refine with follow-ups [#refine]

Once the base component works, add features with follow-up prompts in the same session.

```bash
# Add column resizing
autohand "Add column resizing to DataTable.vue. Dragging a column header border should resize that column. Store widths in a reactive object."

# Add CSV export
autohand "Add a CSV export button to DataTable.vue that exports the currently visible (filtered and sorted) rows."

# Add empty state
autohand "Add an empty state slot to DataTable.vue that shows when rows is empty or filtered results return nothing."

# Add row click handler
autohand "Add a row-click event to DataTable.vue that emits the full row object when a row is clicked. Skip the event if the click target is a checkbox."
```

Each follow-up reads the component as it currently exists, so changes stay consistent with the structure already in place.

:::tip
**Tip:** If the component is growing complex, ask Autohand to extract reusable logic into a composable. For example: `autohand "Extract the sort and pagination logic from DataTable.vue into a useDataTable composable."`
:::

## What you learned [#recap]

- Wrote a detailed design brief that covers props, events, and accessibility
- Generated a production-ready Vue 3 component that matches project patterns
- Reviewed the component for correct types, emits, and CSS variables
- Refined the component with follow-up prompts for new features

### Try next

```bash
autohand "Extract the sort and pagination logic from DataTable.vue into a reusable useDataTable composable"
```

### Related tutorials

**[Generate a Full CRUD Feature](/tutorials/generate-crud-feature)**

Add a complete create, read, update, delete feature to an existing project with validation and tests.

**[Modernize CSS to Custom Properties](/tutorials/modernize-css-custom-properties)**

Convert hardcoded color and spacing values to CSS custom properties for easier theming.
