I’ve been refactoring a Rails application that goes back 12+ years. I moved to Rail 7 and did a major revision a couple of years ago. I’m now in css hell. I’ve had css going back to Zurb foundation. That was removed but I still had a lot of W3-css and my own crap. I moved most of that to tailwind, but still have old css I’m trying to get rid of, or at least clean up.
I have all kind of buttons that I’m trying to make consistent - at least CRUD buttons. I finally figured out how to use tailwind components and added some simple buttons:
@layer components {
.bg-green1 {
@apply bg-green-400 hover:bg-green-700 hover:text-white border-2 border-green-600
}
.bg-orange1 {
@apply bg-amber-400 hover:bg-amber-600 hover:text-white border-2 border-amber-600
}
.bg-blue1 {
@apply bg-blue-400 hover:bg-blue-700 hover:text-white border-2 border-blue-700
}
.bg-red1 {
@apply bg-red-500 border-2 border-red-600 hover:text-white hover:bg-red-600
}
.btn-link {
@apply bg-green1 py-1 px-2 mr-1 rounded-md text-lg font-bold
}
.btn-send {
@apply bg-blue1 py-1 px-2 mr-1 rounded-md text-lg font-bold
}
.btn-warn {
@apply bg-orange1 py-1 px-2 mr-1 rounded-md text-lg font-bold
}
.btn-danger {
@apply bg-red1 py-1 px-2 mr-1 rounded-md text-lg font-bold
}
}
That gave me consistent buttons than I could put in a menubar. (I use slim)
div.gap-4.m-1
button[class="btn-link"] GreenComponent
button[class="btn-send"] BlueComponent
button[class="btn-warn"] OrangeComponent
button[class="btn-danger"] RedComponent
Everything was fine except the hover colors were off. Took a day or so until I found some css where a button was classed:
button:focus,
button:enabled:hover,
[role="button"]:focus,
[role="button"]:not([aria-disabled="true"]):hover,
input[type="submit"]:focus,
input[type="submit"]:enabled:hover,
input[type="reset"]:focus,
input[type="reset"]:enabled:hover,
input[type="button"]:focus,
input[type="button"]:enabled:hover {
filter: brightness(1.4);
cursor: pointer;
}
Copied that from someplace and it was screwing up my buttons. Just commented it out. I also used span or mark instead of button. I then ran into my next problem: button_to
In had a destroyTag helper I added after they removed the ujs confirm tag. Rails 7 fixed that with adding a data attributes. So i replaced my destroyTag helper with a simple button_to that confirms.
button_to(icon("fas fa-trash","Destroy Incomplete Game"),
game_path(@game),
method: :delete,
form: { data: { turbo_confirm: "Are You Sure?"}},
form_class:"btn-danger inline-block ")
That almost worked! It rendered a btn-danger button but it had a larger y padding than the padding{py-1} I specified.
Another day of so trying to figure that out. I’ve come to the conclussion that button_to has some vertical padding added. It was easy to fix, just added py-0 to the end of the form class.
As you can probably tell, I’m not very proficient with css.
Anyone else run into this?