|
| 1 | +# Component specification |
| 2 | + |
| 3 | +Displays short text or icons to represent status, categories, or counts. Badges help users quickly identify important information through visual indicators without cluttering the interface. |
| 4 | + |
| 5 | +- **Component Name:** N8nBadge |
| 6 | +- **Figma Component:** TBD |
| 7 | +- **Current Implementation:** Custom component (no Element+ dependency) |
| 8 | +- **Reka UI Component:** N/A (Reka UI does not provide a Badge primitive) |
| 9 | +- **Nuxt UI Reference:** [Badge](https://ui.nuxt.com/docs/components/badge) (custom implementation, not based on Reka UI) |
| 10 | + |
| 11 | +## Public API Definition |
| 12 | + |
| 13 | +**Props** |
| 14 | + |
| 15 | +- `theme?: BadgeTheme` - Visual style variant for the badge. Values: `'default' | 'success' | 'warning' | 'danger' | 'primary' | 'secondary' | 'tertiary'`. Default: `'default'` |
| 16 | + - `default`: Subtle border badge with neutral styling |
| 17 | + - `success`: Green indicator for positive states |
| 18 | + - `warning`: Yellow/orange indicator for cautionary states |
| 19 | + - `danger`: Red indicator for error/critical states |
| 20 | + - `primary`: Filled badge with contrasting text (pill-shaped) |
| 21 | + - `secondary`: Filled badge with tinted background |
| 22 | + - `tertiary`: Minimal badge variant with reduced padding |
| 23 | +- `size?: TextSize` - Size of the badge text. Values: `'xsmall' | 'small' | 'mini' | 'medium' | 'large' | 'xlarge'`. Default: `'small'` |
| 24 | +- `bold?: boolean` - Whether to render text in bold weight. Default: `false` |
| 25 | +- `showBorder?: boolean` - Whether to show the badge border. Default: `true` |
| 26 | + |
| 27 | +**Slots** |
| 28 | + |
| 29 | +- `default` - Badge content (text, icons, or mixed content). Wrapped in N8nText component for consistent typography. |
| 30 | + |
| 31 | +### Template usage examples |
| 32 | + |
| 33 | +**Simple text badge:** |
| 34 | +```typescript |
| 35 | +<script setup lang="ts"> |
| 36 | +import { N8nBadge } from '@n8n/design-system' |
| 37 | +</script> |
| 38 | + |
| 39 | +<template> |
| 40 | + <N8nBadge theme="default"> |
| 41 | + Read Only |
| 42 | + </N8nBadge> |
| 43 | +</template> |
| 44 | +``` |
| 45 | + |
| 46 | +**Status indicators:** |
| 47 | +```typescript |
| 48 | +<script setup lang="ts"> |
| 49 | +import { N8nBadge } from '@n8n/design-system' |
| 50 | +import { computed } from 'vue' |
| 51 | + |
| 52 | +const status = ref<'success' | 'warning' | 'danger'>('success') |
| 53 | + |
| 54 | +const statusTheme = computed(() => { |
| 55 | + const themeMap = { |
| 56 | + success: 'success', |
| 57 | + warning: 'warning', |
| 58 | + danger: 'danger', |
| 59 | + } |
| 60 | + return themeMap[status.value] |
| 61 | +}) |
| 62 | +</script> |
| 63 | + |
| 64 | +<template> |
| 65 | + <N8nBadge :theme="statusTheme"> |
| 66 | + {{ status }} |
| 67 | + </N8nBadge> |
| 68 | +</template> |
| 69 | +``` |
| 70 | + |
| 71 | +**Count badge (primary theme):** |
| 72 | +```typescript |
| 73 | +<script setup lang="ts"> |
| 74 | +import { N8nBadge } from '@n8n/design-system' |
| 75 | + |
| 76 | +const filterCount = ref(5) |
| 77 | +</script> |
| 78 | + |
| 79 | +<template> |
| 80 | + <N8nBadge theme="primary"> |
| 81 | + {{ filterCount }} |
| 82 | + </N8nBadge> |
| 83 | +</template> |
| 84 | +``` |
| 85 | + |
| 86 | +**Tertiary minimal label:** |
| 87 | +```typescript |
| 88 | +<script setup lang="ts"> |
| 89 | +import { N8nBadge } from '@n8n/design-system' |
| 90 | +</script> |
| 91 | + |
| 92 | +<template> |
| 93 | + <N8nBadge theme="tertiary" :bold="true"> |
| 94 | + Pending |
| 95 | + </N8nBadge> |
| 96 | +</template> |
| 97 | +``` |
| 98 | + |
| 99 | +**Badge with icon and text:** |
| 100 | +```typescript |
| 101 | +<script setup lang="ts"> |
| 102 | +import { N8nBadge } from '@n8n/design-system' |
| 103 | +import ProjectIcon from './ProjectIcon.vue' |
| 104 | + |
| 105 | +const projectBadge = { |
| 106 | + icon: 'project', |
| 107 | + text: 'Team Project' |
| 108 | +} |
| 109 | +</script> |
| 110 | + |
| 111 | +<template> |
| 112 | + <N8nBadge |
| 113 | + theme="tertiary" |
| 114 | + :show-border="false" |
| 115 | + > |
| 116 | + <ProjectIcon :icon="projectBadge.icon" size="mini" /> |
| 117 | + <span>{{ projectBadge.text }}</span> |
| 118 | + </N8nBadge> |
| 119 | +</template> |
| 120 | +``` |
| 121 | + |
| 122 | +**Multiple sizes:** |
| 123 | +```typescript |
| 124 | +<script setup lang="ts"> |
| 125 | +import { N8nBadge } from '@n8n/design-system' |
| 126 | +</script> |
| 127 | + |
| 128 | +<template> |
| 129 | + <N8nBadge theme="primary" size="xsmall">XS</N8nBadge> |
| 130 | + <N8nBadge theme="primary" size="small">Small</N8nBadge> |
| 131 | + <N8nBadge theme="primary" size="medium">Medium</N8nBadge> |
| 132 | +</template> |
| 133 | +``` |
| 134 | + |
| 135 | +**With custom CSS classes:** |
| 136 | +```typescript |
| 137 | +<script setup lang="ts"> |
| 138 | +import { N8nBadge } from '@n8n/design-system' |
| 139 | +</script> |
| 140 | + |
| 141 | +<template> |
| 142 | + <N8nBadge class="ml-3xs" theme="warning" :bold="true"> |
| 143 | + Action Required |
| 144 | + </N8nBadge> |
| 145 | +</template> |
| 146 | +``` |
| 147 | + |
| 148 | +**Conditional rendering:** |
| 149 | +```typescript |
| 150 | +<script setup lang="ts"> |
| 151 | +import { N8nBadge } from '@n8n/design-system' |
| 152 | + |
| 153 | +const isReadOnly = ref(true) |
| 154 | +const needsSetup = ref(false) |
| 155 | +</script> |
| 156 | + |
| 157 | +<template> |
| 158 | + <N8nBadge v-if="isReadOnly" theme="tertiary" :bold="true"> |
| 159 | + Read Only |
| 160 | + </N8nBadge> |
| 161 | + |
| 162 | + <N8nBadge v-if="needsSetup" theme="warning"> |
| 163 | + Setup Required |
| 164 | + </N8nBadge> |
| 165 | +</template> |
| 166 | +``` |
| 167 | + |
| 168 | +**With inline styles (advanced):** |
| 169 | +```typescript |
| 170 | +<script setup lang="ts"> |
| 171 | +import { N8nBadge } from '@n8n/design-system' |
| 172 | +</script> |
| 173 | + |
| 174 | +<template> |
| 175 | + <N8nBadge |
| 176 | + theme="warning" |
| 177 | + style="height: 25px" |
| 178 | + > |
| 179 | + Custom Height |
| 180 | + </N8nBadge> |
| 181 | +</template> |
| 182 | +``` |
| 183 | + |
| 184 | +**Dynamic theme binding:** |
| 185 | +```typescript |
| 186 | +<script setup lang="ts"> |
| 187 | +import { N8nBadge } from '@n8n/design-system' |
| 188 | +import type { BadgeTheme } from '@n8n/design-system/types' |
| 189 | + |
| 190 | +interface FileStatus { |
| 191 | + status: 'completed' | 'pending' | 'failed' |
| 192 | +} |
| 193 | + |
| 194 | +const file = ref<FileStatus>({ status: 'completed' }) |
| 195 | + |
| 196 | +const getStatusTheme = (status: string): BadgeTheme => { |
| 197 | + const themeMap: Record<string, BadgeTheme> = { |
| 198 | + completed: 'success', |
| 199 | + pending: 'warning', |
| 200 | + failed: 'danger', |
| 201 | + } |
| 202 | + return themeMap[status] || 'default' |
| 203 | +} |
| 204 | + |
| 205 | +const statusLabel = (status: string) => { |
| 206 | + const labelMap: Record<string, string> = { |
| 207 | + completed: 'Completed', |
| 208 | + pending: 'Pending', |
| 209 | + failed: 'Failed', |
| 210 | + } |
| 211 | + return labelMap[status] || status |
| 212 | +} |
| 213 | +</script> |
| 214 | + |
| 215 | +<template> |
| 216 | + <N8nBadge :theme="getStatusTheme(file.status)"> |
| 217 | + {{ statusLabel(file.status) }} |
| 218 | + </N8nBadge> |
| 219 | +</template> |
| 220 | +``` |
0 commit comments