Skip to content

Commit 05fd7ef

Browse files
Merge branch 'release-23.x' into removing-react-imports-5
2 parents 794abd1 + 8afa199 commit 05fd7ef

File tree

25 files changed

+144
-296
lines changed

25 files changed

+144
-296
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
jobs:
99
tests:
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node: [20, 24]
14+
continue-on-error: ${{ matrix.node == 24 }}
1115
steps:
1216
- name: Checkout
1317
uses: actions/checkout@v4
@@ -16,7 +20,7 @@ jobs:
1620
- name: Setup Nodejs
1721
uses: actions/setup-node@v4
1822
with:
19-
node-version-file: '.nvmrc'
23+
node-version: ${{ matrix.node }}
2024
- name: Install dependencies
2125
run: npm ci
2226
- name: Check Types

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ActionRow/index.jsx renamed to src/ActionRow/index.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import classNames from 'classnames';
43

4+
interface ActionRowProps extends React.HTMLAttributes<HTMLElement> {
5+
/** Specifies the base element */
6+
as?: React.ElementType;
7+
/** Specifies the contents of the row */
8+
children: React.ReactNode;
9+
/** Specifies class name to append to the base element */
10+
className?: string;
11+
/** Specifies whether row should be displayed horizontally */
12+
isStacked?: boolean;
13+
}
14+
515
function ActionRow({
6-
as,
7-
isStacked,
16+
as = 'div',
17+
isStacked = false,
818
children,
919
...props
10-
}) {
20+
}: ActionRowProps) {
1121
return React.createElement(
1222
as,
1323
{
@@ -21,24 +31,6 @@ function ActionRow({
2131
);
2232
}
2333

24-
ActionRow.propTypes = {
25-
/** Specifies the base element */
26-
as: PropTypes.elementType,
27-
/** Specifies class name to append to the base element */
28-
className: PropTypes.string,
29-
/** Specifies the contents of the row */
30-
children: PropTypes.node,
31-
/** Specifies whether row should be displayed horizontally */
32-
isStacked: PropTypes.bool,
33-
};
34-
35-
ActionRow.defaultProps = {
36-
as: 'div',
37-
className: undefined,
38-
children: null,
39-
isStacked: false,
40-
};
41-
4234
function ActionRowSpacer() {
4335
return <span className="pgn__action-row-spacer" />;
4436
}
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
1+
import React, { ForwardedRef } from 'react';
32
import classNames from 'classnames';
43

4+
interface AnnotationProps extends React.HTMLAttributes<HTMLSpanElement> {
5+
/** Specifies contents of the component. */
6+
children: React.ReactNode;
7+
/** Specifies class name to append to the base element. */
8+
className?: string;
9+
/** Specifies variant to use. */
10+
variant?: 'error' | 'success' | 'warning' | 'light' | 'dark';
11+
/** Specifies arrow position. */
12+
arrowPlacement?: 'top' | 'right' | 'bottom' | 'left';
13+
}
14+
515
const Annotation = React.forwardRef(({
616
className,
7-
variant,
17+
variant = 'success',
818
children,
9-
arrowPlacement,
19+
arrowPlacement = 'bottom',
1020
...props
11-
}, ref) => (
21+
} : AnnotationProps, ref : ForwardedRef<HTMLSpanElement>) => (
1222
<span
1323
className={classNames(
1424
className,
@@ -22,21 +32,4 @@ const Annotation = React.forwardRef(({
2232
</span>
2333
));
2434

25-
Annotation.defaultProps = {
26-
className: undefined,
27-
variant: 'success',
28-
arrowPlacement: 'bottom',
29-
};
30-
31-
Annotation.propTypes = {
32-
/** Specifies contents of the component. */
33-
children: PropTypes.node.isRequired,
34-
/** Specifies class name to append to the base element. */
35-
className: PropTypes.string,
36-
/** Specifies variant to use. */
37-
variant: PropTypes.oneOf(['error', 'success', 'warning', 'light', 'dark']),
38-
/** Specifies arrow position. */
39-
arrowPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
40-
};
41-
4235
export default Annotation;
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import classNames from 'classnames';
3+
// @ts-ignore
44
import defaultAvatar from './default-avatar.svg';
55

6+
export interface AvatarProps extends React.ImgHTMLAttributes<HTMLImageElement> {
7+
/** Alt text. Usually the user's name */
8+
alt?: string;
9+
/** Size of the avatar */
10+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'huge';
11+
/** Image src of the avatar image */
12+
src?: string;
13+
}
14+
615
function Avatar({
7-
alt,
8-
size,
16+
alt = '',
17+
size = 'md',
918
src,
1019
...attrs
11-
}) {
20+
}: AvatarProps) {
1221
return (
1322
<img
1423
{...attrs}
@@ -23,19 +32,4 @@ function Avatar({
2332
);
2433
}
2534

26-
Avatar.propTypes = {
27-
/** Alt text. Usually the user's name */
28-
alt: PropTypes.string,
29-
/** Size of the avatar */
30-
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'huge']),
31-
/** Image src of the avatar image */
32-
src: PropTypes.string,
33-
};
34-
35-
Avatar.defaultProps = {
36-
alt: '',
37-
size: 'md',
38-
src: undefined,
39-
};
40-
4135
export default Avatar;
Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
1+
import React, { ForwardedRef } from 'react';
32
import classNames from 'classnames';
43
import Button from '../Button';
5-
import Avatar from '../Avatar';
4+
import Avatar, { AvatarProps } from '../Avatar';
65

76
const buttonSizesToAvatarSize = {
87
sm: 'xs',
98
md: 'sm',
109
lg: 'md',
1110
};
1211

12+
interface AvatarButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
13+
/** The button text */
14+
children?: string;
15+
/** A class name to append to the button */
16+
className?: string;
17+
/** Show the label or only the avatar */
18+
showLabel?: boolean;
19+
/** The button size */
20+
size?: 'sm' | 'md' | 'lg';
21+
/** Image src of the avatar image */
22+
src?: string;
23+
/** The button style variant to use */
24+
variant?: string;
25+
}
26+
1327
const AvatarButton = React.forwardRef(({
1428
children,
1529
className,
16-
showLabel,
17-
size,
30+
showLabel = true,
31+
size = 'md',
1832
src,
33+
variant = 'tertiary',
1934
...attrs
20-
}, ref) => {
35+
}: AvatarButtonProps, ref: ForwardedRef<HTMLButtonElement>) => {
2136
const avatarSize = buttonSizesToAvatarSize[size] || 'sm';
2237
return (
2338
<Button
@@ -31,35 +46,12 @@ const AvatarButton = React.forwardRef(({
3146
)}
3247
size={size}
3348
ref={ref}
49+
variant={variant}
3450
>
35-
<Avatar src={src} alt={showLabel ? '' : children} size={avatarSize} />
51+
<Avatar src={src} alt={showLabel ? '' : children} size={avatarSize as AvatarProps['size']} />
3652
{showLabel && children}
3753
</Button>
3854
);
3955
});
4056

41-
AvatarButton.propTypes = {
42-
/** The button text */
43-
children: PropTypes.string,
44-
/** A class name to append to the button */
45-
className: PropTypes.string,
46-
/** Show the label or only the avatar */
47-
showLabel: PropTypes.bool,
48-
/** The button size */
49-
size: PropTypes.oneOf(['sm', 'md', 'lg']),
50-
/** Image src of the avatar image */
51-
src: PropTypes.string,
52-
/** The button style variant to use */
53-
variant: PropTypes.string,
54-
};
55-
56-
AvatarButton.defaultProps = {
57-
children: undefined,
58-
className: undefined,
59-
showLabel: true,
60-
size: 'md',
61-
src: undefined,
62-
variant: 'tertiary',
63-
};
64-
6557
export default AvatarButton;
File renamed without changes.

src/Chip/index.tsx

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
11
import React, { ForwardedRef, KeyboardEventHandler, MouseEventHandler } from 'react';
2-
import PropTypes, { type Requireable } from 'prop-types';
32
import classNames from 'classnames';
4-
// @ts-ignore
5-
import { requiredWhen } from '../utils/propTypes';
6-
import { STYLE_VARIANTS } from './constants';
73
import ChipIcon from './ChipIcon';
4+
import { STYLE_VARIANTS } from './constants';
85

96
export const CHIP_PGN_CLASS = 'pgn__chip';
107

118
export interface IChip {
9+
/** Specifies the content of the `Chip`. */
1210
children: React.ReactNode,
11+
/** Click handler for the whole `Chip`, has effect only when Chip does not have any interactive icons. */
1312
onClick?: KeyboardEventHandler & MouseEventHandler,
13+
/** Specifies an additional `className` to add to the base element. */
1414
className?: string,
15+
/** The `Chip` style [variant](https://github.com/openedx/paragon/blob/release-23.x/src/Chip/constants.ts) to use. */
1516
variant?: typeof STYLE_VARIANTS[keyof typeof STYLE_VARIANTS],
17+
/**
18+
* An icon component to render before the content.
19+
* Example import of a Paragon icon component:
20+
*
21+
* `import { Check } from '@openedx/paragon/icons';`
22+
*/
1623
iconBefore?: React.ComponentType,
24+
/** Specifies icon alt text. */
1725
iconBeforeAlt?: string,
26+
/**
27+
* An icon component to render before after the content.
28+
* Example import of a Paragon icon component:
29+
*
30+
* `import { Check } from '@openedx/paragon/icons';`
31+
*/
1832
iconAfter?: React.ComponentType,
33+
/** Specifies icon alt text. */
1934
iconAfterAlt?: string,
35+
/** A click handler for the `Chip` icon before. */
2036
onIconBeforeClick?: KeyboardEventHandler & MouseEventHandler,
37+
/** A click handler for the `Chip` icon after. */
2138
onIconAfterClick?: KeyboardEventHandler & MouseEventHandler,
39+
/** Disables the `Chip`. */
2240
disabled?: boolean,
41+
/** Indicates if `Chip` has been selected. */
2342
isSelected?: boolean,
2443
}
2544

2645
const Chip = React.forwardRef(({
2746
children,
2847
className,
29-
variant,
48+
variant = 'light',
3049
iconBefore,
3150
iconBeforeAlt,
3251
iconAfter,
3352
iconAfterAlt,
3453
onIconBeforeClick,
3554
onIconAfterClick,
36-
disabled,
37-
isSelected,
55+
disabled = false,
56+
isSelected = false,
3857
onClick,
3958
...props
4059
}: IChip, ref: ForwardedRef<HTMLDivElement>) => {
@@ -92,56 +111,4 @@ const Chip = React.forwardRef(({
92111
);
93112
});
94113

95-
Chip.propTypes = {
96-
/** Specifies the content of the `Chip`. */
97-
// @ts-ignore
98-
children: PropTypes.node.isRequired,
99-
/** Specifies an additional `className` to add to the base element. */
100-
className: PropTypes.string,
101-
/** The `Chip` style variant to use. */
102-
variant: PropTypes.oneOf(['light', 'dark']),
103-
/** Disables the `Chip`. */
104-
disabled: PropTypes.bool,
105-
/** Click handler for the whole Chip, has effect only when Chip does not have any interactive icons. */
106-
onClick: PropTypes.func,
107-
/**
108-
* An icon component to render before the content.
109-
* Example import of a Paragon icon component:
110-
*
111-
* `import { Check } from '@openedx/paragon/icons';`
112-
*/
113-
iconBefore: PropTypes.elementType as Requireable<React.ComponentType>,
114-
/** Specifies icon alt text. */
115-
iconBeforeAlt: requiredWhen(PropTypes.string, ['iconBefore', 'onIconBeforeClick']),
116-
/** A click handler for the `Chip` icon before. */
117-
onIconBeforeClick: PropTypes.func,
118-
/**
119-
* An icon component to render before after the content.
120-
* Example import of a Paragon icon component:
121-
*
122-
* `import { Check } from '@openedx/paragon/icons';`
123-
*/
124-
iconAfter: PropTypes.elementType as Requireable<React.ComponentType>,
125-
/** Specifies icon alt text. */
126-
iconAfterAlt: requiredWhen(PropTypes.string, ['iconAfter', 'onIconAfterClick']),
127-
/** A click handler for the `Chip` icon after. */
128-
onIconAfterClick: PropTypes.func,
129-
/** Indicates if `Chip` has been selected. */
130-
isSelected: PropTypes.bool,
131-
};
132-
133-
Chip.defaultProps = {
134-
className: undefined,
135-
variant: STYLE_VARIANTS.LIGHT,
136-
disabled: false,
137-
onClick: undefined,
138-
iconBefore: undefined,
139-
iconAfter: undefined,
140-
onIconBeforeClick: undefined,
141-
onIconAfterClick: undefined,
142-
isSelected: false,
143-
iconAfterAlt: undefined,
144-
iconBeforeAlt: undefined,
145-
};
146-
147114
export default Chip;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)