@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
|
|
4
|
+
import { ExpandLess, ExpandMore } from '../../icons';
|
|
5
|
+
import CollapsibleAdvanced, { CollapsibleContext } from './CollapsibleAdvanced';
|
|
6
|
+
import CollapsibleBody from './CollapsibleBody';
|
|
7
|
+
import CollapsibleTrigger from './CollapsibleTrigger';
|
|
8
|
+
import CollapsibleVisible from './CollapsibleVisible';
|
|
9
|
+
import Icon from '../Icon';
|
|
10
|
+
|
|
11
|
+
export interface CollapsibleProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'title'> {
|
|
12
|
+
/** Specifies contents of the component. */
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
/** Specifies class name to append to the base element. */
|
|
15
|
+
className?: string;
|
|
16
|
+
/** Specifies whether the `Collapsible` should be initially open. */
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
/** Specifies icon to show when `Collapsible` is closed. Pass `null` to hide the icon. */
|
|
19
|
+
iconWhenClosed?: React.ReactElement | null;
|
|
20
|
+
/** Specifies icon to show when `Collapsible` is open. Pass `null` to hide the icon. */
|
|
21
|
+
iconWhenOpen?: React.ReactElement | null;
|
|
22
|
+
/** Callback fired when `Collapsible` closes. */
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
/** Callback fired when `Collapsible` opens. */
|
|
25
|
+
onOpen?: () => void;
|
|
26
|
+
/** Callback fired when `Collapsible's` state is toggled. */
|
|
27
|
+
onToggle?: (isOpen: boolean) => void;
|
|
28
|
+
/** Specifies whether `Collapsible` is open. */
|
|
29
|
+
open?: boolean;
|
|
30
|
+
/** Specifies style variant. */
|
|
31
|
+
styling?: 'basic' | 'card' | 'card-lg';
|
|
32
|
+
/** Specifies title. */
|
|
33
|
+
title: React.ReactNode;
|
|
34
|
+
/** Unmount the component (remove it from the DOM) when it is collapsed */
|
|
35
|
+
unmountOnExit?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const Collapsible = React.forwardRef(({
|
|
39
|
+
children,
|
|
40
|
+
className,
|
|
41
|
+
title,
|
|
42
|
+
styling = 'card',
|
|
43
|
+
iconWhenClosed = <Icon src={ExpandMore} />,
|
|
44
|
+
iconWhenOpen = <Icon src={ExpandLess} />,
|
|
45
|
+
defaultOpen = false,
|
|
46
|
+
unmountOnExit = true,
|
|
47
|
+
...other
|
|
48
|
+
}: CollapsibleProps, ref: React.ForwardedRef<CollapsibleAdvanced>) => {
|
|
49
|
+
const titleElement = React.isValidElement(title) ? title : <span>{title}</span>;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Collapsible.Advanced
|
|
53
|
+
{...other}
|
|
54
|
+
defaultOpen={defaultOpen}
|
|
55
|
+
unmountOnExit={unmountOnExit}
|
|
56
|
+
className={classNames(className, `collapsible-${styling}`)}
|
|
57
|
+
// @ts-ignore - ref type mismatch between class component and forwardRef
|
|
58
|
+
ref={ref}
|
|
59
|
+
>
|
|
60
|
+
<Collapsible.Trigger className="collapsible-trigger">
|
|
61
|
+
{titleElement}
|
|
62
|
+
{(iconWhenClosed || iconWhenOpen) && (
|
|
63
|
+
<span className="collapsible-icon">
|
|
64
|
+
<Collapsible.Visible whenClosed>{iconWhenClosed}</Collapsible.Visible>
|
|
65
|
+
<Collapsible.Visible whenOpen>{iconWhenOpen}</Collapsible.Visible>
|
|
66
|
+
</span>
|
|
67
|
+
)}
|
|
68
|
+
</Collapsible.Trigger>
|
|
69
|
+
|
|
70
|
+
<Collapsible.Body className="collapsible-body">{children}</Collapsible.Body>
|
|
71
|
+
</Collapsible.Advanced>
|
|
72
|
+
);
|
|
73
|
+
}) as CollapsibleComponent;
|
|
74
|
+
|
|
75
|
+
interface CollapsibleComponent extends React.ForwardRefExoticComponent<
|
|
76
|
+
CollapsibleProps & React.RefAttributes<CollapsibleAdvanced>
|
|
77
|
+
> {
|
|
78
|
+
Advanced: typeof CollapsibleAdvanced;
|
|
79
|
+
Body: typeof CollapsibleBody;
|
|
80
|
+
Trigger: typeof CollapsibleTrigger;
|
|
81
|
+
Visible: typeof CollapsibleVisible;
|
|
82
|
+
Context: typeof CollapsibleContext;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Collapsible.Advanced = CollapsibleAdvanced;
|
|
86
|
+
Collapsible.Body = CollapsibleBody;
|
|
87
|
+
Collapsible.Trigger = CollapsibleTrigger;
|
|
88
|
+
Collapsible.Visible = CollapsibleVisible;
|
|
89
|
+
Collapsible.Context = CollapsibleContext;
|
|
90
|
+
|
|
91
|
+
export default Collapsible;
|
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, { useRef, ReactNode } from 'react';
|
|
3
2
|
import Form from '../../Form';
|
|
4
3
|
import { newId } from '../../utils';
|
|
5
4
|
|
|
6
5
|
const DEFAULT_VALUE = '';
|
|
7
6
|
|
|
7
|
+
interface DropdownFilterProps {
|
|
8
|
+
/**
|
|
9
|
+
* Specifies a column object.
|
|
10
|
+
*
|
|
11
|
+
* `setFilter`: Function to set the filter value.
|
|
12
|
+
*
|
|
13
|
+
* `Header`: Column header used for labels and placeholders.
|
|
14
|
+
*
|
|
15
|
+
* `filterChoices`: Specifies array of choices.
|
|
16
|
+
*
|
|
17
|
+
* `getHeaderProps`: Generates a key unique to the column being filtered.
|
|
18
|
+
*/
|
|
19
|
+
column: {
|
|
20
|
+
setFilter: (value: string | number | undefined) => void;
|
|
21
|
+
Header: ReactNode;
|
|
22
|
+
filterChoices: {
|
|
23
|
+
name: string;
|
|
24
|
+
number?: number;
|
|
25
|
+
value: string | number;
|
|
26
|
+
}[];
|
|
27
|
+
getHeaderProps: () => { key: string };
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
function DropdownFilter({
|
|
9
32
|
column: {
|
|
10
33
|
setFilter, Header, filterChoices, getHeaderProps,
|
|
11
34
|
},
|
|
12
|
-
}) {
|
|
35
|
+
}: DropdownFilterProps) {
|
|
13
36
|
// creates a unique label that does not change on re-render in case there are multiple checkbox filters in the dom
|
|
14
37
|
const ariaLabel = useRef(newId(`dropdown-filter-label-${getHeaderProps().key}-`));
|
|
15
|
-
const onChange = (e) => {
|
|
38
|
+
const onChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
16
39
|
if (e.target.value === DEFAULT_VALUE) {
|
|
17
40
|
// setting undefined resets the filter
|
|
18
41
|
return setFilter(undefined);
|
|
@@ -36,28 +59,4 @@ function DropdownFilter({
|
|
|
36
59
|
);
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
DropdownFilter.propTypes = {
|
|
40
|
-
/**
|
|
41
|
-
* Specifies a column object.
|
|
42
|
-
*
|
|
43
|
-
* `setFilter`: Function to set the filter value.
|
|
44
|
-
*
|
|
45
|
-
* `Header`: Column header used for labels and placeholders.
|
|
46
|
-
*
|
|
47
|
-
* `filterChoices`: Specifies array of choices.
|
|
48
|
-
*
|
|
49
|
-
* `getHeaderProps`: Generates a key unique to the column being filtered.
|
|
50
|
-
*/
|
|
51
|
-
column: PropTypes.shape({
|
|
52
|
-
setFilter: PropTypes.func.isRequired,
|
|
53
|
-
Header: PropTypes.oneOfType([PropTypes.elementType, PropTypes.node]).isRequired,
|
|
54
|
-
filterChoices: PropTypes.arrayOf(PropTypes.shape({
|
|
55
|
-
name: PropTypes.string.isRequired,
|
|
56
|
-
number: PropTypes.number,
|
|
57
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
58
|
-
})).isRequired,
|
|
59
|
-
getHeaderProps: PropTypes.func.isRequired,
|
|
60
|
-
}).isRequired,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
62
|
export default DropdownFilter;
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, { ComponentPropsWithoutRef, MouseEventHandler } from 'react';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import MenuItem from '../Menu/MenuItem';
|
|
5
4
|
|
|
5
|
+
interface FormAutosuggestOptionProps extends Omit<ComponentPropsWithoutRef<'li'>, 'children' | 'className' | 'onClick'> {
|
|
6
|
+
/** Specifies class name to append to the base element. */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Specifies the text-content of the `FormAutosuggestOption`. */
|
|
9
|
+
children?: string;
|
|
10
|
+
/** A click handler for the `FormAutosuggestOption` */
|
|
11
|
+
onClick?: MouseEventHandler<HTMLLIElement>;
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
function FormAutosuggestOption({
|
|
7
15
|
children,
|
|
8
16
|
className,
|
|
9
17
|
onClick,
|
|
10
18
|
...props
|
|
11
|
-
}) {
|
|
19
|
+
}: FormAutosuggestOptionProps) {
|
|
12
20
|
return (
|
|
13
21
|
<MenuItem
|
|
14
22
|
as="li"
|
|
15
23
|
data-testid="autosuggest-optionitem"
|
|
16
24
|
role="option"
|
|
17
|
-
tabIndex=
|
|
25
|
+
tabIndex={-1}
|
|
18
26
|
onClick={onClick}
|
|
19
27
|
className={classNames(className, 'dropdown-item')}
|
|
20
28
|
{...props}
|
|
@@ -24,19 +32,4 @@ function FormAutosuggestOption({
|
|
|
24
32
|
);
|
|
25
33
|
}
|
|
26
34
|
|
|
27
|
-
FormAutosuggestOption.defaultProps = {
|
|
28
|
-
className: null,
|
|
29
|
-
children: null,
|
|
30
|
-
onClick: null,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
FormAutosuggestOption.propTypes = {
|
|
34
|
-
/** Specifies class name to append to the base element. */
|
|
35
|
-
className: PropTypes.string,
|
|
36
|
-
/** Specifies the text-content of the `FormAutosuggestOption`. */
|
|
37
|
-
children: PropTypes.string,
|
|
38
|
-
/** A click handler for the `FormAutosuggestOption` */
|
|
39
|
-
onClick: PropTypes.func,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
35
|
export default FormAutosuggestOption;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface FormControlDecoratorProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
location?: 'leading' | 'trailing';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function FormControlDecorator({ children, location = 'leading' }: FormControlDecoratorProps) {
|
|
9
|
+
return (
|
|
10
|
+
<div className={`pgn__form-control-decorator pgn__form-control-decorator-${location}`}>
|
|
11
|
+
{children}
|
|
12
|
+
</div>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default FormControlDecorator;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
3
2
|
import { useFormGroupContext } from './FormGroupContext';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
interface FormControlFloatingLabelProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function FormControlFloatingLabel({ children }: FormControlFloatingLabelProps) {
|
|
6
9
|
const { controlId } = useFormGroupContext();
|
|
7
10
|
return (
|
|
8
11
|
<div className="pgn__form-control-floating-label">
|
|
@@ -18,8 +21,4 @@ function FormControlFloatingLabel({ children }) {
|
|
|
18
21
|
);
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
FormControlFloatingLabel.propTypes = {
|
|
22
|
-
children: PropTypes.node.isRequired,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
24
|
export default FormControlFloatingLabel;
|
package/src/Form/index.tsx
CHANGED
|
@@ -19,7 +19,6 @@ import FormRadioSet from './FormRadioSet';
|
|
|
19
19
|
import FormRadioSetContext from './FormRadioSetContext';
|
|
20
20
|
// @ts-ignore
|
|
21
21
|
import FormAutosuggest from './FormAutosuggest';
|
|
22
|
-
// @ts-ignore
|
|
23
22
|
import FormAutosuggestOption from './FormAutosuggestOption';
|
|
24
23
|
// @ts-ignore
|
|
25
24
|
import FormCheckbox, { CheckboxControl } from './FormCheckbox';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useContext, ReactNode, ElementType, forwardRef, createElement,
|
|
3
|
+
} from 'react';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import ModalContext from './ModalContext';
|
|
6
|
+
import Button, { type ButtonProps } from '../Button';
|
|
7
|
+
import type { ComponentWithAsProp } from '../utils/types/bootstrap';
|
|
8
|
+
|
|
9
|
+
export interface ModalCloseButtonProps extends Omit<ButtonProps, 'children' | 'onClick'> {
|
|
10
|
+
/** Specifies the base element */
|
|
11
|
+
as?: ElementType;
|
|
12
|
+
/** Specifies the content of the button */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
/** Specifies class name to append to the base element */
|
|
15
|
+
className?: string;
|
|
16
|
+
/** Specifies the callback function when the close button is clicked */
|
|
17
|
+
onClick?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ModalCloseButton: ComponentWithAsProp<'button', ModalCloseButtonProps> = forwardRef(({
|
|
21
|
+
as = Button,
|
|
22
|
+
children = null,
|
|
23
|
+
className,
|
|
24
|
+
onClick,
|
|
25
|
+
...props
|
|
26
|
+
}: ModalCloseButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) => {
|
|
27
|
+
const { onClose } = useContext(ModalContext);
|
|
28
|
+
const type = as;
|
|
29
|
+
const componentProps = {
|
|
30
|
+
...props,
|
|
31
|
+
className: classNames('pgn__modal-close-button', className),
|
|
32
|
+
onClick: () => {
|
|
33
|
+
onClose();
|
|
34
|
+
if (onClick) {
|
|
35
|
+
onClick();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
ref,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Use the non-jsx syntax to create this element so we can more
|
|
42
|
+
// finely control the component type (defaulted to Button via defaultProps)
|
|
43
|
+
return createElement(type, componentProps, children);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
ModalCloseButton.displayName = 'ModalCloseButton';
|
|
47
|
+
|
|
48
|
+
export default ModalCloseButton;
|
|
@@ -3,7 +3,6 @@ import classNames from 'classnames';
|
|
|
3
3
|
import { useMediaQuery } from 'react-responsive';
|
|
4
4
|
import { useIntl } from 'react-intl';
|
|
5
5
|
import ModalLayer from './ModalLayer';
|
|
6
|
-
// @ts-ignore for now - this needs to be converted to TypeScript
|
|
7
6
|
import ModalCloseButton from './ModalCloseButton';
|
|
8
7
|
import ModalDialogHeader from './ModalDialogHeader';
|
|
9
8
|
// @ts-ignore for now - this needs to be converted to TypeScript
|
|
@@ -51,7 +51,7 @@ describe('ModalDialog', () => {
|
|
|
51
51
|
>
|
|
52
52
|
<ModalDialog.Header><ModalDialog.Title>The title</ModalDialog.Title></ModalDialog.Header>
|
|
53
53
|
<ModalDialog.Body><p>The hidden content</p></ModalDialog.Body>
|
|
54
|
-
<ModalDialog.Footer><ModalDialog.CloseButton>Cancel</ModalDialog.CloseButton></ModalDialog.Footer>
|
|
54
|
+
<ModalDialog.Footer><ModalDialog.CloseButton variant="tertiary">Cancel</ModalDialog.CloseButton></ModalDialog.Footer>
|
|
55
55
|
</ModalDialog>
|
|
56
56
|
</IntlProvider>,
|
|
57
57
|
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import userEvent, { PointerEventsCheckLevel } from '@testing-library/user-event';
|
|
4
3
|
import { IntlProvider } from 'react-intl';
|
|
5
4
|
|
|
6
5
|
import * as popper from '@popperjs/core';
|
|
7
6
|
|
|
7
|
+
// @ts-ignore
|
|
8
8
|
import Checkpoint from './Checkpoint';
|
|
9
|
+
import CheckpointTitle from './CheckpointTitle';
|
|
9
10
|
|
|
10
11
|
const popperMock = jest.spyOn(popper, 'createPopper');
|
|
11
12
|
|
|
@@ -131,4 +132,13 @@ describe('Checkpoint', () => {
|
|
|
131
132
|
expect(screen.getByText('End', { selector: 'button' })).toBeInTheDocument();
|
|
132
133
|
});
|
|
133
134
|
});
|
|
135
|
+
|
|
136
|
+
// This test is based on the existing behavior, but it doesn't necessarily make sense.
|
|
137
|
+
// It would probably be better to render nothing at all when no heading text is provided.
|
|
138
|
+
describe('CheckpointTitle', () => {
|
|
139
|
+
it('renders an empty heading when no children are provided', () => {
|
|
140
|
+
render(<CheckpointTitle />);
|
|
141
|
+
expect(screen.getByRole('heading', { level: 2 })).toBeEmptyDOMElement();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
134
144
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { forwardRef, ForwardedRef, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface CheckpointBodyProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const CheckpointBody = forwardRef(({
|
|
8
|
+
children = null,
|
|
9
|
+
}: CheckpointBodyProps, ref: ForwardedRef<HTMLDivElement>) => {
|
|
10
|
+
if (!children) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="pgn__checkpoint-body" ref={ref}>
|
|
16
|
+
{children}
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default CheckpointBody;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { forwardRef, ForwardedRef, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface CheckpointTitleProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const CheckpointTitle = forwardRef(({
|
|
8
|
+
children = null,
|
|
9
|
+
}: CheckpointTitleProps, ref: ForwardedRef<HTMLHeadingElement>) => (
|
|
10
|
+
<h2 id="pgn__checkpoint-title" ref={ref}>
|
|
11
|
+
{children}
|
|
12
|
+
</h2>
|
|
13
|
+
));
|
|
14
|
+
|
|
15
|
+
export default CheckpointTitle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer from 'react-test-renderer';
|
|
3
3
|
|
|
4
|
-
import StatefulButton from '
|
|
4
|
+
import StatefulButton from '.';
|
|
5
5
|
import Icon from '../Icon';
|
|
6
6
|
|
|
7
7
|
describe('StatefulButton', () => {
|
|
@@ -13,7 +13,7 @@ describe('StatefulButton', () => {
|
|
|
13
13
|
complete: 'Saved',
|
|
14
14
|
},
|
|
15
15
|
className: 'mr-2',
|
|
16
|
-
variant: 'primary',
|
|
16
|
+
variant: 'primary' as const,
|
|
17
17
|
};
|
|
18
18
|
const tree = renderer.create((
|
|
19
19
|
<div>
|
|
@@ -39,7 +39,7 @@ describe('StatefulButton', () => {
|
|
|
39
39
|
},
|
|
40
40
|
disabledStates: ['pending'],
|
|
41
41
|
className: 'mr-2',
|
|
42
|
-
variant: 'primary',
|
|
42
|
+
variant: 'primary' as const,
|
|
43
43
|
};
|
|
44
44
|
const tree = renderer.create((
|
|
45
45
|
<>
|
|
@@ -63,7 +63,7 @@ describe('StatefulButton', () => {
|
|
|
63
63
|
},
|
|
64
64
|
disabledStates: ['unedited'],
|
|
65
65
|
className: 'mr-2',
|
|
66
|
-
variant: 'primary',
|
|
66
|
+
variant: 'primary' as const,
|
|
67
67
|
};
|
|
68
68
|
const tree = renderer.create((
|
|
69
69
|
<>
|
|
@@ -1,19 +1,61 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import { Cancel, CheckCircleOutline, SpinnerSimple } from '../../icons';
|
|
5
4
|
import Button from '../Button';
|
|
6
5
|
import Icon from '../Icon';
|
|
7
6
|
|
|
7
|
+
export interface StatefulButtonProps extends React.ComponentPropsWithoutRef<typeof Button> {
|
|
8
|
+
/** Optionally specify additional CSS classes to give this button. */
|
|
9
|
+
className?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Each state has:
|
|
12
|
+
* - A label (required)
|
|
13
|
+
* - An icon
|
|
14
|
+
* - an option to be disabled
|
|
15
|
+
*
|
|
16
|
+
* Control the state with the `state` prop. Example usage:
|
|
17
|
+
*
|
|
18
|
+
* ```jsx
|
|
19
|
+
* <StatefulButton
|
|
20
|
+
* state="pending"
|
|
21
|
+
* labels={{
|
|
22
|
+
* default: 'Download',
|
|
23
|
+
* pending: 'Downloading',
|
|
24
|
+
* complete: 'Downloaded',
|
|
25
|
+
* }}
|
|
26
|
+
* icons={{
|
|
27
|
+
* default: <Icon className="fa fa-download" />,
|
|
28
|
+
* pending: <Icon className="fa fa-spinner fa-spin" />,
|
|
29
|
+
* complete: <Icon className="fa fa-check" />,
|
|
30
|
+
* }}
|
|
31
|
+
* disabledStates=['pending']
|
|
32
|
+
* className='btn-primary mr-2'
|
|
33
|
+
* />
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
state?: string;
|
|
37
|
+
/** Each state has a `label`. Required. */
|
|
38
|
+
labels: { [key: string]: React.ReactNode };
|
|
39
|
+
/** Each state has an `icon`. */
|
|
40
|
+
icons?: { [key: string]: React.ReactNode };
|
|
41
|
+
/** States listed in `disabledStates` will not be clickable */
|
|
42
|
+
disabledStates?: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
8
45
|
function StatefulButton({
|
|
9
46
|
className,
|
|
10
|
-
state,
|
|
47
|
+
state = 'default',
|
|
11
48
|
labels,
|
|
12
|
-
icons
|
|
13
|
-
|
|
49
|
+
icons = {
|
|
50
|
+
default: undefined,
|
|
51
|
+
pending: <Icon src={SpinnerSimple} className={classNames('icon-spin')} />,
|
|
52
|
+
complete: <Icon src={CheckCircleOutline} />,
|
|
53
|
+
error: <Icon src={Cancel} />,
|
|
54
|
+
},
|
|
55
|
+
disabledStates = ['pending', 'complete'],
|
|
14
56
|
onClick,
|
|
15
57
|
...attributes
|
|
16
|
-
}) {
|
|
58
|
+
}: StatefulButtonProps) {
|
|
17
59
|
const isDisabled = disabledStates.indexOf(state) !== -1;
|
|
18
60
|
const icon = icons[state] !== undefined ? icons[state] : icons.default;
|
|
19
61
|
const label = labels[state] !== undefined ? labels[state] : labels.default;
|
|
@@ -51,56 +93,4 @@ function StatefulButton({
|
|
|
51
93
|
);
|
|
52
94
|
}
|
|
53
95
|
|
|
54
|
-
StatefulButton.propTypes = {
|
|
55
|
-
className: PropTypes.string,
|
|
56
|
-
/**
|
|
57
|
-
* Each state has:
|
|
58
|
-
* - A label (required)
|
|
59
|
-
* - An icon
|
|
60
|
-
* - an option to be disabled
|
|
61
|
-
*
|
|
62
|
-
* Control the state with the `state` prop. Example usage:
|
|
63
|
-
*
|
|
64
|
-
* ```jsx
|
|
65
|
-
* <StatefulButton
|
|
66
|
-
* state="pending"
|
|
67
|
-
* labels={{
|
|
68
|
-
* default: 'Download',
|
|
69
|
-
* pending: 'Downloading',
|
|
70
|
-
* complete: 'Downloaded',
|
|
71
|
-
* }}
|
|
72
|
-
* icons={{
|
|
73
|
-
* default: <Icon className="fa fa-download" />,
|
|
74
|
-
* pending: <Icon className="fa fa-spinner fa-spin" />,
|
|
75
|
-
* complete: <Icon className="fa fa-check" />,
|
|
76
|
-
* }}
|
|
77
|
-
* disabledStates=['pending']
|
|
78
|
-
* className='btn-primary mr-2'
|
|
79
|
-
* />
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
state: PropTypes.string,
|
|
83
|
-
/** Required. Each state has a `label`. */
|
|
84
|
-
labels: PropTypes.objectOf(PropTypes.node).isRequired,
|
|
85
|
-
/** Required. Each state has an `icon`. */
|
|
86
|
-
icons: PropTypes.objectOf(PropTypes.node),
|
|
87
|
-
/** Required. Each state has a `disabledState` */
|
|
88
|
-
disabledStates: PropTypes.arrayOf(PropTypes.string),
|
|
89
|
-
/** Specifies the callback function when the button is clicked */
|
|
90
|
-
onClick: PropTypes.func,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
StatefulButton.defaultProps = {
|
|
94
|
-
className: undefined,
|
|
95
|
-
state: 'default',
|
|
96
|
-
icons: {
|
|
97
|
-
default: undefined,
|
|
98
|
-
pending: <Icon src={SpinnerSimple} className={classNames('icon-spin')} />,
|
|
99
|
-
complete: <Icon src={CheckCircleOutline} />,
|
|
100
|
-
error: <Icon src={Cancel} />,
|
|
101
|
-
},
|
|
102
|
-
disabledStates: ['pending', 'complete'],
|
|
103
|
-
onClick: undefined,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
96
|
export default StatefulButton;
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import StepperStep from './StepperStep';
|
|
4
3
|
import StepperHeader from './StepperHeader';
|
|
5
4
|
import StepperActionRow from './StepperActionRow';
|
|
6
5
|
import { StepperContextProvider } from './StepperContext';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<StepperContextProvider activeKey={activeKey}>
|
|
11
|
-
{children}
|
|
12
|
-
</StepperContextProvider>
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Stepper.propTypes = {
|
|
7
|
+
export interface StepperProps {
|
|
17
8
|
/**
|
|
18
9
|
* Specifies the content of the `Stepper`.
|
|
19
10
|
*/
|
|
20
|
-
children:
|
|
11
|
+
children: React.ReactNode;
|
|
21
12
|
/**
|
|
22
13
|
* The eventKey of the step to display.
|
|
23
14
|
*/
|
|
24
|
-
activeKey:
|
|
15
|
+
activeKey: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface StepperComponent {
|
|
19
|
+
(props: StepperProps): JSX.Element;
|
|
20
|
+
Step: typeof StepperStep;
|
|
21
|
+
Header: typeof StepperHeader;
|
|
22
|
+
ActionRow: typeof StepperActionRow;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const Stepper: StepperComponent = function Stepper({ children, activeKey }: StepperProps) {
|
|
26
|
+
return (
|
|
27
|
+
<StepperContextProvider activeKey={activeKey}>
|
|
28
|
+
{children}
|
|
29
|
+
</StepperContextProvider>
|
|
30
|
+
);
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
Stepper.Step = StepperStep;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useContext, forwardRef } from 'react';
|
|
2
|
+
import { StepperContext } from './StepperContext';
|
|
3
|
+
import ActionRow from '../ActionRow';
|
|
4
|
+
import type { ComponentWithAsProp } from '../utils/types/bootstrap';
|
|
5
|
+
|
|
6
|
+
export interface StepperActionRowProps {
|
|
7
|
+
/** Specifies the content of the `ActionRow`. */
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* An identifier of the `ActionRow`. When `activeKey` on the
|
|
11
|
+
* `Stepper` equals to the `eventKey`, the `ActionRow` will be displayed.
|
|
12
|
+
*/
|
|
13
|
+
eventKey: string;
|
|
14
|
+
/** Specifies the base element */
|
|
15
|
+
as?: React.ElementType;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type StepperActionRowComponent = ComponentWithAsProp<'div', StepperActionRowProps> & {
|
|
19
|
+
Spacer: typeof ActionRow.Spacer;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const StepperActionRow: ComponentWithAsProp<'div', StepperActionRowProps> = forwardRef(({
|
|
23
|
+
as = ActionRow,
|
|
24
|
+
children,
|
|
25
|
+
eventKey,
|
|
26
|
+
...props
|
|
27
|
+
}: StepperActionRowProps, ref: React.ForwardedRef<HTMLDivElement>) => {
|
|
28
|
+
const { activeKey } = useContext(StepperContext);
|
|
29
|
+
const isActive = activeKey === eventKey;
|
|
30
|
+
|
|
31
|
+
if (!isActive) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return React.createElement(as, { ...props, ref }, children);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
(StepperActionRow as StepperActionRowComponent).Spacer = ActionRow.Spacer;
|
|
39
|
+
StepperActionRow.displayName = 'StepperActionRow';
|
|
40
|
+
|
|
41
|
+
export default StepperActionRow as StepperActionRowComponent;
|