@wordpress/components 25.3.0 → 25.5.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 +31 -0
- package/build/border-control/border-control-dropdown/component.js +8 -10
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/button/index.native.js +9 -6
- package/build/button/index.native.js.map +1 -1
- package/build/color-palette/index.js +2 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/focal-point-picker/index.native.js +6 -4
- package/build/focal-point-picker/index.native.js.map +1 -1
- package/build/form-token-field/styles.js +4 -2
- package/build/form-token-field/styles.js.map +1 -1
- package/build/item-group/item/hook.js +1 -1
- package/build/item-group/item/hook.js.map +1 -1
- package/build/item-group/styles.js +13 -10
- package/build/item-group/styles.js.map +1 -1
- package/build/menu-items-choice/index.js +1 -0
- package/build/menu-items-choice/index.js.map +1 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js +3 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js.map +1 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +50 -44
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +13 -20
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
- package/build/mobile/bottom-sheet/index.native.js +3 -1
- package/build/mobile/bottom-sheet/index.native.js.map +1 -1
- package/build/mobile/image/index.native.js +4 -3
- package/build/mobile/image/index.native.js.map +1 -1
- package/build/mobile/link-picker/link-picker-results.native.js +2 -1
- package/build/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build/mobile/segmented-control/index.native.js +7 -7
- package/build/mobile/segmented-control/index.native.js.map +1 -1
- package/build/modal/index.js +14 -1
- package/build/modal/index.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +18 -10
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/progress-bar/index.js +54 -0
- package/build/progress-bar/index.js.map +1 -0
- package/build/progress-bar/styles.js +69 -0
- package/build/progress-bar/styles.js.map +1 -0
- package/build/progress-bar/types.js +6 -0
- package/build/progress-bar/types.js.map +1 -0
- package/build/query-controls/index.js +1 -0
- package/build/query-controls/index.js.map +1 -1
- package/build/query-controls/index.native.js +1 -0
- package/build/query-controls/index.native.js.map +1 -1
- package/build/tab-panel/index.js +91 -58
- package/build/tab-panel/index.js.map +1 -1
- package/build/text-control/index.js +2 -2
- package/build/text-control/index.js.map +1 -1
- package/build/toolbar/toolbar-group/toolbar-group-container.native.js +10 -7
- package/build/toolbar/toolbar-group/toolbar-group-container.native.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +8 -10
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/button/index.native.js +8 -6
- package/build-module/button/index.native.js.map +1 -1
- package/build-module/color-palette/index.js +2 -2
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/focal-point-picker/index.native.js +6 -5
- package/build-module/focal-point-picker/index.native.js.map +1 -1
- package/build-module/form-token-field/styles.js +3 -2
- package/build-module/form-token-field/styles.js.map +1 -1
- package/build-module/item-group/item/hook.js +1 -1
- package/build-module/item-group/item/hook.js.map +1 -1
- package/build-module/item-group/styles.js +13 -11
- package/build-module/item-group/styles.js.map +1 -1
- package/build-module/menu-items-choice/index.js +1 -0
- package/build-module/menu-items-choice/index.js.map +1 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js +3 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js.map +1 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +43 -41
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +14 -20
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
- package/build-module/mobile/bottom-sheet/index.native.js +3 -1
- package/build-module/mobile/bottom-sheet/index.native.js.map +1 -1
- package/build-module/mobile/image/index.native.js +4 -3
- package/build-module/mobile/image/index.native.js.map +1 -1
- package/build-module/mobile/link-picker/link-picker-results.native.js +2 -1
- package/build-module/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build-module/mobile/segmented-control/index.native.js +7 -7
- package/build-module/mobile/segmented-control/index.native.js.map +1 -1
- package/build-module/modal/index.js +14 -1
- package/build-module/modal/index.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +18 -10
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/progress-bar/index.js +41 -0
- package/build-module/progress-bar/index.js.map +1 -0
- package/build-module/progress-bar/styles.js +61 -0
- package/build-module/progress-bar/styles.js.map +1 -0
- package/build-module/progress-bar/types.js +2 -0
- package/build-module/progress-bar/types.js.map +1 -0
- package/build-module/query-controls/index.js +1 -0
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/query-controls/index.native.js +1 -0
- package/build-module/query-controls/index.native.js.map +1 -1
- package/build-module/tab-panel/index.js +88 -59
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/text-control/index.js +2 -2
- package/build-module/text-control/index.js.map +1 -1
- package/build-module/toolbar/toolbar-group/toolbar-group-container.native.js +11 -7
- package/build-module/toolbar/toolbar-group/toolbar-group-container.native.js.map +1 -1
- package/build-style/style-rtl.css +3 -0
- package/build-style/style.css +3 -0
- package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
- package/build-types/form-token-field/styles.d.ts.map +1 -1
- package/build-types/item-group/item/hook.d.ts.map +1 -1
- package/build-types/item-group/stories/index.d.ts.map +1 -1
- package/build-types/item-group/styles.d.ts +1 -1
- package/build-types/item-group/styles.d.ts.map +1 -1
- package/build-types/menu-items-choice/index.d.ts.map +1 -1
- package/build-types/menu-items-choice/types.d.ts +5 -0
- package/build-types/menu-items-choice/types.d.ts.map +1 -1
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/types.d.ts +3 -1
- package/build-types/navigator/types.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/progress-bar/index.d.ts +5 -0
- package/build-types/progress-bar/index.d.ts.map +1 -0
- package/build-types/progress-bar/stories/index.d.ts +12 -0
- package/build-types/progress-bar/stories/index.d.ts.map +1 -0
- package/build-types/progress-bar/styles.d.ts +18 -0
- package/build-types/progress-bar/styles.d.ts.map +1 -0
- package/build-types/progress-bar/test/index.d.ts +2 -0
- package/build-types/progress-bar/test/index.d.ts.map +1 -0
- package/build-types/progress-bar/types.d.ts +11 -0
- package/build-types/progress-bar/types.d.ts.map +1 -0
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/tab-panel/stories/index.d.ts +1 -0
- package/build-types/tab-panel/stories/index.d.ts.map +1 -1
- package/build-types/tab-panel/types.d.ts +1 -9
- package/build-types/tab-panel/types.d.ts.map +1 -1
- package/build-types/text-control/test/text-control.d.ts +2 -0
- package/build-types/text-control/test/text-control.d.ts.map +1 -0
- package/package.json +22 -22
- package/src/border-control/border-control-dropdown/component.tsx +7 -11
- package/src/border-control/test/index.js +6 -6
- package/src/button/index.native.js +9 -3
- package/src/button/style.native.scss +9 -0
- package/src/color-palette/index.tsx +2 -2
- package/src/color-palette/test/__snapshots__/index.tsx.snap +1 -1
- package/src/color-palette/test/index.tsx +1 -5
- package/src/draggable/test/index.native.js +4 -0
- package/src/focal-point-picker/index.native.js +6 -5
- package/src/form-token-field/styles.ts +2 -0
- package/src/item-group/item/hook.ts +2 -1
- package/src/item-group/stories/index.tsx +8 -3
- package/src/item-group/styles.ts +39 -28
- package/src/menu-item/README.md +7 -0
- package/src/menu-items-choice/index.tsx +1 -0
- package/src/menu-items-choice/types.ts +5 -0
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js +1 -1
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +72 -53
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +15 -21
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +165 -119
- package/src/mobile/bottom-sheet/index.native.js +2 -0
- package/src/mobile/image/index.native.js +8 -6
- package/src/mobile/image/style.native.scss +5 -1
- package/src/mobile/link-picker/link-picker-results.native.js +1 -1
- package/src/mobile/link-settings/test/edit.native.js +37 -23
- package/src/mobile/segmented-control/index.native.js +11 -11
- package/src/modal/index.tsx +16 -0
- package/src/modal/test/index.tsx +33 -0
- package/src/navigator/navigator-provider/component.tsx +30 -23
- package/src/navigator/types.ts +4 -1
- package/src/placeholder/style.scss +5 -0
- package/src/private-apis.ts +2 -0
- package/src/progress-bar/README.md +30 -0
- package/src/progress-bar/index.tsx +45 -0
- package/src/progress-bar/stories/index.tsx +33 -0
- package/src/progress-bar/styles.ts +67 -0
- package/src/progress-bar/test/index.tsx +79 -0
- package/src/progress-bar/types.ts +11 -0
- package/src/query-controls/index.native.js +1 -0
- package/src/query-controls/index.tsx +1 -0
- package/src/tab-panel/index.tsx +121 -84
- package/src/tab-panel/stories/index.tsx +6 -0
- package/src/tab-panel/test/index.tsx +128 -109
- package/src/tab-panel/types.ts +1 -10
- package/src/text-control/index.tsx +2 -2
- package/src/text-control/test/text-control.tsx +61 -0
- package/src/toolbar/toolbar-group/style.native.scss +2 -3
- package/src/toolbar/toolbar-group/toolbar-group-container.native.js +12 -17
- package/src/tooltip/README.md +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -148,6 +148,7 @@ function UnconnectedNavigatorProvider(
|
|
|
148
148
|
focusTargetSelector,
|
|
149
149
|
isBack = false,
|
|
150
150
|
skipFocus = false,
|
|
151
|
+
replace = false,
|
|
151
152
|
...restOptions
|
|
152
153
|
} = options;
|
|
153
154
|
|
|
@@ -172,34 +173,38 @@ function UnconnectedNavigatorProvider(
|
|
|
172
173
|
skipFocus,
|
|
173
174
|
};
|
|
174
175
|
|
|
175
|
-
if ( prevLocationHistory.length
|
|
176
|
-
return [ newLocation ];
|
|
176
|
+
if ( prevLocationHistory.length === 0 ) {
|
|
177
|
+
return replace ? [] : [ newLocation ];
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
180
|
+
const newLocationHistory = prevLocationHistory.slice(
|
|
181
|
+
prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,
|
|
182
|
+
-1
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
if ( ! replace ) {
|
|
186
|
+
newLocationHistory.push(
|
|
187
|
+
// Assign `focusTargetSelector` to the previous location in history
|
|
188
|
+
// (the one we just navigated from).
|
|
189
|
+
{
|
|
190
|
+
...prevLocationHistory[
|
|
191
|
+
prevLocationHistory.length - 1
|
|
192
|
+
],
|
|
193
|
+
focusTargetSelector,
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
newLocationHistory.push( newLocation );
|
|
199
|
+
|
|
200
|
+
return newLocationHistory;
|
|
196
201
|
} );
|
|
197
202
|
},
|
|
198
203
|
[ goBack ]
|
|
199
204
|
);
|
|
200
205
|
|
|
201
|
-
const goToParent: NavigatorContextType[ 'goToParent' ] =
|
|
202
|
-
|
|
206
|
+
const goToParent: NavigatorContextType[ 'goToParent' ] = useCallback(
|
|
207
|
+
( options = {} ) => {
|
|
203
208
|
const currentPath =
|
|
204
209
|
currentLocationHistory.current[
|
|
205
210
|
currentLocationHistory.current.length - 1
|
|
@@ -214,8 +219,10 @@ function UnconnectedNavigatorProvider(
|
|
|
214
219
|
if ( parentPath === undefined ) {
|
|
215
220
|
return;
|
|
216
221
|
}
|
|
217
|
-
goTo( parentPath, { isBack: true } );
|
|
218
|
-
},
|
|
222
|
+
goTo( parentPath, { ...options, isBack: true } );
|
|
223
|
+
},
|
|
224
|
+
[ goTo ]
|
|
225
|
+
);
|
|
219
226
|
|
|
220
227
|
const navigatorContextValue: NavigatorContextType = useMemo(
|
|
221
228
|
() => ( {
|
package/src/navigator/types.ts
CHANGED
|
@@ -14,8 +14,11 @@ export type NavigateOptions = {
|
|
|
14
14
|
focusTargetSelector?: string;
|
|
15
15
|
isBack?: boolean;
|
|
16
16
|
skipFocus?: boolean;
|
|
17
|
+
replace?: boolean;
|
|
17
18
|
};
|
|
18
19
|
|
|
20
|
+
export type NavigateToParentOptions = Omit< NavigateOptions, 'isBack' >;
|
|
21
|
+
|
|
19
22
|
export type NavigatorLocation = NavigateOptions & {
|
|
20
23
|
isInitial?: boolean;
|
|
21
24
|
path?: string;
|
|
@@ -28,7 +31,7 @@ export type Navigator = {
|
|
|
28
31
|
params: MatchParams;
|
|
29
32
|
goTo: ( path: string, options?: NavigateOptions ) => void;
|
|
30
33
|
goBack: () => void;
|
|
31
|
-
goToParent: () => void;
|
|
34
|
+
goToParent: ( options?: NavigateToParentOptions ) => void;
|
|
32
35
|
};
|
|
33
36
|
|
|
34
37
|
export type NavigatorContext = Navigator & {
|
package/src/private-apis.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri
|
|
|
8
8
|
*/
|
|
9
9
|
import { default as CustomSelectControl } from './custom-select-control';
|
|
10
10
|
import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';
|
|
11
|
+
import { default as ProgressBar } from './progress-bar';
|
|
11
12
|
import { createPrivateSlotFill } from './slot-fill';
|
|
12
13
|
import {
|
|
13
14
|
DropdownMenu as DropdownMenuV2,
|
|
@@ -45,4 +46,5 @@ lock( privateApis, {
|
|
|
45
46
|
DropdownMenuSeparatorV2,
|
|
46
47
|
DropdownSubMenuV2,
|
|
47
48
|
DropdownSubMenuTriggerV2,
|
|
49
|
+
ProgressBar,
|
|
48
50
|
} );
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ProgressBar
|
|
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
|
+
A simple horizontal progress bar component.
|
|
8
|
+
|
|
9
|
+
Supports two modes: determinate and indeterminate. A progress bar is determinate when a specific progress value has been specified (from 0 to 100), and indeterminate when a value hasn't been specified.
|
|
10
|
+
|
|
11
|
+
### Props
|
|
12
|
+
|
|
13
|
+
The component accepts the following props:
|
|
14
|
+
|
|
15
|
+
#### `value`: `number`
|
|
16
|
+
|
|
17
|
+
The progress value, a number from 0 to 100.
|
|
18
|
+
If a `value` is not specified, the progress bar will be considered indeterminate.
|
|
19
|
+
|
|
20
|
+
- Required: No
|
|
21
|
+
|
|
22
|
+
##### `className`: `string`
|
|
23
|
+
|
|
24
|
+
A CSS class to apply to the underlying `div` element, serving as a progress bar track.
|
|
25
|
+
|
|
26
|
+
- Required: No
|
|
27
|
+
|
|
28
|
+
#### Inherited props
|
|
29
|
+
|
|
30
|
+
Any additional props will be passed the underlying `<progress/>` element.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ForwardedRef } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import { forwardRef } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import * as ProgressBarStyled from './styles';
|
|
16
|
+
import type { ProgressBarProps } from './types';
|
|
17
|
+
import type { WordPressComponentProps } from '../ui/context';
|
|
18
|
+
|
|
19
|
+
function UnforwardedProgressBar(
|
|
20
|
+
props: WordPressComponentProps< ProgressBarProps, 'progress', false >,
|
|
21
|
+
ref: ForwardedRef< HTMLProgressElement >
|
|
22
|
+
) {
|
|
23
|
+
const { className, value, ...progressProps } = props;
|
|
24
|
+
const isIndeterminate = ! Number.isFinite( value );
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<ProgressBarStyled.Track className={ className }>
|
|
28
|
+
<ProgressBarStyled.Indicator
|
|
29
|
+
isIndeterminate={ isIndeterminate }
|
|
30
|
+
value={ value }
|
|
31
|
+
/>
|
|
32
|
+
<ProgressBarStyled.ProgressElement
|
|
33
|
+
max={ 100 }
|
|
34
|
+
value={ value }
|
|
35
|
+
aria-label={ __( 'Loading …' ) }
|
|
36
|
+
ref={ ref }
|
|
37
|
+
{ ...progressProps }
|
|
38
|
+
/>
|
|
39
|
+
</ProgressBarStyled.Track>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const ProgressBar = forwardRef( UnforwardedProgressBar );
|
|
44
|
+
|
|
45
|
+
export default ProgressBar;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { ProgressBar } from '..';
|
|
10
|
+
|
|
11
|
+
const meta: ComponentMeta< typeof ProgressBar > = {
|
|
12
|
+
component: ProgressBar,
|
|
13
|
+
title: 'Components (Experimental)/ProgressBar',
|
|
14
|
+
argTypes: {
|
|
15
|
+
value: { control: { type: 'number', min: 0, max: 100, step: 1 } },
|
|
16
|
+
},
|
|
17
|
+
parameters: {
|
|
18
|
+
controls: {
|
|
19
|
+
expanded: true,
|
|
20
|
+
},
|
|
21
|
+
docs: { source: { state: 'open' } },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
const Template: ComponentStory< typeof ProgressBar > = ( { ...args } ) => {
|
|
27
|
+
return <ProgressBar { ...args } />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Default: ComponentStory< typeof ProgressBar > = Template.bind(
|
|
31
|
+
{}
|
|
32
|
+
);
|
|
33
|
+
Default.args = {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import styled from '@emotion/styled';
|
|
5
|
+
import { css, keyframes } from '@emotion/react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { COLORS, CONFIG } from '../utils';
|
|
11
|
+
|
|
12
|
+
const animateProgressBar = keyframes( {
|
|
13
|
+
'0%': {
|
|
14
|
+
left: '-50%',
|
|
15
|
+
},
|
|
16
|
+
'100%': {
|
|
17
|
+
left: '100%',
|
|
18
|
+
},
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
// Width of the indicator for the indeterminate progress bar
|
|
22
|
+
export const INDETERMINATE_TRACK_WIDTH = 50;
|
|
23
|
+
|
|
24
|
+
export const Track = styled.div`
|
|
25
|
+
position: relative;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
width: 100%;
|
|
28
|
+
max-width: 160px;
|
|
29
|
+
height: ${ CONFIG.borderWidthFocus };
|
|
30
|
+
background-color: var(
|
|
31
|
+
--wp-components-color-gray-100,
|
|
32
|
+
${ COLORS.gray[ 100 ] }
|
|
33
|
+
);
|
|
34
|
+
border-radius: ${ CONFIG.radiusBlockUi };
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const Indicator = styled.div< {
|
|
38
|
+
isIndeterminate: boolean;
|
|
39
|
+
value?: number;
|
|
40
|
+
} >`
|
|
41
|
+
display: inline-block;
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 0;
|
|
44
|
+
height: 100%;
|
|
45
|
+
border-radius: ${ CONFIG.radiusBlockUi };
|
|
46
|
+
background-color: ${ COLORS.ui.theme };
|
|
47
|
+
|
|
48
|
+
${ ( { isIndeterminate, value } ) =>
|
|
49
|
+
isIndeterminate
|
|
50
|
+
? css( {
|
|
51
|
+
animationDuration: '1.5s',
|
|
52
|
+
animationTimingFunction: 'ease-in-out',
|
|
53
|
+
animationIterationCount: 'infinite',
|
|
54
|
+
animationName: animateProgressBar,
|
|
55
|
+
width: `${ INDETERMINATE_TRACK_WIDTH }%`,
|
|
56
|
+
} )
|
|
57
|
+
: css( { width: `${ value }%` } ) };
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
export const ProgressElement = styled.progress`
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 0;
|
|
63
|
+
left: 0;
|
|
64
|
+
opacity: 0;
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 100%;
|
|
67
|
+
`;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { ProgressBar } from '..';
|
|
10
|
+
import { INDETERMINATE_TRACK_WIDTH } from '../styles';
|
|
11
|
+
|
|
12
|
+
describe( 'ProgressBar', () => {
|
|
13
|
+
it( 'should render an indeterminate semantic progress bar element', () => {
|
|
14
|
+
render( <ProgressBar /> );
|
|
15
|
+
|
|
16
|
+
const progressBar = screen.getByRole( 'progressbar' );
|
|
17
|
+
|
|
18
|
+
expect( progressBar ).toBeInTheDocument();
|
|
19
|
+
expect( progressBar ).not.toBeVisible();
|
|
20
|
+
expect( progressBar ).not.toHaveValue();
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
it( 'should render a determinate semantic progress bar element', () => {
|
|
24
|
+
render( <ProgressBar value={ 55 } /> );
|
|
25
|
+
|
|
26
|
+
const progressBar = screen.getByRole( 'progressbar' );
|
|
27
|
+
|
|
28
|
+
expect( progressBar ).toBeInTheDocument();
|
|
29
|
+
expect( progressBar ).not.toBeVisible();
|
|
30
|
+
expect( progressBar ).toHaveValue( 55 );
|
|
31
|
+
} );
|
|
32
|
+
|
|
33
|
+
it( 'should use `INDETERMINATE_TRACK_WIDTH`% as track width for indeterminate progress bar', () => {
|
|
34
|
+
const { container } = render( <ProgressBar /> );
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* We're intentionally not using an accessible selector, because
|
|
38
|
+
* the track is an intentionally non-interactive presentation element.
|
|
39
|
+
*/
|
|
40
|
+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
|
41
|
+
const indicator = container.firstChild?.firstChild;
|
|
42
|
+
|
|
43
|
+
expect( indicator ).toHaveStyle( {
|
|
44
|
+
width: `${ INDETERMINATE_TRACK_WIDTH }%`,
|
|
45
|
+
} );
|
|
46
|
+
} );
|
|
47
|
+
|
|
48
|
+
it( 'should use `value`% as width for determinate progress bar', () => {
|
|
49
|
+
const { container } = render( <ProgressBar value={ 55 } /> );
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* We're intentionally not using an accessible selector, because
|
|
53
|
+
* the track is an intentionally non-interactive presentation element.
|
|
54
|
+
*/
|
|
55
|
+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
|
56
|
+
const indicator = container.firstChild?.firstChild;
|
|
57
|
+
|
|
58
|
+
expect( indicator ).toHaveStyle( {
|
|
59
|
+
width: '55%',
|
|
60
|
+
} );
|
|
61
|
+
} );
|
|
62
|
+
|
|
63
|
+
it( 'should pass any additional props down to the underlying `progress` element', () => {
|
|
64
|
+
const id = 'foo-bar-123';
|
|
65
|
+
const ariaLabel = 'in progress...';
|
|
66
|
+
const style = { opacity: 1 };
|
|
67
|
+
|
|
68
|
+
render(
|
|
69
|
+
<ProgressBar id={ id } aria-label={ ariaLabel } style={ style } />
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect( screen.getByRole( 'progressbar' ) ).toHaveAttribute( 'id', id );
|
|
73
|
+
expect( screen.getByRole( 'progressbar' ) ).toHaveAttribute(
|
|
74
|
+
'aria-label',
|
|
75
|
+
ariaLabel
|
|
76
|
+
);
|
|
77
|
+
expect( screen.getByRole( 'progressbar' ) ).toHaveStyle( style );
|
|
78
|
+
} );
|
|
79
|
+
} );
|