updates
This commit is contained in:
1 parent
9ff4ece541
commit
e91811ff23
11 files changed
+377
-61
No files matched your search
@@ -0,0 +1,23 @@
|
||||
.shepherd-element {
|
||||
@apply !bg-primary-dark !rounded-lg !p-2;
|
||||
}
|
||||
|
||||
.shepherd-text {
|
||||
@apply text-[11px] !text-white;
|
||||
}
|
||||
|
||||
.shepherd-footer {
|
||||
@apply !bg-primary-dark !rounded-b-lg;
|
||||
}
|
||||
|
||||
.shepherd-button {
|
||||
@apply !bg-primary-main hover:!bg-customblue-80 active:!bg-customblue-40 !box-content !inline-flex !h-[15px] !min-w-[60px] !flex-row !items-center !justify-center !gap-[5px] !whitespace-nowrap !rounded !px-[10px] !text-center !font-sans !text-[11px] !font-semibold !leading-[1.2] !text-white !outline-none !transition !duration-300 !ease-in-out focus:!outline-none;
|
||||
}
|
||||
|
||||
.shepherd-arrow::before {
|
||||
@apply !bg-primary-dark;
|
||||
}
|
||||
|
||||
.shepherd-element[data-popper-placement^='left'] > .shepherd-arrow {
|
||||
right: -5px !important;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useShepherd } from 'react-shepherd';
|
||||
import { StepOptions, TourOptions } from 'shepherd.js';
|
||||
import { useLocation } from 'react-router';
|
||||
import 'shepherd.js/dist/css/shepherd.css';
|
||||
import './Onboarding.css';
|
||||
|
||||
const hasTourBeenShown = (tourId: string) => {
|
||||
const shownTours = JSON.parse(localStorage.getItem('shownTours')) || [];
|
||||
return shownTours.includes(tourId);
|
||||
};
|
||||
const markTourAsShown = (tourId: string) => {
|
||||
const shownTours = JSON.parse(localStorage.getItem('shownTours')) || [];
|
||||
if (!shownTours.includes(tourId)) {
|
||||
shownTours.push(tourId);
|
||||
localStorage.setItem('shownTours', JSON.stringify(shownTours));
|
||||
}
|
||||
};
|
||||
|
||||
const Onboarding = () => {
|
||||
const Shepherd = useShepherd();
|
||||
const location = useLocation();
|
||||
const tours = window.config.tours as Array<{
|
||||
id: string;
|
||||
route: string;
|
||||
tourOptions: TourOptions;
|
||||
steps: StepOptions[];
|
||||
}>;
|
||||
useEffect(() => {
|
||||
if (!tours) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const pathname = location.pathname;
|
||||
const matchingTour = tours.find(tour => tour.route === pathname);
|
||||
|
||||
if (matchingTour) {
|
||||
const startTour = () => {
|
||||
const tourInstance = new Shepherd.Tour(matchingTour.tourOptions);
|
||||
matchingTour.steps.forEach(step => tourInstance.addStep(step));
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
const firstStepElement = document.querySelector(
|
||||
matchingTour.steps[0].attachTo.element as string
|
||||
);
|
||||
if (firstStepElement) {
|
||||
observer.disconnect();
|
||||
tourInstance.start();
|
||||
markTourAsShown(matchingTour.id);
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasTourBeenShown(matchingTour.id)) {
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
setTimeout(() => observer.disconnect(), 5000);
|
||||
}
|
||||
};
|
||||
|
||||
startTour();
|
||||
}
|
||||
}, [Shepherd, tours, location.pathname]);
|
||||
return null;
|
||||
};
|
||||
|
||||
export { Onboarding };
|
||||
@@ -0,0 +1,3 @@
|
||||
import { Onboarding } from './Onboarding';
|
||||
|
||||
export { Onboarding };
|
||||
@@ -28,6 +28,7 @@ import ThumbnailList from './ThumbnailList';
|
||||
import PanelSection from './PanelSection';
|
||||
import DisplaySetMessageListTooltip from './DisplaySetMessageListTooltip';
|
||||
import { Toolbox, ToolboxUI } from './Toolbox';
|
||||
import { Onboarding } from './Onboarding';
|
||||
|
||||
export {
|
||||
Button,
|
||||
@@ -71,4 +72,5 @@ export {
|
||||
DisplaySetMessageListTooltip,
|
||||
Toolbox,
|
||||
ToolboxUI,
|
||||
Onboarding,
|
||||
};
|
||||
Reference in new issue
Block a user