@wordpress/components 25.9.1 → 25.11.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 +48 -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/autocomplete/index.js +104 -52
- package/build/autocomplete/index.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/dropdown-menu-v2-ariakit/index.js +217 -0
- package/build/dropdown-menu-v2-ariakit/index.js.map +1 -0
- package/build/dropdown-menu-v2-ariakit/styles.js +157 -0
- package/build/dropdown-menu-v2-ariakit/styles.js.map +1 -0
- package/build/dropdown-menu-v2-ariakit/types.js +6 -0
- package/build/dropdown-menu-v2-ariakit/types.js.map +1 -0
- package/build/font-size-picker/utils.js +1 -1
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/input-control/styles/input-control-styles.js +23 -23
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/mobile/global-styles-context/utils.native.js +1 -1
- package/build/mobile/global-styles-context/utils.native.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 +18 -2
- 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/select-control/styles/select-control-styles.js +8 -8
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.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/tooltip/index.js +2 -2
- package/build/tooltip/index.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/autocomplete/index.js +104 -52
- package/build-module/autocomplete/index.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/dropdown-menu-v2-ariakit/index.js +199 -0
- package/build-module/dropdown-menu-v2-ariakit/index.js.map +1 -0
- package/build-module/dropdown-menu-v2-ariakit/styles.js +136 -0
- package/build-module/dropdown-menu-v2-ariakit/styles.js.map +1 -0
- package/build-module/dropdown-menu-v2-ariakit/types.js +2 -0
- package/build-module/dropdown-menu-v2-ariakit/types.js.map +1 -0
- package/build-module/font-size-picker/utils.js +1 -1
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/input-control/styles/input-control-styles.js +23 -23
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/mobile/global-styles-context/utils.native.js +2 -2
- package/build-module/mobile/global-styles-context/utils.native.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 +18 -2
- 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/select-control/styles/select-control-styles.js +8 -8
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.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/tooltip/index.js +2 -2
- package/build-module/tooltip/index.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 +17 -5
- package/build-style/style.css +17 -5
- 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/autocomplete/index.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/dropdown-menu-v2-ariakit/index.d.ts +11 -0
- package/build-types/dropdown-menu-v2-ariakit/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts +16 -0
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts +88 -0
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts +2 -0
- package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts +174 -0
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts.map +1 -0
- 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/tooltip/index.d.ts.map +1 -1
- package/build-types/unit-control/utils.d.ts.map +1 -1
- package/package.json +21 -20
- 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/autocomplete/index.tsx +136 -77
- 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/dimension-control/test/__snapshots__/index.test.js.snap +8 -8
- package/src/dropdown-menu-v2-ariakit/README.md +324 -0
- package/src/dropdown-menu-v2-ariakit/index.tsx +318 -0
- package/src/dropdown-menu-v2-ariakit/stories/index.story.tsx +506 -0
- package/src/dropdown-menu-v2-ariakit/styles.ts +297 -0
- package/src/dropdown-menu-v2-ariakit/test/index.tsx +1139 -0
- package/src/dropdown-menu-v2-ariakit/types.ts +186 -0
- package/src/font-size-picker/utils.ts +2 -1
- package/src/heading/stories/index.story.tsx +2 -4
- package/src/input-control/styles/input-control-styles.tsx +2 -2
- package/src/mobile/global-styles-context/utils.native.js +2 -2
- 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 +31 -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/select-control/styles/select-control-styles.ts +2 -2
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.tsx +1 -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 +1133 -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 +16 -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/tooltip/index.tsx +2 -3
- 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
package/src/private-apis.ts
CHANGED
|
@@ -6,6 +6,13 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
+
import {
|
|
10
|
+
Composite as CompositeV2,
|
|
11
|
+
CompositeGroup as CompositeGroupV2,
|
|
12
|
+
CompositeItem as CompositeItemV2,
|
|
13
|
+
CompositeRow as CompositeRowV2,
|
|
14
|
+
useCompositeStore as useCompositeStoreV2,
|
|
15
|
+
} from './composite/v2';
|
|
9
16
|
import { default as CustomSelectControl } from './custom-select-control';
|
|
10
17
|
import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';
|
|
11
18
|
import { default as ProgressBar } from './progress-bar';
|
|
@@ -22,17 +29,32 @@ import {
|
|
|
22
29
|
DropdownSubMenu as DropdownSubMenuV2,
|
|
23
30
|
DropdownSubMenuTrigger as DropdownSubMenuTriggerV2,
|
|
24
31
|
} from './dropdown-menu-v2';
|
|
32
|
+
import {
|
|
33
|
+
DropdownMenu as DropdownMenuV2Ariakit,
|
|
34
|
+
DropdownMenuGroup as DropdownMenuGroupV2Ariakit,
|
|
35
|
+
DropdownMenuGroupLabel as DropdownMenuGroupLabelV2Ariakit,
|
|
36
|
+
DropdownMenuItem as DropdownMenuItemV2Ariakit,
|
|
37
|
+
DropdownMenuCheckboxItem as DropdownMenuCheckboxItemV2Ariakit,
|
|
38
|
+
DropdownMenuRadioItem as DropdownMenuRadioItemV2Ariakit,
|
|
39
|
+
DropdownMenuSeparator as DropdownMenuSeparatorV2Ariakit,
|
|
40
|
+
} from './dropdown-menu-v2-ariakit';
|
|
25
41
|
import { ComponentsContext } from './context/context-system-provider';
|
|
26
42
|
import Theme from './theme';
|
|
43
|
+
import Tabs from './tabs';
|
|
27
44
|
|
|
28
45
|
export const { lock, unlock } =
|
|
29
46
|
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
30
|
-
'I know using unstable features means my
|
|
47
|
+
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
|
|
31
48
|
'@wordpress/components'
|
|
32
49
|
);
|
|
33
50
|
|
|
34
51
|
export const privateApis = {};
|
|
35
52
|
lock( privateApis, {
|
|
53
|
+
CompositeV2,
|
|
54
|
+
CompositeGroupV2,
|
|
55
|
+
CompositeItemV2,
|
|
56
|
+
CompositeRowV2,
|
|
57
|
+
useCompositeStoreV2,
|
|
36
58
|
CustomSelectControl,
|
|
37
59
|
__experimentalPopoverLegacyPositionToPlacement,
|
|
38
60
|
createPrivateSlotFill,
|
|
@@ -48,5 +70,13 @@ lock( privateApis, {
|
|
|
48
70
|
DropdownSubMenuV2,
|
|
49
71
|
DropdownSubMenuTriggerV2,
|
|
50
72
|
ProgressBar,
|
|
73
|
+
Tabs,
|
|
51
74
|
Theme,
|
|
75
|
+
DropdownMenuV2Ariakit,
|
|
76
|
+
DropdownMenuGroupV2Ariakit,
|
|
77
|
+
DropdownMenuGroupLabelV2Ariakit,
|
|
78
|
+
DropdownMenuItemV2Ariakit,
|
|
79
|
+
DropdownMenuCheckboxItemV2Ariakit,
|
|
80
|
+
DropdownMenuRadioItemV2Ariakit,
|
|
81
|
+
DropdownMenuSeparatorV2Ariakit,
|
|
52
82
|
} );
|
|
@@ -27,11 +27,17 @@ export const Track = styled.div`
|
|
|
27
27
|
width: 100%;
|
|
28
28
|
max-width: 160px;
|
|
29
29
|
height: ${ CONFIG.borderWidthFocus };
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
/* Text color at 10% opacity */
|
|
31
|
+
background-color: color-mix(
|
|
32
|
+
in srgb,
|
|
33
|
+
var( --wp-components-color-foreground, ${ COLORS.gray[ 900 ] } ),
|
|
34
|
+
transparent 90%
|
|
33
35
|
);
|
|
34
36
|
border-radius: ${ CONFIG.radiusBlockUi };
|
|
37
|
+
|
|
38
|
+
// Windows high contrast mode.
|
|
39
|
+
outline: 2px solid transparent;
|
|
40
|
+
outline-offset: 2px;
|
|
35
41
|
`;
|
|
36
42
|
|
|
37
43
|
export const Indicator = styled.div< {
|
|
@@ -43,7 +49,16 @@ export const Indicator = styled.div< {
|
|
|
43
49
|
top: 0;
|
|
44
50
|
height: 100%;
|
|
45
51
|
border-radius: ${ CONFIG.radiusBlockUi };
|
|
46
|
-
|
|
52
|
+
/* Text color at 90% opacity */
|
|
53
|
+
background-color: color-mix(
|
|
54
|
+
in srgb,
|
|
55
|
+
var( --wp-components-color-foreground, ${ COLORS.gray[ 900 ] } ),
|
|
56
|
+
transparent 10%
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Windows high contrast mode.
|
|
60
|
+
outline: 2px solid transparent;
|
|
61
|
+
outline-offset: -2px;
|
|
47
62
|
|
|
48
63
|
${ ( { isIndeterminate, value } ) =>
|
|
49
64
|
isIndeterminate
|
|
@@ -68,7 +68,7 @@ const observeAndResizeJS = `
|
|
|
68
68
|
style
|
|
69
69
|
) {
|
|
70
70
|
if (
|
|
71
|
-
/^\\d+(vmin|vmax|
|
|
71
|
+
/^\\d+(vw|vh|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)$/.test( ruleOrNode.style[ style ] )
|
|
72
72
|
) {
|
|
73
73
|
ruleOrNode.style[ style ] = '';
|
|
74
74
|
}
|
package/src/sandbox/index.tsx
CHANGED
|
@@ -55,7 +55,9 @@ const observeAndResizeJS = function () {
|
|
|
55
55
|
[ 'width', 'height', 'minHeight', 'maxHeight' ] as const
|
|
56
56
|
).forEach( function ( style ) {
|
|
57
57
|
if (
|
|
58
|
-
/^\\d+(vmin|vmax|
|
|
58
|
+
/^\\d+(vw|vh|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)$/.test(
|
|
59
|
+
ruleOrNode.style[ style ]
|
|
60
|
+
)
|
|
59
61
|
) {
|
|
60
62
|
ruleOrNode.style[ style ] = '';
|
|
61
63
|
}
|
|
@@ -66,7 +66,7 @@ function createSlotRegistry(): SlotFillBubblesVirtuallyContext {
|
|
|
66
66
|
const slotFills = fills.get( name );
|
|
67
67
|
if ( slotFills ) {
|
|
68
68
|
// Force update fills.
|
|
69
|
-
slotFills.
|
|
69
|
+
slotFills.forEach( ( fill ) => fill.current.rerender() );
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Tabs
|
|
2
|
+
|
|
3
|
+
<div class="callout callout-alert">
|
|
4
|
+
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
Tabs is a collection of React components that combine to render an [ARIA-compliant tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/).
|
|
8
|
+
|
|
9
|
+
Tabs organizes content across different screens, data sets, and interactions. It has two sections: a list of tabs, and the view to show when tabs are chosen.
|
|
10
|
+
|
|
11
|
+
## Development guidelines
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
|
|
15
|
+
#### Uncontrolled Mode
|
|
16
|
+
|
|
17
|
+
Tabs can be used in an uncontrolled mode, where the component manages its own state. In this mode, the `initialTabId` prop can be used to set the initially selected tab. If this prop is not set, the first tab will be selected by default. In addition, in most cases where the currently active tab becomes disabled or otherwise unavailable, uncontrolled mode will automatically fall back to selecting the first available tab.
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import { Tabs } from '@wordpress/components';
|
|
21
|
+
|
|
22
|
+
const onSelect = ( tabName ) => {
|
|
23
|
+
console.log( 'Selecting tab', tabName );
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const MyUncontrolledTabs = () => (
|
|
27
|
+
<Tabs onSelect={onSelect} initialTab="tab2">
|
|
28
|
+
<Tabs.TabList >
|
|
29
|
+
<Tabs.Tab id={ 'tab1' } title={ 'Tab 1' }>
|
|
30
|
+
Tab 1
|
|
31
|
+
</Tabs.Tab>
|
|
32
|
+
<Tabs.Tab id={ 'tab2' } title={ 'Tab 2' }>
|
|
33
|
+
Tab 2
|
|
34
|
+
</Tabs.Tab>
|
|
35
|
+
<Tabs.Tab id={ 'tab3' } title={ 'Tab 3' }>
|
|
36
|
+
Tab 3
|
|
37
|
+
</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
|
+
#### Controlled Mode
|
|
53
|
+
|
|
54
|
+
Tabs can also be used in a controlled mode, where the parent component specifies the `selectedTabId` and the `onSelect` props to control tab selection. In this mode, the `initialTabId` prop will be ignored if it is provided. If the `selectedTabId` is `null`, no tab is selected. In this mode, if the currently selected tab becomes disabled or otherwise unavailable, the component will _not_ fall back to another available tab, leaving the controlling component in charge of implementing the desired logic.
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
import { Tabs } from '@wordpress/components';
|
|
58
|
+
const [ selectedTabId, setSelectedTabId ] = useState<
|
|
59
|
+
string | undefined | null
|
|
60
|
+
>();
|
|
61
|
+
|
|
62
|
+
const onSelect = ( tabName ) => {
|
|
63
|
+
console.log( 'Selecting tab', tabName );
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const MyControlledTabs = () => (
|
|
67
|
+
<Tabs
|
|
68
|
+
selectedTabId={ selectedTabId }
|
|
69
|
+
onSelect={ ( selectedId ) => {
|
|
70
|
+
setSelectedTabId( selectedId );
|
|
71
|
+
onSelect( selectedId );
|
|
72
|
+
} }
|
|
73
|
+
>
|
|
74
|
+
<Tabs.TabList >
|
|
75
|
+
<Tabs.Tab id={ 'tab1' } title={ 'Tab 1' }>
|
|
76
|
+
Tab 1
|
|
77
|
+
</Tabs.Tab>
|
|
78
|
+
<Tabs.Tab id={ 'tab2' } title={ 'Tab 2' }>
|
|
79
|
+
Tab 2
|
|
80
|
+
</Tabs.Tab>
|
|
81
|
+
<Tabs.Tab id={ 'tab3' } title={ 'Tab 3' }>
|
|
82
|
+
Tab 3
|
|
83
|
+
</Tabs.Tab>
|
|
84
|
+
</Tabs.TabList>
|
|
85
|
+
<Tabs.TabPanel id={ 'tab1' }>
|
|
86
|
+
<p>Selected tab: Tab 1</p>
|
|
87
|
+
</Tabs.TabPanel>
|
|
88
|
+
<Tabs.TabPanel id={ 'tab2' }>
|
|
89
|
+
<p>Selected tab: Tab 2</p>
|
|
90
|
+
</Tabs.TabPanel>
|
|
91
|
+
<Tabs.TabPanel id={ 'tab3' }>
|
|
92
|
+
<p>Selected tab: Tab 3</p>
|
|
93
|
+
</Tabs.TabPanel>
|
|
94
|
+
</Tabs>
|
|
95
|
+
);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Components and Sub-components
|
|
99
|
+
|
|
100
|
+
Tabs is comprised of four individual components:
|
|
101
|
+
- `Tabs`: a wrapper component and context provider. It is responsible for managing the state of the tabs and rendering the `TabList` and `TabPanels`.
|
|
102
|
+
- `TabList`: a wrapper component for the `Tab` components. It is responsible for rendering the list of tabs.
|
|
103
|
+
- `Tab`: renders a single tab. The currently active tab receives default styling that can be overridden with CSS targeting [aria-selected="true"].
|
|
104
|
+
- `TabPanel`: renders the content to display for a single tab once that tab is selected.
|
|
105
|
+
|
|
106
|
+
#### Tabs
|
|
107
|
+
|
|
108
|
+
##### Props
|
|
109
|
+
|
|
110
|
+
###### `children`: `React.ReactNode`
|
|
111
|
+
|
|
112
|
+
The children elements, which should be at least a `Tabs.Tablist` component and a series of `Tabs.TabPanel` components.
|
|
113
|
+
|
|
114
|
+
- Required: Yes
|
|
115
|
+
|
|
116
|
+
###### `selectOnMove`: `boolean`
|
|
117
|
+
|
|
118
|
+
When `true`, the tab will be selected when receiving focus (automatic tab activation). When `false`, the tab will be selected only when clicked (manual tab activation). See the [official W3C docs](https://www.w3.org/WAI/ARIA/apg/patterns/tabpanel/) for more info.
|
|
119
|
+
|
|
120
|
+
- Required: No
|
|
121
|
+
- Default: `true`
|
|
122
|
+
|
|
123
|
+
###### `initialTabId`: `string`
|
|
124
|
+
|
|
125
|
+
The id of the tab to be selected upon mounting of component. If this prop is not set, the first tab will be selected by default. The id provided will be internally prefixed with a unique instance ID to avoid collisions.
|
|
126
|
+
|
|
127
|
+
_Note: this prop will be overridden by the `selectedTabId` prop if it is provided. (Controlled Mode)_
|
|
128
|
+
|
|
129
|
+
- Required: No
|
|
130
|
+
|
|
131
|
+
###### `onSelect`: `( ( selectedId: string | null | undefined ) => void )`
|
|
132
|
+
|
|
133
|
+
The function called when a tab has been selected. It is passed the selected tab's ID as an argument.
|
|
134
|
+
|
|
135
|
+
- Required: No
|
|
136
|
+
- Default: `noop`
|
|
137
|
+
|
|
138
|
+
###### `orientation`: `horizontal | vertical`
|
|
139
|
+
|
|
140
|
+
The orientation of the `tablist` (`vertical` or `horizontal`)
|
|
141
|
+
|
|
142
|
+
- Required: No
|
|
143
|
+
- Default: `horizontal`
|
|
144
|
+
|
|
145
|
+
###### `selectedTabId`: `string | null`
|
|
146
|
+
|
|
147
|
+
The ID of the tab to display. This id is prepended with the `Tabs` instanceId internally.
|
|
148
|
+
If left `undefined`, the component assumes it is being used in uncontrolled mode. Consequently, any value different than `undefined` will set the component in `controlled` mode. When in controlled mode, the `null` value will result in no tab being selected.
|
|
149
|
+
|
|
150
|
+
- Required: No
|
|
151
|
+
|
|
152
|
+
#### TabList
|
|
153
|
+
|
|
154
|
+
##### Props
|
|
155
|
+
|
|
156
|
+
###### `children`: `React.ReactNode`
|
|
157
|
+
|
|
158
|
+
The children elements, which should be a series of `Tabs.TabPanel` components.
|
|
159
|
+
|
|
160
|
+
- Required: No
|
|
161
|
+
|
|
162
|
+
###### `className`: `string`
|
|
163
|
+
|
|
164
|
+
The class name to apply to the tablist.
|
|
165
|
+
|
|
166
|
+
- Required: No
|
|
167
|
+
- Default: ''
|
|
168
|
+
|
|
169
|
+
###### `style`: `React.CSSProperties`
|
|
170
|
+
|
|
171
|
+
Custom CSS styles for the tablist.
|
|
172
|
+
|
|
173
|
+
- Required: No
|
|
174
|
+
|
|
175
|
+
#### Tab
|
|
176
|
+
|
|
177
|
+
##### Props
|
|
178
|
+
|
|
179
|
+
###### `id`: `string`
|
|
180
|
+
|
|
181
|
+
The id of the tab, which is prepended with the `Tabs` instance ID.
|
|
182
|
+
|
|
183
|
+
- Required: Yes
|
|
184
|
+
|
|
185
|
+
###### `style`: `React.CSSProperties`
|
|
186
|
+
|
|
187
|
+
Custom CSS styles for the tab.
|
|
188
|
+
|
|
189
|
+
- Required: No
|
|
190
|
+
|
|
191
|
+
###### `children`: `React.ReactNode`
|
|
192
|
+
|
|
193
|
+
The children elements, generally the text to display on the tab.
|
|
194
|
+
|
|
195
|
+
- Required: No
|
|
196
|
+
|
|
197
|
+
###### `className`: `string`
|
|
198
|
+
|
|
199
|
+
The class name to apply to the tab.
|
|
200
|
+
|
|
201
|
+
- Required: No
|
|
202
|
+
|
|
203
|
+
###### `disabled`: `boolean`
|
|
204
|
+
|
|
205
|
+
Determines if the tab button should be disabled.
|
|
206
|
+
|
|
207
|
+
- Required: No
|
|
208
|
+
- Default: `false`
|
|
209
|
+
|
|
210
|
+
###### `render`: `React.ReactNode`
|
|
211
|
+
|
|
212
|
+
The type of component to render the tab button as. If this prop is not provided, the tab button will be rendered as a `button` element.
|
|
213
|
+
|
|
214
|
+
- Required: No
|
|
215
|
+
|
|
216
|
+
#### TabPanel
|
|
217
|
+
|
|
218
|
+
##### Props
|
|
219
|
+
|
|
220
|
+
###### `children`: `React.ReactNode`
|
|
221
|
+
|
|
222
|
+
The children elements, generally the content to display on the tabpanel.
|
|
223
|
+
|
|
224
|
+
- Required: No
|
|
225
|
+
|
|
226
|
+
###### `id`: `string`
|
|
227
|
+
|
|
228
|
+
The id of the tabpanel, which is combined with the `Tabs` instance ID and the suffix `-view`
|
|
229
|
+
|
|
230
|
+
- Required: Yes
|
|
231
|
+
|
|
232
|
+
###### `className`: `string`
|
|
233
|
+
|
|
234
|
+
The class name to apply to the tabpanel.
|
|
235
|
+
|
|
236
|
+
- Required: No
|
|
237
|
+
|
|
238
|
+
###### `style`: `React.CSSProperties`
|
|
239
|
+
|
|
240
|
+
Custom CSS styles for the tab.
|
|
241
|
+
|
|
242
|
+
- Required: No
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createContext, useContext } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { TabsContextProps } from './types';
|
|
10
|
+
|
|
11
|
+
export const TabsContext = createContext< TabsContextProps >( undefined );
|
|
12
|
+
|
|
13
|
+
export const useTabsContext = () => useContext( TabsContext );
|
|
@@ -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 { 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
|
+
useLayoutEffect( () => {
|
|
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
|
+
useLayoutEffect( () => {
|
|
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;
|