@openedx/paragon 23.23.1 → 23.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Card/CardFooter.d.ts +19 -0
- package/dist/Card/CardFooter.js +5 -31
- package/dist/Card/CardFooter.js.map +1 -1
- package/dist/Card/CardSection.d.ts +19 -0
- package/dist/Card/CardSection.js +5 -31
- package/dist/Card/CardSection.js.map +1 -1
- package/dist/Card/CardStatus.d.ts +17 -0
- package/dist/Card/CardStatus.js +3 -25
- package/dist/Card/CardStatus.js.map +1 -1
- package/dist/Collapsible/CollapsibleAdvanced.d.ts +41 -0
- package/dist/Collapsible/CollapsibleAdvanced.js +8 -38
- package/dist/Collapsible/CollapsibleAdvanced.js.map +1 -1
- package/dist/Collapsible/CollapsibleBody.d.ts +11 -0
- package/dist/Collapsible/CollapsibleBody.js +6 -20
- package/dist/Collapsible/CollapsibleBody.js.map +1 -1
- package/dist/Collapsible/CollapsibleTrigger.d.ts +17 -0
- package/dist/Collapsible/CollapsibleTrigger.js +16 -33
- package/dist/Collapsible/CollapsibleTrigger.js.map +1 -1
- package/dist/Collapsible/CollapsibleVisible.d.ts +11 -0
- package/dist/Collapsible/CollapsibleVisible.js +6 -17
- package/dist/Collapsible/CollapsibleVisible.js.map +1 -1
- package/dist/Collapsible/index.d.ts +40 -0
- package/dist/Collapsible/index.js +23 -73
- package/dist/Collapsible/index.js.map +1 -1
- package/dist/DataTable/filters/DropdownFilter.d.ts +28 -0
- package/dist/DataTable/filters/DropdownFilter.js +0 -24
- package/dist/DataTable/filters/DropdownFilter.js.map +1 -1
- package/dist/Form/FormAutosuggestOption.d.ts +11 -0
- package/dist/Form/FormAutosuggestOption.js +1 -15
- package/dist/Form/FormAutosuggestOption.js.map +1 -1
- package/dist/Form/FormControlDecorator.d.ts +7 -0
- package/dist/Form/FormControlDecorator.js +1 -9
- package/dist/Form/FormControlDecorator.js.map +1 -1
- package/dist/Form/FormControlFloatingLabel.d.ts +6 -0
- package/dist/Form/FormControlFloatingLabel.js +0 -4
- package/dist/Form/FormControlFloatingLabel.js.map +1 -1
- package/dist/Form/index.d.ts +1 -1
- package/dist/Form/index.js +0 -1
- package/dist/Form/index.js.map +1 -1
- package/dist/Modal/ModalCloseButton.d.ts +15 -0
- package/dist/Modal/ModalCloseButton.js +11 -25
- package/dist/Modal/ModalCloseButton.js.map +1 -1
- package/dist/Modal/ModalDialog.d.ts +1 -1
- package/dist/Modal/ModalDialog.js +0 -1
- package/dist/Modal/ModalDialog.js.map +1 -1
- package/dist/ProductTour/CheckpointBody.d.ts +6 -0
- package/dist/ProductTour/CheckpointBody.js +3 -10
- package/dist/ProductTour/CheckpointBody.js.map +1 -1
- package/dist/ProductTour/CheckpointTitle.d.ts +6 -0
- package/dist/ProductTour/CheckpointTitle.js +3 -10
- package/dist/ProductTour/CheckpointTitle.js.map +1 -1
- package/dist/StatefulButton/index.d.ts +45 -0
- package/dist/StatefulButton/index.js +15 -61
- package/dist/StatefulButton/index.js.map +1 -1
- package/dist/Stepper/Stepper.d.ts +22 -0
- package/dist/Stepper/Stepper.js +1 -12
- package/dist/Stepper/Stepper.js.map +1 -1
- package/dist/Stepper/StepperActionRow.d.ts +19 -0
- package/dist/Stepper/StepperActionRow.js +10 -21
- package/dist/Stepper/StepperActionRow.js.map +1 -1
- package/dist/Stepper/StepperContext.d.ts +33 -0
- package/dist/Stepper/StepperContext.js +7 -10
- package/dist/Stepper/StepperContext.js.map +1 -1
- package/dist/Stepper/StepperHeader.d.ts +27 -0
- package/dist/Stepper/StepperHeader.js +17 -43
- package/dist/Stepper/StepperHeader.js.map +1 -1
- package/dist/Stepper/StepperHeaderStep.d.ts +16 -0
- package/dist/Stepper/StepperHeaderStep.js +2 -23
- package/dist/Stepper/StepperHeaderStep.js.map +1 -1
- package/dist/Stepper/StepperStep.d.ts +29 -0
- package/dist/Stepper/StepperStep.js +1 -36
- package/dist/Stepper/StepperStep.js.map +1 -1
- package/dist/Stepper/index.js +1 -0
- package/dist/Stepper/index.js.map +1 -0
- package/dist/TransitionReplace/index.d.ts +54 -0
- package/dist/TransitionReplace/index.js +9 -60
- package/dist/TransitionReplace/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/theme-urls.json +6 -6
- package/lib/__tests__/build-scss.test.js +90 -2
- package/lib/build-scss.js +17 -10
- package/package.json +1 -1
- package/src/Card/{CardFooter.jsx → CardFooter.tsx} +25 -34
- package/src/Card/{CardSection.jsx → CardSection.tsx} +25 -34
- package/src/Card/{CardStatus.jsx → CardStatus.tsx} +21 -33
- package/src/Collapsible/{Collapsible.test.jsx → Collapsible.test.tsx} +88 -21
- package/src/Collapsible/{CollapsibleAdvanced.jsx → CollapsibleAdvanced.tsx} +42 -43
- package/src/Collapsible/{CollapsibleBody.jsx → CollapsibleBody.tsx} +13 -22
- package/src/Collapsible/{CollapsibleTrigger.jsx → CollapsibleTrigger.tsx} +29 -36
- package/src/Collapsible/{CollapsibleVisible.jsx → CollapsibleVisible.tsx} +14 -20
- package/src/Collapsible/__snapshots__/{Collapsible.test.jsx.snap → Collapsible.test.tsx.snap} +0 -1
- package/src/Collapsible/index.tsx +91 -0
- package/src/DataTable/filters/{DropdownFilter.jsx → DropdownFilter.tsx} +27 -28
- package/src/Form/{FormAutosuggestOption.jsx → FormAutosuggestOption.tsx} +12 -19
- package/src/Form/FormControlDecorator.tsx +16 -0
- package/src/Form/{FormControlFloatingLabel.jsx → FormControlFloatingLabel.tsx} +6 -7
- package/src/Form/index.tsx +0 -1
- package/src/Modal/ModalCloseButton.tsx +48 -0
- package/src/Modal/ModalDialog.tsx +0 -1
- package/src/Modal/tests/ModalDialog.test.tsx +1 -1
- package/src/ProductTour/{Checkpoint.test.jsx → Checkpoint.test.tsx} +11 -1
- package/src/ProductTour/CheckpointBody.tsx +21 -0
- package/src/ProductTour/CheckpointTitle.tsx +15 -0
- package/src/StatefulButton/{StatefulButtontest.test.jsx → StatefulButtontest.test.tsx} +4 -4
- package/src/StatefulButton/{index.jsx → index.tsx} +47 -57
- package/src/Stepper/{Stepper.jsx → Stepper.tsx} +18 -12
- package/src/Stepper/StepperActionRow.tsx +41 -0
- package/src/Stepper/{StepperContext.jsx → StepperContext.tsx} +41 -17
- package/src/Stepper/{StepperHeader.jsx → StepperHeader.tsx} +47 -44
- package/src/Stepper/{StepperHeaderStep.jsx → StepperHeaderStep.tsx} +18 -26
- package/src/Stepper/{StepperStep.jsx → StepperStep.tsx} +30 -39
- package/src/Stepper/index.ts +1 -0
- package/src/Stepper/tests/{Stepper.test.jsx → Stepper.test.tsx} +156 -14
- package/src/TransitionReplace/{TransitionReplace.test.jsx → TransitionReplace.test.tsx} +12 -10
- package/src/TransitionReplace/{index.jsx → index.tsx} +63 -72
- package/src/index.ts +4 -8
- package/src/Collapsible/index.jsx +0 -99
- package/src/Form/FormControlDecorator.jsx +0 -21
- package/src/Modal/ModalCloseButton.jsx +0 -45
- package/src/ProductTour/CheckpointBody.jsx +0 -24
- package/src/ProductTour/CheckpointTitle.jsx +0 -18
- package/src/Stepper/StepperActionRow.jsx +0 -40
- /package/{src/Stepper/index.js → dist/Stepper/index.d.ts} +0 -0
- /package/src/StatefulButton/__snapshots__/{StatefulButtontest.test.jsx.snap → StatefulButtontest.test.tsx.snap} +0 -0
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
useCallback, useEffect, useReducer, useState,
|
|
3
3
|
} from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
4
|
|
|
6
|
-
export
|
|
5
|
+
export interface Step {
|
|
6
|
+
eventKey: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
hasError?: boolean;
|
|
10
|
+
index?: number;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface StepperContextValue {
|
|
15
|
+
activeKey: string;
|
|
16
|
+
registerStep: (step: Step) => void;
|
|
17
|
+
steps: Step[];
|
|
18
|
+
removeStep: (eventKey: string) => void;
|
|
19
|
+
getIsViewed: (index: number) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const StepperContext = React.createContext<StepperContextValue>({
|
|
7
23
|
activeKey: '',
|
|
24
|
+
registerStep: () => {},
|
|
25
|
+
steps: [],
|
|
26
|
+
removeStep: () => {},
|
|
27
|
+
getIsViewed: () => false,
|
|
8
28
|
});
|
|
9
29
|
|
|
10
|
-
|
|
11
|
-
|
|
30
|
+
type StepsAction =
|
|
31
|
+
| { type: 'register'; step: Step }
|
|
32
|
+
| { type: 'remove'; eventKey: string };
|
|
33
|
+
|
|
34
|
+
const stepsReducer = (stepsState: Step[], action: StepsAction): Step[] => {
|
|
35
|
+
let newStepsState: Step[] = [];
|
|
12
36
|
switch (action.type) {
|
|
13
37
|
case 'remove':
|
|
14
38
|
return stepsState.filter(step => step.eventKey !== action.eventKey);
|
|
@@ -27,22 +51,29 @@ const stepsReducer = (stepsState, action) => {
|
|
|
27
51
|
}
|
|
28
52
|
|
|
29
53
|
// If using the index prop
|
|
30
|
-
if (stepsState.some(step => step.index)) {
|
|
54
|
+
if (stepsState.some(step => step.index !== undefined)) {
|
|
31
55
|
return newStepsState.sort((a, b) => (
|
|
32
|
-
a.index > b.index ? 1 : -1
|
|
56
|
+
(a.index || 0) > (b.index || 0) ? 1 : -1
|
|
33
57
|
));
|
|
34
58
|
}
|
|
35
59
|
return newStepsState;
|
|
36
60
|
}
|
|
37
61
|
};
|
|
38
62
|
|
|
39
|
-
export
|
|
63
|
+
export interface StepperContextProviderProps {
|
|
64
|
+
/** Specifies the content of the `ContextProvider`. */
|
|
65
|
+
children: React.ReactNode;
|
|
66
|
+
/** Specifies the current step of the `Stepper`. */
|
|
67
|
+
activeKey: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function StepperContextProvider({ children, activeKey }: StepperContextProviderProps) {
|
|
40
71
|
const [steps, dispatch] = useReducer(stepsReducer, []);
|
|
41
72
|
const [currentBoundary, setCurrentBoundary] = useState(0);
|
|
42
|
-
const registerStep = useCallback((step) => dispatch({ step, type: 'register' }), []);
|
|
43
|
-
const removeStep = useCallback((eventKey) => dispatch({ eventKey, type: 'remove' }), []);
|
|
73
|
+
const registerStep = useCallback((step: Step) => dispatch({ step, type: 'register' }), []);
|
|
74
|
+
const removeStep = useCallback((eventKey: string) => dispatch({ eventKey, type: 'remove' }), []);
|
|
44
75
|
|
|
45
|
-
const getIsViewed = (index) => index <= currentBoundary;
|
|
76
|
+
const getIsViewed = (index: number) => index <= currentBoundary;
|
|
46
77
|
|
|
47
78
|
useEffect(() => {
|
|
48
79
|
const activeIndex = steps.findIndex(step => step.eventKey === activeKey);
|
|
@@ -64,11 +95,4 @@ export function StepperContextProvider({ children, activeKey }) {
|
|
|
64
95
|
);
|
|
65
96
|
}
|
|
66
97
|
|
|
67
|
-
StepperContextProvider.propTypes = {
|
|
68
|
-
/** Specifies the content of the `ContextProvider`. */
|
|
69
|
-
children: PropTypes.node.isRequired,
|
|
70
|
-
/** Specifies the current step of the `Stepper`. */
|
|
71
|
-
activeKey: PropTypes.node.isRequired,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
98
|
export { stepsReducer };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import StepperHeaderStep from './StepperHeaderStep';
|
|
5
|
-
import { StepperContext } from './StepperContext';
|
|
4
|
+
import { StepperContext, Step } from './StepperContext';
|
|
6
5
|
import useWindowSize from '../hooks/useWindowSizeHook';
|
|
7
6
|
import breakpoints, { Size } from '../utils/breakpoints';
|
|
8
7
|
|
|
@@ -10,37 +9,72 @@ function StepListSeparator() {
|
|
|
10
9
|
return <li aria-hidden="true" className="pgn__stepper-header-line" />;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export interface StepListProps {
|
|
13
|
+
steps: Step[];
|
|
14
|
+
activeKey: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function StepList({ steps, activeKey }: StepListProps) {
|
|
14
18
|
return (
|
|
15
19
|
<ul className="pgn__stepper-header-step-list">
|
|
16
|
-
{steps.map((
|
|
17
|
-
<React.Fragment key={
|
|
20
|
+
{steps.map((step, index) => (
|
|
21
|
+
<React.Fragment key={step.eventKey}>
|
|
18
22
|
{index !== 0 && <StepListSeparator />}
|
|
19
23
|
<StepperHeaderStep
|
|
20
|
-
{...
|
|
24
|
+
{...step}
|
|
21
25
|
index={index}
|
|
22
|
-
isActive={activeKey ===
|
|
23
|
-
|
|
24
|
-
{label}
|
|
25
|
-
</StepperHeaderStep>
|
|
26
|
+
isActive={activeKey === step.eventKey}
|
|
27
|
+
/>
|
|
26
28
|
</React.Fragment>
|
|
27
29
|
))}
|
|
28
30
|
</ul>
|
|
29
31
|
);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
export interface PageCountProps {
|
|
35
|
+
activeStepIndex: number;
|
|
36
|
+
totalSteps: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function PageCount({ activeStepIndex, totalSteps }: PageCountProps) {
|
|
40
|
+
return <>Step {activeStepIndex + 1} of {totalSteps}</>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface StepperHeaderProps {
|
|
44
|
+
/** Specifies class name to append to the base element. */
|
|
45
|
+
className?: string | null;
|
|
46
|
+
/** A component that receives `activeStepIndex` and `totalSteps` props to display them. */
|
|
47
|
+
PageCountComponent?: React.ComponentType<PageCountProps>;
|
|
48
|
+
/** The max width in which the compact view of the header will switch to display the step number that is
|
|
49
|
+
* currently in progress. Options include 'xs', 'sm', 'md', 'lg', 'xl', and 'xxl'.
|
|
50
|
+
*/
|
|
51
|
+
compactWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface StepperHeaderComponent {
|
|
55
|
+
(props: StepperHeaderProps): JSX.Element | null;
|
|
56
|
+
Step: typeof StepperHeaderStep;
|
|
57
|
+
}
|
|
33
58
|
|
|
34
|
-
|
|
59
|
+
const StepperHeader: StepperHeaderComponent = function StepperHeader({
|
|
60
|
+
className = null,
|
|
61
|
+
PageCountComponent = PageCount,
|
|
62
|
+
compactWidth = 'sm',
|
|
63
|
+
}: StepperHeaderProps) {
|
|
35
64
|
const { steps, activeKey } = useContext(StepperContext);
|
|
36
65
|
const windowDimensions = useWindowSize();
|
|
37
66
|
const size = Size[compactWidth] || 'small';
|
|
38
67
|
const breakpointWidth = breakpoints[size].maxWidth || Infinity;
|
|
39
|
-
const isCompactView = windowDimensions.width < breakpointWidth;
|
|
68
|
+
const isCompactView = windowDimensions.width !== undefined && windowDimensions.width < breakpointWidth;
|
|
40
69
|
|
|
41
70
|
if (isCompactView) {
|
|
42
71
|
const activeStepIndex = steps.findIndex(step => step.eventKey === activeKey);
|
|
43
72
|
const activeStep = steps[activeStepIndex];
|
|
73
|
+
|
|
74
|
+
if (!activeStep) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
44
78
|
return (
|
|
45
79
|
<div className={classNames('pgn__stepper-header', className)}>
|
|
46
80
|
<StepperHeaderStep
|
|
@@ -65,37 +99,6 @@ function StepperHeader({ className, PageCountComponent, compactWidth }) {
|
|
|
65
99
|
<StepList steps={steps} activeKey={activeKey} />
|
|
66
100
|
</div>
|
|
67
101
|
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
StepperHeader.propTypes = {
|
|
71
|
-
/** Specifies class name to append to the base element. */
|
|
72
|
-
className: PropTypes.string,
|
|
73
|
-
/** A component that receives `activeStepIndex` and `totalSteps` props to display them. */
|
|
74
|
-
PageCountComponent: PropTypes.elementType,
|
|
75
|
-
/** The max width in which the compact view of the header will switch to display the step number that is
|
|
76
|
-
* currently in progress. Options include 'xs', 'sm', 'md', 'lg', 'xl', and 'xxl'.
|
|
77
|
-
*/
|
|
78
|
-
compactWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
StepperHeader.defaultProps = {
|
|
82
|
-
className: null,
|
|
83
|
-
PageCountComponent: PageCount,
|
|
84
|
-
compactWidth: 'sm',
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
StepList.propTypes = {
|
|
88
|
-
steps: PropTypes.arrayOf(PropTypes.shape({
|
|
89
|
-
eventKey: PropTypes.string,
|
|
90
|
-
title: PropTypes.string,
|
|
91
|
-
description: PropTypes.string,
|
|
92
|
-
hasError: PropTypes.bool,
|
|
93
|
-
})),
|
|
94
|
-
activeKey: PropTypes.string.isRequired,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
StepList.defaultProps = {
|
|
98
|
-
steps: [],
|
|
99
102
|
};
|
|
100
103
|
|
|
101
104
|
StepperHeader.Step = StepperHeaderStep;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
|
|
5
4
|
import { Check, Error } from '../../icons';
|
|
@@ -7,14 +6,29 @@ import { StepperContext } from './StepperContext';
|
|
|
7
6
|
import Icon from '../Icon';
|
|
8
7
|
import Bubble from '../Bubble';
|
|
9
8
|
|
|
9
|
+
export interface StepperHeaderStepProps {
|
|
10
|
+
/** A number that will be display in the icon of the `HeaderStep`. */
|
|
11
|
+
index: number;
|
|
12
|
+
/** A text of the `HeaderStep`. */
|
|
13
|
+
title: string;
|
|
14
|
+
/** Specifies that this `HeaderStep` is active. */
|
|
15
|
+
isActive?: boolean;
|
|
16
|
+
/** Informs user if this `Step` has errors. */
|
|
17
|
+
hasError?: boolean;
|
|
18
|
+
/** A text under the `title`. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Callback fired when element gets clicked. */
|
|
21
|
+
onClick?: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
function StepperHeaderStep({
|
|
11
25
|
title,
|
|
12
|
-
isActive,
|
|
13
|
-
hasError,
|
|
26
|
+
isActive = false,
|
|
27
|
+
hasError = false,
|
|
14
28
|
description,
|
|
15
29
|
index,
|
|
16
30
|
onClick,
|
|
17
|
-
}) {
|
|
31
|
+
}: StepperHeaderStepProps) {
|
|
18
32
|
const { getIsViewed } = useContext(StepperContext);
|
|
19
33
|
const isComplete = getIsViewed(index + 1);
|
|
20
34
|
const isViewed = getIsViewed(index);
|
|
@@ -71,26 +85,4 @@ function StepperHeaderStep({
|
|
|
71
85
|
);
|
|
72
86
|
}
|
|
73
87
|
|
|
74
|
-
StepperHeaderStep.propTypes = {
|
|
75
|
-
/** A number that will be display in the icon of the `HeaderStep`. */
|
|
76
|
-
index: PropTypes.number.isRequired,
|
|
77
|
-
/** A text of the `HeaderStep`. */
|
|
78
|
-
title: PropTypes.string.isRequired,
|
|
79
|
-
/** Specifies that this `HeaderStep` is active. */
|
|
80
|
-
isActive: PropTypes.bool,
|
|
81
|
-
/** Informs user if this `Step` has errors. */
|
|
82
|
-
hasError: PropTypes.bool,
|
|
83
|
-
/** A text under the `title`. */
|
|
84
|
-
description: PropTypes.string,
|
|
85
|
-
/** Callback fired when element gets clicked. */
|
|
86
|
-
onClick: PropTypes.func,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
StepperHeaderStep.defaultProps = {
|
|
90
|
-
isActive: false,
|
|
91
|
-
hasError: false,
|
|
92
|
-
description: undefined,
|
|
93
|
-
onClick: undefined,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
88
|
export default StepperHeaderStep;
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import { StepperContext } from './StepperContext';
|
|
5
4
|
|
|
5
|
+
export interface StepperStepProps {
|
|
6
|
+
/** Specifies the content of the `Step`. */
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/** Specifies class name to append to the base element */
|
|
9
|
+
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* An identifier of the `Step`. When `activeKey` on the
|
|
12
|
+
* `Stepper` equals to the `eventKey`, the `Step` will be displayed.
|
|
13
|
+
*/
|
|
14
|
+
eventKey: string;
|
|
15
|
+
/** A text of the `Step`. */
|
|
16
|
+
title: string;
|
|
17
|
+
/** A text under the `title`. */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** Informs user if this `Step` has errors. */
|
|
20
|
+
hasError?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Position of the `Step`, only required if adding error state
|
|
23
|
+
* or conditionally rendering steps.
|
|
24
|
+
* */
|
|
25
|
+
index?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Click handler for the `Step`. Takes effect only after the `Step` has been visited, making it clickable
|
|
28
|
+
* and invoking this function on click. Should be used to provide navigation between steps.
|
|
29
|
+
*/
|
|
30
|
+
onClick?: () => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
export default function StepperStep({
|
|
7
34
|
children,
|
|
8
35
|
eventKey,
|
|
@@ -10,9 +37,9 @@ export default function StepperStep({
|
|
|
10
37
|
title,
|
|
11
38
|
index,
|
|
12
39
|
description,
|
|
13
|
-
hasError,
|
|
40
|
+
hasError = false,
|
|
14
41
|
onClick,
|
|
15
|
-
}) {
|
|
42
|
+
}: StepperStepProps) {
|
|
16
43
|
const { activeKey, registerStep, removeStep } = useContext(StepperContext);
|
|
17
44
|
|
|
18
45
|
useEffect(() => {
|
|
@@ -39,39 +66,3 @@ export default function StepperStep({
|
|
|
39
66
|
</div>
|
|
40
67
|
);
|
|
41
68
|
}
|
|
42
|
-
|
|
43
|
-
StepperStep.propTypes = {
|
|
44
|
-
/** Specifies the content of the `Step`. */
|
|
45
|
-
children: PropTypes.node.isRequired,
|
|
46
|
-
/** Specifies class name to append to the base element */
|
|
47
|
-
className: PropTypes.string,
|
|
48
|
-
/**
|
|
49
|
-
* An identifier of the `Step`. When `activeKey` on the
|
|
50
|
-
* `Stepper` equals to the `eventKey`, the `Step` will be displayed.
|
|
51
|
-
*/
|
|
52
|
-
eventKey: PropTypes.string.isRequired,
|
|
53
|
-
/** A text of the `Step`. */
|
|
54
|
-
title: PropTypes.string.isRequired,
|
|
55
|
-
/** A text under the `title`. */
|
|
56
|
-
description: PropTypes.string,
|
|
57
|
-
/** Informs user if this `Step` has errors. */
|
|
58
|
-
hasError: PropTypes.bool,
|
|
59
|
-
/**
|
|
60
|
-
* Position of the `Step`, only required if adding error state
|
|
61
|
-
* or conditionally rendering steps.
|
|
62
|
-
* */
|
|
63
|
-
index: PropTypes.number,
|
|
64
|
-
/**
|
|
65
|
-
* Click handler for the `Step`. Takes effect only after the `Step` has been visited, making it clickable
|
|
66
|
-
* and invoking this function on click. Should be used to provide navigation between steps.
|
|
67
|
-
*/
|
|
68
|
-
onClick: PropTypes.func,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
StepperStep.defaultProps = {
|
|
72
|
-
className: undefined,
|
|
73
|
-
description: undefined,
|
|
74
|
-
hasError: false,
|
|
75
|
-
index: undefined,
|
|
76
|
-
onClick: undefined,
|
|
77
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Stepper';
|
|
@@ -3,19 +3,42 @@ import { render, screen } from '@testing-library/react';
|
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
|
|
5
5
|
import Stepper from '../Stepper';
|
|
6
|
-
import {
|
|
6
|
+
import StepperHeader, { PageCountProps } from '../StepperHeader';
|
|
7
|
+
import StepperHeaderStep from '../StepperHeaderStep';
|
|
8
|
+
import StepperStep from '../StepperStep';
|
|
9
|
+
import { StepperContext, StepperContextValue, stepsReducer } from '../StepperContext';
|
|
10
|
+
|
|
11
|
+
interface MockWindowSize {
|
|
12
|
+
width: number | undefined;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
|
-
const mockWindowSize = { width: 1000, height: 1000 };
|
|
16
|
+
const mockWindowSize: MockWindowSize = { width: 1000, height: 1000 };
|
|
9
17
|
|
|
10
18
|
jest.mock('../../hooks/useWindowSizeHook', () => () => mockWindowSize);
|
|
11
19
|
|
|
20
|
+
function CustomPageCount({ activeStepIndex, totalSteps }: PageCountProps) {
|
|
21
|
+
return <span>{`Custom ${activeStepIndex + 1}/${totalSteps}`}</span>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ExampleProps {
|
|
25
|
+
activeKey: string;
|
|
26
|
+
hasStepWithError?: boolean;
|
|
27
|
+
hasFourthStep?: boolean;
|
|
28
|
+
handleStepClick?: (key: string) => void;
|
|
29
|
+
compactWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
function Example({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
activeKey,
|
|
34
|
+
hasStepWithError,
|
|
35
|
+
hasFourthStep,
|
|
36
|
+
handleStepClick,
|
|
37
|
+
compactWidth = 'sm',
|
|
38
|
+
}: ExampleProps) {
|
|
16
39
|
return (
|
|
17
40
|
<Stepper activeKey={activeKey}>
|
|
18
|
-
<Stepper.Header compactWidth=
|
|
41
|
+
<Stepper.Header compactWidth={compactWidth} />
|
|
19
42
|
|
|
20
43
|
<Stepper.Step
|
|
21
44
|
eventKey="welcome"
|
|
@@ -60,7 +83,7 @@ function Example({
|
|
|
60
83
|
describe('Stepper', () => {
|
|
61
84
|
it('renders the activeKey content', () => {
|
|
62
85
|
const { rerender } = render(
|
|
63
|
-
<Example activeKey="welcome"
|
|
86
|
+
<Example activeKey="welcome" hasFourthStep />,
|
|
64
87
|
);
|
|
65
88
|
|
|
66
89
|
expect(screen.getByText('Welcome content')).toBeInTheDocument();
|
|
@@ -71,7 +94,7 @@ describe('Stepper', () => {
|
|
|
71
94
|
expect(screen.queryByText('Review actions content')).not.toBeInTheDocument();
|
|
72
95
|
|
|
73
96
|
rerender(
|
|
74
|
-
<Example activeKey="cats"
|
|
97
|
+
<Example activeKey="cats" hasFourthStep />,
|
|
75
98
|
);
|
|
76
99
|
|
|
77
100
|
expect(screen.getByText('Cat content')).toBeInTheDocument();
|
|
@@ -86,7 +109,7 @@ describe('Stepper', () => {
|
|
|
86
109
|
it('ignores onClick function if Step has not been visited yet', async () => {
|
|
87
110
|
const onStepClick = jest.fn();
|
|
88
111
|
render(
|
|
89
|
-
<Example activeKey="welcome"
|
|
112
|
+
<Example activeKey="welcome" hasFourthStep handleStepClick={onStepClick} />,
|
|
90
113
|
);
|
|
91
114
|
|
|
92
115
|
await userEvent.click(screen.getByText('Cat'));
|
|
@@ -96,13 +119,28 @@ describe('Stepper', () => {
|
|
|
96
119
|
it('invokes onClick function if Step has been visited', async () => {
|
|
97
120
|
const onStepClick = jest.fn();
|
|
98
121
|
render(
|
|
99
|
-
<Example activeKey="review"
|
|
122
|
+
<Example activeKey="review" hasFourthStep handleStepClick={onStepClick} />,
|
|
100
123
|
);
|
|
101
124
|
|
|
102
125
|
await userEvent.click(screen.getByText('Welcome'));
|
|
103
126
|
expect(onStepClick).toHaveBeenCalledTimes(1);
|
|
104
127
|
});
|
|
128
|
+
|
|
129
|
+
it('renders an error icon in a clickable Step with errors', async () => {
|
|
130
|
+
const onStepClick = jest.fn();
|
|
131
|
+
render(
|
|
132
|
+
<Example activeKey="review" hasStepWithError handleStepClick={onStepClick} />,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const catStepButton = screen.getByRole('button', { name: 'Cat step' });
|
|
136
|
+
expect(catStepButton).toHaveClass('pgn__stepper-header-step-has-error');
|
|
137
|
+
expect(screen.getByTestId('step-error')).toBeInTheDocument();
|
|
138
|
+
|
|
139
|
+
await userEvent.click(catStepButton);
|
|
140
|
+
expect(onStepClick).toHaveBeenCalledWith('cats');
|
|
141
|
+
});
|
|
105
142
|
});
|
|
143
|
+
|
|
106
144
|
describe('stepper header compact view', () => {
|
|
107
145
|
beforeEach(() => {
|
|
108
146
|
mockWindowSize.width = 200;
|
|
@@ -142,6 +180,58 @@ describe('Stepper', () => {
|
|
|
142
180
|
|
|
143
181
|
expect(container.querySelector(step)).toBeInTheDocument();
|
|
144
182
|
});
|
|
183
|
+
|
|
184
|
+
it('renders nothing when the activeKey does not match any step', () => {
|
|
185
|
+
const { container } = render(
|
|
186
|
+
<Example activeKey="non-existent" />,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(container.querySelector('.pgn__stepper-header')).not.toBeInTheDocument();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('renders a custom PageCountComponent', () => {
|
|
193
|
+
render(
|
|
194
|
+
<Stepper activeKey="b">
|
|
195
|
+
<Stepper.Header PageCountComponent={CustomPageCount} className="custom-header" />
|
|
196
|
+
<Stepper.Step eventKey="a" title="A">A content</Stepper.Step>
|
|
197
|
+
<Stepper.Step eventKey="b" title="B">B content</Stepper.Step>
|
|
198
|
+
</Stepper>,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
expect(screen.getByText('Custom 2/2')).toBeInTheDocument();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('renders the standard view when the window width is undefined', () => {
|
|
205
|
+
mockWindowSize.width = undefined;
|
|
206
|
+
|
|
207
|
+
const { container } = render(
|
|
208
|
+
<Example activeKey="cats" />,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
expect(container.querySelector(step)).not.toBeInTheDocument();
|
|
212
|
+
expect(screen.getAllByTestId('step')).toHaveLength(3);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('always renders the compact view when compactWidth has no max width', () => {
|
|
216
|
+
mockWindowSize.width = 5000;
|
|
217
|
+
|
|
218
|
+
const { container } = render(
|
|
219
|
+
<Example compactWidth="xxl" activeKey="cats" />,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
expect(container.querySelector(step)).toBeInTheDocument();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('falls back to the small breakpoint for an unknown compactWidth', () => {
|
|
226
|
+
mockWindowSize.width = 700;
|
|
227
|
+
|
|
228
|
+
const { container } = render(
|
|
229
|
+
// @ts-expect-error testing an invalid compactWidth value
|
|
230
|
+
<Example compactWidth="unknown" activeKey="cats" />,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
expect(container.querySelector(step)).toBeInTheDocument();
|
|
234
|
+
});
|
|
145
235
|
});
|
|
146
236
|
|
|
147
237
|
describe('tab updates', () => {
|
|
@@ -223,23 +313,75 @@ describe('stepsReducer', () => {
|
|
|
223
313
|
const step2WithError = { ...step2, hasError: true };
|
|
224
314
|
|
|
225
315
|
it('registers a steps in order', () => {
|
|
226
|
-
const action1 = { type: 'register', step: step1 };
|
|
316
|
+
const action1 = { type: 'register' as const, step: step1 };
|
|
227
317
|
const stepsState1 = stepsReducer([], action1);
|
|
228
318
|
expect(stepsState1).toEqual([step1]);
|
|
229
|
-
const action2 = { type: 'register', step: step2 };
|
|
319
|
+
const action2 = { type: 'register' as const, step: step2 };
|
|
230
320
|
const stepsState2 = stepsReducer(stepsState1, action2);
|
|
231
321
|
expect(stepsState2).toEqual([step1, step2]);
|
|
232
322
|
});
|
|
233
323
|
|
|
234
324
|
it('removes a step', () => {
|
|
235
|
-
const action = { type: 'remove', eventKey: step2.eventKey };
|
|
325
|
+
const action = { type: 'remove' as const, eventKey: step2.eventKey };
|
|
236
326
|
const steps = stepsReducer([step1, step2], action);
|
|
237
327
|
expect(steps).toEqual([step1]);
|
|
238
328
|
});
|
|
239
329
|
|
|
240
330
|
it('updates a step', () => {
|
|
241
|
-
const action = { type: 'register', step: step2WithError };
|
|
331
|
+
const action = { type: 'register' as const, step: step2WithError };
|
|
242
332
|
const steps = stepsReducer([step1, step2, step3], action);
|
|
243
333
|
expect(steps).toEqual([step1, step2WithError, step3]);
|
|
244
334
|
});
|
|
335
|
+
|
|
336
|
+
it('sorts steps by index when steps use the index prop', () => {
|
|
337
|
+
const indexedStep1 = { ...step1, index: 1 };
|
|
338
|
+
const indexedStep2 = { ...step2, index: 2 };
|
|
339
|
+
const stepWithoutIndex = { ...step3 };
|
|
340
|
+
const action = { type: 'register' as const, step: stepWithoutIndex };
|
|
341
|
+
const steps = stepsReducer([indexedStep2, indexedStep1], action);
|
|
342
|
+
expect(steps).toEqual([stepWithoutIndex, indexedStep1, indexedStep2]);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('StepperContext default value', () => {
|
|
347
|
+
it('provides no-op defaults when used outside of a Stepper', () => {
|
|
348
|
+
let contextValue: StepperContextValue | undefined;
|
|
349
|
+
function Consumer() {
|
|
350
|
+
contextValue = React.useContext(StepperContext);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
render(<Consumer />);
|
|
354
|
+
|
|
355
|
+
expect(contextValue!.activeKey).toBe('');
|
|
356
|
+
expect(contextValue!.steps).toEqual([]);
|
|
357
|
+
expect(contextValue!.getIsViewed(0)).toBe(false);
|
|
358
|
+
expect(() => contextValue!.registerStep({ eventKey: 'a', title: 'A' })).not.toThrow();
|
|
359
|
+
expect(() => contextValue!.removeStep('a')).not.toThrow();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('renders Stepper subcomponents without a provider', () => {
|
|
363
|
+
const { unmount } = render(
|
|
364
|
+
<>
|
|
365
|
+
<StepperHeader />
|
|
366
|
+
<StepperStep eventKey="a" title="A">A content</StepperStep>
|
|
367
|
+
</>,
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
expect(screen.queryByText('A content')).not.toBeInTheDocument();
|
|
371
|
+
expect(screen.queryAllByTestId('step')).toHaveLength(0);
|
|
372
|
+
expect(() => unmount()).not.toThrow();
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe('StepperHeaderStep', () => {
|
|
377
|
+
it('renders a non-active, non-error step by default', () => {
|
|
378
|
+
const onClick = jest.fn();
|
|
379
|
+
render(<StepperHeaderStep index={0} title="Default step" onClick={onClick} />);
|
|
380
|
+
|
|
381
|
+
const step = screen.getByTestId('step');
|
|
382
|
+
expect(step).not.toHaveClass('pgn__stepper-header-step-active');
|
|
383
|
+
expect(step).not.toHaveClass('pgn__stepper-header-step-has-error');
|
|
384
|
+
expect(screen.getByText('1')).toBeInTheDocument();
|
|
385
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
386
|
+
});
|
|
245
387
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render } from '@testing-library/react';
|
|
3
2
|
|
|
4
|
-
import TransitionReplace from '.';
|
|
3
|
+
import TransitionReplace, { TransitionReplaceProps } from '.';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
interface TestReplacementProps extends Omit<TransitionReplaceProps, 'children'> {
|
|
6
|
+
showContentA: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function TestReplacement({ showContentA, ...props }: TestReplacementProps) {
|
|
8
10
|
return (
|
|
9
11
|
<TransitionReplace {...props}>
|
|
10
12
|
{showContentA ? (
|
|
@@ -19,17 +21,17 @@ function TestReplacement({ showContentA, ...props }) {
|
|
|
19
21
|
describe('TransitionReplace', () => {
|
|
20
22
|
it('should add entering class names for each part of the transition', (done) => {
|
|
21
23
|
let count = 0;
|
|
22
|
-
const onChildEnter = (node) => {
|
|
24
|
+
const onChildEnter = (node: HTMLElement) => {
|
|
23
25
|
count++;
|
|
24
26
|
expect(count).toEqual(1);
|
|
25
27
|
expect(node.classList.contains('test-enter')).toEqual(true);
|
|
26
28
|
};
|
|
27
|
-
const onChildEntering = (node) => {
|
|
29
|
+
const onChildEntering = (node: HTMLElement) => {
|
|
28
30
|
count++;
|
|
29
31
|
expect(count).toEqual(2);
|
|
30
32
|
expect(node.classList.contains('test-enter-active')).toEqual(true);
|
|
31
33
|
};
|
|
32
|
-
const onChildEntered = (node) => {
|
|
34
|
+
const onChildEntered = (node: HTMLElement) => {
|
|
33
35
|
count++;
|
|
34
36
|
expect(count).toEqual(3);
|
|
35
37
|
expect(node.classList.contains('test-enter-done')).toEqual(true);
|
|
@@ -63,17 +65,17 @@ describe('TransitionReplace', () => {
|
|
|
63
65
|
|
|
64
66
|
it('should add exiting class names for each part of the transition', (done) => {
|
|
65
67
|
let count = 0;
|
|
66
|
-
const onChildExit = (node) => {
|
|
68
|
+
const onChildExit = (node: HTMLElement) => {
|
|
67
69
|
count++;
|
|
68
70
|
expect(count).toEqual(1);
|
|
69
71
|
expect(node.classList.contains('test-exit')).toEqual(true);
|
|
70
72
|
};
|
|
71
|
-
const onChildExiting = (node) => {
|
|
73
|
+
const onChildExiting = (node: HTMLElement) => {
|
|
72
74
|
count++;
|
|
73
75
|
expect(count).toEqual(2);
|
|
74
76
|
expect(node.classList.contains('test-exit-active')).toEqual(true);
|
|
75
77
|
};
|
|
76
|
-
const onChildExited = (node) => {
|
|
78
|
+
const onChildExited = (node: HTMLElement) => {
|
|
77
79
|
count++;
|
|
78
80
|
expect(count).toEqual(3);
|
|
79
81
|
expect(node.classList.contains('test-exit-done')).toEqual(true);
|