feat(ui): light mode and new theming system (#1468)

This commit is contained in:
Alex
2026-05-26 01:07:33 -04:00
committed by GitHub
parent 3211d7818a
commit 22ff6d8e90
131 changed files with 2816 additions and 3391 deletions
@@ -15,12 +15,12 @@
<path d="M96.7715 113.077H43.5539V119.537H96.7715C98.5535 119.537 99.9964 118.092 99.9964 116.307C99.9964 114.522 98.5535 113.077 96.7715 113.077Z" fill="url(#mobile-topbar-brand-secondary-gradient)"/>
<defs>
<linearGradient id="mobile-topbar-brand-primary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
<stop offset="0" style="stop-color: var(--color-logo-start)"/>
<stop offset="1" style="stop-color: var(--color-logo-end)"/>
</linearGradient>
<linearGradient id="mobile-topbar-brand-secondary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
<stop offset="0" style="stop-color: var(--color-logo-start)"/>
<stop offset="1" style="stop-color: var(--color-logo-end)"/>
</linearGradient>
</defs>
</svg>
@@ -13,8 +13,9 @@
box-sizing: border-box;
height: 3.5rem;
z-index: 100;
background-color: var(--surface-app);
border-bottom: 1px solid var(--content-border-color);
background-color: var(--color-app);
color: var(--color-text);
border-bottom: 1px solid var(--color-border);
padding:
0
calc(0.75rem + env(safe-area-inset-right))
@@ -32,7 +33,6 @@
flex: 1 1 auto;
min-width: 0;
gap: 0.4rem;
color: var(--text-color);
}
.mobile-topbar-brand-icon {
@@ -63,16 +63,15 @@
border: 0;
background: none;
border-radius: 6px;
color: var(--text-color);
cursor: pointer;
transition: background-color 0.15s ease, color 0.15s ease;
&:hover {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
&:focus-visible {
outline: 2px solid var(--primary-color);
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
@@ -18,17 +18,17 @@
border-radius: var(--sidebar-row-radius);
&:focus-within {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
}
@media (hover: hover) and (pointer: fine) {
.sidebar-item-container:hover {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
.sidebar-item-container:hover .sidebar-item-chevron {
color: var(--text-color);
color: var(--color-text);
}
.sidebar-item-container:hover .entity-menu-icon {
@@ -41,7 +41,7 @@
}
.sidebar-item-container.active-route-container {
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
}
.sidebar-item-link {
@@ -73,13 +73,13 @@ a.sidebar-item-link {
}
.sidebar-item-container:has(.sidebar-item-link:focus-visible) {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
border-radius: var(--sidebar-row-radius);
}
a.sidebar-item-link.active-route {
color: var(--primary-color);
color: var(--color-primary-text);
}
.sidebar-item-chrome {
@@ -96,7 +96,7 @@ a.sidebar-item-link.active-route {
.sidebar-item-chevron {
font-size: var(--text-sm);
color: var(--text-color-secondary);
color: var(--color-text-secondary);
padding-right: var(--space-3);
transition: color var(--transition-fast);
}
@@ -156,7 +156,7 @@ a.sidebar-item-link.active-route {
border: 0;
border-radius: var(--radius-pill);
background: transparent;
color: var(--text-color-secondary);
color: var(--color-text-secondary);
cursor: pointer;
font: inherit;
font-size: var(--text-sm);
@@ -165,11 +165,11 @@ a.sidebar-item-link.active-route {
.entity-menu-button:hover {
background-color: transparent;
color: var(--primary-color);
color: var(--color-primary);
}
.entity-menu-button:focus-visible {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
@@ -197,7 +197,7 @@ a.sidebar-item-link.active-route {
}
.book-count {
color: var(--text-color-secondary);
color: var(--color-text-secondary);
font-size: var(--text-sm);
font-variant-numeric: tabular-nums;
}
@@ -219,7 +219,7 @@ a.sidebar-item-link.active-route {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #ef4444;
background-color: var(--color-red-500);
animation: pulse 2s ease-in-out infinite;
}
@@ -233,11 +233,11 @@ a.sidebar-item-link.active-route {
}
.sidebar-item-container.active-route-container {
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
}
.sidebar-item-container:has(:focus-visible) {
outline: 2px solid var(--primary-color);
outline: 2px solid var(--color-primary);
outline-offset: -2px;
}
@@ -31,7 +31,7 @@
color: inherit;
&:focus-visible {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
@@ -53,12 +53,12 @@
}
.expand-icon {
color: var(--surface-500);
color: var(--color-surface-500);
}
@media (hover: hover) and (pointer: fine) {
.expand-icon:hover {
color: var(--surface-200);
color: var(--color-surface-200);
}
}
@@ -66,7 +66,7 @@
.root-item-with-dropdown:focus-visible {
background-color: transparent;
box-shadow: none;
outline: 2px solid var(--primary-color);
outline: 2px solid var(--color-primary);
outline-offset: -2px;
}
}
@@ -116,6 +116,6 @@
.expand-icon {
font-size: 1.125rem;
color: var(--text-color-secondary);
color: var(--color-text-secondary);
}
}
@@ -9,12 +9,12 @@
<path d="M96.7715 113.077H43.5539V119.537H96.7715C98.5535 119.537 99.9964 118.092 99.9964 116.307C99.9964 114.522 98.5535 113.077 96.7715 113.077Z" fill="url(#sidebar-brand-secondary-gradient)"/>
<defs>
<linearGradient id="sidebar-brand-primary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
<stop offset="0" style="stop-color: var(--color-logo-start)"/>
<stop offset="1" style="stop-color: var(--color-logo-end)"/>
</linearGradient>
<linearGradient id="sidebar-brand-secondary-gradient" x1="50" y1="0" x2="50" y2="119.537" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
<stop offset="0" style="stop-color: var(--color-logo-start)"/>
<stop offset="1" style="stop-color: var(--color-logo-end)"/>
</linearGradient>
</defs>
</svg>
@@ -22,9 +22,9 @@
<svg class="sidebar-brand-wordmark" width="2500" height="350" viewBox="0 0 2500 350" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<g clip-path="url(#sidebar-brand-wordmark-clip)">
<path d="M71.8311 296.149V314.103V332.047V350L89.7839 332.047L107.747 350V332.047V314.103V296.149H71.8311Z" fill="white"/>
<path d="M1748.64 102.654H1701.96C1691.71 102.654 1683.37 110.983 1683.37 121.23V165.376C1683.37 175.622 1691.7 183.952 1701.96 183.952H1748.64C1757.49 183.952 1764.7 176.746 1764.7 167.895V118.721C1764.7 109.869 1757.49 102.664 1748.64 102.664V102.654Z" style="fill: var(--primary-400)"/>
<path d="M896.673 102.654H852.504C842.263 102.654 833.919 110.983 833.919 121.23V167.885C833.919 176.736 841.128 183.942 849.984 183.942H899.184C908.039 183.942 915.249 176.736 915.249 167.885V121.23C915.249 110.983 906.915 102.654 896.663 102.654H896.673Z" style="fill: var(--primary-400)"/>
<path d="M653.709 183.942H697.878C708.119 183.942 716.463 175.612 716.463 165.366V118.711C716.463 109.859 709.254 102.654 700.398 102.654H651.199C642.343 102.654 635.134 109.859 635.134 118.711V165.366C635.134 175.612 643.467 183.942 653.719 183.942H653.709Z" style="fill: var(--primary-400)"/>
<path d="M1748.64 102.654H1701.96C1691.71 102.654 1683.37 110.983 1683.37 121.23V165.376C1683.37 175.622 1691.7 183.952 1701.96 183.952H1748.64C1757.49 183.952 1764.7 176.746 1764.7 167.895V118.721C1764.7 109.869 1757.49 102.664 1748.64 102.664V102.654Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
<path d="M896.673 102.654H852.504C842.263 102.654 833.919 110.983 833.919 121.23V167.885C833.919 176.736 841.128 183.942 849.984 183.942H899.184C908.039 183.942 915.249 176.736 915.249 167.885V121.23C915.249 110.983 906.915 102.654 896.663 102.654H896.673Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
<path d="M653.709 183.942H697.878C708.119 183.942 716.463 175.612 716.463 165.366V118.711C716.463 109.859 709.254 102.654 700.398 102.654H651.199C642.343 102.654 635.134 109.859 635.134 118.711V165.366C635.134 175.612 643.467 183.942 653.719 183.942H653.709Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
<path d="M107.747 80.7661H269.361C274.322 80.7661 278.338 76.7519 278.338 71.7944V8.97179C278.338 4.01422 274.322 0 269.361 0H35.9155C29.369 0 23.2442 1.75622 17.9527 4.81707C12.5007 7.96823 7.96226 12.5043 4.80949 17.9536C1.75712 23.2323 0 29.354 0 35.8972V296.149C0 315.979 16.0751 332.046 35.9155 332.046H58.8786V314.103H35.9155C25.9953 314.103 17.9527 306.064 17.9527 296.149C17.9527 286.234 25.9953 278.196 35.9155 278.196H260.385C270.305 278.196 278.348 270.157 278.348 260.242V116.663C278.348 106.748 270.305 98.7097 260.385 98.7097H107.747C102.786 98.7097 98.7702 102.724 98.7702 107.681V170.504C98.7702 175.462 102.786 179.476 107.747 179.476H188.554C193.514 179.476 197.53 183.49 197.53 188.448C197.53 193.405 193.514 197.419 188.554 197.419H107.747C92.8663 197.419 80.8074 185.367 80.8074 170.494V107.671C80.8074 92.7988 92.8663 80.7461 107.747 80.7461V80.7661Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
<path d="M269.361 314.103H121.231V332.046H269.361C274.322 332.046 278.338 328.032 278.338 323.075C278.338 318.117 274.322 314.103 269.361 314.103Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
<path d="M1620.14 3.3017C1600.16 3.3017 1583.98 19.489 1583.98 39.4498V248.099C1583.98 267.538 1599.74 283.294 1619.19 283.294H1847.17C1856.53 283.294 1864.11 275.717 1864.11 266.364V19.6898C1864.11 10.6377 1856.77 3.3017 1847.72 3.3017H1620.14ZM1782.77 167.885C1782.77 186.701 1767.46 202.006 1748.64 202.006H1701.96C1681.74 202.006 1665.3 185.567 1665.3 165.366V121.219C1665.3 101.018 1681.74 84.5796 1701.96 84.5796H1748.64C1767.46 84.5796 1782.77 99.8839 1782.77 118.701V167.885Z" fill="url(#sidebar-brand-wordmark-gradient)"/>
@@ -38,8 +38,8 @@
</g>
<defs>
<linearGradient id="sidebar-brand-wordmark-gradient" x1="1250.2" y1="0" x2="1250.2" y2="332.046" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color: var(--primary-300)"/>
<stop offset="1" style="stop-color: var(--primary-500)"/>
<stop offset="0" style="stop-color: var(--color-logo-start)"/>
<stop offset="1" style="stop-color: var(--color-logo-end)"/>
</linearGradient>
<clipPath id="sidebar-brand-wordmark-clip">
<rect width="2500" height="350" fill="white"/>
@@ -148,7 +148,7 @@
<div class="sidebar-nav-top">
<button
type="button"
class="sidebar-action-link sidebar-search-button"
class="sidebar-action-link sidebar-search-button bg-surface-200 hover:bg-surface-300 dark:bg-surface-800 dark:hover:bg-surface-700"
[pTooltip]="t('search')"
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
tooltipPosition="right"
@@ -172,7 +172,7 @@
<div class="sidebar-footer-actions">
<button
type="button"
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button"
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button hover:bg-surface-hover"
[pTooltip]="t('add')"
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="top"
@@ -188,7 +188,7 @@
@if (canUploadBooks()) {
<button
type="button"
class="sidebar-action-link sidebar-footer-action"
class="sidebar-action-link sidebar-footer-action hover:bg-surface-hover"
[attr.aria-label]="t('uploadBook')"
[pTooltip]="t('uploadBook')"
[tooltipDisabled]="!layoutService.isDesktop()"
@@ -204,7 +204,7 @@
type="button"
cdkOverlayOrigin
#notificationsFooterOrigin="cdkOverlayOrigin"
class="sidebar-action-link sidebar-footer-action sidebar-notification-button"
class="sidebar-action-link sidebar-footer-action sidebar-notification-button hover:bg-surface-hover"
[attr.aria-label]="t('notifications')"
[pTooltip]="t('notifications')"
[tooltipDisabled]="!layoutService.isDesktop()"
@@ -223,7 +223,7 @@
</button>
<a
class="sidebar-action-link sidebar-footer-action"
class="sidebar-action-link sidebar-footer-action hover:bg-surface-hover"
[class.active-route]="isSettingsActive()"
[attr.aria-current]="isSettingsActive() ? 'page' : null"
[routerLink]="['/settings']"
@@ -36,16 +36,16 @@
min-width: 0;
min-height: var(--sidebar-row-min-height);
padding: var(--sidebar-row-padding-block) var(--sidebar-row-padding-inline-end) var(--sidebar-row-padding-block) var(--sidebar-row-padding-inline-start);
color: var(--text-color);
color: var(--color-text);
text-decoration: none;
letter-spacing: 0.02em;
&:hover {
color: var(--primary-color);
color: var(--color-primary);
}
&:focus-visible {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
@@ -108,10 +108,10 @@
}
.sidebar-action-link.sidebar-toolbar-button {
color: var(--primary-color);
color: var(--color-primary);
&:hover {
color: var(--primary-color);
color: var(--color-primary);
}
}
@@ -127,18 +127,18 @@
border: 0;
background: none;
border-radius: var(--sidebar-row-radius);
color: var(--text-color-secondary);
color: var(--color-text-secondary);
cursor: pointer;
text-decoration: none;
transition: background-color var(--transition-fast), color var(--transition-fast);
&:hover {
background-color: var(--surface-hover);
color: var(--text-color);
background-color: var(--color-surface-hover);
color: var(--color-text);
}
&:focus-visible {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
@@ -170,8 +170,8 @@
height: 1rem;
padding: 0 0.25rem;
border-radius: var(--radius-pill);
background: var(--primary-color);
color: var(--primary-color-text);
background: var(--color-primary);
color: var(--color-primary-contrast);
font-size: 0.65rem;
font-weight: 700;
line-height: 1rem;
@@ -203,7 +203,7 @@
gap: var(--space-2);
padding-top: var(--space-2);
margin-top: var(--space-2);
border-top: 1px solid var(--border-color);
border-top: 1px solid var(--color-border);
}
.sidebar-action-link {
@@ -217,9 +217,8 @@
min-width: 0;
padding: var(--sidebar-row-padding-block) var(--sidebar-row-padding-inline-end) var(--sidebar-row-padding-block) var(--sidebar-row-padding-inline-start);
border: 0;
background: none;
border-radius: var(--sidebar-row-radius);
color: var(--text-color);
color: var(--color-text);
font: inherit;
font-size: var(--text-base);
text-align: left;
@@ -227,19 +226,14 @@
cursor: pointer;
transition: background-color var(--transition-fast), padding var(--transition-base);
&:hover {
background-color: var(--surface-hover);
}
&:focus-visible {
background-color: var(--surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
&.active-route {
color: var(--primary-color);
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
color: var(--color-primary-text);
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
.sidebar-footer-action-label {
color: inherit;
@@ -298,11 +292,6 @@
.sidebar-search-button {
padding-inline-end: var(--space-2);
background-color: var(--surface-hover);
&:hover {
background-color: color-mix(in srgb, var(--surface-hover), white 15%);
}
}
.sidebar-search-shortcut {
@@ -314,7 +303,7 @@
border: 0;
background: transparent;
margin-left: auto;
color: var(--text-color-secondary);
color: var(--color-text-secondary);
font-family: inherit;
font-size: var(--text-xs);
line-height: 1;
@@ -335,18 +324,18 @@
border: 0;
background: none;
border-radius: var(--sidebar-row-radius);
color: var(--text-color);
color: var(--color-text);
font: inherit;
text-align: left;
cursor: pointer;
transition: background-color var(--transition-fast);
&:hover {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
&:focus-visible {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
box-shadow: var(--sidebar-focus-ring);
outline: none;
}
@@ -370,8 +359,8 @@
width: 1.75rem;
height: 1.75rem;
border-radius: var(--radius-pill);
background-color: color-mix(in srgb, var(--primary-color) 18%, transparent);
color: var(--primary-color);
background-color: color-mix(in srgb, var(--color-primary) 18%, transparent);
color: var(--color-primary);
font-size: var(--text-xs);
font-weight: 600;
letter-spacing: 0.02em;
@@ -402,7 +391,7 @@
.sidebar-user-handle {
font-size: var(--text-xs);
color: var(--text-color-secondary);
color: var(--color-text-secondary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -440,11 +429,11 @@
width: 2.5rem;
height: 2.5rem;
border-radius: var(--radius-pill);
background-color: var(--surface-hover);
color: var(--text-color);
background-color: var(--color-card);
color: var(--color-text);
&:hover {
background-color: color-mix(in srgb, var(--surface-hover), white 15%);
background-color: var(--color-surface-hover);
}
}
@@ -487,10 +476,10 @@
min-height: 4.75rem;
padding: var(--space-2) var(--space-1);
border-radius: var(--radius-lg);
background-color: var(--surface-hover);
background-color: var(--color-card);
&:hover {
background-color: color-mix(in srgb, var(--surface-hover), white 15%);
background-color: var(--color-surface-hover);
}
}
@@ -502,7 +491,7 @@
white-space: normal;
text-align: center;
text-wrap: balance;
color: var(--text-color-secondary);
color: var(--color-text-secondary);
overflow-wrap: anywhere;
}
@@ -569,7 +558,7 @@
background: none;
&:hover {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
}
@@ -584,7 +573,7 @@
background: none;
.sidebar-user-avatar {
background-color: color-mix(in srgb, var(--primary-color) 24%, transparent);
background-color: color-mix(in srgb, var(--color-primary) 24%, transparent);
}
}
@@ -602,15 +591,15 @@
height: 3rem;
border-radius: var(--radius-pill);
background: none;
color: var(--text-color);
color: var(--color-text);
&:hover {
background-color: var(--surface-hover);
background-color: var(--color-surface-hover);
}
&.active-route {
background-color: color-mix(in srgb, var(--primary-color) 8%, transparent);
color: var(--primary-color);
background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
color: var(--color-primary-text);
}
}
@@ -1,66 +0,0 @@
import {provideHttpClient} from '@angular/common/http';
import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing';
import {TestBed} from '@angular/core/testing';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {BackgroundUploadService} from './background-upload.service';
describe('BackgroundUploadService', () => {
let service: BackgroundUploadService;
let httpTestingController: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
provideHttpClient(),
provideHttpClientTesting(),
BackgroundUploadService,
],
});
service = TestBed.inject(BackgroundUploadService);
httpTestingController = TestBed.inject(HttpTestingController);
});
afterEach(() => {
httpTestingController.verify();
TestBed.resetTestingModule();
vi.restoreAllMocks();
});
it('uploads a file as multipart form data and maps the returned URL', () => {
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
const file = new File(['image-bytes'], 'background.png', {type: 'image/png'});
let result: string | undefined;
service.uploadFile(file).subscribe(value => {
result = value;
});
const request = httpTestingController.expectOne(req => req.url.endsWith('/api/v1/background/upload'));
expect(request.request.method).toBe('POST');
expect(request.request.body instanceof FormData).toBe(true);
expect((request.request.body as FormData).get('file')).toBe(file);
request.flush({url: 'https://example.test/background.png'});
expect(result).toBe('https://example.test/background.png');
expect(logSpy).toHaveBeenCalled();
});
it('uploads a background URL and maps the returned URL', () => {
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
let result: string | undefined;
service.uploadUrl('https://example.test/source.jpg').subscribe(value => {
result = value;
});
const request = httpTestingController.expectOne(req => req.url.endsWith('/api/v1/background/url'));
expect(request.request.method).toBe('POST');
expect(request.request.body).toEqual({url: 'https://example.test/source.jpg'});
request.flush({url: 'https://example.test/normalized.jpg'});
expect(result).toBe('https://example.test/normalized.jpg');
expect(logSpy).toHaveBeenCalled();
});
});
@@ -1,26 +0,0 @@
import {Injectable, inject} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable, map, tap} from 'rxjs';
import {API_CONFIG} from '../../../core/config/api-config';
@Injectable({providedIn: 'root'})
export class BackgroundUploadService {
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/background`;
private readonly http = inject(HttpClient);
uploadFile(file: File): Observable<string> {
const formData = new FormData();
formData.append('file', file);
return this.http.post<{ url: string }>(`${this.baseUrl}/upload`, formData).pipe(
tap(response => console.log('File upload response:', response)),
map(resp => resp?.url)
);
}
uploadUrl(url: string): Observable<string> {
return this.http.post<{ url: string }>(`${this.baseUrl}/url`, {url}).pipe(
tap(response => console.log('URL upload response:', response)),
map(resp => resp?.url)
);
}
}
@@ -1,62 +0,0 @@
<ng-container *transloco="let t; prefix: 'layout.uploadDialog'">
<div class="upload-dialog-content">
<div class="upload-section">
<div class="file-selector">
<label class="file-label" for="upload-dialog-file-input">{{ t('chooseFile') }}</label>
<p-button
[label]="t('selectImage')"
icon="pi pi-upload"
(click)="fileInput.click()"
outlined
severity="info">
</p-button>
</div>
<input
id="upload-dialog-file-input"
#fileInput
type="file"
accept=".jpg,.jpeg,.png,image/jpeg,image/png"
(change)="onFileSelected($event)"
style="display: none;">
<small class="file-note">{{ t('fileNote') }}</small>
@if (uploadFile) {
<small class="selected-file">{{ uploadFile.name }}</small>
}
</div>
<p-divider align="center" type="solid">
<span class="or-text">{{ t('or') }}</span>
</p-divider>
<div class="url-section">
<label for="urlInput" class="url-label">{{ t('imageUrl') }}</label>
<input
id="urlInput"
type="text"
[(ngModel)]="uploadImageUrl"
[placeholder]="t('urlPlaceholder')"
class="url-input"
pInputText>
<small class="url-note">{{ t('urlNote') }}</small>
</div>
@if (uploadError) {
<p-message severity="error">{{uploadError}}</p-message>
}
<div class="dialog-footer">
<p-button
[label]="'common.cancel' | transloco"
icon="pi pi-times"
(click)="cancel()"
severity="secondary"
outlined>
</p-button>
<p-button
[label]="'common.submit' | transloco"
icon="pi pi-check"
(click)="submit()">
</p-button>
</div>
</div>
</ng-container>
@@ -1,82 +0,0 @@
.upload-dialog-content {
display: flex;
flex-direction: column;
gap: 1.5rem;
padding: 1rem 0;
.upload-section {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-bottom: 1rem;
.file-selector {
display: flex;
align-items: center;
gap: 1rem;
}
.file-label {
font-weight: 500;
color: var(--text-color);
}
.file-input {
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: var(--p-border-radius);
background: var(--ground-background);
}
.file-note {
color: var(--text-secondary-color);
font-size: 0.875rem;
margin-top: 0.25rem;
}
.selected-file {
color: var(--text-secondary-color);
font-style: italic;
}
}
.url-section {
display: flex;
flex-direction: column;
gap: 0.25rem;
.url-label {
font-weight: 500;
color: var(--text-color);
margin-bottom: 0.5rem;
}
.url-input {
width: 100%;
padding: 0.75rem;
}
.url-note {
color: var(--text-secondary-color);
font-size: 0.875rem;
margin-top: 0.25rem;
}
}
.or-text {
font-size: 0.9rem;
color: var(--text-color);
font-weight: 500;
}
p-message {
margin-top: 1rem;
}
.dialog-footer {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 1rem;
}
}
@@ -1,125 +0,0 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {of, throwError} from 'rxjs';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {TranslocoService} from '@jsverse/transloco';
import {getTranslocoModule} from '../../../../core/testing/transloco-testing';
import {BackgroundUploadService} from '../background-upload.service';
import {UploadDialogComponent} from './upload-dialog.component';
describe('UploadDialogComponent', () => {
let fixture: ComponentFixture<UploadDialogComponent>;
let component: UploadDialogComponent;
let dialogRef: {close: ReturnType<typeof vi.fn>};
let backgroundUploadService: {
uploadFile: ReturnType<typeof vi.fn>;
uploadUrl: ReturnType<typeof vi.fn>;
};
let translocoService: TranslocoService;
beforeEach(async () => {
dialogRef = {
close: vi.fn(),
};
backgroundUploadService = {
uploadFile: vi.fn(() => of('https://example.com/uploaded.png')),
uploadUrl: vi.fn(() => of('https://example.com/from-url.png')),
};
await TestBed.configureTestingModule({
imports: [UploadDialogComponent, getTranslocoModule()],
providers: [
{provide: DynamicDialogRef, useValue: dialogRef},
{provide: BackgroundUploadService, useValue: backgroundUploadService},
],
}).compileComponents();
fixture = TestBed.createComponent(UploadDialogComponent);
component = fixture.componentInstance;
translocoService = TestBed.inject(TranslocoService);
});
afterEach(() => {
vi.restoreAllMocks();
TestBed.resetTestingModule();
});
it('stores the selected file and clears the URL field', () => {
const file = new File(['image'], 'cover.png', {type: 'image/png'});
const event = {
target: {
files: [file],
},
} as unknown as Event;
component.uploadImageUrl = 'https://example.com/old.png';
component.onFileSelected(event);
expect(component.uploadFile).toBe(file);
expect(component.uploadImageUrl).toBe('');
});
it('requires either a file or a URL before uploading', () => {
component.submit();
expect(component.uploadError).toBe(
translocoService.translate('layout.uploadDialog.errorNoInput')
);
expect(backgroundUploadService.uploadFile).not.toHaveBeenCalled();
expect(backgroundUploadService.uploadUrl).not.toHaveBeenCalled();
});
it('uploads a selected file and closes the dialog with the returned URL', () => {
const file = new File(['image'], 'cover.png', {type: 'image/png'});
component.uploadFile = file;
component.submit();
expect(backgroundUploadService.uploadFile).toHaveBeenCalledWith(file);
expect(dialogRef.close).toHaveBeenCalledWith({
imageUrl: 'https://example.com/uploaded.png',
});
});
it('uploads a trimmed URL and closes the dialog with the returned value', () => {
component.uploadImageUrl = ' https://example.com/bg.png ';
component.submit();
expect(backgroundUploadService.uploadUrl).toHaveBeenCalledWith('https://example.com/bg.png');
expect(dialogRef.close).toHaveBeenCalledWith({
imageUrl: 'https://example.com/from-url.png',
});
});
it('shows an error when the upload succeeds without returning an image URL', () => {
backgroundUploadService.uploadUrl.mockReturnValueOnce(of(''));
component.uploadImageUrl = 'https://example.com/bg.png';
component.submit();
expect(component.uploadError).toBe('Failed to upload image.');
expect(dialogRef.close).not.toHaveBeenCalled();
});
it('shows a generic upload error when the upload request fails', () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined);
backgroundUploadService.uploadFile.mockReturnValueOnce(
throwError(() => new Error('boom'))
);
component.uploadFile = new File(['image'], 'cover.png', {type: 'image/png'});
component.submit();
expect(component.uploadError).toBe('Upload failed. Please try again.');
expect(console.error).toHaveBeenCalled();
expect(dialogRef.close).not.toHaveBeenCalled();
});
it('closes the dialog when cancel is clicked', () => {
component.cancel();
expect(dialogRef.close).toHaveBeenCalledWith();
});
});
@@ -1,74 +0,0 @@
import {Component, inject} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {Button} from 'primeng/button';
import {InputText} from 'primeng/inputtext';
import {Divider} from 'primeng/divider';
import {Message} from 'primeng/message';
import {BackgroundUploadService} from '../background-upload.service';
import {take} from 'rxjs';
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
@Component({
selector: 'app-upload-dialog',
standalone: true,
templateUrl: './upload-dialog.component.html',
styleUrls: ['./upload-dialog.component.scss'],
imports: [
FormsModule,
Button,
InputText,
Divider,
Message,
TranslocoDirective,
TranslocoPipe
]
})
export class UploadDialogComponent {
private readonly dialogRef = inject(DynamicDialogRef);
private readonly backgroundUploadService = inject(BackgroundUploadService);
private readonly t = inject(TranslocoService);
uploadImageUrl = '';
uploadFile: File | null = null;
uploadError = '';
onFileSelected(event: Event) {
const input = event.target as HTMLInputElement;
if (input.files && input.files.length > 0) {
this.uploadFile = input.files[0];
this.uploadImageUrl = '';
}
}
submit() {
this.uploadError = '';
let upload$;
if (this.uploadFile) {
upload$ = this.backgroundUploadService.uploadFile(this.uploadFile);
} else if (this.uploadImageUrl.trim()) {
upload$ = this.backgroundUploadService.uploadUrl(this.uploadImageUrl.trim());
} else {
this.uploadError = this.t.translate('layout.uploadDialog.errorNoInput');
return;
}
upload$.pipe(take(1)).subscribe({
next: (imageUrl) => {
if (imageUrl) {
this.dialogRef.close({ imageUrl });
} else {
this.uploadError = 'Failed to upload image.';
}
},
error: (err) => {
console.error('Upload failed:', err);
this.uploadError = 'Upload failed. Please try again.';
}
});
}
cancel() {
this.dialogRef.close();
}
}
@@ -1,37 +0,0 @@
import Aura from '@primeuix/themes/aura';
import {describe, expect, it} from 'vitest';
import ExtendedAura from './theme-palette-extend';
interface AppThemePreset {
primitive?: Record<string, Record<string, string>>;
semantic?: AppThemeSemantic;
}
interface AppThemeSemantic {
colorScheme?: {
light?: AppThemeColorScheme;
dark?: AppThemeColorScheme;
};
}
interface AppThemeColorScheme {
content?: {
background?: string;
};
}
describe('theme-palette-extend', () => {
it('extends Aura with custom primitive palettes and app content surfaces', () => {
const auraPrimitive = Aura.primitive as Record<string, Record<string, string>>;
const preset = ExtendedAura as AppThemePreset;
expect(auraPrimitive).toBeTruthy();
expect(auraPrimitive['coralSunset']['500']).toBe('#ef7550');
expect(auraPrimitive['skyBlue']['700']).toBe('#2e88e6');
expect(auraPrimitive['dustyNeutral']['950']).toBe('#2f2821');
expect(preset.primitive?.['coralSunset']['500']).toBe('#ef7550');
expect(preset.semantic?.colorScheme?.light?.content?.background).toBe('var(--surface-page)');
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--surface-page)');
});
});
@@ -1,241 +0,0 @@
import Aura from '@primeuix/themes/aura';
import { definePreset } from '@primeuix/themes';
type ColorPalette = Record<string, string>;
/*
* PrimeNG theme bridge.
*
* App-owned CSS tokens define the native shell/page foundation. This file only
* extends Prime's Aura preset so Prime components can use the same app-selected
* palettes and the same app-owned page background.
*/
/* Extra primary palettes exposed to the theme configurator and Prime runtime. */
const customPalettes: Record<string, ColorPalette> = {
coralSunset: {
50: '#fef7f0',
100: '#feede1',
200: '#fcd9c2',
300: '#f9be9e',
400: '#f59673',
500: '#ef7550',
600: '#de5a3a',
700: '#b94730',
800: '#943a2e',
900: '#78322a',
950: '#401814'
},
roseBlush: {
50: '#fef7f7',
100: '#feebeb',
200: '#fddcdc',
300: '#fbbfbf',
400: '#f69393',
500: '#ed6767',
600: '#d93f3f',
700: '#b73030',
800: '#982d2d',
900: '#7f2d2d',
950: '#451313'
},
melonBlush: {
50: '#fffafb',
100: '#fff2f4',
200: '#ffdfe7',
300: '#ffcbd4',
400: '#ffaebb',
500: '#ff90a2',
600: '#ff6f88',
700: '#e8506b',
800: '#b7384d',
900: '#7f2231',
950: '#3f1118'
},
cottonCandy: {
50: '#fff9fb',
100: '#fff0f6',
200: '#ffdfee',
300: '#ffc0e0',
400: '#ffa3cf',
500: '#ff86bf',
600: '#ff69ad',
700: '#e14f93',
800: '#b93a72',
900: '#86284f',
950: '#42142a'
},
apricotSunrise: {
50: '#fffaf7',
100: '#fff1e8',
200: '#ffe2c9',
300: '#ffd2a8',
400: '#ffbf88',
500: '#ffad68',
600: '#ff974f',
700: '#e67a3b',
800: '#b6572b',
900: '#7f351b',
950: '#3f190f'
},
antiqueBronze: {
50: '#faf7f2',
100: '#f4ede0',
200: '#e8d9c0',
300: '#d9c199',
400: '#c8a56f',
500: '#b8904f',
600: '#a67c44',
700: '#8a6439',
800: '#715233',
900: '#5c442c',
950: '#302316'
},
butteryYellow: {
50: '#fffef7',
100: '#fffceb',
200: '#fff7d1',
300: '#ffeea7',
400: '#ffe072',
500: '#ffcf45',
600: '#ffb61f',
700: '#ff9b0a',
800: '#cc7606',
900: '#a35f0c',
950: '#633204'
},
vanillaCream: {
50: '#fefdfb',
100: '#fefbf6',
200: '#fdf5ea',
300: '#fbecd5',
400: '#f7dbb5',
500: '#f1c589',
600: '#e8a95c',
700: '#d88d3e',
800: '#b47134',
900: '#915c2e',
950: '#4e2f17'
},
citrusMint: {
50: '#fbfff9',
100: '#f4fff2',
200: '#e8ffd9',
300: '#d1ffbc',
400: '#b7ffa0',
500: '#96ff84',
600: '#76e96e',
700: '#4fb84c',
800: '#2f7f32',
900: '#1a4f20',
950: '#0a2410'
},
freshMint: {
50: '#f8fff9',
100: '#f0fff3',
200: '#dcffea',
300: '#bfffd6',
400: '#99ffc2',
500: '#7fffae',
600: '#5fe592',
700: '#3fbf75',
800: '#2d8f55',
900: '#1e5f39',
950: '#0f2f1d'
},
sagePearl: {
50: '#fbfdfb',
100: '#f4f8f4',
200: '#e6efe6',
300: '#d1e6d1',
400: '#bcdcbf',
500: '#9fcfa8',
600: '#84b792',
700: '#5f8f6e',
800: '#3f6648',
900: '#25442e',
950: '#0f2118'
},
skyBlue: {
50: '#f7fbff',
100: '#eef6ff',
200: '#dceefd',
300: '#c1e8ff',
400: '#99dfff',
500: '#6fc8ff',
600: '#48afff',
700: '#2e88e6',
800: '#2360b3',
900: '#153d80',
950: '#071d40'
},
periwinkleCream: {
50: '#fbfbff',
100: '#f2f3ff',
200: '#e7eaff',
300: '#d2dcff',
400: '#b9c9ff',
500: '#9fb2ff',
600: '#7f97ff',
700: '#5f78e6',
800: '#4559b3',
900: '#2b387f',
950: '#151c40'
},
pastelRoyalBlue: {
50: '#f6fbff',
100: '#eef6ff',
200: '#dbeeff',
300: '#b9ddff',
400: '#92c7ff',
500: '#63aaff',
600: '#3b88ff',
700: '#2e66cc',
800: '#235099',
900: '#183366',
950: '#0d1a33'
},
lavenderDream: {
50: '#fbf7ff',
100: '#f6eeff',
200: '#ebdcff',
300: '#dcc0ff',
400: '#caa1ff',
500: '#b47fff',
600: '#9366e6',
700: '#6f45b3',
800: '#4c2f80',
900: '#2d1b4f',
950: '#15082a'
},
dustyNeutral: {
50: '#faf9f7',
100: '#f3f1ed',
200: '#e8e3db',
300: '#d8cfc2',
400: '#c4b5a3',
500: '#b39c85',
600: '#a28a70',
700: '#87725d',
800: '#6f5e4e',
900: '#5a4e42',
950: '#2f2821'
}
};
if (!Aura.primitive) {
Aura.primitive = {};
}
Object.assign(Aura.primitive, customPalettes);
const AppPrimePreset = definePreset(Aura, {
semantic: {
colorScheme: {
light: { content: { background: 'var(--surface-page)' } },
dark: { content: { background: 'var(--surface-page)' } }
}
}
});
export default AppPrimePreset;
@@ -0,0 +1,76 @@
import {describe, expect, it} from 'vitest';
import ExtendedAura, {primeThemeTokenPalettes} from './theme-palette-extend';
interface AppThemePreset {
semantic?: AppThemeSemantic;
}
interface AppThemeSemantic {
colorScheme?: {
light?: AppThemeColorScheme;
dark?: AppThemeColorScheme;
};
}
interface AppThemeColorScheme {
content?: {
background?: string;
};
primary?: {
color?: string;
contrastColor?: string;
hoverColor?: string;
activeColor?: string;
};
highlight?: {
background?: string;
color?: string;
};
}
interface AppThemePresetComponents {
components?: {
button?: {
colorScheme?: {
light?: {
outlined?: Record<string, { borderColor?: string; color?: string }>;
};
};
};
};
}
describe('theme-palette-extend', () => {
it('bridges app content surfaces', () => {
const preset = ExtendedAura as AppThemePreset;
expect(preset.semantic?.colorScheme?.light?.content?.background).toBe('var(--color-page)');
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--color-page)');
});
it('uses balanced light outlined button tokens', () => {
const outlined = (ExtendedAura as AppThemePreset & AppThemePresetComponents)
.components?.button?.colorScheme?.light?.outlined;
expect(outlined?.['primary']).toMatchObject({
borderColor: 'var(--color-primary)',
color: 'var(--color-primary)',
});
expect(outlined?.['info']).toMatchObject({ borderColor: '{sky.400}', color: '{sky.600}' });
expect(outlined?.['help']).toMatchObject({ borderColor: '{purple.400}', color: '{purple.600}' });
expect(outlined?.['secondary']).toMatchObject({
borderColor: '{surface.400}',
color: '{surface.600}',
});
});
it('defines Prime palettes from app CSS tokens', () => {
const palettes = primeThemeTokenPalettes();
expect(palettes.primary['0']).toBeUndefined();
expect(palettes.primary['500']).toBe('var(--color-primary-500)');
expect(palettes.surface['0']).toBe('var(--color-surface-0)');
expect(palettes.surface['950']).toBe('var(--color-surface-950)');
});
});
@@ -0,0 +1,124 @@
import Aura from '@primeuix/themes/aura';
import {$t, definePreset} from '@primeuix/themes';
export type ColorPalette = Record<string, string>;
export interface ResolvedThemePalettes {
primary: ColorPalette;
surface: ColorPalette;
}
const COLOR_STOPS = ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900', '950'] as const;
const SURFACE_STOPS = ['0', ...COLOR_STOPS] as const;
/*
* PrimeNG theme bridge.
*
* App-owned CSS tokens define the native shell/page foundation. This file only
* extends Prime's Aura preset so Prime components can use the same app-selected
* palettes and the same Tailwind-owned page background.
*/
/** Popup menu surfaces use card elevation, not page canvas. */
const menuRoot = { background: 'var(--color-card)' };
/*
* Aura light outlined buttons default to *-200 borders — too faint on --color-card.
* Use *-400 borders and *-600 text: readable without feeling heavy.
*/
const lightOutlinedButton = {
primary: { borderColor: 'var(--color-primary)', color: 'var(--color-primary)' },
secondary: { borderColor: '{surface.400}', color: '{surface.600}' },
plain: { borderColor: '{surface.400}', color: '{surface.600}' },
success: { borderColor: '{green.400}', color: '{green.600}' },
info: { borderColor: '{sky.400}', color: '{sky.600}' },
warn: { borderColor: '{orange.400}', color: '{orange.600}' },
danger: { borderColor: '{red.400}', color: '{red.600}' },
help: { borderColor: '{purple.400}', color: '{purple.600}' },
};
const appPrimary = {
color: 'var(--color-primary)',
contrastColor: 'var(--color-primary-contrast)',
hoverColor: 'var(--color-primary-hover)',
activeColor: 'var(--color-primary-active)',
};
const appHighlight = {
background: 'color-mix(in srgb, var(--color-primary), transparent 84%)',
focusBackground: 'color-mix(in srgb, var(--color-primary), transparent 76%)',
color: 'var(--color-primary-text)',
focusColor: 'var(--color-primary-text)',
};
function buildAppTokenPalette(prefix: 'primary' | 'surface', stops: readonly string[]): ColorPalette {
return Object.fromEntries(
stops.map((stop) => [stop, `var(--color-${prefix}-${stop})`])
);
}
const appTokenPalettes: ResolvedThemePalettes = {
primary: buildAppTokenPalette('primary', COLOR_STOPS),
surface: buildAppTokenPalette('surface', SURFACE_STOPS),
};
export function primeThemeTokenPalettes(): ResolvedThemePalettes {
return appTokenPalettes;
}
function buildPrimePalettePreset(theme: ResolvedThemePalettes): object {
return {
semantic: {
primary: theme.primary,
colorScheme: {
light: {
primary: appPrimary,
highlight: appHighlight,
},
dark: {
primary: appPrimary,
highlight: appHighlight,
},
},
},
};
}
const AppPrimePreset = definePreset(Aura, {
semantic: {
colorScheme: {
light: { content: { background: 'var(--color-page)' } },
dark: {
content: { background: 'var(--color-page)' },
// Card menus are surface.800; Aura default hover is also 800 — use app surface-hover mix.
navigation: {
item: {
focusBackground: 'color-mix(in srgb, {text.color}, transparent 92%)',
activeBackground: 'color-mix(in srgb, {text.color}, transparent 92%)',
},
},
},
},
},
components: {
menu: { root: menuRoot },
tieredmenu: { root: menuRoot },
contextmenu: { root: menuRoot },
menubar: { submenu: menuRoot },
button: {
colorScheme: {
light: { outlined: lightOutlinedButton },
},
},
},
});
export function applyPrimeTheme(theme: ResolvedThemePalettes): void {
$t()
.preset(AppPrimePreset)
.preset(buildPrimePalettePreset(theme))
.surfacePalette(theme.surface)
.use({useDefaultOptions: true});
}
export default AppPrimePreset;