@wordpress/components 25.9.0 → 25.10.0
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.md +32 -0
- package/build/alignment-matrix-control/cell.js +8 -5
- package/build/alignment-matrix-control/cell.js.map +1 -1
- package/build/alignment-matrix-control/index.js +27 -43
- package/build/alignment-matrix-control/index.js.map +1 -1
- package/build/alignment-matrix-control/utils.js +29 -9
- package/build/alignment-matrix-control/utils.js.map +1 -1
- package/build/circular-option-picker/circular-option-picker-option.js +20 -39
- package/build/circular-option-picker/circular-option-picker-option.js.map +1 -1
- package/build/circular-option-picker/circular-option-picker.js +11 -32
- package/build/circular-option-picker/circular-option-picker.js.map +1 -1
- package/build/circular-option-picker/types.js.map +1 -1
- package/build/color-palette/index.js +7 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/color-picker/component.js +12 -2
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/picker.js +77 -1
- package/build/color-picker/picker.js.map +1 -1
- package/build/color-picker/styles.js +8 -8
- package/build/color-picker/styles.js.map +1 -1
- package/build/color-picker/types.js.map +1 -1
- package/build/composite/v2.js +43 -0
- package/build/composite/v2.js.map +1 -0
- package/build/confirm-dialog/component.js +74 -8
- package/build/confirm-dialog/component.js.map +1 -1
- package/build/confirm-dialog/types.js.map +1 -1
- package/build/custom-gradient-picker/gradient-bar/control-points.js +13 -4
- package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build/font-size-picker/utils.js +1 -1
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/modal/index.js +45 -16
- package/build/modal/index.js.map +1 -1
- package/build/palette-edit/index.js +4 -0
- package/build/palette-edit/index.js.map +1 -1
- package/build/popover/index.js +34 -6
- package/build/popover/index.js.map +1 -1
- package/build/private-apis.js +9 -1
- package/build/private-apis.js.map +1 -1
- package/build/progress-bar/styles.js +5 -5
- package/build/progress-bar/styles.js.map +1 -1
- package/build/sandbox/index.js +1 -1
- package/build/sandbox/index.js.map +1 -1
- package/build/sandbox/index.native.js +1 -1
- package/build/sandbox/index.native.js.map +1 -1
- package/build/tabs/context.js +16 -0
- package/build/tabs/context.js.map +1 -0
- package/build/tabs/index.js +147 -0
- package/build/tabs/index.js.map +1 -0
- package/build/tabs/styles.js +38 -0
- package/build/tabs/styles.js.map +1 -0
- package/build/tabs/tab.js +46 -0
- package/build/tabs/tab.js.map +1 -0
- package/build/tabs/tablist.js +47 -0
- package/build/tabs/tablist.js.map +1 -0
- package/build/tabs/tabpanel.js +48 -0
- package/build/tabs/tabpanel.js.map +1 -0
- package/build/tabs/types.js +6 -0
- package/build/tabs/types.js.map +1 -0
- package/build/text/component.js +7 -6
- package/build/text/component.js.map +1 -1
- package/build/text/hook.js +6 -15
- package/build/text/hook.js.map +1 -1
- package/build/text/index.js.map +1 -1
- package/build/text/styles.js +7 -7
- package/build/text/styles.js.map +1 -1
- package/build/text/types.js.map +1 -1
- package/build/text/utils.js +17 -33
- package/build/text/utils.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.js +1 -0
- package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build/toolbar/toolbar/index.js +17 -10
- package/build/toolbar/toolbar/index.js.map +1 -1
- package/build/toolbar/toolbar/types.js.map +1 -1
- package/build/tools-panel/tools-panel-item/hook.js +2 -2
- package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build/tools-panel/types.js.map +1 -1
- package/build/unit-control/utils.js +108 -0
- package/build/unit-control/utils.js.map +1 -1
- package/build/utils/unit-values.js +1 -1
- package/build/utils/unit-values.js.map +1 -1
- package/build-module/alignment-matrix-control/cell.js +7 -4
- package/build-module/alignment-matrix-control/cell.js.map +1 -1
- package/build-module/alignment-matrix-control/index.js +27 -43
- package/build-module/alignment-matrix-control/index.js.map +1 -1
- package/build-module/alignment-matrix-control/utils.js +29 -8
- package/build-module/alignment-matrix-control/utils.js.map +1 -1
- package/build-module/circular-option-picker/circular-option-picker-option.js +20 -39
- package/build-module/circular-option-picker/circular-option-picker-option.js.map +1 -1
- package/build-module/circular-option-picker/circular-option-picker.js +10 -31
- package/build-module/circular-option-picker/circular-option-picker.js.map +1 -1
- package/build-module/circular-option-picker/types.js.map +1 -1
- package/build-module/color-palette/index.js +7 -2
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-picker/component.js +13 -3
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/picker.js +78 -2
- package/build-module/color-picker/picker.js.map +1 -1
- package/build-module/color-picker/styles.js +8 -8
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/color-picker/types.js.map +1 -1
- package/build-module/composite/v2.js +15 -0
- package/build-module/composite/v2.js.map +1 -0
- package/build-module/confirm-dialog/component.js +72 -7
- package/build-module/confirm-dialog/component.js.map +1 -1
- package/build-module/confirm-dialog/types.js.map +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js +13 -4
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build-module/font-size-picker/utils.js +1 -1
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/modal/index.js +47 -18
- package/build-module/modal/index.js.map +1 -1
- package/build-module/palette-edit/index.js +4 -0
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/popover/index.js +34 -6
- package/build-module/popover/index.js.map +1 -1
- package/build-module/private-apis.js +9 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/progress-bar/styles.js +5 -5
- package/build-module/progress-bar/styles.js.map +1 -1
- package/build-module/sandbox/index.js +1 -1
- package/build-module/sandbox/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +1 -1
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/tabs/context.js +12 -0
- package/build-module/tabs/context.js.map +1 -0
- package/build-module/tabs/index.js +142 -0
- package/build-module/tabs/index.js.map +1 -0
- package/build-module/tabs/styles.js +36 -0
- package/build-module/tabs/styles.js.map +1 -0
- package/build-module/tabs/tab.js +43 -0
- package/build-module/tabs/tab.js.map +1 -0
- package/build-module/tabs/tablist.js +41 -0
- package/build-module/tabs/tablist.js.map +1 -0
- package/build-module/tabs/tabpanel.js +43 -0
- package/build-module/tabs/tabpanel.js.map +1 -0
- package/build-module/tabs/types.js +2 -0
- package/build-module/tabs/types.js.map +1 -0
- package/build-module/text/component.js +6 -6
- package/build-module/text/component.js.map +1 -1
- package/build-module/text/hook.js +11 -19
- package/build-module/text/hook.js.map +1 -1
- package/build-module/text/index.js.map +1 -1
- package/build-module/text/styles.js +7 -7
- package/build-module/text/styles.js.map +1 -1
- package/build-module/text/types.js.map +1 -1
- package/build-module/text/utils.js +17 -10
- package/build-module/text/utils.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +1 -0
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build-module/toolbar/toolbar/index.js +18 -11
- package/build-module/toolbar/toolbar/index.js.map +1 -1
- package/build-module/toolbar/toolbar/types.js.map +1 -1
- package/build-module/tools-panel/tools-panel-item/hook.js +2 -2
- package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build-module/tools-panel/types.js.map +1 -1
- package/build-module/unit-control/utils.js +108 -0
- package/build-module/unit-control/utils.js.map +1 -1
- package/build-module/utils/unit-values.js +1 -1
- package/build-module/utils/unit-values.js.map +1 -1
- package/build-style/style-rtl.css +16 -4
- package/build-style/style.css +16 -4
- package/build-types/alignment-matrix-control/cell.d.ts +1 -1
- package/build-types/alignment-matrix-control/cell.d.ts.map +1 -1
- package/build-types/alignment-matrix-control/index.d.ts.map +1 -1
- package/build-types/alignment-matrix-control/stories/index.story.d.ts.map +1 -1
- package/build-types/alignment-matrix-control/utils.d.ts +9 -9
- package/build-types/alignment-matrix-control/utils.d.ts.map +1 -1
- package/build-types/circular-option-picker/circular-option-picker-option.d.ts.map +1 -1
- package/build-types/circular-option-picker/circular-option-picker.d.ts.map +1 -1
- package/build-types/circular-option-picker/types.d.ts +4 -6
- package/build-types/circular-option-picker/types.d.ts.map +1 -1
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +1 -1
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +3 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/composite/v2.d.ts +12 -0
- package/build-types/composite/v2.d.ts.map +1 -0
- package/build-types/confirm-dialog/component.d.ts +70 -29
- package/build-types/confirm-dialog/component.d.ts.map +1 -1
- package/build-types/confirm-dialog/stories/index.story.d.ts +11 -0
- package/build-types/confirm-dialog/stories/index.story.d.ts.map +1 -0
- package/build-types/confirm-dialog/test/index.d.ts +2 -0
- package/build-types/confirm-dialog/test/index.d.ts.map +1 -0
- package/build-types/confirm-dialog/types.d.ts +32 -10
- package/build-types/confirm-dialog/types.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
- package/build-types/font-size-picker/utils.d.ts.map +1 -1
- package/build-types/heading/stories/index.story.d.ts.map +1 -1
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/popover/stories/e2e/index.story.d.ts +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/progress-bar/styles.d.ts.map +1 -1
- package/build-types/sandbox/index.d.ts.map +1 -1
- package/build-types/tabs/context.d.ts +8 -0
- package/build-types/tabs/context.d.ts.map +1 -0
- package/build-types/tabs/index.d.ts +13 -0
- package/build-types/tabs/index.d.ts.map +1 -0
- package/build-types/tabs/stories/index.story.d.ts +20 -0
- package/build-types/tabs/stories/index.story.d.ts.map +1 -0
- package/build-types/tabs/styles.d.ts +17 -0
- package/build-types/tabs/styles.d.ts.map +1 -0
- package/build-types/tabs/tab.d.ts +10 -0
- package/build-types/tabs/tab.d.ts.map +1 -0
- package/build-types/tabs/tablist.d.ts +7 -0
- package/build-types/tabs/tablist.d.ts.map +1 -0
- package/build-types/tabs/tabpanel.d.ts +7 -0
- package/build-types/tabs/tabpanel.d.ts.map +1 -0
- package/build-types/tabs/test/index.d.ts +2 -0
- package/build-types/tabs/test/index.d.ts.map +1 -0
- package/build-types/tabs/types.d.ts +134 -0
- package/build-types/tabs/types.d.ts.map +1 -0
- package/build-types/text/component.d.ts +4 -2
- package/build-types/text/component.d.ts.map +1 -1
- package/build-types/text/hook.d.ts +171 -165
- package/build-types/text/hook.d.ts.map +1 -1
- package/build-types/text/index.d.ts +2 -2
- package/build-types/text/index.d.ts.map +1 -1
- package/build-types/text/stories/index.story.d.ts +21 -0
- package/build-types/text/stories/index.story.d.ts.map +1 -0
- package/build-types/text/styles.d.ts +7 -7
- package/build-types/text/styles.d.ts.map +1 -1
- package/build-types/text/types.d.ts +1 -1
- package/build-types/text/types.d.ts.map +1 -1
- package/build-types/text/utils.d.ts +56 -61
- package/build-types/text/utils.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
- package/build-types/toolbar/stories/index.story.d.ts +5 -0
- package/build-types/toolbar/stories/index.story.d.ts.map +1 -1
- package/build-types/toolbar/toolbar/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar/types.d.ts +10 -0
- package/build-types/toolbar/toolbar/types.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +2 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/unit-control/utils.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/alignment-matrix-control/cell.tsx +6 -2
- package/src/alignment-matrix-control/index.tsx +31 -54
- package/src/alignment-matrix-control/stories/index.story.tsx +3 -7
- package/src/alignment-matrix-control/test/index.tsx +117 -18
- package/src/alignment-matrix-control/utils.tsx +33 -9
- package/src/button/style.scss +1 -2
- package/src/circular-option-picker/circular-option-picker-option.tsx +24 -38
- package/src/circular-option-picker/circular-option-picker.tsx +11 -28
- package/src/circular-option-picker/types.ts +6 -5
- package/src/color-palette/index.tsx +6 -1
- package/src/color-picker/component.tsx +25 -3
- package/src/color-picker/picker.tsx +96 -2
- package/src/color-picker/styles.ts +0 -1
- package/src/color-picker/types.ts +3 -0
- package/src/composite/v2.ts +22 -0
- package/src/confirm-dialog/README.md +1 -1
- package/src/confirm-dialog/component.tsx +79 -13
- package/src/confirm-dialog/stories/{index.story.js → index.story.tsx} +26 -24
- package/src/confirm-dialog/test/{index.js → index.tsx} +3 -3
- package/src/confirm-dialog/types.ts +32 -12
- package/src/custom-gradient-picker/gradient-bar/control-points.tsx +32 -25
- package/src/font-size-picker/utils.ts +2 -1
- package/src/heading/stories/index.story.tsx +2 -4
- package/src/modal/index.tsx +58 -22
- package/src/modal/test/index.tsx +29 -0
- package/src/notice/style.scss +0 -1
- package/src/palette-edit/index.tsx +4 -0
- package/src/popover/index.tsx +99 -57
- package/src/popover/style.scss +9 -0
- package/src/private-apis.ts +15 -1
- package/src/progress-bar/styles.ts +19 -4
- package/src/sandbox/index.native.js +1 -1
- package/src/sandbox/index.tsx +3 -1
- package/src/tabs/README.md +242 -0
- package/src/tabs/context.ts +13 -0
- package/src/tabs/index.tsx +167 -0
- package/src/tabs/stories/index.story.tsx +352 -0
- package/src/tabs/styles.ts +103 -0
- package/src/tabs/tab.tsx +39 -0
- package/src/tabs/tablist.tsx +40 -0
- package/src/tabs/tabpanel.tsx +42 -0
- package/src/tabs/test/index.tsx +1124 -0
- package/src/tabs/types.ts +142 -0
- package/src/text/README.md +2 -2
- package/src/text/{component.js → component.tsx} +10 -6
- package/src/text/{hook.js → hook.ts} +12 -15
- package/src/text/stories/index.story.tsx +80 -0
- package/src/text/types.ts +1 -6
- package/src/text/{utils.js → utils.ts} +40 -14
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +8 -0
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +1 -0
- package/src/toolbar/stories/index.story.tsx +15 -0
- package/src/toolbar/test/index.tsx +8 -0
- package/src/toolbar/toolbar/README.md +9 -0
- package/src/toolbar/toolbar/index.tsx +21 -12
- package/src/toolbar/toolbar/style.scss +9 -0
- package/src/toolbar/toolbar/types.ts +10 -0
- package/src/tools-panel/tools-panel/README.md +3 -0
- package/src/tools-panel/tools-panel-item/hook.ts +4 -6
- package/src/tools-panel/types.ts +2 -0
- package/src/unit-control/utils.ts +124 -0
- package/src/utils/unit-values.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/src/text/stories/index.story.js +0 -53
- /package/src/text/{index.js → index.ts} +0 -0
- /package/src/text/{styles.js → styles.ts} +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line no-restricted-imports
|
|
5
|
+
import * as Ariakit from '@ariakit/react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
11
|
+
import { useEffect, useLayoutEffect, useRef } from '@wordpress/element';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import type { TabsProps } from './types';
|
|
17
|
+
import { TabsContext } from './context';
|
|
18
|
+
import { Tab } from './tab';
|
|
19
|
+
import { TabList } from './tablist';
|
|
20
|
+
import { TabPanel } from './tabpanel';
|
|
21
|
+
|
|
22
|
+
function Tabs( {
|
|
23
|
+
selectOnMove = true,
|
|
24
|
+
initialTabId,
|
|
25
|
+
orientation = 'horizontal',
|
|
26
|
+
onSelect,
|
|
27
|
+
children,
|
|
28
|
+
selectedTabId,
|
|
29
|
+
}: TabsProps ) {
|
|
30
|
+
const instanceId = useInstanceId( Tabs, 'tabs' );
|
|
31
|
+
const store = Ariakit.useTabStore( {
|
|
32
|
+
selectOnMove,
|
|
33
|
+
orientation,
|
|
34
|
+
defaultSelectedId: initialTabId && `${ instanceId }-${ initialTabId }`,
|
|
35
|
+
setSelectedId: ( selectedId ) => {
|
|
36
|
+
const strippedDownId =
|
|
37
|
+
typeof selectedId === 'string'
|
|
38
|
+
? selectedId.replace( `${ instanceId }-`, '' )
|
|
39
|
+
: selectedId;
|
|
40
|
+
onSelect?.( strippedDownId );
|
|
41
|
+
},
|
|
42
|
+
selectedId: selectedTabId && `${ instanceId }-${ selectedTabId }`,
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
const isControlled = selectedTabId !== undefined;
|
|
46
|
+
|
|
47
|
+
const { items, selectedId } = store.useState();
|
|
48
|
+
const { setSelectedId } = store;
|
|
49
|
+
|
|
50
|
+
// Keep track of whether tabs have been populated. This is used to prevent
|
|
51
|
+
// certain effects from firing too early while tab data and relevant
|
|
52
|
+
// variables are undefined during the initial render.
|
|
53
|
+
const tabsHavePopulated = useRef( false );
|
|
54
|
+
if ( items.length > 0 ) {
|
|
55
|
+
tabsHavePopulated.current = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const selectedTab = items.find( ( item ) => item.id === selectedId );
|
|
59
|
+
const firstEnabledTab = items.find( ( item ) => {
|
|
60
|
+
// Ariakit internally refers to disabled tabs as `dimmed`.
|
|
61
|
+
return ! item.dimmed;
|
|
62
|
+
} );
|
|
63
|
+
const initialTab = items.find(
|
|
64
|
+
( item ) => item.id === `${ instanceId }-${ initialTabId }`
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Handle selecting the initial tab.
|
|
68
|
+
useLayoutEffect( () => {
|
|
69
|
+
if ( isControlled ) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Wait for the denoted initial tab to be declared before making a
|
|
74
|
+
// selection. This ensures that if a tab is declared lazily it can
|
|
75
|
+
// still receive initial selection, as well as ensuring no tab is
|
|
76
|
+
// selected if an invalid `initialTabId` is provided.
|
|
77
|
+
if ( initialTabId && ! initialTab ) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// If the currently selected tab is missing (i.e. removed from the DOM),
|
|
82
|
+
// fall back to the initial tab or the first enabled tab if there is
|
|
83
|
+
// one. Otherwise, no tab should be selected.
|
|
84
|
+
if ( ! items.find( ( item ) => item.id === selectedId ) ) {
|
|
85
|
+
if ( initialTab && ! initialTab.dimmed ) {
|
|
86
|
+
setSelectedId( initialTab?.id );
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if ( firstEnabledTab ) {
|
|
91
|
+
setSelectedId( firstEnabledTab.id );
|
|
92
|
+
} else if ( tabsHavePopulated.current ) {
|
|
93
|
+
setSelectedId( null );
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, [
|
|
97
|
+
firstEnabledTab,
|
|
98
|
+
initialTab,
|
|
99
|
+
initialTabId,
|
|
100
|
+
isControlled,
|
|
101
|
+
items,
|
|
102
|
+
selectedId,
|
|
103
|
+
setSelectedId,
|
|
104
|
+
] );
|
|
105
|
+
|
|
106
|
+
// Handle the currently selected tab becoming disabled.
|
|
107
|
+
useEffect( () => {
|
|
108
|
+
if ( ! selectedTab?.dimmed ) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// In controlled mode, we trust that disabling tabs is done
|
|
113
|
+
// intentionally, and don't select a new tab automatically.
|
|
114
|
+
if ( isControlled ) {
|
|
115
|
+
setSelectedId( null );
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// If the currently selected tab becomes disabled, fall back to the
|
|
120
|
+
// `initialTabId` if possible. Otherwise select the first
|
|
121
|
+
// enabled tab (if there is one).
|
|
122
|
+
if ( initialTab && ! initialTab.dimmed ) {
|
|
123
|
+
setSelectedId( initialTab.id );
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ( firstEnabledTab ) {
|
|
128
|
+
setSelectedId( firstEnabledTab.id );
|
|
129
|
+
}
|
|
130
|
+
}, [
|
|
131
|
+
firstEnabledTab,
|
|
132
|
+
initialTab,
|
|
133
|
+
isControlled,
|
|
134
|
+
selectedTab?.dimmed,
|
|
135
|
+
setSelectedId,
|
|
136
|
+
] );
|
|
137
|
+
|
|
138
|
+
// Clear `selectedId` if the active tab is removed from the DOM in controlled mode.
|
|
139
|
+
useEffect( () => {
|
|
140
|
+
if ( ! isControlled ) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Once the tabs have populated, if the `selectedTabId` still can't be
|
|
145
|
+
// found, clear the selection.
|
|
146
|
+
if ( tabsHavePopulated.current && !! selectedTabId && ! selectedTab ) {
|
|
147
|
+
setSelectedId( null );
|
|
148
|
+
}
|
|
149
|
+
}, [
|
|
150
|
+
isControlled,
|
|
151
|
+
selectedId,
|
|
152
|
+
selectedTab,
|
|
153
|
+
selectedTabId,
|
|
154
|
+
setSelectedId,
|
|
155
|
+
] );
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<TabsContext.Provider value={ { store, instanceId } }>
|
|
159
|
+
{ children }
|
|
160
|
+
</TabsContext.Provider>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
Tabs.TabList = TabList;
|
|
165
|
+
Tabs.Tab = Tab;
|
|
166
|
+
Tabs.TabPanel = TabPanel;
|
|
167
|
+
export default Tabs;
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Meta, StoryFn } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { wordpress, more, link } from '@wordpress/icons';
|
|
10
|
+
import { useState } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import Tabs from '..';
|
|
16
|
+
import { Slot, Fill, Provider as SlotFillProvider } from '../../slot-fill';
|
|
17
|
+
import DropdownMenu from '../../dropdown-menu';
|
|
18
|
+
import Button from '../../button';
|
|
19
|
+
|
|
20
|
+
const meta: Meta< typeof Tabs > = {
|
|
21
|
+
title: 'Components (Experimental)/Tabs',
|
|
22
|
+
component: Tabs,
|
|
23
|
+
parameters: {
|
|
24
|
+
actions: { argTypesRegex: '^on.*' },
|
|
25
|
+
controls: { expanded: true },
|
|
26
|
+
docs: { canvas: { sourceState: 'shown' } },
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export default meta;
|
|
30
|
+
|
|
31
|
+
const Template: StoryFn< typeof Tabs > = ( props ) => {
|
|
32
|
+
return (
|
|
33
|
+
<Tabs { ...props }>
|
|
34
|
+
<Tabs.TabList>
|
|
35
|
+
<Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab>
|
|
36
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
37
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
38
|
+
</Tabs.TabList>
|
|
39
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
40
|
+
<p>Selected tab: Tab 1</p>
|
|
41
|
+
</Tabs.TabPanel>
|
|
42
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
43
|
+
<p>Selected tab: Tab 2</p>
|
|
44
|
+
</Tabs.TabPanel>
|
|
45
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
46
|
+
<p>Selected tab: Tab 3</p>
|
|
47
|
+
</Tabs.TabPanel>
|
|
48
|
+
</Tabs>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const Default = Template.bind( {} );
|
|
53
|
+
|
|
54
|
+
const DisabledTabTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
55
|
+
return (
|
|
56
|
+
<Tabs { ...props }>
|
|
57
|
+
<Tabs.TabList>
|
|
58
|
+
<Tabs.Tab id={ 'tab1' } disabled={ true }>
|
|
59
|
+
Tab 1
|
|
60
|
+
</Tabs.Tab>
|
|
61
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
62
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
63
|
+
</Tabs.TabList>
|
|
64
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
65
|
+
<p>Selected tab: Tab 1</p>
|
|
66
|
+
</Tabs.TabPanel>
|
|
67
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
68
|
+
<p>Selected tab: Tab 2</p>
|
|
69
|
+
</Tabs.TabPanel>
|
|
70
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
71
|
+
<p>Selected tab: Tab 3</p>
|
|
72
|
+
</Tabs.TabPanel>
|
|
73
|
+
</Tabs>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
export const DisabledTab = DisabledTabTemplate.bind( {} );
|
|
77
|
+
|
|
78
|
+
const WithTabIconsAndTooltipsTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
79
|
+
return (
|
|
80
|
+
<Tabs { ...props }>
|
|
81
|
+
<Tabs.TabList>
|
|
82
|
+
<Tabs.Tab
|
|
83
|
+
id={ 'tab1' }
|
|
84
|
+
render={
|
|
85
|
+
<Button icon={ wordpress } label="Tab 1" showTooltip />
|
|
86
|
+
}
|
|
87
|
+
/>
|
|
88
|
+
<Tabs.Tab
|
|
89
|
+
id={ 'tab2' }
|
|
90
|
+
render={
|
|
91
|
+
<Button icon={ link } label="Tab 2" showTooltip />
|
|
92
|
+
}
|
|
93
|
+
/>
|
|
94
|
+
<Tabs.Tab
|
|
95
|
+
id={ 'tab3' }
|
|
96
|
+
render={
|
|
97
|
+
<Button icon={ more } label="Tab 3" showTooltip />
|
|
98
|
+
}
|
|
99
|
+
/>
|
|
100
|
+
</Tabs.TabList>
|
|
101
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
102
|
+
<p>Selected tab: Tab 1</p>
|
|
103
|
+
</Tabs.TabPanel>
|
|
104
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
105
|
+
<p>Selected tab: Tab 2</p>
|
|
106
|
+
</Tabs.TabPanel>
|
|
107
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
108
|
+
<p>Selected tab: Tab 3</p>
|
|
109
|
+
</Tabs.TabPanel>
|
|
110
|
+
</Tabs>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
export const WithTabIconsAndTooltips = WithTabIconsAndTooltipsTemplate.bind(
|
|
114
|
+
{}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
export const ManualActivation = Template.bind( {} );
|
|
118
|
+
ManualActivation.args = {
|
|
119
|
+
selectOnMove: false,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const UsingSlotFillTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
123
|
+
return (
|
|
124
|
+
<SlotFillProvider>
|
|
125
|
+
<Tabs { ...props }>
|
|
126
|
+
<Tabs.TabList>
|
|
127
|
+
<Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab>
|
|
128
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
129
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
130
|
+
</Tabs.TabList>
|
|
131
|
+
<Fill name="tabs-are-fun">
|
|
132
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
133
|
+
<p>Selected tab: Tab 1</p>
|
|
134
|
+
</Tabs.TabPanel>
|
|
135
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
136
|
+
<p>Selected tab: Tab 2</p>
|
|
137
|
+
</Tabs.TabPanel>
|
|
138
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
139
|
+
<p>Selected tab: Tab 3</p>
|
|
140
|
+
</Tabs.TabPanel>
|
|
141
|
+
</Fill>
|
|
142
|
+
</Tabs>
|
|
143
|
+
<div
|
|
144
|
+
style={ {
|
|
145
|
+
border: '2px solid #999',
|
|
146
|
+
width: '300px',
|
|
147
|
+
margin: '20px auto',
|
|
148
|
+
} }
|
|
149
|
+
>
|
|
150
|
+
<p>other stuff</p>
|
|
151
|
+
<p>other stuff</p>
|
|
152
|
+
<p>this is fun!</p>
|
|
153
|
+
<p>other stuff</p>
|
|
154
|
+
<Slot bubblesVirtually as="div" name="tabs-are-fun" />
|
|
155
|
+
</div>
|
|
156
|
+
</SlotFillProvider>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
export const UsingSlotFill = UsingSlotFillTemplate.bind( {} );
|
|
160
|
+
UsingSlotFill.storyName = 'Using SlotFill';
|
|
161
|
+
|
|
162
|
+
const CloseButtonTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
163
|
+
const [ isOpen, setIsOpen ] = useState( true );
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<>
|
|
167
|
+
{ isOpen ? (
|
|
168
|
+
<div
|
|
169
|
+
style={ {
|
|
170
|
+
width: '400px',
|
|
171
|
+
height: '100vh',
|
|
172
|
+
borderRight: '1px solid #333',
|
|
173
|
+
} }
|
|
174
|
+
>
|
|
175
|
+
<Tabs { ...props }>
|
|
176
|
+
<div
|
|
177
|
+
style={ {
|
|
178
|
+
display: 'flex',
|
|
179
|
+
borderBottom: '1px solid #333',
|
|
180
|
+
} }
|
|
181
|
+
>
|
|
182
|
+
<Tabs.TabList>
|
|
183
|
+
<Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab>
|
|
184
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
185
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
186
|
+
</Tabs.TabList>
|
|
187
|
+
<Button
|
|
188
|
+
variant={ 'tertiary' }
|
|
189
|
+
style={ {
|
|
190
|
+
marginLeft: 'auto',
|
|
191
|
+
alignSelf: 'center',
|
|
192
|
+
} }
|
|
193
|
+
onClick={ () => setIsOpen( false ) }
|
|
194
|
+
>
|
|
195
|
+
Close Tabs
|
|
196
|
+
</Button>
|
|
197
|
+
</div>
|
|
198
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
199
|
+
<p>Selected tab: Tab 1</p>
|
|
200
|
+
</Tabs.TabPanel>
|
|
201
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
202
|
+
<p>Selected tab: Tab 2</p>
|
|
203
|
+
</Tabs.TabPanel>
|
|
204
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
205
|
+
<p>Selected tab: Tab 3</p>
|
|
206
|
+
</Tabs.TabPanel>
|
|
207
|
+
</Tabs>
|
|
208
|
+
</div>
|
|
209
|
+
) : (
|
|
210
|
+
<Button
|
|
211
|
+
variant={ 'tertiary' }
|
|
212
|
+
onClick={ () => setIsOpen( true ) }
|
|
213
|
+
>
|
|
214
|
+
Open Tabs
|
|
215
|
+
</Button>
|
|
216
|
+
) }
|
|
217
|
+
</>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
export const InsertCustomElements = CloseButtonTemplate.bind( {} );
|
|
221
|
+
|
|
222
|
+
const ControlledModeTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
223
|
+
const [ selectedTabId, setSelectedTabId ] = useState<
|
|
224
|
+
string | undefined | null
|
|
225
|
+
>( props.selectedTabId );
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
<Tabs
|
|
230
|
+
{ ...props }
|
|
231
|
+
selectedTabId={ selectedTabId }
|
|
232
|
+
onSelect={ ( selectedId ) => {
|
|
233
|
+
setSelectedTabId( selectedId );
|
|
234
|
+
props.onSelect?.( selectedId );
|
|
235
|
+
} }
|
|
236
|
+
>
|
|
237
|
+
<Tabs.TabList>
|
|
238
|
+
<Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab>
|
|
239
|
+
|
|
240
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
241
|
+
|
|
242
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
243
|
+
</Tabs.TabList>
|
|
244
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
245
|
+
<p>Selected tab: Tab 1</p>
|
|
246
|
+
</Tabs.TabPanel>
|
|
247
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
248
|
+
<p>Selected tab: Tab 2</p>
|
|
249
|
+
</Tabs.TabPanel>
|
|
250
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
251
|
+
<p>Selected tab: Tab 3</p>
|
|
252
|
+
</Tabs.TabPanel>
|
|
253
|
+
</Tabs>
|
|
254
|
+
{
|
|
255
|
+
<div style={ { marginTop: '200px' } }>
|
|
256
|
+
<p>Select a tab:</p>
|
|
257
|
+
<DropdownMenu
|
|
258
|
+
controls={ [
|
|
259
|
+
{
|
|
260
|
+
onClick: () => setSelectedTabId( 'tab1' ),
|
|
261
|
+
title: 'Tab 1',
|
|
262
|
+
isActive: selectedTabId === 'tab1',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
onClick: () => setSelectedTabId( 'tab2' ),
|
|
266
|
+
title: 'Tab 2',
|
|
267
|
+
isActive: selectedTabId === 'tab2',
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
onClick: () => setSelectedTabId( 'tab3' ),
|
|
271
|
+
title: 'Tab 3',
|
|
272
|
+
isActive: selectedTabId === 'tab3',
|
|
273
|
+
},
|
|
274
|
+
] }
|
|
275
|
+
label="Choose a tab. The power is yours."
|
|
276
|
+
/>
|
|
277
|
+
</div>
|
|
278
|
+
}
|
|
279
|
+
</>
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export const ControlledMode = ControlledModeTemplate.bind( {} );
|
|
284
|
+
ControlledMode.args = {
|
|
285
|
+
selectedTabId: 'tab3',
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const TabBecomesDisabledTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
289
|
+
const [ disableTab2, setDisableTab2 ] = useState( false );
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<>
|
|
293
|
+
<Button
|
|
294
|
+
variant="primary"
|
|
295
|
+
onClick={ () => setDisableTab2( ! disableTab2 ) }
|
|
296
|
+
>
|
|
297
|
+
{ disableTab2 ? 'Enable' : 'Disable' } Tab 2
|
|
298
|
+
</Button>
|
|
299
|
+
<Tabs { ...props }>
|
|
300
|
+
<Tabs.TabList>
|
|
301
|
+
<Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab>
|
|
302
|
+
<Tabs.Tab id={ 'tab2' } disabled={ disableTab2 }>
|
|
303
|
+
Tab 2
|
|
304
|
+
</Tabs.Tab>
|
|
305
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
306
|
+
</Tabs.TabList>
|
|
307
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
308
|
+
<p>Selected tab: Tab 1</p>
|
|
309
|
+
</Tabs.TabPanel>
|
|
310
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
311
|
+
<p>Selected tab: Tab 2</p>
|
|
312
|
+
</Tabs.TabPanel>
|
|
313
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
314
|
+
<p>Selected tab: Tab 3</p>
|
|
315
|
+
</Tabs.TabPanel>
|
|
316
|
+
</Tabs>
|
|
317
|
+
</>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
export const TabBecomesDisabled = TabBecomesDisabledTemplate.bind( {} );
|
|
321
|
+
|
|
322
|
+
const TabGetsRemovedTemplate: StoryFn< typeof Tabs > = ( props ) => {
|
|
323
|
+
const [ removeTab1, setRemoveTab1 ] = useState( false );
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<>
|
|
327
|
+
<Button
|
|
328
|
+
variant="primary"
|
|
329
|
+
onClick={ () => setRemoveTab1( ! removeTab1 ) }
|
|
330
|
+
>
|
|
331
|
+
{ removeTab1 ? 'Restore' : 'Remove' } Tab 1
|
|
332
|
+
</Button>
|
|
333
|
+
<Tabs { ...props }>
|
|
334
|
+
<Tabs.TabList>
|
|
335
|
+
{ ! removeTab1 && <Tabs.Tab id={ 'tab1' }>Tab 1</Tabs.Tab> }
|
|
336
|
+
<Tabs.Tab id={ 'tab2' }>Tab 2</Tabs.Tab>
|
|
337
|
+
<Tabs.Tab id={ 'tab3' }>Tab 3</Tabs.Tab>
|
|
338
|
+
</Tabs.TabList>
|
|
339
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
340
|
+
<p>Selected tab: Tab 1</p>
|
|
341
|
+
</Tabs.TabPanel>
|
|
342
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
343
|
+
<p>Selected tab: Tab 2</p>
|
|
344
|
+
</Tabs.TabPanel>
|
|
345
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
346
|
+
<p>Selected tab: Tab 3</p>
|
|
347
|
+
</Tabs.TabPanel>
|
|
348
|
+
</Tabs>
|
|
349
|
+
</>
|
|
350
|
+
);
|
|
351
|
+
};
|
|
352
|
+
export const TabGetsRemoved = TabGetsRemovedTemplate.bind( {} );
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import styled from '@emotion/styled';
|
|
5
|
+
// eslint-disable-next-line no-restricted-imports
|
|
6
|
+
import * as Ariakit from '@ariakit/react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { COLORS } from '../utils';
|
|
12
|
+
import { space } from '../utils/space';
|
|
13
|
+
import { reduceMotion } from '../utils/reduce-motion';
|
|
14
|
+
|
|
15
|
+
export const TabListWrapper = styled.div`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: stretch;
|
|
18
|
+
flex-direction: row;
|
|
19
|
+
&[aria-orientation='vertical'] {
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
export const Tab = styled( Ariakit.Tab )`
|
|
25
|
+
&& {
|
|
26
|
+
position: relative;
|
|
27
|
+
border-radius: 0;
|
|
28
|
+
height: ${ space( 12 ) };
|
|
29
|
+
background: transparent;
|
|
30
|
+
border: none;
|
|
31
|
+
box-shadow: none;
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
padding: 3px ${ space( 4 ) }; // Use padding to offset the [aria-selected="true"] border, this benefits Windows High Contrast mode
|
|
34
|
+
margin-left: 0;
|
|
35
|
+
font-weight: 500;
|
|
36
|
+
|
|
37
|
+
&[aria-disabled='true'] {
|
|
38
|
+
cursor: default;
|
|
39
|
+
opacity: 0.3;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&:focus:not( :disabled ) {
|
|
43
|
+
position: relative;
|
|
44
|
+
box-shadow: none;
|
|
45
|
+
outline: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Tab indicator
|
|
49
|
+
&::after {
|
|
50
|
+
content: '';
|
|
51
|
+
position: absolute;
|
|
52
|
+
right: 0;
|
|
53
|
+
bottom: 0;
|
|
54
|
+
left: 0;
|
|
55
|
+
pointer-events: none;
|
|
56
|
+
|
|
57
|
+
// Draw the indicator.
|
|
58
|
+
background: ${ COLORS.theme.accent };
|
|
59
|
+
height: calc( 0 * var( --wp-admin-border-width-focus ) );
|
|
60
|
+
border-radius: 0;
|
|
61
|
+
|
|
62
|
+
// Animation
|
|
63
|
+
transition: all 0.1s linear;
|
|
64
|
+
${ reduceMotion( 'transition' ) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Active.
|
|
68
|
+
&[aria-selected='true']::after {
|
|
69
|
+
height: calc( 1 * var( --wp-admin-border-width-focus ) );
|
|
70
|
+
|
|
71
|
+
// Windows high contrast mode.
|
|
72
|
+
outline: 2px solid transparent;
|
|
73
|
+
outline-offset: -1px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Focus.
|
|
77
|
+
&::before {
|
|
78
|
+
content: '';
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: ${ space( 3 ) };
|
|
81
|
+
right: ${ space( 3 ) };
|
|
82
|
+
bottom: ${ space( 3 ) };
|
|
83
|
+
left: ${ space( 3 ) };
|
|
84
|
+
pointer-events: none;
|
|
85
|
+
|
|
86
|
+
// Draw the indicator.
|
|
87
|
+
box-shadow: 0 0 0 0 transparent;
|
|
88
|
+
border-radius: 2px;
|
|
89
|
+
|
|
90
|
+
// Animation
|
|
91
|
+
transition: all 0.1s linear;
|
|
92
|
+
${ reduceMotion( 'transition' ) };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&:focus-visible::before {
|
|
96
|
+
box-shadow: 0 0 0 var( --wp-admin-border-width-focus )
|
|
97
|
+
${ COLORS.theme.accent };
|
|
98
|
+
|
|
99
|
+
// Windows high contrast mode.
|
|
100
|
+
outline: 2px solid transparent;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`;
|
package/src/tabs/tab.tsx
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useContext, forwardRef } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import type { TabProps } from './types';
|
|
11
|
+
import warning from '@wordpress/warning';
|
|
12
|
+
import { TabsContext } from './context';
|
|
13
|
+
import { Tab as StyledTab } from './styles';
|
|
14
|
+
|
|
15
|
+
export const Tab = forwardRef< HTMLButtonElement, TabProps >( function Tab(
|
|
16
|
+
{ children, id, className, disabled, render, style },
|
|
17
|
+
ref
|
|
18
|
+
) {
|
|
19
|
+
const context = useContext( TabsContext );
|
|
20
|
+
if ( ! context ) {
|
|
21
|
+
warning( '`Tabs.TabList` must be wrapped in a `Tabs` component.' );
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const { store, instanceId } = context;
|
|
25
|
+
const instancedTabId = `${ instanceId }-${ id }`;
|
|
26
|
+
return (
|
|
27
|
+
<StyledTab
|
|
28
|
+
ref={ ref }
|
|
29
|
+
store={ store }
|
|
30
|
+
id={ instancedTabId }
|
|
31
|
+
className={ className }
|
|
32
|
+
style={ style }
|
|
33
|
+
disabled={ disabled }
|
|
34
|
+
render={ render }
|
|
35
|
+
>
|
|
36
|
+
{ children }
|
|
37
|
+
</StyledTab>
|
|
38
|
+
);
|
|
39
|
+
} );
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line no-restricted-imports
|
|
5
|
+
import * as Ariakit from '@ariakit/react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import warning from '@wordpress/warning';
|
|
11
|
+
import { forwardRef } from '@wordpress/element';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import type { TabListProps } from './types';
|
|
17
|
+
import { useTabsContext } from './context';
|
|
18
|
+
import { TabListWrapper } from './styles';
|
|
19
|
+
|
|
20
|
+
export const TabList = forwardRef< HTMLDivElement, TabListProps >(
|
|
21
|
+
function TabList( { children, className, style }, ref ) {
|
|
22
|
+
const context = useTabsContext();
|
|
23
|
+
if ( ! context ) {
|
|
24
|
+
warning( '`Tabs.TabList` must be wrapped in a `Tabs` component.' );
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const { store } = context;
|
|
28
|
+
return (
|
|
29
|
+
<Ariakit.TabList
|
|
30
|
+
ref={ ref }
|
|
31
|
+
style={ style }
|
|
32
|
+
store={ store }
|
|
33
|
+
className={ className }
|
|
34
|
+
render={ <TabListWrapper /> }
|
|
35
|
+
>
|
|
36
|
+
{ children }
|
|
37
|
+
</Ariakit.TabList>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
);
|