Read the statement by Michael Teeuw here.
Three module issues from a new user
-
I’ve figured it out!
Like the original post, I’m working with Calendar module. I wanted to understand why we could write, say symbol: “cloud” instead of having to declare the full “fas fa-fw fa-cloud” to invoke the symbol.
I went into /modules/default/calendar/calendar.js and noticed the following section of code:
const symbols = this.symbolsForEvent(event); symbols.forEach((s, index) => { const symbol = document.createElement("span"); symbol.className = "fas fa-fw fa-" + s; if (index > 0) { symbol.style.paddingLeft = "5px"; } symbolWrapper.appendChild(symbol); }); eventWrapper.appendChild(symbolWrapper); } else if (this.config.timeFormat === "dateheaders") { const blankCell = document.createElement("td"); blankCell.innerHTML = " "; eventWrapper.appendChild(blankCell); }
calendar.js is hardcoding the fas (solid) font family in, not allowing us to invoke a family like fab (brands). setting the line:
symbol.className = "fas fa-fw fa-" + s;
to just:
symbol.className = s;
forces us to redeclare every symbol in config.js from “cloud” to “fas fa-fw fa-cloud”, but we can now access all available FA icons.
And so, I get my leaf :)
Screen Shot 2022-04-28 at 17.37.44
-
@skyfall awesome
-
@skyfall I think we could fix that with a little smarter code, and not break existing modules
changesymbol.className = "fas fa-fw fa-" + s;
to
// if requested symbol name starts with 'fa-' , get the substring after 'fa-' // if not, use as is symbol.className = "fas fa-fw fa-" +(s.startsWith('fa-')?s.slice(3):s);
of course if the other icon names start with fa-, then u didn’t need any of this…
can u provide an example of the branded icon name?
-
I was using https://fontawesome.com/icons/canadian-maple-leaf?s=brands for example
I was thinking about how to fix this without breaking too; could just be an else if statement checking to see if it starts with “fab” or “fal”, otherwise keeping the fas hardcode. Would let us declare other families and keep the shorthand for the default fas configuration.
-
@skyfall oh, I see you have to call out fa-brands
hm…
maybe if the specific string has more than 1 word
like “fa-brands fa-iconname”
then you use as is (full string)
otherwise you use the default approach of appending the name to the ‘fa-’ already there// if there is a space in the name, 'collectionname iconname' use the string as is // for example "fa-brands fa-canadian-maple-leaf" // else use the current approach symbol.className =(s.indexOf(' ')>0?s:( "fas fa-fw fa-" +s));
this would let other prefix specific icons in, and not break old…
-
Yeah, there’s a few things to try and we can make it work without breaking default notation
I think one thing to keep in mind is MM seems to refer to them as “fab” instead of fa-brands; not sure where that translation happens.
I did see some of the commits from January that initially addresses this. I’m mobile right now so I don’t have the references, but it looked like this convention is used in more places than just calendar. Should be the same fix for all instances though.
I’ll experiment with it a bit too when I sit down to look.
-
@skyfall I found this post exactly because of that icon, lol
Have anyone made it work? changing fas to fal does the job for the Canadian maple leaf icon but breaks the others :(
-
@sdetweil said in Three module issues from a new user:
// if there is a space in the name, ‘collectionname iconname’ use the string as is
// for example “fa-brands fa-canadian-maple-leaf”
// else use the current approach
symbol.className =(s.indexOf(’ ')>0?s:( “fas fa-fw fa-” +s));This works perfectly in calendar, however in the CX3 module it does not work, apparently spaces are not allowed
-
it would have been nice if the fontawesome 4 prefixes weren’t hardcoded into the module sources/templates. Would have made changing the icons to something else in so much easier.
-
@kayakbabe I agree.
I went to line 448 and 449 of MMM-CalendarEXT3.js and edited this
exDom.classList.add('symbol', 'fa-solid') exDom.classList.add(...event.symbol.map((s) => {return 'fa-' + s}))
I did it once but since the update I had to reinstall the whole MagicMirror and lost the changes, I did not realized I did not backup that part of the code. I don’t remember what I did but I removed fa-solid and made something that changes fas and fab. based on config.js.
Very similar of what it’s explain on this topic, but I can’t make it work anymore. Sorry for diverting the thread. We should talk about this on a new post as I’m talking about an extension.
FontAwesome is already at version 6. It would be nice if MagicMirror in the future considers a flexible version in case of future updates, where you can choose in config.js if you want “fas” (by default) of “fab” :beaming_face_with_smiling_eyes:
-