@@ -7,12 +7,11 @@ const props = withDefaults(
77 /** Disabled links will be displayed as plain text */
88 disabled?: boolean
99 /**
10- * `type` should never be used, because this will always be a link.
11- * */
12- type ?: never
13- variant ?: ' button-primary' | ' button-secondary' | ' link'
14- size ?: ' small' | ' medium'
15- block ?: boolean
10+ * Controls whether the link is styled as text or as a button.
11+ */
12+ type ?: ' button' | ' link'
13+ size ?: ' xs' | ' sm' | ' md' | ' lg'
14+ inline ?: boolean
1615
1716 ariaKeyshortcuts ?: string
1817
@@ -37,7 +36,7 @@ const props = withDefaults(
3736 noUnderline ?: boolean
3837 } & NuxtLinkProps
3938 > (),
40- { variant : ' link' , size: ' medium ' },
39+ { type : ' link' , size: ' md ' , inline: true },
4140)
4241
4342const isLinkExternal = computed (
@@ -50,47 +49,66 @@ const isLinkAnchor = computed(
5049 () => !! props .to && typeof props .to === ' string' && props .to .startsWith (' #' ),
5150)
5251
53- /** size is only applicable for button like links */
54- const isLink = computed (() => props .variant === ' link' )
55- const isButton = computed (() => ! isLink .value )
56- const isButtonSmall = computed (() => props .size === ' small' && ! isLink .value )
57- const isButtonMedium = computed (() => props .size === ' medium' && ! isLink .value )
52+ const isLink = computed (() => props .type === ' link' )
53+ const isButton = computed (() => props .type === ' button' )
54+ const sizeClass = computed (() => {
55+ if (isButton .value ) {
56+ switch (props .size ) {
57+ case ' xs' :
58+ return ' text-xs px-2 py-0.5'
59+ case ' sm' :
60+ return ' text-sm px-4 py-2'
61+ case ' md' :
62+ return ' text-base px-5 py-2.5'
63+ case ' lg' :
64+ return ' text-lg px-6 py-3'
65+ }
66+ }
67+
68+ switch (props .size ) {
69+ case ' xs' :
70+ return ' text-xs'
71+ case ' sm' :
72+ return ' text-sm'
73+ case ' md' :
74+ return ' text-base'
75+ case ' lg' :
76+ return ' text-lg'
77+ }
78+ })
5879 </script >
5980
6081<template >
6182 <span
6283 v-if =" disabled"
63- :class =" {
64- 'flex': block,
65- 'inline-flex': !block,
66- 'opacity-50 gap-x-1 items-center justify-center font-mono border border-transparent rounded-md':
67- isButton,
68- 'text-sm px-4 py-2': isButtonMedium,
69- 'text-xs px-2 py-0.5': isButtonSmall,
70- 'text-bg bg-fg': variant === 'button-primary',
71- 'bg-transparent text-fg': variant === 'button-secondary',
72- }"
84+ :class =" [
85+ inline ? 'inline-flex' : 'flex',
86+ sizeClass,
87+ {
88+ 'opacity-50 gap-x-1 items-center justify-center font-mono border border-transparent rounded-md':
89+ isButton,
90+ 'bg-transparent text-fg': isButton,
91+ },
92+ ]"
7393 ><slot
7494 /></span >
7595 <NuxtLink
7696 v-else
7797 class =" group/link gap-x-1 items-center"
78- :class =" {
79- 'flex': block,
80- 'inline-flex': !block,
81- 'underline-offset-[0.2rem] underline decoration-1 decoration-fg/30':
82- !isLinkAnchor && isLink && !noUnderline,
83- 'justify-start font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200':
84- isLink,
85- 'justify-center font-mono border border-border rounded-md transition-all duration-200':
86- isButton,
87- 'text-sm px-4 py-2': isButtonMedium,
88- 'text-xs px-2 py-0.5': isButtonSmall,
89- 'bg-transparent text-fg hover:(bg-fg/10 text-accent) focus-visible:(bg-fg/10 text-accent) aria-[current=true]:(bg-fg/10 text-accent border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
90- variant === 'button-secondary',
91- 'text-bg bg-fg hover:(bg-fg/50 text-accent) focus-visible:(bg-fg/50) aria-current:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':
92- variant === 'button-primary',
93- }"
98+ :class =" [
99+ inline ? 'inline-flex' : 'flex',
100+ sizeClass,
101+ {
102+ 'underline-offset-[0.2rem] underline decoration-1 decoration-fg/30':
103+ !isLinkAnchor && isLink && !noUnderline,
104+ 'justify-start font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200':
105+ isLink,
106+ 'justify-center font-mono border border-border rounded-md transition-all duration-200':
107+ isButton,
108+ 'bg-transparent text-fg hover:(bg-fg/10 text-accent) focus-visible:(bg-fg/10 text-accent) aria-[current=true]:(bg-fg/10 text-accent border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
109+ isButton,
110+ },
111+ ]"
94112 :to =" to"
95113 :aria-keyshortcuts =" ariaKeyshortcuts"
96114 :target =" isLinkExternal ? '_blank' : undefined"
0 commit comments