Fork me on GitHub
#helix
<
2021-11-18
>
crankyadmin13:11:40

Hi, I’m trying to get headlessui working in my app using Helix.

crankyadmin13:11:47

(ns website.core
  (:require [helix.core :refer [defnc $ <>]]
            [helix.dom :as  d]
            ["react-dom" :as rdom]
            ["@headlessui/react" :refer [Switch]]))

(def switch-label  #(. Switch -Label))
(def switch-group #(. Switch -Group))

(defnc my-component []

  (switch-group
     (switch-label "Dooo")
     (Switch {:checked true
              :class "relative inline-flex items-center h-6 rounded-full w-11 bg-gray-200"})))

(defn ^:export start
  []
  (rdom/render ($ my-component) (js/document.getElementById "app")))

crankyadmin13:11:58

I know my Switch is missing a bunch of props but its getting switch-group and switch-label to play nicely.

crankyadmin13:11:01

So I guess my question comes down to this, how does one go about using a lib such as HeadlessUI in Helix?

crankyadmin13:11:43

Using

(def switch-label  (. Switch -Label))
(def switch-group (. Switch -Group))

(defnc my-component []

  (switch-group
     (switch-label "Foo")
     (Switch {:checked true
              :class "relative inline-flex items-center h-6 rounded-full w-11 bg-gray-200"})))

crankyadmin13:11:34

Results in this error

crankyadmin13:11:30

I’m idiot… ignore me. Just in case any one ever stumbles on this

crankyadmin13:11:33

(ns website.core
  (:require [helix.core :refer [defnc $ <>]]
            [helix.dom :as  d]
            ["react-dom" :as rdom]
            ["@headlessui/react" :as ui]))

(def switch-label ui/Switch.Label)
(def switch-group ui/Switch.Group)

(defnc my-component []

  
  ($ switch-group
    ($ switch-label "Hello?")
   ($ ui/Switch {:checked true
                :className "relative inline-flex items-center h-6 rounded-full w-11 bg-gray-200"})))

👏 4
1
lilactown16:11:49

nice! glad you figured it out

lilactown16:11:37

I recently used headlessui for their popover menu 😄 I felt ready to answer when I started reading and then you came to the conclusion already!