Fork me on GitHub
#fulcro
<
2023-01-16
>
Jakub Holý (HolyJak)17:01:13

In RAD, what I am doing wrong here in trying to use an icon for an action ?

ro/row-actions [{:label  (fn [_ {:thing/keys [id]}] (ui-icon {:key (str id) :name "trash"}))
? The action column is not displayed … I have require [com.fulcrologic.semantic-ui.elements.icon.ui-icon :refer [ui-icon]]

2
tony.kay17:01:06

any console errors?

tony.kay17:01:38

I’m doing a similar thing in my reports. Works fine. RAD Version? There were some places where I wasn’t doing labels right that I fixed a few versions ago

Jakub Holý (HolyJak)17:01:46

No error or warning. According to React Components view, the element is in dom just does not render anything visible..

tony.kay17:01:08

I’m using that exact icon (trash) in the code I’m looking at right now

Jakub Holý (HolyJak)17:01:28

Do I need to include it explicitly, is it not baked into semantic ui?

tony.kay17:01:33

icons are loaded from a theme

tony.kay17:01:41

it’s not just that one file

tony.kay17:01:50

The css does relative inclusions

Jakub Holý (HolyJak)17:01:00

the only css I have is semantic.min.css

tony.kay17:01:08

service from a CDN or locally?

tony.kay17:01:20

that’s your problem

Jakub Holý (HolyJak)17:01:48

right, I see url(themes/default/assets/fonts/icons.woff2) in the .css

tony.kay17:01:58

you can pull in the node module using package.json and mirror it from there, or follow their instructions for building a custom version that installs into local directories

tony.kay17:01:15

or use the CDN…that works

Jakub Holý (HolyJak)17:01:57

ah, not, sorry, it is from CDN: Request URL:

Jakub Holý (HolyJak)17:01:37

Ah, the icons are downloaded fine it seems Request URL: I priginally filtered only for css files 😅

Jakub Holý (HolyJak)18:01:21

In the html I see <i aria-hidden="true" class="trash icon"></i> which seems correct to me, so now figuring out what the issue is…

Jakub Holý (HolyJak)18:01:37

The only trash -related class applied to the element is

i.icon.trash:before {
    content: "\f1f8";
}
Not sure what \f1f8 is

tony.kay18:01:41

unicode character for the icon

tony.kay18:01:02

the icons are just font glyphs

Jakub Holý (HolyJak)18:01:05

somehow the font is not applied 😭

Jakub Holý (HolyJak)18:01:44

not sure what I am missing. This trivial page is displaying no icons either: The icons work in this minimalist example:

<html>
    <head><link type="text/css" rel="stylesheet" href="" /></head>
    <body><h1>Icon: <i class="edit icon"></i> / <i class="trash icon"></i></h1></body>
</html>
so I just need to find out what messes it up in my app.

Jakub Holý (HolyJak)19:01:26

Hm, something is wrong with the label. Having (dom/i :.trash.icon {:key "xxx"}) elsewhere in the app works fine but this:

ro/row-actions {:label  (fn [_ _] (dom/i :.trash.icon {:key "xxx"}))
                            :action ...}]
displays nothing. No warnings either (I expected React to complain about rpeated key)

Jakub Holý (HolyJak)19:01:18

FOUND IT! If I remove the class buttons from the parent div (ie. <div class="ui buttons"> -> <div class="ui"> then the icon shows up.

Jakub Holý (HolyJak)19:01:19

WRONG: `ro/row-actions [{:label (fn [ ] (i :.trash.icon {:key "xxx"})) …` CORRECT:

ro/row-actions  [{:label  (fn [_ _] (button :.ui.icon.button {:key "xxx"} (i :.trash.icon))) …

Jakub Holý (HolyJak)20:01:50

Ok, the saga does not end. @U0CKQ19AQ if I make a button icon label like ☝️ then clicking it will have no effect and will instead trigger the :event/select-row event. And here is why:

(if (string? label)
                    (dom/button :.ui.button {:key      idx
                                             :disabled disabled?
                                             :onClick  onClick}
                      label)
                    label)
so it makes sense - I provide an Element as the label, indicating I want to take full control of the, well, control 😅

Jakub Holý (HolyJak)20:01:56

I see that report-level controls support :icon param that makes this much simpler…

tony.kay20:01:37

correct the third arg of your row action for label includes the control itself, so you can grab action

tony.kay20:01:18

:label  (fn [this props {:keys [action]}]
                                           (su/icon
                                             {:name        "trash"
                                              :onClick     (fn [] (when action (action this props)))

🙏 2
Jakub Holý (HolyJak)20:01:40

Perhaps it would make sense to send PR to add :icon support to row action controls, just as we do for report controls?

tony.kay20:01:08

always open to PRs that round things out

👍 2
Jakub Holý (HolyJak)20:01:46

ro/row-actions docstring reads >

* `:label` : REQUIRED. A string or `(fn [report-instance row-props] string-or-element?)`.
i.e. does not mention the 3rd argument

tony.kay20:01:05

ok, so fix that too 😄

Jakub Holý (HolyJak)20:01:50

Will do. I guess it will also be so that only one of label / icon is required, i.e. if I provide icon I can omit label.

tony.kay20:01:43

So, one thing to consider but maybe the cat’s already out of the bag: in the case of label one can argue that it is sufficiently general to be a simple keyword. Once we move into icons it get a little more grey. I was trying to make things so general that you could use a text terminal library with RAD, and icons might be a no-go in some places. However, for assistive technologies unlabled icons are also a no-no, so I think label is always required, and icon is an optional UI-specific (possibly unsupported) option where in HTML-land it gets and aria-label if it is just an icon? But then what if you want a button with an icon and a label. Then you’re back to just doing a custom control with :label as a fn.

tony.kay20:01:31

meh. I kinda got tired of thinking of all the edge cases and have just been adding practical things as I go…but just throwing that out there so you at least have some context on a wider goal.

Jakub Holý (HolyJak)20:01:29

thank you for that! and it makes perfect sense.

Jakub Holý (HolyJak)20:01:44

I guess I will just follow what ActionButton does, i.e. (when icon ... )(when label label) though it would be nicer to support a hidden aria label as you rightly pointed out

Jakub Holý (HolyJak)20:01:14

Better to be consistently wrong than inconsistently and occasionally right 🙂

tony.kay20:01:13

I don’t know…gradual convergence to right sounds better to me 🙂

Jakub Holý (HolyJak)20:01:09

Eh, you are right …. again 😅 Maybe I need to think about it more overnight.

tony.kay20:01:03

you see why I’ve slowed down on dev. Running two business and trying to do this lift in open-source space is too much for one person 🙂

💯 2
Jakub Holý (HolyJak)21:01:08

::suo/report-row-button-renderer is wonderful and I will use it ❤️ That way I have 100% control of what is rendered, without too much typing for each control

Jakub Holý (HolyJak)22:01:45

https://github.com/fulcrologic/fulcro-i18n/blob/main/I18N.adoc#13-configuring-i18n mentions requiring com.fulcrologic.fulcro-i18n.icu-formatter :as icu] but I do see no such namespace there?! The solution was to upgrade from 0.0.5-alpha to 1.0.0 😅

Eva O23:01:18

I'm getting Use of undeclared Var error when I try to make a defsc-form use hooks:

(defsc-form Signup
  [_this _props]
  {fo/attributes [account/email
                  account/password
                  account/password-confirmation
                  account/first-name
                  account/birthday]
   fo/id account/id
   :use-hooks? true})

tony.kay15:01:04

hooks should work there. Need more data.

Eva O02:01:27

This is my error message:

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: [file location]/signup.cljc:64:13
--------------------------------------------------------------------------------
  61 |                                  :username email}))
  62 |     uism-env))
  63 | 
  64 | (defsc-form Signup
-------------------^------------------------------------------------------------
 Use of undeclared Var match-cloud.ui.account.signup/Signup
--------------------------------------------------------------------------------
  65 |   [this {::form/keys [errors] :ui/keys [active-step] :or {active-step 0} :as props}]
  66 |   {fo/attributes [account/email
  67 |                   account/password
  68 |                   account/password-confirmation
--------------------------------------------------------------------------------
[:cards] Build completed. (1725 files, 3 compiled, 1 warnings, 2.12s)

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: [file location]/signup.cljc:64:13
--------------------------------------------------------------------------------
  61 |                                  :username email}))
  62 |     uism-env))
  63 | 
  64 | (defsc-form Signup
-------------------^------------------------------------------------------------
 Use of undeclared Var match-cloud.ui.account.signup/Signup
--------------------------------------------------------------------------------
  65 |   [this {::form/keys [errors] :ui/keys [active-step] :or {active-step 0} :as props}]
  66 |   {fo/attributes [account/email
  67 |                   account/password
  68 |                   account/password-confirmation
--------------------------------------------------------------------------------

Eva O02:01:48

And then it doesn't render the form

Eva O02:01:25

Everything works fine when I get rid of :use-hooks?

Eva O03:01:07

I can use hooks in normal components and in reports. Just not forms.

Eva O03:01:22

RAD v1.3.13

tony.kay13:01:05

Hey, sorry, I got busy and didn’t have a chance to look at this. I know there is code in place for hooks support in forms, but I’m not sure I have any production code using the feature. I’ll try to look at it. The original form stuff was never meant to be used with hooks, and I added it somewhat recently. I’m sure I tested it then, but who knows maybe there is a regression.

tony.kay13:01:46

Fixed in fulcro-rad-1.4.4

🙌 2