Reopen correct component based on consent mode

OPT_OUT regulations (e.g. CCPA) now reopen the banner instead
of the preference panel when clicking the settings widget,
since users only need Accept/Reject choices rather than
granular per-category toggles.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-08 10:32:45 +04:00
parent 901f715b7b
commit 5a80073356
4 changed files with 8 additions and 3 deletions

View File

@@ -70,6 +70,7 @@ export interface ProboRootElement extends ProboElement {
readonly gpcApplied: boolean;
readonly regulation: Regulation | null;
readonly consentMode: "OPT_IN" | "OPT_OUT" | null;
readonly reopenState: ProboState;
setState(state: ProboState): void;
updateDraft(category: string, value: boolean): void;
}

View File

@@ -67,6 +67,10 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem
return null;
}
get reopenState(): ProboState {
return this.consentMode === "OPT_OUT" ? "banner" : "panel";
}
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {
if (name === "reopen-widget" && oldValue !== newValue) {
this.dispatchEvent(
@@ -93,7 +97,7 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem
}
private onOpenPreferences = (): void => {
this.setState("panel");
this.setState(this.reopenState);
};
setState(state: ProboState): void {

View File

@@ -151,7 +151,7 @@ export class ProboSettingsButton extends HTMLElement {
private handleClick = (): void => {
if (!this.root) return;
this.root.setState("panel");
this.root.setState(this.root.reopenState);
};
private updateGpcBadge(label: string | null): void {

View File

@@ -68,6 +68,6 @@ export class ProboSettingsLink extends HTMLElement {
private handleClick = (e: Event): void => {
if (!this.root) return;
e.preventDefault();
this.root.setState("panel");
this.root.setState(this.root.reopenState);
};
}