excid3 / tailwindcss-stimulus-components

A set of StimulusJS components for TailwindCSS apps similar to Bootstrap JS components.
https://excid3.github.io/tailwindcss-stimulus-components/
MIT License
1.38k stars 138 forks source link

Alert example throws error: v3.0.3 & Stimulus v3.01 #135

Closed mrjonesbot closed 1 year ago

mrjonesbot commented 2 years ago

Error is thrown on connect and on click action.

Screen Shot 2022-01-31 at 10 55 35 PM
excid3 commented 2 years ago

Can you click on that line in Stimulus.js and share what that is? Curious where it's falling over inside Stimulus. Looks to be the classes API.

mrjonesbot commented 2 years ago

@excid3

Screen Shot 2022-02-01 at 9 02 21 AM
excid3 commented 2 years ago

According to the docs, we're using that properly? https://stimulus.hotwired.dev/reference/css-classes#properties

mrjonesbot commented 2 years ago

I think it's because the example doesn't declare a class for the controller to use in the HTML, like:

data-search-loading-class="bg-gray-500 animate-spinner cursor-busy">

At least, that's what it looks like in the docs.

Screen Shot 2022-02-01 at 9 24 49 AM

Declare a css class reference, then declare the class on the data attribute.

excid3 commented 2 years ago

Ah, so maybe its undefined or null instead of an empty array?

excid3 commented 2 years ago

Removing the classes on the first alert example correctly gave me [] and the other is an array as well.

Screen Shot 2022-02-01 at 12 00 32 PM

Looks like it's working correctly?

Are you using @hotwired/stimulus

mrjonesbot commented 2 years ago

Yep

Screen Shot 2022-02-01 at 12 02 52 PM

Does it matter what version of Rails I'm on?

Going to clear my yarn cache and see if that resolves the issue.

I'm still not seeing the data-attribute mapping for these classes in the example though.

excid3 commented 2 years ago

Hmm, I guess can you stick a console.log() in the node_modules and see if it's not an array for your example?

mrjonesbot commented 2 years ago

I wish I could just start over on Rails 7 lmao

When I dig into my node_modules, propertiesForClassDefinition is not matching the current version somehow.

Screen Shot 2022-02-01 at 1 11 46 PM

I was importing Stimulus from the wrong package, so let me update those refs and get back to you.

mrjonesbot commented 2 years ago

Ok so, I updated my references and received a fun new error.

app/javascript/controllers/index.js

// Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.

import { Application } from "@hotwired/stimulus"
import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
import { Autocomplete } from 'stimulus-autocomplete'

const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))

application.register('autocomplete', Autocomplete)

import { Alert, Dropdown, Modal, Tabs, Popover, Toggle, Slideover } from "tailwindcss-stimulus-components"
application.register('alert', Alert)
application.register('dropdown', Dropdown)
application.register('modal', Modal)
application.register('tabs', Tabs)
application.register('popover', Popover)
application.register('toggle', Toggle)
application.register('slideover', Slideover)

import Flatpickr from 'stimulus-flatpickr'
application.register('flatpickr', Flatpickr)

import StimulusReflex from 'stimulus_reflex'
import consumer from '../channels/consumer'
import controller from './application_controller'
StimulusReflex.initialize(application, { consumer, controller, debug: false })

Screen Shot 2022-02-01 at 1 16 42 PM

Screen Shot 2022-02-01 at 1 17 45 PM

mrjonesbot commented 2 years ago

Ok it actually looks like my install of StimulusReflex is causing issues with my controllers, since I'm in the process of ripping it out anyways, I'm going to do that and circle back.