feat(elements): Enhance consent management components with advanced styling and interaction
This commit is contained in:
		| @@ -1,5 +1,12 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## 2025-01-14 - 1.3.0 - feat(elements) | ||||
| Enhance consent management components with advanced styling and interaction | ||||
|  | ||||
| - Added delayed animation effect to 'consentsoftware-toggle' when required. | ||||
| - Improved styling for better visual feedback on selections and requirements. | ||||
| - Enhanced modal transition and visibility settings for the 'consentsoftware-cookieconsent'. | ||||
|  | ||||
| ## 2025-01-13 - 1.2.0 - feat(pages) | ||||
| Add initial structure for pages with page1 component | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@consent.software/catalog', | ||||
|   version: '1.2.0', | ||||
|   version: '1.3.0', | ||||
|   description: 'A library of web components designed to integrate robust consent management capabilities into web applications, ensuring compliance with privacy regulations.' | ||||
| } | ||||
|   | ||||
| @@ -18,9 +18,6 @@ export class ConsentsoftwareCookieconsent extends LitElement { | ||||
|   @property({ type: String, reflect: true }) | ||||
|   public theme: 'light' | 'dark' = 'light'; | ||||
|  | ||||
|   @property({ type: Number }) | ||||
|   public heightPixels = 60; | ||||
|  | ||||
|   /** | ||||
|    * We bind `heightPixels` to a CSS variable (--cookieconsent-height). | ||||
|    * Then we can do margin-bottom animations in CSS. | ||||
| @@ -69,6 +66,9 @@ export class ConsentsoftwareCookieconsent extends LitElement { | ||||
|       align-items: center; | ||||
|       justify-content: center; | ||||
|       z-index: 1000; /* standard z-index for fixed elements */ | ||||
|       background: rgba(0, 0, 0, 0); | ||||
|       backdrop-filter: blur(0px); | ||||
|       transition: all 0.2s; | ||||
|     } | ||||
|  | ||||
|     .modalBox { | ||||
| @@ -88,7 +88,9 @@ export class ConsentsoftwareCookieconsent extends LitElement { | ||||
|        * The animation occurs when we toggle the gotIt/show attributes. | ||||
|        */ | ||||
|       will-change: transform; /* ensure efficient rendering */ | ||||
|       transition: all 0.2s; | ||||
|       transition: all 0.3s; | ||||
|       transform: scale(0.95); | ||||
|       opacity: 0; | ||||
|     } | ||||
|  | ||||
|     /*  | ||||
| @@ -261,9 +263,20 @@ export class ConsentsoftwareCookieconsent extends LitElement { | ||||
|  | ||||
|     const cookieLevel = await this.csWebclientInstance.getCookieLevels(); | ||||
|     if (!cookieLevel) { | ||||
|       delayFor(300).then(() => { | ||||
|       this.setAttribute('show', 'true'); | ||||
|       this.setAttribute('gotIt', 'false'); | ||||
|       requestAnimationFrame(async () => { | ||||
|         await this.updated(); | ||||
|         const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay'); | ||||
|         if (pageOverlay) { | ||||
|           pageOverlay.style.background = 'rgba(0, 0, 0, 0.5)'; | ||||
|           pageOverlay.style.backdropFilter = 'blur(2px)'; | ||||
|         } | ||||
|         const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox'); | ||||
|         if (modalBox) { | ||||
|           modalBox.style.transform = `scale(1)`; | ||||
|           modalBox.style.opacity = '1'; | ||||
|         } | ||||
|       }); | ||||
|     } else { | ||||
|       this.setAttribute('show', 'false'); | ||||
| @@ -275,7 +288,7 @@ export class ConsentsoftwareCookieconsent extends LitElement { | ||||
|    * Called after the first render of the component. | ||||
|    * We measure the actual height of the banner and update the CSS variable. | ||||
|    */ | ||||
|   public firstUpdated() {} | ||||
|   public async firstUpdated() {} | ||||
|  | ||||
|   /** | ||||
|    * Called whenever the element is updated or re-rendered. | ||||
|   | ||||
| @@ -43,7 +43,7 @@ export class ConsentsoftwareMainSelection extends LitElement { | ||||
|     return html` | ||||
|       <div class="maincontainer"> | ||||
|         <div class="itemBox"> | ||||
|           <consentsoftware-toggle>Required</consentsoftware-toggle> | ||||
|           <consentsoftware-toggle required>Required</consentsoftware-toggle> | ||||
|         </div> | ||||
|         <div class="itemBox"> | ||||
|           <consentsoftware-toggle>Preferences</consentsoftware-toggle> | ||||
|   | ||||
| @@ -2,6 +2,8 @@ import { LitElement, html, css, type TemplateResult } from 'lit'; | ||||
| import { customElement } from 'lit/decorators.js'; | ||||
| import { property } from 'lit/decorators/property.js'; | ||||
|  | ||||
| import { delayFor } from '@push.rocks/smartdelay'; | ||||
|  | ||||
| @customElement('consentsoftware-toggle') | ||||
| export class ConsentsoftwareToggle extends LitElement { | ||||
|   public static demo = () => html`<consentsoftware-toggle></consentsoftware-toggle>`; | ||||
| @@ -27,15 +29,16 @@ export class ConsentsoftwareToggle extends LitElement { | ||||
|       margin: auto; | ||||
|       height: 30px; | ||||
|       width: 60px; | ||||
|       border-radius: 15px; | ||||
|       border-radius: 20px; | ||||
|       background: rgba(255, 255, 255, 0.1); | ||||
|       position: relative; | ||||
|       overflow: hidden; | ||||
|       transition: all 0.2s; | ||||
|       border: 1px solid rgba(255, 255, 255, 0); | ||||
|     } | ||||
|  | ||||
|     :host([selected]) .toggleKnobArea { | ||||
|       background: blue; | ||||
|       background: green; | ||||
|     } | ||||
|  | ||||
|     .toggleKnobMover { | ||||
| @@ -51,12 +54,21 @@ export class ConsentsoftwareToggle extends LitElement { | ||||
|       top: 0; | ||||
|       left: 0; | ||||
|       transition: all 0.2s; | ||||
|       transform: scale(0.8); | ||||
|       transform: scale(0.7); | ||||
|     } | ||||
|  | ||||
|     :host([selected]) .toggleKnobInner { | ||||
|       background: white; | ||||
|     } | ||||
|  | ||||
|     :host([required]) .toggleKnobArea { | ||||
|       background: none; | ||||
|       border: 1px solid rgba(255, 255, 255, 0.1); | ||||
|     } | ||||
|  | ||||
|     :host([required]) .toggleKnobInner { | ||||
|       background: rgba(255, 255, 255, 0.1); | ||||
|     } | ||||
|   `; | ||||
|  | ||||
|   constructor() { | ||||
| @@ -76,11 +88,30 @@ export class ConsentsoftwareToggle extends LitElement { | ||||
|     `; | ||||
|   } | ||||
|  | ||||
|   public async firstUpdated(_changedProperties: Map<string | number | symbol, unknown>) { | ||||
|     super.firstUpdated(_changedProperties); | ||||
|     if (this.required) { | ||||
|       this.selected = true; | ||||
|       this.syncSelection(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public async handleClick(mouseEvent) { | ||||
|     if (this.required) { | ||||
|       const moverElement: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobMover'); | ||||
|       moverElement.style.transform = 'translateX(20px)'; | ||||
|       await delayFor(250); | ||||
|       moverElement.style.transform = 'translateX(30px)'; | ||||
|       return; | ||||
|     } | ||||
|     this.selected = !this.selected; | ||||
|     mouseEvent.stopPropagation(); | ||||
|     mouseEvent.preventDefault(); | ||||
|     this.syncSelection(); | ||||
|     this.dispatchEvent(new CustomEvent('toggle', { detail: { selected: this.selected } })); | ||||
|   } | ||||
|  | ||||
|   public async syncSelection() { | ||||
|     console.log(`Selected ${this.selected}`); | ||||
|     const moverElement: HTMLDivElement = this.shadowRoot.querySelector('.toggleKnobMover'); | ||||
|     if (this.selected) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user