-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add button link as styles function, introduce tailwind-merge #593
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Link styled to look like a button. | ||
* | ||
* Currently, only the "ghost" variant is implemented. | ||
* | ||
* @function | ||
*/ | ||
|
||
import { twJoin, twMerge, type ClassNameValue } from 'tailwind-merge'; | ||
|
||
export type ButtonLinkVariant = 'ghost' | 'dark'; | ||
|
||
export interface ButtonLinkAttributes { | ||
variant?: ButtonLinkVariant; | ||
extraClasses?: ClassNameValue; | ||
} | ||
|
||
const BUTTON_LINK_CLASSES = | ||
'flex h-7.5 items-center gap-1.5 whitespace-nowrap px-3 py-1.5 text-xs'; | ||
|
||
const BUTTON_LINK_VARIANT_CLASSES = { | ||
ghost: 'text-default hover:bg-ghost-light active:bg-ghost-medium', | ||
dark: 'border border-gray-9 bg-gray-9 text-white hover:border-black hover:bg-black active:bg-[#000]', | ||
} as const; | ||
|
||
// Just export the classes option (I can handle overrides myself) | ||
export const BUTTON_LINK_GHOST = twJoin( | ||
BUTTON_LINK_CLASSES, | ||
BUTTON_LINK_VARIANT_CLASSES.ghost | ||
); | ||
|
||
export const BUTTON_LINK_DARK = twJoin( | ||
BUTTON_LINK_CLASSES, | ||
BUTTON_LINK_VARIANT_CLASSES.dark | ||
); | ||
|
||
// Give me a function to generate the classes function (allows overrides) | ||
export const buttonLinkStyles = ({ | ||
variant = 'ghost', | ||
extraClasses = '', | ||
}: ButtonLinkAttributes) => | ||
twMerge( | ||
BUTTON_LINK_CLASSES, | ||
BUTTON_LINK_VARIANT_CLASSES[variant], | ||
extraClasses | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
<script lang="ts"> | ||
import { uniqueId } from 'lodash-es'; | ||
import { | ||
provideNotify, | ||
useNotify, | ||
provideToast, | ||
ToastVariant, | ||
Badge, | ||
Banner, | ||
Breadcrumbs, | ||
Button, | ||
IconButton, | ||
buttonLinkStyles, | ||
CodeSnippet, | ||
ContextMenu, | ||
ContextMenuItem, | ||
ContextMenuSeparator, | ||
FloatingMenu, | ||
Icon, | ||
Label, | ||
Banner, | ||
IconButton, | ||
Input, | ||
Label, | ||
Modal, | ||
Multiselect, | ||
NotificationContainer, | ||
NumericInput, | ||
Pill, | ||
Switch, | ||
Progress, | ||
Radio, | ||
TabsBar, | ||
Tab, | ||
Tooltip, | ||
TooltipContainer, | ||
TooltipTarget, | ||
TooltipText, | ||
TextInput, | ||
NumericInput, | ||
RangeInput, | ||
RestrictedTextInput, | ||
SearchableSelect, | ||
Select, | ||
SliderInput, | ||
VectorInput, | ||
Switch, | ||
Tab, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHeaderCell, | ||
TableHeader, | ||
TableHeaderCell, | ||
TableRow, | ||
TabsBar, | ||
TextInput, | ||
ToastBanner, | ||
ToastContainer, | ||
ToastVariant, | ||
ToggleButtons, | ||
Select, | ||
SearchableSelect, | ||
Multiselect, | ||
NotificationContainer, | ||
provideNotify, | ||
provideToast, | ||
useNotify, | ||
Modal, | ||
CodeSnippet, | ||
RangeInput, | ||
Progress, | ||
Tooltip, | ||
TooltipContainer, | ||
TooltipTarget, | ||
TooltipText, | ||
VectorInput, | ||
BUTTON_LINK_GHOST, | ||
BUTTON_LINK_DARK, | ||
} from '$lib'; | ||
import { uniqueId } from 'lodash-es'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
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. Just some import sorting. |
||
provideNotify(); | ||
|
||
|
@@ -193,7 +197,6 @@ console.log(\`The FizzBuzz sequence for n = 15 is:\`); | |
console.log(sequence); // Outputs: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]`.trim(); | ||
|
||
const goSnippet = ` | ||
import "fmt" | ||
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 linter actually hates this, will fix later. |
||
|
||
// FizzBuzz | ||
// | ||
|
@@ -465,6 +468,123 @@ const onHoverDelayMsInput = (event: Event) => { | |
|
||
<NotificationContainer /> | ||
|
||
<div class="container mx-auto my-4 flex flex-col gap-8 p-4"> | ||
<h2 class="h-2">With a function</h2> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
rel="" | ||
class={buttonLinkStyles({})} | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing with an icon:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class={buttonLinkStyles({ variant: 'dark' })} | ||
> | ||
<Icon name="link" /> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this pink thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class={buttonLinkStyles({ extraClasses: 'text-pink-500' })} | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
</div> | ||
|
||
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 will create a better example if we decide to go this way. |
||
<div class="container mx-auto my-4 flex flex-col gap-8 p-4"> | ||
<h2 class="h-2">With class exports</h2> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
rel="" | ||
class={BUTTON_LINK_GHOST} | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing with an icon:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class={BUTTON_LINK_DARK} | ||
> | ||
<Icon name="link" /> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this pink thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class={twMerge(BUTTON_LINK_GHOST, 'text-pink-500')} | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
</div> | ||
|
||
<div class="container mx-auto my-4 flex flex-col gap-8 p-4"> | ||
<h2 class="h-2">With class definitions</h2> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
rel="" | ||
class="button-link-ghost" | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this cool thing with an icon:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class="button-link-dark" | ||
> | ||
<Icon name="link" /> | ||
My button link | ||
</a> | ||
</div> | ||
|
||
<div class="flex items-center gap-2"> | ||
<p class="text-xs">Check out this pink thing:</p> | ||
<a | ||
href="https://design.viam.com" | ||
target="_blank" | ||
class="button-link-ghost !text-pink-500" | ||
> | ||
My button link | ||
</a> | ||
</div> | ||
</div> | ||
|
||
<div class="container mx-auto my-4 flex flex-col gap-8 p-4"> | ||
<!-- Badge --> | ||
<h1 class="text-2xl">Badge</h1> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't look like anything here is related to
link
, should we just call this.button
? My assumption when looking at this name is that it's a special collection for link buttons, when it's just the primary button styles.