UNPKG

@octopusdeploy/design-system-components

Version:
74 lines (73 loc) 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestDesignSystemProvider = TestDesignSystemProvider; const jsx_runtime_1 = require("react/jsx-runtime"); const material_1 = require("@mui/material"); const react_1 = require("react"); const OctopusRoutingContext_1 = require("../routing/OctopusRoutingContext"); const TransitionComponentProvider_1 = require("../transition/TransitionComponentProvider"); function TestDesignSystemProvider({ Link = TestLink, useIsUrlActive = () => () => false, useDispatchLinkAnalytics = () => () => { }, children }) { return ((0, jsx_runtime_1.jsx)(OctopusRoutingContext_1.OctopusRoutingProvider, { Link: Link, useIsUrlActive: useIsUrlActive, useDispatchLinkAnalytics: useDispatchLinkAnalytics, children: (0, jsx_runtime_1.jsx)(SetMuiTestTheme, { TransitionComponent: TransitionComponentProvider_1.DefaultTransitionComponent, children: children }) })); } const TestLink = (0, react_1.forwardRef)(({ href, disableImplicitEventTracking, ...props }, ref) => { // Currently the design system needs to handle our intermediate PageUrl object // Here we just resolve it with no space id for tests const resolvedHref = href ? (typeof href === "string" ? href : href.resolveWithSpaceId(null)) : undefined; return (0, jsx_runtime_1.jsx)("a", { ...props, href: resolvedHref, ref: ref }); }); TestLink.displayName = "Link"; /** * Applies MUI theme defaults suited to tests: disabling transitions, and disabling the drawer's focus trap enforcement. * Extend the theme here when tests need other MUI defaults. */ const SetMuiTestTheme = ({ children, TransitionComponent }) => { const theme = (0, material_1.createTheme)({ transitions: { // Disable all transitions by overriding the mui transition helper create: () => "none", }, components: { MuiDialog: { defaultProps: { slots: { transition: TransitionComponent, backdrop: TransitionComponent, }, }, }, MuiDrawer: { defaultProps: { // The drawer's focus trap steals focus from dropdowns (e.g. Select) opened in a portal outside the // drawer and closes them before they can be used. Disabling enforcement keeps those dropdowns usable in tests disableEnforceFocus: true, slots: { transition: TransitionComponent, backdrop: TransitionComponent, }, }, }, MuiModal: { defaultProps: { slots: { backdrop: TransitionComponent, }, }, }, MuiSnackbar: { defaultProps: { slots: { transition: TransitionComponent, }, }, }, MuiPopover: { defaultProps: { slots: { transition: TransitionComponent, }, }, }, }, }); return (0, jsx_runtime_1.jsx)(material_1.ThemeProvider, { theme: theme, children: children }); };