Skip to content

Commit c30e342

Browse files
committed
feat: NqLinks with auto icons, first blue rest secondary
1 parent 7d05ac5 commit c30e342

File tree

2 files changed

+83
-11
lines changed
  • docs/vitepress-theme/components
  • packages/nimiq-vitepress-theme/src/components

2 files changed

+83
-11
lines changed

docs/vitepress-theme/components/links.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ A component for displaying external links with consistent styling. Perfect for s
1111

1212
### NqLinksItem Interface
1313

14-
| Name | Type | Default | Description |
15-
| --------- | -------- | ------------------- | ------------------------------------------------------------------------ |
16-
| `label` | `string` | required | The text displayed for the link |
17-
| `href` | `string` | required | The URL the link points to |
18-
| `icon` | `string` | `undefined` | Optional icon class (e.g., `i-nimiq:external`) |
19-
| `variant` | `string` | `nq-pill-secondary` | Pill variant: `blue`, `gold`, `green`, `secondary`, `tertiary`, `orange` |
20-
| `title` | `string` | `undefined` | Optional tooltip text for accessibility |
14+
| Name | Type | Default | Description |
15+
| --------- | ----------------- | ------------------- | -------------------------------------------------------------------------------------------------------- |
16+
| `label` | `string` | required | The text displayed for the link |
17+
| `href` | `string` | required | The URL the link points to |
18+
| `icon` | `string \| false` | auto-detected | Icon class or `false` to disable. Auto-detects icons for common domains (GitHub, Discord, Twitter, etc.) |
19+
| `variant` | `string` | first: `nq-pill-blue`, rest: `nq-pill-secondary` | Pill variant: `blue`, `gold`, `green`, `secondary`, `tertiary`, `orange` |
20+
| `title` | `string` | `undefined` | Optional tooltip text for accessibility |
2121

2222
All links automatically open in a new tab with `target="_blank"` and include `rel="noopener noreferrer"` for security.
2323

@@ -130,6 +130,46 @@ Use different pill variants to color-code your links.
130130

131131
</ComponentPreview>
132132

133+
### Auto-Detected Domain Icons
134+
135+
Links automatically get appropriate icons based on their domain. Set `icon: false` to disable.
136+
137+
<ComponentPreview lang="vue">
138+
139+
<NqPlayground>
140+
<NqLinks :items="[
141+
{
142+
label: 'GitHub Repository',
143+
href: 'https://github.com/nimiq/ui'
144+
},
145+
{
146+
label: 'Discord Community',
147+
href: 'https://discord.gg/nimiq'
148+
},
149+
{
150+
label: 'Follow on Twitter',
151+
href: 'https://twitter.com/nimiq'
152+
},
153+
{
154+
label: 'No Icon Link',
155+
href: 'https://example.com',
156+
icon: false
157+
}
158+
]" />
159+
</NqPlayground>
160+
161+
</ComponentPreview>
162+
163+
#### Supported Domains
164+
165+
The following domains are automatically detected and assigned icons:
166+
167+
- **Nimiq**: `nimiq.com``i-nimiq:logos-nimiq-mono`
168+
- **GitHub**: `github.com``i-nimiq:logos-github-mono`
169+
- **Discord**: `discord.gg`, `discord.com``i-nimiq:logos-discord-mono`
170+
- **Twitter/X**: `twitter.com`, `x.com``i-nimiq:logos-twitter-mono`
171+
- **Telegram**: `telegram.org`, `t.me``i-nimiq:logos-telegram-mono`
172+
133173
## Usage Notes
134174

135175
- Use either `item` for a single link or `items` for multiple links, not both

packages/nimiq-vitepress-theme/src/components/NqLinks.vue

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,52 @@ import { computed } from 'vue'
44
interface NqLinksItem {
55
label: string
66
href: string
7-
icon?: string
7+
icon?: string | false
88
variant?: `nq-pill-${'blue' | 'gold' | 'green' | 'secondary' | 'tertiary' | 'orange'}`
99
title?: string
1010
}
1111
1212
const props = defineProps<{ item?: NqLinksItem, items?: NqLinksItem[] }>()
1313
14-
const items = computed(() => props.items?.length ? props.items : props.item ? [props.item] : [])
14+
const domainIconMap: Record<string, string> = {
15+
'nimiq.com': 'i-nimiq:logos-nimiq-mono',
16+
'github.com': 'i-nimiq:logos-github-mono',
17+
'discord.gg': 'i-nimiq:logos-discord-mono',
18+
'discord.com': 'i-nimiq:logos-discord-mono',
19+
'twitter.com': 'i-nimiq:logos-twitter-mono',
20+
'x.com': 'i-nimiq:logos-twitter-mono',
21+
'telegram.org': 'i-nimiq:logos-telegram-mono',
22+
't.me': 'i-nimiq:logos-telegram-mono',
23+
}
24+
25+
const items = computed(() => {
26+
const itemsList = props.items?.length ? props.items : props.item ? [props.item] : []
27+
28+
return itemsList.map((item) => {
29+
let detectedIcon: string | undefined
30+
31+
if (item.icon !== false && !item.icon) {
32+
// Auto-detect icon based on domain
33+
for (const [domain, icon] of Object.entries(domainIconMap)) {
34+
if (item.href.includes(domain)) {
35+
detectedIcon = icon
36+
break
37+
}
38+
}
39+
}
40+
41+
return {
42+
...item,
43+
icon: item.icon === false ? false : item.icon || detectedIcon,
44+
}
45+
})
46+
})
1547
</script>
1648

1749
<template>
1850
<div flex="~ gap-8" class="nq-raw">
19-
<a v-for="{ label, href, icon, title = label, variant = 'nq-pill-secondary' } in items" :key="href" :href :title target="_blank" rel="noopener noreferrer" nq-arrow f-text-xs mx-0 font-semibold z-100 :class="variant">
20-
<div v-if="icon" :class="icon" mr-4 />
51+
<a v-for="({ label, href, icon, title = label, variant }, index) in items" :key="href" :href :title target="_blank" rel="noopener noreferrer" nq-arrow f-text-xs mx-0 font-semibold z-100 :class="variant || (index === 0 ? 'nq-pill-blue' : 'nq-pill-secondary')">
52+
<div v-if="icon && icon !== false" :class="icon" mr-4 />
2153
{{ label }}
2254
</a>
2355
</div>

0 commit comments

Comments
 (0)