@etchteam/storybook-addon-marker
Version:
Add a Marker.io feedback button to the storybook UI
49 lines (42 loc) • 1.15 kB
JavaScript
import markerSDK from '@marker.io/browser';
import { useGlobals, useChannel } from 'storybook/preview-api';
// src/withMarker.js
// src/constants.js
var ADDON_ID = "marker";
var EVENTS = {
LOADED: `${ADDON_ID}/loaded`,
CAPTURE: `${ADDON_ID}/capture`
};
// src/hideDefaultMarkerButton.js
var hideDefaultMarkerButton = () => {
const markerBtns = [
...document.querySelectorAll(".marker-app #feedback-button")
];
markerBtns.forEach((markerBtn) => markerBtn.style.display = "none");
};
// src/withMarker.js
var withMarker = (storyFn) => {
const [globals] = useGlobals();
const { project, mode, ...config } = globals.marker ?? {};
const emit = useChannel({
[EVENTS.CAPTURE]: () => {
window.Marker?.capture(mode)?.then(() => {
hideDefaultMarkerButton();
});
}
});
if (!project || window.Marker) {
return storyFn();
}
markerSDK.loadWidget({ project, ...config }).then(() => {
hideDefaultMarkerButton();
emit(EVENTS.LOADED);
});
return storyFn();
};
// src/preview.js
var preview = {
decorators: [withMarker]
};
var preview_default = preview;
export { preview_default as default };