{"version":3,"file":"UiShellProvider.cjs","names":["_react","require","_createContrastColors","_OdysseyDesignTokensContext","_createMessageBus","_jsxRuntime","defaultCloseSideNavMessageBus","exports","createMessageBus","defaultSubscribeToCloseRightSideMenu","UiShellContext","createContext","undefined","useUiShellContext","useContext","UiShellProvider","appBackgroundColor","appBackgroundContrastMode","children","closeSideNavMenu","sideNavBackgroundColor","sideNavBackgroundContrastColor","subscribeToCloseRightSideMenu","subscribeToCloseSideNavMenu","topNavBackgroundColor","odysseyDesignTokens","useOdysseyDesignTokens","defaultedSideNavBackgroundColor","HueNeutralWhite","sideNavContrastColors","generateContrastColors","backgroundColor","backgroundContrastColor","isAppBackgroundHightContrast","defaultTopAndAppBackgroundColor","HueNeutral50","topNavColor","appContentBackgroundColor","memoizedContextValue","useMemo","publish","subscribe","jsx","Provider","value","MemoizedUiShellProvider","memo"],"sources":["../../../src/ui-shell/UiShellProvider.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n  createContext,\n  memo,\n  PropsWithChildren,\n  useContext,\n  useMemo,\n} from \"react\";\n\nimport {\n  ContrastColors,\n  generateContrastColors,\n} from \"../createContrastColors.js\";\nimport { useOdysseyDesignTokens } from \"../OdysseyDesignTokensContext.js\";\nimport { createMessageBus, MessageBus } from \"../tools/createMessageBus.js\";\nimport { ContrastMode } from \"../useContrastMode.js\";\n\nexport const defaultCloseSideNavMessageBus = createMessageBus();\nexport const defaultSubscribeToCloseRightSideMenu = () => () => {};\n\nexport type UiShellColors = {\n  /**\n   * Custom background color for the app content area.\n   */\n  appBackgroundColor: string;\n  /**\n   * Custom background color for the side nav area.\n   */\n  sideNavBackgroundColor: string;\n  /**\n   * Custom color for fonts and other contrasted colors in the side nav area. Other contrast colors are derived from this one.\n   *\n   * If not passed, it gets computed from Odyssey.\n   */\n  sideNavBackgroundContrastColor?: string;\n  sideNavContrastColors?: ContrastColors;\n  /**\n   * Custom background color for the top nav area.\n   */\n  topNavBackgroundColor: string;\n};\n\nexport type UiShellContext = {\n  /**\n   * This is a callback that publishes a change to all subscribers listening for when to close the side nav.\n   */\n  closeSideNavMenu: MessageBus<void>[\"publish\"];\n  /**\n   * This is a callback that provides a subscriber callback to listen for changes to state. It allows UI Shell to listen for a publisher that asks us to close the right-side menu.\n   */\n  subscribeToCloseRightSideMenu: MessageBus<void>[\"subscribe\"];\n  /**\n   * This is a callback that provides a subscriber callback to listen for changes to state. It allows UI Shell to listen for a publisher that asks us to close the side nav.\n   */\n  subscribeToCloseSideNavMenu: MessageBus<void>[\"subscribe\"];\n} & UiShellColors;\n\nconst UiShellContext = createContext<UiShellContext | undefined>(undefined);\n\nexport const useUiShellContext = () => {\n  return useContext(UiShellContext);\n};\n\nexport type UiShellProviderProps = {\n  /**\n   * Sets either a gray or white background color for the app content area.\n   */\n  appBackgroundContrastMode?: ContrastMode;\n} & Partial<UiShellContext>;\n\nconst UiShellProvider = ({\n  appBackgroundColor,\n  appBackgroundContrastMode = \"lowContrast\",\n  children,\n  closeSideNavMenu,\n  sideNavBackgroundColor,\n  sideNavBackgroundContrastColor,\n  subscribeToCloseRightSideMenu,\n  subscribeToCloseSideNavMenu,\n  topNavBackgroundColor,\n}: PropsWithChildren<UiShellProviderProps>) => {\n  const odysseyDesignTokens = useOdysseyDesignTokens();\n  const defaultedSideNavBackgroundColor =\n    sideNavBackgroundColor || odysseyDesignTokens.HueNeutralWhite;\n\n  const sideNavContrastColors =\n    defaultedSideNavBackgroundColor !== odysseyDesignTokens.HueNeutralWhite\n      ? generateContrastColors({\n          backgroundColor:\n            sideNavBackgroundColor || defaultedSideNavBackgroundColor,\n          backgroundContrastColor: sideNavBackgroundContrastColor,\n          odysseyDesignTokens,\n        })\n      : undefined;\n\n  const isAppBackgroundHightContrast =\n    appBackgroundContrastMode === \"highContrast\";\n\n  const defaultTopAndAppBackgroundColor = isAppBackgroundHightContrast\n    ? odysseyDesignTokens.HueNeutralWhite\n    : odysseyDesignTokens.HueNeutral50;\n\n  const topNavColor = topNavBackgroundColor || defaultTopAndAppBackgroundColor;\n\n  const appContentBackgroundColor =\n    appBackgroundColor || defaultTopAndAppBackgroundColor;\n\n  const memoizedContextValue = useMemo(\n    () => ({\n      appBackgroundColor: appContentBackgroundColor,\n      closeSideNavMenu:\n        closeSideNavMenu ?? defaultCloseSideNavMessageBus.publish,\n      sideNavBackgroundColor:\n        sideNavBackgroundColor || odysseyDesignTokens.HueNeutralWhite,\n      sideNavContrastColors,\n      subscribeToCloseSideNavMenu:\n        subscribeToCloseSideNavMenu ?? defaultCloseSideNavMessageBus.subscribe,\n      subscribeToCloseRightSideMenu:\n        subscribeToCloseRightSideMenu ?? defaultSubscribeToCloseRightSideMenu,\n      topNavBackgroundColor: topNavColor,\n    }),\n    [\n      appContentBackgroundColor,\n      odysseyDesignTokens.HueNeutralWhite,\n      closeSideNavMenu,\n      sideNavBackgroundColor,\n      sideNavContrastColors,\n      subscribeToCloseRightSideMenu,\n      subscribeToCloseSideNavMenu,\n      topNavColor,\n    ],\n  );\n\n  return (\n    <UiShellContext.Provider value={memoizedContextValue}>\n      {children}\n    </UiShellContext.Provider>\n  );\n};\n\nconst MemoizedUiShellProvider = memo(UiShellProvider);\n\nexport { MemoizedUiShellProvider as UiShellProvider };\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAQA,IAAAC,qBAAA,GAAAD,OAAA;AAIA,IAAAE,2BAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAA4E,IAAAI,WAAA,GAAAJ,OAAA;AAzB5E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