-
-
Notifications
You must be signed in to change notification settings - Fork 427
refactor: remove unnecessary prop from links #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
f305156
37412df
51b4fd5
a544c36
45a1a2f
57f81b0
322495f
86242b9
1d1e74f
65bc1c3
af56682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,8 @@ const props = withDefaults( | |
| * `type` should never be used, because this will always be a link. | ||
| * */ | ||
| 'type'?: never | ||
| 'variant'?: 'button-primary' | 'button-secondary' | 'link' | ||
| 'variant'?: 'button-primary' | 'button-secondary' | 'link' | 'link-block' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mix responsibilities. The prop should be responsible for a specific area
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know what you mean. This goes back to my previous comment: Adding another prop, that is only relevant for a certain variant is also not the best design. Again: probably best to split the component. Would you be fine with this as an intermediate solution?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's call this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, missed comment
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I see. Just one thing: Would it default to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, just noticed buttons are currently inline as well. Ok I'll have a go on it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point isn't that there are so many options, but that they're for completely different purposes. In your set of conditions below, you can see what you're using for what. Essentially, you're generating several other props from this one And this list of conditions below is actually more logical for DX, and that's what you came up with. We're more comfortable writing and working with a component when we clearly understand what the result will be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also pretty standard practice when it's responsible for a narrow section: disabled, autocorrect, checked, hidden, open. It's probably even more standard in Vue, since it's positioned as closer to the HTML
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, never would have liked to set |
||
| 'size'?: 'small' | 'medium' | ||
| 'iconSize'?: 'sm' | 'md' | 'lg' | ||
|
|
||
| 'keyshortcut'?: string | ||
|
|
||
|
|
@@ -52,28 +51,21 @@ const isLinkAnchor = computed( | |
| () => !!props.to && typeof props.to === 'string' && props.to.startsWith('#'), | ||
| ) | ||
|
|
||
| const ICON_SIZE_MAP = { | ||
| sm: 'size-3 min-w-3', | ||
| md: 'size-4 min-w-4', | ||
| lg: 'size-5 min-w-5', | ||
| } | ||
|
|
||
| /** size is only applicable for button like links */ | ||
| const isLink = computed(() => props.variant === 'link') | ||
| const isButton = computed(() => props.variant !== 'link') | ||
| const isButtonSmall = computed(() => props.size === 'small' && props.variant !== 'link') | ||
| const isButtonMedium = computed(() => props.size === 'medium' && props.variant !== 'link') | ||
|
|
||
| const iconSizeClass = computed( | ||
| () => ICON_SIZE_MAP[props.iconSize || (isButtonSmall.value && 'sm') || 'md'], | ||
| ) | ||
| const isLink = computed(() => props.variant === 'link' || props.variant === 'link-block') | ||
| const isButton = computed(() => !isLink.value) | ||
| const isButtonSmall = computed(() => props.size === 'small' && !isLink.value) | ||
| const isButtonMedium = computed(() => props.size === 'medium' && !isLink.value) | ||
| const isBlock = computed(() => isButton.value || props.variant === 'link-block') | ||
|
alexdln marked this conversation as resolved.
Outdated
|
||
| </script> | ||
|
|
||
| <template> | ||
| <span | ||
| v-if="disabled" | ||
| :class="{ | ||
| 'opacity-50 inline-flex gap-x-1 items-center justify-center font-mono border border-transparent rounded-md': | ||
| 'flex': isBlock, | ||
| 'inline-flex': !isBlock, | ||
| 'opacity-50 gap-x-1 items-center justify-center font-mono border border-transparent rounded-md': | ||
| isButton, | ||
| 'text-sm px-4 py-2': isButtonMedium, | ||
| 'text-xs px-2 py-0.5': isButtonSmall, | ||
|
|
@@ -84,12 +76,15 @@ const iconSizeClass = computed( | |
| /></span> | ||
| <NuxtLink | ||
| v-else | ||
| class="group/link inline-flex gap-x-1 items-center justify-center" | ||
| class="group/link gap-x-1 items-center" | ||
| :class="{ | ||
| 'flex': isBlock, | ||
| 'inline-flex': !isBlock, | ||
|
essenmitsosse marked this conversation as resolved.
Outdated
|
||
| 'underline-offset-[0.2rem] underline decoration-1 decoration-fg/30': !isLinkAnchor && isLink, | ||
| 'font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200': | ||
| 'justify-start font-mono text-fg hover:(decoration-accent text-accent) focus-visible:(decoration-accent text-accent) transition-colors duration-200': | ||
| isLink, | ||
| 'font-mono border border-border rounded-md transition-all duration-200': isButton, | ||
| 'justify-center font-mono border border-border rounded-md transition-all duration-200': | ||
| isButton, | ||
| 'text-sm px-4 py-2': isButtonMedium, | ||
| 'text-xs px-2 py-0.5': isButtonSmall, | ||
| 'bg-transparent text-fg hover:(bg-fg/10) focus-visible:(bg-fg/10)': | ||
|
|
@@ -100,22 +95,22 @@ const iconSizeClass = computed( | |
| :aria-keyshortcuts="keyshortcut" | ||
| :target="isLinkExternal ? '_blank' : undefined" | ||
| > | ||
| <span v-if="classicon" class="me-1" :class="[iconSizeClass, classicon]" aria-hidden="true" /> | ||
| <span v-if="classicon" class="size-[1em]" :class="classicon" aria-hidden="true" /> | ||
| <slot /> | ||
| <!-- automatically show icon indicating external link --> | ||
| <span | ||
| v-if="isLinkExternal && !classicon" | ||
| class="i-carbon:launch rtl-flip w-3 h-3 opacity-50" | ||
| class="i-carbon:launch rtl-flip size-[1em] opacity-50" | ||
| aria-hidden="true" | ||
| /> | ||
| <span | ||
| v-else-if="isLinkAnchor && isLink" | ||
| class="i-carbon:link w-3 h-3 opacity-0 group-hover/link:opacity-100 transition-opacity duration-200" | ||
| class="i-carbon:link size-[1em] opacity-0 group-hover/link:opacity-100 transition-opacity duration-200" | ||
| aria-hidden="true" | ||
| /> | ||
| <kbd | ||
| v-if="keyshortcut" | ||
| class="ms-2 inline-flex items-center justify-center w-4 h-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline" | ||
| class="ms-2 inline-flex items-center justify-center size-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline" | ||
| aria-hidden="true" | ||
| > | ||
| {{ keyshortcut }} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.