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

Figure out the best way to have "components" and reusable styles #1

Open
scotttrinh opened this issue Dec 18, 2020 · 1 comment
Open

Comments

@scotttrinh
Copy link
Collaborator

scotttrinh commented Dec 18, 2020

TailwindCSS has a directive called @apply that takes a list of utility classes and generates the CSS that it would output, so you can use a class. You can see it here:

.kdl-section {
@apply py-10 px-2 md:px-4 prose prose-xl mx-auto;
}

However, I've heard that it is discouraged, and using the template language's component abstraction is better. Since we're using HTML (and Liquid) here, there isn't a place that is obvious to me for this component abstraction. There is Web Components, and full-fledged UI libraries like React/Vue/etc, but that all seems overkill.

For now, seems like @apply does the trick, but I wanted to open this question up to in case someone has some experience in this.

@scotttrinh
Copy link
Collaborator Author

Here is the portion of the Tailwind docs that talks about extracting components: https://tailwindcss.com/docs/extracting-components

It's very rare that all of the information needed to define a UI component can live entirely in CSS — there's almost always some important corresponding HTML structure you need to use as well.

For this reason, it's often better to extract reusable pieces of your UI into template partials or JavaScript components instead of writing custom CSS classes.

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

No branches or pull requests

1 participant