Feature/Embed/Add Embed ui instruction config to hide event type description (#5951)

* Add embed ui instruction to hide event type description

* Add EventTypeDetails option in Embed Snippet Generator
This commit is contained in:
Hariom Balhara authored and GitHub committed 2022-12-13 07:23:26 +00:00
1 parent b7fcf6ade1
commit 3a641e0bc1
6 files changed
+288 -228

No files matched your search

+19 -2
View File
@@ -4,6 +4,7 @@ import { useState, useEffect, CSSProperties } from "react";
import { sdkActionManager } from "./sdk-event";
export interface UiConfig {
hideEventTypeDetails?: boolean;
theme?: "dark" | "light" | "auto";
styles?: EmbedStyles;
}
@@ -39,7 +40,9 @@ const embedStore = {
parentInformedAboutContentHeight: boolean;
windowLoadEventFired: boolean;
theme?: UiConfig["theme"];
setTheme: (arg0: string) => void;
uiConfig?: Omit<UiConfig, "styles" | "theme">;
setTheme?: (arg0: string) => void;
setUiConfig?: (arg0: UiConfig) => void;
};
let isSafariBrowser = false;
@@ -146,6 +149,12 @@ export const useEmbedTheme = () => {
return theme === "auto" ? null : theme;
};
export const useEmbedUiConfig = () => {
const [uiConfig, setUiConfig] = useState(embedStore.uiConfig || {});
embedStore.setUiConfig = setUiConfig;
return uiConfig;
};
// TODO: Make it usable as an attribute directly instead of styles value. It would allow us to go beyond styles e.g. for debugging we can add a special attribute indentifying the element on which UI config has been applied
export const useEmbedStyles = (elementName: keyof EmbedStyles) => {
const [styles, setStyles] = useState({} as EmbedStyles);
@@ -258,7 +267,15 @@ export const methods = {
if (uiConfig.theme) {
embedStore.theme = uiConfig.theme as UiConfig["theme"];
embedStore.setTheme(uiConfig.theme);
if (embedStore.setTheme) {
embedStore.setTheme(uiConfig.theme);
}
}
// Set the value here so that if setUiConfig state isn't available and later it's defined,it uses this value
embedStore.uiConfig = uiConfig;
if (embedStore.setUiConfig) {
embedStore.setUiConfig(uiConfig);
}
setEmbedStyles(stylesConfig || {});