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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user