Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onborda PR #29

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

Onborda PR #29

wants to merge 30 commits into from

Conversation

alexc-harrap
Copy link

Hi @uixmat

I have been building off of your package (thanks for this!) to add some features that we needed for our use case. It is a large PR and does contain some breaking changes so not expecting it to be approved, but creating a PR in case you would like to copy some of the enhancements I have added even if you reject the PR.

Breaking Changes

  • <Onborda /> no longer has steps : Tour[]. This has been moved up to <OnbordaProvider /> and called tours: Tours[].
    • This is so OnbordaContext has access to every tour and its steps to allow a new useOnborda function of setStep which can switch to any step in the current tour, not just the previous or next.
  • Step.prevRoute and Step.nextRoute have been deprecated in favour of a single Step.route defined per step. This is to ensure when switching to any step, the correct route can be navigated to.

Added new optional TourCard

The TourCard is a secondary card displayed in addition of the StepCard on the overlay. The TourCard is intended to show details of the current tour. Eg the todo list of steps.

Added optional Step.interactable = false

Each step can now block or allow interaction with the focused element on a step-by-step basis. EG if the step is part of a setup tour and you point the user to an input for setting their organisation name for example, they can fill that in while the overlay is still active. But if you want to just show them around the site without them changing the current route, then it can be set to false.

Added useOnborda.completedSteps[]

completedSteps is a Set of indexes. Once a step is shown or conditions met (see below), it is added to this Set automatically. This allows the TourCard to keep track of which steps have been 'completed' and allow showing a checkmark against the step for example.

Added optional Step.isCompleteConditions()

isCompleteConditions is a client function that is bound to an event listener on the focussed element on click, input and change. The Element is then passed to this function for custom conditions to be applied before the step is added to the completedSteps Set. EG if the focused element is an input field, the isCompleteConditions function can check the value is valid before marking it as complete.

Added optional Step.onComplete() callback

onComplete is a callback called whenever the step is marked as completed. This can be used to store the state of the step server side.

Added optional Step.customQuerySelector()

I found while using Step.selector that sometimes with UI libraries, the element you can set the ID on is within other divs, causing the pointer to be offset. This allows for getting the selectors parent Element for example.

Added optional Tour.initialCompletedStepsState()

initialCompletedStepsState is a Promise<boolean[]> that is called when a tour is started. This allows fetching the initial completed steps state from a server action. It should return a boolean array the same size as the Tour.Steps array.

Added [key: string] to Tour and Step Objects

[key: string] is a way to allow the user to provide any additional data or flags they wish to use in their TourCard or StepCard making it easier to customise per step or per tour.

Added optional OnbordaProvider.activeTour

activeTour is way to set an initial active tour on load without having to call startOnborda or setTour. This can be useful for Setup tours where you would want the tour to be forced on until the user has completed it.

I have created a demo codespace on my github showcasing the TourCard:
https://github.com/alexc-harrap/Libresoft-Onborda-Demo

Its now possible to have a second element on the page while a tour is active, displaying information about the current Tour.
…inter is centered to the page and arrow is hidden for a generic modal step.
…ector function per step for setting the pointer to more complex elements, eg call .closest
…nto <Portal/>. Added timout to MutationObserver
…t the next step by user-provided condidtions
Deprecated .nextRoute and .prevRoute in favour of .route
Deprecated Onborda.steps in favor of OnbordaProvider.tours. currentTourSteps now stored in useState within useOnborda.
Each step can now have an initialCompletedState via async function. This will be called when the tour starts via a Promise.all on every step. User will start tour on the first incomplete step.

Handling of routing and finding element to focus has been consolidated into the main useEffect to reduce repeated code. nextStep, prevState and setStep now just change the currentStep useState, triggering the useEffect to change route and find the element if set.
Added onComplete callbacks to the Step object.
Merged useEffects to improve route change awareness ensuring onComplete is called after the route has updated to prevent potential serverActions revalidation on the previous route blocking router.push.
…p states in one call rather than one per step
@Qodestackr
Copy link

Is adding a global context the best way out ?

@Jkroeger123
Copy link

this is great, thanks for putting this together!

@uixmat
Copy link
Owner

uixmat commented Dec 22, 2024

Hey @alexc-harrap - thanks so much for all your work here, some really good changes! I'm sorry for such a slow response speed, i've just started working at Prisma with no time-off between so its been a hectic couple of months!

I'm implementing some of the changes bit by bit right now!

Copy link
Owner

@uixmat uixmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexc-harrap I'm making some updates today and i really like this update but would like to give you full credit and have you marked as a collaborator on the package. After i've made a release i'd love you to submit a PR with the onComplete and path changes (2b32a4c) if you have the time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants