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

small devx changes for css / tailwind tooling #1264

Merged
merged 1 commit into from
Sep 7, 2022
Merged

Conversation

theoephraim
Copy link
Contributor

@theoephraim theoephraim commented Sep 6, 2022

did some digging into latest tooling and best practices for tailwind/css/etc.

Hopefully these small quality of life improvements will help make things easier and keep things tidy.

Some quick guidelines on tailwind classes:

  • try to keep tailwind classes in the template as much as possible
  • feel free to use clsx even when seems unnecessary as it will make adding more classes easier later
  • break up super long lists of classes into multiple lines, grouping things as appropriate (ex: static classes, dark mode, toggles based on state, etc)
  • dont copy paste classes if used multiple times in component, move to script as static var or computed (if dynamic) and use clsx and tw helpers
  • its OK to also add semantic classes with BEM-ish naming if it might be helpful in debugging what html belongs to which component
  • we may fall back to using css occasionally where it makes sense, but it should be very rare

@netlify
Copy link

netlify bot commented Sep 6, 2022

👷 Deploy request for system-init-corp pending review.

A Netlify team Owner will need to approve the deploy before you can run your build.

Are you a team Owner? Visit the deploys page to approve it

Need more help? Learn more in the Netlify docs

Name Link
🔨 Latest commit 7e7e245

@@ -55,3 +55,19 @@ This template should help get you started developing with Vue 3 and Typescript i
- Enable format on save (recommended)
- add `"editor.formatOnSave": true` to `.vscode/settings.json` file
- add `"[vue][typescript][javascript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }` to `.vscode/settings.json` file

### .vscode/settings.json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added full example of vscode settings file

class="appearance-none block px-3 py-2 border rounded-sm shadow-sm focus:outline-none sm:text-sm checked:bg-neutral-900 bg-neutral-600 indeterminate:bg-neutral-900"
:class="checkBoxClasses"
:class="
clsx(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just picked a random component with an long classes function to show an example of how clsx can help

<Icon name="minus" size="full" />
</div>

<Menu>
<MenuButton
as="div"
class="bg-white border-neutral-300 border text-black dark:bg-black dark:text-white dark:border-black text-center w-20 cursor-pointer mx-2 flex flex-col justify-center"
:class="
clsx(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

still helpeful, even if just breaking up lines, plus lets us quickly add more later

Copy link
Contributor

@nickgerace nickgerace left a comment

Choose a reason for hiding this comment

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

I like this better!

@theoephraim
Copy link
Contributor Author

bors merge

@si-bors-ng
Copy link
Contributor

si-bors-ng bot commented Sep 7, 2022

@si-bors-ng si-bors-ng bot merged commit c1517cd into main Sep 7, 2022
@si-bors-ng si-bors-ng bot deleted the theo/css-testing branch September 7, 2022 15:01
zacharyhamm pushed a commit that referenced this pull request Sep 7, 2022
1264: small devx changes for css / tailwind tooling r=theoephraim a=theoephraim

did some digging into latest tooling and best practices for tailwind/css/etc.

Hopefully these small quality of life improvements will help make things easier and keep things tidy.

- main tool is https://github.com/lukeed/clsx
- secondary is using a (noop) [string template tag function](https://www.freecodecamp.org/news/a-quick-introduction-to-tagged-template-literals-2a07fd54bc1d/) with IDE settings to get autocomplete on class lists outside of the template tag

Some quick guidelines on tailwind classes:
- try to keep tailwind classes in the template _as much as possible_
- feel free to use clsx even when seems unnecessary as it will make adding more classes easier later
- break up super long lists of classes into multiple lines, grouping things as appropriate (ex: static classes, dark mode, toggles based on state, etc)
- dont copy paste classes if used multiple times in component, move to script as static var or computed (if dynamic) and use `clsx` and `tw` helpers
- its OK to also add semantic classes with BEM-ish naming if it might be helpful in debugging what html belongs to which component
- we may fall back to using css occasionally where it makes sense, but it should be very rare

Co-authored-by: Theo Ephraim <theo@systeminit.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants