@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.
Files changed (74) hide show
  1. package/dist/Button/index.d.ts +35 -0
  2. package/dist/Button/index.js +37 -15
  3. package/dist/Button/index.js.map +1 -1
  4. package/dist/Chip/ChipIcon.d.ts +13 -8
  5. package/dist/Chip/ChipIcon.js +0 -2
  6. package/dist/Chip/ChipIcon.js.map +1 -1
  7. package/dist/Chip/constants.d.ts +4 -0
  8. package/dist/Chip/constants.js +3 -2
  9. package/dist/Chip/constants.js.map +1 -0
  10. package/dist/Chip/index.d.ts +4 -3
  11. package/dist/Chip/index.js +2 -4
  12. package/dist/Chip/index.js.map +1 -1
  13. package/dist/ChipCarousel/index.js +0 -2
  14. package/dist/ChipCarousel/index.js.map +1 -1
  15. package/dist/Hyperlink/index.d.ts +24 -0
  16. package/dist/Hyperlink/index.js +20 -32
  17. package/dist/Hyperlink/index.js.map +1 -1
  18. package/dist/Icon/index.d.ts +4 -2
  19. package/dist/Icon/index.js +1 -1
  20. package/dist/Icon/index.js.map +1 -1
  21. package/dist/IconButton/index.d.ts +342 -0
  22. package/dist/IconButton/index.js +18 -26
  23. package/dist/IconButton/index.js.map +1 -1
  24. package/dist/Modal/ModalPopup.js +7 -1
  25. package/dist/Modal/ModalPopup.js.map +1 -1
  26. package/dist/Modal/_ModalDialog.scss +4 -0
  27. package/dist/Overlay/index.d.ts +128 -0
  28. package/dist/Overlay/index.js +8 -2
  29. package/dist/Overlay/index.js.map +1 -1
  30. package/dist/Tooltip/index.d.ts +7 -0
  31. package/dist/Tooltip/index.js.map +1 -1
  32. package/dist/core.css +3 -0
  33. package/dist/core.css.map +1 -1
  34. package/dist/core.min.css +1 -1
  35. package/dist/index.d.ts +5 -5
  36. package/dist/index.js +7 -7
  37. package/dist/setupTest.d.ts +2 -0
  38. package/dist/setupTest.js.map +1 -0
  39. package/dist/utils/types/bootstrap.d.ts +39 -0
  40. package/dist/utils/types/bootstrap.js +2 -0
  41. package/dist/utils/types/bootstrap.js.map +1 -0
  42. package/package.json +5 -5
  43. package/src/Button/{Button.test.jsx → Button.test.tsx} +14 -2
  44. package/src/Button/__snapshots__/{Button.test.jsx.snap → Button.test.tsx.snap} +19 -2
  45. package/src/Button/{index.jsx → index.tsx} +58 -16
  46. package/src/Chip/{Chip.test.jsx → Chip.test.tsx} +5 -7
  47. package/src/Chip/ChipIcon.tsx +8 -8
  48. package/src/Chip/{constants.js → constants.ts} +1 -1
  49. package/src/Chip/index.tsx +6 -8
  50. package/src/ChipCarousel/index.tsx +0 -2
  51. package/src/Hyperlink/{Hyperlink.test.jsx → Hyperlink.test.tsx} +21 -10
  52. package/src/Hyperlink/{index.jsx → index.tsx} +41 -37
  53. package/src/Icon/index.d.ts +4 -2
  54. package/src/Icon/index.jsx +1 -1
  55. package/src/IconButton/{IconButton.test.jsx → IconButton.test.tsx} +24 -3
  56. package/src/IconButton/__snapshots__/IconButton.test.tsx.snap +90 -0
  57. package/src/IconButton/{index.jsx → index.tsx} +66 -26
  58. package/src/Modal/ModalPopup.jsx +9 -1
  59. package/src/Modal/_ModalDialog.scss +4 -0
  60. package/src/Modal/tests/ModalPopupNoMock.test.jsx +29 -0
  61. package/src/Overlay/{index.jsx → index.tsx} +13 -8
  62. package/src/Tooltip/{index.jsx → index.tsx} +9 -3
  63. package/src/index.d.ts +5 -5
  64. package/src/index.js +7 -7
  65. package/src/{setupTest.js → setupTest.ts} +1 -0
  66. package/src/utils/types/bootstrap.test.tsx +86 -0
  67. package/src/utils/types/bootstrap.ts +43 -0
  68. package/src/IconButton/__snapshots__/IconButton.test.jsx.snap +0 -20
  69. /package/src/Button/{ButtonGroup.test.jsx → ButtonGroup.test.tsx} +0 -0
  70. /package/src/Button/{ButtonToolbar.test.jsx → ButtonToolbar.test.tsx} +0 -0
  71. /package/src/Button/__snapshots__/{ButtonGroup.test.jsx.snap → ButtonGroup.test.tsx.snap} +0 -0
  72. /package/src/Button/__snapshots__/{ButtonToolbar.test.jsx.snap → ButtonToolbar.test.tsx.snap} +0 -0
  73. /package/src/Chip/__snapshots__/{Chip.test.jsx.snap → Chip.test.tsx.snap} +0 -0
  74. /package/src/Tooltip/{Tooltip.test.jsx → Tooltip.test.tsx} +0 -0
package/src/index.js CHANGED
@@ -1,13 +1,18 @@
1
- // To keep this file in sync with the .d.ts file, it's in the same order
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';
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
1
2
  import 'regenerator-runtime/runtime';
2
3
 
3
4
  import '@testing-library/jest-dom';
@@ -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
- `;