feat(elements): Revamp consent components with improved theming, layout, and accessibility

This commit is contained in:
2025-11-30 21:43:36 +00:00
parent 8a26378689
commit 0b366b360d
5 changed files with 243 additions and 185 deletions

View File

@@ -33,191 +33,192 @@ export class ConsentsoftwareCookieconsent extends LitElement {
public static styles = css`
:host {
font-family: ${shared.fontStack};
font-size: 14px;
user-select: none;
/* Default variables for Light Theme */
--text-color: #333;
--background-color: #eeeeee;
--accent-color: #333333;
--button-bg: #ffffff;
--button-hover-bg: #f2f2f2;
--icon-color: #4496f5;
--link-color: #333;
--padding-sides: 16px;
/* Additional variables for modal and info container styling */
--info-bg: rgba(0, 0, 0, 0.1);
--info-text: rgba(255, 255, 255, 0.5);
--modal-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
/* Shadcn-inspired Dark Theme (default) */
--background: hsl(0 0% 7%);
--foreground: hsl(0 0% 95%);
--muted: hsl(0 0% 15%);
--muted-foreground: hsl(0 0% 64%);
--border: hsl(0 0% 18%);
--input: hsl(0 0% 15%);
--primary: hsl(0 0% 98%);
--primary-foreground: hsl(0 0% 9%);
--secondary: hsl(0 0% 15%);
--secondary-foreground: hsl(0 0% 98%);
--accent: hsl(0 0% 15%);
--accent-foreground: hsl(0 0% 98%);
--ring: hsl(0 0% 30%);
--radius: 8px;
}
/* Dark Theme Overrides:
When theme attribute is 'dark', override variables accordingly. */
:host([theme='dark']) {
--text-color: #fff;
--background-color: #111;
--accent-color: #333333;
--button-bg: #252525;
--button-hover-bg: #222222;
--icon-color: #4496f5;
--link-color: #fff;
--info-bg: rgba(0, 0, 0, 0.1);
--info-text: rgba(255, 255, 255, 0.5);
--modal-box-shadow: 0px 0px 8px rgba(255, 255, 255, 0.6);
--background: hsl(0 0% 7%);
--foreground: hsl(0 0% 95%);
--muted: hsl(0 0% 15%);
--muted-foreground: hsl(0 0% 64%);
--border: hsl(0 0% 18%);
--input: hsl(0 0% 15%);
--primary: hsl(0 0% 98%);
--primary-foreground: hsl(0 0% 9%);
--secondary: hsl(0 0% 15%);
--secondary-foreground: hsl(0 0% 98%);
--accent: hsl(0 0% 15%);
--accent-foreground: hsl(0 0% 98%);
--ring: hsl(0 0% 30%);
}
/* Light Theme Overrides:
Explicit light theme settings, currently matching defaults.
Can be customized independently if desired. */
:host([theme='light']) {
--text-color: #333;
--background-color: #eeeeee;
--accent-color: #333333;
--button-bg: #ffffff;
--button-hover-bg: #f2f2f2;
--icon-color: #4496f5;
--link-color: #333;
--info-bg: rgba(0, 0, 0, 0.1);
--info-text: rgba(0, 0, 0, 0.5);
--modal-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
--background: hsl(0 0% 100%);
--foreground: hsl(0 0% 9%);
--muted: hsl(0 0% 96%);
--muted-foreground: hsl(0 0% 45%);
--border: hsl(0 0% 90%);
--input: hsl(0 0% 90%);
--primary: hsl(0 0% 9%);
--primary-foreground: hsl(0 0% 98%);
--secondary: hsl(0 0% 96%);
--secondary-foreground: hsl(0 0% 9%);
--accent: hsl(0 0% 96%);
--accent-foreground: hsl(0 0% 9%);
--ring: hsl(0 0% 64%);
}
/* Overlay covering the page behind the modal */
.pageOverlay {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
inset: 0;
display: grid;
align-items: center;
justify-content: center;
z-index: 1000; /* Ensures the overlay is on top of other elements */
background: rgba(255, 255, 255, 0);
z-index: 1000;
background: rgba(0, 0, 0, 0);
backdrop-filter: blur(0px);
transition: all 0.2s;
transition: all 0.2s ease-out;
}
/* Shake animation for overlay when clicked */
.pageOverlay.shake {
background: rgba(0, 0, 0, 0.5) !important;
background: rgba(0, 0, 0, 0.6) !important;
}
/* Modal box styling using theme variables for colors and shadows */
.modalBox {
display: block;
color: var(--text-color);
background: var(--background-color);
box-shadow: var(--modal-box-shadow);
color: var(--foreground);
background: var(--background);
box-shadow:
0 0 0 1px var(--border),
0 16px 70px rgba(0, 0, 0, 0.35);
position: relative;
border: 1px dotted rgba(255, 255, 255, 0.1);
border-top: 1px solid var(--accent-color);
border-radius: 16px;
max-width: 1100px;
min-width: calc(100vw / 3);
border-radius: var(--radius);
max-width: 520px;
min-width: 320px;
box-sizing: border-box;
overflow: hidden;
will-change: transform;
transition: all 0.3s;
transform: scale(0.95);
transition: all 0.2s ease-out;
transform: scale(0.96);
opacity: 0;
}
/* Media query for mobile devices: stack buttons vertically */
@media (max-width: 600px) {
@media (max-width: 560px) {
.modalBox {
max-width: 100%;
min-width: 100%;
height: 100vh;
box-shadow: none;
border-radius: 0px;
border-radius: 0;
}
}
/* Shake animation for modal box */
.modalBox.shake {
animation: shake 150ms 2 linear;
animation: shake 120ms 2 linear;
}
@keyframes shake {
0% {
transform: translate(3px, 0);
}
50% {
transform: translate(-3px, 0);
}
100% {
transform: translate(0, 0);
}
0% { transform: translateX(3px); }
50% { transform: translateX(-3px); }
100% { transform: translateX(0); }
}
/* Toggle display based on [show] attribute */
:host([show='false']) {
display: none;
}
:host([show='true']) {
display: block;
}
:host([show='false']) { display: none; }
:host([show='true']) { display: block; }
.content {
margin: auto;
}
.text-container {
padding-left: var(--padding-sides);
padding-right: var(--padding-sides);
display: grid;
grid-template-columns: auto;
padding: 12px 16px;
font-size: 0.9em;
line-height: 1.5;
color: var(--muted-foreground);
}
.text-container a {
color: var(--link-color);
text-decoration: none;
color: var(--foreground);
text-decoration: underline;
text-underline-offset: 2px;
}
.text-container a:hover {
opacity: 0.8;
}
.button-container {
padding: var(--padding-sides);
padding: 12px 16px 16px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
gap: 8px;
}
/* Media query for mobile devices: stack buttons vertically */
@media (max-width: 600px) {
@media (max-width: 560px) {
.button-container {
grid-template-columns: 1fr;
}
}
/* Consent button styling using theme variables */
.consent-button {
border-radius: 3px;
background: var(--button-bg);
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
padding: 10px;
line-height: 30px;
border-radius: calc(var(--radius) - 2px);
background: var(--secondary);
border: 1px solid var(--border);
padding: 8px 16px;
font-size: 0.85em;
font-weight: 500;
text-align: center;
cursor: pointer;
transition: all 0.2s;
transition: all 0.15s ease;
color: var(--secondary-foreground);
}
.consent-button:hover {
background: var(--button-hover-bg);
background: var(--accent);
border-color: var(--ring);
}
.consent-button:last-child {
background: var(--primary);
color: var(--primary-foreground);
border-color: var(--primary);
}
.consent-button:last-child:hover {
opacity: 0.9;
}
/* Use theme variables for info container background and text */
.info-container {
text-align: center;
line-height: 3em;
background: var(--info-bg);
border-top: 1px dotted rgba(255, 255, 255, 0.1);
font-size: 0.8em;
color: var(--info-text);
padding: 10px 16px;
background: var(--muted);
border-top: 1px solid var(--border);
font-size: 0.75em;
color: var(--muted-foreground);
}
.info-container a {
text-decoration: underline;
color: var(--link-color);
transition: color 0.2s;
color: var(--foreground);
text-decoration: none;
}
.info-container a:hover {
color: #ffffff;
text-decoration: underline;
}
`;
@@ -234,11 +235,11 @@ export class ConsentsoftwareCookieconsent extends LitElement {
<div class="content">
<consentsoftware-header></consentsoftware-header>
<consentsoftware-tabs></consentsoftware-tabs>
<div class="text-container" style="padding: 16px;">
<div class="text-container">
<div class="toptext">
This page uses cookies. Please review our
We use cookies to enhance your experience. Review our
<a href="https://lossless.gmbh/cookie" target="_blank">cookie policy</a>
and choose which cookie level you are willing to accept.
and select your preferences.
</div>
</div>
<consentsoftware-mainselection></consentsoftware-mainselection>
@@ -291,9 +292,9 @@ export class ConsentsoftwareCookieconsent extends LitElement {
await this.updated();
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
if (pageOverlay) {
// Apply dark overlay styling when modal appears
pageOverlay.style.background = 'rgba(0,0,0, 0.5)';
pageOverlay.style.backdropFilter = 'blur(20px)';
// Apply subtle backdrop blur when modal appears
pageOverlay.style.background = 'rgba(0,0,0, 0.6)';
pageOverlay.style.backdropFilter = 'blur(4px)';
}
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
if (modalBox) {
@@ -335,8 +336,7 @@ export class ConsentsoftwareCookieconsent extends LitElement {
console.log(`Set level to ${levelsArg}`);
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
if (pageOverlay) {
// Fade out overlay effect using inline styles for transition
pageOverlay.style.background = 'rgba(255,255,255, 0)';
pageOverlay.style.background = 'rgba(0,0,0, 0)';
pageOverlay.style.backdropFilter = 'blur(0px)';
}
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');