{"version":3,"file":"Tabs.cjs","names":["_lab","require","_react","_Badge","_Box","_OdysseyDesignTokensContext","_jsxRuntime","_interopRequireDefault","e","__esModule","default","TabLabel","label","notificationCount","notificationCountMax","tabState","value","odysseyDesignTokens","useOdysseyDesignTokens","jsxs","Fragment","children","undefined","jsx","Box","sx","marginInlineStart","Spacing2","Badge","badgeContent","badgeContentMax","type","Tabs","ariaLabel","initialValue","tabs","onChange","onChangeProp","setTabState","useState","scrollButtons","setScrollButtons","useCallback","event","useEffect","animationFrame","cleanup","cancelAnimationFrame","document","removeEventListener","refreshScrollButtons","requestAnimationFrame","addEventListener","renderTab","tab","index","testId","isDisabled","startIcon","_Tab2","disabled","icon","tabIndex","toString","TabContext","TabList","variant","map","TabPanel","MemoizedTabs","exports","memo","displayName"],"sources":["../../src/Tabs.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  TabContext as MuiTabContext,\n  TabList as MuiTabList,\n  TabListProps as MuiTabListProps,\n  TabPanel as MuiTabPanel,\n} from \"@mui/lab\";\nimport { Tab as MuiTab } from \"@mui/material\";\nimport {\n  memo,\n  ReactElement,\n  ReactNode,\n  useCallback,\n  useEffect,\n  useState,\n} from \"react\";\n\nimport { Badge, BadgeProps } from \"./Badge.js\";\nimport { Box } from \"./Box.js\";\nimport { HtmlProps } from \"./HtmlProps.js\";\nimport { useOdysseyDesignTokens } from \"./OdysseyDesignTokensContext.js\";\n\nexport type TabItemProps = {\n  /**\n   * Content rendered inside the tab panel when this tab is active.\n   */\n  children: ReactNode;\n  /**\n   * If `true`, the tab is disabled and cannot be selected.\n   */\n  isDisabled?: boolean;\n  /**\n   * The label text for the TabItem\n   */\n  label: string;\n  /**\n   * An optional icon to display at the start of the TabItem\n   */\n  startIcon?: ReactElement;\n  /**\n   * The value associated with the TabItem\n   */\n  value?: string;\n} & {\n  /**\n   * The count to display in the notification badge on the tab. Badge is hidden when the value is 0 or undefined.\n   */\n  notificationCount?: BadgeProps[\"badgeContent\"];\n  /**\n   * The maximum value to display in the notification badge before truncating with \"+\".\n   */\n  notificationCountMax?: BadgeProps[\"badgeContentMax\"];\n} & Pick<HtmlProps, \"testId\" | \"translate\">;\n\nexport type TabsProps = {\n  /**\n   * @deprecated please use the `value` prop instead\n   * When `value` is provided, `initialValue` isn't used.\n   */\n  initialValue?: string;\n  /**\n   * Called when the active tab changes. Receives the new tab value.\n   */\n  onChange?: MuiTabListProps[\"onChange\"];\n  /**\n   * The TabItems to be included in the Tabs group\n   */\n  tabs: TabItemProps[];\n  /**\n   * Identifier for the selected tab.\n   */\n  value?: string;\n};\n\nconst TabLabel = ({\n  label,\n  notificationCount,\n  notificationCountMax,\n  tabState,\n  value,\n}: Pick<\n  TabItemProps,\n  \"label\" | \"notificationCount\" | \"notificationCountMax\" | \"value\"\n> & {\n  tabState: string;\n}) => {\n  const odysseyDesignTokens = useOdysseyDesignTokens();\n\n  return (\n    <>\n      {label}\n      {notificationCount !== undefined && notificationCount > 0 && (\n        <Box\n          sx={{\n            marginInlineStart: notificationCount\n              ? odysseyDesignTokens.Spacing2\n              : 0,\n          }}\n        >\n          <Badge\n            badgeContent={notificationCount}\n            badgeContentMax={notificationCountMax}\n            type={value === tabState ? \"attention\" : \"default\"}\n          />\n        </Box>\n      )}\n    </>\n  );\n};\n\n/**\n * A tabbed navigation component that renders a list of tabs and their associated content panels. Supports controlled and uncontrolled selection, notification badges, icons, and scrollable overflow.\n */\nconst Tabs = ({\n  ariaLabel,\n  initialValue,\n  tabs,\n  value,\n  onChange: onChangeProp,\n}: TabsProps & Pick<HtmlProps, \"ariaLabel\">) => {\n  const [tabState, setTabState] = useState(\n    initialValue ?? value ?? tabs[0]?.value ?? \"0\",\n  );\n  /*\n    The scrollButtons prop is initially set to `false`.\n    It's then reset to `auto` when the document is visible.\n    This prevents a rare bug where scroll buttons appear\n    when the component is rendered while hidden and the\n    screen is wide enough to not need scroll buttons.\n  */\n  const [scrollButtons, setScrollButtons] =\n    useState<MuiTabListProps[\"scrollButtons\"]>(false);\n  const onChange = useCallback<NonNullable<MuiTabListProps[\"onChange\"]>>(\n    (event, value: string) => {\n      setTabState(value);\n      onChangeProp?.(event, value);\n    },\n    [onChangeProp],\n  );\n\n  useEffect(() => {\n    if (value !== undefined) {\n      setTabState(value);\n    }\n  }, [value]);\n\n  // listen for visibility change to reset scroll buttons override\n  useEffect(() => {\n    // keep track of animation frame to cancel when needed\n    let animationFrame: number;\n\n    // called when unmounted or scroll buttons is reset\n    const cleanup = () => {\n      cancelAnimationFrame(animationFrame);\n      document.removeEventListener(\"visibilitychange\", refreshScrollButtons);\n    };\n\n    // Reset the scroll buttons override when the document becomes visible. If called, then the document is hidden because the event listener is only registered if the document is hidden\n    function refreshScrollButtons() {\n      animationFrame = requestAnimationFrame(() => {\n        cleanup();\n        setScrollButtons(\"auto\");\n      });\n    }\n\n    // don't override scroll buttons if it's already set to \"auto\"\n    if (scrollButtons !== \"auto\") {\n      document.addEventListener(\"visibilitychange\", refreshScrollButtons);\n    }\n    return () => {\n      cleanup();\n    };\n  }, [scrollButtons]);\n\n  const renderTab = useCallback(\n    (tab: TabItemProps, index: number) => {\n      const {\n        testId,\n        isDisabled,\n        label,\n        startIcon,\n        value,\n        notificationCount,\n        notificationCountMax,\n      } = tab;\n\n      return (\n        <MuiTab\n          data-se={testId}\n          disabled={isDisabled}\n          icon={startIcon}\n          key={value ? value : index.toString()}\n          label={\n            <TabLabel\n              label={label}\n              notificationCount={notificationCount}\n              notificationCountMax={notificationCountMax}\n              tabState={tabState}\n              value={value}\n            />\n          }\n          tabIndex={0}\n          value={value ? value : index.toString()}\n        />\n      );\n    },\n    [tabState],\n  );\n\n  return (\n    <MuiTabContext value={tabState}>\n      <MuiTabList\n        aria-label={ariaLabel}\n        onChange={onChange}\n        scrollButtons={scrollButtons}\n        variant=\"scrollable\"\n      >\n        {tabs.map((tab, index) => renderTab(tab, index))}\n      </MuiTabList>\n      {tabs.map((tab, index) => (\n        <MuiTabPanel\n          key={tab.value ? tab.value : index.toString()}\n          value={tab.value ? tab.value : index.toString()}\n        >\n          {tab.children}\n        </MuiTabPanel>\n      ))}\n    </MuiTabContext>\n  );\n};\n\nconst MemoizedTabs = memo(Tabs);\nMemoizedTabs.displayName = \"Tabs\";\n\nexport { MemoizedTabs as Tabs };\n"],"mappings":";;;;;;;AAYA,IAAAA,IAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AASA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,2BAAA,GAAAJ,OAAA;AAAyE,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAM,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA/BzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA2EA,MAAMG,QAAQ,GAAGA,CAAC;EAChBC,KAAK;EACLC,iBAAiB;EACjBC,oBAAoB;EACpBC,QAAQ;EACRC;AAMF,CAAC,KAAK;EACJ,MAAMC,mBAAmB,GAAG,IAAAC,kDAAsB,EAAC,CAAC;EAEpD,OACE,IAAAZ,WAAA,CAAAa,IAAA,EAAAb,WAAA,CAAAc,QAAA;IAAAC,QAAA,GACGT,KAAK,EACLC,iBAAiB,KAAKS,SAAS,IAAIT,iBAAiB,GAAG,CAAC,IACvD,IAAAP,WAAA,CAAAiB,GAAA,EAACnB,IAAA,CAAAoB,GAAG;MACFC,EAAE,EAA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