Skip to content

Commit 234c2e2

Browse files
committed
fix: css
1 parent 79f874a commit 234c2e2

File tree

4 files changed

+37
-60
lines changed

4 files changed

+37
-60
lines changed

web/postcss/scopeTailwindToUnapi.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const DEFAULT_INCLUDE_ROOT = true;
3535

3636
const KEYFRAME_AT_RULES = new Set(['keyframes']);
3737
const NON_SCOPED_AT_RULES = new Set(['font-face', 'page']);
38-
const MERGE_WITH_SCOPE_PATTERNS: RegExp[] = [/^\.theme-/, /^\.has-custom-/, /^\.dark\b/];
38+
const MERGE_WITH_SCOPE_PATTERNS: RegExp[] = [/^\.theme-/, /^\.has-custom-/, /^\.dark\b/, /^\.light\b/];
39+
const ROOT_ELEMENT_PATTERN = /^(html|body)(?=$|[.#[:\s>+~])/;
3940

4041
function shouldScopeRule(rule: Rule, targetLayers: Set<string>, includeRootRules: boolean): boolean {
4142
const hasSelectorString = typeof rule.selector === 'string' && rule.selector.length > 0;
@@ -104,6 +105,12 @@ function prefixSelector(selector: string, scope: string): string {
104105
return trimmed;
105106
}
106107

108+
const rootElementMatch = trimmed.match(ROOT_ELEMENT_PATTERN);
109+
if (rootElementMatch) {
110+
const suffix = trimmed.slice(rootElementMatch[0].length);
111+
return suffix ? `${scope}${suffix}` : scope;
112+
}
113+
107114
if (trimmed === ':root') {
108115
return scope;
109116
}

web/src/__tests__/scopeTailwindToUnapi.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ describe('scopeTailwindToUnapi plugin', () => {
6767
expect(rule.selector).toBe('.unapi .card');
6868
});
6969

70+
it('scopes html and body selectors to the root scope element', () => {
71+
const plugin = scopeTailwindToUnapi();
72+
const rule = createRule(['html', 'body.dark']);
73+
74+
plugin.Rule?.(rule);
75+
76+
expect(rule.selectors).toEqual(['.unapi', '.unapi.dark']);
77+
});
78+
79+
it('merges theme mode selectors onto the unapi scope', () => {
80+
const plugin = scopeTailwindToUnapi();
81+
const rule = createRule(['.light', '.dark']);
82+
83+
plugin.Rule?.(rule);
84+
85+
expect(rule.selectors).toEqual(['.unapi.light', '.unapi.dark']);
86+
});
87+
7088
it('processes large rule sets within the target budget', () => {
7189
const plugin = scopeTailwindToUnapi();
7290
const totalRules = 10_000;

web/src/assets/main.css

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Tailwind v4 configuration with Nuxt UI v3
33
* Using scoped selectors to prevent breaking Unraid WebGUI
44
*/
@@ -9,55 +9,36 @@
99
/* Import theme and utilities only - no global preflight */
1010
@import "tailwindcss/theme.css" layer(theme);
1111
@import "tailwindcss/utilities.css" layer(utilities);
12-
@import "@nuxt/ui";
12+
@import "@nuxt/ui/.nuxt/ui.css" layer(theme);
13+
@import "@nuxt/ui";
1314
@import 'tw-animate-css';
1415
@import '../../../@tailwind-shared/index.css';
1516

1617
/* Scan for Tailwind classes in all source files */
1718
@source "../**/*.{vue,ts,js,tsx,jsx}";
1819
@source "../../../unraid-ui/src/**/*.{vue,ts,js,tsx,jsx}";
1920

20-
/*
21+
/*
2122
* Scoped base styles for .unapi elements only
2223
* Import Tailwind's preflight into our custom layer and scope it
2324
*/
2425

2526
@layer unapi-base {
26-
/* Scope all Tailwind preflight styles to .unapi */
27-
.unapi {
28-
@import "tailwindcss/preflight.css";
29-
}
30-
31-
/* Override Unraid's button styles for Nuxt UI components */
32-
.unapi button {
33-
/* Reset Unraid's button styles */
34-
margin: 0 !important;
35-
padding: 0;
36-
border: none;
37-
background: none;
38-
}
27+
/* Scope Tailwind preflight so Nuxt UI components get default browser resets */
28+
@import "tailwindcss/preflight.css";
3929

4030
/* Accessible focus styles for keyboard navigation */
4131
.unapi button:focus-visible {
4232
outline: 2px solid #ff8c2f;
4333
outline-offset: 2px;
4434
}
4535

46-
/* Restore button functionality while removing Unraid's forced styles */
47-
.unapi button:not([role="switch"]) {
48-
display: inline-flex;
49-
align-items: center;
50-
justify-content: center;
51-
cursor: pointer;
52-
transition: all 0.2s;
53-
}
54-
5536
/* Ensure Nuxt UI modal/slideover close buttons work properly */
5637
.unapi [role="dialog"] button,
5738
.unapi [data-radix-collection-item] button {
58-
margin: 0 !important;
59-
background: transparent !important;
60-
border: none !important;
39+
margin: 0;
40+
background: transparent;
41+
border: none;
6142
}
6243

6344
/* Focus styles for dialog buttons */
@@ -95,37 +76,6 @@
9576
padding-inline-start: 0;
9677
list-style-type: none;
9778
}
98-
99-
/* Reset toggle/switch button backgrounds */
100-
.unapi button[role="switch"],
101-
.unapi button[role="switch"][data-state="checked"],
102-
.unapi button[role="switch"][data-state="unchecked"] {
103-
background-color: transparent;
104-
background: transparent;
105-
border: 1px solid #ccc;
106-
}
107-
108-
/* Style for checked state */
109-
.unapi button[role="switch"][data-state="checked"] {
110-
background-color: #ff8c2f; /* Unraid orange */
111-
}
112-
113-
/* Style for unchecked state */
114-
.unapi button[role="switch"][data-state="unchecked"] {
115-
background-color: #e5e5e5;
116-
}
117-
118-
/* Dark mode toggle styles */
119-
.unapi.dark button[role="switch"][data-state="unchecked"],
120-
.dark .unapi button[role="switch"][data-state="unchecked"] {
121-
background-color: #333;
122-
border-color: #555;
123-
}
124-
125-
/* Toggle thumb/handle */
126-
.unapi button[role="switch"] span {
127-
background-color: white;
128-
}
12979
}
13080

13181
/* Override link styles inside .unapi */

web/vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export default defineConfig({
9696
'~': fileURLToPath(new URL('./src', import.meta.url)),
9797
'~~': fileURLToPath(new URL('./', import.meta.url)),
9898
'~/': fileURLToPath(new URL('./src/', import.meta.url)),
99+
'#build': fileURLToPath(new URL('./node_modules/@nuxt/ui/.nuxt', import.meta.url)),
100+
'#build/ui.css': fileURLToPath(new URL('./node_modules/@nuxt/ui/.nuxt/ui.css', import.meta.url)),
99101
},
100102
},
101103

0 commit comments

Comments
 (0)