UNPKG

@gfazioli/mantine-onboarding-tour

Version:

A Mantine 9 onboarding tour component with focus-reveal overlays, cutout highlights, step-by-step popover navigation, and compound components for guided user experiences.

133 lines (129 loc) 5.12 kB
'use client'; 'use strict'; var core = require('@mantine/core'); var React = require('react'); var OnboardingTourPopoverContent_module = require('./OnboardingTourPopoverContent.module.css.cjs'); const defaultProps = { withPrevButton: true, withNextButton: true, withSkipButton: true, withStepper: true, nextStepNavigation: "Next", endStepNavigation: "End", prevStepNavigation: "Prev", skipNavigation: "Skip", stepperStepProps: { allowStepClick: true } }; const OnboardingTourPopoverContent = core.factory( (_props) => { const props = core.useProps("OnboardingTourPopoverContent", defaultProps, _props); const { tourController, loop, header, title, content, footer, withPrevButton, withNextButton, withSkipButton, withStepper, nextStepNavigation, endStepNavigation, prevStepNavigation, skipNavigation, stepper, stepperStepProps, stepperProps, // Destructure callbacks inherited from OnboardingTourOptions // to prevent them from leaking into DOM via ...others onOnboardingTourComplete: _onComplete, onOnboardingTourSkip: _onSkip, classNames, style, styles, unstyled, vars, className, ...others } = props; const getStyles = core.useStyles({ name: "OnboardingTourPopoverContent", props, classes: OnboardingTourPopoverContent_module, className, style, classNames, styles, unstyled, vars }); const { tour, currentStep, currentStepIndex, setCurrentStepIndex: setCurrentStep, skipTour, nextStep: nextTour, prevStep: prevTour } = tourController; if (!tourController || !currentStep) { return null; } const { header: headerTourStep, title: titleTourStep, content: contentTourStep, footer: footerTourStep } = currentStep; const withFunction = (prop, wrapper) => { if (typeof prop === "function") { return prop(tourController); } else if (typeof prop === "string" && wrapper) { return wrapper(prop); } return prop; }; const skipNavigationComponent = withSkipButton && withFunction(skipNavigation, (label) => /* @__PURE__ */ React.createElement( core.Anchor, { size: "xs", onClick: () => { skipTour(); } }, label )) || /* @__PURE__ */ React.createElement("div", null); const headerComponent = withFunction(header || headerTourStep); const titleComponent = withFunction( title || titleTourStep, (label) => /* @__PURE__ */ React.createElement(core.Text, { fw: 800, size: "xl" }, label) ); const contentComponent = withFunction(content || contentTourStep); const footerComponent = withFunction(footer || footerTourStep); const prevNavigationComponent = withPrevButton && ((currentStepIndex ?? 0) > 0 || loop) ? withFunction(prevStepNavigation, (label) => /* @__PURE__ */ React.createElement(core.Button, { variant: "light", size: "xs", onClick: prevTour }, label)) : /* @__PURE__ */ React.createElement("div", null); const nextNavigationComponent = withNextButton && ((currentStepIndex ?? 0) < tour.length - 1 || loop) && withFunction(nextStepNavigation, (label) => /* @__PURE__ */ React.createElement(core.Button, { variant: "light", size: "xs", onClick: nextTour }, label)); const endNavigationComponent = withNextButton && (currentStepIndex ?? 0) === tour.length - 1 && !loop && withFunction(endStepNavigation, (label) => /* @__PURE__ */ React.createElement(core.Button, { size: "xs", onClick: nextTour }, label)); const stepperComponent = withStepper && (withFunction(stepper) || /* @__PURE__ */ React.createElement(core.Group, { grow: true }, /* @__PURE__ */ React.createElement( core.Stepper, { ...stepperProps, onStepClick: setCurrentStep, classNames: { stepIcon: OnboardingTourPopoverContent_module.stepIcon, separator: OnboardingTourPopoverContent_module.separator }, active: currentStepIndex ?? 0, size: "xs" }, tour.map((step) => /* @__PURE__ */ React.createElement(core.Stepper.Step, { ...stepperStepProps, key: step.id, value: step.id })) ))); return /* @__PURE__ */ React.createElement(core.Box, { ...getStyles("popoverContent"), ...others }, /* @__PURE__ */ React.createElement(core.Stack, null, headerComponent, titleComponent, contentComponent, /* @__PURE__ */ React.createElement(core.Group, { justify: "space-between" }, skipNavigationComponent, /* @__PURE__ */ React.createElement(core.Group, { justify: "space-between" }, prevNavigationComponent, nextNavigationComponent, endNavigationComponent)), stepperComponent, footerComponent)); } ); OnboardingTourPopoverContent.displayName = "OnboardingTourPopoverContent"; exports.OnboardingTourPopoverContent = OnboardingTourPopoverContent; exports.defaultProps = defaultProps; //# sourceMappingURL=OnboardingTourPopoverContent.cjs.map