Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 777acd06a5 | |||
| 0d90a7ae7f | |||
| 0b366b360d | |||
| 8a26378689 | |||
| 1e74560aca | |||
| 2184d8be18 | |||
| 46602851aa | |||
| fc2ba54725 | |||
| a9ae67b43b | |||
| 599b529744 | |||
| d15f8ecf39 | |||
| ed51ea2049 | |||
| 7ab409ca80 | |||
| e4b611c86d | |||
| 5bb5e8e458 | |||
| e4efdcd9a6 | |||
| 6b31a80f07 | |||
| 7829e6a052 | |||
| 8b18e33c6e | |||
| 9407295866 | |||
| 472fa6b684 | |||
| bdf9aa7e54 | |||
| 72c318a793 | |||
| 71ee96307e | |||
| e0ed973b3a | |||
| 1ab6e09c95 | |||
| 26fd75b8ae | |||
| 48a5b96b2a | |||
| 66a883d90e | |||
| 6e6f5273a2 | |||
| 1e091ec600 | |||
| fb15f62189 | |||
| f5d9f05bf2 | |||
| 8bc25e1045 | |||
| d3b74d5766 | |||
| cdaaebde42 | |||
| 45f9f6f891 | |||
| 37c48a6803 | |||
| b4b01cc319 |
121
changelog.md
121
changelog.md
@@ -1,5 +1,126 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-11-30 - 2.0.0 - BREAKING CHANGE(elements)
|
||||||
|
Migrate web components to @design.estate/dees-element, introduce shared theme colors and cssManager, and update imports/usages across ts_web.
|
||||||
|
|
||||||
|
- Replaced direct lit usage with @design.estate/dees-element across the project (imports and base classes).
|
||||||
|
- Added cssManager export and a Shadcn-inspired color palette (colors) in ts_web/elements/shared.ts to centralize theming.
|
||||||
|
- Updated all components to extend DeesElement and include cssManager.defaultStyles in their static styles.
|
||||||
|
- Adjusted lifecycle and event typings (firstUpdated signatures, pointer/mouse event typing) and minor behaviour refinements in consentsoftware-toggle (drag handling, sync logic).
|
||||||
|
- Updated package.json dependencies to remove 'lit' and add '@design.estate/dees-element'.
|
||||||
|
- Updated page imports (ts_web/pages/page1.ts) to use the new html export from @design.estate/dees-element.
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
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)
|
||||||
|
Fixed incorrect main and typings fields, replacing with exports field
|
||||||
|
|
||||||
|
- Updated package.json to use the 'exports' field instead of 'main' and 'typings' for module entry points
|
||||||
|
|
||||||
|
## 2025-01-14 - 1.3.2 - fix(core)
|
||||||
|
No code changes detected, maintain current state.
|
||||||
|
|
||||||
|
|
||||||
|
## 2025-01-14 - 1.3.1 - fix(package setup)
|
||||||
|
Fix package metadata and dependency consistency
|
||||||
|
|
||||||
|
|
||||||
## 2025-01-14 - 1.3.0 - feat(elements)
|
## 2025-01-14 - 1.3.0 - feat(elements)
|
||||||
Enhance consent management components with advanced styling and interaction
|
Enhance consent management components with advanced styling and interaction
|
||||||
|
|
||||||
|
|||||||
29
package.json
29
package.json
@@ -1,29 +1,30 @@
|
|||||||
{
|
{
|
||||||
"name": "@consent.software/catalog",
|
"name": "@consent.software/catalog",
|
||||||
"version": "1.3.0",
|
"version": "2.0.0",
|
||||||
"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.",
|
||||||
"main": "dist_ts_web/index.js",
|
"exports": {
|
||||||
"typings": "dist_ts_web/index.d.ts",
|
".": "./dist_ts_web/index.js"
|
||||||
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run build",
|
"test": "pnpm 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": "Task Venture Capital 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",
|
"@design.estate/dees-element": "^2.1.3",
|
||||||
"lit": "^3.2.1"
|
"@push.rocks/smartdelay": "^3.0.5"
|
||||||
},
|
},
|
||||||
"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": [
|
||||||
|
|||||||
3388
pnpm-lock.yaml
generated
3388
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
251
readme.md
251
readme.md
@@ -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. Here’s 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 component’s 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
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@consent.software/catalog',
|
name: '@consent.software/catalog',
|
||||||
version: '1.3.0',
|
version: '2.0.0',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,245 +1,218 @@
|
|||||||
import * as shared from './shared.js';
|
import { cssManager, colors } from './shared.js';
|
||||||
|
|
||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import {
|
||||||
import { customElement } from 'lit/decorators.js';
|
DeesElement,
|
||||||
import { property } from 'lit/decorators/property.js';
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
type TemplateResult,
|
||||||
|
property,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
import * as csInterfaces from '@consent.software/interfaces';
|
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 DeesElement {
|
||||||
public static demo = () => html`<consentsoftware-cookieconsent></consentsoftware-cookieconsent>`;
|
public static demo = () => html`<consentsoftware-cookieconsent></consentsoftware-cookieconsent>`;
|
||||||
|
|
||||||
public csWebclientInstance = new csWebclient.CsWebclient();
|
public csWebclientInstance = new csWebclient.CsWebclient();
|
||||||
public csWebclientRan = false;
|
public csWebclientRan = false;
|
||||||
|
|
||||||
@property({ type: String, reflect: true })
|
public static styles = [
|
||||||
public theme: 'light' | 'dark' = 'light';
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
/**
|
|
||||||
* We bind `heightPixels` to a CSS variable (--cookieconsent-height).
|
|
||||||
* Then we can do margin-bottom animations in CSS.
|
|
||||||
*/
|
|
||||||
public static styles = css`
|
|
||||||
:host {
|
:host {
|
||||||
font-family: ${shared.fontStack};
|
font-size: 14px;
|
||||||
/* Default theme variables */
|
user-select: none;
|
||||||
--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;
|
|
||||||
}
|
|
||||||
|
|
||||||
: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;
|
|
||||||
}
|
|
||||||
|
|
||||||
: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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.pageOverlay {
|
.pageOverlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0px;
|
inset: 0;
|
||||||
bottom: 0px;
|
|
||||||
right: 0px;
|
|
||||||
left: 0px;
|
|
||||||
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;
|
||||||
background: rgba(0, 0, 0, 0);
|
background: rgba(0, 0, 0, 0);
|
||||||
backdrop-filter: blur(0px);
|
backdrop-filter: blur(0px);
|
||||||
transition: all 0.2s;
|
transition: all 0.2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pageOverlay.shake {
|
||||||
|
background: rgba(0, 0, 0, 0.6) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modalBox {
|
.modalBox {
|
||||||
display: block;
|
display: block;
|
||||||
color: var(--text-color);
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
background: var(--background-color);
|
background: ${cssManager.bdTheme(colors.light.background, colors.dark.background)};
|
||||||
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.4);
|
box-shadow:
|
||||||
position: realtive;
|
0 0 0 1px ${cssManager.bdTheme(colors.light.border, colors.dark.border)},
|
||||||
border-top: 1px solid var(--accent-color);
|
0 16px 70px ${cssManager.bdTheme('rgba(0, 0, 0, 0.15)', 'rgba(0, 0, 0, 0.35)')};
|
||||||
border-radius: 16px;
|
position: relative;
|
||||||
max-width: 1100px;
|
border-radius: 8px;
|
||||||
min-width: calc(100vw / 3);
|
max-width: 520px;
|
||||||
|
min-width: 320px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
/*
|
will-change: transform;
|
||||||
* We start with margin-bottom as negative to hide the banner.
|
transition: all 0.2s ease-out;
|
||||||
* The animation occurs when we toggle the gotIt/show attributes.
|
transform: scale(0.96);
|
||||||
*/
|
|
||||||
will-change: transform; /* ensure efficient rendering */
|
|
||||||
transition: all 0.3s;
|
|
||||||
transform: scale(0.95);
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@media (max-width: 560px) {
|
||||||
* Toggle display based on [show] attribute
|
.modalBox {
|
||||||
* (so if show=false, the banner doesn't show at all).
|
max-width: 100%;
|
||||||
*/
|
min-width: 100%;
|
||||||
:host([show='false']) {
|
height: 100vh;
|
||||||
display: none;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
:host([show='true']) {
|
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
.modalBox.shake {
|
||||||
* Animate margin-bottom when [gotIt] toggles.
|
animation: shake 120ms 2 linear;
|
||||||
* 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;
|
@keyframes shake {
|
||||||
|
0% { transform: translateX(3px); }
|
||||||
|
50% { transform: translateX(-3px); }
|
||||||
|
100% { transform: translateX(0); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([show='false']) { display: none; }
|
||||||
|
:host([show='true']) { display: block; }
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-container {
|
.text-container {
|
||||||
padding-left: var(--padding-sides);
|
padding: 12px 16px;
|
||||||
padding-right: var(--padding-sides);
|
font-size: 0.9em;
|
||||||
display: grid;
|
line-height: 1.5;
|
||||||
grid-template-columns: auto;
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-container a {
|
.text-container a {
|
||||||
color: var(--link-color);
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
text-decoration: none;
|
text-decoration: underline;
|
||||||
|
text-underline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-container a:hover {
|
||||||
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-container {
|
.button-container {
|
||||||
padding: var(--padding-sides);
|
padding: 12px 16px 16px;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
gap: 16px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-container {
|
@media (max-width: 560px) {
|
||||||
color: var(--text-color);
|
.button-container {
|
||||||
text-align: center;
|
grid-template-columns: 1fr;
|
||||||
line-height: 2em;
|
|
||||||
background: rgba(0, 0, 0, 0.1);
|
|
||||||
border-top: 1px solid 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 {
|
.consent-button {
|
||||||
border-radius: 3px;
|
border-radius: 6px;
|
||||||
background: var(--button-bg);
|
background: ${cssManager.bdTheme(colors.light.secondary, colors.dark.secondary)};
|
||||||
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
|
border: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
padding: 10px;
|
padding: 8px 16px;
|
||||||
line-height: 30px;
|
font-size: 0.85em;
|
||||||
|
font-weight: 500;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.2s;
|
transition: all 0.15s ease;
|
||||||
|
color: ${cssManager.bdTheme(colors.light.secondaryForeground, colors.dark.secondaryForeground)};
|
||||||
}
|
}
|
||||||
|
|
||||||
.consent-button:hover {
|
.consent-button:hover {
|
||||||
background: var(--button-hover-bg);
|
background: ${cssManager.bdTheme(colors.light.accent, colors.dark.accent)};
|
||||||
|
border-color: ${cssManager.bdTheme(colors.light.ring, colors.dark.ring)};
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
.consent-button:last-child {
|
||||||
|
background: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
||||||
|
color: ${cssManager.bdTheme(colors.light.primaryForeground, colors.dark.primaryForeground)};
|
||||||
|
border-color: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
||||||
|
}
|
||||||
|
|
||||||
|
.consent-button:last-child:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-container {
|
||||||
|
text-align: center;
|
||||||
|
padding: 10px 16px;
|
||||||
|
background: ${cssManager.bdTheme(colors.light.muted, colors.dark.muted)};
|
||||||
|
border-top: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
|
font-size: 0.75em;
|
||||||
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-container a {
|
||||||
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-container a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.setAttribute('gotIt', 'true');
|
// Initially hide the consent banner until needed
|
||||||
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>
|
||||||
<consentsoftware-tabs></consentsoftware-tabs>
|
<consentsoftware-tabs></consentsoftware-tabs>
|
||||||
<div class="text-container" style="padding: 16px;">
|
<div class="text-container">
|
||||||
<div class="toptext">
|
<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>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="button-container">
|
|
||||||
<div
|
|
||||||
class="consent-button"
|
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional'])}
|
|
||||||
>
|
|
||||||
Functional cookies
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="consent-button"
|
|
||||||
@click=${(event: MouseEvent) => this.setLevel(event, ['functional', 'analytics'])}
|
|
||||||
>
|
|
||||||
Analytics cookies
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="consent-button"
|
|
||||||
@click=${(event: MouseEvent) =>
|
|
||||||
this.setLevel(event, ['functional', 'analytics', 'marketing'])}
|
|
||||||
>
|
|
||||||
Marketing cookies
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="consent-button"
|
|
||||||
@click=${(event: MouseEvent) =>
|
|
||||||
this.setLevel(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
|
||||||
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>
|
||||||
@@ -255,46 +228,39 @@ 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.
|
||||||
|
* Displays the consent banner if no cookie levels are set.
|
||||||
*/
|
*/
|
||||||
public async connectedCallback() {
|
public async connectedCallback() {
|
||||||
super.connectedCallback();
|
await super.connectedCallback();
|
||||||
this.updateTheme();
|
|
||||||
|
|
||||||
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');
|
||||||
this.setAttribute('gotIt', 'false');
|
|
||||||
requestAnimationFrame(async () => {
|
requestAnimationFrame(async () => {
|
||||||
await this.updated();
|
await this.updateComplete;
|
||||||
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)';
|
// Apply subtle backdrop blur when modal appears
|
||||||
pageOverlay.style.backdropFilter = 'blur(2px)';
|
pageOverlay.style.background = 'rgba(0,0,0, 0.6)';
|
||||||
|
pageOverlay.style.backdropFilter = 'blur(4px)';
|
||||||
}
|
}
|
||||||
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');
|
||||||
this.setAttribute('gotIt', 'true');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public async firstUpdated() {
|
||||||
* Called after the first render of the component.
|
// Run consent scripts if levels are already set
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public async updated() {
|
|
||||||
console.log(`The height of the cookie banner is ${this.shadowRoot?.host?.clientHeight}px`);
|
|
||||||
const acceptedCookieLevels = await this.csWebclientInstance.getCookieLevels();
|
const acceptedCookieLevels = await this.csWebclientInstance.getCookieLevels();
|
||||||
if (!this.csWebclientRan && acceptedCookieLevels) {
|
if (!this.csWebclientRan && acceptedCookieLevels) {
|
||||||
this.csWebclientRan = true;
|
this.csWebclientRan = true;
|
||||||
@@ -303,27 +269,51 @@ export class ConsentsoftwareCookieconsent extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the user’s chosen cookie level(s) and hides the banner.
|
* Handles consent button clicks, sets cookie levels, 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(0,0,0, 0)';
|
||||||
|
pageOverlay.style.backdropFilter = 'blur(0px)';
|
||||||
|
}
|
||||||
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
||||||
|
if (modalBox) {
|
||||||
|
// Scale down and fade out modal box before hiding
|
||||||
|
modalBox.style.transform = `scale(0.95)`;
|
||||||
|
modalBox.style.opacity = '0';
|
||||||
|
}
|
||||||
|
// Save user consent preferences
|
||||||
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'); // Hide the consent banner
|
||||||
// After user selection, re-check for any required scripts to run
|
|
||||||
this.updated();
|
// Run consent scripts
|
||||||
|
if (!this.csWebclientRan) {
|
||||||
|
this.csWebclientRan = true;
|
||||||
|
await this.csWebclientInstance.getAndRunConsentTuples();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamically switches the theme between light/dark,
|
* Handles clicks on the page overlay. If clicked outside the modal,
|
||||||
* respecting `prefers-color-scheme` by default.
|
* triggers a shake animation as feedback.
|
||||||
*/
|
*/
|
||||||
private updateTheme() {
|
private async pageOverlayClick(e: MouseEvent) {
|
||||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
if (e.target === e.currentTarget) {
|
||||||
this.theme = prefersDark ? 'dark' : 'light';
|
const pageOverlay: HTMLDivElement = this.shadowRoot?.querySelector('.pageOverlay');
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
const modalBox: HTMLDivElement = this.shadowRoot?.querySelector('.modalBox');
|
||||||
this.theme = e.matches ? 'dark' : 'light';
|
if (pageOverlay && modalBox) {
|
||||||
});
|
pageOverlay.classList.add('shake');
|
||||||
|
modalBox.classList.add('shake');
|
||||||
|
await delayFor(2000);
|
||||||
|
pageOverlay.classList.remove('shake');
|
||||||
|
modalBox.classList.remove('shake');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,52 @@
|
|||||||
import * as shared from './shared.js';
|
import { cssManager, colors } from './shared.js';
|
||||||
|
|
||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import {
|
||||||
import { customElement } from 'lit/decorators.js';
|
DeesElement,
|
||||||
import { property } from 'lit/decorators/property.js';
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
type TemplateResult,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
@customElement('consentsoftware-header')
|
@customElement('consentsoftware-header')
|
||||||
export class ConsentsoftwareHeader extends LitElement {
|
export class ConsentsoftwareHeader extends DeesElement {
|
||||||
public static demo = () => html`<consentsoftware-tabs></consentsoftware-tabs>`;
|
public static demo = () => html`<consentsoftware-header></consentsoftware-header>`;
|
||||||
|
|
||||||
public static styles = css`
|
public static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
line-height: 2em;
|
padding: 14px 16px;
|
||||||
text-align: center;
|
border-bottom: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
font-family: ${shared.fontStack};
|
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 0.95em;
|
||||||
|
font-weight: 600;
|
||||||
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
constructor() {
|
.icon {
|
||||||
super();
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
What about cookies?
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<circle cx="12" cy="12" r="10"/>
|
||||||
|
<path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/>
|
||||||
|
<path d="M12 17h.01"/>
|
||||||
|
</svg>
|
||||||
|
Cookie Preferences
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,73 @@
|
|||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import { cssManager, colors } from './shared.js';
|
||||||
import { customElement } from 'lit/decorators.js';
|
|
||||||
import { property } from 'lit/decorators/property.js';
|
import {
|
||||||
|
DeesElement,
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
type TemplateResult,
|
||||||
|
property,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
@customElement('consentsoftware-mainselection')
|
@customElement('consentsoftware-mainselection')
|
||||||
export class ConsentsoftwareMainSelection extends LitElement {
|
export class ConsentsoftwareMainSelection extends DeesElement {
|
||||||
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 = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
: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 {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr);
|
||||||
|
padding: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.maincontainer {
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.itemBox {
|
.itemBox {
|
||||||
padding: 16px;
|
padding: 12px 8px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-right: 1px solid rgba(255, 255, 255, 0.1);
|
border-right: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
}
|
}
|
||||||
|
|
||||||
.itemBox:last-child {
|
.itemBox:last-child {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
constructor() {
|
@media (max-width: 560px) {
|
||||||
super();
|
.itemBox {
|
||||||
|
padding: 10px 8px;
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.itemBox:nth-child(odd) {
|
||||||
|
border-right: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
|
}
|
||||||
|
|
||||||
|
.itemBox:nth-last-child(-n+2) {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="maincontainer">
|
<div class="maincontainer">
|
||||||
@@ -58,5 +87,5 @@ export class ConsentsoftwareMainSelection extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getResults(mouseEvent) {}
|
public async getResults() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import { cssManager, colors } from './shared.js';
|
||||||
import { customElement } from 'lit/decorators.js';
|
|
||||||
import { property } from 'lit/decorators/property.js';
|
import {
|
||||||
|
DeesElement,
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
type TemplateResult,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
@customElement('consentsoftware-tabs')
|
@customElement('consentsoftware-tabs')
|
||||||
export class ConsentsoftwareTabs extends LitElement {
|
export class ConsentsoftwareTabs extends DeesElement {
|
||||||
public static demo = () => html`<consentsoftware-tabs></consentsoftware-tabs>`;
|
public static demo = () => html`<consentsoftware-tabs></consentsoftware-tabs>`;
|
||||||
|
|
||||||
public static styles = css`
|
public static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
background: ${cssManager.bdTheme(colors.light.muted, colors.dark.muted)};
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs {
|
.tabs {
|
||||||
@@ -20,37 +28,50 @@ export class ConsentsoftwareTabs extends LitElement {
|
|||||||
|
|
||||||
.tabs .tab {
|
.tabs .tab {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 3em;
|
padding: 8px 0;
|
||||||
|
font-size: 0.8em;
|
||||||
|
font-weight: 500;
|
||||||
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transition: color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs .tab:hover {
|
||||||
|
color: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.tabs .tab {
|
||||||
|
font-size: 0.75em;
|
||||||
|
padding: 6px 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.selector {
|
.selector {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: calc(100% / 3);
|
width: calc(100% / 3);
|
||||||
height: 1px;
|
height: 2px;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0px;
|
bottom: 0;
|
||||||
background: orange;
|
background: ${cssManager.bdTheme(colors.light.foreground, colors.dark.foreground)};
|
||||||
transition: all 0.2s;
|
transition: all 0.2s ease-out;
|
||||||
}
|
border-radius: 1px;
|
||||||
`;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<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</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="selector"></div>
|
<div class="selector"></div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async handleClick(mouseEvent) {
|
public async handleClick(mouseEvent: MouseEvent) {
|
||||||
const target = mouseEvent.target as HTMLElement;
|
const target = mouseEvent.target as HTMLElement;
|
||||||
const tab: HTMLDivElement = target.closest('.tab');
|
const tab: HTMLDivElement = target.closest('.tab');
|
||||||
if (tab) {
|
if (tab) {
|
||||||
|
|||||||
@@ -1,127 +1,271 @@
|
|||||||
import { LitElement, html, css, type TemplateResult } from 'lit';
|
import { cssManager, colors } from './shared.js';
|
||||||
import { customElement } from 'lit/decorators.js';
|
|
||||||
import { property } from 'lit/decorators/property.js';
|
import {
|
||||||
|
DeesElement,
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
type TemplateResult,
|
||||||
|
property,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
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 DeesElement {
|
||||||
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;
|
||||||
|
|
||||||
public static styles = css`
|
/**
|
||||||
|
* Knob position tracking (0 = off, maxTravel = on)
|
||||||
|
* This is the travel distance, not absolute left position.
|
||||||
|
* Actual left = padding + currentX
|
||||||
|
*/
|
||||||
|
private currentX = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drag state
|
||||||
|
*/
|
||||||
|
private isDragging = false;
|
||||||
|
private hasDragged = false;
|
||||||
|
private startX = 0;
|
||||||
|
|
||||||
|
// Toggle dimensions (with border-box, 1px border reduces inner by 2px)
|
||||||
|
private readonly trackWidth = 36; // outer width
|
||||||
|
private readonly trackHeight = 20; // outer height
|
||||||
|
private readonly knobSize = 14;
|
||||||
|
private readonly padding = 2; // padding from inner edge to knob
|
||||||
|
private readonly maxTravel = 16; // (36 - 2) - 14 - (2 * 2) = 34 - 14 - 4 = 16
|
||||||
|
|
||||||
|
public static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 8px;
|
||||||
|
font-size: 0.8em;
|
||||||
|
font-weight: 500;
|
||||||
|
color: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggleKnobArea {
|
.toggleKnobArea {
|
||||||
cursor: pointer;
|
|
||||||
margin: auto;
|
|
||||||
height: 30px;
|
|
||||||
width: 60px;
|
|
||||||
border-radius: 20px;
|
|
||||||
background: rgba(255, 255, 255, 0.1);
|
|
||||||
position: relative;
|
position: relative;
|
||||||
|
margin: auto;
|
||||||
|
height: 20px;
|
||||||
|
width: 36px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: ${cssManager.bdTheme(colors.light.input, colors.dark.input)};
|
||||||
|
border: 1px solid ${cssManager.bdTheme(colors.light.border, colors.dark.border)};
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
transition: all 0.2s;
|
transition: all 0.15s ease;
|
||||||
border: 1px solid rgba(255, 255, 255, 0);
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggleKnobArea:hover {
|
||||||
|
border-color: ${cssManager.bdTheme(colors.light.ring, colors.dark.ring)};
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([selected]) .toggleKnobArea {
|
:host([selected]) .toggleKnobArea {
|
||||||
background: green;
|
background: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
||||||
|
border-color: ${cssManager.bdTheme(colors.light.primary, colors.dark.primary)};
|
||||||
}
|
}
|
||||||
|
|
||||||
.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: 2px;
|
||||||
left: 0;
|
width: 14px;
|
||||||
transition: all 0.2s;
|
height: 14px;
|
||||||
transform: scale(0.7);
|
border-radius: 7px;
|
||||||
|
background: ${cssManager.bdTheme(colors.light.mutedForeground, colors.dark.mutedForeground)};
|
||||||
|
transition: left 0.15s ease, background 0.15s ease;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggleKnobInner.dragging {
|
||||||
|
transition: background 0.15s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([selected]) .toggleKnobInner {
|
:host([selected]) .toggleKnobInner {
|
||||||
background: white;
|
background: ${cssManager.bdTheme(colors.light.primaryForeground, colors.dark.primaryForeground)};
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([required]) .toggleKnobArea {
|
:host([required]) .toggleKnobArea {
|
||||||
background: none;
|
cursor: not-allowed;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([required]) .toggleKnobInner {
|
:host([required][selected]) .toggleKnobArea {
|
||||||
background: rgba(255, 255, 255, 0.1);
|
background: ${cssManager.bdTheme(colors.light.ring, colors.dark.ring)};
|
||||||
|
border-color: ${cssManager.bdTheme(colors.light.ring, colors.dark.ring)};
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
constructor() {
|
:host([required][selected]) .toggleKnobInner {
|
||||||
super();
|
background: ${cssManager.bdTheme(colors.light.muted, colors.dark.muted)};
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
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.padding + 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(_changedProperties: Map<PropertyKey, unknown>) {
|
||||||
|
await super.firstUpdated(_changedProperties);
|
||||||
if (this.required) {
|
if (this.required) {
|
||||||
this.selected = true;
|
this.selected = true;
|
||||||
this.syncSelection();
|
this.currentX = this.maxTravel;
|
||||||
|
this.requestUpdate();
|
||||||
|
} else {
|
||||||
|
this.currentX = this.selected ? this.maxTravel : 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 (this.isDragging || this.hasDragged) {
|
||||||
moverElement.style.transform = 'translateX(30px)';
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.required) {
|
||||||
|
// Small bounce animation for required toggles
|
||||||
|
this.currentX = this.maxTravel;
|
||||||
|
this.requestUpdate();
|
||||||
|
await new Promise((r) => setTimeout(r, 10));
|
||||||
|
this.currentX = this.maxTravel - 3;
|
||||||
|
this.requestUpdate();
|
||||||
|
await delayFor(150);
|
||||||
|
this.currentX = this.maxTravel;
|
||||||
|
this.requestUpdate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
this.selected = !this.selected;
|
this.selected = !this.selected;
|
||||||
mouseEvent.stopPropagation();
|
this.currentX = this.selected ? this.maxTravel : 0;
|
||||||
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 to valid travel range (0 to maxTravel)
|
||||||
|
this.currentX = Math.max(0, Math.min(newX, this.maxTravel));
|
||||||
|
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 based on midpoint
|
||||||
|
const midpoint = this.maxTravel / 2;
|
||||||
|
this.selected = this.currentX > midpoint;
|
||||||
|
this.currentX = this.selected ? this.maxTravel : 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.maxTravel : 0;
|
||||||
|
this.requestUpdate();
|
||||||
|
}
|
||||||
|
super.updated(changedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getText(): string | null {
|
||||||
return this.textContent;
|
return this.textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,39 @@
|
|||||||
import { unsafeCSS } from 'lit'
|
import { unsafeCSS, cssManager } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
export { cssManager };
|
||||||
|
|
||||||
export const fontStack = unsafeCSS('system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif');
|
export const fontStack = unsafeCSS('system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif');
|
||||||
|
|
||||||
|
// Shadcn-inspired color palette
|
||||||
|
export const colors = {
|
||||||
|
light: {
|
||||||
|
background: '#ffffff',
|
||||||
|
foreground: '#09090b',
|
||||||
|
muted: '#f4f4f5',
|
||||||
|
mutedForeground: '#71717a',
|
||||||
|
border: '#e4e4e7',
|
||||||
|
input: '#e4e4e7',
|
||||||
|
primary: '#18181b',
|
||||||
|
primaryForeground: '#fafafa',
|
||||||
|
secondary: '#f4f4f5',
|
||||||
|
secondaryForeground: '#18181b',
|
||||||
|
accent: '#f4f4f5',
|
||||||
|
accentForeground: '#18181b',
|
||||||
|
ring: '#a1a1aa',
|
||||||
|
},
|
||||||
|
dark: {
|
||||||
|
background: '#09090b',
|
||||||
|
foreground: '#fafafa',
|
||||||
|
muted: '#27272a',
|
||||||
|
mutedForeground: '#a1a1aa',
|
||||||
|
border: '#27272a',
|
||||||
|
input: '#27272a',
|
||||||
|
primary: '#fafafa',
|
||||||
|
primaryForeground: '#18181b',
|
||||||
|
secondary: '#27272a',
|
||||||
|
secondaryForeground: '#fafafa',
|
||||||
|
accent: '#27272a',
|
||||||
|
accentForeground: '#fafafa',
|
||||||
|
ring: '#52525b',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import { html } from 'lit';
|
import { html } from '@design.estate/dees-element';
|
||||||
|
|
||||||
export const page1 = () => html``;
|
export const page1 = () => html``;
|
||||||
@@ -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,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2022",
|
||||||
"module": "ES2020",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "node12"
|
"moduleResolution": "NodeNext"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user