@wordpress/components 21.2.0 → 21.3.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 +35 -3
- package/CONTRIBUTING.md +20 -0
- package/build/border-box-control/border-box-control/component.js +2 -0
- package/build/border-box-control/border-box-control/component.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +4 -1
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-control/border-control/component.js +2 -0
- package/build/border-control/border-control/component.js.map +1 -1
- package/build/disabled/index.js +6 -26
- package/build/disabled/index.js.map +1 -1
- package/build/font-size-picker/index.js +1 -1
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/styles.js +5 -13
- package/build/font-size-picker/styles.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/form-token-field/suggestions-list.js +5 -5
- package/build/form-token-field/suggestions-list.js.map +1 -1
- package/build/higher-order/with-fallback-styles/index.js +1 -1
- package/build/higher-order/with-fallback-styles/index.js.map +1 -1
- package/build/index.js +8 -6
- package/build/index.js.map +1 -1
- package/build/modal/aria-helper.js +2 -3
- package/build/modal/aria-helper.js.map +1 -1
- package/build/modal/index.js +42 -11
- package/build/modal/index.js.map +1 -1
- package/build/modal/types.js +6 -0
- package/build/modal/types.js.map +1 -0
- package/build/navigator/index.js +8 -8
- package/build/navigator/index.js.map +1 -1
- package/build/navigator/navigator-back-button/component.js +5 -4
- package/build/navigator/navigator-back-button/component.js.map +1 -1
- package/build/navigator/navigator-back-button/index.js +1 -1
- package/build/navigator/navigator-back-button/index.js.map +1 -1
- package/build/navigator/navigator-button/component.js +5 -4
- package/build/navigator/navigator-button/component.js.map +1 -1
- package/build/navigator/navigator-button/index.js +1 -1
- package/build/navigator/navigator-button/index.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +10 -7
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-provider/index.js +1 -1
- package/build/navigator/navigator-provider/index.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +24 -27
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/navigator/navigator-screen/index.js +1 -1
- package/build/navigator/navigator-screen/index.js.map +1 -1
- package/build/sandbox/index.js +55 -59
- package/build/sandbox/index.js.map +1 -1
- package/build/sandbox/index.native.js +63 -62
- package/build/sandbox/index.native.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/tab-panel/index.js +4 -4
- package/build/tab-panel/index.js.map +1 -1
- package/build/theme/index.js +62 -0
- package/build/theme/index.js.map +1 -0
- package/build/theme/styles.js +33 -0
- package/build/theme/styles.js.map +1 -0
- package/build/theme/types.js +6 -0
- package/build/theme/types.js.map +1 -0
- package/build/tools-panel/tools-panel/hook.js +3 -3
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build/tools-panel/tools-panel-item/hook.js +6 -6
- package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build/tooltip/index.js +4 -1
- package/build/tooltip/index.js.map +1 -1
- package/build/tooltip/index.native.js +17 -4
- package/build/tooltip/index.native.js.map +1 -1
- package/build-module/border-box-control/border-box-control/component.js +2 -0
- package/build-module/border-box-control/border-box-control/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +4 -1
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-control/border-control/component.js +2 -0
- package/build-module/border-control/border-control/component.js.map +1 -1
- package/build-module/disabled/index.js +7 -26
- package/build-module/disabled/index.js.map +1 -1
- package/build-module/font-size-picker/index.js +1 -1
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/styles.js +5 -13
- package/build-module/font-size-picker/styles.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/form-token-field/suggestions-list.js +5 -5
- package/build-module/form-token-field/suggestions-list.js.map +1 -1
- package/build-module/higher-order/with-fallback-styles/index.js +2 -2
- package/build-module/higher-order/with-fallback-styles/index.js.map +1 -1
- package/build-module/index.js +2 -1
- package/build-module/index.js.map +1 -1
- package/build-module/modal/aria-helper.js +2 -3
- package/build-module/modal/aria-helper.js.map +1 -1
- package/build-module/modal/index.js +44 -12
- package/build-module/modal/index.js.map +1 -1
- package/build-module/modal/types.js +2 -0
- package/build-module/modal/types.js.map +1 -0
- package/build-module/navigator/index.js +4 -4
- package/build-module/navigator/index.js.map +1 -1
- package/build-module/navigator/navigator-back-button/component.js +3 -3
- package/build-module/navigator/navigator-back-button/component.js.map +1 -1
- package/build-module/navigator/navigator-back-button/index.js +1 -1
- package/build-module/navigator/navigator-back-button/index.js.map +1 -1
- package/build-module/navigator/navigator-button/component.js +3 -3
- package/build-module/navigator/navigator-button/component.js.map +1 -1
- package/build-module/navigator/navigator-button/index.js +1 -1
- package/build-module/navigator/navigator-button/index.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +8 -6
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-provider/index.js +1 -1
- package/build-module/navigator/navigator-provider/index.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +12 -26
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/index.js +1 -1
- package/build-module/navigator/navigator-screen/index.js.map +1 -1
- package/build-module/sandbox/index.js +56 -59
- package/build-module/sandbox/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +54 -52
- package/build-module/sandbox/index.native.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/tab-panel/index.js +4 -4
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/theme/index.js +52 -0
- package/build-module/theme/index.js.map +1 -0
- package/build-module/theme/styles.js +25 -0
- package/build-module/theme/styles.js.map +1 -0
- package/build-module/theme/types.js +2 -0
- package/build-module/theme/types.js.map +1 -0
- package/build-module/tools-panel/tools-panel/hook.js +3 -3
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/tools-panel/tools-panel-item/hook.js +6 -6
- package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build-module/tooltip/index.js +4 -1
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tooltip/index.native.js +17 -4
- package/build-module/tooltip/index.native.js.map +1 -1
- package/build-style/style-rtl.css +26 -22
- package/build-style/style.css +26 -22
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control/component.d.ts +1 -0
- package/build-types/border-control/border-control/component.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts +1 -0
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/border-control/stories/index.d.ts +6 -0
- package/build-types/border-control/stories/index.d.ts.map +1 -1
- package/build-types/border-control/types.d.ts +4 -0
- package/build-types/border-control/types.d.ts.map +1 -1
- package/build-types/confirm-dialog/types.d.ts +5 -1
- package/build-types/confirm-dialog/types.d.ts.map +1 -1
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts.map +1 -1
- package/build-types/modal/aria-helper.d.ts +4 -4
- package/build-types/modal/aria-helper.d.ts.map +1 -1
- package/build-types/modal/index.d.ts +35 -2
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/modal/stories/index.d.ts +9 -0
- package/build-types/modal/stories/index.d.ts.map +1 -0
- package/build-types/modal/test/aria-helper.d.ts +2 -0
- package/build-types/modal/test/aria-helper.d.ts.map +1 -0
- package/build-types/modal/test/index.d.ts +2 -0
- package/build-types/modal/test/index.d.ts.map +1 -0
- package/build-types/modal/types.d.ts +134 -0
- package/build-types/modal/types.d.ts.map +1 -0
- package/build-types/navigator/index.d.ts +4 -4
- package/build-types/navigator/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/component.d.ts +4 -2
- package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-back-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/index.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/component.d.ts +4 -2
- package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/index.d.ts +1 -1
- package/build-types/navigator/navigator-button/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts +2 -2
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/index.d.ts +1 -1
- package/build-types/navigator/navigator-provider/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts +2 -2
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/index.d.ts +1 -1
- package/build-types/navigator/navigator-screen/index.d.ts.map +1 -1
- package/build-types/navigator/stories/index.d.ts +9 -0
- package/build-types/navigator/stories/index.d.ts.map +1 -0
- package/build-types/navigator/test/index.d.ts +2 -0
- package/build-types/navigator/test/index.d.ts.map +1 -0
- package/build-types/navigator/types.d.ts +4 -1
- package/build-types/navigator/types.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/theme/index.d.ts +31 -0
- package/build-types/theme/index.d.ts.map +1 -0
- package/build-types/theme/stories/index.d.ts +13 -0
- package/build-types/theme/stories/index.d.ts.map +1 -0
- package/build-types/theme/styles.d.ts +10 -0
- package/build-types/theme/styles.d.ts.map +1 -0
- package/build-types/theme/test/index.d.ts +2 -0
- package/build-types/theme/test/index.d.ts.map +1 -0
- package/build-types/theme/types.d.ts +21 -0
- package/build-types/theme/types.d.ts.map +1 -0
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/base-field/test/index.js +4 -6
- package/src/border-box-control/border-box-control/component.tsx +2 -0
- package/src/border-box-control/border-box-control/hook.ts +4 -0
- package/src/border-box-control/test/index.js +7 -2
- package/src/border-control/border-control/README.md +6 -0
- package/src/border-control/border-control/component.tsx +2 -0
- package/src/border-control/types.ts +4 -0
- package/src/button/style.scss +25 -25
- package/src/button/test/index.js +3 -5
- package/src/combobox-control/test/index.js +1 -1
- package/src/confirm-dialog/types.ts +6 -0
- package/src/date-time/time/test/index.tsx +2 -6
- package/src/disabled/index.tsx +11 -33
- package/src/disabled/test/index.tsx +14 -82
- package/src/dropdown/test/index.js +4 -3
- package/src/font-size-picker/index.tsx +1 -1
- package/src/font-size-picker/styles.ts +3 -1
- package/src/font-size-picker/test/index.tsx +2 -2
- package/src/font-size-picker/test/utils.ts +5 -5
- package/src/font-size-picker/utils.ts +1 -1
- package/src/form-file-upload/test/index.tsx +1 -1
- package/src/form-token-field/suggestions-list.tsx +5 -5
- package/src/higher-order/with-fallback-styles/index.js +6 -2
- package/src/higher-order/with-focus-outside/test/index.js +44 -45
- package/src/higher-order/with-focus-return/test/index.js +34 -30
- package/src/higher-order/with-notices/test/index.js +1 -1
- package/src/index.js +2 -1
- package/src/input-control/test/index.js +2 -2
- package/src/item-group/test/index.js +2 -2
- package/src/menu-item/test/index.js +0 -3
- package/src/mobile/bottom-sheet/test/range-cell.native.js +16 -14
- package/src/modal/README.md +53 -54
- package/src/modal/{aria-helper.js → aria-helper.ts} +5 -7
- package/src/modal/{index.js → index.tsx} +48 -12
- package/src/modal/stories/{index.js → index.tsx} +47 -42
- package/src/modal/test/{aria-helper.js → aria-helper.ts} +0 -0
- package/src/modal/test/{index.js → index.tsx} +13 -3
- package/src/modal/types.ts +144 -0
- package/src/navigation/test/index.js +1 -1
- package/src/navigator/index.ts +4 -4
- package/src/navigator/navigator-back-button/component.tsx +4 -4
- package/src/navigator/navigator-back-button/index.ts +1 -1
- package/src/navigator/navigator-button/component.tsx +4 -4
- package/src/navigator/navigator-button/index.ts +1 -1
- package/src/navigator/navigator-provider/component.tsx +6 -4
- package/src/navigator/navigator-provider/index.ts +1 -1
- package/src/navigator/navigator-screen/component.tsx +20 -26
- package/src/navigator/navigator-screen/index.ts +1 -1
- package/src/navigator/stories/index.tsx +210 -0
- package/src/navigator/test/index.tsx +509 -0
- package/src/navigator/types.ts +2 -0
- package/src/notice/test/__snapshots__/index.js.snap +39 -38
- package/src/notice/test/index.js +15 -36
- package/src/notice/test/list.js +6 -14
- package/src/number-control/test/index.js +3 -2
- package/src/panel/test/body.js +2 -2
- package/src/placeholder/style.scss +5 -0
- package/src/sandbox/index.js +62 -47
- package/src/sandbox/index.native.js +72 -52
- package/src/sandbox/test/index.js +7 -10
- package/src/shortcut/test/index.tsx +1 -1
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.js +5 -3
- package/src/style.scss +4 -0
- package/src/tab-panel/index.tsx +4 -7
- package/src/text-highlight/test/index.tsx +1 -3
- package/src/theme/README.md +34 -0
- package/src/theme/index.tsx +51 -0
- package/src/theme/stories/index.tsx +47 -0
- package/src/theme/styles.ts +28 -0
- package/src/theme/test/index.tsx +101 -0
- package/src/theme/types.ts +21 -0
- package/src/toolbar/test/index.js +2 -2
- package/src/toolbar-group/test/index.js +6 -10
- package/src/tools-panel/test/index.js +4 -6
- package/src/tools-panel/tools-panel/hook.ts +2 -9
- package/src/tools-panel/tools-panel-item/hook.ts +17 -3
- package/src/tooltip/index.js +3 -0
- package/src/tooltip/index.native.js +15 -0
- package/src/tooltip/test/index.native.js +1 -2
- package/src/tree-grid/test/__snapshots__/cell.js.snap +1 -3
- package/src/tree-grid/test/__snapshots__/roving-tab-index-item.js.snap +17 -15
- package/src/tree-grid/test/__snapshots__/row.js.snap +25 -21
- package/src/tree-grid/test/cell.js +4 -4
- package/src/tree-grid/test/roving-tab-index-item.js +8 -8
- package/src/tree-grid/test/roving-tab-index.js +3 -3
- package/src/tree-grid/test/row.js +20 -16
- package/src/truncate/test/index.tsx +4 -4
- package/src/ui/shortcut/test/index.js +2 -1
- package/src/ui/spinner/test/index.js +14 -13
- package/src/ui/tooltip/test/index.js +16 -14
- package/src/utils/theme-variables.scss +8 -0
- package/src/visually-hidden/README.md +4 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/navigator/stories/index.js +0 -194
- package/src/navigator/test/index.js +0 -472
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
import type { ForwardedRef } from 'react';
|
|
5
5
|
// eslint-disable-next-line no-restricted-imports
|
|
6
6
|
import { motion, MotionProps } from 'framer-motion';
|
|
7
|
-
import { css } from '@emotion/react';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* WordPress dependencies
|
|
11
10
|
*/
|
|
12
11
|
import { focus } from '@wordpress/dom';
|
|
13
|
-
import { useContext, useEffect,
|
|
12
|
+
import { useContext, useEffect, useRef } from '@wordpress/element';
|
|
14
13
|
import {
|
|
15
14
|
useReducedMotion,
|
|
16
15
|
useMergeRefs,
|
|
@@ -27,7 +26,6 @@ import {
|
|
|
27
26
|
useContextSystem,
|
|
28
27
|
WordPressComponentProps,
|
|
29
28
|
} from '../../ui/context';
|
|
30
|
-
import { useCx } from '../../utils/hooks/use-cx';
|
|
31
29
|
import { View } from '../../view';
|
|
32
30
|
import { NavigatorContext } from '../context';
|
|
33
31
|
import type { NavigatorScreenProps } from '../types';
|
|
@@ -44,7 +42,10 @@ type Props = Omit<
|
|
|
44
42
|
keyof MotionProps
|
|
45
43
|
>;
|
|
46
44
|
|
|
47
|
-
function
|
|
45
|
+
function UnconnectedNavigatorScreen(
|
|
46
|
+
props: Props,
|
|
47
|
+
forwardedRef: ForwardedRef< any >
|
|
48
|
+
) {
|
|
48
49
|
const { children, className, path, ...otherProps } = useContextSystem(
|
|
49
50
|
props,
|
|
50
51
|
'NavigatorScreen'
|
|
@@ -57,21 +58,6 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
57
58
|
|
|
58
59
|
const previousLocation = usePrevious( location );
|
|
59
60
|
|
|
60
|
-
const cx = useCx();
|
|
61
|
-
const classes = useMemo(
|
|
62
|
-
() =>
|
|
63
|
-
cx(
|
|
64
|
-
css( {
|
|
65
|
-
// Ensures horizontal overflow is visually accessible.
|
|
66
|
-
overflowX: 'auto',
|
|
67
|
-
// In case the root has a height, it should not be exceeded.
|
|
68
|
-
maxHeight: '100%',
|
|
69
|
-
} ),
|
|
70
|
-
className
|
|
71
|
-
),
|
|
72
|
-
[ className, cx ]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
61
|
// Focus restoration
|
|
76
62
|
const isInitialLocation = location.isInitial && ! location.isBack;
|
|
77
63
|
useEffect( () => {
|
|
@@ -79,14 +65,20 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
79
65
|
// - if the current location is not the initial one (to avoid moving focus on page load)
|
|
80
66
|
// - when the screen becomes visible
|
|
81
67
|
// - if the wrapper ref has been assigned
|
|
82
|
-
if
|
|
68
|
+
// - if focus hasn't already been restored for the current location
|
|
69
|
+
if (
|
|
70
|
+
isInitialLocation ||
|
|
71
|
+
! isMatch ||
|
|
72
|
+
! wrapperRef.current ||
|
|
73
|
+
location.hasRestoredFocus
|
|
74
|
+
) {
|
|
83
75
|
return;
|
|
84
76
|
}
|
|
85
77
|
|
|
86
78
|
const activeElement = wrapperRef.current.ownerDocument.activeElement;
|
|
87
79
|
|
|
88
80
|
// If an element is already focused within the wrapper do not focus the
|
|
89
|
-
// element. This prevents inputs or buttons from losing focus
|
|
81
|
+
// element. This prevents inputs or buttons from losing focus unnecessarily.
|
|
90
82
|
if ( wrapperRef.current.contains( activeElement ) ) {
|
|
91
83
|
return;
|
|
92
84
|
}
|
|
@@ -110,10 +102,12 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
110
102
|
elementToFocus = firstTabbable ?? wrapperRef.current;
|
|
111
103
|
}
|
|
112
104
|
|
|
105
|
+
location.hasRestoredFocus = true;
|
|
113
106
|
elementToFocus.focus();
|
|
114
107
|
}, [
|
|
115
108
|
isInitialLocation,
|
|
116
109
|
isMatch,
|
|
110
|
+
location.hasRestoredFocus,
|
|
117
111
|
location.isBack,
|
|
118
112
|
previousLocation?.focusTargetSelector,
|
|
119
113
|
] );
|
|
@@ -128,7 +122,7 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
128
122
|
return (
|
|
129
123
|
<View
|
|
130
124
|
ref={ mergedWrapperRef }
|
|
131
|
-
className={
|
|
125
|
+
className={ className }
|
|
132
126
|
{ ...otherProps }
|
|
133
127
|
>
|
|
134
128
|
{ children }
|
|
@@ -174,7 +168,7 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
174
168
|
return (
|
|
175
169
|
<motion.div
|
|
176
170
|
ref={ mergedWrapperRef }
|
|
177
|
-
className={
|
|
171
|
+
className={ className }
|
|
178
172
|
{ ...otherProps }
|
|
179
173
|
{ ...animatedProps }
|
|
180
174
|
>
|
|
@@ -217,9 +211,9 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
|
|
|
217
211
|
* );
|
|
218
212
|
* ```
|
|
219
213
|
*/
|
|
220
|
-
const
|
|
221
|
-
|
|
214
|
+
export const NavigatorScreen = contextConnect(
|
|
215
|
+
UnconnectedNavigatorScreen,
|
|
222
216
|
'NavigatorScreen'
|
|
223
217
|
);
|
|
224
218
|
|
|
225
|
-
export default
|
|
219
|
+
export default NavigatorScreen;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './component';
|
|
1
|
+
export { default as NavigatorScreen } from './component';
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import Button from '../../button';
|
|
10
|
+
import { Card, CardBody, CardFooter, CardHeader } from '../../card';
|
|
11
|
+
import { HStack } from '../../h-stack';
|
|
12
|
+
import Dropdown from '../../dropdown';
|
|
13
|
+
import {
|
|
14
|
+
NavigatorProvider,
|
|
15
|
+
NavigatorScreen,
|
|
16
|
+
NavigatorButton,
|
|
17
|
+
NavigatorBackButton,
|
|
18
|
+
} from '..';
|
|
19
|
+
|
|
20
|
+
const meta: ComponentMeta< typeof NavigatorProvider > = {
|
|
21
|
+
component: NavigatorProvider,
|
|
22
|
+
title: 'Components (Experimental)/Navigator',
|
|
23
|
+
subcomponents: { NavigatorScreen, NavigatorButton, NavigatorBackButton },
|
|
24
|
+
argTypes: {
|
|
25
|
+
as: { control: { type: null } },
|
|
26
|
+
children: { control: { type: null } },
|
|
27
|
+
initialPath: { control: { type: null } },
|
|
28
|
+
},
|
|
29
|
+
parameters: {
|
|
30
|
+
controls: { expanded: true },
|
|
31
|
+
docs: { source: { state: 'open' } },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export default meta;
|
|
35
|
+
|
|
36
|
+
const Template: ComponentStory< typeof NavigatorProvider > = ( {
|
|
37
|
+
style,
|
|
38
|
+
...props
|
|
39
|
+
} ) => (
|
|
40
|
+
<NavigatorProvider
|
|
41
|
+
style={ { ...style, height: '100vh', maxHeight: '450px' } }
|
|
42
|
+
{ ...props }
|
|
43
|
+
>
|
|
44
|
+
<NavigatorScreen path="/">
|
|
45
|
+
<Card>
|
|
46
|
+
<CardBody>
|
|
47
|
+
<p>This is the home screen.</p>
|
|
48
|
+
|
|
49
|
+
<HStack justify="flex-start" wrap>
|
|
50
|
+
<NavigatorButton variant="secondary" path="/child">
|
|
51
|
+
Navigate to child screen.
|
|
52
|
+
</NavigatorButton>
|
|
53
|
+
|
|
54
|
+
<NavigatorButton
|
|
55
|
+
variant="secondary"
|
|
56
|
+
path="/overflow-child"
|
|
57
|
+
>
|
|
58
|
+
Navigate to screen with horizontal overflow.
|
|
59
|
+
</NavigatorButton>
|
|
60
|
+
|
|
61
|
+
<NavigatorButton variant="secondary" path="/stickies">
|
|
62
|
+
Navigate to screen with sticky content.
|
|
63
|
+
</NavigatorButton>
|
|
64
|
+
|
|
65
|
+
<Dropdown
|
|
66
|
+
renderToggle={ ( {
|
|
67
|
+
isOpen,
|
|
68
|
+
onToggle,
|
|
69
|
+
}: {
|
|
70
|
+
// TODO: remove once `Dropdown` is refactored to TypeScript
|
|
71
|
+
isOpen: boolean;
|
|
72
|
+
onToggle: () => void;
|
|
73
|
+
} ) => (
|
|
74
|
+
<Button
|
|
75
|
+
onClick={ onToggle }
|
|
76
|
+
aria-expanded={ isOpen }
|
|
77
|
+
variant="primary"
|
|
78
|
+
>
|
|
79
|
+
Open test dialog
|
|
80
|
+
</Button>
|
|
81
|
+
) }
|
|
82
|
+
renderContent={ () => (
|
|
83
|
+
<Card>
|
|
84
|
+
<CardHeader>Go</CardHeader>
|
|
85
|
+
<CardBody>Stuff</CardBody>
|
|
86
|
+
</Card>
|
|
87
|
+
) }
|
|
88
|
+
/>
|
|
89
|
+
</HStack>
|
|
90
|
+
</CardBody>
|
|
91
|
+
</Card>
|
|
92
|
+
</NavigatorScreen>
|
|
93
|
+
|
|
94
|
+
<NavigatorScreen path="/child">
|
|
95
|
+
<Card>
|
|
96
|
+
<CardBody>
|
|
97
|
+
<p>This is the child screen.</p>
|
|
98
|
+
<NavigatorBackButton variant="secondary">
|
|
99
|
+
Go back
|
|
100
|
+
</NavigatorBackButton>
|
|
101
|
+
</CardBody>
|
|
102
|
+
</Card>
|
|
103
|
+
</NavigatorScreen>
|
|
104
|
+
|
|
105
|
+
<NavigatorScreen path="/overflow-child">
|
|
106
|
+
<Card>
|
|
107
|
+
<CardBody>
|
|
108
|
+
<NavigatorBackButton variant="secondary">
|
|
109
|
+
Go back
|
|
110
|
+
</NavigatorBackButton>
|
|
111
|
+
<div
|
|
112
|
+
style={ {
|
|
113
|
+
display: 'inline-block',
|
|
114
|
+
background: 'papayawhip',
|
|
115
|
+
} }
|
|
116
|
+
>
|
|
117
|
+
<span
|
|
118
|
+
style={ {
|
|
119
|
+
color: 'palevioletred',
|
|
120
|
+
whiteSpace: 'nowrap',
|
|
121
|
+
fontSize: '42vw',
|
|
122
|
+
} }
|
|
123
|
+
>
|
|
124
|
+
¯\_(ツ)_/¯
|
|
125
|
+
</span>
|
|
126
|
+
</div>
|
|
127
|
+
</CardBody>
|
|
128
|
+
</Card>
|
|
129
|
+
</NavigatorScreen>
|
|
130
|
+
|
|
131
|
+
<NavigatorScreen path="/stickies">
|
|
132
|
+
<Card>
|
|
133
|
+
<CardHeader style={ getStickyStyles( { zIndex: 2 } ) }>
|
|
134
|
+
<NavigatorBackButton variant="secondary">
|
|
135
|
+
Go back
|
|
136
|
+
</NavigatorBackButton>
|
|
137
|
+
</CardHeader>
|
|
138
|
+
<CardBody>
|
|
139
|
+
<div
|
|
140
|
+
style={ getStickyStyles( {
|
|
141
|
+
top: 69,
|
|
142
|
+
bgColor: 'peachpuff',
|
|
143
|
+
} ) }
|
|
144
|
+
>
|
|
145
|
+
<h2>A wild sticky element appears</h2>
|
|
146
|
+
</div>
|
|
147
|
+
<MetaphorIpsum quantity={ 3 } />
|
|
148
|
+
</CardBody>
|
|
149
|
+
<CardBody>
|
|
150
|
+
<div
|
|
151
|
+
style={ getStickyStyles( {
|
|
152
|
+
top: 69,
|
|
153
|
+
bgColor: 'paleturquoise',
|
|
154
|
+
} ) }
|
|
155
|
+
>
|
|
156
|
+
<h2>Another wild sticky element appears</h2>
|
|
157
|
+
</div>
|
|
158
|
+
<MetaphorIpsum quantity={ 3 } />
|
|
159
|
+
</CardBody>
|
|
160
|
+
<CardFooter
|
|
161
|
+
style={ getStickyStyles( {
|
|
162
|
+
bgColor: 'mistyrose',
|
|
163
|
+
} ) }
|
|
164
|
+
>
|
|
165
|
+
<Button variant="primary">Primary noop</Button>
|
|
166
|
+
</CardFooter>
|
|
167
|
+
</Card>
|
|
168
|
+
</NavigatorScreen>
|
|
169
|
+
</NavigatorProvider>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
export const Default: ComponentStory< typeof NavigatorProvider > =
|
|
173
|
+
Template.bind( {} );
|
|
174
|
+
Default.args = {
|
|
175
|
+
initialPath: '/',
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function getStickyStyles( {
|
|
179
|
+
bottom = 0,
|
|
180
|
+
bgColor = 'whitesmoke',
|
|
181
|
+
top = 0,
|
|
182
|
+
zIndex = 1,
|
|
183
|
+
} ): React.CSSProperties {
|
|
184
|
+
return {
|
|
185
|
+
display: 'flex',
|
|
186
|
+
position: 'sticky',
|
|
187
|
+
top,
|
|
188
|
+
bottom,
|
|
189
|
+
zIndex,
|
|
190
|
+
backgroundColor: bgColor,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function MetaphorIpsum( { quantity }: { quantity: number } ) {
|
|
195
|
+
const list = [
|
|
196
|
+
'A loopy clarinet’s year comes with it the thought that the fenny step-son is an ophthalmologist. The literature would have us believe that a glabrate country is not but a rhythm. A beech is a rub from the right perspective. In ancient times few can name an unglossed walrus that isn’t an unspilt trial.',
|
|
197
|
+
'Authors often misinterpret the afterthought as a roseless mother-in-law, when in actuality it feels more like an uncapped thunderstorm. In recent years, some posit the tarry bottle to be less than acerb. They were lost without the unkissed timbale that composed their customer. A donna is a springtime breath.',
|
|
198
|
+
'It’s an undeniable fact, really; their museum was, in this moment, a snotty beef. The swordfishes could be said to resemble prowessed lasagnas. However, the rainier authority comes from a cureless soup. Unfortunately, that is wrong; on the contrary, the cover is a powder.',
|
|
199
|
+
];
|
|
200
|
+
quantity = Math.min( list.length, quantity );
|
|
201
|
+
return (
|
|
202
|
+
<>
|
|
203
|
+
{ list.slice( 0, quantity ).map( ( text, key ) => (
|
|
204
|
+
<p style={ { maxWidth: '20em' } } key={ key }>
|
|
205
|
+
{ text }
|
|
206
|
+
</p>
|
|
207
|
+
) ) }
|
|
208
|
+
</>
|
|
209
|
+
);
|
|
210
|
+
}
|