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

Conversation

DTCurrie
Copy link
Member

Proposing an idea here. We want to move the button link from app to prime, but after some recent conversations, I wonder if we instead just want to export a function to generate the styles for a button link. It will allow us to use the tools already built to support a native <a /> element, including things like autocompleting for rel and target, which our button link implementation limits. It also creates pretty easy-to-test little units.

Another thing I introduced was tailwind-merge, which works a lot like classnames but also merges tailwind classes down to avoid conflicting styles. With the way we use extraClasses this allows an easy way to actually override styles without having to use important tags.

Screenshot 2024-10-28 at 3 35 36 PM Screenshot 2024-10-28 at 3 37 25 PM Screenshot 2024-10-28 at 3 37 49 PM

} 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.

@@ -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.

</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.

pnpm-lock.yaml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't reviewed the rest of this PR yet but I wouldn't expect a 22k line diff for the pnpm-lock. pnpm dedupe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ran it, still getting those changes. Seems like it is bumping the lockfile version from 6.0 to 9.0 and doing any allowed minor/patch bumps on all dependencies. I freshly cloned the repo and installed so may be related to that.

Copy link
Member

@mcous mcous left a comment

Choose a reason for hiding this comment

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

I am very much in favor of this change, but I think for now, we should avoid tailwind-merge. From their docs:

Reasons not to use it

Generally speaking, there are situations where you could use tailwind-merge but probably shouldn't. Think of tailwind-merge as an escape hatch rather than the primary tool to handle style variants.1

I think for now we should keep Prime on classnames, and add tailwind-merge to the places where we need to do overrides. I imagine then that we can look at our twMerge callsites and use that to refine the APIs of our style functions

@DTCurrie
Copy link
Member Author

DTCurrie commented Oct 28, 2024

I am very much in favor of this change, but I think for now, we should avoid tailwind-merge. From their docs:

Reasons not to use it

Generally speaking, there are situations where you could use tailwind-merge but probably shouldn't. Think of tailwind-merge as an escape hatch rather than the primary tool to handle style variants.1

I think for now we should keep Prime on classnames, and add tailwind-merge to the places where we need to do overrides. I imagine then that we can look at our twMerge callsites and use that to refine the APIs of our style functions

I am okay with not doing it for now, but buttons and inputs are probably our most commonly overwritten components style-wise. It is hard to find all of the cases where we are using the important operator in use since the ! is so common.

I'd also argue that the usage here is kind of an escape hatch. Extra classes are the "I need to change the styles of this component, but it shouldn't require a new variant" lever we can pull. We could only use tailwind-merge for layering extra classes on to whatever variants we create with classnames, so it is only used when extra classes are applied.

@mcous
Copy link
Member

mcous commented Oct 28, 2024

I am okay with not doing it for now, but buttons and inputs are probably our most commonly overwritten components style-wise. It is hard to find all of the cases where we are using the important operator in use since the ! is so common.

Yeah definitely feeling the pain, and I think replacing ! usage with twMerge is a great idea, so I'm glad you've brought the library up. My only thought is that I think we could keep the escape hatch confined to our application code rather than our component library, so we can use it as a design signal to improve the component library

e.g. If we see <button class={twMerge(buttonStyles(), 'h-7.5')} >, we keep our fast velocity but also see that our buttonStyles function needs to grow a height option

@DTCurrie
Copy link
Member Author

I am okay with not doing it for now, but buttons and inputs are probably our most commonly overwritten components style-wise. It is hard to find all of the cases where we are using the important operator in use since the ! is so common.

Yeah definitely feeling the pain, and I think replacing ! usage with twMerge is a great idea, so I'm glad you've brought the library up. My only thought is that I think we could keep the escape hatch confined to our application code rather than our component library, so we can use it as a design signal to improve the component library

e.g. If we see <button class={twMerge(buttonStyles(), 'h-7.5')} >, we keep our fast velocity but also see that our buttonStyles function needs to grow a height option

Yeah that's fair.

@@ -15,3 +15,16 @@ button {
:host([hidden]) {
display: none;
}

/* Just give me the CSS classes option */
.button-link {
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants