@openedx/paragon 23.0.0-alpha.2 → 23.0.0-alpha.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/Button/index.d.ts +35 -0
- package/dist/Button/index.js +37 -15
- package/dist/Button/index.js.map +1 -1
- package/dist/Chip/ChipIcon.d.ts +13 -8
- package/dist/Chip/ChipIcon.js +0 -2
- package/dist/Chip/ChipIcon.js.map +1 -1
- package/dist/Chip/constants.d.ts +4 -0
- package/dist/Chip/constants.js +3 -2
- package/dist/Chip/constants.js.map +1 -0
- package/dist/Chip/index.d.ts +4 -3
- package/dist/Chip/index.js +2 -4
- package/dist/Chip/index.js.map +1 -1
- package/dist/ChipCarousel/index.js +0 -2
- package/dist/ChipCarousel/index.js.map +1 -1
- package/dist/Hyperlink/index.d.ts +24 -0
- package/dist/Hyperlink/index.js +20 -32
- package/dist/Hyperlink/index.js.map +1 -1
- package/dist/Icon/index.d.ts +4 -2
- package/dist/Icon/index.js +1 -1
- package/dist/Icon/index.js.map +1 -1
- package/dist/IconButton/index.d.ts +342 -0
- package/dist/IconButton/index.js +18 -26
- package/dist/IconButton/index.js.map +1 -1
- package/dist/Modal/ModalPopup.js +7 -1
- package/dist/Modal/ModalPopup.js.map +1 -1
- package/dist/Modal/_ModalDialog.scss +4 -0
- package/dist/Overlay/index.d.ts +128 -0
- package/dist/Overlay/index.js +8 -2
- package/dist/Overlay/index.js.map +1 -1
- package/dist/Tooltip/index.d.ts +7 -0
- package/dist/Tooltip/index.js.map +1 -1
- package/dist/core.css +3 -0
- package/dist/core.css.map +1 -1
- package/dist/core.min.css +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -7
- package/dist/setupTest.d.ts +2 -0
- package/dist/setupTest.js.map +1 -0
- package/dist/utils/types/bootstrap.d.ts +39 -0
- package/dist/utils/types/bootstrap.js +2 -0
- package/dist/utils/types/bootstrap.js.map +1 -0
- package/package.json +5 -5
- package/src/Button/{Button.test.jsx → Button.test.tsx} +14 -2
- package/src/Button/__snapshots__/{Button.test.jsx.snap → Button.test.tsx.snap} +19 -2
- package/src/Button/{index.jsx → index.tsx} +58 -16
- package/src/Chip/{Chip.test.jsx → Chip.test.tsx} +5 -7
- package/src/Chip/ChipIcon.tsx +8 -8
- package/src/Chip/{constants.js → constants.ts} +1 -1
- package/src/Chip/index.tsx +6 -8
- package/src/ChipCarousel/index.tsx +0 -2
- package/src/Hyperlink/{Hyperlink.test.jsx → Hyperlink.test.tsx} +21 -10
- package/src/Hyperlink/{index.jsx → index.tsx} +41 -37
- package/src/Icon/index.d.ts +4 -2
- package/src/Icon/index.jsx +1 -1
- package/src/IconButton/{IconButton.test.jsx → IconButton.test.tsx} +24 -3
- package/src/IconButton/__snapshots__/IconButton.test.tsx.snap +90 -0
- package/src/IconButton/{index.jsx → index.tsx} +66 -26
- package/src/Modal/ModalPopup.jsx +9 -1
- package/src/Modal/_ModalDialog.scss +4 -0
- package/src/Modal/tests/ModalPopupNoMock.test.jsx +29 -0
- package/src/Overlay/{index.jsx → index.tsx} +13 -8
- package/src/Tooltip/{index.jsx → index.tsx} +9 -3
- package/src/index.d.ts +5 -5
- package/src/index.js +7 -7
- package/src/{setupTest.js → setupTest.ts} +1 -0
- package/src/utils/types/bootstrap.test.tsx +86 -0
- package/src/utils/types/bootstrap.ts +43 -0
- package/src/IconButton/__snapshots__/IconButton.test.jsx.snap +0 -20
- /package/src/Button/{ButtonGroup.test.jsx → ButtonGroup.test.tsx} +0 -0
- /package/src/Button/{ButtonToolbar.test.jsx → ButtonToolbar.test.tsx} +0 -0
- /package/src/Button/__snapshots__/{ButtonGroup.test.jsx.snap → ButtonGroup.test.tsx.snap} +0 -0
- /package/src/Button/__snapshots__/{ButtonToolbar.test.jsx.snap → ButtonToolbar.test.tsx.snap} +0 -0
- /package/src/Chip/__snapshots__/{Chip.test.jsx.snap → Chip.test.tsx.snap} +0 -0
- /package/src/Tooltip/{Tooltip.test.jsx → Tooltip.test.tsx} +0 -0
package/src/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
//
|
|
2
|
-
// and each line number is the same
|
|
1
|
+
// Keep this file in sync with the .d.ts file (manually). It's in the same order
|
|
2
|
+
// and each line number is the same, to make it easier.
|
|
3
3
|
|
|
4
4
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
5
5
|
// Things that have types
|
|
6
6
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
7
7
|
export { default as Bubble } from './Bubble';
|
|
8
|
+
export { default as Button, ButtonGroup, ButtonToolbar } from './Button';
|
|
8
9
|
export { default as Chip, CHIP_PGN_CLASS } from './Chip';
|
|
9
10
|
export { default as ChipCarousel } from './ChipCarousel';
|
|
11
|
+
export { default as Hyperlink, HYPER_LINK_EXTERNAL_LINK_ALT_TEXT, HYPER_LINK_EXTERNAL_LINK_TITLE } from './Hyperlink';
|
|
10
12
|
export { default as Icon } from './Icon';
|
|
13
|
+
export { default as IconButton, IconButtonWithTooltip } from './IconButton';
|
|
14
|
+
export { default as Overlay, OverlayTrigger } from './Overlay';
|
|
15
|
+
export { default as Tooltip } from './Tooltip';
|
|
11
16
|
|
|
12
17
|
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
|
13
18
|
// Things that don't have types
|
|
@@ -20,7 +25,6 @@ export { default as Avatar } from './Avatar';
|
|
|
20
25
|
export { default as AvatarButton } from './AvatarButton';
|
|
21
26
|
export { default as Badge } from './Badge';
|
|
22
27
|
export { default as Breadcrumb } from './Breadcrumb';
|
|
23
|
-
export { default as Button, ButtonGroup, ButtonToolbar } from './Button';
|
|
24
28
|
export {
|
|
25
29
|
default as Card,
|
|
26
30
|
CardColumns,
|
|
@@ -69,8 +73,6 @@ export {
|
|
|
69
73
|
FormAutosuggestOption,
|
|
70
74
|
InputGroup,
|
|
71
75
|
} from './Form';
|
|
72
|
-
export { default as Hyperlink, HYPER_LINK_EXTERNAL_LINK_ALT_TEXT, HYPER_LINK_EXTERNAL_LINK_TITLE } from './Hyperlink';
|
|
73
|
-
export { default as IconButton, IconButtonWithTooltip } from './IconButton';
|
|
74
76
|
export { default as IconButtonToggle } from './IconButtonToggle';
|
|
75
77
|
export { default as Image, Figure } from './Image';
|
|
76
78
|
export { default as MailtoLink, MAIL_TO_LINK_EXTERNAL_LINK_ALTERNATIVE_TEXT, MAIL_TO_LINK_EXTERNAL_LINK_TITLE } from './MailtoLink';
|
|
@@ -97,7 +99,6 @@ export {
|
|
|
97
99
|
NavLink,
|
|
98
100
|
} from './Nav';
|
|
99
101
|
export { default as Navbar, NavbarBrand, NAVBAR_LABEL } from './Navbar';
|
|
100
|
-
export { default as Overlay, OverlayTrigger } from './Overlay';
|
|
101
102
|
export { default as PageBanner, PAGE_BANNER_DISMISS_ALT_TEXT } from './PageBanner';
|
|
102
103
|
export {
|
|
103
104
|
default as Pagination,
|
|
@@ -132,7 +133,6 @@ export {
|
|
|
132
133
|
TabPane,
|
|
133
134
|
} from './Tabs';
|
|
134
135
|
export { default as Toast, TOAST_CLOSE_LABEL_TEXT, TOAST_DELAY } from './Toast';
|
|
135
|
-
export { default as Tooltip } from './Tooltip';
|
|
136
136
|
export { default as TransitionReplace } from './TransitionReplace';
|
|
137
137
|
export { default as ValidationMessage } from './ValidationMessage';
|
|
138
138
|
export { default as DataTable } from './DataTable';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { BsPropsWithAs, ComponentWithAsProp } from './bootstrap';
|
|
4
|
+
|
|
5
|
+
// Note: these are type-only tests. They don't actually do much at runtime; the important checks are at transpile time.
|
|
6
|
+
|
|
7
|
+
describe('BsPropsWithAs', () => {
|
|
8
|
+
interface Props<As extends React.ElementType = 'table'> extends BsPropsWithAs<As> {
|
|
9
|
+
otherProp?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
it('defines optional bsPrefix, className, and as but no other props', () => {
|
|
13
|
+
const checkProps = <As extends React.ElementType = 'table'>(_props: Props<As>) => {};
|
|
14
|
+
// These are all valid props per the prop definition:
|
|
15
|
+
checkProps({ });
|
|
16
|
+
checkProps({ bsPrefix: 'bs' });
|
|
17
|
+
checkProps({ className: 'foo bar' });
|
|
18
|
+
checkProps({ as: 'tr' });
|
|
19
|
+
checkProps({ className: 'foo bar', as: 'button', otherProp: 15 });
|
|
20
|
+
// But these are all invalid:
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
checkProps({ newProp: 10 });
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
checkProps({ onClick: () => {} });
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
checkProps({ id: 'id' });
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
checkProps({ children: <tr /> });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('ComponentWithAsProp', () => {
|
|
33
|
+
interface MyProps extends BsPropsWithAs {
|
|
34
|
+
customProp?: string;
|
|
35
|
+
}
|
|
36
|
+
const MyComponent: ComponentWithAsProp<'div', MyProps> = (
|
|
37
|
+
React.forwardRef<HTMLDivElement, MyProps>(
|
|
38
|
+
({ as: Inner = 'div', ...props }, ref) => <Inner {...props} ref={ref} />,
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line react/function-component-definition
|
|
43
|
+
const CustomComponent: React.FC<{ requiredProp: string }> = () => <span />;
|
|
44
|
+
|
|
45
|
+
it('is defined to wrap a <div> by default, and accepts related props', () => {
|
|
46
|
+
// This is valid - by default it is a DIV so accepts props and ref related to DIV:
|
|
47
|
+
const divClick: React.MouseEventHandler<HTMLDivElement> = () => {};
|
|
48
|
+
const divRef: React.RefObject<HTMLDivElement> = { current: null };
|
|
49
|
+
const valid = <MyComponent ref={divRef} onClick={divClick} customProp="foo" />;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('is defined to wrap a <div> by default, and rejects unrelated props', () => {
|
|
53
|
+
const btnRef: React.RefObject<HTMLButtonElement> = { current: null };
|
|
54
|
+
// @ts-expect-error because the ref is to a <button> ref, but this is wrapping a <div>
|
|
55
|
+
const invalidRef = <MyComponent ref={btnRef} customProp="foo" />;
|
|
56
|
+
|
|
57
|
+
const btnClick: React.MouseEventHandler<HTMLButtonElement> = () => {};
|
|
58
|
+
// @ts-expect-error because the handler is for a <button> event, but this is wrapping a <div>
|
|
59
|
+
const invalidClick = <MyComponent onClick={btnClick} />;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('can be changed to wrap a <canvas>, and accepts related props', () => {
|
|
63
|
+
const canvasClick: React.MouseEventHandler<HTMLCanvasElement> = () => {};
|
|
64
|
+
const canvasRef: React.RefObject<HTMLCanvasElement> = { current: null };
|
|
65
|
+
const valid = <MyComponent as="canvas" ref={canvasRef} onClick={canvasClick} customProp="foo" />;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('can be changed to wrap a <canvas>, and rejects unrelated props', () => {
|
|
69
|
+
const btnRef: React.RefObject<HTMLButtonElement> = { current: null };
|
|
70
|
+
// @ts-expect-error because the ref is to a <button> ref, but this is wrapping an <canvas>
|
|
71
|
+
const invalidRef = <MyComponent as="canvas" ref={btnRef} customProp="foo" />;
|
|
72
|
+
|
|
73
|
+
const btnClick: React.MouseEventHandler<HTMLButtonElement> = () => {};
|
|
74
|
+
// @ts-expect-error because the handler is for a <button> event, but this is wrapping an <canvas>
|
|
75
|
+
const invalidClick = <MyComponent as="canvas" onClick={btnClick} />;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('can be changed to wrap a custom component, and accepts related props', () => {
|
|
79
|
+
const valid = <MyComponent as={CustomComponent} requiredProp="hello" />;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('can be changed to wrap a custom component, and rejects unrelated props', () => {
|
|
83
|
+
// @ts-expect-error The onClick prop has not been declared for our custom component.
|
|
84
|
+
const valid = <MyComponent as={CustomComponent} requiredProp="hello" onClick={() => {}} />;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types related to bootstrap components
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import type { BsPrefixProps, BsPrefixRefForwardingComponent } from 'react-bootstrap/esm/helpers';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type helper for defining props of a component that wraps a bootstrap
|
|
10
|
+
* component. This type defines three props:
|
|
11
|
+
* 1. `className`: this component accepts additional CSS classes.
|
|
12
|
+
* 2. `bsPrefix`: locally change the class name prefix used for this component.
|
|
13
|
+
* 3. `as`: optionally specify which HTML element or Component is used, e.g. `"div"`
|
|
14
|
+
*
|
|
15
|
+
* This type assumes no `children` are allowed, but you can extend it to allow children.
|
|
16
|
+
*/
|
|
17
|
+
export type BsPropsWithAs<As extends React.ElementType = React.ElementType> = BsPrefixProps<As>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This is a helper that can be used to define the type of a Paragon component
|
|
21
|
+
* that accepts an `as` prop.
|
|
22
|
+
*
|
|
23
|
+
* It:
|
|
24
|
+
* - assumes you are using `forwardRef`, and sets the type of the `ref` prop
|
|
25
|
+
* to match the type of the component passed in the `as` prop.
|
|
26
|
+
* - assumes you are passing all unused props to the component, so adds any
|
|
27
|
+
* props from the `as` component type to the props you specify as `Props`.
|
|
28
|
+
*
|
|
29
|
+
* Example;
|
|
30
|
+
* ```
|
|
31
|
+
* interface MyProps extends BsPropsWithAs {
|
|
32
|
+
* customProp?: string;
|
|
33
|
+
* }
|
|
34
|
+
* export const MyComponent: ComponentWithAsProp<'div', MyProps> = (
|
|
35
|
+
* React.forwardRef<HTMLDivElement, MyProps>(
|
|
36
|
+
* ({ as: Inner = 'div', ...props }, ref) => <Inner {...props} ref={ref} />,
|
|
37
|
+
* )
|
|
38
|
+
* );
|
|
39
|
+
* ```
|
|
40
|
+
* Note that you need to define the default (e.g. `'div'`) in three different places.
|
|
41
|
+
*/
|
|
42
|
+
export type ComponentWithAsProp<DefaultElementType extends React.ElementType, Props>
|
|
43
|
+
= BsPrefixRefForwardingComponent<DefaultElementType, Props>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<IconButton /> renders with required props 1`] = `
|
|
4
|
-
<button
|
|
5
|
-
aria-label="alternative"
|
|
6
|
-
className="btn-icon btn-icon-primary btn-icon-md"
|
|
7
|
-
onClick={[Function]}
|
|
8
|
-
type="button"
|
|
9
|
-
>
|
|
10
|
-
<span
|
|
11
|
-
className="btn-icon__icon-container"
|
|
12
|
-
>
|
|
13
|
-
<span
|
|
14
|
-
aria-hidden={true}
|
|
15
|
-
className="btn-icon__icon"
|
|
16
|
-
id="Icon1"
|
|
17
|
-
/>
|
|
18
|
-
</span>
|
|
19
|
-
</button>
|
|
20
|
-
`;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/Button/__snapshots__/{ButtonToolbar.test.jsx.snap → ButtonToolbar.test.tsx.snap}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|