8 Commits

10 changed files with 1636 additions and 1071 deletions

View File

@@ -1,5 +1,35 @@
# Changelog # Changelog
## 2025-11-30 - 1.6.1 - fix(build)
Update TypeScript config and build tooling; use accessor for Lit properties; bump deps and adjust package metadata
- ts_web/tsconfig.json: target -> ES2022, module -> ES2022, moduleResolution -> bundler, lib updated to ES2022/DOM/DOM.Iterable
- tsconfig.json (root): target -> ES2022, module -> NodeNext, moduleResolution -> NodeNext
- Component properties migrated to use the TypeScript 'accessor' modifier (consentsoftware-cookieconsent, consentsoftware-mainselection, consentsoftware-toggle)
- Bumped runtime and dev dependencies: lit -> ^3.3.1; upgrades to @design.estate/dees-wcctools, @git.zone/tsbuild, @git.zone/tsbundle, @git.zone/tswatch
- Package metadata: author updated to Task Venture Capital GmbH and test script changed to use pnpm
## 2025-01-22 - 1.6.0 - feat(elements)
Enhance theme handling and CSS organization for consent component
- Introduced theme-specific CSS variables for better theming support in consentsoftware-cookieconsent.
- Reorganized styles in consentsoftware-cookieconsent for cleaner look and consistency.
- Added media queries for responsive design in consentsoftware-tabs.
## 2025-01-21 - 1.5.4 - fix(consentsoftware-components)
Add interactive consent software components for managing cookie levels.
- Implemented 'consentsoftware-cookieconsent' component for cookie management
- Introduced 'consentsoftware-toggle' for user interaction improvements
- Added theme support for light/dark modes in consent components
- Enhanced consent interface with responsive design and accessibility features
## 2025-01-20 - 1.5.3 - fix(consentsoftware-cookieconsent)
Fix visual inconsistencies in the consent software modal overlay and shadow.
- Updated the shadow color in the modal box to use a consistent color.
- Restored backdrop blur effect in the page overlay when visible.
## 2025-01-20 - 1.5.2 - fix(core) ## 2025-01-20 - 1.5.2 - fix(core)
No changes detected No changes detected

View File

