Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"lodash-es": "^4.17.21",
"nanoid": "^5.0.4",
"prism-themes": "^1.9.0",
"prismjs": "^1.29.0"
"prismjs": "^1.29.0",
"tailwind-merge": "^2.5.4"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/lib/button/button-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Link styled to look like a button.
*
* Currently, only the "ghost" variant is implemented.
*
* @function
*/

import { 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;

export const buttonLinkStyles = ({
variant = 'ghost',
extraClasses = '',
}: ButtonLinkAttributes) =>
twMerge(
BUTTON_LINK_CLASSES,
BUTTON_LINK_VARIANT_CLASSES[variant],
extraClasses
);
5 changes: 5 additions & 0 deletions packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export { default as Badge } from './badge.svelte';
export { Banner, BannerVariant, type BannerVariantType } from './banner';
export { default as Breadcrumbs } from './breadcrumbs.svelte';
export { default as Button } from './button/button.svelte';
export {
buttonLinkStyles,
type ButtonLinkAttributes,
type ButtonLinkVariant,
} from './button/button-link';
export { default as IconButton } from './button/icon-button.svelte';
export { clickOutside } from './click-outside';
export { default as CodeSnippet } from './code-snippet.svelte';
Expand Down
94 changes: 66 additions & 28 deletions packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
<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,
} from '$lib';
import { uniqueId } from 'lodash-es';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some import sorting.

provideNotify();

Expand Down Expand Up @@ -193,7 +194,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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter actually hates this, will fix later.


// FizzBuzz
//
Expand Down Expand Up @@ -465,6 +465,44 @@ const onHoverDelayMsInput = (event: Event) => {

<NotificationContainer />

<div class="container mx-auto my-4 flex flex-col gap-8 p-4">
<h2 class="h-2">New stuff!</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"
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>

Copy link
Member Author

Choose a reason for hiding this comment

The 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">
<!-- Badge -->
<h1 class="text-2xl">Badge</h1>
Expand Down
Loading
Loading