$npx -y skills add dylantarre/design-system-skills --skill vueBuilds token-driven Vue 3 components with Composition API and TypeScript. Use when creating Vue component libraries, integrating design tokens, or building Nuxt design system components with composables.
| 1 | # Vue Component Patterns |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Build accessible, token-driven Vue 3 components using Composition API and modern patterns. Covers SFC structure, TypeScript integration, composables, and consuming design tokens. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Creating a Vue 3 component library |
| 10 | - Building components that use design tokens |
| 11 | - Setting up a design system in Vue/Nuxt |
| 12 | - Converting designs to Vue components |
| 13 | |
| 14 | ## The Process |
| 15 | |
| 16 | 1. **Identify component type**: Primitive, composite, or layout? |
| 17 | 2. **Choose styling approach**: Scoped CSS, CSS Modules, Tailwind, or UnoCSS? |
| 18 | 3. **Define props with TypeScript**: Use `defineProps` with interfaces |
| 19 | 4. **Implement with tokens**: CSS custom properties or provide/inject |
| 20 | 5. **Add accessibility**: ARIA, keyboard handling, focus management |
| 21 | 6. **Create composables**: Extract reusable logic |
| 22 | |
| 23 | ## Project Structure |
| 24 | |
| 25 | ``` |
| 26 | src/ |
| 27 | ├── components/ |
| 28 | │ ├── primitives/ |
| 29 | │ │ ├── VButton/ |
| 30 | │ │ │ ├── VButton.vue |
| 31 | │ │ │ ├── VButton.test.ts |
| 32 | │ │ │ └── index.ts |
| 33 | │ │ ├── VInput/ |
| 34 | │ │ └── VText/ |
| 35 | │ ├── composite/ |
| 36 | │ │ ├── VCard/ |
| 37 | │ │ ├── VModal/ |
| 38 | │ │ └── VDropdown/ |
| 39 | │ └── layout/ |
| 40 | │ ├── VStack/ |
| 41 | │ ├── VGrid/ |
| 42 | │ └── VContainer/ |
| 43 | ├── composables/ |
| 44 | │ ├── useTheme.ts |
| 45 | │ ├── useBreakpoint.ts |
| 46 | │ └── useId.ts |
| 47 | ├── tokens/ |
| 48 | │ └── index.css |
| 49 | └── index.ts |
| 50 | ``` |
| 51 | |
| 52 | ## Component Patterns |
| 53 | |
| 54 | ### Button Component |
| 55 | |
| 56 | **VButton.vue:** |
| 57 | ```vue |
| 58 | <script setup lang="ts"> |
| 59 | import { computed, useSlots } from 'vue'; |
| 60 | |
| 61 | export interface ButtonProps { |
| 62 | /** Visual style variant */ |
| 63 | variant?: 'primary' | 'secondary' | 'ghost' | 'danger'; |
| 64 | /** Size of the button */ |
| 65 | size?: 'sm' | 'md' | 'lg'; |
| 66 | /** Full width button */ |
| 67 | fullWidth?: boolean; |
| 68 | /** Loading state */ |
| 69 | loading?: boolean; |
| 70 | /** Disabled state */ |
| 71 | disabled?: boolean; |
| 72 | /** HTML button type */ |
| 73 | type?: 'button' | 'submit' | 'reset'; |
| 74 | } |
| 75 | |
| 76 | const props = withDefaults(defineProps<ButtonProps>(), { |
| 77 | variant: 'primary', |
| 78 | size: 'md', |
| 79 | fullWidth: false, |
| 80 | loading: false, |
| 81 | disabled: false, |
| 82 | type: 'button', |
| 83 | }); |
| 84 | |
| 85 | const emit = defineEmits<{ |
| 86 | click: [event: MouseEvent]; |
| 87 | }>(); |
| 88 | |
| 89 | const slots = useSlots(); |
| 90 | |
| 91 | const isDisabled = computed(() => props.disabled || props.loading); |
| 92 | |
| 93 | const classes = computed(() => [ |
| 94 | 'btn', |
| 95 | `btn--${props.variant}`, |
| 96 | `btn--${props.size}`, |
| 97 | { |
| 98 | 'btn--full-width': props.fullWidth, |
| 99 | 'btn--loading': props.loading, |
| 100 | }, |
| 101 | ]); |
| 102 | |
| 103 | function handleClick(event: MouseEvent) { |
| 104 | if (!isDisabled.value) { |
| 105 | emit('click', event); |
| 106 | } |
| 107 | } |
| 108 | </script> |
| 109 | |
| 110 | <template> |
| 111 | <button |
| 112 | :type="type" |
| 113 | :class="classes" |
| 114 | :disabled="isDisabled" |
| 115 | :aria-busy="loading" |
| 116 | @click="handleClick" |
| 117 | > |
| 118 | <span v-if="loading" class="btn__spinner" aria-hidden="true" /> |
| 119 | <span v-if="slots.leftIcon" class="btn__icon"> |
| 120 | <slot name="leftIcon" /> |
| 121 | </span> |
| 122 | <span class="btn__label"> |
| 123 | <slot /> |
| 124 | </span> |
| 125 | <span v-if="slots.rightIcon" class="btn__icon"> |
| 126 | <slot name="rightIcon" /> |
| 127 | </span> |
| 128 | </button> |
| 129 | </template> |
| 130 | |
| 131 | <style scoped> |
| 132 | .btn { |
| 133 | display: inline-flex; |
| 134 | align-items: center; |
| 135 | justify-content: center; |
| 136 | gap: var(--spacing-xs); |
| 137 | font-family: inherit; |
| 138 | font-weight: 500; |
| 139 | line-height: 1; |
| 140 | white-space: nowrap; |
| 141 | cursor: pointer; |
| 142 | user-select: none; |
| 143 | border: 1px solid transparent; |
| 144 | border-radius: var(--radius-md); |
| 145 | transition: |
| 146 | background-color 150ms ease, |
| 147 | border-color 150ms ease, |
| 148 | transform 100ms ease; |
| 149 | } |
| 150 | |
| 151 | .btn:focus-visible { |
| 152 | outline: 2px solid var(--color-primary-500); |
| 153 | outline-offset: 2px; |
| 154 | } |
| 155 | |
| 156 | .btn:active:not(:disabled) { |
| 157 | transform: scale(0.98); |
| 158 | } |
| 159 | |
| 160 | .btn:disabled { |
| 161 | cursor: not-allowed; |
| 162 | opacity: 0.5; |
| 163 | } |
| 164 | |
| 165 | /* Variants */ |
| 166 | .btn--primary { |
| 167 | background-color: var(--color-primary-500); |
| 168 | color: white; |
| 169 | } |
| 170 | |
| 171 | .btn--primary:hover:not(:disabled) { |
| 172 | background-color: var(--color-primary-600); |
| 173 | } |
| 174 | |
| 175 | .btn--secondary { |
| 176 | background-color: transparent; |
| 177 | border-color: var(--color-gray-300); |
| 178 | color: var(--color-gray-700); |
| 179 | } |
| 180 | |
| 181 | .btn--secondary:hover:not(:disabled) { |
| 182 | background-color: var(--color-gray-50); |
| 183 | border-color: var(--color-gray-400); |
| 184 | } |
| 185 | |
| 186 | .btn--ghost { |
| 187 | background-color: transparent; |
| 188 | color: var(--color-gray-700); |
| 189 | } |
| 190 | |
| 191 | .btn--ghost:hover:not(:disabled) { |
| 192 | background-color: var(--color-gray-100); |
| 193 | } |
| 194 | |
| 195 | .btn--danger { |
| 196 | background-color: var(--color-error-500); |
| 197 | color: white; |
| 198 | } |
| 199 | |
| 200 | .btn--danger:hover:not(:disabled) { |
| 201 | background-color: var(--color-error-600); |
| 202 | } |
| 203 | |
| 204 | /* Sizes */ |
| 205 | .btn--sm { |
| 206 | height: 32px; |
| 207 | padding: 0 var(--spacing-sm); |
| 208 | font-size: var(--text-sm); |
| 209 | } |
| 210 | |
| 211 | .btn--md { |
| 212 | height: 40px; |
| 213 | padding: 0 var(--spacing-md); |
| 214 | font-size: var(--text-base); |
| 215 | } |
| 216 | |
| 217 | .btn--lg { |
| 218 | height: 48px; |
| 219 | padding: 0 var(--spacing-lg); |
| 220 | font-size: var(--text-lg); |
| 221 | } |
| 222 | |
| 223 | /* Modifiers */ |
| 224 | .btn--full-width { |
| 225 | width: 100%; |
| 226 | } |
| 227 | |
| 228 | .btn--loading .btn__label { |
| 229 | opacity: 0; |
| 230 | } |
| 231 | |
| 232 | .btn__spinner { |
| 233 | position: absolute; |
| 234 | width: 1em |