@openedx/paragon 22.18.1 → 22.19.0

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.
@@ -0,0 +1,36 @@
1
+ import React, { ReactNode, ElementType, FC, ForwardRefExoticComponent, RefAttributes } from 'react';
2
+ import { AlertProps as BaseAlertProps } from 'react-bootstrap';
3
+ import { IconProps } from '../Icon';
4
+ export declare const ALERT_CLOSE_LABEL_TEXT = "Dismiss";
5
+ export type AlertVariant = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light';
6
+ export type BaseProps = Omit<BaseAlertProps, 'children' | 'variant' | 'closeLabel'>;
7
+ export interface AlertProps extends BaseProps {
8
+ className?: string;
9
+ bsPrefix?: string;
10
+ variant?: AlertVariant;
11
+ children?: ReactNode;
12
+ icon?: React.ComponentType<IconProps>;
13
+ show?: boolean;
14
+ dismissible?: boolean;
15
+ onClose?: () => void;
16
+ actions?: React.ReactElement[];
17
+ stacked?: boolean;
18
+ closeLabel?: string | ReactNode;
19
+ }
20
+ export interface AlertHeadingProps {
21
+ as?: ElementType;
22
+ bsPrefix?: string;
23
+ children?: ReactNode;
24
+ }
25
+ export interface AlertLinkProps {
26
+ as?: ElementType;
27
+ bsPrefix?: string;
28
+ children?: ReactNode;
29
+ href?: string;
30
+ }
31
+ export interface AlertComponent extends ForwardRefExoticComponent<AlertProps & RefAttributes<HTMLDivElement>> {
32
+ Heading: FC<AlertHeadingProps>;
33
+ Link: FC<AlertLinkProps>;
34
+ }
35
+ declare const Alert: AlertComponent;
36
+ export default Alert;
@@ -1,16 +1,18 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
1
+ /* eslint-disable react/require-default-props */
2
+ import React, { useCallback, useEffect, useState, forwardRef, cloneElement } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
  import classNames from 'classnames';
4
- import BaseAlert from 'react-bootstrap/Alert';
5
+ import { Alert as BaseAlert } from 'react-bootstrap';
5
6
  import divWithClassName from 'react-bootstrap/divWithClassName';
6
7
  import { FormattedMessage } from 'react-intl';
7
8
  import { useMediaQuery } from 'react-responsive';
8
9
  import Icon from '../Icon';
9
10
  import breakpoints from '../utils/breakpoints';
10
11
  import Button from '../Button';
12
+ // @ts-ignore for now - this needs to be converted to TypeScript
11
13
  import ActionRow from '../ActionRow';
12
14
  export const ALERT_CLOSE_LABEL_TEXT = 'Dismiss';
