Skip to content

Commit 68e4c84

Browse files
cn0809nighca
andauthored
refactor(spx-gui): migrate XBuilder frontend styling to Tailwind CSS (#3002)
* sv * disable tailwind preflight * fix: theme leading/text variables & tailwind utilities confliction with existing classes * batch migration task 1 * batch migration task 2 - asset * copilot * editor - wip * almost done * details * move UI component base styles into Tailwind component layer * move template root comment outside * fix incompatible css nesting & some details * update doc * refine tailwind flex utility usage and styling guidelines * fix: missing navbar background image * fix: css layer order messed up in split css chunk * fix: utilities not work for UITextInput/UIDivider/UIRadioGroup * draft: vue 3+ tailwind 4 component guildelines * migrate UIButton to recipe-based tailwind styling * fix: unexpected twMerge result due to non-standard tailwind tokens * migrate UI components to tailwind v4 & remove scss deps * support custom text-size utilities in twMerge * move input layout classes to native wrappers & update docs * Use naive-ui with layer support (#2) * text-body -> text-base & remove redundant descriptions in docs * simplify root class merging in UI components * remove redundant layer order declarations * fix: restore loading compatibility hooks for project runner * align component styles with css layers and root class merging --------- Co-authored-by: Hanxing Yang <nighca@live.cn>
1 parent 8d27ea2 commit 68e4c84

339 files changed

Lines changed: 5332 additions & 10398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

spx-gui/.vscode/extensions.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"recommendations": [
3-
"Vue.volar",
3+
"vue.volar",
44
"dbaeumer.vscode-eslint",
5-
"esbenp.prettier-vscode"
5+
"esbenp.prettier-vscode",
6+
"bradlc.vscode-tailwindcss"
67
]
78
}

spx-gui/AGENTS.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,56 @@ When working with backend unique string identifiers such as `username`, project
8080

8181
* Generate accessibility info for interactive elements using `v-radar` directive.
8282

83+
## Styling Preferences
84+
85+
### Defaults
86+
87+
* Use Tailwind as the default for local layout and surface styling.
88+
* Keep styles local to the page/feature/component. Do not move local styles into `src/app.css`.
89+
* Prefer readable template utilities and remove redundant local style blocks when they no longer improve clarity.
90+
* Prefer direct template utilities over local `@apply` blocks when the styles are only used by one or two template nodes.
91+
* If local authored styles are still needed, use plain CSS.
92+
93+
### Boundaries and Source of Truth
94+
95+
* Keep `src/app.css` limited to Tailwind entry setup, theme bridge, and rare project-wide utilities.
96+
* Keep `src/components/ui/global.css` and `src/components/ui/reset.css` as the base reset/foundation layer (Tailwind preflight stays disabled).
97+
* The global CSS layer order is `theme, base, naive-ui, components, utilities`, declared in `index.html`.
98+
* Keep `--ui-*` tokens as the source of truth.
99+
* In Tailwind classes, prefer bridged semantic tokens (for example `text-text`, `text-title`, `bg-primary-100`).
100+
* In local CSS, prefer direct `--ui-*` variables instead of bridged Tailwind variables.
101+
102+
### Responsive and Theme Rules
103+
104+
* Keep breakpoints in `src/app.css` aligned with `src/components/ui/responsive.ts`.
105+
* Use only `tablet`, `desktop`, and `desktop-large` responsive names.
106+
* Prefer responsive CSS/Tailwind variants over `useResponsive()`; keep `useResponsive()` for non-style runtime logic.
107+
* Keep Tailwind theme namespaces reset to project tokens only (color, shadow, font, text, radius, etc.).
108+
109+
### When Local CSS Is Better
110+
111+
* Keep local CSS for `:deep(...)`, generated content, third-party DOM overrides, and complex stateful widgets.
112+
* Keep a small local CSS rule for structural selectors that are awkward in template logic (for example nested `:last-child` rules) instead of encoding them with hard-to-read dynamic class expressions.
113+
* Prefer plain local CSS over complex Tailwind descendant/arbitrary selectors for cross-component or slot-content styling.
114+
* Preserve semantic hook classes used by parent selectors or slots (for example `.corner-menu`, `.course-item-mini`).
115+
* For newly added components, avoid introducing `:deep(...)` selectors and cross-file hook classes when possible, since they increase maintenance cost.
116+
* Do not force full Tailwind conversion when a small local style block is clearer.
117+
118+
### Practical Styling Notes
119+
120+
* For root-class overrides and utility conflicts:
121+
- For business components, external root `class` overrides are allowed by default. If utility conflicts need an explicit winner, prefer adding Tailwind's important modifier at the usage site (for example `rounded-md!`, `w-32!`) instead of expanding the component API. This keeps intent explicit, usage concise, and matches the fact that business components rarely need nested override chains.
122+
- For most UI components, `twMerge` and `@layer components` are set up so external utilities or custom classes can override root classes in the common case without special handling, though edge cases can still exist.
123+
- For the Naive UI-root components listed in `src/components/ui/README.md`, Naive UI defaults live in the `naive-ui` layer and our authored UI styles live in the `components` layer, so component-layer rules have higher cascade priority on the same element/property pair.
124+
- Even so, those Naive UI-root components still are not identical to DOM-root utility wrappers. Treat them as component-specific: simple root overrides are often fine, while deeper visual changes may still need wrapper layout control, explicit props, or Naive UI theme overrides.
125+
* Avoid non-equivalent Tailwind simplifications for flex values. In particular, `flex: 1 1 0` is not equivalent to Tailwind `flex-1` (`flex: 1 1 0%`), so do not simplify between them unless the layout behavior has been verified. Likewise, do not simplify `flex: 0 0 auto` to `shrink-0`; use the equivalent `flex-none` when that shorthand is desired.
126+
* Prefer `style` / `:style` for one-off values when clearer than Tailwind arbitrary utilities. For example, prefer `style="box-shadow: 0 24px 32px -16px rgba(0, 0, 0, 0.1)"` over a long arbitrary utility such as `shadow-[0_24px_32px_-16px_rgba(0,0,0,0.1)]`.
127+
* For important/non-obvious background assets, prefer TS imports and inline `backgroundImage` binding.
128+
* Keep fixed utility classes in `class`; reserve `:class` for stateful/dynamic parts only.
129+
* In plain `<style scoped>`, flatten `:deep(...)` selectors (for example `.preview :deep(svg)`) so the final selector structure and specificity stay obvious.
130+
* Do not use native CSS nesting in plain `<style>` / `<style scoped>` blocks; use flat selectors to avoid browser compatibility issues.
131+
* Keep single-use values local; only add setup variables when reused/computed or clearly improving readability.
132+
83133
### Menu Item Text Guidelines
84134

85135
When creating or modifying menu items, follow these UI guidelines for ellipses:

spx-gui/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
width: 100%;
2222
height: 100%;
2323
}
24+
25+
@layer theme, base, naive-ui, components, utilities;
2426
</style>
27+
<!-- naive-ui's style will be inserted here -->
28+
<meta name="naive-ui-style" />
29+
<!-- vueuc's style will be inserted here -->
30+
<meta name="vueuc-style" />
2531
</head>
2632

2733
<body>

0 commit comments

Comments
 (0)