Documentation to Implement TailwindUI
IIRC, there's a difference between the css used with the admin backend (via Administrate), which I dont think is Tailwind, versus what is in the rest of the app, which seems to be Tailwind or vanilla css. I have not had many challenges with the latter for that reason. One thing that did present a challenge was the JS being used to power various effects, but since TW 2.0 and updates to TWUI there has become easier. I did have to write a bit of JS to get certain effects to work right, but that was because I didnt have enough of a contemporary JS skillset so I had to fall back to jquery. I did have some webpackr issues, ugh those were a headache. And because there's leftover Administrate CSS, and Tailwind CSS, and my css files are very heavy but I'm just living with it until all of JSP uses TW. I don't feel I really *need* to make the admin backend prettier as long as I'm getting what I want from the front end
what sort of conflicts are you getting? any specifics?
what sort of conflicts are you getting? any specifics?
I dropped some sample TailwindUI components into a new view, and they were only partially styled. I've tried tweaking the
@import
setup in various files based on other tutorials I've come across, but it's still not right. CSS via Webpacker always confuses me, so I was hoping there was some setup documentation specific to TailwindUI I'd just missed.there isn't although I think this is something the TW experts are better at solving. I was frustrated for upwards of a month since it also involved JS from a few of the TW UI components, which used Stimulus. I eventually paid someone I found on the TW forums to solve it (it took him like 15 min -- to solve the problem you have to have expertise in Rails, Webpacker, and TW, as well as having a comfort level with JSP, and that combined was just too much of a hurdle for me). And I completely agree that I cannot fathom Webpacker nor how we got to the point where we put css files into sub-directories named "js". Nevertheless here we are. If you want, you can look at my code and hopefully it will help
let me ask him for permission first.
one thing that he did point out to me was: you know all those HTML comments you see in the TW components examples, such as:
`...
<!--
one thing that he did point out to me was: you know all those HTML comments you see in the TW components examples, such as:
`...
<!--
Off-canvas menu overlay, show/hide based on off-canvas menu state.
Entering: "transition-opacity ease-linear duration-300"
From: "opacity-0"
To: "opacity-100"
Leaving: "transition-opacity ease-linear duration-300"
From: "opacity-100"
To: "opacity-0"
-->
...`
those are all just classes you can apply to the element in question to cause those effects. Now, in more modern frameworks a lot of this is built in behind the scenes but even if you used the ancient workhorse jQuery, you can achieve the above with:
`
// when the hamburger is clicked
those are all just classes you can apply to the element in question to cause those effects. Now, in more modern frameworks a lot of this is built in behind the scenes but even if you used the ancient workhorse jQuery, you can achieve the above with:
`
// when the hamburger is clicked
$('#mobile-sidebar-el0').toggle()
$('#mobile-sidebar-el1').toggle()
$('#mobile-sidebar-el2').toggle()
await new Promise(r => setTimeout(r, 100))
$('#mobile-sidebar-el1').addClass('opacity-100').removeClass('opacity-0')
// note we never remove the translate-x-0 class, we just add/remove the -translate-x-full class
// otherwise the transition effect is jarring
$('#mobile-sidebar-el2').removeClass('-translate-x-full')
`
and the DOM needs a tiny bit of time for the toggles and such to "take" hence the `setTimeout()`
That was just enough of a point in the right direction from him that I could implement everything I needed from the TW components based on what I knew of jQuery from a while back. I'm sure it's valuable and long-term smart to add additional skills like Stimulus to one's toolbox, but it's also valuable to be able to get something up and running in a few hours.
So I hope that points you in the right direction
and the DOM needs a tiny bit of time for the toggles and such to "take" hence the `setTimeout()`
That was just enough of a point in the right direction from him that I could implement everything I needed from the TW components based on what I knew of jQuery from a while back. I'm sure it's valuable and long-term smart to add additional skills like Stimulus to one's toolbox, but it's also valuable to be able to get something up and running in a few hours.
So I hope that points you in the right direction
I was having some of these issue, I had to make webpacker recompile for these styles to work.
If the styles you are adding has more colors like indigo you can add it to the tailwind config file
If the styles you are adding has more colors like indigo you can add it to the tailwind config file
app
/
javascript
/
stylesheets
/
tailwind.config.js
which will also cause webpacker to recompile, I have even added comments just to have it recompile, probably a better way but would do the trick theme: {
| // Extend (add to) the default theme in the `extend` key
| extend: {
| // Create your own at: https://javisperez.github.io/tailwindcolorshades
| colors: {
| teal: colors.teal,
orange: colors.orange,
indigo: colors.indigo,
| 'primary': {
| 50: '#F6F7FF',
| 100: '#EDF0FE',
| 200: '#D2D9FD',
| 300: '#B6C1FB',
| 400: '#8093F9',
| 500: '#4965F6',
| 600: '#425BDD',
| 700: '#2C3D94',
| 800: '#212D6F',
| 900: '#161E4A',
| },
| // Extend (add to) the default theme in the `extend` key
| extend: {
| // Create your own at: https://javisperez.github.io/tailwindcolorshades
| colors: {
| teal: colors.teal,
orange: colors.orange,
indigo: colors.indigo,
| 'primary': {
| 50: '#F6F7FF',
| 100: '#EDF0FE',
| 200: '#D2D9FD',
| 300: '#B6C1FB',
| 400: '#8093F9',
| 500: '#4965F6',
| 600: '#425BDD',
| 700: '#2C3D94',
| 800: '#212D6F',
| 900: '#161E4A',
| },
app
/
javascript
/
stylesheets
/
tailwind.config.js
like text-primary-500 don't work. I'm having the same issue integrating Tailwind UI into Jumpstart. I was hoping for an easy way to just drop in Tailwind UI elements, but they're not working as expected.
An explanation of how to integrate Tailwind UI into Jumpstart, so we can just drop those components in would be very helpful.
An explanation of how to integrate Tailwind UI into Jumpstart, so we can just drop those components in would be very helpful.
Here is my solution so far (which seems to work for me). My desired solution was to have "drop in" functionality for Tailwind UI.
I'm working on a Mac, so your milage may very...
Step 1: I used yarn to install the latest version of tailwindui
I'm working on a Mac, so your milage may very...
Step 1: I used yarn to install the latest version of tailwindui
yarn add @tailwindcss/ui
Step 2: In app/javascript/stylesheets/tailwind.config.js, I updated my plugins array to look like this,plugins: [ require('@tailwindcss/ui'), require('@tailwindcss/aspect-ratio'), require('@tailwindcss/forms'), require('@tailwindcss/line-clamp'), require('@tailwindcss/typography') ],
* Note, for some reason it was important that I added '@tailwindcss/ui' first.
Step 3: Lastly, in app/javascript/stylesheets/components.scss I commented out the component styles I didn't want from jumpstart rails, because they are the ones interfering with Tailwind UI.
Here is an example of my components.scss file,
Step 3: Lastly, in app/javascript/stylesheets/components.scss I commented out the component styles I didn't want from jumpstart rails, because they are the ones interfering with Tailwind UI.
Here is an example of my components.scss file,
@import 'tailwindcss/components'; @import "components/base"; //@import "components/actiontext"; //@import "components/alert"; //@import "components/animation"; //@import "components/announcements"; @import "components/avatars"; //@import "components/buttons"; //@import "components/code"; //@import "components/connected_accounts"; //@import "components/direct_uploads"; //@import "components/docs"; //@import "components/forms"; //@import "components/icons"; //@import "components/iframe"; //@import "components/nav"; //@import "components/pagination"; //@import "components/tabs"; //@import "components/trix"; //@import "components/typography"; @import "components/util";
You'll see that I'm keeping the "avatars" component styles provided by Jumpstart, because I liked it better than Tailwind UI.
Final note, this will remove a lot of the default styles you see with Jumpstart. So you'll have to make sure you're ok with switching primary to the Tailwind UI components throughout the app.
Thanks
Brent
. I came up with a similar solution except I didn't need to place
I also did comment out the
I think you're also new to JSP like me. It would be great to connect with you on LinkedIn.
require('@tailwindcss/ui')
before other require
statements, and the components seem to be working fine for me.I also did comment out the
@import "components/base";
statement in app/javascript/stylesheets/components.scss
, as it was interfering with the look and feel of the TailwindUI elements, but I'm guessing you already know about it.I think you're also new to JSP like me. It would be great to connect with you on LinkedIn.
I'm having many of the issues mentioned in this thread while trying to get tailwindUI to work. My JSP template has an
Rahul Gulati
Brent
did you both have to create this directory, or did it exist for you already?
The default JSP template (as of 10/20/2021) does not seem to have the
I'm about 9 hours in trying to figure out how to override JSP default styles now and not sure what else to do at this point. Wondering if my issues are related to the recent JSP move to Rails CSS & JS bundling packages.
Any thoughts/help is appreciated.
app/assets/stylesheets/application.tailwind.css
app/javascript
directory but does not have an app/javascript/stylesheets
directory. The default JSP template (as of 10/20/2021) does not seem to have the
app/javascript/stylesheets
directory structure and the tailwind.config.js
is located in the root. Did you have to move/relocate this?I'm about 9 hours in trying to figure out how to override JSP default styles now and not sure what else to do at this point. Wondering if my issues are related to the recent JSP move to Rails CSS & JS bundling packages.
Any thoughts/help is appreciated.
app/assets/stylesheets/application.tailwind.css
@import "tailwindcss/base"; @import "tailwindcss/components"; /* * Jumpstart Pro default styles * Remove these if you'd like to use TailwindUI which expects a clean slate */ @import "tailwindcss/utilities"; @import "tippy.js/dist/tippy.css"; @import "flatpickr/dist/flatpickr.css";
root/tailwind.config.js
// See the Tailwind default theme values here: // https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js const colors = require('tailwindcss/colors') const defaultTheme = require('tailwindcss/defaultTheme') module.exports = { // https://tailwindcss.com/docs/just-in-time-mode mode: 'jit', plugins: [ require('@tailwindcss/aspect-ratio'), require('@tailwindcss/forms')({ strategy: 'class' }), require('@tailwindcss/line-clamp'), require('@tailwindcss/typography'), ], purge: [ './app/helpers/**/*.rb', './app/javascript/**/*.js', './app/views/**/*.erb', './lib/jumpstart/app/views/**/*.erb', './lib/jumpstart/app/helpers/**/*.rb', ], // All the default values will be compiled unless they are overridden below theme: { // Extend (add to) the default theme in the `extend` key extend: { // Create your own at: https://javisperez.github.io/tailwindcolorshades colors: { //orange: colors.orange, transparent: 'transparent', current: 'currentColor', black: colors.black, white: colors.white, gray: colors.trueGray, indigo: colors.indigo, red: colors.rose, yellow: colors.amber, primary: colors.blue, secondary: colors.emerald, tertiary: colors.gray, danger: colors.red, "code-400": "#fefcf9", "code-600": "#3c455b", }, fontFamily: { sans: ['Inter', ...defaultTheme.fontFamily.sans], }, }, }, variants: { borderWidth: ['responsive', 'last', 'hover', 'focus'], }, // Opt-in to TailwindCSS future changes future: { }, }
pacakage.json
{ "name": "jumpstart-app", "private": true, "dependencies": { "@hotwired/stimulus": "^3.0.0", "@hotwired/turbo-rails": "^7.0.0-beta.5", "@rails/actioncable": "^6.1.4", "@rails/actiontext": "^6.1.4", "@rails/activestorage": "^6.1.4", "@rails/request.js": "^0.0.5", "@rails/ujs": "^6.1.4", "@tailwindcss/aspect-ratio": "^0.3.0", "@tailwindcss/forms": "^0.3.2", "@tailwindcss/line-clamp": "^0.2.0", "@tailwindcss/typography": "^0.4.0", "@tailwindcss/ui": "^0.7.2", "autoprefixer": "^10.3.4", "clipboard": "^2.0.8", "esbuild": "^0.13.0", "esbuild-rails": "^1.0.3", "flatpickr": "^4.6.9", "glob": "^7.1.7", "js-cookie": "^3.0.0", "jstz": "^2.1.1", "local-time": "^2.1.0", "postcss": "^8.3.6", "postcss-import": "^14.0.1", "slim-select": "^1.27.0", "stimulus-flatpickr": "^3.0.0-0", "tailwindcss": "^2.2.15", "tailwindcss-stimulus-components": "^3.0.0", "tippy.js": "^6.3.1", "tributejs": "^5.1.3", "trix": "^1.3.1" }, "scripts": { "build:css": "tailwindcss --postcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css", "build": "node esbuild.config.js" } }
app/assets/stylesheets/application.tailwind.css
As you can see in package.json you pasted:
"build:css": "tailwindcss --postcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"
TailwindUI expects a completely blank UI, so no styling at all. You can comment out the Jumpstart styles in that file if you want to start with a blank slate.
I personally just add TailwindUI components along with the Jumpstart styles and tweak them as necessary (like removing list item styles when necessary). Up to you.
Read up on the CSSBundling-Rails gem if you want to learn more about how it works. Jumpstart Pro doesn't do anything fancy at all, just uses the base configuration. 👍
I personally just add TailwindUI components along with the Jumpstart styles and tweak them as necessary (like removing list item styles when necessary). Up to you.
Read up on the CSSBundling-Rails gem if you want to learn more about how it works. Jumpstart Pro doesn't do anything fancy at all, just uses the base configuration. 👍
Thanks, that stuff is a black box to me so will read up now that I know where to look.
You can comment out the Jumpstart styles in that file if you want to start with a blank slate.
You mean in app/assets/stylesheets/application.tailwind.css? If so, I thought I did. Should I have done/do something different?
@import "tailwindcss/base";
@import "tailwindcss/components";
/*
* Jumpstart Pro default styles
* Remove these if you'd like to use TailwindUI which expects a clean slate
*/
@import "tailwindcss/utilities";
@import "tippy.js/dist/tippy.css";
@import "flatpickr/dist/flatpickr.css";
Easy enough for me to tweak TaiwindUI templates where needed either way. Thanks.
Adding tailwindui doesn't seem as simple as uncommenting the JSP styles :(.
First the JSP styles define a few Bootstrap-like CSS classes that you then have to recreate using tailwind (like .btn).
Second the page structure of some tailwindui elements won't fit the site structure of JSP. This means further rework: creating new layouts and rewriting partials (including their variants).
Third the JSP css (unless you completely uncommented it) doesn't honor your tailwind theme. For example changing your primary color in the tailwind config will not change anything. Maybe JSP could at least use the colors defined in the theme (i.e. bg-primary-500 instead of bg-blue-500)?
After all, it would be too much to ask of JSP to make styling your app with tailwindui any easier. It will simply cost some effort to get your own look and JSP is just here as a starting point. But maybe a future version of JSP could offer tailwindcss as an option, so we don't have to change as many files to get started :).
First the JSP styles define a few Bootstrap-like CSS classes that you then have to recreate using tailwind (like .btn).
Second the page structure of some tailwindui elements won't fit the site structure of JSP. This means further rework: creating new layouts and rewriting partials (including their variants).
Third the JSP css (unless you completely uncommented it) doesn't honor your tailwind theme. For example changing your primary color in the tailwind config will not change anything. Maybe JSP could at least use the colors defined in the theme (i.e. bg-primary-500 instead of bg-blue-500)?
After all, it would be too much to ask of JSP to make styling your app with tailwindui any easier. It will simply cost some effort to get your own look and JSP is just here as a starting point. But maybe a future version of JSP could offer tailwindcss as an option, so we don't have to change as many files to get started :).
I don't know about y'all but its been pretty easy. Mind you TailwindUI still uses some old stuff where JSP is on tailwind3.
You can comment out the css in JSP and use them in the HTML or override them in the css file to what you want. As an example this is something I am working on using tailwind.
You can comment out the css in JSP and use them in the HTML or override them in the css file to what you want. As an example this is something I am working on using tailwind.
Notifications
You’re not receiving notifications from this thread.