Considering App Structure
I'm currently structuring the Vue.js app, focusing on how to integrate Tailwind CSS seamlessly. I'm thinking about components and how they'll work together with transitions for that smooth user interface. I'm also delving into how to best organize the components and state management for efficient development and future scalability.
Planning Implementation Details
\n\n
I'm now focusing on implementation. I've chosen a Task Manager as a good balance of features to showcase, avoiding overkill or oversimplification. I'm nailing down the plan; using Vue 3 with Vite, Tailwind CSS, and Vue's built-in transitions. The current plan involves project setup, Tailwind configuration, and the initial component structure for App.vue. I'll delve into adding, removing, and reordering items with transitions next.
Outlining Component Interactions
\n\n
My current thinking revolves around CardList.vue and BaseModal.vue components, focusing on their dynamic interplay. I'm mapping specific Tailwind classes to Vue's transition classes for smooth animations. I'm also sketching out how the v-move class will achieve the list's item reordering transitions. The next step is fleshing out the logic for adding, deleting, and managing a modal state within the Vue components.
Designing App.vue Logic
\n\n
My current focus is simplifying the App.vue logic for easy user adoption. I'm prioritizing clarity while also making the code readily copy-pastable. I'm leaning heavily on Vue's <TransitionGroup> for the list, with specific CSS classes (list-enter-active, list-leave-active, etc.) managing the list item transitions. For the modal, I'm opting for a single fade transition, combining opacity and scale for simplicity. Tailwind classes like bg-slate-800 and shadow-xl will be utilized to maintain a clean, modern aesthetic.
Clarifying Output Structure
\n\n
I'm now refining the tutorial's structure. The goal is a clear, concise guide. I'm focusing on these sections: Project Setup, Tailwind Configuration, a single cohesive code example, and a detailed breakdown of the transition CSS. This revised approach should provide the user with all necessary information in an easily digestible format.
Illustrating Transition Versatility
\n\n
I'm now emphasizing Vue transition versatility. I'll showcase both the "Utility Class" method in the modal template and the "CSS Class" method in the list for a clear contrast. This will highlight different ways of implementing transitions.
Here is a complete guide to building a Vue.js 3 application that integrates Tailwind CSS and utilizes Vue’s built-in <Transition> system for a polished UX.
We will build a "Dynamic Task List" that demonstrates:
- Enter/Leave Transitions: When items are added or deleted.
- List Reordering: Smooth movement when the list shifts.
- Modal Transitions: A smooth fade-in/scale-up effect for dialogs.
Prerequisites
Ensure you have Node.js installed.
Step 1: Scaffolding the Project
Run these commands in your terminal:
# 1. Create Vue project (Select "No" for TypeScript/Router for simplicity if asked)
npm create vite@latest my-vue-tailwind -- --template vue
# 2. Enter directory
cd my-vue-tailwind
# 3. Install Tailwind CSS dependencies
npm install -D tailwindcss postcss autoprefixer
# 4. Initialize Tailwind config
npx tailwindcss init -p
Step 2: Configure Tailwind
- Open
tailwind.config.js and update the content array to scan your files:
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
- Open
src/style.css and replace the content with the Tailwind directives:
@tailwind base;
@tailwind components;
@tailwind utilities;
Step 3: The Application Code
We will implement everything in App.vue to keep it self-contained.
Replace the contents of src/App.vue with the following:
<script setup>
import { ref } from 'vue';
// --- State Management ---
const nextId = ref(4);
const showModal = ref(false);
const newTask = ref('');
const tasks = ref([
{ id: 1, title: 'Design Core Layout', tag: 'Design' },
{ id: 2, title: 'Integrate Tailwind', tag: 'Dev' },
{ id: 3, title: 'Refine Animations', tag: 'UX' },
]);
// --- Actions ---
const addTask = () => {
if (!newTask.value) return;
// Add to top of list to show list movement down
tasks.value.unshift({
id: nextId.value++,
title: newTask.value,
tag: 'New',
});
newTask.value = '';
showModal.value = false;
};
const removeTask = (id) => {
tasks.value = tasks.value.filter((t) => t.id !== id);
};
const shuffle = () => {
tasks.value = tasks.value.sort(() => Math.random() - 0.5);
};
</script>
<template>
<div class="min-h-screen bg-slate-900 text-slate-100 p-8 font-sans selection:bg-indigo-500 selection:text-white">
<!-- Header -->
<div class="max-w-2xl mx-auto mb-8 flex justify-between items-center">
<div>
<h1 class="text-3xl font-bold bg-gradient-to-r from-indigo-400 to-cyan-400 bg-clip-text text-transparent">
Smooth Vue
</h1>
<p class="text-slate-400">Tailwind + Transitions Demo</p>
</div>
<div class="space-x-3">
<button
@click="shuffle"
class="px-4 py-2 text-sm font-medium text-slate-300 hover:text-white transition-colors"
>
Shuffle List
</button>
<button
@click="showModal = true"
class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-lg shadow-lg hover:shadow-indigo-500/30 transition-all duration-300 transform hover:-translate-y-0.5"
>
+ Add Task
</button>
</div>
</div>
<!-- Task List with TransitionGroup -->
<div class="max-w-2xl mx-auto">
<!--
TransitionGroup allows for animating items in a list.
'tag="ul"' renders this as a <ul> element.
'name="list"' looks for CSS classes starting with .list-
-->
<TransitionGroup name="list" tag="ul" class="space-y-3 relative">
<li
v-for="task in tasks"
:key="task.id"
class="bg-slate-800 border border-slate-700 p-4 rounded-xl flex justify-between items-center shadow-md hover:border-indigo-500/50 transition-colors"
>
<div class="flex items-center gap-3">
<span class="bg-slate-700 text-xs font-bold px-2 py-1 rounded text-slate-300">
{{ task.tag }}
</span>
<span class="font-medium">{{ task.title }}</span>
</div>
<button
@click="removeTask(task.id)"
class="text-slate-500 hover:text-red-400 p-2 rounded-full hover:bg-slate-700 transition-colors"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</li>
</TransitionGroup>
<div v-if="tasks.length === 0" class="mt-10 text-center text-slate-500 italic">
No tasks remaining. Time to relax!
</div>
</div>
<!-- Modal with Transition -->
<!--
Using specific classes for enter-active, leave-active, etc.
This allows us to use Tailwind utility classes directly in the transition props
-->
<Transition
enter-active-class="duration-300 ease-out"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="duration-200 ease-in"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-if="showModal"
class="fixed inset-0 bg-black/70 backdrop-blur-sm z-50 flex items-center justify-center p-4"
@click.self="showModal = false"
>
<!-- Inner Modal Card Transition (Scale effect) -->
<Transition
appear
enter-active-class="duration-300 ease-out delay-75"
enter-from-class="opacity-0 scale-90 translate-y-4"
enter-to-class="opacity-100 scale-100 translate-y-0"
leave-active-class="duration-200 ease-in"
leave-from-class="opacity-100 scale-100"
leave-to-class="opacity-0 scale-95"
>
<div v-if="showModal" class="bg-slate-800 border border-slate-700 w-full max-w-md rounded-2xl shadow-2xl overflow-hidden">
<div class="p-6">
<h3 class="text-xl font-bold text-white mb-4">New Task</h3>
<input
v-model="newTask"
@keyup.enter="addTask"
type="text"
placeholder="What needs to be done?"
class="w-full bg-slate-900 text-white border border-slate-700 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent placeholder-slate-500"
autoFocus
/>
</div>
<div class="bg-slate-900/50 px-6 py-4 flex justify-end gap-3">
<button
@click="showModal = false"
class="px-4 py-2 text-slate-400 hover:text-white transition-colors"
>
Cancel
</button>
<button
@click="addTask"
class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-lg transition-colors"
>
Create Task
</button>
</div>
</div>
</Transition>
</div>
</Transition>
</div>
</template>
<style scoped>
/*
Custom CSS for the List Transition Group.
While Tailwind works for simple transitions, complex "FLIP" list animations
often require standard CSS classes for readability and the absolute positioning requirement.
*/
/* 1. Helper to ensure items move smoothly when neighbors leave */
.list-move,
.list-enter-active,
.list-leave-active {
transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
}
/* 2. The state from which elements enter and to which they leave */
.list-enter-from,
.list-leave-to {
opacity: 0;
transform: scaleY(0.01) translate(30px, 0);
}
/* 3. Crucial: Ensure removed items are taken out of flow so others can move up smoothy */
.list-leave-active {
position: absolute;
width: 100%; /* prevent width collapse during absolute positioning */
}
</style>
How It Works (UX Breakdown)
1. The <TransitionGroup> (List Animation)
In the <style> block, we defined classes prefixed with .list-.
- The FLIP Technique: Vue uses opacity and transforms to animate items.
v-move (or .list-move): This is the magic class. When an item is deleted, the remaining items don't just "snap" up. Vue calculates the difference in position and smoothly slides them to their new spot.
position: absolute on Leave: Notice .list-leave-active { position: absolute }. This removes the deleting item from the DOM flow immediately, triggering the move animation for the siblings instantly while the deleting item fades out.
2. The Modal Utility Classes
Instead of writing custom CSS in the <style> block (like we did for the list), we used Tailwind classes directly in the <Transition> props.
- Backdrop: Simply fades in (
opacity-0 to opacity-100).
- Modal Card: Uses a combination of
scale, opacity, and translate-y.
- Entry: It starts slightly smaller (
scale-90), invisible, and lower down, then springs into place.
- Exit: It shrinks slightly and fades out.
- Ordering: We nested the transitions. The backdrop transition wraps the modal transition. This allows the backdrop to fade in, and the modal to "pop" in slightly after.
Running the App
npm run dev
Open the local host link.
- Click Add Task to see the Modal transition.
- Add a task to see it slide into the list.
- Click Shuffle to see the items physically trade places comfortably.
- Click the Trash Icon to see the item slide right and fade out while the list closes the gap smoothly.