@octopusdeploy/design-system-components
Version:
The design systems component library.
73 lines (72 loc) • 3.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetMuiDefaultTransitions = void 0;
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)(exports.SetMuiDefaultTransitions, { 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";
/**
* Set the default transitions for MUI. This can be used to disable transitions
* during tests for example.
*/
const SetMuiDefaultTransitions = ({ 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: {
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 });
};
exports.SetMuiDefaultTransitions = SetMuiDefaultTransitions;