13
- const Alert = /*#__PURE__*/React.forwardRef((_ref, ref) => {
15
+ const Alert = /*#__PURE__*/forwardRef((_ref, ref) => {
14
16
  let {
15
17
  children,
16
18
  icon,
@@ -38,7 +40,7 @@ const Alert = /*#__PURE__*/React.forwardRef((_ref, ref) => {
38
40
  size: actionButtonSize,
39
41
  key: Action.props.children
40
42
  };
41
- return /*#__PURE__*/React.cloneElement(Action, addtlActionProps);
43
+ return /*#__PURE__*/cloneElement(Action, addtlActionProps);
42
44
  }, []);
43
45
  return /*#__PURE__*/React.createElement(BaseAlert, {
44
46
  ...props,
@@ -54,7 +56,7 @@ const Alert = /*#__PURE__*/React.forwardRef((_ref, ref) => {
54
56
  })
55
57
  }, /*#__PURE__*/React.createElement("div", {
56
58
  className: "alert-message-content"
57
- }, children), (dismissible || actions?.length > 0) && /*#__PURE__*/React.createElement(ActionRow, {
59
+ }, children), (dismissible || actions && actions.length > 0) && /*#__PURE__*/React.createElement(ActionRow, {
58
60
  className: "pgn__alert-actions"
59
61
  }, /*#__PURE__*/React.createElement(ActionRow.Spacer, null), dismissible && /*#__PURE__*/React.createElement(Button, {
60
62
  size: actionButtonSize,
@@ -82,14 +84,18 @@ function AlertLink(props) {
82
84
  ...props
83
85
  });
84
86
  }
85
- const commonPropTypes = {
87
+ AlertLink.propTypes = {
88
+ /** Specifies the base element */
89
+ as: PropTypes.elementType,
90
+ /** Overrides underlying component base CSS class name */
91
+ bsPrefix: PropTypes.string
92
+ };
93
+ AlertHeading.propTypes = {
86
94
  /** Specifies the base element */
87
95
  as: PropTypes.elementType,
88
96
  /** Overrides underlying component base CSS class name */
89
97
  bsPrefix: PropTypes.string
90
98
  };
91
- AlertLink.propTypes = commonPropTypes;
92
- AlertHeading.propTypes = commonPropTypes;
93
99
  AlertLink.defaultProps = {
94
100
  as: 'a',
95
101
  bsPrefix: 'alert-link'
@@ -147,7 +153,10 @@ Alert.defaultProps = {
147
153
  onClose: () => {},
148
154
  closeLabel: undefined,
149
155
  show: true,
150
- stacked: false
156
+ stacked: false,
157
+ className: undefined,
158
+ bsPrefix: undefined,
159
+ variant: undefined
151
160
  };
152
161
  Alert.Heading = AlertHeading;
153
162
  Alert.Link = AlertLink;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","useCallback","useEffect","useState","PropTypes","classNames","BaseAlert","divWithClassName","FormattedMessage","useMediaQuery","Icon","breakpoints","Button","ActionRow","ALERT_CLOSE_LABEL_TEXT","Alert","forwardRef","_ref","ref","children","icon","actions","dismissible","onClose","closeLabel","stacked","props","isStacked","setIsStacked","isExtraSmall","maxWidth","extraSmall","actionButtonSize","cloneActionElement","Action","addtlActionProps","size","key","cloneElement","createElement","className","src","length","Spacer","variant","onClick","id","defaultMessage","description","map","DivStyledAsH4","displayName","AlertHeading","Heading","AlertLink","Link","commonPropTypes","as","elementType","bsPrefix","string","propTypes","defaultProps","oneOf","transition","oneOfType","bool","shape","in","appear","node","onEnter","func","onEntered","onEntering","onExit","onExited","onExiting","show","arrayOf","element","undefined"],"sources":["../../src/Alert/index.jsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport BaseAlert from 'react-bootstrap/Alert';\nimport divWithClassName from 'react-bootstrap/divWithClassName';\nimport { FormattedMessage } from 'react-intl';\nimport { useMediaQuery } from 'react-responsive';\nimport Icon from '../Icon';\nimport breakpoints from '../utils/breakpoints';\nimport Button from '../Button';\nimport ActionRow from '../ActionRow';\n\nexport const ALERT_CLOSE_LABEL_TEXT = 'Dismiss';\n\nconst Alert = React.forwardRef(({\n children,\n icon,\n actions,\n dismissible,\n onClose,\n closeLabel,\n stacked,\n ...props\n}, ref) => {\n const [isStacked, setIsStacked] = useState(stacked);\n const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });\n const actionButtonSize = 'sm';\n\n useEffect(() => {\n if (isExtraSmall) {\n setIsStacked(true);\n } else {\n setIsStacked(stacked);\n }\n }, [isExtraSmall, stacked]);\n\n const cloneActionElement = useCallback(\n (Action) => {\n const addtlActionProps = { size: actionButtonSize, key: Action.props.children };\n return React.cloneElement(Action, addtlActionProps);\n },\n [],\n );\n\n return (\n <BaseAlert\n {...props}\n className={classNames('alert-content', props.className)}\n ref={ref}\n >\n {icon && <Icon src={icon} className=\"alert-icon\" />}\n <div\n className={classNames({\n 'pgn__alert-message-wrapper': !isStacked,\n 'pgn__alert-message-wrapper-stacked': isStacked,\n })}\n >\n <div className=\"alert-message-content\">\n {children}\n </div>\n {(dismissible || actions?.length > 0) && (\n <ActionRow className=\"pgn__alert-actions\">\n <ActionRow.Spacer />\n {dismissible && (\n <Button\n size={actionButtonSize}\n variant=\"tertiary\"\n onClick={onClose}\n >\n {closeLabel || (\n <FormattedMessage\n id=\"pgn.Alert.closeLabel\"\n defaultMessage=\"Dismiss\"\n description=\"Label of a close button on Alert component\"\n />\n )}\n </Button>\n )}\n {actions && actions.map(cloneActionElement)}\n </ActionRow>\n )}\n </div>\n </BaseAlert>\n );\n});\n\n// This is needed to display a default prop for Alert.Heading element\n// Copied from react-bootstrap since BaseAlert.Heading component doesn't have defaultProps,\n// so there seems to be no other way of providing correct default prop for base element\nconst DivStyledAsH4 = divWithClassName('h4');\nDivStyledAsH4.displayName = 'DivStyledAsH4';\n\nfunction AlertHeading(props) {\n return <BaseAlert.Heading {...props} />;\n}\nfunction AlertLink(props) {\n return <BaseAlert.Link {...props} />;\n}\n\nconst commonPropTypes = {\n /** Specifies the base element */\n as: PropTypes.elementType,\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n};\n\nAlertLink.propTypes = commonPropTypes;\nAlertHeading.propTypes = commonPropTypes;\n\nAlertLink.defaultProps = {\n as: 'a',\n bsPrefix: 'alert-link',\n};\n\nAlertHeading.defaultProps = {\n as: DivStyledAsH4,\n bsPrefix: 'alert-heading',\n};\n\nAlert.propTypes = {\n ...BaseAlert.propTypes,\n /** Specifies class name to append to the base element */\n className: PropTypes.string,\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n /** Specifies variant to use. */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light']),\n /**\n * Animate the entering and exiting of the Alert. `true` will use the `<Fade>` transition,\n * more detailed customization is also provided.\n */\n transition: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({\n in: PropTypes.bool,\n appear: PropTypes.bool,\n children: PropTypes.node,\n onEnter: PropTypes.func,\n onEntered: PropTypes.func,\n onEntering: PropTypes.func,\n onExit: PropTypes.func,\n onExited: PropTypes.func,\n onExiting: PropTypes.func,\n })]),\n /** Docstring for the children prop */\n children: PropTypes.node,\n /** Docstring for the icon prop... Icon that will be shown in the alert */\n icon: PropTypes.func,\n /** Whether the alert is shown. */\n show: PropTypes.bool,\n /** Whether the alert is dismissible. Defaults to true. */\n dismissible: PropTypes.bool,\n /** Optional callback function for when the alert it dismissed. */\n onClose: PropTypes.func,\n /** Optional list of action elements. May include, at most, 2 actions, or 1 if dismissible is true. */\n actions: PropTypes.arrayOf(PropTypes.element),\n /** Position of the dismiss and call-to-action buttons. Defaults to ``false``. */\n stacked: PropTypes.bool,\n /** Sets the text for alert close button, defaults to 'Dismiss'. */\n closeLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n};\n\nAlert.defaultProps = {\n ...BaseAlert.defaultProps,\n children: undefined,\n icon: undefined,\n actions: undefined,\n dismissible: false,\n onClose: () => {},\n closeLabel: undefined,\n show: true,\n stacked: false,\n};\n\nAlert.Heading = AlertHeading;\nAlert.Link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,CAACsC,OAAO,GAAGD,YAAY;AAC5BrC,KAAK,CAACwC,IAAI,GAAGD,SAAS;AAEtB,eAAevC,KAAK","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","useCallback","useEffect","useState","forwardRef","cloneElement","PropTypes","classNames","Alert","BaseAlert","divWithClassName","FormattedMessage","useMediaQuery","Icon","breakpoints","Button","ActionRow","ALERT_CLOSE_LABEL_TEXT","_ref","ref","children","icon","actions","dismissible","onClose","closeLabel","stacked","props","isStacked","setIsStacked","isExtraSmall","maxWidth","extraSmall","actionButtonSize","cloneActionElement","Action","addtlActionProps","size","key","createElement","className","src","length","Spacer","variant","onClick","id","defaultMessage","description","map","DivStyledAsH4","displayName","AlertHeading","Heading","AlertLink","Link","propTypes","as","elementType","bsPrefix","string","defaultProps","oneOf","transition","oneOfType","bool","shape","in","appear","node","onEnter","func","onEntered","onEntering","onExit","onExited","onExiting","show","arrayOf","element","undefined"],"sources":["../../src/Alert/index.tsx"],"sourcesContent":["/* eslint-disable react/require-default-props */\nimport React, {\n useCallback,\n useEffect,\n useState,\n ReactNode,\n ElementType,\n forwardRef,\n FC,\n ForwardRefExoticComponent,\n RefAttributes,\n cloneElement,\n} from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport {\n Alert as BaseAlert,\n AlertProps as BaseAlertProps,\n} from 'react-bootstrap';\nimport divWithClassName from 'react-bootstrap/divWithClassName';\nimport { FormattedMessage } from 'react-intl';\nimport { useMediaQuery } from 'react-responsive';\nimport Icon, { IconProps } from '../Icon';\nimport breakpoints from '../utils/breakpoints';\nimport Button from '../Button';\n// @ts-ignore for now - this needs to be converted to TypeScript\nimport ActionRow from '../ActionRow';\n\nexport const ALERT_CLOSE_LABEL_TEXT = 'Dismiss';\n\nexport type AlertVariant = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light';\n\nexport type BaseProps = Omit<BaseAlertProps, 'children' | 'variant' | 'closeLabel'>;\n\nexport interface AlertProps extends BaseProps {\n className?: string;\n bsPrefix?: string;\n variant?: AlertVariant;\n children?: ReactNode;\n icon?: React.ComponentType<IconProps>;\n show?: boolean;\n dismissible?: boolean;\n onClose?: () => void;\n actions?: React.ReactElement[];\n stacked?: boolean;\n closeLabel?: string | ReactNode;\n}\n\nexport interface AlertHeadingProps {\n as?: ElementType;\n bsPrefix?: string;\n children?: ReactNode;\n}\n\nexport interface AlertLinkProps {\n as?: ElementType;\n bsPrefix?: string;\n children?: ReactNode;\n href?: string;\n}\n\nexport interface AlertComponent extends ForwardRefExoticComponent<AlertProps & RefAttributes<HTMLDivElement>> {\n Heading: FC<AlertHeadingProps>;\n Link: FC<AlertLinkProps>;\n}\n\nconst Alert = forwardRef<HTMLDivElement, AlertProps>(({\n children,\n icon,\n actions,\n dismissible,\n onClose,\n closeLabel,\n stacked,\n ...props\n}, ref) => {\n const [isStacked, setIsStacked] = useState(stacked);\n const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth });\n const actionButtonSize = 'sm';\n\n useEffect(() => {\n if (isExtraSmall) {\n setIsStacked(true);\n } else {\n setIsStacked(stacked);\n }\n }, [isExtraSmall, stacked]);\n\n const cloneActionElement = useCallback(\n (Action: React.ReactElement) => {\n const addtlActionProps = { size: actionButtonSize, key: Action.props.children };\n return cloneElement(Action, addtlActionProps);\n },\n [],\n );\n\n return (\n <BaseAlert\n {...props}\n className={classNames('alert-content', props.className)}\n ref={ref}\n >\n {icon && <Icon src={icon} className=\"alert-icon\" />}\n <div\n className={classNames({\n 'pgn__alert-message-wrapper': !isStacked,\n 'pgn__alert-message-wrapper-stacked': isStacked,\n })}\n >\n <div className=\"alert-message-content\">\n {children}\n </div>\n {(dismissible || (actions && actions.length > 0)) && (\n <ActionRow className=\"pgn__alert-actions\">\n <ActionRow.Spacer />\n {dismissible && (\n <Button\n size={actionButtonSize}\n variant=\"tertiary\"\n onClick={onClose}\n >\n {closeLabel || (\n <FormattedMessage\n id=\"pgn.Alert.closeLabel\"\n defaultMessage=\"Dismiss\"\n description=\"Label of a close button on Alert component\"\n />\n )}\n </Button>\n )}\n {actions && actions.map(cloneActionElement)}\n </ActionRow>\n )}\n </div>\n </BaseAlert>\n );\n}) as AlertComponent;\n\n// This is needed to display a default prop for Alert.Heading element\n// Copied from react-bootstrap since BaseAlert.Heading component doesn't have defaultProps,\n// so there seems to be no other way of providing correct default prop for base element\nconst DivStyledAsH4 = divWithClassName('h4');\nDivStyledAsH4.displayName = 'DivStyledAsH4';\n\nfunction AlertHeading(props: AlertHeadingProps): JSX.Element {\n return <BaseAlert.Heading {...props} />;\n}\n\nfunction AlertLink(props: AlertLinkProps): JSX.Element {\n return <BaseAlert.Link {...props} />;\n}\n\nAlertLink.propTypes = {\n /** Specifies the base element */\n as: PropTypes.elementType as PropTypes.Validator<ElementType>,\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n};\n\nAlertHeading.propTypes = {\n /** Specifies the base element */\n as: PropTypes.elementType as PropTypes.Validator<ElementType>,\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n};\n\nAlertLink.defaultProps = {\n as: 'a' as ElementType,\n bsPrefix: 'alert-link',\n};\n\nAlertHeading.defaultProps = {\n as: DivStyledAsH4,\n bsPrefix: 'alert-heading',\n};\n\nAlert.propTypes = {\n ...BaseAlert.propTypes,\n /** Specifies class name to append to the base element */\n className: PropTypes.string,\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n /** Specifies variant to use. */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'] as AlertVariant[]),\n /**\n * Animate the entering and exiting of the Alert. `true` will use the `<Fade>` transition,\n * more detailed customization is also provided.\n */\n transition: PropTypes.oneOfType([\n PropTypes.bool,\n PropTypes.shape({\n in: PropTypes.bool,\n appear: PropTypes.bool,\n children: PropTypes.node,\n onEnter: PropTypes.func,\n onEntered: PropTypes.func,\n onEntering: PropTypes.func,\n onExit: PropTypes.func,\n onExited: PropTypes.func,\n onExiting: PropTypes.func,\n }),\n ]) as PropTypes.Validator<BaseAlertProps['transition']>,\n /** Docstring for the children prop */\n children: PropTypes.node as PropTypes.Validator<ReactNode>,\n /** Docstring for the icon prop... Icon that will be shown in the alert */\n icon: PropTypes.func,\n /** Whether the alert is shown. */\n show: PropTypes.bool,\n /** Whether the alert is dismissible. Defaults to true. */\n dismissible: PropTypes.bool,\n /** Optional callback function for when the alert it dismissed. */\n onClose: PropTypes.func,\n /** Optional list of action elements. May include, at most, 2 actions, or 1 if dismissible is true. */\n actions: PropTypes.arrayOf(PropTypes.element) as PropTypes.Validator<React.ReactElement[]>,\n /** Position of the dismiss and call-to-action buttons. Defaults to ``false``. */\n stacked: PropTypes.bool,\n /** Sets the text for alert close button, defaults to 'Dismiss'. */\n closeLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n};\n\nAlert.defaultProps = {\n ...BaseAlert.defaultProps,\n children: undefined,\n icon: undefined,\n actions: undefined,\n dismissible: false,\n onClose: () => {},\n closeLabel: undefined,\n show: true,\n stacked: false,\n className: undefined,\n bsPrefix: undefined,\n variant: undefined,\n};\n\nAlert.Heading = AlertHeading;\nAlert.Link = AlertLink;\n\nexport default Alert;\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,QAAQ,EAGRC,UAAU,EAIVC,YAAY,QACP,OAAO;AACd,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,SACEC,KAAK,IAAIC,SAAS,QAEb,iBAAiB;AACxB,OAAOC,gBAAgB,MAAM,kCAAkC;AAC/D,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,aAAa,QAAQ,kBAAkB;AAChD,OAAOC,IAAI,MAAqB,SAAS;AACzC,OAAOC,WAAW,MAAM,sBAAsB;AAC9C,OAAOC,MAAM,MAAM,WAAW;AAC9B;AACA,OAAOC,SAAS,MAAM,cAAc;A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CAACiE;EACvB,CAAC,CAAC,CACH,CAAsD;EACvD;EACAnD,QAAQ,EAAEd,SAAS,CAAC+D,IAAsC;EAC1D;EACAhD,IAAI,EAAEf,SAAS,CAACiE,IAAI;EACpB;EACAM,IAAI,EAAEvE,SAAS,CAAC2D,IAAI;EACpB;EACA1C,WAAW,EAAEjB,SAAS,CAAC2D,IAAI;EAC3B;EACAzC,OAAO,EAAElB,SAAS,CAACiE,IAAI;EACvB;EACAjD,OAAO,EAAEhB,SAAS,CAACwE,OAAO,CAACxE,SAAS,CAACyE,OAAO,CAA8C;EAC1F;EACArD,OAAO,EAAEpB,SAAS,CAAC2D,IAAI;EACvB;EACAxC,UAAU,EAAEnB,SAAS,CAAC0D,SAAS,CAAC,CAAC1D,SAAS,CAACsD,MAAM,EAAEtD,SAAS,CAACyE,OAAO,CAAC;AACvE,CAAC;AAEDvE,KAAK,CAACqD,YAAY,GAAG;EACnB,GAAGpD,SAAS,CAACoD,YAAY;EACzBzC,QAAQ,EAAE4D,SAAS;EACnB3D,IAAI,EAAE2D,SAAS;EACf1D,OAAO,EAAE0D,SAAS;EAClBzD,WAAW,EAAE,KAAK;EAClBC,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,UAAU,EAAEuD,SAAS;EACrBH,IAAI,EAAE,IAAI;EACVnD,OAAO,EAAE,KAAK;EACdc,SAAS,EAAEwC,SAAS;EACpBrB,QAAQ,EAAEqB,SAAS;EACnBpC,OAAO,EAAEoC;AACX,CAAC;AAEDxE,KAAK,CAAC6C,OAAO,GAAGD,YAAY;AAC5B5C,KAAK,CAAC+C,IAAI,GAAGD,SAAS;AAEtB,eAAe9C,KAAK","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -46,13 +46,14 @@ export { default as useToggle, type Toggler, type ToggleHandlers } from './hooks
46
46
  export { default as useArrowKeyNavigation, type ArrowKeyNavProps } from './hooks/useArrowKeyNavigationHook';
47
47
  export { default as useIndexOfLastVisibleChild } from './hooks/useIndexOfLastVisibleChildHook';
48
48
  export { default as useIsVisible } from './hooks/useIsVisibleHook';
49
+ export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
50
+ export { default as breakpoints } from './utils/breakpoints';
49
51
 
50
52
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
51
53
  // Things that don't have types
52
54
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
53
55
  export const asInput: any; // from './asInput';
54
56
  export const ActionRow: any; // from './ActionRow';
55
- export const Alert: any, ALERT_CLOSE_LABEL_TEXT: string; // from './Alert';
56
57
  export const Annotation: any; // from './Annotation';
57
58
  export const Avatar: any; // from './Avatar';
58
59
  export const AvatarButton: any; // from './AvatarButton';
@@ -190,7 +191,6 @@ export const Stack: any; // from './Stack';
190
191
  export const ToggleButton: any, ToggleButtonGroup: any; // from './ToggleButton';
191
192
  export const Sticky: any; // from './Sticky';
192
193
  export const SelectableBox: any; // from './SelectableBox';
193
- export const breakpoints: any; // from './utils/breakpoints';
194
194
  export const Variant: any; // from './utils/constants';
195
195
  export const
196
196
  OverflowScrollContext: any,
package/dist/index.js CHANGED
@@ -46,13 +46,14 @@ export { default as useToggle } from './hooks/useToggleHook';
46
46
  export { default as useArrowKeyNavigation } from './hooks/useArrowKeyNavigationHook';
47
47
  export { default as useIndexOfLastVisibleChild } from './hooks/useIndexOfLastVisibleChildHook';
48
48
  export { default as useIsVisible } from './hooks/useIsVisibleHook';
49
+ export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
50
+ export { default as breakpoints } from './utils/breakpoints';
49
51
 
50
52
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
51
53
  // Things that don't have types
52
54
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
53
55
  export { default as asInput } from './asInput';
54
56
  export { default as ActionRow } from './ActionRow';
55
- export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
56
57
  export { default as Annotation } from './Annotation';
57
58
  export { default as Avatar } from './Avatar';
58
59
  export { default as AvatarButton } from './AvatarButton';
@@ -190,7 +191,6 @@ export { default as Stack } from './Stack';
190
191
  export { default as ToggleButton, ToggleButtonGroup } from './ToggleButton';
191
192
  export { default as Sticky } from './Sticky';
192
193
  export { default as SelectableBox } from './SelectableBox';
193
- export { default as breakpoints } from './utils/breakpoints';
194
194
  export { default as Variant } from './utils/constants';
195
195
  export {
196
196
  OverflowScrollContext,
@@ -0,0 +1,26 @@
1
+ interface BreakpointRange {
2
+ minWidth?: number;
3
+ maxWidth?: number;
4
+ }
5
+
6
+ interface Breakpoints {
7
+ extraSmall: BreakpointRange;
8
+ small: BreakpointRange;
9
+ medium: BreakpointRange;
10
+ large: BreakpointRange;
11
+ extraLarge: BreakpointRange;
12
+ extraExtraLarge: BreakpointRange;
13
+ }
14
+
15
+ export const Size: {
16
+ readonly xs: 'extraSmall';
17
+ readonly sm: 'small';
18
+ readonly md: 'medium';
19
+ readonly lg: 'large';
20
+ readonly xl: 'extraLarge';
21
+ readonly xxl: 'extraExtraLarge';
22
+ };
23
+
24
+ declare const breakpoints: Breakpoints;
25
+
26
+ export default breakpoints;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "22.18.1",
3
+ "version": "22.19.0",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -7,10 +7,13 @@ import { Context as ResponsiveContext } from 'react-responsive';
7
7
  import { Info } from '../../icons';
8
8
  import breakpoints from '../utils/breakpoints';
9
9
  import Button from '../Button';
10
- import Alert from '.';
10
+ import Alert, { AlertProps } from '.';
11
11
 
12
- // eslint-disable-next-line react/prop-types
13
- function AlertWrapper({ children, ...props }) {
12
+ /** A compile time check. Whatever React elements this wraps won't run at runtime. */
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ function CompileCheck(_props: { children: React.ReactNode }) { return null; }
15
+
16
+ function AlertWrapper({ children, ...props }: AlertProps & { children: React.ReactNode }) {
14
17
  return (
15
18
  <IntlProvider locale="en" messages={{}}>
16
19
  <Alert {...props}>
@@ -20,6 +23,33 @@ function AlertWrapper({ children, ...props }) {
20
23
  );
21
24
  }
22
25
 
26
+ describe('Alert component type checking', () => {
27
+ it('has correct typing', () => {
28
+ <CompileCheck>
29
+ <Alert>Basic alert</Alert>
30
+ <Alert variant="primary">Primary alert</Alert>
31
+ <Alert icon={Info}>Alert with icon</Alert>
32
+ <Alert dismissible onClose={() => {}}>Dismissible alert</Alert>
33
+ <Alert actions={[<Button key="action">Action</Button>]}>Alert with action</Alert>
34
+ <Alert stacked>Stacked alert</Alert>
35
+ <Alert closeLabel="Close">Custom close label</Alert>
36
+ <Alert.Heading>Alert heading</Alert.Heading>
37
+ <Alert.Link href="#">Alert link</Alert.Link>
38
+
39
+ {/* @ts-expect-error Invalid variant */}
40
+ <Alert variant="invalid" />
41
+ {/* @ts-expect-error Invalid icon type */}
42
+ <Alert icon="string" />
43
+ {/* @ts-expect-error Invalid closeLabel type */}
44
+ <Alert closeLabel={{}} />
45
+ {/* @ts-expect-error Invalid Heading props */}
46
+ <Alert.Heading href="#" />
47
+ {/* @ts-expect-error Invalid Link props */}
48
+ <Alert.Link variant="primary" />
49
+ </CompileCheck>;
50
+ });
51
+ });
52
+
23
53
  describe('<Alert />', () => {
24
54
  it('renders without any props', () => {
25
55
  const tree = renderer.create((
@@ -1,18 +1,70 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
1
+ /* eslint-disable react/require-default-props */
2
+ import React, {
3
+ useCallback,
4
+ useEffect,
5
+ useState,
6
+ ReactNode,
7
+ ElementType,
8
+ forwardRef,
9
+ FC,
10
+ ForwardRefExoticComponent,
11
+ RefAttributes,
12
+ cloneElement,
13
+ } from 'react';
2
14
  import PropTypes from 'prop-types';
3
15
  import classNames from 'classnames';
4
- import BaseAlert from 'react-bootstrap/Alert';
16
+ import {
17
+ Alert as BaseAlert,
18
+ AlertProps as BaseAlertProps,
19
+ } from 'react-bootstrap';
5
20
  import divWithClassName from 'react-bootstrap/divWithClassName';
6
21
  import { FormattedMessage } from 'react-intl';
7
22
  import { useMediaQuery } from 'react-responsive';
8
- import Icon from '../Icon';
23
+ import Icon, { IconProps } from '../Icon';
9
24
  import breakpoints from '../utils/breakpoints';
10
25
  import Button from '../Button';
26
+ // @ts-ignore for now - this needs to be converted to TypeScript
11
27
  import ActionRow from '../ActionRow';
12
28
 
13
29
  export const ALERT_CLOSE_LABEL_TEXT = 'Dismiss';
14
30
 
15
- const Alert = React.forwardRef(({
31
+ export type AlertVariant = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light';
32
+
33
+ export type BaseProps = Omit<BaseAlertProps, 'children' | 'variant' | 'closeLabel'>;
34
+
35
+ export interface AlertProps extends BaseProps {
36
+ className?: string;
37
+ bsPrefix?: string;
38
+ variant?: AlertVariant;
39
+ children?: ReactNode;
40
+ icon?: React.ComponentType<IconProps>;
41
+ show?: boolean;
42
+ dismissible?: boolean;
43
+ onClose?: () => void;
44
+ actions?: React.ReactElement[];
45
+ stacked?: boolean;
46
+ closeLabel?: string | ReactNode;
47
+ }
48
+
49
+ export interface AlertHeadingProps {
50
+ as?: ElementType;
51
+ bsPrefix?: string;
52
+ children?: ReactNode;
53
+ }
54
+
55
+ export interface AlertLinkProps {
56
+ as?: ElementType;
57
+ bsPrefix?: string;
58
+ children?: ReactNode;
59
+ href?: string;
60
+ }
61
+
62
+ export interface AlertComponent extends ForwardRefExoticComponent<AlertProps & RefAttributes<HTMLDivElement>> {
63
+ Heading: FC<AlertHeadingProps>;
64
+ Link: FC<AlertLinkProps>;
65
+ }
66
+
67
+ const Alert = forwardRef<HTMLDivElement, AlertProps>(({
16
68
  children,
17
69
  icon,
18
70
  actions,
@@ -35,9 +87,9 @@ const Alert = React.forwardRef(({
35
87
  }, [isExtraSmall, stacked]);
36
88
 
37
89
  const cloneActionElement = useCallback(
38
- (Action) => {
90
+ (Action: React.ReactElement) => {
39
91
  const addtlActionProps = { size: actionButtonSize, key: Action.props.children };
40
- return React.cloneElement(Action, addtlActionProps);
92
+ return cloneElement(Action, addtlActionProps);
41
93
  },
42
94
  [],
43
95
  );
@@ -58,7 +110,7 @@ const Alert = React.forwardRef(({
58
110
  <div className="alert-message-content">
59
111
  {children}
60
112
  </div>
61
- {(dismissible || actions?.length > 0) && (
113
+ {(dismissible || (actions && actions.length > 0)) && (
62
114
  <ActionRow className="pgn__alert-actions">
63
115
  <ActionRow.Spacer />
64
116
  {dismissible && (
@@ -82,7 +134,7 @@ const Alert = React.forwardRef(({
82
134
  </div>
83
135
  </BaseAlert>
84
136
  );
85
- });
137
+ }) as AlertComponent;
86
138
 
87
139
  // This is needed to display a default prop for Alert.Heading element
88
140
  // Copied from react-bootstrap since BaseAlert.Heading component doesn't have defaultProps,
@@ -90,25 +142,30 @@ const Alert = React.forwardRef(({
90
142
  const DivStyledAsH4 = divWithClassName('h4');
91
143
  DivStyledAsH4.displayName = 'DivStyledAsH4';
92
144
 
93
- function AlertHeading(props) {
145
+ function AlertHeading(props: AlertHeadingProps): JSX.Element {
94
146
  return <BaseAlert.Heading {...props} />;
95
147
  }
96
- function AlertLink(props) {
148
+
149
+ function AlertLink(props: AlertLinkProps): JSX.Element {
97
150
  return <BaseAlert.Link {...props} />;
98
151
  }
99
152
 
100
- const commonPropTypes = {
153
+ AlertLink.propTypes = {
101
154
  /** Specifies the base element */
102
- as: PropTypes.elementType,
155
+ as: PropTypes.elementType as PropTypes.Validator<ElementType>,
103
156
  /** Overrides underlying component base CSS class name */
104
157
  bsPrefix: PropTypes.string,
105
158
  };
106
159
 
107
- AlertLink.propTypes = commonPropTypes;
108
- AlertHeading.propTypes = commonPropTypes;
160
+ AlertHeading.propTypes = {
161
+ /** Specifies the base element */
162
+ as: PropTypes.elementType as PropTypes.Validator<ElementType>,
163
+ /** Overrides underlying component base CSS class name */
164
+ bsPrefix: PropTypes.string,
165
+ };
109
166
 
110
167
  AlertLink.defaultProps = {
111
- as: 'a',
168
+ as: 'a' as ElementType,
112
169
  bsPrefix: 'alert-link',
113
170
  };
114
171
 
@@ -124,24 +181,27 @@ Alert.propTypes = {
124
181
  /** Overrides underlying component base CSS class name */
125
182
  bsPrefix: PropTypes.string,
126
183
  /** Specifies variant to use. */
127
- variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light']),
184
+ variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'] as AlertVariant[]),
128
185
  /**
129
186
  * Animate the entering and exiting of the Alert. `true` will use the `<Fade>` transition,
130
187
  * more detailed customization is also provided.
131
188
  */
132
- transition: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
133
- in: PropTypes.bool,
134
- appear: PropTypes.bool,
135
- children: PropTypes.node,
136
- onEnter: PropTypes.func,
137
- onEntered: PropTypes.func,
138
- onEntering: PropTypes.func,
139
- onExit: PropTypes.func,
140
- onExited: PropTypes.func,
141
- onExiting: PropTypes.func,
142
- })]),
189
+ transition: PropTypes.oneOfType([
190
+ PropTypes.bool,
191
+ PropTypes.shape({
192
+ in: PropTypes.bool,
193
+ appear: PropTypes.bool,
194
+ children: PropTypes.node,
195
+ onEnter: PropTypes.func,
196
+ onEntered: PropTypes.func,
197
+ onEntering: PropTypes.func,
198
+ onExit: PropTypes.func,
199
+ onExited: PropTypes.func,
200
+ onExiting: PropTypes.func,
201
+ }),
202
+ ]) as PropTypes.Validator<BaseAlertProps['transition']>,
143
203
  /** Docstring for the children prop */
144
- children: PropTypes.node,
204
+ children: PropTypes.node as PropTypes.Validator<ReactNode>,
145
205
  /** Docstring for the icon prop... Icon that will be shown in the alert */
146
206
  icon: PropTypes.func,
147
207
  /** Whether the alert is shown. */
@@ -151,7 +211,7 @@ Alert.propTypes = {
151
211
  /** Optional callback function for when the alert it dismissed. */
152
212
  onClose: PropTypes.func,
153
213
  /** Optional list of action elements. May include, at most, 2 actions, or 1 if dismissible is true. */
154
- actions: PropTypes.arrayOf(PropTypes.element),
214
+ actions: PropTypes.arrayOf(PropTypes.element) as PropTypes.Validator<React.ReactElement[]>,
155
215
  /** Position of the dismiss and call-to-action buttons. Defaults to ``false``. */
156
216
  stacked: PropTypes.bool,
157
217
  /** Sets the text for alert close button, defaults to 'Dismiss'. */
@@ -168,6 +228,9 @@ Alert.defaultProps = {
168
228
  closeLabel: undefined,
169
229
  show: true,
170
230
  stacked: false,
231
+ className: undefined,
232
+ bsPrefix: undefined,
233
+ variant: undefined,
171
234
  };
172
235
 
173
236
  Alert.Heading = AlertHeading;
@@ -114,6 +114,7 @@ You can use `Dropdown.Toggle` with [IconButton](/components/iconbutton) componen
114
114
  src={MoreVert}
115
115
  iconAs={Icon}
116
116
  variant="primary"
117
+ aria-label="More actions"
117
118
  />
118
119
  <Dropdown.Menu>
119
120
  <Dropdown.Item href="#/action-1">Action</Dropdown.Item>
package/src/index.d.ts CHANGED
@@ -46,13 +46,14 @@ export { default as useToggle, type Toggler, type ToggleHandlers } from './hooks
46
46
  export { default as useArrowKeyNavigation, type ArrowKeyNavProps } from './hooks/useArrowKeyNavigationHook';
47
47
  export { default as useIndexOfLastVisibleChild } from './hooks/useIndexOfLastVisibleChildHook';
48
48
  export { default as useIsVisible } from './hooks/useIsVisibleHook';
49
+ export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
50
+ export { default as breakpoints } from './utils/breakpoints';
49
51
 
50
52
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
51
53
  // Things that don't have types
52
54
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
53
55
  export const asInput: any; // from './asInput';
54
56
  export const ActionRow: any; // from './ActionRow';
55
- export const Alert: any, ALERT_CLOSE_LABEL_TEXT: string; // from './Alert';
56
57
  export const Annotation: any; // from './Annotation';
57
58
  export const Avatar: any; // from './Avatar';
58
59
  export const AvatarButton: any; // from './AvatarButton';
@@ -190,7 +191,6 @@ export const Stack: any; // from './Stack';
190
191
  export const ToggleButton: any, ToggleButtonGroup: any; // from './ToggleButton';
191
192
  export const Sticky: any; // from './Sticky';
192
193
  export const SelectableBox: any; // from './SelectableBox';
193
- export const breakpoints: any; // from './utils/breakpoints';
194
194
  export const Variant: any; // from './utils/constants';
195
195
  export const
196
196
  OverflowScrollContext: any,
package/src/index.js CHANGED
@@ -46,13 +46,14 @@ export { default as useToggle } from './hooks/useToggleHook';
46
46
  export { default as useArrowKeyNavigation } from './hooks/useArrowKeyNavigationHook';
47
47
  export { default as useIndexOfLastVisibleChild } from './hooks/useIndexOfLastVisibleChildHook';
48
48
  export { default as useIsVisible } from './hooks/useIsVisibleHook';
49
+ export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
50
+ export { default as breakpoints } from './utils/breakpoints';
49
51
 
50
52
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
51
53
  // Things that don't have types
52
54
  // // // // // // // // // // // // // // // // // // // // // // // // // // //
53
55
  export { default as asInput } from './asInput';
54
56
  export { default as ActionRow } from './ActionRow';
55
- export { default as Alert, ALERT_CLOSE_LABEL_TEXT } from './Alert';
56
57
  export { default as Annotation } from './Annotation';
57
58
  export { default as Avatar } from './Avatar';
58
59
  export { default as AvatarButton } from './AvatarButton';
@@ -190,7 +191,6 @@ export { default as Stack } from './Stack';
190
191
  export { default as ToggleButton, ToggleButtonGroup } from './ToggleButton';
191
192
  export { default as Sticky } from './Sticky';
192
193
  export { default as SelectableBox } from './SelectableBox';
193
- export { default as breakpoints } from './utils/breakpoints';
194
194
  export { default as Variant } from './utils/constants';
195
195
  export {
196
196
  OverflowScrollContext,
@@ -0,0 +1,26 @@
1
+ interface BreakpointRange {
2
+ minWidth?: number;
3
+ maxWidth?: number;
4
+ }
5
+
6
+ interface Breakpoints {
7
+ extraSmall: BreakpointRange;
8
+ small: BreakpointRange;
9
+ medium: BreakpointRange;
10
+ large: BreakpointRange;
11
+ extraLarge: BreakpointRange;
12
+ extraExtraLarge: BreakpointRange;
13
+ }
14
+
15
+ export const Size: {
16
+ readonly xs: 'extraSmall';
17
+ readonly sm: 'small';
18
+ readonly md: 'medium';
19
+ readonly lg: 'large';
20
+ readonly xl: 'extraLarge';
21
+ readonly xxl: 'extraExtraLarge';
22
+ };
23
+
24
+ declare const breakpoints: Breakpoints;
25
+
26
+ export default breakpoints;