@fluentui/react-tabs 9.1.4 → 9.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.json +81 -1
  2. package/CHANGELOG.md +26 -2
  3. package/lib/components/Tab/Tab.js +0 -1
  4. package/lib/components/Tab/Tab.js.map +1 -1
  5. package/lib/components/Tab/renderTab.js +8 -5
  6. package/lib/components/Tab/renderTab.js.map +1 -1
  7. package/lib/components/Tab/useTab.js +0 -1
  8. package/lib/components/Tab/useTab.js.map +1 -1
  9. package/lib/components/Tab/useTabAnimatedIndicator.js +27 -38
  10. package/lib/components/Tab/useTabAnimatedIndicator.js.map +1 -1
  11. package/lib/components/Tab/useTabStyles.js +334 -349
  12. package/lib/components/Tab/useTabStyles.js.map +1 -1
  13. package/lib/components/TabList/TabList.js +0 -1
  14. package/lib/components/TabList/TabList.js.map +1 -1
  15. package/lib/components/TabList/TabListContext.js +2 -2
  16. package/lib/components/TabList/TabListContext.js.map +1 -1
  17. package/lib/components/TabList/renderTabList.js +2 -2
  18. package/lib/components/TabList/renderTabList.js.map +1 -1
  19. package/lib/components/TabList/useTabList.js +2 -3
  20. package/lib/components/TabList/useTabList.js.map +1 -1
  21. package/lib/components/TabList/useTabListContextValues.js.map +1 -1
  22. package/lib/components/TabList/useTabListStyles.js +13 -16
  23. package/lib/components/TabList/useTabListStyles.js.map +1 -1
  24. package/lib/index.js.map +1 -1
  25. package/lib-commonjs/Tab.js +0 -2
  26. package/lib-commonjs/Tab.js.map +1 -1
  27. package/lib-commonjs/TabList.js +0 -2
  28. package/lib-commonjs/TabList.js.map +1 -1
  29. package/lib-commonjs/components/Tab/Tab.js +0 -6
  30. package/lib-commonjs/components/Tab/Tab.js.map +1 -1
  31. package/lib-commonjs/components/Tab/Tab.types.js.map +1 -1
  32. package/lib-commonjs/components/Tab/index.js +0 -7
  33. package/lib-commonjs/components/Tab/index.js.map +1 -1
  34. package/lib-commonjs/components/Tab/renderTab.js +8 -9
  35. package/lib-commonjs/components/Tab/renderTab.js.map +1 -1
  36. package/lib-commonjs/components/Tab/useTab.js +0 -7
  37. package/lib-commonjs/components/Tab/useTab.js.map +1 -1
  38. package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js +27 -45
  39. package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js.map +1 -1
  40. package/lib-commonjs/components/Tab/useTabStyles.js +334 -355
  41. package/lib-commonjs/components/Tab/useTabStyles.js.map +1 -1
  42. package/lib-commonjs/components/TabList/TabList.js +0 -7
  43. package/lib-commonjs/components/TabList/TabList.js.map +1 -1
  44. package/lib-commonjs/components/TabList/TabList.types.js.map +1 -1
  45. package/lib-commonjs/components/TabList/TabListContext.js +2 -4
  46. package/lib-commonjs/components/TabList/TabListContext.js.map +1 -1
  47. package/lib-commonjs/components/TabList/index.js +0 -6
  48. package/lib-commonjs/components/TabList/index.js.map +1 -1
  49. package/lib-commonjs/components/TabList/renderTabList.js +2 -7
  50. package/lib-commonjs/components/TabList/renderTabList.js.map +1 -1
  51. package/lib-commonjs/components/TabList/useTabList.js +2 -8
  52. package/lib-commonjs/components/TabList/useTabList.js.map +1 -1
  53. package/lib-commonjs/components/TabList/useTabListContextValues.js +0 -2
  54. package/lib-commonjs/components/TabList/useTabListContextValues.js.map +1 -1
  55. package/lib-commonjs/components/TabList/useTabListStyles.js +13 -19
  56. package/lib-commonjs/components/TabList/useTabListStyles.js.map +1 -1
  57. package/lib-commonjs/index.js +0 -4
  58. package/lib-commonjs/index.js.map +1 -1
  59. package/package.json +7 -7
@@ -4,55 +4,46 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useTabAnimatedIndicatorStyles_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_1 = /*#__PURE__*/require("@griffel/react");
11
-
12
9
  const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-selector");
13
-
14
10
  const TabListContext_1 = /*#__PURE__*/require("../TabList/TabListContext");
15
-
16
- const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme"); // eslint-disable-next-line @typescript-eslint/naming-convention
17
-
18
-
11
+ const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
19
13
  const tabIndicatorCssVars_unstable = {
20
14
  offsetVar: '--fui-Tab__indicator--offset',
21
15
  scaleVar: '--fui-Tab__indicator--scale'
22
16
  };
23
-
24
17
  const useActiveIndicatorStyles = /*#__PURE__*/react_1.__styles({
25
- "base": {
26
- "B68tc82": "f1mtd64y",
27
- "Bmxbyg5": "f1y7q3j9"
18
+ base: {
19
+ B68tc82: "f1mtd64y",
20
+ Bmxbyg5: "f1y7q3j9"
28
21
  },
29
- "animated": {
30
- "Ba2ppi3": "fhwpy7i",
31
- "F2fol1": "f6zz20j",
32
- "B1dyfl9": "f1ai4sc1",
33
- "B0vmy72": "f9qxlq5",
34
- "u9bimw": "f1aql376"
22
+ animated: {
23
+ Ba2ppi3: "fhwpy7i",
24
+ F2fol1: "f6zz20j",
25
+ B1dyfl9: "f1ai4sc1",
26
+ B0vmy72: "f9qxlq5",
27
+ u9bimw: "f1aql376"
35
28
  },
36
- "horizontal": {
37
- "sjv3b2": ["fug4aj8", "f1i5xzg7"],
38
- "b1kco5": "f1q7ujh"
29
+ horizontal: {
30
+ sjv3b2: ["fug4aj8", "f1i5xzg7"],
31
+ b1kco5: "f1q7ujh"
39
32
  },
40
- "vertical": {
41
- "sjv3b2": "f1hqboyk",
42
- "b1kco5": "f1dxupa6"
33
+ vertical: {
34
+ sjv3b2: "f1hqboyk",
35
+ b1kco5: "f1dxupa6"
43
36
  }
44
37
  }, {
45
- "d": [".f1mtd64y{overflow-x:visible;}", ".f1y7q3j9{overflow-y:visible;}", ".fhwpy7i::after{transition-property:transform;}", ".f6zz20j::after{transition-duration:var(--durationSlow);}", ".f1ai4sc1::after{transition-timing-function:var(--curveDecelerateMax);}", ".fug4aj8::after{transform-origin:left;}", ".f1i5xzg7::after{transform-origin:right;}", ".f1q7ujh::after{-webkit-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));-moz-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));-ms-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));}", ".f1hqboyk::after{transform-origin:top;}", ".f1dxupa6::after{-webkit-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));-moz-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));-ms-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));}"],
46
- "m": [["@media (prefers-reduced-motion: reduce){.f9qxlq5::after{transition-property:none;}}", {
47
- "m": "(prefers-reduced-motion: reduce)"
38
+ d: [".f1mtd64y{overflow-x:visible;}", ".f1y7q3j9{overflow-y:visible;}", ".fhwpy7i::after{transition-property:transform;}", ".f6zz20j::after{transition-duration:var(--durationSlow);}", ".f1ai4sc1::after{transition-timing-function:var(--curveDecelerateMax);}", ".fug4aj8::after{transform-origin:left;}", ".f1i5xzg7::after{transform-origin:right;}", ".f1q7ujh::after{-webkit-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));-moz-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));-ms-transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));transform:translateX(var(--fui-Tab__indicator--offset)) scaleX(var(--fui-Tab__indicator--scale));}", ".f1hqboyk::after{transform-origin:top;}", ".f1dxupa6::after{-webkit-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));-moz-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));-ms-transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));transform:translateY(var(--fui-Tab__indicator--offset)) scaleY(var(--fui-Tab__indicator--scale));}"],
39
+ m: [["@media (prefers-reduced-motion: reduce){.f9qxlq5::after{transition-property:none;}}", {
40
+ m: "(prefers-reduced-motion: reduce)"
48
41
  }], ["@media (prefers-reduced-motion: reduce){.f1aql376::after{transition-duration:0.01ms;}}", {
49
- "m": "(prefers-reduced-motion: reduce)"
42
+ m: "(prefers-reduced-motion: reduce)"
50
43
  }]]
51
44
  });
52
-
53
45
  const calculateTabRect = element => {
54
46
  var _a;
55
-
56
47
  if (element) {
57
48
  const parentRect = ((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || {
58
49
  x: 0,
@@ -68,21 +59,16 @@ const calculateTabRect = element => {
68
59
  height: tabRect.height
69
60
  };
70
61
  }
71
-
72
62
  return undefined;
73
63
  };
74
-
75
64
  const getRegisteredTabRect = (registeredTabs, value) => {
76
65
  var _a;
77
-
78
66
  const element = value !== undefined && value !== null ? (_a = registeredTabs[JSON.stringify(value)]) === null || _a === void 0 ? void 0 : _a.ref.current : undefined;
79
67
  return element ? calculateTabRect(element) : undefined;
80
68
  };
81
69
  /**
82
70
  * Adds additional styling to the active tab selection indicator to create a sliding animation.
83
71
  */
84
-
85
-
86
72
  const useTabAnimatedIndicatorStyles_unstable = state => {
87
73
  const {
88
74
  disabled,
@@ -104,7 +90,6 @@ const useTabAnimatedIndicatorStyles_unstable = state => {
104
90
  });
105
91
  }
106
92
  }, [lastAnimatedFrom]);
107
-
108
93
  if (selected) {
109
94
  const {
110
95
  previousSelectedValue,
@@ -113,7 +98,6 @@ const useTabAnimatedIndicatorStyles_unstable = state => {
113
98
  } = getRegisteredTabs();
114
99
  const previousSelectedTabRect = getRegisteredTabRect(registeredTabs, previousSelectedValue);
115
100
  const selectedTabRect = getRegisteredTabRect(registeredTabs, selectedValue);
116
-
117
101
  if (selectedTabRect && previousSelectedTabRect && previousSelectedValue && lastAnimatedFrom !== previousSelectedValue) {
118
102
  const offset = vertical ? previousSelectedTabRect.y - selectedTabRect.y : previousSelectedTabRect.x - selectedTabRect.x;
119
103
  const scale = vertical ? previousSelectedTabRect.height / selectedTabRect.height : previousSelectedTabRect.width / selectedTabRect.width;
@@ -127,26 +111,24 @@ const useTabAnimatedIndicatorStyles_unstable = state => {
127
111
  // need to clear the last animated from so that if this tab is selected again
128
112
  // from the same previous tab as last time, that animation still happens.
129
113
  setLastAnimatedFrom(undefined);
130
- } // do not apply any animation if the tab is disabled
131
-
132
-
114
+ }
115
+ // do not apply any animation if the tab is disabled
133
116
  if (disabled) {
134
117
  return state;
135
- } // the animation should only happen as the selection indicator returns to its
118
+ }
119
+ // the animation should only happen as the selection indicator returns to its
136
120
  // original position and not when set at the previous tabs position.
137
-
138
-
139
121
  const animating = animationValues.offset === 0 && animationValues.scale === 1;
140
122
  state.root.className = react_1.mergeClasses(state.root.className, selected && activeIndicatorStyles.base, selected && animating && activeIndicatorStyles.animated, selected && (vertical ? activeIndicatorStyles.vertical : activeIndicatorStyles.horizontal));
141
123
  const rootCssVars = {
142
124
  [tabIndicatorCssVars_unstable.offsetVar]: `${animationValues.offset}px`,
143
125
  [tabIndicatorCssVars_unstable.scaleVar]: `${animationValues.scale}`
144
126
  };
145
- state.root.style = { ...rootCssVars,
127
+ state.root.style = {
128
+ ...rootCssVars,
146
129
  ...state.root.style
147
130
  };
148
131
  return state;
149
132
  };
150
-
151
133
  exports.useTabAnimatedIndicatorStyles_unstable = useTabAnimatedIndicatorStyles_unstable;
152
134
  //# sourceMappingURL=useTabAnimatedIndicator.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-tabs/src/components/Tab/useTabAnimatedIndicator.ts"],"names":[],"mappings":";;;;;;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AF/C,CAApB;EAKA,KAAK,CAAC,IAAN,CAAW,KAAX,GAAmB,EACjB,GAAG,WADc;IAEjB,GAAG,KAAK,CAAC,IAAN,CAAW;EAFG,CAAnB;EAKA,OAAO,KAAP;AACD,CArEM;;AAAM,OAAA,CAAA,sCAAA,GAAsC,sCAAtC","sourcesContent":["import * as React from 'react';\nimport type { TabState, TabValue } from './Tab.types';\n\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { TabListContext } from '../TabList/TabListContext';\nimport { TabRegisterData } from '../TabList/TabList.types';\nimport { tokens } from '@fluentui/react-theme';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst tabIndicatorCssVars_unstable = {\n offsetVar: '--fui-Tab__indicator--offset',\n scaleVar: '--fui-Tab__indicator--scale',\n};\n\nconst useActiveIndicatorStyles = makeStyles({\n base: {\n // overflow is required to allow the selection indicator to animate outside the tab area.\n ...shorthands.overflow('visible'),\n },\n animated: {\n '::after': {\n transitionProperty: 'transform',\n transitionDuration: `${tokens.durationSlow}`,\n transitionTimingFunction: `${tokens.curveDecelerateMax}`,\n },\n '@media (prefers-reduced-motion: reduce)': {\n '::after': {\n transitionProperty: 'none',\n transitionDuration: '0.01ms',\n },\n },\n },\n horizontal: {\n '::after': {\n transformOrigin: 'left',\n transform: `translateX(var(${tabIndicatorCssVars_unstable.offsetVar}))\n scaleX(var(${tabIndicatorCssVars_unstable.scaleVar}))`,\n },\n },\n vertical: {\n '::after': {\n transformOrigin: 'top',\n transform: `translateY(var(${tabIndicatorCssVars_unstable.offsetVar}))\n scaleY(var(${tabIndicatorCssVars_unstable.scaleVar}))`,\n },\n },\n});\n\nconst calculateTabRect = (element: HTMLElement) => {\n if (element) {\n const parentRect = element.parentElement?.getBoundingClientRect() || { x: 0, y: 0, width: 0, height: 0 };\n const tabRect = element.getBoundingClientRect();\n\n return {\n x: tabRect.x - parentRect.x,\n y: tabRect.y - parentRect.y,\n width: tabRect.width,\n height: tabRect.height,\n };\n }\n return undefined;\n};\n\nconst getRegisteredTabRect = (registeredTabs: Record<string, TabRegisterData>, value?: TabValue) => {\n const element =\n value !== undefined && value !== null ? registeredTabs[JSON.stringify(value)]?.ref.current : undefined;\n return element ? calculateTabRect(element) : undefined;\n};\n\n/**\n * Adds additional styling to the active tab selection indicator to create a sliding animation.\n */\nexport const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabState => {\n const { disabled, selected, vertical } = state;\n\n const activeIndicatorStyles = useActiveIndicatorStyles();\n const [lastAnimatedFrom, setLastAnimatedFrom] = React.useState<TabValue>();\n const [animationValues, setAnimationValues] = React.useState({ offset: 0, scale: 1 });\n const getRegisteredTabs = useContextSelector(TabListContext, ctx => ctx.getRegisteredTabs);\n\n React.useEffect(() => {\n if (lastAnimatedFrom) {\n setAnimationValues({ offset: 0, scale: 1 });\n }\n }, [lastAnimatedFrom]);\n\n if (selected) {\n const { previousSelectedValue, selectedValue, registeredTabs } = getRegisteredTabs();\n const previousSelectedTabRect = getRegisteredTabRect(registeredTabs, previousSelectedValue);\n const selectedTabRect = getRegisteredTabRect(registeredTabs, selectedValue);\n\n if (\n selectedTabRect &&\n previousSelectedTabRect &&\n previousSelectedValue &&\n lastAnimatedFrom !== previousSelectedValue\n ) {\n const offset = vertical\n ? previousSelectedTabRect.y - selectedTabRect.y\n : previousSelectedTabRect.x - selectedTabRect.x;\n\n const scale = vertical\n ? previousSelectedTabRect.height / selectedTabRect.height\n : previousSelectedTabRect.width / selectedTabRect.width;\n\n setAnimationValues({ offset, scale });\n setLastAnimatedFrom(previousSelectedValue);\n }\n } else if (lastAnimatedFrom) {\n // need to clear the last animated from so that if this tab is selected again\n // from the same previous tab as last time, that animation still happens.\n setLastAnimatedFrom(undefined);\n }\n\n // do not apply any animation if the tab is disabled\n if (disabled) {\n return state;\n }\n\n // the animation should only happen as the selection indicator returns to its\n // original position and not when set at the previous tabs position.\n const animating = animationValues.offset === 0 && animationValues.scale === 1;\n\n state.root.className = mergeClasses(\n state.root.className,\n selected && activeIndicatorStyles.base,\n selected && animating && activeIndicatorStyles.animated,\n selected && (vertical ? activeIndicatorStyles.vertical : activeIndicatorStyles.horizontal),\n );\n\n const rootCssVars = {\n [tabIndicatorCssVars_unstable.offsetVar]: `${animationValues.offset}px`,\n [tabIndicatorCssVars_unstable.scaleVar]: `${animationValues.scale}`,\n };\n\n state.root.style = {\n ...rootCssVars,\n ...state.root.style,\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AAGA;AACA;AACA;AAEA;AAEA;AACA,MAAMA,4BAA4B,GAAG;EACnCC,SAAS,EAAE,8BAA8B;EACzCC,QAAQ,EAAE;CACX;AAED,MAAMC,wBAAwB,gBAAGC,gBAAU;EAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;EAAA;AAAA;EAAA;EAAA;IAAA;EAAA;IAAA;EAAA;AAAA,EAgCzC;AAEF,MAAMC,gBAAgB,GAAIC,OAAoB,IAAI;;EAChD,IAAIA,OAAO,EAAE;IACX,MAAMC,UAAU,GAAG,cAAO,CAACC,aAAa,0CAAEC,qBAAqB,EAAE,KAAI;MAAEC,CAAC,EAAE,CAAC;MAAEC,CAAC,EAAE,CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAC,CAAE;IACxG,MAAMC,OAAO,GAAGR,OAAO,CAACG,qBAAqB,EAAE;IAE/C,OAAO;MACLC,CAAC,EAAEI,OAAO,CAACJ,CAAC,GAAGH,UAAU,CAACG,CAAC;MAC3BC,CAAC,EAAEG,OAAO,CAACH,CAAC,GAAGJ,UAAU,CAACI,CAAC;MAC3BC,KAAK,EAAEE,OAAO,CAACF,KAAK;MACpBC,MAAM,EAAEC,OAAO,CAACD;KACjB;;EAEH,OAAOE,SAAS;AAClB,CAAC;AAED,MAAMC,o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uB,IAAI,CAACM,KAAK,GAAG;IACjB,GAAGD,WAAW;IACd,GAAG5B,KAAK,CAACuB,IAAI,CAACM;GACf;EAED,OAAO7B,KAAK;AACd,CAAC;AArEY8B,8CAAsC","names":["tabIndicatorCssVars_unstable","offsetVar","scaleVar","useActiveIndicatorStyles","react_1","calculateTabRect","element","parentRect","parentElement","getBoundingClientRect","x","y","width","height","tabRect","undefined","getRegisteredTabRect","registeredTabs","value","JSON","stringify","ref","current","useTabAnimatedIndicatorStyles_unstable","state","disabled","selected","vertical","activeIndicatorStyles","lastAnimatedFrom","setLastAnimatedFrom","React","useState","animationValues","setAnimationValues","offset","scale","getRegisteredTabs","react_context_selector_1","TabListContext_1","ctx","useEffect","previousSelectedValue","selectedValue","previousSelectedTabRect","selectedTabRect","animating","root","className","base","animated","horizontal","rootCssVars","style","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-tabs/src/components/Tab/useTabAnimatedIndicator.ts"],"sourcesContent":["import * as React from 'react';\nimport type { TabState, TabValue } from './Tab.types';\n\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { TabListContext } from '../TabList/TabListContext';\nimport { TabRegisterData } from '../TabList/TabList.types';\nimport { tokens } from '@fluentui/react-theme';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst tabIndicatorCssVars_unstable = {\n offsetVar: '--fui-Tab__indicator--offset',\n scaleVar: '--fui-Tab__indicator--scale',\n};\n\nconst useActiveIndicatorStyles = makeStyles({\n base: {\n // overflow is required to allow the selection indicator to animate outside the tab area.\n ...shorthands.overflow('visible'),\n },\n animated: {\n '::after': {\n transitionProperty: 'transform',\n transitionDuration: `${tokens.durationSlow}`,\n transitionTimingFunction: `${tokens.curveDecelerateMax}`,\n },\n '@media (prefers-reduced-motion: reduce)': {\n '::after': {\n transitionProperty: 'none',\n transitionDuration: '0.01ms',\n },\n },\n },\n horizontal: {\n '::after': {\n transformOrigin: 'left',\n transform: `translateX(var(${tabIndicatorCssVars_unstable.offsetVar}))\n scaleX(var(${tabIndicatorCssVars_unstable.scaleVar}))`,\n },\n },\n vertical: {\n '::after': {\n transformOrigin: 'top',\n transform: `translateY(var(${tabIndicatorCssVars_unstable.offsetVar}))\n scaleY(var(${tabIndicatorCssVars_unstable.scaleVar}))`,\n },\n },\n});\n\nconst calculateTabRect = (element: HTMLElement) => {\n if (element) {\n const parentRect = element.parentElement?.getBoundingClientRect() || { x: 0, y: 0, width: 0, height: 0 };\n const tabRect = element.getBoundingClientRect();\n\n return {\n x: tabRect.x - parentRect.x,\n y: tabRect.y - parentRect.y,\n width: tabRect.width,\n height: tabRect.height,\n };\n }\n return undefined;\n};\n\nconst getRegisteredTabRect = (registeredTabs: Record<string, TabRegisterData>, value?: TabValue) => {\n const element =\n value !== undefined && value !== null ? registeredTabs[JSON.stringify(value)]?.ref.current : undefined;\n return element ? calculateTabRect(element) : undefined;\n};\n\n/**\n * Adds additional styling to the active tab selection indicator to create a sliding animation.\n */\nexport const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabState => {\n const { disabled, selected, vertical } = state;\n\n const activeIndicatorStyles = useActiveIndicatorStyles();\n const [lastAnimatedFrom, setLastAnimatedFrom] = React.useState<TabValue>();\n const [animationValues, setAnimationValues] = React.useState({ offset: 0, scale: 1 });\n const getRegisteredTabs = useContextSelector(TabListContext, ctx => ctx.getRegisteredTabs);\n\n React.useEffect(() => {\n if (lastAnimatedFrom) {\n setAnimationValues({ offset: 0, scale: 1 });\n }\n }, [lastAnimatedFrom]);\n\n if (selected) {\n const { previousSelectedValue, selectedValue, registeredTabs } = getRegisteredTabs();\n const previousSelectedTabRect = getRegisteredTabRect(registeredTabs, previousSelectedValue);\n const selectedTabRect = getRegisteredTabRect(registeredTabs, selectedValue);\n\n if (\n selectedTabRect &&\n previousSelectedTabRect &&\n previousSelectedValue &&\n lastAnimatedFrom !== previousSelectedValue\n ) {\n const offset = vertical\n ? previousSelectedTabRect.y - selectedTabRect.y\n : previousSelectedTabRect.x - selectedTabRect.x;\n\n const scale = vertical\n ? previousSelectedTabRect.height / selectedTabRect.height\n : previousSelectedTabRect.width / selectedTabRect.width;\n\n setAnimationValues({ offset, scale });\n setLastAnimatedFrom(previousSelectedValue);\n }\n } else if (lastAnimatedFrom) {\n // need to clear the last animated from so that if this tab is selected again\n // from the same previous tab as last time, that animation still happens.\n setLastAnimatedFrom(undefined);\n }\n\n // do not apply any animation if the tab is disabled\n if (disabled) {\n return state;\n }\n\n // the animation should only happen as the selection indicator returns to its\n // original position and not when set at the previous tabs position.\n const animating = animationValues.offset === 0 && animationValues.scale === 1;\n\n state.root.className = mergeClasses(\n state.root.className,\n selected && activeIndicatorStyles.base,\n selected && animating && activeIndicatorStyles.animated,\n selected && (vertical ? activeIndicatorStyles.vertical : activeIndicatorStyles.horizontal),\n );\n\n const rootCssVars = {\n [tabIndicatorCssVars_unstable.offsetVar]: `${animationValues.offset}px`,\n [tabIndicatorCssVars_unstable.scaleVar]: `${animationValues.scale}`,\n };\n\n state.root.style = {\n ...rootCssVars,\n ...state.root.style,\n };\n\n return state;\n};\n"]}