@fluentui/react-tabs 9.0.0-beta.8 → 9.0.0-rc.3
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 +371 -1
- package/CHANGELOG.md +101 -4
- package/dist/{react-tabs.d.ts → index.d.ts} +73 -70
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/components/Tab/Tab.types.js.map +1 -1
- 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 +28 -29
- package/lib/components/Tab/useTab.js.map +1 -1
- package/lib/components/Tab/useTabAnimatedIndicator.js +134 -0
- package/lib/components/Tab/useTabAnimatedIndicator.js.map +1 -0
- package/lib/components/Tab/useTabStyles.js +220 -88
- package/lib/components/Tab/useTabStyles.js.map +1 -1
- 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 +28 -52
- 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.js +14 -91
- package/lib/components/TabList/useTabListStyles.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- 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 +28 -29
- package/lib-commonjs/components/Tab/useTab.js.map +1 -1
- 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.js +220 -88
- package/lib-commonjs/components/Tab/useTabStyles.js.map +1 -1
- 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 +27 -51
- 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.js +14 -94
- package/lib-commonjs/components/TabList/useTabListStyles.js.map +1 -1
- package/lib-commonjs/index.js +64 -3
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +12 -21
- package/lib/Tab.d.ts +0 -1
- package/lib/TabList.d.ts +0 -1
- package/lib/components/Tab/Tab.d.ts +0 -6
- package/lib/components/Tab/Tab.types.d.ts +0 -52
- package/lib/components/Tab/index.d.ts +0 -5
- package/lib/components/Tab/renderTab.d.ts +0 -5
- package/lib/components/Tab/useTab.d.ts +0 -12
- package/lib/components/Tab/useTabStyles.d.ts +0 -6
- package/lib/components/TabList/TabList.d.ts +0 -6
- package/lib/components/TabList/TabList.types.d.ts +0 -99
- package/lib/components/TabList/TabListContext.d.ts +0 -3
- package/lib/components/TabList/index.d.ts +0 -5
- package/lib/components/TabList/renderTabList.d.ts +0 -5
- package/lib/components/TabList/useTabList.d.ts +0 -12
- package/lib/components/TabList/useTabListContextValues.d.ts +0 -2
- package/lib/components/TabList/useTabListStyles.d.ts +0 -9
- package/lib/index.d.ts +0 -2
- package/lib/tab.constants.d.ts +0 -15
- package/lib/tab.constants.js +0 -17
- package/lib/tab.constants.js.map +0 -1
- package/lib-commonjs/Tab.d.ts +0 -1
- package/lib-commonjs/TabList.d.ts +0 -1
- package/lib-commonjs/components/Tab/Tab.d.ts +0 -6
- package/lib-commonjs/components/Tab/Tab.types.d.ts +0 -52
- package/lib-commonjs/components/Tab/index.d.ts +0 -5
- package/lib-commonjs/components/Tab/renderTab.d.ts +0 -5
- package/lib-commonjs/components/Tab/useTab.d.ts +0 -12
- package/lib-commonjs/components/Tab/useTabStyles.d.ts +0 -6
- package/lib-commonjs/components/TabList/TabList.d.ts +0 -6
- package/lib-commonjs/components/TabList/TabList.types.d.ts +0 -99
- package/lib-commonjs/components/TabList/TabListContext.d.ts +0 -3
- package/lib-commonjs/components/TabList/index.d.ts +0 -5
- package/lib-commonjs/components/TabList/renderTabList.d.ts +0 -5
- package/lib-commonjs/components/TabList/useTabList.d.ts +0 -12
- package/lib-commonjs/components/TabList/useTabListContextValues.d.ts +0 -2
- package/lib-commonjs/components/TabList/useTabListStyles.d.ts +0 -9
- package/lib-commonjs/index.d.ts +0 -2
- package/lib-commonjs/tab.constants.d.ts +0 -15
- package/lib-commonjs/tab.constants.js +0 -23
- package/lib-commonjs/tab.constants.js.map +0 -1
|
@@ -3,20 +3,9 @@ import type { ComponentState } from '@fluentui/react-utilities';
|
|
|
3
3
|
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
4
4
|
import * as React_2 from 'react';
|
|
5
5
|
import type { Slot } from '@fluentui/react-utilities';
|
|
6
|
+
import { SlotClassNames } from '@fluentui/react-utilities';
|
|
6
7
|
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
export declare const indicatorOffsetVar = "--selection-indicator-offset";
|
|
10
|
-
|
|
11
|
-
export declare type RegisterTabData = {
|
|
12
|
-
/**
|
|
13
|
-
* The value of the selected tab.
|
|
14
|
-
*/
|
|
15
|
-
value: TabValue;
|
|
16
|
-
ref: React_2.RefObject<HTMLElement>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export declare type RegisterTabEventHandler = (data: RegisterTabData) => void;
|
|
8
|
+
export declare type RegisterTabEventHandler = (data: TabRegisterData) => void;
|
|
20
9
|
|
|
21
10
|
/**
|
|
22
11
|
* Render the final JSX of Tab
|
|
@@ -44,33 +33,48 @@ export declare type SelectTabEventHandler = (event: SelectTabEvent, data: Select
|
|
|
44
33
|
*/
|
|
45
34
|
export declare const Tab: ForwardRefComponent<TabProps>;
|
|
46
35
|
|
|
47
|
-
export declare const
|
|
36
|
+
export declare const tabClassNames: SlotClassNames<TabSlots>;
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A tab list provides single selection from a set of tabs.
|
|
40
|
+
*/
|
|
41
|
+
export declare const TabList: ForwardRefComponent<TabListProps>;
|
|
42
|
+
|
|
43
|
+
export declare const tabListClassNames: SlotClassNames<TabListSlots>;
|
|
44
|
+
|
|
45
|
+
export declare type TabListContextValue = Pick<TabListProps, 'onTabSelect' | 'selectedValue'> & Required<Pick<TabListProps, 'appearance' | 'disabled' | 'size' | 'vertical'>> & {
|
|
46
|
+
/** A callback to allow a tab to register itself with the tab list. */
|
|
47
|
+
onRegister: RegisterTabEventHandler;
|
|
48
|
+
/** A callback to allow a tab to unregister itself with the tab list. */
|
|
49
|
+
onUnregister: RegisterTabEventHandler;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* A callback to allow a tab to select itself when pressed.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
onSelect: SelectTabEventHandler;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the registered tab data along with current and previous selected values.
|
|
56
|
+
*/
|
|
57
|
+
getRegisteredTabs: () => {
|
|
58
|
+
selectedValue?: TabValue;
|
|
59
|
+
previousSelectedValue?: TabValue;
|
|
60
|
+
registeredTabs: Record<string, TabRegisterData>;
|
|
61
|
+
};
|
|
54
62
|
};
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
|
-
*
|
|
65
|
+
* Context values used in rendering TabList.
|
|
58
66
|
*/
|
|
59
|
-
export declare type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
export declare type TabListContextValues = {
|
|
68
|
+
/**
|
|
69
|
+
* The context of the tab list available to each tab.
|
|
70
|
+
*/
|
|
71
|
+
tabList: TabListContextValue;
|
|
64
72
|
};
|
|
65
73
|
|
|
66
74
|
/**
|
|
67
|
-
*
|
|
75
|
+
* TabList Props
|
|
68
76
|
*/
|
|
69
|
-
export declare
|
|
70
|
-
|
|
71
|
-
export declare const tabListClassName = "fui-TabList";
|
|
72
|
-
|
|
73
|
-
declare type TabListCommons = {
|
|
77
|
+
export declare type TabListProps = ComponentProps<TabListSlots> & {
|
|
74
78
|
/**
|
|
75
79
|
* A tab list can supports 'transparent' and 'subtle' appearance.
|
|
76
80
|
*- 'subtle': Minimizes emphasis to blend into the background until hovered or focused.
|
|
@@ -79,6 +83,16 @@ declare type TabListCommons = {
|
|
|
79
83
|
* @default 'transparent'
|
|
80
84
|
*/
|
|
81
85
|
appearance?: 'transparent' | 'subtle';
|
|
86
|
+
/**
|
|
87
|
+
* The value of the tab to be selected by default.
|
|
88
|
+
* Typically useful when the selectedValue is uncontrolled.
|
|
89
|
+
*/
|
|
90
|
+
defaultSelectedValue?: TabValue;
|
|
91
|
+
/**
|
|
92
|
+
* A tab list can be set to disable interaction.
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
disabled?: boolean;
|
|
82
96
|
/**
|
|
83
97
|
* Raised when a tab is selected.
|
|
84
98
|
*/
|
|
@@ -100,64 +114,49 @@ declare type TabListCommons = {
|
|
|
100
114
|
vertical?: boolean;
|
|
101
115
|
};
|
|
102
116
|
|
|
103
|
-
export declare type
|
|
104
|
-
/** A callback to allow a tab to register itself with the tab list. */
|
|
105
|
-
onRegister: RegisterTabEventHandler;
|
|
106
|
-
/** A callback to allow a tab to unregister itself with the tab list. */
|
|
107
|
-
onUnregister: RegisterTabEventHandler;
|
|
117
|
+
export declare type TabListSlots = {
|
|
108
118
|
/**
|
|
109
|
-
*
|
|
119
|
+
* The slot associated with the root element of this tab list.
|
|
110
120
|
*/
|
|
111
|
-
|
|
121
|
+
root: Slot<'div'>;
|
|
112
122
|
};
|
|
113
123
|
|
|
114
124
|
/**
|
|
115
|
-
*
|
|
125
|
+
* State used in rendering TabList.
|
|
116
126
|
*/
|
|
117
|
-
export declare type
|
|
118
|
-
/**
|
|
119
|
-
* The context of the tab list available to each tab.
|
|
120
|
-
*/
|
|
121
|
-
tabList: TabListContextValue;
|
|
122
|
-
};
|
|
127
|
+
export declare type TabListState = ComponentState<Required<TabListSlots>> & TabListContextValue;
|
|
123
128
|
|
|
124
129
|
/**
|
|
125
|
-
*
|
|
130
|
+
* Tab Props
|
|
126
131
|
*/
|
|
127
|
-
export declare type
|
|
132
|
+
export declare type TabProps = ComponentProps<Partial<TabSlots>> & {
|
|
128
133
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
134
|
+
* A tab can be set to disable interaction.
|
|
135
|
+
* @default false
|
|
131
136
|
*/
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export declare const tabListSelectionIndicatorName = "fui-TabList_SelectionIndicator";
|
|
136
|
-
|
|
137
|
-
export declare type TabListSlots = {
|
|
137
|
+
disabled?: boolean;
|
|
138
138
|
/**
|
|
139
|
-
* The
|
|
139
|
+
* The value that identifies this tab when selected.
|
|
140
140
|
*/
|
|
141
|
-
|
|
141
|
+
value: TabValue;
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
144
|
+
export declare type TabRegisterData = {
|
|
145
|
+
/**
|
|
146
|
+
* The value of the tab.
|
|
147
|
+
*/
|
|
148
|
+
value: TabValue;
|
|
149
|
+
/**
|
|
150
|
+
* The reference to the tab HTML element.
|
|
151
|
+
*/
|
|
152
|
+
ref: React_2.RefObject<HTMLElement>;
|
|
149
153
|
};
|
|
150
154
|
|
|
151
|
-
/**
|
|
152
|
-
* Tab Props
|
|
153
|
-
*/
|
|
154
|
-
export declare type TabProps = ComponentProps<Partial<TabSlots>> & TabCommons;
|
|
155
|
-
|
|
156
155
|
export declare type TabSlots = {
|
|
157
156
|
/**
|
|
158
157
|
* Root of the component.
|
|
159
158
|
*/
|
|
160
|
-
root: Slot<'
|
|
159
|
+
root: Slot<'button'>;
|
|
161
160
|
/**
|
|
162
161
|
* Icon that renders before the content.
|
|
163
162
|
*/
|
|
@@ -172,15 +171,19 @@ export declare type TabSlots = {
|
|
|
172
171
|
/**
|
|
173
172
|
* State used in rendering Tab
|
|
174
173
|
*/
|
|
175
|
-
export declare type TabState = ComponentState<TabSlots> &
|
|
174
|
+
export declare type TabState = ComponentState<TabSlots> & Pick<TabProps, 'value'> & Required<Pick<TabProps, 'disabled'>> & {
|
|
176
175
|
/**
|
|
177
176
|
* A tab supports 'transparent' and 'subtle' appearance.
|
|
178
177
|
*/
|
|
179
|
-
appearance?:
|
|
178
|
+
appearance?: 'transparent' | 'subtle';
|
|
179
|
+
/**
|
|
180
|
+
* A tab can have only an icon slot filled and no content.
|
|
181
|
+
*/
|
|
182
|
+
iconOnly: boolean;
|
|
180
183
|
/**
|
|
181
|
-
* If this tab is selected
|
|
184
|
+
* If this tab is selected
|
|
182
185
|
*/
|
|
183
|
-
selected
|
|
186
|
+
selected: boolean;
|
|
184
187
|
/**
|
|
185
188
|
* A tab can be either 'small' or 'medium' size.
|
|
186
189
|
*/
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tab.types.js","sourceRoot":"../src/","sources":["components/Tab/Tab.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\n/**\n * Any value that identifies a specific tab.\n */\nexport type TabValue = unknown;\n\nexport type TabSlots = {\n /**\n * Root of the component.\n */\n root: Slot<'
|
|
1
|
+
{"version":3,"file":"Tab.types.js","sourceRoot":"../src/","sources":["components/Tab/Tab.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\n/**\n * Any value that identifies a specific tab.\n */\nexport type TabValue = unknown;\n\nexport type TabSlots = {\n /**\n * Root of the component.\n */\n root: Slot<'button'>;\n\n /**\n * Icon that renders before the content.\n */\n icon?: Slot<'span'>;\n\n /**\n * Component children are placed in this slot\n * Avoid using the `children` property in this slot in favour of Component children whenever possible.\n */\n content: NonNullable<Slot<'span'>>;\n};\n\n/**\n * Tab Props\n */\nexport type TabProps = ComponentProps<Partial<TabSlots>> & {\n /**\n * A tab can be set to disable interaction.\n * @default false\n */\n disabled?: boolean;\n /**\n * The value that identifies this tab when selected.\n */\n value: TabValue;\n};\n\n/**\n * State used in rendering Tab\n */\nexport type TabState = ComponentState<TabSlots> &\n Pick<TabProps, 'value'> &\n Required<Pick<TabProps, 'disabled'>> & {\n /**\n * A tab supports 'transparent' and 'subtle' appearance.\n */\n appearance?: 'transparent' | 'subtle';\n /**\n * A tab can have only an icon slot filled and no content.\n */\n iconOnly: boolean;\n /**\n * If this tab is selected\n */\n selected: boolean;\n /**\n * A tab can be either 'small' or 'medium' size.\n */\n size: 'small' | 'medium';\n /**\n * A tab can arrange its content based on if the tabs in the list are arranged vertically.\n */\n vertical: boolean;\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Tab/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './Tab';\nexport * from './Tab.types';\nexport * from './renderTab';\nexport * from './useTab';\nexport * from './useTabStyles';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Tab/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './Tab';\nexport * from './Tab.types';\nexport * from './renderTab';\nexport * from './useTab';\nexport * from './useTabStyles';\nexport * from './useTabAnimatedIndicator';\n"]}
|
|
@@ -3,7 +3,6 @@ import { getSlots } from '@fluentui/react-utilities';
|
|
|
3
3
|
/**
|
|
4
4
|
* Render the final JSX of Tab
|
|
5
5
|
*/
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
6
|
|
|
8
7
|
export const renderTab_unstable = state => {
|
|
9
8
|
const {
|
|
@@ -12,7 +11,7 @@ export const renderTab_unstable = state => {
|
|
|
12
11
|
} = getSlots(state);
|
|
13
12
|
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
14
13
|
}, slots.icon && /*#__PURE__*/React.createElement(slots.icon, { ...slotProps.icon
|
|
15
|
-
}), /*#__PURE__*/React.createElement(slots.content, { ...slotProps.content
|
|
14
|
+
}), !state.iconOnly && /*#__PURE__*/React.createElement(slots.content, { ...slotProps.content
|
|
16
15
|
}));
|
|
17
16
|
};
|
|
18
17
|
//# sourceMappingURL=renderTab.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Tab/renderTab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG
|
|
1
|
+
{"version":3,"sources":["components/Tab/renderTab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,kBAAkB,GAAI,KAAD,IAAoB;AACpD,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAW,KAAX,CAArC;AAEA,sBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,EACG,KAAK,CAAC,IAAN,iBAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,CADjB,EAEG,CAAC,KAAK,CAAC,QAAP,iBAAmB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;AAAf,GAAd,CAFtB,CADF;AAMD,CATM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { TabState, TabSlots } from './Tab.types';\n\n/**\n * Render the final JSX of Tab\n */\nexport const renderTab_unstable = (state: TabState) => {\n const { slots, slotProps } = getSlots<TabSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.icon && <slots.icon {...slotProps.icon} />}\n {!state.iconOnly && <slots.content {...slotProps.content} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -11,35 +11,27 @@ import { useContextSelector } from '@fluentui/react-context-selector';
|
|
|
11
11
|
* @param props - props from this instance of Tab
|
|
12
12
|
* @param ref - reference to root HTMLElement of Tab
|
|
13
13
|
*/
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
14
|
|
|
16
15
|
export const useTab_unstable = (props, ref) => {
|
|
17
16
|
const {
|
|
18
17
|
content,
|
|
18
|
+
disabled: tabDisabled = false,
|
|
19
19
|
icon,
|
|
20
20
|
value
|
|
21
21
|
} = props;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
selected: ctx.selectedValue === value,
|
|
33
|
-
onRegister: ctx.onRegister,
|
|
34
|
-
onUnregister: ctx.onUnregister,
|
|
35
|
-
onSelect: ctx.onSelect,
|
|
36
|
-
size: ctx.size,
|
|
37
|
-
vertical: !!ctx.vertical
|
|
38
|
-
}));
|
|
22
|
+
const appearance = useContextSelector(TabListContext, ctx => ctx.appearance);
|
|
23
|
+
const listDisabled = useContextSelector(TabListContext, ctx => ctx.disabled);
|
|
24
|
+
const selected = useContextSelector(TabListContext, ctx => ctx.selectedValue === value);
|
|
25
|
+
const onRegister = useContextSelector(TabListContext, ctx => ctx.onRegister);
|
|
26
|
+
const onUnregister = useContextSelector(TabListContext, ctx => ctx.onUnregister);
|
|
27
|
+
const onSelect = useContextSelector(TabListContext, ctx => ctx.onSelect);
|
|
28
|
+
const size = useContextSelector(TabListContext, ctx => ctx.size);
|
|
29
|
+
const vertical = useContextSelector(TabListContext, ctx => !!ctx.vertical);
|
|
30
|
+
const disabled = listDisabled || tabDisabled;
|
|
31
|
+
const innerRef = React.useRef(null);
|
|
39
32
|
const onClick = useEventCallback(event => onSelect(event, {
|
|
40
33
|
value
|
|
41
34
|
}));
|
|
42
|
-
const innerRef = React.useRef(null);
|
|
43
35
|
React.useEffect(() => {
|
|
44
36
|
onRegister({
|
|
45
37
|
value,
|
|
@@ -52,27 +44,34 @@ export const useTab_unstable = (props, ref) => {
|
|
|
52
44
|
});
|
|
53
45
|
};
|
|
54
46
|
}, [onRegister, onUnregister, innerRef, value]);
|
|
47
|
+
const iconShorthand = resolveShorthand(icon);
|
|
48
|
+
const contentShorthand = resolveShorthand(content, {
|
|
49
|
+
required: true,
|
|
50
|
+
defaultProps: {
|
|
51
|
+
children: props.children
|
|
52
|
+
}
|
|
53
|
+
});
|
|
55
54
|
return {
|
|
56
55
|
components: {
|
|
57
|
-
root: '
|
|
56
|
+
root: 'button',
|
|
58
57
|
icon: 'span',
|
|
59
58
|
content: 'span'
|
|
60
59
|
},
|
|
61
|
-
root: getNativeElementProps('
|
|
60
|
+
root: getNativeElementProps('button', {
|
|
62
61
|
ref: useMergedRefs(ref, innerRef),
|
|
63
62
|
role: 'tab',
|
|
64
|
-
|
|
63
|
+
// aria-selected undefined indicates it is not selectable
|
|
64
|
+
// according to https://www.w3.org/TR/wai-aria-1.1/#aria-selected
|
|
65
|
+
'aria-selected': disabled ? undefined : `${selected}`,
|
|
65
66
|
...props,
|
|
67
|
+
disabled,
|
|
66
68
|
onClick
|
|
67
69
|
}),
|
|
68
|
-
icon:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
defaultProps: {
|
|
72
|
-
children: props.children
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
70
|
+
icon: iconShorthand,
|
|
71
|
+
iconOnly: Boolean((iconShorthand === null || iconShorthand === void 0 ? void 0 : iconShorthand.children) && !contentShorthand.children),
|
|
72
|
+
content: contentShorthand,
|
|
75
73
|
appearance,
|
|
74
|
+
disabled,
|
|
76
75
|
selected,
|
|
77
76
|
size,
|
|
78
77
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Tab/useTab.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,gBAAlD,EAAoE,aAApE,QAAyF,2BAAzF;AAEA,SAAS,cAAT,QAA+B,2BAA/B;AACA,SAAS,kBAAT,QAAmC,kCAAnC;AAGA;;;;;;;;AAQG
|
|
1
|
+
{"version":3,"sources":["components/Tab/useTab.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,gBAAlD,EAAoE,aAApE,QAAyF,2BAAzF;AAEA,SAAS,cAAT,QAA+B,2BAA/B;AACA,SAAS,kBAAT,QAAmC,kCAAnC;AAGA;;;;;;;;AAQG;;AACH,OAAO,MAAM,eAAe,GAAG,CAAC,KAAD,EAAkB,GAAlB,KAA2D;AACxF,QAAM;AAAE,IAAA,OAAF;AAAW,IAAA,QAAQ,EAAE,WAAW,GAAG,KAAnC;AAA0C,IAAA,IAA1C;AAAgD,IAAA;AAAhD,MAA0D,KAAh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AAa,YAAb,EAA2B,QAA3B,EAAqC,KAArC,CATH;AAWA,QAAM,aAAa,GAAG,gBAAgB,CAAC,IAAD,CAAtC;AACA,QAAM,gBAAgB,GAAG,gBAAgB,CAAC,OAAD,EAAU;AAAE,IAAA,QAAQ,EAAE,IAAZ;AAAkB,IAAA,YAAY,EAAE;AAAE,MAAA,QAAQ,EAAE,KAAK,CAAC;AAAlB;AAAhC,GAAV,CAAzC;AACA,SAAO;AACL,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE,QADI;AAEV,MAAA,IAAI,EAAE,MAFI;AAGV,MAAA,OAAO,EAAE;AAHC,KADP;AAML,IAAA,IAAI,EAAE,qBAAqB,CAAC,QAAD,EAAW;AACpC,MAAA,GAAG,EAAE,aAAa,CAAC,GAAD,EAAM,QAAN,CADkB;AAEpC,MAAA,IAAI,EAAE,KAF8B;AAGpC;AACA;AACA,uBAAiB,QAAQ,GAAG,SAAH,GAAe,GAAG,QAAQ,EALf;AAMpC,SAAG,KANiC;AAOpC,MAAA,QAPoC;AAQpC,MAAA;AARoC,KAAX,CANtB;AAgBL,IAAA,IAAI,EAAE,aAhBD;AAiBL,IAAA,QAAQ,EAAE,OAAO,CAAC,CAAA,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,QAAf,KAA2B,CAAC,gBAAgB,CAAC,QAA9C,CAjBZ;AAkBL,IAAA,OAAO,EAAE,gBAlBJ;AAmBL,IAAA,UAnBK;AAoBL,IAAA,QApBK;AAqBL,IAAA,QArBK;AAsBL,IAAA,IAtBK;AAuBL,IAAA,KAvBK;AAwBL,IAAA;AAxBK,GAAP;AA0BD,CAvDM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { TabProps, TabState } from './Tab.types';\nimport { TabListContext } from '../TabList/TabListContext';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { SelectTabEvent } from '../TabList/TabList.types';\n\n/**\n * Create the state required to render Tab.\n *\n * The returned state can be modified with hooks such as useTabStyles_unstable,\n * before being passed to renderTab_unstable.\n *\n * @param props - props from this instance of Tab\n * @param ref - reference to root HTMLElement of Tab\n */\nexport const useTab_unstable = (props: TabProps, ref: React.Ref<HTMLElement>): TabState => {\n const { content, disabled: tabDisabled = false, icon, value } = props;\n\n const appearance = useContextSelector(TabListContext, ctx => ctx.appearance);\n const listDisabled = useContextSelector(TabListContext, ctx => ctx.disabled);\n const selected = useContextSelector(TabListContext, ctx => ctx.selectedValue === value);\n const onRegister = useContextSelector(TabListContext, ctx => ctx.onRegister);\n const onUnregister = useContextSelector(TabListContext, ctx => ctx.onUnregister);\n const onSelect = useContextSelector(TabListContext, ctx => ctx.onSelect);\n const size = useContextSelector(TabListContext, ctx => ctx.size);\n const vertical = useContextSelector(TabListContext, ctx => !!ctx.vertical);\n const disabled = listDisabled || tabDisabled;\n\n const innerRef = React.useRef<HTMLElement>(null);\n const onClick = useEventCallback((event: SelectTabEvent) => onSelect(event, { value }));\n\n React.useEffect(() => {\n onRegister({\n value,\n ref: innerRef,\n });\n\n return () => {\n onUnregister({ value, ref: innerRef });\n };\n }, [onRegister, onUnregister, innerRef, value]);\n\n const iconShorthand = resolveShorthand(icon);\n const contentShorthand = resolveShorthand(content, { required: true, defaultProps: { children: props.children } });\n return {\n components: {\n root: 'button',\n icon: 'span',\n content: 'span',\n },\n root: getNativeElementProps('button', {\n ref: useMergedRefs(ref, innerRef),\n role: 'tab',\n // aria-selected undefined indicates it is not selectable\n // according to https://www.w3.org/TR/wai-aria-1.1/#aria-selected\n 'aria-selected': disabled ? undefined : `${selected}`,\n ...props,\n disabled,\n onClick,\n }),\n icon: iconShorthand,\n iconOnly: Boolean(iconShorthand?.children && !contentShorthand.children),\n content: contentShorthand,\n appearance,\n disabled,\n selected,\n size,\n value,\n vertical,\n };\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { __styles, mergeClasses, shorthands } from '@griffel/react';
|
|
3
|
+
import { useContextSelector } from '@fluentui/react-context-selector';
|
|
4
|
+
import { TabListContext } from '../TabList/TabListContext';
|
|
5
|
+
import { tokens } from '@fluentui/react-theme'; // 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": "f1gswng4",
|
|
20
|
+
"Jgwf15": "fjw9r1k",
|
|
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;}", ".f1gswng4:after{transition-duration:var(--durationSlow);}", ".fjw9r1k:after{transition-timing-function:var(--curveDecelerateMax);}", ".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 !== undefined && value !== null ? (_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,kBAAT,QAAmC,kCAAnC;AACA,SAAS,cAAT,QAA+B,2BAA/B;AAEA,SAAS,MAAT,QAA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;AACD,CArEM","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/"}
|