Skip to content

Commit 5d6bda0

Browse files
committed
fix: css
1 parent 79f874a commit 5d6bda0

File tree

3 files changed

+23
-58
lines changed

3 files changed

+23
-58
lines changed

web/postcss/scopeTailwindToUnapi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const DEFAULT_INCLUDE_ROOT = true;
3636
const KEYFRAME_AT_RULES = new Set(['keyframes']);
3737
const NON_SCOPED_AT_RULES = new Set(['font-face', 'page']);
3838
const MERGE_WITH_SCOPE_PATTERNS: RegExp[] = [/^\.theme-/, /^\.has-custom-/, /^\.dark\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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ 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+
7079
it('processes large rule sets within the target budget', () => {
7180
const plugin = scopeTailwindToUnapi();
7281
const totalRules = 10_000;

web/src/assets/main.css

Lines changed: 7 additions & 58 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
*/
@@ -17,47 +17,27 @@
1717
@source "../**/*.{vue,ts,js,tsx,jsx}";
1818
@source "../../../unraid-ui/src/**/*.{vue,ts,js,tsx,jsx}";
1919

20-
/*
20+
/*
2121
* Scoped base styles for .unapi elements only
2222
* Import Tailwind's preflight into our custom layer and scope it
2323
*/
2424

2525
@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-
}
26+
/* Scope Tailwind preflight so Nuxt UI components get default browser resets */
27+
@import "tailwindcss/preflight.css";
3928

4029
/* Accessible focus styles for keyboard navigation */
4130
.unapi button:focus-visible {
4231
outline: 2px solid #ff8c2f;
4332
outline-offset: 2px;
4433
}
4534

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-
5535
/* Ensure Nuxt UI modal/slideover close buttons work properly */
5636
.unapi [role="dialog"] button,
5737
.unapi [data-radix-collection-item] button {
58-
margin: 0 !important;
59-
background: transparent !important;
60-
border: none !important;
38+
margin: 0;
39+
background: transparent;
40+
border: none;
6141
}
6242

6343
/* Focus styles for dialog buttons */
@@ -95,37 +75,6 @@
9575
padding-inline-start: 0;
9676
list-style-type: none;
9777
}
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-
}
12978
}
13079

13180
/* Override link styles inside .unapi */

0 commit comments

Comments
 (0)