@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.
- package/CHANGELOG.json +81 -1
- package/CHANGELOG.md +26 -2
- package/lib/components/Tab/Tab.js +0 -1
- package/lib/components/Tab/Tab.js.map +1 -1
- package/lib/components/Tab/renderTab.js +8 -5
- package/lib/components/Tab/renderTab.js.map +1 -1
- package/lib/components/Tab/useTab.js +0 -1
- package/lib/components/Tab/useTab.js.map +1 -1
- package/lib/components/Tab/useTabAnimatedIndicator.js +27 -38
- package/lib/components/Tab/useTabAnimatedIndicator.js.map +1 -1
- package/lib/components/Tab/useTabStyles.js +334 -349
- package/lib/components/Tab/useTabStyles.js.map +1 -1
- package/lib/components/TabList/TabList.js +0 -1
- package/lib/components/TabList/TabList.js.map +1 -1
- package/lib/components/TabList/TabListContext.js +2 -2
- package/lib/components/TabList/TabListContext.js.map +1 -1
- package/lib/components/TabList/renderTabList.js +2 -2
- package/lib/components/TabList/renderTabList.js.map +1 -1
- package/lib/components/TabList/useTabList.js +2 -3
- package/lib/components/TabList/useTabList.js.map +1 -1
- package/lib/components/TabList/useTabListContextValues.js.map +1 -1
- package/lib/components/TabList/useTabListStyles.js +13 -16
- package/lib/components/TabList/useTabListStyles.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Tab.js +0 -2
- package/lib-commonjs/Tab.js.map +1 -1
- package/lib-commonjs/TabList.js +0 -2
- package/lib-commonjs/TabList.js.map +1 -1
- package/lib-commonjs/components/Tab/Tab.js +0 -6
- package/lib-commonjs/components/Tab/Tab.js.map +1 -1
- package/lib-commonjs/components/Tab/Tab.types.js.map +1 -1
- package/lib-commonjs/components/Tab/index.js +0 -7
- package/lib-commonjs/components/Tab/index.js.map +1 -1
- package/lib-commonjs/components/Tab/renderTab.js +8 -9
- package/lib-commonjs/components/Tab/renderTab.js.map +1 -1
- package/lib-commonjs/components/Tab/useTab.js +0 -7
- package/lib-commonjs/components/Tab/useTab.js.map +1 -1
- package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js +27 -45
- package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js.map +1 -1
- package/lib-commonjs/components/Tab/useTabStyles.js +334 -355
- package/lib-commonjs/components/Tab/useTabStyles.js.map +1 -1
- package/lib-commonjs/components/TabList/TabList.js +0 -7
- package/lib-commonjs/components/TabList/TabList.js.map +1 -1
- package/lib-commonjs/components/TabList/TabList.types.js.map +1 -1
- package/lib-commonjs/components/TabList/TabListContext.js +2 -4
- package/lib-commonjs/components/TabList/TabListContext.js.map +1 -1
- package/lib-commonjs/components/TabList/index.js +0 -6
- package/lib-commonjs/components/TabList/index.js.map +1 -1
- package/lib-commonjs/components/TabList/renderTabList.js +2 -7
- package/lib-commonjs/components/TabList/renderTabList.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabList.js +2 -8
- package/lib-commonjs/components/TabList/useTabList.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabListContextValues.js +0 -2
- package/lib-commonjs/components/TabList/useTabListContextValues.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabListStyles.js +13 -19
- package/lib-commonjs/components/TabList/useTabListStyles.js.map +1 -1
- package/lib-commonjs/index.js +0 -4
- package/lib-commonjs/index.js.map +1 -1
- 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
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
base: {
|
|
19
|
+
B68tc82: "f1mtd64y",
|
|
20
|
+
Bmxbyg5: "f1y7q3j9"
|
|
28
21
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
animated: {
|
|
23
|
+
Ba2ppi3: "fhwpy7i",
|
|
24
|
+
F2fol1: "f6zz20j",
|
|
25
|
+
B1dyfl9: "f1ai4sc1",
|
|
26
|
+
B0vmy72: "f9qxlq5",
|
|
27
|
+
u9bimw: "f1aql376"
|
|
35
28
|
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
horizontal: {
|
|
30
|
+
sjv3b2: ["fug4aj8", "f1i5xzg7"],
|
|
31
|
+
b1kco5: "f1q7ujh"
|
|
39
32
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
vertical: {
|
|
34
|
+
sjv3b2: "f1hqboyk",
|
|
35
|
+
b1kco5: "f1dxupa6"
|
|
43
36
|
}
|
|
44
37
|
}, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
114
|
+
}
|
|
115
|
+
// do not apply any animation if the tab is disabled
|
|
133
116
|
if (disabled) {
|
|
134
117
|
return state;
|
|
135
|
-
}
|
|
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 = {
|
|
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,"
|
|
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,q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G5C,oBAAY,CACjCoB,KAAK,CAACuB,IAAI,CAACC,SAAS,EACpBtB,QAAQ,IAAIE,qBAAqB,CAACqB,IAAI,EACtCvB,QAAQ,IAAIoB,SAAS,IAAIlB,qBAAqB,CAACsB,QAAQ,EACvDxB,QAAQ,KAAKC,QAAQ,GAAGC,qBAAqB,CAACD,QAAQ,GAAGC,qBAAqB,CAACuB,UAAU,CAAC,CAC3F;EAED,MAAMC,WAAW,GAAG;IAClB,CAACpD,4BAA4B,CAACC,SAAS,GAAG,GAAGgC,eAAe,CAACE,MAAM,IAAI;IACvE,CAACnC,4BAA4B,CAACE,QAAQ,GAAG,GAAG+B,eAAe,CAACG,KAAK;GAClE;EAEDZ,KAAK,CAACuB,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"]}
|