Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
599b529744 | |||
d15f8ecf39 | |||
ed51ea2049 | |||
7ab409ca80 | |||
e4b611c86d | |||
5bb5e8e458 | |||
e4efdcd9a6 | |||
6b31a80f07 | |||
7829e6a052 | |||
8b18e33c6e | |||
9407295866 | |||
472fa6b684 | |||
bdf9aa7e54 | |||
72c318a793 | |||
71ee96307e | |||
e0ed973b3a | |||
1ab6e09c95 | |||
26fd75b8ae | |||
48a5b96b2a | |||
66a883d90e | |||
6e6f5273a2 | |||
1e091ec600 | |||
fb15f62189 | |||
f5d9f05bf2 |
74
changelog.md
74
changelog.md
@ -1,5 +1,79 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
No changes detected
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-01-20 - 1.5.1 - fix(consentsoftware-cookieconsent)
|
||||||
|
Adjusted shake animation duration and box-shadow for modalBox in consent cookie component.
|
||||||
|
|
||||||
|
- Changed the box-shadow to be softer with reduced spread for more subtle visual effect.
|
||||||
|
- Increased the duration of shake animation from 300ms to 2000ms for enhanced user feedback upon overlay interaction.
|
||||||
|
|
||||||
|
## 2025-01-20 - 1.5.0 - feat(consentsoftware-cookieconsent)
|
||||||
|
Enhance consent modal with shake animation on overlay click
|
||||||
|
|
||||||
|
- Added shake animation to the modal and overlay when clicked outside the modal.
|
||||||
|
- Updated dependency @consent.software/interfaces to version ^1.0.14.
|
||||||
|
|
||||||
|
## 2025-01-17 - 1.4.5 - fix(elements)
|
||||||
|
Fix issues in consentsoftware-cookieconsent component
|
||||||
|
|
||||||
|
- Removed unused attribute handling for 'gotIt'.
|
||||||
|
- Fixed background and backdrop-filter transitions to ensure proper UI behavior.
|
||||||
|
- Consolidated consent button click handling into handleConsentButtonClick.
|
||||||
|
- Improved modal visibility toggling and acceptance flow.
|
||||||
|
|
||||||
|
## 2025-01-17 - 1.4.4 - fix(core)
|
||||||
|
Update LitElement properties to use accessors
|
||||||
|
|
||||||
|
- Changes made in ts_web/elements/consentsoftware-toggle.ts
|
||||||
|
- Updated properties 'required' and 'selected' to use accessors
|
||||||
|
|
||||||
|
## 2025-01-17 - 1.4.3 - fix(consentsoftware-cookieconsent)
|
||||||
|
Fix transition property in consent button styles and add HTMLElementTagNameMap declaration for global interface.
|
||||||
|
|
||||||
|
- Updated the transition property for consent buttons to transition all properties instead of just the background.
|
||||||
|
- Added global interface HTMLElementTagNameMap for custom element type support.
|
||||||
|
|
||||||
|
## 2025-01-16 - 1.4.2 - fix(cookieconsent)
|
||||||
|
Fix user-select property in consentsoftware-cookieconsent component for consistency in interaction.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-01-16 - 1.4.1 - fix(consentsoftware-toggle)
|
||||||
|
Fix issue in drag event handling logic for the toggle component.
|
||||||
|
|
||||||
|
- Corrected dragging functionality to accurately track dragging state.
|
||||||
|
- Included logic to delay the reset of the dragging state after toggling.
|
||||||
|
|
||||||
|
## 2025-01-16 - 1.4.0 - feat(toggle component)
|
||||||
|
Enhanced consent toggle component with drag functionality
|
||||||
|
|
||||||
|
- Implemented drag functionality for the toggle knob.
|
||||||
|
- Added smooth transitions for the toggle knob movement.
|
||||||
|
- Handled drag state management to differentiate between actual click and drag.
|
||||||
|
- Improved user interaction by allowing click anywhere in the toggle area.
|
||||||
|
|
||||||
|
## 2025-01-16 - 1.3.5 - fix(elements)
|
||||||
|
Improved styling consistency across several components
|
||||||
|
|
||||||
|
- Increased box-shadow intensity for better visual separation
|
||||||
|
- Changed border-bottom styles to use dotted lines for consistency
|
||||||
|
- Adjusted line-height for better vertical spacing
|
||||||
|
- Fixed border-right gradient on itemBox for better styling
|
||||||
|
|
||||||
|
## 2025-01-14 - 1.3.4 - fix(dependencies)
|
||||||
|
Corrected build script and updated @consent.software/webclient dependency version
|
||||||
|
|
||||||
|
- Corrected the build script entry in package.json.
|
||||||
|
- Updated @consent.software/webclient dependency to version ^1.1.0.
|
||||||
|
|
||||||
## 2025-01-14 - 1.3.3 - fix(package.json)
|
## 2025-01-14 - 1.3.3 - fix(package.json)
|
||||||
Fixed incorrect main and typings fields, replacing with exports field
|
Fixed incorrect main and typings fields, replacing with exports field
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@consent.software/catalog",
|
"name": "@consent.software/catalog",
|
||||||
"version": "1.3.3",
|
"version": "1.5.3",
|
||||||
"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": {
|
||||||
@ -9,14 +9,14 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run build",
|
"test": "npm run build",
|
||||||
"build": "tsbuild element --allowimplicitany && tsbundle element --production",
|
"build": "tsbuild tsfolders --allowimplicitany && tsbundle element --production",
|
||||||
"watch": "tswatch element"
|
"watch": "tswatch element"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@consent.software/interfaces": "^1.0.11",
|
"@consent.software/interfaces": "^1.0.14",
|
||||||
"@consent.software/webclient": "^1.0.14",
|
"@consent.software/webclient": "^1.1.0",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"lit": "^3.2.1"
|
"lit": "^3.2.1"
|
||||||
},
|
},
|
||||||
|
1284
pnpm-lock.yaml
generated
1284
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@consent.software/catalog',
|
name: '@consent.software/catalog',
|
||||||
version: '1.3.3',
|
version: '1.5.3',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,12 @@ import * as csInterfaces from '@consent.software/interfaces';
|
|||||||
import * as csWebclient from '@consent.software/webclient';
|
import * as csWebclient from '@consent.software/webclient';
|
||||||
import { delayFor } from '@push.rocks/smartdelay';
|
import { delayFor } from '@push.rocks/smartdelay';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'consentsoftware-cookieconsent': ConsentsoftwareCookieconsent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@customElement('consentsoftware-cookieconsent')
|
@customElement('consentsoftware-cookieconsent')
|
||||||
export class ConsentsoftwareCookieconsent extends LitElement {
|
export class ConsentsoftwareCookieconsent extends LitElement {
|
||||||
public static demo = () => html`<consentsoftware-cookieconsent></consentsoftware-cookieconsent>`;
|
public static demo = () => html`<consentsoftware-cookieconsent></consentsoftware-cookieconsent>`;
|
||||||
@ -25,6 +31,7 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
public static styles = css`
|
public static styles = css`
|
||||||
:host {
|
:host {
|
||||||
font-family: ${shared.fontStack};
|
font-family: ${shared.fontStack};
|
||||||
|
user-select: none;
|
||||||
/* Default theme variables */
|
/* Default theme variables */
|
||||||
--text-color: #333;
|
--text-color: #333;
|
||||||
--background-color: #eeeeee;
|
--background-color: #eeeeee;
|
||||||
@ -66,33 +73,50 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
z-index: 1000; /* standard z-index for fixed elements */
|
z-index: 1000; /* standard z-index for fixed elements */
|
||||||
background: rgba(0, 0, 0, 0);
|
background: rgba(255, 255, 255, 0);
|
||||||
backdrop-filter: blur(0px);
|
backdrop-filter: blur(0px);
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pageOverlay.shake {
|
||||||
|
background: rgba(0, 0, 0, 0.5) !important;
|
||||||
|
}
|
||||||
|
|
||||||
.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.4);
|
box-shadow: 0px 0px 8px rgba(255, 255, 255, 0.6);
|
||||||
position: realtive;
|
position: realtive;
|
||||||
|
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;
|
||||||
max-width: 1100px;
|
max-width: 1100px;
|
||||||
min-width: calc(100vw / 3);
|
min-width: calc(100vw / 3);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
/*
|
|
||||||
* We start with margin-bottom as negative to hide the banner.
|
|
||||||
* The animation occurs when we toggle the gotIt/show attributes.
|
|
||||||
*/
|
|
||||||
will-change: transform; /* ensure efficient rendering */
|
will-change: transform; /* ensure efficient rendering */
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
transform: scale(0.95);
|
transform: scale(0.95);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modalBox.shake {
|
||||||
|
animation: shake 150ms 2 linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shake {
|
||||||
|
0% {
|
||||||
|
transform: translate(3px, 0);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: translate(-3px, 0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translate(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Toggle display based on [show] attribute
|
* Toggle display based on [show] attribute
|
||||||
* (so if show=false, the banner doesn't show at all).
|
* (so if show=false, the banner doesn't show at all).
|
||||||
@ -104,18 +128,6 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Animate margin-bottom when [gotIt] toggles.
|
|
||||||
* If gotIt=true, push the banner down off-screen.
|
|
||||||
* If gotIt=false, pull the banner into view.
|
|
||||||
*/
|
|
||||||
:host([gotIt='true']) {
|
|
||||||
background: blue;
|
|
||||||
}
|
|
||||||
:host([gotIt='false']) {
|
|
||||||
background: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
@ -142,9 +154,9 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
.info-container {
|
.info-container {
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 2em;
|
line-height: 3em;
|
||||||
background: rgba(0, 0, 0, 0.1);
|
background: rgba(0, 0, 0, 0.1);
|
||||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
border-top: 1px dotted rgba(255, 255, 255, 0.1);
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
color: rgba(255, 255, 255, 0.5);
|
color: rgba(255, 255, 255, 0.5);
|
||||||
}
|
}
|
||||||
@ -166,7 +178,7 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.consent-button:hover {
|
.consent-button:hover {
|
||||||
@ -176,13 +188,12 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.setAttribute('gotIt', 'true');
|
|
||||||
this.setAttribute('show', 'false');
|
this.setAttribute('show', 'false');
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="pageOverlay">
|
<div class="pageOverlay" @click=${this.pageOverlayClick}>
|
||||||
<div class="modalBox">
|
<div class="modalBox">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<consentsoftware-header></consentsoftware-header>
|
<consentsoftware-header></consentsoftware-header>
|
||||||
@ -197,27 +208,29 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
<!-- <div class="button-container">
|
<!-- <div class="button-container">
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional'])}
|
@click=${(event: MouseEvent) =>
|
||||||
|
this.handleConsentButtonClick(event, ['functional'])}
|
||||||
>
|
>
|
||||||
Functional cookies
|
Functional cookies
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional', 'analytics'])}
|
@click=${(event: MouseEvent) =>
|
||||||
|
this.handleConsentButtonClick(event, ['functional', 'analytics'])}
|
||||||
>
|
>
|
||||||
Analytics cookies
|
Analytics cookies
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) =>
|
@click=${(event: MouseEvent) =>
|
||||||
this.setLevel(event, ['functional', 'analytics', 'marketing'])}
|
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing'])}
|
||||||
>
|
>
|
||||||
Marketing cookies
|
Marketing cookies
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) =>
|
@click=${(event: MouseEvent) =>
|
||||||
this.setLevel(event, ['functional', 'analytics', 'marketing', 'all'])}
|
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing', 'all'])}
|
||||||
>
|
>
|
||||||
All cookies
|
All cookies
|
||||||
</div>
|
</div>
|
||||||
@ -226,20 +239,22 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional'])}
|
@click=${(event: MouseEvent) =>
|
||||||
|
this.handleConsentButtonClick(event, ['functional'])}
|
||||||
>
|
>
|
||||||
Deny
|
Deny
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional', 'analytics'])}
|
@click=${(event: MouseEvent) =>
|
||||||
|
this.handleConsentButtonClick(event, ['functional', 'analytics'])}
|
||||||
>
|
>
|
||||||
Accept selection
|
Accept selection
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="consent-button"
|
class="consent-button"
|
||||||
@click=${(event: MouseEvent) =>
|
@click=${(event: MouseEvent) =>
|
||||||
this.setLevel(event, ['functional', 'analytics', 'marketing'])}
|
this.handleConsentButtonClick(event, ['functional', 'analytics', 'marketing'])}
|
||||||
>
|
>
|
||||||
Accept all cookies
|
Accept all cookies
|
||||||
</div>
|
</div>
|
||||||
@ -247,6 +262,7 @@ 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>
|
||||||
@ -264,13 +280,12 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
const cookieLevel = await this.csWebclientInstance.getCookieLevels();
|
const cookieLevel = await this.csWebclientInstance.getCookieLevels();
|
||||||
if (!cookieLevel) {
|
if (!cookieLevel) {
|
||||||
this.setAttribute('show', 'true');
|
this.setAttribute('show', 'true');
|
||||||
this.setAttribute('gotIt', 'false');
|
|
||||||
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(0,0,0, 0.5)';
|
pageOverlay.style.background = 'rgba(0,0,0, 0.5)';
|
||||||
pageOverlay.style.backdropFilter = 'blur(2px)';
|
pageOverlay.style.backdropFilter = 'blur(20px)';
|
||||||
}
|
}
|
||||||
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
||||||
if (modalBox) {
|
if (modalBox) {
|
||||||
@ -280,7 +295,6 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setAttribute('show', 'false');
|
this.setAttribute('show', 'false');
|
||||||
this.setAttribute('gotIt', 'true');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,16 +319,42 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
/**
|
/**
|
||||||
* Sets the user’s chosen cookie level(s) and hides the banner.
|
* Sets the user’s chosen cookie level(s) and hides the banner.
|
||||||
*/
|
*/
|
||||||
private async setLevel(event: MouseEvent, levelsArg: csInterfaces.TCookieLevel[]) {
|
private async handleConsentButtonClick(
|
||||||
|
event: MouseEvent,
|
||||||
|
levelsArg: csInterfaces.TCookieLevel[]
|
||||||
|
) {
|
||||||
console.log(`Set level to ${levelsArg}`);
|
console.log(`Set level to ${levelsArg}`);
|
||||||
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
||||||
|
if (pageOverlay) {
|
||||||
|
pageOverlay.style.background = 'rgba(255,255,255, 0)';
|
||||||
|
pageOverlay.style.backdropFilter = 'blur(0px)';
|
||||||
|
}
|
||||||
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
||||||
|
if (modalBox) {
|
||||||
|
modalBox.style.transform = `scale(0.95)`;
|
||||||
|
modalBox.style.opacity = '0';
|
||||||
|
}
|
||||||
await this.csWebclientInstance.setCookieLevels(levelsArg);
|
await this.csWebclientInstance.setCookieLevels(levelsArg);
|
||||||
this.setAttribute('gotIt', 'true');
|
|
||||||
await delayFor(300);
|
await delayFor(300);
|
||||||
this.setAttribute('show', 'false');
|
this.setAttribute('show', 'false');
|
||||||
// After user selection, re-check for any required scripts to run
|
// After user selection, re-check for any required scripts to run
|
||||||
this.updated();
|
this.updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async pageOverlayClick(e: MouseEvent) {
|
||||||
|
if (e.target === e.currentTarget) {
|
||||||
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
||||||
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
||||||
|
if (pageOverlay && modalBox) {
|
||||||
|
pageOverlay.classList.add('shake');
|
||||||
|
modalBox.classList.add('shake');
|
||||||
|
await delayFor(2000);
|
||||||
|
pageOverlay.classList.remove('shake');
|
||||||
|
modalBox.classList.remove('shake');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamically switches the theme between light/dark,
|
* Dynamically switches the theme between light/dark,
|
||||||
* respecting `prefers-color-scheme` by default.
|
* respecting `prefers-color-scheme` by default.
|
||||||
|
@ -11,10 +11,10 @@ export class ConsentsoftwareHeader extends LitElement {
|
|||||||
public static styles = css`
|
public static styles = css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
line-height: 2em;
|
line-height: 3em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-family: ${shared.fontStack};
|
font-family: ${shared.fontStack};
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
border-bottom: 1px dotted rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
|
@ -16,8 +16,6 @@ export class ConsentsoftwareMainSelection extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.maincontainer {
|
.maincontainer {
|
||||||
@ -28,7 +26,8 @@ export class ConsentsoftwareMainSelection extends LitElement {
|
|||||||
.itemBox {
|
.itemBox {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-right: 1px solid rgba(255, 255, 255, 0.1);
|
border-right: 1px solid;
|
||||||
|
border-image: radial-gradient(circle, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 100%) 1;
|
||||||
}
|
}
|
||||||
.itemBox:last-child {
|
.itemBox:last-child {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
|
@ -44,7 +44,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}>About Cookies</div>
|
<div class="tab" @click=${this.handleClick}>Cookie Policy + Legal Info</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="selector"></div>
|
<div class="selector"></div>
|
||||||
`;
|
`;
|
||||||
|
@ -1,18 +1,31 @@
|
|||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import { LitElement, html, css, type TemplateResult } from 'lit';
|
||||||
import { customElement } from 'lit/decorators.js';
|
import { customElement } from 'lit/decorators.js';
|
||||||
import { property } from 'lit/decorators/property.js';
|
import { property } from 'lit/decorators/property.js';
|
||||||
|
|
||||||
import { delayFor } from '@push.rocks/smartdelay';
|
import { delayFor } from '@push.rocks/smartdelay';
|
||||||
|
|
||||||
@customElement('consentsoftware-toggle')
|
@customElement('consentsoftware-toggle')
|
||||||
export class ConsentsoftwareToggle extends LitElement {
|
export class ConsentsoftwareToggle extends LitElement {
|
||||||
public static demo = () => html`<consentsoftware-toggle></consentsoftware-toggle>`;
|
|
||||||
|
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean })
|
||||||
public required = false;
|
public accessor required = false;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ type: Boolean, reflect: true })
|
||||||
public selected = false;
|
public accessor selected = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We always track the knob’s left offset in `currentX`.
|
||||||
|
* - 0 => fully left
|
||||||
|
* - 30 => fully right
|
||||||
|
*/
|
||||||
|
private currentX = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drag state
|
||||||
|
*/
|
||||||
|
private isDragging = false;
|
||||||
|
private hasDragged = false;
|
||||||
|
private startX = 0; // pointerdown offset
|
||||||
|
private readonly knobWidth = 30;
|
||||||
|
private readonly trackWidth = 60;
|
||||||
|
|
||||||
public static styles = css`
|
public static styles = css`
|
||||||
:host {
|
:host {
|
||||||
@ -24,17 +37,21 @@ export class ConsentsoftwareToggle extends LitElement {
|
|||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
user-select: none; /* helps avoid text selection on drag */
|
||||||
|
}
|
||||||
|
|
||||||
.toggleKnobArea {
|
.toggleKnobArea {
|
||||||
cursor: pointer;
|
position: relative;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 60px;
|
width: 60px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
background: rgba(255, 255, 255, 0.1);
|
background: rgba(255, 255, 255, 0.1);
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
transition: all 0.2s;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0);
|
border: 1px solid rgba(255, 255, 255, 0);
|
||||||
|
overflow: hidden;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([selected]) .toggleKnobArea {
|
:host([selected]) .toggleKnobArea {
|
||||||
@ -42,19 +59,27 @@ export class ConsentsoftwareToggle extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.toggleKnobMover {
|
.toggleKnobMover {
|
||||||
transition: all 0.2s;
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggleKnobInner {
|
.toggleKnobInner {
|
||||||
height: 30px;
|
|
||||||
width: 30px;
|
|
||||||
border-radius: 15px;
|
|
||||||
background: rgba(255, 255, 255, 0.5);
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
transition: all 0.2s;
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
border-radius: 15px;
|
||||||
|
background: rgba(255, 255, 255, 0.5);
|
||||||
|
transition: left 0.2s ease, background 0.2s ease;
|
||||||
transform: scale(0.7);
|
transform: scale(0.7);
|
||||||
|
/* Prevent scroll gestures on mobile */
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggleKnobInner.dragging {
|
||||||
|
transition: background 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([selected]) .toggleKnobInner {
|
:host([selected]) .toggleKnobInner {
|
||||||
@ -78,50 +103,153 @@ export class ConsentsoftwareToggle extends LitElement {
|
|||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="label">${this.getText()}</div>
|
<div class="label">${this.getText()}</div>
|
||||||
|
<!-- A user can click anywhere in this toggle area. -->
|
||||||
<div class="toggle" @click=${this.handleClick}>
|
<div class="toggle" @click=${this.handleClick}>
|
||||||
<div class="toggleKnobArea">
|
<div class="toggleKnobArea">
|
||||||
<div class="toggleKnobMover">
|
<div class="toggleKnobMover">
|
||||||
<div class="toggleKnobInner"></div>
|
<!-- The knob itself, with pointer events for dragging. -->
|
||||||
|
<div
|
||||||
|
class="toggleKnobInner"
|
||||||
|
style="left: ${this.currentX}px;"
|
||||||
|
@pointerdown=${this.onPointerDown}
|
||||||
|
@pointermove=${this.onPointerMove}
|
||||||
|
@pointerup=${this.onPointerUp}
|
||||||
|
@pointercancel=${this.onPointerUp}
|
||||||
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async firstUpdated(_changedProperties: Map<string | number | symbol, unknown>) {
|
/**
|
||||||
super.firstUpdated(_changedProperties);
|
* If required = true on first render, auto-select and set the knob to the right.
|
||||||
|
*/
|
||||||
|
public async firstUpdated() {
|
||||||
if (this.required) {
|
if (this.required) {
|
||||||
|
// If "required" => always selected
|
||||||
this.selected = true;
|
this.selected = true;
|
||||||
this.syncSelection();
|
this.currentX = this.knobWidth; // 30
|
||||||
|
this.requestUpdate();
|
||||||
|
} else {
|
||||||
|
// If not required, set knob to 0 or 30 depending on `selected`
|
||||||
|
this.currentX = this.selected ? this.knobWidth : 0;
|
||||||
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async handleClick(mouseEvent) {
|
/**
|
||||||
if (this.required) {
|
* CLICK HANDLER
|
||||||
const moverElement: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobMover');
|
*/
|
||||||
moverElement.style.transform = 'translateX(20px)';
|
public async handleClick(event: MouseEvent) {
|
||||||
await delayFor(250);
|
// If the user truly dragged the knob, skip the normal click toggle.
|
||||||
moverElement.style.transform = 'translateX(30px)';
|
if (this.isDragging || this.hasDragged) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.required) {
|
||||||
|
// small bounce from 30 -> 20 -> 30
|
||||||
|
this.currentX = this.knobWidth; // ensure at 30
|
||||||
|
this.requestUpdate();
|
||||||
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
|
|
||||||
|
this.currentX = 20; // small bounce left
|
||||||
|
this.requestUpdate();
|
||||||
|
await delayFor(200);
|
||||||
|
|
||||||
|
this.currentX = this.knobWidth; // back to 30
|
||||||
|
this.requestUpdate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal toggle if no drag & not required
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
this.selected = !this.selected;
|
this.selected = !this.selected;
|
||||||
mouseEvent.stopPropagation();
|
this.currentX = this.selected ? this.knobWidth : 0; // snap knob left(0) or right(30)
|
||||||
mouseEvent.preventDefault();
|
this.requestUpdate();
|
||||||
this.syncSelection();
|
|
||||||
this.dispatchEvent(new CustomEvent('toggle', { detail: { selected: this.selected } }));
|
this.dispatchEvent(new CustomEvent('toggle', { detail: { selected: this.selected } }));
|
||||||
|
delayFor(0).then(() => {
|
||||||
|
this.hasDragged = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async syncSelection() {
|
/**
|
||||||
console.log(`Selected ${this.selected}`);
|
* DRAG HANDLERS (pointer events)
|
||||||
const moverElement: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobMover');
|
*/
|
||||||
if (this.selected) {
|
private onPointerDown(event: PointerEvent) {
|
||||||
moverElement.style.transform = 'translateX(30px)';
|
if (this.required) {
|
||||||
} else {
|
// If "required", disallow manual dragging
|
||||||
moverElement.style.transform = 'translateX(0px)';
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getText() {
|
// Start dragging
|
||||||
|
this.isDragging = true;
|
||||||
|
// The difference between the pointer’s X and the knob’s current position
|
||||||
|
this.startX = event.clientX - this.currentX;
|
||||||
|
|
||||||
|
// capture pointer so we keep receiving pointermove/pointerup
|
||||||
|
(event.target as HTMLElement).setPointerCapture(event.pointerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onPointerMove(event: PointerEvent) {
|
||||||
|
if (!this.isDragging) return;
|
||||||
|
const newX = event.clientX - this.startX;
|
||||||
|
this.hasDragged = true;
|
||||||
|
const toggleKnobInner: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobInner');
|
||||||
|
toggleKnobInner.classList.add('dragging');
|
||||||
|
|
||||||
|
// Clamp
|
||||||
|
this.currentX = Math.max(0, Math.min(newX, this.trackWidth - this.knobWidth));
|
||||||
|
this.requestUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private onPointerUp(event: PointerEvent) {
|
||||||
|
if (!this.isDragging) return;
|
||||||
|
(event.target as HTMLElement).releasePointerCapture(event.pointerId);
|
||||||
|
this.isDragging = false;
|
||||||
|
|
||||||
|
// If we didn’t truly drag, pointerup does nothing; click handler handles toggling.
|
||||||
|
if (!this.hasDragged) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const toggleKnobInner: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobInner');
|
||||||
|
toggleKnobInner.classList.remove('dragging');
|
||||||
|
|
||||||
|
// Real drag => decide final side
|
||||||
|
const midpoint = (this.trackWidth - this.knobWidth) / 2; // 15
|
||||||
|
this.selected = this.currentX > midpoint;
|
||||||
|
this.currentX = this.selected ? this.knobWidth : 0; // snap to edge
|
||||||
|
this.requestUpdate();
|
||||||
|
|
||||||
|
// Dispatch toggle event
|
||||||
|
this.dispatchEvent(new CustomEvent('toggle', { detail: { selected: this.selected } }));
|
||||||
|
delayFor(0).then(() => {
|
||||||
|
this.hasDragged = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If external code sets `selected = true/false`, we also sync the knob position
|
||||||
|
*/
|
||||||
|
protected updated(changedProperties: Map<PropertyKey, unknown>): void {
|
||||||
|
if (
|
||||||
|
changedProperties.has('selected') &&
|
||||||
|
!this.isDragging &&
|
||||||
|
!this.hasDragged &&
|
||||||
|
!this.required
|
||||||
|
) {
|
||||||
|
this.currentX = this.selected ? this.knobWidth : 0;
|
||||||
|
this.requestUpdate();
|
||||||
|
}
|
||||||
|
super.updated(changedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getText(): string | null {
|
||||||
return this.textContent;
|
return this.textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user