@@ -1,6 +1,6 @@
{ {
"name": "@consent.software/catalog", "name": "@consent.software/catalog",
"version": "1.5.2", "version": "1.6.1",
"private": false, "private": false,
"description": "A library of web components designed to integrate robust consent management capabilities into web applications, ensuring compliance with privacy regulations.", "description": "A library of web components designed to integrate robust consent management capabilities into web applications, ensuring compliance with privacy regulations.",
"exports": { "exports": {
@@ -8,23 +8,23 @@
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "npm run build", "test": "pnpm run build",
"build": "tsbuild tsfolders --allowimplicitany && tsbundle element --production", "build": "tsbuild tsfolders --allowimplicitany && tsbundle element --production",
"watch": "tswatch element" "watch": "tswatch element"
}, },
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@consent.software/interfaces": "^1.0.14", "@consent.software/interfaces": "^1.0.14",
"@consent.software/webclient": "^1.1.0", "@consent.software/webclient": "^1.1.0",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"lit": "^3.2.1" "lit": "^3.3.1"
}, },
"devDependencies": { "devDependencies": {
"@design.estate/dees-wcctools": "^1.0.90", "@design.estate/dees-wcctools": "^1.2.1",
"@git.zone/tsbuild": "^2.2.0", "@git.zone/tsbuild": "^3.1.2",
"@git.zone/tsbundle": "^2.1.0", "@git.zone/tsbundle": "^2.6.2",
"@git.zone/tswatch": "^2.0.37", "@git.zone/tswatch": "^2.2.1",
"@push.rocks/projectinfo": "^5.0.2" "@push.rocks/projectinfo": "^5.0.2"
}, },
"files": [ "files": [

2199
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

251
readme.md
View File

@@ -1,138 +1,207 @@
# @consent.software_private/catalog # @consent.software/catalog
Webcomponents for consent.software widget. A sleek, modern library of web components for seamless consent management integration. Built with Lit and designed for GDPR/CCPA compliance out of the box.
## Install ## Issue Reporting and Security
To install this module, you need to have [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed on your machine. You can then run the following command in your terminal to add the module to your project: For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
```shell ## Features
npm install @consent.software_private/catalog
🍪 **Cookie Consent Modal** - Beautiful, responsive consent dialog with light/dark theme support
🎛️ **Interactive Toggles** - Draggable toggle switches with smooth animations
📱 **Mobile-First Design** - Fully responsive across all device sizes
🎨 **Theme-Aware** - Automatically detects system light/dark mode preference
🔒 **Privacy-First** - Integrates with consent.software backend for compliant consent tracking
**Zero Config** - Drop-in components that just work
## Installation
```bash
npm install @consent.software/catalog
# or
pnpm add @consent.software/catalog
``` ```
Ensure you have ESM support enabled in your TypeScript configuration, as this package uses ES module syntax. ## Quick Start
## Usage Import the components and add the consent banner to your page:
The `@consent.software_private/catalog` module offers a set of web components to integrate consent management capabilities into your web application. These components leverage modern browser APIs and employ a system for cookie management that aligns with regulatory requirements.
### Initial Setup
First, import the necessary modules and set up your project to use the web components provided:
```typescript ```typescript
import '@consent.software_private/catalog'; import '@consent.software/catalog';
// That's it! Add the component to your HTML
``` ```
Ensure this import statement is included in your main JavaScript/TypeScript file where you want to utilize the consent management web components. It is vital to transpile with TypeScript compiler settings that support ES modules. ```html
<consentsoftware-cookieconsent></consentsoftware-cookieconsent>
### Building a Consent Modal
A primary feature of this module is the `consentsoftware-cookieconsent` component. This component can be embedded into your application to allow users to select their preferred cookie levels.
#### Setting Up the Environment
Before creating instances of the components, make sure your project environment is ready. Setup the DOM tools and any associated dependencies:
```typescript
import { domtools } from '@design.estate/dees-domtools';
domtools.elementBasic.setup();
``` ```
#### Using the Consentsoftware-Cookieconsent Component The consent banner automatically:
- Shows on first visit when no consent preferences are stored
- Hides after user makes a selection
- Respects system dark/light mode
- Stores preferences via the consent.software backend
Here's how you can include the `consentsoftware-cookieconsent` component in your application: ## Components
```typescript ### `<consentsoftware-cookieconsent>`
import { html, render } from 'lit-html';
const template = html` The main consent modal component. Provides a full-screen overlay with cookie preference options.
<consentsoftware-cookieconsent></consentsoftware-cookieconsent>
`;
render(template, document.body); ```html
<consentsoftware-cookieconsent></consentsoftware-cookieconsent>
``` ```
This will add the consent banner to the bottom of the page, providing users options to set their preferences. **Features:**
- Three-button interface: Deny, Accept Selection, Accept All
- Four cookie categories: Required, Preferences, Statistics, Marketing
- Animated modal with backdrop blur
- Shake feedback when clicking outside the modal
- Automatic theme detection (light/dark)
#### Customizing the Component ### `<consentsoftware-toggle>`
The `consentsoftware-cookieconsent` component allows you to customize its design via CSS properties. Leverage light and dark themes through the CSS manager used in styling attributes: A draggable toggle switch component with touch support.
```typescript ```html
const styles = ` <consentsoftware-toggle>Label Text</consentsoftware-toggle>
:host { <consentsoftware-toggle required>Required</consentsoftware-toggle>
--cookieconsent-height: 70px;
--cookieconsent-background: #222;
--cookieconsent-text-color: #fff;
}
`;
``` ```
Apply these custom styles to modify the appearance to match your site's design language. **Properties:**
- `required` (boolean) - When true, toggle is locked in the "on" position
- `selected` (boolean) - Current toggle state
#### Handling User Interactions **Events:**
- `toggle` - Fired when state changes, includes `{ selected: boolean }` in detail
The component is interactive, responding to user actions to set cookie levels. Heres how the interaction flow works: ### `<consentsoftware-tabs>`
1. **User Interaction**: Users click one of the consent buttons (e.g., "Functional Cookies"). Tab navigation component with animated indicator.
2. **Handling Consent Levels**: The component's `setLevel` method is invoked, updating the user's cookie preferences, e.g.:
```html
<consentsoftware-tabs></consentsoftware-tabs>
```
Displays three tabs: Consent, Details, and Cookie Policy.
### `<consentsoftware-header>`
Simple header component for the consent modal.
```html
<consentsoftware-header></consentsoftware-header>
```
### `<consentsoftware-mainselection>`
Grid layout containing toggle switches for each cookie category.
```html
<consentsoftware-mainselection></consentsoftware-mainselection>
```
## Backend Integration
This catalog integrates with the `@consent.software/webclient` package for backend communication:
```typescript ```typescript
private async setLevel(event: MouseEvent, levelsArg: Array<TCookieLevel>) { import { CsWebclient } from '@consent.software/webclient';
await this.csWebclientInstance.setCookieLevels(levelsArg);
// Adjust styling and visibility const client = new CsWebclient();
this.setAttribute('gotIt', 'true');
await delayFor(300); // Check current consent levels
this.setAttribute('show', 'false'); const levels = await client.getCookieLevels();
// Update other business logic based on consent levels if (!levels) {
// Show consent dialog
}
// Set consent levels programmatically
await client.setCookieLevels(['functional', 'analytics']);
// Run consent-dependent scripts
await client.getAndRunConsentTuples();
```
## Styling & Theming
The components use CSS custom properties for easy theming:
```css
consentsoftware-cookieconsent {
/* Text and colors */
--text-color: #333;
--background-color: #eeeeee;
--accent-color: #333333;
/* Buttons */
--button-bg: #ffffff;
--button-hover-bg: #f2f2f2;
/* Links */
--link-color: #333;
--icon-color: #4496f5;
/* Modal */
--modal-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
--info-bg: rgba(0, 0, 0, 0.1);
--info-text: rgba(0, 0, 0, 0.5);
} }
``` ```
The system remembers user choices using a backend managed by the `consent.software` infrastructure. The component automatically switches to dark theme variables when `theme="dark"` is set or when the system prefers dark mode.
### Integrating with Your Backend ## Cookie Levels
For full functionality, the component interacts with a backend to manage user consent states. Using `@consent.software/webclient`, you can query the user's current consent levels, perform updates, and verify whether consent has been previously granted: The consent system uses three user-selectable levels plus a required baseline:
```typescript | Level | Description |
const webclientInstance = new CsWebclient(); |-------|-------------|
const cookieLevels = await webclientInstance.getCookieLevels(); | `functional` | Required cookies for site operation (always enabled) |
| `preferences` | User preference cookies |
| `analytics` | Statistics and analytics tracking |
| `marketing` | Marketing and advertising cookies |
if (!cookieLevels) { ## Browser Support
// Show consent dialog if no consent levels are set
document.querySelector('consentsoftware-cookieconsent').show = true; - Chrome (last 2 versions)
} else { - Firefox (last 2 versions)
// Apply the consent settings to your analytics, advertisements, etc. - Safari (last 2 versions)
applyConsentSettings(cookieLevels); - Edge (last 2 versions)
}
Built with modern ES modules and requires browsers with native Custom Elements v1 support.
## Development
```bash
# Install dependencies
pnpm install
# Build the project
pnpm run build
# Watch mode for development
pnpm run watch
``` ```
### Advanced Considerations ## License and Legal Information
#### Responsive Design This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
The component is responsive, optimized for various screen sizes using a grid layout. Ensure your main HTML elements are responsive to accommodate the consent bar. **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
#### Accessibility and Compliance ### Trademarks
Ensure your application properly adheres to legal and accessibility standards by aligning with the consent management system's features. This often involves using correct semantics, polyfills for custom elements, and thorough testing on different devices and browsers. This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
#### Managing State Across Sessions Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
Store user's consent preferences beyond the session using either localStorage, cookies, or server-side sessions. Adjust the components connectedCallback and updated lifecycle methods to fetch and apply these stored settings. ### Company Information
Proper handling ensures a seamless user experience, helping companies comply with international privacy laws like GDPR. Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
### Integration and Testing For any legal inquiries or further information, please contact us via email at hello@task.vc.
Test extensively in your development environment, ensure correct rendering, and simulate various user interactions to gain confidence in production-level functionality. Automated testing might include: By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
- Unit tests for lifecycle behavior using testing libraries such as Mocha or Jest.
- Integration trials ensuring the component plays well with surrounding UI elements.
### Conclusion
With these guidelines, developers can integrate, customize, and extend the consent management capabilities within their applications using `@consent.software_private/catalog`. Adapt the styling, maximize UX, and ensure regulatory compliance for a robust implementation. Mastery of the component enables seamless user consent handling and enhances your app's governance credentials.
undefined

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@consent.software/catalog', name: '@consent.software/catalog',
version: '1.5.2', version: '1.6.1',
description: 'A library of web components designed to integrate robust consent management capabilities into web applications, ensuring compliance with privacy regulations.' description: 'A library of web components designed to integrate robust consent management capabilities into web applications, ensuring compliance with privacy regulations.'
} }

View File

@@ -21,18 +21,20 @@ export class ConsentsoftwareCookieconsent extends LitElement {
public csWebclientInstance = new csWebclient.CsWebclient(); public csWebclientInstance = new csWebclient.CsWebclient();
public csWebclientRan = false; public csWebclientRan = false;
// Reflects the current theme ('light' or 'dark')
@property({ type: String, reflect: true }) @property({ type: String, reflect: true })
public theme: 'light' | 'dark' = 'light'; public accessor theme: 'light' | 'dark' = 'light';
/** /**
* We bind `heightPixels` to a CSS variable (--cookieconsent-height). * Define component styles with CSS variables that adjust based on theme.
* Then we can do margin-bottom animations in CSS. * The default variables serve as baseline for the light theme.
* Theme-specific overrides modify these for dark mode.
*/ */
public static styles = css` public static styles = css`
:host { :host {
font-family: ${shared.fontStack}; font-family: ${shared.fontStack};
user-select: none; user-select: none;
/* Default theme variables */ /* Default variables for Light Theme */
--text-color: #333; --text-color: #333;
--background-color: #eeeeee; --background-color: #eeeeee;
--accent-color: #333333; --accent-color: #333333;
@@ -41,8 +43,14 @@ export class ConsentsoftwareCookieconsent extends LitElement {
--icon-color: #4496f5; --icon-color: #4496f5;
--link-color: #333; --link-color: #333;
--padding-sides: 16px; --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);
} }
/* Dark Theme Overrides:
When theme attribute is 'dark', override variables accordingly. */
:host([theme='dark']) { :host([theme='dark']) {
--text-color: #fff; --text-color: #fff;
--background-color: #111; --background-color: #111;
@@ -51,8 +59,14 @@ export class ConsentsoftwareCookieconsent extends LitElement {
--button-hover-bg: #222222; --button-hover-bg: #222222;
--icon-color: #4496f5; --icon-color: #4496f5;
--link-color: #fff; --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);
} }
/* Light Theme Overrides:
Explicit light theme settings, currently matching defaults.
Can be customized independently if desired. */
:host([theme='light']) { :host([theme='light']) {
--text-color: #333; --text-color: #333;
--background-color: #eeeeee; --background-color: #eeeeee;
@@ -61,34 +75,39 @@ export class ConsentsoftwareCookieconsent extends LitElement {
--button-hover-bg: #f2f2f2; --button-hover-bg: #f2f2f2;
--icon-color: #4496f5; --icon-color: #4496f5;
--link-color: #333; --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);
} }
/* Overlay covering the page behind the modal */
.pageOverlay { .pageOverlay {
position: fixed; position: fixed;
top: 0px; top: 0;
bottom: 0px; bottom: 0;
right: 0px; right: 0;
left: 0px; left: 0;
display: grid; display: grid;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 1000; /* standard z-index for fixed elements */ z-index: 1000; /* Ensures the overlay is on top of other elements */
background: rgba(255, 255, 255, 0); background: rgba(255, 255, 255, 0);
backdrop-filter: blur(0px); backdrop-filter: blur(0px);
transition: all 0.2s; transition: all 0.2s;
} }
/* Shake animation for overlay when clicked */
.pageOverlay.shake { .pageOverlay.shake {
background: rgba(0, 0, 0, 0.5) !important; background: rgba(0, 0, 0, 0.5) !important;
backdrop-filter: blur(20px) !important;
} }
/* Modal box styling using theme variables for colors and shadows */
.modalBox { .modalBox {
display: block; display: block;
color: var(--text-color); color: var(--text-color);
background: var(--background-color); background: var(--background-color);
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.6); box-shadow: var(--modal-box-shadow);
position: realtive; position: relative;
border: 1px dotted rgba(255, 255, 255, 0.1); border: 1px dotted rgba(255, 255, 255, 0.1);
border-top: 1px solid var(--accent-color); border-top: 1px solid var(--accent-color);
border-radius: 16px; border-radius: 16px;
@@ -96,15 +115,24 @@ export class ConsentsoftwareCookieconsent extends LitElement {
min-width: calc(100vw / 3); min-width: calc(100vw / 3);
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
will-change: transform; /* ensure efficient rendering */ will-change: transform;
transition: all 0.3s; transition: all 0.3s;
transform: scale(0.95); transform: scale(0.95);
opacity: 0; opacity: 0;
} }
/* Media query for mobile devices: stack buttons vertically */
@media (max-width: 600px) {
.modalBox {
height: 100vh;
box-shadow: none;
border-radius: 0px;
}
}
/* Shake animation for modal box */
.modalBox.shake { .modalBox.shake {
animation: shake 150ms 2 linear; animation: shake 150ms 2 linear;
box-shadow: 0px 0px 8px rgba(255, 255, 255, 0.6);
} }
@keyframes shake { @keyframes shake {
@@ -119,10 +147,7 @@ export class ConsentsoftwareCookieconsent extends LitElement {
} }
} }
/* /* Toggle display based on [show] attribute */
* Toggle display based on [show] attribute
* (so if show=false, the banner doesn't show at all).
*/
:host([show='false']) { :host([show='false']) {
display: none; display: none;
} }
@@ -153,25 +178,14 @@ export class ConsentsoftwareCookieconsent extends LitElement {
gap: 16px; gap: 16px;
} }
.info-container { /* Media query for mobile devices: stack buttons vertically */
color: var(--text-color); @media (max-width: 600px) {
text-align: center; .button-container {
line-height: 3em; grid-template-columns: 1fr;
background: rgba(0, 0, 0, 0.1); }
border-top: 1px dotted rgba(255, 255, 255, 0.1);
font-size: 0.8em;
color: rgba(255, 255, 255, 0.5);
}
.info-container a {
text-decoration: underline;
color: var(--link-color);
transition: color 0.2s;
}
.info-container a:hover {
color: #ffffff;
} }
/* Consent button styling using theme variables */
.consent-button { .consent-button {
border-radius: 3px; border-radius: 3px;
background: var(--button-bg); background: var(--button-bg);
@@ -186,10 +200,30 @@ export class ConsentsoftwareCookieconsent extends LitElement {
.consent-button:hover { .consent-button:hover {
background: var(--button-hover-bg); background: var(--button-hover-bg);
} }
/* 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);
}
.info-container a {
text-decoration: underline;
color: var(--link-color);
transition: color 0.2s;
}
.info-container a:hover {
color: #ffffff;
}
`; `;
constructor() { constructor() {
super(); super();
// Initially hide the consent banner until needed
this.setAttribute('show', 'false'); this.setAttribute('show', 'false');
} }
@@ -207,36 +241,6 @@ export class ConsentsoftwareCookieconsent extends LitElement {
and choose which cookie level you are willing to accept. and choose which cookie level you are willing to accept.
</div> </div>
</div> </div>
<!-- <div class="button-container">
<div
class="consent-button"
@click=${(event: MouseEvent) =>
this.handleConsentButtonClick(event, ['functional'])}
>
Functional cookies
</div>
<div
class="consent-button"
@click=${(event: MouseEvent) =>
this.handleConsentButtonClick(event, ['functional', 'analytics'])}
>
Analytics cookies
</div>
<div
class="consent-button"
@click=${(event: MouseEvent) =>
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing'])}
>
Marketing cookies
</div>
<div
class="consent-button"
@click=${(event: MouseEvent) =>
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing', 'all'])}
>
All cookies
</div>
</div> -->
<consentsoftware-mainselection></consentsoftware-mainselection> <consentsoftware-mainselection></consentsoftware-mainselection>
<div class="button-container"> <div class="button-container">
<div <div
@@ -264,7 +268,6 @@ export class ConsentsoftwareCookieconsent extends LitElement {
<div class="info-container"> <div class="info-container">
consent management powered by consent management powered by
<a href="https://consent.software">consent.software</a> <a href="https://consent.software">consent.software</a>
(Open Source)
</div> </div>
</div> </div>
</div> </div>
@@ -273,41 +276,44 @@ export class ConsentsoftwareCookieconsent extends LitElement {
} }
/** /**
* Called when the element is inserted into the DOM. * Lifecycle method called when the element is connected to the DOM.
* It sets up the theme and displays the consent banner if no cookie levels are set.
*/ */
public async connectedCallback() { public async connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this.updateTheme(); this.updateTheme(); // Initialize theme based on system preference
const cookieLevel = await this.csWebclientInstance.getCookieLevels(); const cookieLevel = await this.csWebclientInstance.getCookieLevels();
if (!cookieLevel) { if (!cookieLevel) {
// Show consent banner if cookie levels haven't been set yet
this.setAttribute('show', 'true'); this.setAttribute('show', 'true');
requestAnimationFrame(async () => { requestAnimationFrame(async () => {
await this.updated(); await this.updated();
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay'); const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
if (pageOverlay) { if (pageOverlay) {
pageOverlay.style.background = 'rgba(255,255,255, 0.1)'; // Apply dark overlay styling when modal appears
pageOverlay.style.backdropFilter = 'blur(0px)'; pageOverlay.style.background = 'rgba(0,0,0, 0.5)';
pageOverlay.style.backdropFilter = 'blur(20px)';
} }
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox'); const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
if (modalBox) { if (modalBox) {
// Animate modal box appearance
modalBox.style.transform = `scale(1)`; modalBox.style.transform = `scale(1)`;
modalBox.style.opacity = '1'; modalBox.style.opacity = '1';
} }
}); });
} else { } else {
// Hide banner if cookie levels are already set
this.setAttribute('show', 'false'); this.setAttribute('show', 'false');
} }
} }
/** public async firstUpdated() {
* Called after the first render of the component. // Placeholder for any logic needed after first render
* We measure the actual height of the banner and update the CSS variable. }
*/
public async firstUpdated() {}
/** /**
* Called whenever the element is updated or re-rendered. * Called after updates. Logs banner height and runs consent scripts if necessary.
*/ */
public async updated() { public async updated() {
console.log(`The height of the cookie banner is ${this.shadowRoot?.host?.clientHeight}px`); console.log(`The height of the cookie banner is ${this.shadowRoot?.host?.clientHeight}px`);
@@ -319,7 +325,8 @@ export class ConsentsoftwareCookieconsent extends LitElement {
} }
/** /**
* Sets the users chosen cookie level(s) and hides the banner. * Handles consent button clicks, sets cookie levels, and hides the banner.
* Uses theme variables for styling transitions.
*/ */
private async handleConsentButtonClick( private async handleConsentButtonClick(
event: MouseEvent, event: MouseEvent,
@@ -328,21 +335,27 @@ export class ConsentsoftwareCookieconsent extends LitElement {
console.log(`Set level to ${levelsArg}`); console.log(`Set level to ${levelsArg}`);
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay'); const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
if (pageOverlay) { if (pageOverlay) {
// Fade out overlay effect using inline styles for transition
pageOverlay.style.background = 'rgba(255,255,255, 0)'; pageOverlay.style.background = 'rgba(255,255,255, 0)';
pageOverlay.style.backdropFilter = 'blur(0px)'; pageOverlay.style.backdropFilter = 'blur(0px)';
} }
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox'); const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
if (modalBox) { if (modalBox) {
// Scale down and fade out modal box before hiding
modalBox.style.transform = `scale(0.95)`; modalBox.style.transform = `scale(0.95)`;
modalBox.style.opacity = '0'; modalBox.style.opacity = '0';
} }
// Save user consent preferences
await this.csWebclientInstance.setCookieLevels(levelsArg); await this.csWebclientInstance.setCookieLevels(levelsArg);
await delayFor(300); await delayFor(300);
this.setAttribute('show', 'false'); this.setAttribute('show', 'false'); // Hide the consent banner
// After user selection, re-check for any required scripts to run this.updated(); // Trigger any post-consent actions
this.updated();
} }
/**
* Handles clicks on the page overlay. If clicked outside the modal,
* triggers a shake animation as feedback.
*/
private async pageOverlayClick(e: MouseEvent) { private async pageOverlayClick(e: MouseEvent) {
if (e.target === e.currentTarget) { if (e.target === e.currentTarget) {
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay'); const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
@@ -358,12 +371,15 @@ export class ConsentsoftwareCookieconsent extends LitElement {
} }
/** /**
* Dynamically switches the theme between light/dark, * Dynamically switches the theme between light and dark.
* respecting `prefers-color-scheme` by default. * Listens for system theme changes to update the component's theme.
*/ */
private updateTheme() { private updateTheme() {
// Check the initial system preference for dark mode
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
this.theme = prefersDark ? 'dark' : 'light'; this.theme = prefersDark ? 'dark' : 'light';
// Listen for changes in the system color scheme preference
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => { window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
this.theme = e.matches ? 'dark' : 'light'; this.theme = e.matches ? 'dark' : 'light';
}); });

View File

@@ -7,10 +7,10 @@ export class ConsentsoftwareMainSelection extends LitElement {
public static demo = () => html`<consentsoftware-mainselection></consentsoftware-mainselection>`; public static demo = () => html`<consentsoftware-mainselection></consentsoftware-mainselection>`;
@property({ type: Boolean }) @property({ type: Boolean })
public required = false; public accessor required = false;
@property({ type: Boolean }) @property({ type: Boolean })
public selected = false; public accessor selected = false;
public static styles = css` public static styles = css`
:host { :host {

View File

@@ -24,6 +24,13 @@ export class ConsentsoftwareTabs extends LitElement {
cursor: pointer; cursor: pointer;
} }
/* Media query for mobile devices: stack buttons vertically */
@media (max-width: 600px) {
.tabs .tab {
font-size: 0.8em;
}
}
.selector { .selector {
position: absolute; position: absolute;
width: calc(100% / 3); width: calc(100% / 3);
@@ -44,7 +51,7 @@ export class ConsentsoftwareTabs extends LitElement {
<div class="tabs"> <div class="tabs">
<div class="tab" @click=${this.handleClick}>Consent</div> <div class="tab" @click=${this.handleClick}>Consent</div>
<div class="tab" @click=${this.handleClick}>Details</div> <div class="tab" @click=${this.handleClick}>Details</div>
<div class="tab" @click=${this.handleClick}>Cookie Policy + Legal Info</div> <div class="tab" @click=${this.handleClick}>Cookie Policy</div>
</div> </div>
<div class="selector"></div> <div class="selector"></div>
`; `;
@@ -61,4 +68,4 @@ export class ConsentsoftwareTabs extends LitElement {
} }
} }
} }
} }

View File

@@ -1,9 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es2017", "target": "ES2022",
"module": "es2015", "module": "ES2022",
"moduleResolution": "node", "moduleResolution": "bundler",
"lib": ["es2017", "dom"], "lib": ["ES2022", "DOM", "DOM.Iterable"],
"declaration": true, "declaration": true,
"inlineSources": true, "inlineSources": true,
"inlineSourceMap": true, "inlineSourceMap": true,

View File

@@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ES2022",
"module": "ES2020", "module": "NodeNext",
"moduleResolution": "node12" "moduleResolution": "NodeNext"
} }
} }