@fluentui/react-tabs 9.0.0-beta.8 → 9.0.0-beta.9
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 +108 -1
- package/CHANGELOG.md +24 -2
- package/dist/react-tabs.d.ts +48 -36
- package/lib/components/Tab/Tab.types.d.ts +14 -5
- package/lib/components/Tab/Tab.types.js.map +1 -1
- package/lib/components/Tab/index.d.ts +1 -0
- package/lib/components/Tab/index.js +1 -0
- package/lib/components/Tab/index.js.map +1 -1
- package/lib/components/Tab/renderTab.js +1 -2
- package/lib/components/Tab/renderTab.js.map +1 -1
- package/lib/components/Tab/useTab.js +25 -29
- package/lib/components/Tab/useTab.js.map +1 -1
- package/lib/components/Tab/useTabAnimatedIndicator.d.ts +5 -0
- package/lib/components/Tab/useTabAnimatedIndicator.js +134 -0
- package/lib/components/Tab/useTabAnimatedIndicator.js.map +1 -0
- package/lib/components/Tab/useTabStyles.d.ts +4 -2
- package/lib/components/Tab/useTabStyles.js +280 -84
- package/lib/components/Tab/useTabStyles.js.map +1 -1
- package/lib/components/TabList/TabList.types.d.ts +21 -16
- package/lib/components/TabList/TabList.types.js.map +1 -1
- package/lib/components/TabList/TabListContext.js +6 -0
- package/lib/components/TabList/TabListContext.js.map +1 -1
- package/lib/components/TabList/renderTabList.js +0 -1
- package/lib/components/TabList/renderTabList.js.map +1 -1
- package/lib/components/TabList/useTabList.js +26 -51
- package/lib/components/TabList/useTabList.js.map +1 -1
- package/lib/components/TabList/useTabListContextValues.js +4 -0
- package/lib/components/TabList/useTabListContextValues.js.map +1 -1
- package/lib/components/TabList/useTabListStyles.d.ts +4 -5
- package/lib/components/TabList/useTabListStyles.js +8 -90
- package/lib/components/TabList/useTabListStyles.js.map +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/tab.constants.d.ts +59 -12
- package/lib/tab.constants.js +64 -13
- package/lib/tab.constants.js.map +1 -1
- package/lib-commonjs/components/Tab/Tab.types.d.ts +14 -5
- package/lib-commonjs/components/Tab/index.d.ts +1 -0
- package/lib-commonjs/components/Tab/index.js +2 -0
- package/lib-commonjs/components/Tab/index.js.map +1 -1
- package/lib-commonjs/components/Tab/renderTab.js +1 -2
- package/lib-commonjs/components/Tab/renderTab.js.map +1 -1
- package/lib-commonjs/components/Tab/useTab.js +25 -29
- package/lib-commonjs/components/Tab/useTab.js.map +1 -1
- package/lib-commonjs/components/Tab/useTabAnimatedIndicator.d.ts +5 -0
- package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js +148 -0
- package/lib-commonjs/components/Tab/useTabAnimatedIndicator.js.map +1 -0
- package/lib-commonjs/components/Tab/useTabStyles.d.ts +4 -2
- package/lib-commonjs/components/Tab/useTabStyles.js +281 -84
- package/lib-commonjs/components/Tab/useTabStyles.js.map +1 -1
- package/lib-commonjs/components/TabList/TabList.types.d.ts +21 -16
- package/lib-commonjs/components/TabList/TabListContext.js +6 -0
- package/lib-commonjs/components/TabList/TabListContext.js.map +1 -1
- package/lib-commonjs/components/TabList/renderTabList.js +0 -1
- package/lib-commonjs/components/TabList/renderTabList.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabList.js +25 -50
- package/lib-commonjs/components/TabList/useTabList.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabListContextValues.js +4 -0
- package/lib-commonjs/components/TabList/useTabListContextValues.js.map +1 -1
- package/lib-commonjs/components/TabList/useTabListStyles.d.ts +4 -5
- package/lib-commonjs/components/TabList/useTabListStyles.js +7 -92
- package/lib-commonjs/components/TabList/useTabListStyles.js.map +1 -1
- package/lib-commonjs/index.d.ts +4 -2
- package/lib-commonjs/index.js +76 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/tab.constants.d.ts +59 -12
- package/lib-commonjs/tab.constants.js +66 -14
- package/lib-commonjs/tab.constants.js.map +1 -1
- package/package.json +9 -18
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
3
|
+
import { pendingAnimationDurationTokens, pendingAnimationEasingTokens } from '../../tab.constants';
|
|
4
|
+
import { useContextSelector } from '@fluentui/react-context-selector';
|
|
5
|
+
import { TabListContext } from '../TabList/TabListContext'; // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
6
|
+
|
|
7
|
+
const tabIndicatorCssVars_unstable = {
|
|
8
|
+
offsetVar: '--fui-Tab__indicator--offset',
|
|
9
|
+
scaleVar: '--fui-Tab__indicator--scale'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const useActiveIndicatorStyles = /*#__PURE__*/__styles({
|
|
13
|
+
"base": {
|
|
14
|
+
"B68tc82": "f1mtd64y",
|
|
15
|
+
"Bmxbyg5": "f1y7q3j9"
|
|
16
|
+
},
|
|
17
|
+
"animated": {
|
|
18
|
+
"wbfbqe": "fopw4to",
|
|
19
|
+
"mafdb0": "f8wx3i3",
|
|
20
|
+
"Jgwf15": "fgw312z",
|
|
21
|
+
"Bh4j9q1": "f1cif4e6",
|
|
22
|
+
"Gk6w4d": "fa42t5a"
|
|
23
|
+
},
|
|
24
|
+
"horizontal": {
|
|
25
|
+
"Blx6ldh": ["f1g89gis", "fcjnwxz"],
|
|
26
|
+
"xn0juu": "f7m34ad"
|
|
27
|
+
},
|
|
28
|
+
"vertical": {
|
|
29
|
+
"Blx6ldh": "fqfgdei",
|
|
30
|
+
"xn0juu": "fwvsziq"
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
"d": [".f1mtd64y{overflow-x:visible;}", ".f1y7q3j9{overflow-y:visible;}", ".fopw4to:after{transition-property:transform;}", ".f8wx3i3:after{transition-duration:300ms;}", ".fgw312z:after{transition-timing-function:cubic-bezier(0,0,0,1);}", ".f1g89gis:after{transform-origin:left;}", ".fcjnwxz:after{transform-origin:right;}", ".f7m34ad: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));}", ".fqfgdei:after{transform-origin:top;}", ".fwvsziq: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));}"],
|
|
34
|
+
"t": ["@media (prefers-reduced-motion: reduce){.f1cif4e6:after{transition-property:none;}}", "@media (prefers-reduced-motion: reduce){.fa42t5a:after{transition-duration:0.01ms;}}"]
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const calculateTabRect = element => {
|
|
38
|
+
var _a;
|
|
39
|
+
|
|
40
|
+
if (element) {
|
|
41
|
+
const parentRect = ((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) || {
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0,
|
|
44
|
+
width: 0,
|
|
45
|
+
height: 0
|
|
46
|
+
};
|
|
47
|
+
const tabRect = element.getBoundingClientRect();
|
|
48
|
+
return {
|
|
49
|
+
x: tabRect.x - parentRect.x,
|
|
50
|
+
y: tabRect.y - parentRect.y,
|
|
51
|
+
width: tabRect.width,
|
|
52
|
+
height: tabRect.height
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getRegisteredTabRect = (registeredTabs, value) => {
|
|
60
|
+
var _a;
|
|
61
|
+
|
|
62
|
+
const element = value ? (_a = registeredTabs[JSON.stringify(value)]) === null || _a === void 0 ? void 0 : _a.ref.current : undefined;
|
|
63
|
+
return element ? calculateTabRect(element) : undefined;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Adds additional styling to the active tab selection indicator to create a sliding animation.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export const useTabAnimatedIndicatorStyles_unstable = state => {
|
|
71
|
+
const {
|
|
72
|
+
disabled,
|
|
73
|
+
selected,
|
|
74
|
+
vertical
|
|
75
|
+
} = state;
|
|
76
|
+
const activeIndicatorStyles = useActiveIndicatorStyles();
|
|
77
|
+
const [lastAnimatedFrom, setLastAnimatedFrom] = React.useState();
|
|
78
|
+
const [animationValues, setAnimationValues] = React.useState({
|
|
79
|
+
offset: 0,
|
|
80
|
+
scale: 1
|
|
81
|
+
});
|
|
82
|
+
const getRegisteredTabs = useContextSelector(TabListContext, ctx => ctx.getRegisteredTabs);
|
|
83
|
+
React.useEffect(() => {
|
|
84
|
+
if (lastAnimatedFrom) {
|
|
85
|
+
setAnimationValues({
|
|
86
|
+
offset: 0,
|
|
87
|
+
scale: 1
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}, [lastAnimatedFrom]);
|
|
91
|
+
|
|
92
|
+
if (selected) {
|
|
93
|
+
const {
|
|
94
|
+
previousSelectedValue,
|
|
95
|
+
selectedValue,
|
|
96
|
+
registeredTabs
|
|
97
|
+
} = getRegisteredTabs();
|
|
98
|
+
const previousSelectedTabRect = getRegisteredTabRect(registeredTabs, previousSelectedValue);
|
|
99
|
+
const selectedTabRect = getRegisteredTabRect(registeredTabs, selectedValue);
|
|
100
|
+
|
|
101
|
+
if (selectedTabRect && previousSelectedTabRect && previousSelectedValue && lastAnimatedFrom !== previousSelectedValue) {
|
|
102
|
+
const offset = vertical ? previousSelectedTabRect.y - selectedTabRect.y : previousSelectedTabRect.x - selectedTabRect.x;
|
|
103
|
+
const scale = vertical ? previousSelectedTabRect.height / selectedTabRect.height : previousSelectedTabRect.width / selectedTabRect.width;
|
|
104
|
+
setAnimationValues({
|
|
105
|
+
offset,
|
|
106
|
+
scale
|
|
107
|
+
});
|
|
108
|
+
setLastAnimatedFrom(previousSelectedValue);
|
|
109
|
+
}
|
|
110
|
+
} else if (lastAnimatedFrom) {
|
|
111
|
+
// need to clear the last animated from so that if this tab is selected again
|
|
112
|
+
// from the same previous tab as last time, that animation still happens.
|
|
113
|
+
setLastAnimatedFrom(undefined);
|
|
114
|
+
} // do not apply any animation if the tab is disabled
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if (disabled) {
|
|
118
|
+
return state;
|
|
119
|
+
} // the animation should only happen as the selection indicator returns to its
|
|
120
|
+
// original position and not when set at the previous tabs position.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
const animating = animationValues.offset === 0 && animationValues.scale === 1;
|
|
124
|
+
state.root.className = mergeClasses(state.root.className, selected && activeIndicatorStyles.base, selected && animating && activeIndicatorStyles.animated, selected && (vertical ? activeIndicatorStyles.vertical : activeIndicatorStyles.horizontal));
|
|
125
|
+
const rootCssVars = {
|
|
126
|
+
[tabIndicatorCssVars_unstable.offsetVar]: `${animationValues.offset}px`,
|
|
127
|
+
[tabIndicatorCssVars_unstable.scaleVar]: `${animationValues.scale}`
|
|
128
|
+
};
|
|
129
|
+
state.root.style = { ...rootCssVars,
|
|
130
|
+
...state.root.style
|
|
131
|
+
};
|
|
132
|
+
return state;
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=useTabAnimatedIndicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/Tab/useTabAnimatedIndicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AACA,SAAS,8BAAT,EAAyC,4BAAzC,QAA6E,qBAA7E;AACA,SAAS,kBAAT,QAAmC,kCAAnC;AACA,SAAS,cAAT,Q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type { TabState, TabValue } from './Tab.types';\n\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport { pendingAnimationDurationTokens, pendingAnimationEasingTokens } from '../../tab.constants';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { TabListContext } from '../TabList/TabListContext';\nimport { TabRegisterData } from '../TabList/TabList.types';\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: `${pendingAnimationDurationTokens.slow}`,\n transitionTimingFunction: `${pendingAnimationEasingTokens.declerateMax}`,\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 = value ? 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,5 +1,7 @@
|
|
|
1
|
-
import type { TabState } from './Tab.types';
|
|
2
|
-
|
|
1
|
+
import type { TabSlots, TabState } from './Tab.types';
|
|
2
|
+
import { SlotClassNames } from '@fluentui/react-utilities';
|
|
3
|
+
export declare const tabClassNames: SlotClassNames<TabSlots>;
|
|
4
|
+
export declare const tabClassName: string;
|
|
3
5
|
/**
|
|
4
6
|
* Apply styling to the Tab slots based on the state
|
|
5
7
|
*/
|