Skip to content

Conversation

@evnchn
Copy link
Collaborator

@evnchn evnchn commented Nov 21, 2025

Motivation

Due to various reasons it may not be good to have ourselves tied down to using Tailwind CDN JS

  • Large size
  • Performance reasons
  • Lack of configurability

So this PR want to enable UnoCSS support, an atomic and configurable CSS engine.

Implementation

Compared to predecessor #4832, this is more clean because:

  • Dark mode works without sketchy hacks
  • Code is cleaned up in some places (shorter name allClasses, which generateStylesFromClasses takes no argument, cleaner for loop, etc)
  • No need preset-wind <-> preset-wind3 hack, because of https://github.com/unocss/unocss/releases/tag/v66.5.3 by yours truly
  • Now that we have CSS layering, stuff becomes more organized and simple.

Going over the changes briefly:

  • Extract core libraries
  • Expose option in ui.run ui.run_with and AppConfig
  • Use UnoCSS in HTML and JS
  • Ignore for precommit codespell

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
  • Pytests have been added (b0fb62a).
  • Documentation has been added (20e3916).

@evnchn

This comment was marked as resolved.

@evnchn
Copy link
Collaborator Author

evnchn commented Nov 22, 2025

57a3b33 tested and works.

// Modified from examples/custom_vue_element/counter.js to use Tailwind classes
export default {
  template: `
    <button
      @click="handle_click"
      :class="[
        'px-4 py-2 rounded-md transition-colors',
        value > 0 ? 'bg-green-200 hover:bg-green-300' : 'bg-gray-200 hover:bg-gray-300'
      ]"
    >
      <strong>{{ title }}: {{ value }}</strong>
    </button>
  `,
  props: {
    title: String,
  },
  data() {
    return {
      value: 0,
    };
  },
  methods: {
    handle_click() {
      this.value += 1;
      this.$emit("change", this.value);
    },
    reset() {
      this.value = 0;
    },
  },
};

@evnchn evnchn added feature Type/scope: New feature or enhancement review Status: PR is open and needs review labels Nov 22, 2025
Copy link
Collaborator Author

@evnchn evnchn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted some mistakes while on the train

Comment on lines +102 to +103
ui.run(uvicorn_reload_includes='*.py, *.css, *.html', reload=not on_fly,
reconnect_timeout=10.0, tailwind=False, unocss_preset='wind4')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally left this in there. Oh well. Let's remove this before we merge (or not, since it works)

@falkoschindler falkoschindler added this to the 3.5 milestone Nov 22, 2025
@evnchn
Copy link
Collaborator Author

evnchn commented Nov 22, 2025

Actually is the observer needed? All of NiceGUI components do not add Tailwind classes programmatically...

Perhaps configurable? observer can be one of 3 values:

  • None: No observer, most performant
  • 'components': Catches components which add Tailwind classes programmatically
  • 'full': Observes the entire body and misses nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Type/scope: New feature or enhancement review Status: PR is open and needs review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants