@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
|
|
3
|
-
import { getNativeElementProps,
|
|
3
|
+
import { getNativeElementProps, useControllableState, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
4
4
|
/**
|
|
5
5
|
* Create the state required to render TabList.
|
|
6
6
|
*
|
|
@@ -10,11 +10,11 @@ import { getNativeElementProps, useConst, useControllableState, useEventCallback
|
|
|
10
10
|
* @param props - props from this instance of TabList
|
|
11
11
|
* @param ref - reference to root HTMLElement of TabList
|
|
12
12
|
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
13
|
|
|
15
14
|
export const useTabList_unstable = (props, ref) => {
|
|
16
15
|
const {
|
|
17
16
|
appearance = 'transparent',
|
|
17
|
+
disabled = false,
|
|
18
18
|
onTabSelect,
|
|
19
19
|
size = 'medium',
|
|
20
20
|
vertical = false
|
|
@@ -22,67 +22,42 @@ export const useTabList_unstable = (props, ref) => {
|
|
|
22
22
|
const innerRef = React.useRef(null);
|
|
23
23
|
const focusAttributes = useArrowNavigationGroup({
|
|
24
24
|
circular: true,
|
|
25
|
-
axis: vertical ? 'vertical' : 'horizontal'
|
|
25
|
+
axis: vertical ? 'vertical' : 'horizontal',
|
|
26
|
+
memorizeCurrent: true
|
|
26
27
|
});
|
|
27
28
|
const [selectedValue, setSelectedValue] = useControllableState({
|
|
28
29
|
state: props.selectedValue,
|
|
29
30
|
defaultState: props.defaultSelectedValue,
|
|
30
31
|
initialState: undefined
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}); // provide force recalculation of the selection indicator rectangle
|
|
36
|
-
|
|
37
|
-
const [calcRect, setCalcRect] = React.useState(0);
|
|
38
|
-
const recalcRect = useConst(() => () => setCalcRect(value => ++value)); // when this list or any tab resizes, recalculate the selection indicator rectangle
|
|
39
|
-
|
|
40
|
-
const resizeObserver = React.useMemo(() => new ResizeObserver(entries => {
|
|
41
|
-
recalcRect();
|
|
42
|
-
}), [recalcRect]); // observe this list for resize
|
|
32
|
+
}); // considered usePrevious, but it is sensitive to re-renders
|
|
33
|
+
// this could cause the previous to move to current in the case where the tab list re-renders.
|
|
34
|
+
// these refs avoid getRegisteredTabs changing when selectedValue changes and causing
|
|
35
|
+
// renders for tabs that have not changed.
|
|
43
36
|
|
|
37
|
+
const currentSelectedValue = React.useRef(undefined);
|
|
38
|
+
const previousSelectedValue = React.useRef(undefined);
|
|
44
39
|
React.useEffect(() => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
previousSelectedValue.current = currentSelectedValue.current;
|
|
41
|
+
currentSelectedValue.current = selectedValue;
|
|
42
|
+
}, [selectedValue]);
|
|
43
|
+
const onSelect = useEventCallback((event, data) => {
|
|
44
|
+
setSelectedValue(data.value);
|
|
45
|
+
onTabSelect === null || onTabSelect === void 0 ? void 0 : onTabSelect(event, data);
|
|
46
|
+
});
|
|
52
47
|
const registeredTabs = React.useRef({});
|
|
53
48
|
const onRegister = useEventCallback(data => {
|
|
54
|
-
var _a;
|
|
55
|
-
|
|
56
49
|
registeredTabs.current[JSON.stringify(data.value)] = data;
|
|
57
|
-
((_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) && resizeObserver.observe(data.ref.current);
|
|
58
|
-
recalcRect();
|
|
59
50
|
});
|
|
60
51
|
const onUnregister = useEventCallback(data => {
|
|
61
|
-
var _a;
|
|
62
|
-
|
|
63
52
|
delete registeredTabs.current[JSON.stringify(data.value)];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const tabRef = (_b = registeredTabs.current[JSON.stringify(selectedValue)]) === null || _b === void 0 ? void 0 : _b.ref;
|
|
73
|
-
const tabRect = (_c = tabRef === null || tabRef === void 0 ? void 0 : tabRef.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect();
|
|
74
|
-
|
|
75
|
-
if (listRect && tabRect) {
|
|
76
|
-
return {
|
|
77
|
-
x: tabRect.x - listRect.x,
|
|
78
|
-
y: tabRect.y - listRect.y,
|
|
79
|
-
width: tabRect.width,
|
|
80
|
-
height: tabRect.height
|
|
81
|
-
};
|
|
82
|
-
} // calcRect is used to force updates when registered tabs change or resize occurs
|
|
83
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
-
|
|
85
|
-
}, [calcRect, selectedValue]);
|
|
53
|
+
});
|
|
54
|
+
const getRegisteredTabs = React.useCallback(() => {
|
|
55
|
+
return {
|
|
56
|
+
selectedValue: currentSelectedValue.current,
|
|
57
|
+
previousSelectedValue: previousSelectedValue.current,
|
|
58
|
+
registeredTabs: registeredTabs.current
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
86
61
|
return {
|
|
87
62
|
components: {
|
|
88
63
|
root: 'div'
|
|
@@ -94,13 +69,14 @@ export const useTabList_unstable = (props, ref) => {
|
|
|
94
69
|
...props
|
|
95
70
|
}),
|
|
96
71
|
appearance,
|
|
97
|
-
|
|
72
|
+
disabled,
|
|
98
73
|
selectedValue,
|
|
99
74
|
size,
|
|
100
75
|
vertical,
|
|
101
76
|
onRegister,
|
|
102
77
|
onUnregister,
|
|
103
|
-
onSelect
|
|
78
|
+
onSelect,
|
|
79
|
+
getRegisteredTabs
|
|
104
80
|
};
|
|
105
81
|
};
|
|
106
82
|
//# sourceMappingURL=useTabList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/TabList/useTabList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,uBAAT,QAAwC,yBAAxC;AACA,SACE,qBADF,EAEE,
|
|
1
|
+
{"version":3,"sources":["components/TabList/useTabList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,uBAAT,QAAwC,yBAAxC;AACA,SACE,qBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,QAKO,2BALP;AASA;;;;;;;;AAQG;;AACH,OAAO,MAAM,mBAAmB,GAAG,CAAC,KAAD,EAAsB,GAAtB,KAAmE;AACpG,QAAM;AAAE,IAAA,UAAU,GAAG,aAAf;AAA8B,IAAA,QAAQ,GAAG,KAAzC;AAAgD,IAAA,WAAhD;AAA6D,IAAA,IAAI,GAAG,QAApE;AAA8E,IAAA,QAAQ,GAAG;AAAzF,MAAmG,KAAzG;AAEA,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAA0B,IAA1B,CAAjB;AAEA,QAAM,eAAe,GAAG,uBAAuB,CAAC;AAC9C,IAAA,QAAQ,EAAE,IADoC;AAE9C,IAAA,IAAI,EAAE,QAAQ,GA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,CAAC,KAApB,CAAvB,CAAP;AACD,GAFoC,CAArC;AAIA,QAAM,iBAAiB,GAAG,KAAK,CAAC,WAAN,CAAkB,MAAK;AAC/C,WAAO;AACL,MAAA,aAAa,EAAE,oBAAoB,CAAC,OAD/B;AAEL,MAAA,qBAAqB,EAAE,qBAAqB,CAAC,OAFxC;AAGL,MAAA,cAAc,EAAE,cAAc,CAAC;AAH1B,KAAP;AAKD,GANyB,EAMvB,EANuB,CAA1B;AAQA,SAAO;AACL,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE;AADI,KADP;AAIL,IAAA,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;AACjC,MAAA,GAAG,EAAE,aAAa,CAAC,GAAD,EAAM,QAAN,CADe;AAEjC,MAAA,IAAI,EAAE,SAF2B;AAGjC,SAAG,eAH8B;AAIjC,SAAG;AAJ8B,KAAR,CAJtB;AAUL,IAAA,UAVK;AAWL,IAAA,QAXK;AAYL,IAAA,aAZK;AAaL,IAAA,IAbK;AAcL,IAAA,QAdK;AAeL,IAAA,UAfK;AAgBL,IAAA,YAhBK;AAiBL,IAAA,QAjBK;AAkBL,IAAA;AAlBK,GAAP;AAoBD,CAxEM","sourcesContent":["import * as React from 'react';\nimport { useArrowNavigationGroup } from '@fluentui/react-tabster';\nimport {\n getNativeElementProps,\n useControllableState,\n useEventCallback,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport type { TabRegisterData, SelectTabData, SelectTabEvent, TabListProps, TabListState } from './TabList.types';\nimport { TabValue } from '../Tab/Tab.types';\n\n/**\n * Create the state required to render TabList.\n *\n * The returned state can be modified with hooks such as useTabListStyles_unstable,\n * before being passed to renderTabList_unstable.\n *\n * @param props - props from this instance of TabList\n * @param ref - reference to root HTMLElement of TabList\n */\nexport const useTabList_unstable = (props: TabListProps, ref: React.Ref<HTMLElement>): TabListState => {\n const { appearance = 'transparent', disabled = false, onTabSelect, size = 'medium', vertical = false } = props;\n\n const innerRef = React.useRef<HTMLElement>(null);\n\n const focusAttributes = useArrowNavigationGroup({\n circular: true,\n axis: vertical ? 'vertical' : 'horizontal',\n memorizeCurrent: true,\n });\n\n const [selectedValue, setSelectedValue] = useControllableState({\n state: props.selectedValue,\n defaultState: props.defaultSelectedValue,\n initialState: undefined,\n });\n\n // considered usePrevious, but it is sensitive to re-renders\n // this could cause the previous to move to current in the case where the tab list re-renders.\n // these refs avoid getRegisteredTabs changing when selectedValue changes and causing\n // renders for tabs that have not changed.\n const currentSelectedValue = React.useRef<TabValue | undefined>(undefined);\n const previousSelectedValue = React.useRef<TabValue | undefined>(undefined);\n\n React.useEffect(() => {\n previousSelectedValue.current = currentSelectedValue.current;\n currentSelectedValue.current = selectedValue;\n }, [selectedValue]);\n\n const onSelect = useEventCallback((event: SelectTabEvent, data: SelectTabData) => {\n setSelectedValue(data.value);\n onTabSelect?.(event, data);\n });\n\n const registeredTabs = React.useRef<Record<string, TabRegisterData>>({});\n\n const onRegister = useEventCallback((data: TabRegisterData) => {\n registeredTabs.current[JSON.stringify(data.value)] = data;\n });\n\n const onUnregister = useEventCallback((data: TabRegisterData) => {\n delete registeredTabs.current[JSON.stringify(data.value)];\n });\n\n const getRegisteredTabs = React.useCallback(() => {\n return {\n selectedValue: currentSelectedValue.current,\n previousSelectedValue: previousSelectedValue.current,\n registeredTabs: registeredTabs.current,\n };\n }, []);\n\n return {\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, innerRef),\n role: 'tablist',\n ...focusAttributes,\n ...props,\n }),\n appearance,\n disabled,\n selectedValue,\n size,\n vertical,\n onRegister,\n onUnregister,\n onSelect,\n getRegisteredTabs,\n };\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
export function useTabListContextValues(state) {
|
|
2
2
|
const {
|
|
3
3
|
appearance,
|
|
4
|
+
disabled,
|
|
4
5
|
selectedValue: selectedKey,
|
|
5
6
|
onRegister,
|
|
6
7
|
onUnregister,
|
|
7
8
|
onSelect,
|
|
9
|
+
getRegisteredTabs,
|
|
8
10
|
size,
|
|
9
11
|
vertical
|
|
10
12
|
} = state;
|
|
11
13
|
const tabList = {
|
|
12
14
|
appearance,
|
|
15
|
+
disabled,
|
|
13
16
|
selectedValue: selectedKey,
|
|
14
17
|
onSelect,
|
|
15
18
|
onRegister,
|
|
16
19
|
onUnregister,
|
|
20
|
+
getRegisteredTabs,
|
|
17
21
|
size,
|
|
18
22
|
vertical
|
|
19
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/TabList/useTabListContextValues.tsx"],"names":[],"mappings":"AAEA,OAAM,SAAU,uBAAV,CAAkC,KAAlC,EAAqD;AACzD,QAAM;
|
|
1
|
+
{"version":3,"sources":["components/TabList/useTabListContextValues.tsx"],"names":[],"mappings":"AAEA,OAAM,SAAU,uBAAV,CAAkC,KAAlC,EAAqD;AACzD,QAAM;AACJ,IAAA,UADI;AAEJ,IAAA,QAFI;AAGJ,IAAA,aAAa,EAAE,WAHX;AAIJ,IAAA,UAJI;AAKJ,IAAA,YALI;AAMJ,IAAA,QANI;AAOJ,IAAA,iBAPI;AAQJ,IAAA,IARI;AASJ,IAAA;AATI,MAUF,KAVJ;AAYA,QAAM,OAAO,GAAwB;AACnC,IAAA,UADmC;AAEnC,IAAA,QAFmC;AAGnC,IAAA,aAAa,EAAE,WAHoB;AAInC,IAAA,QAJmC;AAKnC,IAAA,UALmC;AAMnC,IAAA,YANmC;AAOnC,IAAA,iBAPmC;AAQnC,IAAA,IARmC;AASnC,IAAA;AATmC,GAArC;AAYA,SAAO;AAAE,IAAA;AAAF,GAAP;AACD","sourcesContent":["import { TabListContextValue, TabListContextValues, TabListState } from './TabList.types';\n\nexport function useTabListContextValues(state: TabListState): TabListContextValues {\n const {\n appearance,\n disabled,\n selectedValue: selectedKey,\n onRegister,\n onUnregister,\n onSelect,\n getRegisteredTabs,\n size,\n vertical,\n } = state;\n\n const tabList: TabListContextValue = {\n appearance,\n disabled,\n selectedValue: selectedKey,\n onSelect,\n onRegister,\n onUnregister,\n getRegisteredTabs,\n size,\n vertical,\n };\n\n return { tabList };\n}\n"],"sourceRoot":"../src/"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { __styles, mergeClasses
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const tabListClassName = 'fui-TabList';
|
|
6
|
-
export const tabListSelectionIndicatorName = 'fui-TabList_SelectionIndicator';
|
|
7
|
-
export const indicatorOffsetVar = '--selection-indicator-offset';
|
|
8
|
-
export const indicatorLengthVar = '--selection-indicator-length';
|
|
1
|
+
import { __styles, mergeClasses } from '@griffel/react';
|
|
2
|
+
export const tabListClassNames = {
|
|
3
|
+
root: 'fui-TabList'
|
|
4
|
+
};
|
|
9
5
|
/**
|
|
10
6
|
* Styles for the root slot
|
|
11
7
|
*/
|
|
@@ -14,105 +10,32 @@ const useStyles = /*#__PURE__*/__styles({
|
|
|
14
10
|
"root": {
|
|
15
11
|
"mc9l5x": "f22iagw",
|
|
16
12
|
"Beiy3e4": "f1063pyq",
|
|
13
|
+
"Bnnss6s": "fi64zpg",
|
|
14
|
+
"Eh141a": "flvyvdh",
|
|
17
15
|
"qhf8xq": "f10pi13n"
|
|
18
16
|
},
|
|
17
|
+
"horizontal": {
|
|
18
|
+
"Bt984gj": "f1q9h2pe",
|
|
19
|
+
"Beiy3e4": "f1063pyq"
|
|
20
|
+
},
|
|
19
21
|
"vertical": {
|
|
22
|
+
"Bt984gj": "f1q9h2pe",
|
|
20
23
|
"Beiy3e4": "f1vx9l62"
|
|
21
24
|
}
|
|
22
25
|
}, {
|
|
23
|
-
"d": [".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1063pyq{-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;}", ".f10pi13n{position:relative;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}"]
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* Styles for the selection indicator slot when horizontal.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const useHorizontalIndicatorStyles = /*#__PURE__*/__styles({
|
|
31
|
-
"base": {
|
|
32
|
-
"Bkbwdz4": "f30248y",
|
|
33
|
-
"frdscb": ["fvxed1z", "f1j2a01o"],
|
|
34
|
-
"B9nohqn": ["f1j2a01o", "fvxed1z"],
|
|
35
|
-
"B1dhsta": ["fsamouo", "f1aazreq"],
|
|
36
|
-
"Bjdmjzx": ["f1aazreq", "fsamouo"],
|
|
37
|
-
"Bj55yzk": "fw2wsqs",
|
|
38
|
-
"oqd9ik": "ffdc0f3",
|
|
39
|
-
"Bs6t6z0": "fqc6z8f",
|
|
40
|
-
"mpb1vu": "f119hevp",
|
|
41
|
-
"jc51t6": ["f1uyszuw", "f1xp83vy"],
|
|
42
|
-
"Hdbjpj": "f11ef69",
|
|
43
|
-
"Biobvvw": "f1tzy5p2",
|
|
44
|
-
"Bunff0j": "fs357bs"
|
|
45
|
-
},
|
|
46
|
-
"small": {
|
|
47
|
-
"jc51t6": ["f1w3ykbk", "f1xm0lqg"],
|
|
48
|
-
"Biobvvw": "f1akpkq3"
|
|
49
|
-
},
|
|
50
|
-
"animated": {
|
|
51
|
-
"wbfbqe": ["fjzde92", "f1xfxhj5"],
|
|
52
|
-
"mafdb0": "f1fuwhvj"
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
"d": [".f30248y:after{background-color:var(--colorBrandStroke1);}", ".fvxed1z:after{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f1j2a01o:after{border-bottom-left-radius:var(--borderRadiusMedium);}", ".fsamouo:after{border-top-right-radius:var(--borderRadiusMedium);}", ".f1aazreq:after{border-top-left-radius:var(--borderRadiusMedium);}", ".fw2wsqs:after{bottom:0;}", ".ffdc0f3:after{box-sizing:border-box;}", ".fqc6z8f:after{content:\"\";}", ".f119hevp:after{height:2px;}", ".f1uyszuw:after{left:calc(var(--selection-indicator-offset) + 10px);}", ".f1xp83vy:after{right:calc(var(--selection-indicator-offset) + 10px);}", ".f11ef69:after{position:absolute;}", ".f1tzy5p2:after{width:calc(var(--selection-indicator-length) - (2 * 10px));}", ".fs357bs:after{z-index:1;}", ".f1w3ykbk:after{left:calc(var(--selection-indicator-offset) + 6px);}", ".f1xm0lqg:after{right:calc(var(--selection-indicator-offset) + 6px);}", ".f1akpkq3:after{width:calc(var(--selection-indicator-length) - (2 * 6px));}", ".fjzde92:after{transition-property:left,width;}", ".f1xfxhj5:after{transition-property:right,width;}", ".f1fuwhvj:after{transition-duration:350ms,350ms;}"]
|
|
56
|
-
});
|
|
57
|
-
/**
|
|
58
|
-
* Styles for the selection indicator slot when vertical.
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const useVerticalIndicatorStyles = /*#__PURE__*/__styles({
|
|
63
|
-
"base": {
|
|
64
|
-
"B1dvbpk": "fa05st",
|
|
65
|
-
"px8gyy": ["f16to4m4", "f1ceoihi"],
|
|
66
|
-
"B5c9fhp": ["f1ceoihi", "f16to4m4"],
|
|
67
|
-
"Bhe99jt": ["fkibbow", "fnlo9u7"],
|
|
68
|
-
"B2r1szc": ["fnlo9u7", "fkibbow"],
|
|
69
|
-
"Bmqnesq": "f170vdtw",
|
|
70
|
-
"rurcny": "fuzzvh5",
|
|
71
|
-
"Bbc2r3f": "f13xaayz",
|
|
72
|
-
"Byque4d": ["f1t0u0az", "fmlx6bj"],
|
|
73
|
-
"xx9plb": "fxf9f1y",
|
|
74
|
-
"Bf8kmfk": "fwt37qm",
|
|
75
|
-
"Bdn98qo": "f15bpuwh",
|
|
76
|
-
"Bab4cu6": "f1ijlm3k"
|
|
77
|
-
},
|
|
78
|
-
"small": {
|
|
79
|
-
"Bf8kmfk": "f8k0k00",
|
|
80
|
-
"Bbc2r3f": "fyephjl"
|
|
81
|
-
},
|
|
82
|
-
"animated": {
|
|
83
|
-
"iukgx1": "fcs48rj",
|
|
84
|
-
"B5szp9g": "f1u309tb"
|
|
85
|
-
}
|
|
86
|
-
}, {
|
|
87
|
-
"d": [".fa05st:before{background-color:var(--colorBrandStroke1);}", ".f16to4m4:before{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f1ceoihi:before{border-bottom-left-radius:var(--borderRadiusMedium);}", ".fkibbow:before{border-top-right-radius:var(--borderRadiusMedium);}", ".fnlo9u7:before{border-top-left-radius:var(--borderRadiusMedium);}", ".f170vdtw:before{box-sizing:border-box;}", ".fuzzvh5:before{content:\"\";}", ".f13xaayz:before{height:calc(var(--selection-indicator-length) - (2 * 10px));}", ".f1t0u0az:before{left:0;}", ".fmlx6bj:before{right:0;}", ".fxf9f1y:before{position:absolute;}", ".fwt37qm:before{top:calc(var(--selection-indicator-offset) + 10px);}", ".f15bpuwh:before{width:2px;}", ".f1ijlm3k:before{z-index:1;}", ".f8k0k00:before{top:calc(var(--selection-indicator-offset) + 6px);}", ".fyephjl:before{height:calc(var(--selection-indicator-length) - (2 * 6px));}", ".fcs48rj:before{transition-property:top,height;}", ".f1u309tb:before{transition-duration:350ms,350ms;}"]
|
|
26
|
+
"d": [".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1063pyq{-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;}", ".fi64zpg{-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;}", ".flvyvdh{-webkit-box-flex-wrap:nowrap;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;}", ".f10pi13n{position:relative;}", ".f1q9h2pe{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}"]
|
|
88
27
|
});
|
|
89
28
|
/**
|
|
90
29
|
* Apply styling to the TabList slots based on the state
|
|
91
30
|
*/
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
93
31
|
|
|
94
32
|
|
|
95
33
|
export const useTabListStyles_unstable = state => {
|
|
96
34
|
const {
|
|
97
|
-
selectedTabRect: selectionIndicatorRect,
|
|
98
|
-
selectedValue,
|
|
99
|
-
size,
|
|
100
35
|
vertical
|
|
101
|
-
} = state;
|
|
102
|
-
|
|
103
|
-
const previousSelectedValue = usePrevious(selectedValue);
|
|
104
|
-
const shouldAnimate = !!previousSelectedValue && previousSelectedValue !== selectedValue;
|
|
36
|
+
} = state;
|
|
105
37
|
const styles = useStyles();
|
|
106
|
-
|
|
107
|
-
const verticalIndicatorStyles = useVerticalIndicatorStyles();
|
|
108
|
-
state.root.className = mergeClasses(tabListClassName, styles.root, vertical && styles.vertical, !!selectedValue && (vertical ? verticalIndicatorStyles.base : horizontalIndicatorStyles.base), !!selectedValue && size === 'small' && (vertical ? verticalIndicatorStyles.small : horizontalIndicatorStyles.small), !!selectedValue && shouldAnimate && (vertical ? verticalIndicatorStyles.animated : horizontalIndicatorStyles.animated), state.root.className);
|
|
109
|
-
const rootCssVars = selectionIndicatorRect ? {
|
|
110
|
-
[indicatorOffsetVar]: vertical ? `${selectionIndicatorRect.y}px` : `${selectionIndicatorRect.x}px`,
|
|
111
|
-
[indicatorLengthVar]: vertical ? `${selectionIndicatorRect.height}px` : `${selectionIndicatorRect.width}px`
|
|
112
|
-
} : {};
|
|
113
|
-
state.root.style = { ...rootCssVars,
|
|
114
|
-
...state.root.style
|
|
115
|
-
};
|
|
38
|
+
state.root.className = mergeClasses(tabListClassNames.root, styles.root, vertical ? styles.vertical : styles.horizontal, state.root.className);
|
|
116
39
|
return state;
|
|
117
40
|
};
|
|
118
41
|
//# sourceMappingURL=useTabListStyles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/TabList/useTabListStyles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["components/TabList/useTabListStyles.ts"],"names":[],"mappings":"AACA,mBAAqB,YAArB,QAAyC,gBAAzC;AAGA,OAAO,MAAM,iBAAiB,GAAiC;AAC7D,EAAA,IAAI,EAAE;AADuD,CAAxD;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAlB;AAkBA;;AAEG;;;AACH,OAAO,MAAM,yBAAyB,GAAI,KAAD,IAAsC;AAC7E,QAAM;AAAE,IAAA;AAAF,MAAe,KAArB;AAEA,QAAM,MAAM,GAAG,SAAS,EAAxB;AAEA,EAAA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CACjC,iBAAiB,CAAC,IADe,EAEjC,MAAM,CAAC,IAF0B,EAGjC,QAAQ,GAAG,MAAM,CAAC,QAAV,GAAqB,MAAM,CAAC,UAHH,EAIjC,KAAK,CAAC,IAAN,CAAW,SAJsB,CAAnC;AAOA,SAAO,KAAP;AACD,CAbM","sourcesContent":["import { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport type { TabListSlots, TabListState } from './TabList.types';\n\nexport const tabListClassNames: SlotClassNames<TabListSlots> = {\n root: 'fui-TabList',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n display: 'flex',\n flexDirection: 'row',\n flexShrink: 0,\n flexWrap: 'nowrap',\n position: 'relative',\n },\n horizontal: {\n alignItems: 'stretch',\n flexDirection: 'row',\n },\n vertical: {\n alignItems: 'stretch',\n flexDirection: 'column',\n },\n});\n\n/**\n * Apply styling to the TabList slots based on the state\n */\nexport const useTabListStyles_unstable = (state: TabListState): TabListState => {\n const { vertical } = state;\n\n const styles = useStyles();\n\n state.root.className = mergeClasses(\n tabListClassNames.root,\n styles.root,\n vertical ? styles.vertical : styles.horizontal,\n state.root.className,\n );\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { renderTab_unstable, Tab, tabClassNames, useTabStyles_unstable, useTab_unstable } from './Tab';
|
|
2
|
+
export { renderTabList_unstable, TabList, tabListClassNames, useTabListStyles_unstable, useTabList_unstable } from './TabList';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AACA,SAAS,kBAAT,EAA6B,GAA7B,EAAkC,aAAlC,EAAiD,qBAAjD,EAAwE,eAAxE,QAA+F,OAA/F;AAaA,SACE,sBADF,EAEE,OAFF,EAGE,iBAHF,EAIE,yBAJF,EAKE,mBALF,QAMO,WANP","sourcesContent":["export type { TabProps, TabSlots, TabState, TabValue } from './Tab';\nexport { renderTab_unstable, Tab, tabClassNames, useTabStyles_unstable, useTab_unstable } from './Tab';\nexport type {\n TabRegisterData,\n RegisterTabEventHandler,\n SelectTabData,\n SelectTabEvent,\n SelectTabEventHandler,\n TabListContextValue,\n TabListContextValues,\n TabListProps,\n TabListSlots,\n TabListState,\n} from './TabList';\nexport {\n renderTabList_unstable,\n TabList,\n tabListClassNames,\n useTabListStyles_unstable,\n useTabList_unstable,\n} from './TabList';\n"],"sourceRoot":"../src/"}
|
|
@@ -15,4 +15,6 @@ tslib_1.__exportStar(require("./renderTab"), exports);
|
|
|
15
15
|
tslib_1.__exportStar(require("./useTab"), exports);
|
|
16
16
|
|
|
17
17
|
tslib_1.__exportStar(require("./useTabStyles"), exports);
|
|
18
|
+
|
|
19
|
+
tslib_1.__exportStar(require("./useTabAnimatedIndicator"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Tab/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,OAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Tab';\nexport * from './Tab.types';\nexport * from './renderTab';\nexport * from './useTab';\nexport * from './useTabStyles';\n"],"sourceRoot":"../src/"}
|
|
1
|
+
{"version":3,"sources":["components/Tab/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,OAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Tab';\nexport * from './Tab.types';\nexport * from './renderTab';\nexport * from './useTab';\nexport * from './useTabStyles';\nexport * from './useTabAnimatedIndicator';\n"],"sourceRoot":"../src/"}
|
|
@@ -11,7 +11,6 @@ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
|
11
11
|
/**
|
|
12
12
|
* Render the final JSX of Tab
|
|
13
13
|
*/
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
const renderTab_unstable = state => {
|
|
@@ -21,7 +20,7 @@ const renderTab_unstable = state => {
|
|
|
21
20
|
} = react_utilities_1.getSlots(state);
|
|
22
21
|
return React.createElement(slots.root, { ...slotProps.root
|
|
23
22
|
}, slots.icon && React.createElement(slots.icon, { ...slotProps.icon
|
|
24
|
-
}), React.createElement(slots.content, { ...slotProps.content
|
|
23
|
+
}), !state.iconOnly && React.createElement(slots.content, { ...slotProps.content
|
|
25
24
|
}));
|
|
26
25
|
};
|
|
27
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Tab/renderTab.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG
|
|
1
|
+
{"version":3,"sources":["components/Tab/renderTab.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,kBAAkB,GAAI,KAAD,IAAoB;AACpD,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,iBAAA,CAAA,QAAA,CAAmB,KAAnB,CAA7B;AAEA,SACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,EACG,KAAK,CAAC,IAAN,IAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,CADjB,EAEG,CAAC,KAAK,CAAC,QAAP,IAAmB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;AAAf,GAAd,CAFtB,CADF;AAMD,CATM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","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/"}
|
|
@@ -21,36 +21,28 @@ const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-s
|
|
|
21
21
|
* @param props - props from this instance of Tab
|
|
22
22
|
* @param ref - reference to root HTMLElement of Tab
|
|
23
23
|
*/
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
const useTab_unstable = (props, ref) => {
|
|
28
27
|
const {
|
|
29
28
|
content,
|
|
29
|
+
disabled: tabDisabled = false,
|
|
30
30
|
icon,
|
|
31
31
|
value
|
|
32
32
|
} = props;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
selected: ctx.selectedValue === value,
|
|
44
|
-
onRegister: ctx.onRegister,
|
|
45
|
-
onUnregister: ctx.onUnregister,
|
|
46
|
-
onSelect: ctx.onSelect,
|
|
47
|
-
size: ctx.size,
|
|
48
|
-
vertical: !!ctx.vertical
|
|
49
|
-
}));
|
|
33
|
+
const appearance = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.appearance);
|
|
34
|
+
const listDisabled = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.disabled);
|
|
35
|
+
const selected = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.selectedValue === value);
|
|
36
|
+
const onRegister = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.onRegister);
|
|
37
|
+
const onUnregister = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.onUnregister);
|
|
38
|
+
const onSelect = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.onSelect);
|
|
39
|
+
const size = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => ctx.size);
|
|
40
|
+
const vertical = react_context_selector_1.useContextSelector(TabListContext_1.TabListContext, ctx => !!ctx.vertical);
|
|
41
|
+
const disabled = listDisabled || tabDisabled;
|
|
42
|
+
const innerRef = React.useRef(null);
|
|
50
43
|
const onClick = react_utilities_1.useEventCallback(event => onSelect(event, {
|
|
51
44
|
value
|
|
52
45
|
}));
|
|
53
|
-
const innerRef = React.useRef(null);
|
|
54
46
|
React.useEffect(() => {
|
|
55
47
|
onRegister({
|
|
56
48
|
value,
|
|
@@ -63,27 +55,34 @@ const useTab_unstable = (props, ref) => {
|
|
|
63
55
|
});
|
|
64
56
|
};
|
|
65
57
|
}, [onRegister, onUnregister, innerRef, value]);
|
|
58
|
+
const iconShorthand = react_utilities_1.resolveShorthand(icon);
|
|
59
|
+
const contentShorthand = react_utilities_1.resolveShorthand(content, {
|
|
60
|
+
required: true,
|
|
61
|
+
defaultProps: {
|
|
62
|
+
children: props.children
|
|
63
|
+
}
|
|
64
|
+
});
|
|
66
65
|
return {
|
|
67
66
|
components: {
|
|
68
|
-
root: '
|
|
67
|
+
root: 'button',
|
|
69
68
|
icon: 'span',
|
|
70
69
|
content: 'span'
|
|
71
70
|
},
|
|
72
|
-
root: react_utilities_1.getNativeElementProps('
|
|
71
|
+
root: react_utilities_1.getNativeElementProps('button', {
|
|
73
72
|
ref: react_utilities_1.useMergedRefs(ref, innerRef),
|
|
74
73
|
role: 'tab',
|
|
75
|
-
|
|
74
|
+
// aria-selected undefined indicates it is not selectable
|
|
75
|
+
// according to https://www.w3.org/TR/wai-aria-1.1/#aria-selected
|
|
76
|
+
'aria-selected': disabled ? undefined : `${selected}`,
|
|
76
77
|
...props,
|
|
78
|
+
disabled,
|
|
77
79
|
onClick
|
|
78
80
|
}),
|
|
79
|
-
icon:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
defaultProps: {
|
|
83
|
-
children: props.children
|
|
84
|
-
}
|
|
85
|
-
}),
|
|
81
|
+
icon: iconShorthand,
|
|
82
|
+
iconOnly: Boolean((iconShorthand === null || iconShorthand === void 0 ? void 0 : iconShorthand.children) && !contentShorthand.children),
|
|
83
|
+
content: contentShorthand,
|
|
86
84
|
appearance,
|
|
85
|
+
disabled,
|
|
87
86
|
selected,
|
|
88
87
|
size,
|
|
89
88
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Tab/useTab.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAEA,MAAA,gBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,wBAAA,gBAAA,OAAA,CAAA,kCAAA,CAAA;AAGA;;;;;;;;AAQG
|
|
1
|
+
{"version":3,"sources":["components/Tab/useTab.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAEA,MAAA,gBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,wBAAA,gBAAA,OAAA,CAAA,kCAAA,CAAA;AAGA;;;;;;;;AAQG;;;AACI,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,KAAhE;AAEA,QAAM,UAAU,GAAG,wBAAA,CAAA,kBAAA,CAAmB,gBAAA,CAAA,cA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uBL,IAAA,KAvBK;AAwBL,IAAA;AAxBK,GAAP;AA0BD,CAvDM;;AAAM,OAAA,CAAA,eAAA,GAAe,eAAf","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/"}
|