getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

[typhoon] LangSwitcher CSS for Typhoon? #110

Closed key-notes closed 3 years ago

key-notes commented 3 years ago

Could anyone perhaps provide the CSS needed to implement the LangSwitcher plugin with the Typhoon theme? Many thanks in advance.

rhukster commented 3 years ago

While I want to do a better integrated solution, a quick fix is to do this:

First, rather than making changes directly to tailwind that will be lost with an update, you should create a copy of tailwind using the devtools plugin. (more info: https://getgrav.org/premium/typhoon/docs#create-a-custom-theme-from-typhoon)

Assuming you have done this, you will need to be 'watching' for custom CSS changes, so install the npm dependencies and run the watch command: https://getgrav.org/premium/typhoon/docs#installing-npm-to-compile-css

Then, you can add some simple CSS to the css/custom/plugins.css file. At the bottom add:

/* LANGSWITCHER PLUGIN */
ul.langswitcher {
    @apply flex h-16 mr-8;
    li {
        @apply inline-flex ml-4 text-sm items-center pt-1 font-medium;
    }
}
/* END LANGSWITCHER */

On saving you should see some output about compilation where you ran your npm run watch command.

This should be enough to give the langswitcher styling to integrate with the menu:

CleanShot 2021-06-15 at 12 23 59@2x

NOTE: Make sure you have disabled the built-in CSS for langswitcher as that will only conflict.

key-notes commented 3 years ago

Thanks for these detailed instructions. I upgraded nvm on my server and created a child theme, but the site returns the error:

"An exception has been thrown during the rendering of a template ("HEX color needs to be 6 or 3 digits long")."

Apparently this is triggered by line 7 of /user/themes/typhoon/templates/partials/theme-variables.html.twig:

{% set primary_color = color(theme_var('colors.primary')) %}

Another user experienced the same error, and from your reply it seems this is an issue with devtools:

Will this be fixed soon? Is there anything I can do on my end?

key-notes commented 3 years ago

Thanks so much for these detailed instructions. I was able to do most of these tasks, though "npm run watch" returns this output:

[ps473904]$ npm run watch npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /home/dh_4nhwym/grav/user/themes/typhoon-child-theme/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open '/home/dh_4nhwym/grav/user/themes/typhoon-child-theme/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in: npm ERR! /home/dh_4nhwym/.npm/_logs/2021-06-16T07_11_56_549Z-debug.log

There's a "package-lock.json" file in this directory, but no "package.json".

Any ideas?

key-notes commented 3 years ago

Got it working! The problem was that I had used "inheritance" rather than "copy" for the theme.

One thing I don't understand now is: What happens when Typhoon is updated? Since I now made a full copy, wouldn't I need to copy the updated Typhoon theme and redo all my changes from scratch every time the theme is updated? I thought "inheritance" mode was meant to solve this problem, so I don't understand why making a full copy is necessary.

Also, "npm run watch" is now working in the SSH terminal. But won't that stop the moment I close the terminal? Shouldn't it continue running on the server?

key-notes commented 3 years ago

Update: I copied the Typhoon theme and am modifying the copy. npm run watch is working, but it somehow doesn't respond to updates to plugins.css. I ran the command in /user/themes/typhoon-customized.

As long as the LangSwitcher plugin's CSS is disabled, the languages do appear, though they're stacked vertically and not styled like in your example screenshot. It seems the updated CSS is not getting read, although I can confirm that it did get uploaded to the server.

Screen Shot 2021-06-16 at 12 12 56 PM
key-notes commented 3 years ago

Is there a way to shorten the language names (e.g., "English" to "en", "Français" to "fr", etc.)?

Or even better, could a flag icon be displayed instead?

The language switcher currently gets cut off on tablets in portrait mode due to the length of the menu, so visitors can't actually switch languages. (I've already reduced the menu items and their names to the bare minimum, so there's no more room for a long language selector.)

Incidentally, it's in full-width desktop view that the languages are displayed stacked on atop the other.

How can we make the language selector as small as possible?

key-notes commented 3 years ago

Update: The display bug was evidently due to Chrome's cache.

Language names do appear to be defined internally in Grav, as so far I haven't found a setting that allows us to abbreviate them. This wouldn't be a major problem were it not for the fact that on some displays (e.g., tablet in portrait mode) every pixel counts, and visitors can't see the language link to select their language.

Also, a suggestion: It may be very helpful to have an option to set LangSwitcher not to display the current language. That would save horizontal space given the current configuration.

Even better would be a dropdown menu, since it could be much smaller horizontally and allow for many languages in the dropdown.

rhukster commented 3 years ago

The langswitcher is intended to be a bare-bones solution. You can always extend the twig template in your own theme and customize as you like.

However, I do plan on providing a better 'customized' integration for Typhoon.

key-notes commented 3 years ago

Thanks for the explanation. I solved the problem for the time being simply by moving another navbar link to a submenu. This made enough room for the language switcher on tablets in portrait mode, at least if there are only two languages.

rhukster commented 3 years ago

i'll keep this open until I'm able to add that customized functionality I mentioned.

rhukster commented 3 years ago

This has been done..

login-langswitcher

key-notes commented 3 years ago

That's wonderful! Thanks so much. I'll update it right away.

key-notes commented 3 years ago

Bad news: It seems it's rather impossible to switch back to the updated, default Typhoon theme after performing the tasks you kindly listed above (prior to your theme update). Trying to load the site with the newly updated default theme selected returns the error:

An exception has been thrown during the rendering of a template ("Identifier "langswitcher" is not defined.").

The error is triggered in this file:

/user/themes/typhoon/templates/partials/navigation.html.twig

I made no changes to this file, but it appears to reference classes without indicating exactly where those classes are defined.

I even deleted this code from /user/themes/typhoon/css/custom:

/* LANGSWITCHER PLUGIN */ ul.langswitcher { @apply flex h-16 mr-8; li { @apply inline-flex ml-4 text-sm items-center pt-1 font-medium; } } /* END LANGSWITCHER */

npm run watch is running and it did detect the changed CSS file. Also, I cleared the cache and tried multiple browsers, but this does not appear to be a caching issue.

How can I undo the damage? More importantly, as asked earlier, what is the "official" workflow for updating "child themes," or as Grav appears to call them, "inheritance" themes? Again, I created a full copy of the previous Typhoon theme because this was the only way it would work.

I'm afraid I'm really confused right now. There must be a way to use the equivalent of a "child theme" while being able to update the parent theme. Many thanks in advance for any detailed instructions.

rhukster commented 3 years ago

This bug was already identified and fixed in 2.1.1 yesterday. Please update to this newer version. Sorry about that.

key-notes commented 3 years ago

Thanks! 2.1.1 works, although it changed the language selector in the navbar to a login link. "Enable Langswitcher menu" is enabled (I hadn't disabled it) and the LangSwitcher plugin is also enabled.

Also, I just disabled "Enable login menu." That removed the login menu, but the language switcher still doesn't show up. What can I do next?

rhukster commented 3 years ago

Ah! I forgot to release langswitcher plugin with an update that makes it accessible via the theme. That's why it was working for me as I was already using the unreleased version.

I've pushed this release now, and it should show up in GPM as langswitcher v1.4.3 in the next 15 mins or so. Should be good after that. You might need to "Check Updates" in the admin or run bin/gpm index -f to clear the GPM index cache and get the latest versions.

key-notes commented 3 years ago

I see it happens to the best of them too! No worries. Just updated langswitcher and it now works perfectly. The dropdown menu looks great—just the solution I was hoping for. :-)