justpy icon indicating copy to clipboard operation
justpy copied to clipboard

Update embedded Tailwind?

Open lcosmin opened this issue 4 years ago • 12 comments

It seems that the version embedded with JustPy is a bit older and doesn't support things like bg-green-50, bg-gray-50, etc. Could it be updated? I could attempt a PR for this myself, but I'm not so skilled with CSS or JustPy, so I might miss something. But I'm willing to give it a try if it'd be accepted.

lcosmin avatar Feb 12 '21 15:02 lcosmin

You are correct. I have made the change and it will be in the new version that will be out soon.

elimintz avatar Feb 12 '21 15:02 elimintz

By the way, is there an estimation for the new version's release date?

lcosmin avatar Feb 22 '21 10:02 lcosmin

Yes, in the next couple of weeks. In the meantime the workaround is to insert you own css using head_html: https://justpy.io/reference/webpage/#head_html-and-body_html

Add the following two statements below after creating your web page (wp for this exampe):

wp.tailwind = False  # Will not load old version
wp.head_html = '<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">'  # change link as appropriate

elimintz avatar Feb 22 '21 17:02 elimintz

Any progress on a new release with a more up to date version of Tailwind? It would be great o have the support for CSS filters that was added in Tailwind 2.1 as part of the standard package, so that it can work for standalone installs.

nickovs avatar Jun 09 '21 03:06 nickovs

I'm not making promises any more... :) I have some time this month and hope to get it done.

If you copy the tailwind version of your choice into your static directory, you can then insert a link to it at the top of your page.

elimintz avatar Jun 09 '21 19:06 elimintz

I'd love to do this in the upcoming release - how can we test this? So far only one example seems to use tailwind

examples % grep tailwind *.py
uber-nyc-pickups.py:    wp = jp.QuasarPage(tailwind=True, title='Uber NYC Pickups')

How would i now the tailwind upgrade has worked?

WolfgangFahl avatar Aug 21 '22 09:08 WolfgangFahl

The way to know the upgrade worked is either to use the browser developer tools to see which version was downloaded or use a feature only available in the new version and see if it works. For my local version I already changed the templates to use the latest tailwind version, but do not yet support specifying the version. Will try working on this issue this week

elimintz avatar Aug 21 '22 20:08 elimintz

@elimintz thanks for clarifying that this may indeed be part of the upcoming milestone

WolfgangFahl avatar Aug 22 '22 05:08 WolfgangFahl

The following will update to the latest version of tailwind:

Change lines 8 to 23 in tailwind.html to:

{% if options.tailwind %}
            {% if not options.no_internet %}
                <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
            {% else %}
                <script src="/templates/local/tailwind/tailwind.js"></script>
            {% endif %}
        {% endif %}

To support the no_internet option, update the value of the file /templates/local/tailwind/tailwind.js to the content of the script downloaded 2 lines above.

I think this should be the extent of the change regarding tailwind with this version. If somebody needs to use an older version of tailwind, it is easy to do with the tailwind=False option of WebPage and inserting the version required. I have been using this new version of the template for a while now and it works well.

elimintz avatar Aug 22 '22 21:08 elimintz

see also #528

WolfgangFahl avatar Sep 14 '22 13:09 WolfgangFahl

The Tailwind class should load the available Tailwind classes from a json or yaml file to reduce the size of the class. Furthermore, the available classes should be load automatically e.g. extracted from https://tailwind.build/classes if an update is needed https://github.com/justpy-org/justpy/blob/2f3c26c4c3da7d4e7e0736d4243e420e136cb765/jpcore/tailwind.py#L4

tholzheim avatar Sep 14 '22 13:09 tholzheim

Because it was a lot of work each time to add the new tailwind class groups as new versions of tailwind came out, in my internal versions I stopped relying on the tailwind.py methods set_class and set_classes. Perhaps we just provide a tailwind stub in justpy, and if people want they can override with their own implementation.

If we want to support several versions of tailwind, maintaining taliwind.py becomes very, very cumbersome. I think we should not try. I am not sure actually which version of tailwind that current tailwind.py supports.

I recommend dropping support for set_class and set_classes in future versions.

elimintz avatar Sep 14 '22 13:09 elimintz

see #685

WolfgangFahl avatar Sep 20 '23 09:09 WolfgangFahl