diff --git a/src/docs/styles.css b/src/docs/styles.css
index 01ccc8d..b796100 100644
--- a/src/docs/styles.css
+++ b/src/docs/styles.css
@@ -122,12 +122,18 @@ input :required {
grid-template-columns: 1fr;
}
+.code {
+ overflow-wrap: break-word;
+ word-break: break-word;
+}
+
.code > pre {
background: lightgrey;
padding: 15px;
font-size: 14px;
margin: 0;
min-height: 300px;
+ white-space: pre-wrap;
}
.codeHeader {
@@ -177,6 +183,59 @@ footer {
text-align: center;
}
+.config > * >textarea {
+ width: 90%;
+ border: 1px solid #bbb;
+ border-radius: 5px;
+ flex-wrap: wrap;
+ overflow-wrap: break-word;
+ text-overflow: clip;
+ resize: none;
+}
+
+.modal {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width:100%;
+ height: 100%;
+ background: rgba(0, 0, 0, 0.6);
+}
+
+.modal .modal-main {
+ position:fixed;
+ background: white;
+ width: 50%;
+ height: auto;
+ top:50%;
+ left:50%;
+ transform: translate(-50%,-50%);
+ display: flex;
+ flex-direction: column;
+ padding: 10px;
+}
+
+.modal-main .themeText {
+ border: 1px solid #bbb;
+ border-radius: 5px;
+ resize: none;
+}
+
+.modal-main button {
+ align-self: flex-end;
+ width: 50px;
+ margin-top: 10px;
+}
+
+.display-block {
+ display: block;
+}
+
+.display-none {
+ display: none;
+}
+
+
@media only screen and (max-width: 900px) {
.code {
display: none;
diff --git a/src/docs/utils.js b/src/docs/utils.js
index 150f29a..3149b21 100644
--- a/src/docs/utils.js
+++ b/src/docs/utils.js
@@ -31,10 +31,17 @@ const initializeState = type => ({
flag: false,
reportMode: defaultOptions[type].mode,
datasetId: '',
+ theme: {},
+show: false
});
+const isObject = obj => {
+ return (typeof obj === "object" && obj !== null) || typeof obj === "function";
+}
+
export {
embedTypes,
defaultOptions,
- initializeState
+ initializeState,
+ isObject,
};
diff --git a/src/lib/config.js b/src/lib/config.js
index 2ec6f99..d03f0bd 100644
--- a/src/lib/config.js
+++ b/src/lib/config.js
@@ -1,5 +1,5 @@
import { models } from 'powerbi-client';
-import { clean } from "./utils";
+import { clean, isEmpty } from "./utils";
import pbi from 'powerbi-client';
const createConfig = props => {
@@ -16,7 +16,9 @@ const createConfig = props => {
dashboardId,
datasetId,
reportMode,
+ theme,
} = props;
+
if(reportMode === 'create') {
return clean({
tokenType: models.TokenType[tokenType],
@@ -43,15 +45,26 @@ const createConfig = props => {
},
datasetId,
reportMode,
+ theme: !isEmpty(theme)?{themeJson: theme}:null,
});
}
return null;
};
+ const validateCustomTheme = config => {
+ if(config.theme) {
+ err = pbi.models.validateCustomTheme(config.theme);
+ if(err) {
+ return []
+ }
+ }
+ return [];
+ };
+
const validateTypeConfig = config => {
switch (config.type) {
case 'report':
- return pbi.models.validateReportLoad(config);
+ return pbi.models.validateReportLoad(config) && validateCustomTheme(config);
case 'dashboard':
return pbi.models.validateDashboardLoad(config);
case 'tile':
diff --git a/src/lib/onEmbedHandlers.js b/src/lib/onEmbedHandlers.js
index 9abb625..3a2b483 100644
--- a/src/lib/onEmbedHandlers.js
+++ b/src/lib/onEmbedHandlers.js
@@ -7,11 +7,13 @@ const reportHandler = (report, reportMode, props) => {
if(validateMode(reportMode) && reportMode !== "view") {
report.switchMode(reportMode);
}
-
validateAndInvokeCallback(props.onLoad, report);
+ if(props.theme) report.applyTheme(props.theme);
});
- report.on('rendered', () => validateAndInvokeCallback(props.onRender, report));
+ report.on('rendered', () => {
+ validateAndInvokeCallback(props.onRender, report);
+ });
report.on('error', event => validateAndInvokeCallback(props.onError, event.detail));
diff --git a/src/lib/utils.js b/src/lib/utils.js
index 115099b..bb2a3e5 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -27,4 +27,6 @@ const validateAndInvokeCallback = (callback, data) => {
}
}
-export { clean, validateMode, validateAndInvokeCallback };
+const isEmpty = (obj) => { return Object.keys(obj).length === 0 && obj.constructor === Object};
+
+export { clean, validateMode, validateAndInvokeCallback, isEmpty };