@openedx/paragon 23.23.0 → 23.23.1

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.
@@ -1,20 +1,44 @@
1
1
  import React from 'react';
2
-
3
- export interface IconProps extends React.ComponentPropsWithoutRef<'span'> {
4
- // Note: React.ComponentType is what we want here. React.ElementType would allow some element type strings like "div",
5
- // but we only want to allow components like 'Add' (a specific icon component function/class)
6
- src?: React.ComponentType;
7
- svgAttrs?: {
2
+ /**
3
+ * An svg with an "img" role must satisfy the following a11y requirements
4
+ * - It needs a text alternative in the form of aria-label, aria-labelledby, or screen-reader only text.
5
+ * - If no label is desired, aria-label will be set to an empty string and aria-hidden to "true".
6
+ * - focusable is set to false on the svg in all cases as a workaround for an ie11 bug
7
+ */
8
+ interface SvgAttrs extends React.SVGAttributes<SVGElement> {
8
9
  'aria-label'?: string;
9
10
  'aria-labelledby'?: string;
10
- };
11
- id?: string | null;
12
- size?: 'xs' | 'sm' | 'md' | 'lg' | 'inline';
13
- className?: string | string[];
14
- hidden?: boolean;
15
- screenReaderText?: React.ReactNode;
11
+ 'aria-hidden'?: boolean;
16
12
  }
17
-
18
- declare const Icon: React.FC<IconProps>;
19
-
13
+ export interface IconProps extends Omit<React.ComponentPropsWithoutRef<'span'>, 'id' | 'className'> {
14
+ /**
15
+ * An icon component to render.
16
+ * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`
17
+ */
18
+ src?: React.ComponentType<any>;
19
+ /** HTML element attributes to pass through to the underlying `svg` element */
20
+ svgAttrs?: SvgAttrs;
21
+ /**
22
+ * the `id` property of the Icon element, by default this value is generated
23
+ * with the `newId` function with the `prefix` of `Icon`.
24
+ */
25
+ id?: string;
26
+ /** The size of the icon. */
27
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'inline';
28
+ /** A class name that will define what the Icon looks like. */
29
+ className?: string;
30
+ /**
31
+ * a boolean that determines the value of `aria-hidden` attribute on the Icon span,
32
+ * this value is `true` by default.
33
+ */
34
+ hidden?: boolean;
35
+ /**
36
+ * a string or an element that will be used on a secondary span leveraging the `sr-only` style
37
+ * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless
38
+ * the Icon is being used in a way that is purely decorative or provides no additional context for screen
39
+ * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.
40
+ */
41
+ screenReaderText?: React.ReactNode;
42
+ }
43
+ declare function Icon({ src: Component, id, className, hidden, screenReaderText, svgAttrs, size, ...attrs }: IconProps): import("react/jsx-runtime").JSX.Element;
20
44
  export default Icon;
@@ -1,8 +1,6 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import classNames from 'classnames';
4
3
  import newId from '../utils/newId';
5
- import withDeprecatedProps, { DeprTypes } from '../withDeprecatedProps';
6
4
 
7
5
  /**
8
6
  * An svg with an "img" role must satisfy the following a11y requirements
@@ -15,9 +13,9 @@ function Icon({
15
13
  src: Component,
16
14
  id,
17
15
  className,
18
- hidden,
16
+ hidden = true,
19
17
  screenReaderText,
20
- svgAttrs,
18
+ svgAttrs = {},
21
19
  size,
22
20
  ...attrs
23
21
  }) {
@@ -53,54 +51,5 @@ function Icon({
53
51
  className: "sr-only"
54
52
  }, screenReaderText));
55
53
  }
56
- Icon.propTypes = {
57
- /**
58
- * An icon component to render.
59
- * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`
60
- */
61
- src: PropTypes.elementType,
62
- /** HTML element attributes to pass through to the underlying svg element */
63
- svgAttrs: PropTypes.shape({
64
- 'aria-label': PropTypes.string,
65
- 'aria-labelledby': PropTypes.string
66
- }),
67
- /**
68
- * the `id` property of the Icon element, by default this value is generated
69
- * with the `newId` function with the `prefix` of `Icon`.
70
- */
71
- id: PropTypes.string,
72
- /** The size of the icon. */
73
- size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg']),
74
- /** A class name that will define what the Icon looks like. */
75
- className: PropTypes.string,
76
- /**
77
- * a boolean that determines the value of `aria-hidden` attribute on the Icon span,
78
- * this value is `true` by default.
79
- */
80
- hidden: PropTypes.bool,
81
- /**
82
- * a string or an element that will be used on a secondary span leveraging the `sr-only` style
83
- * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless
84
- * the Icon is being used in a way that is purely decorative or provides no additional context for screen
85
- * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.
86
- */
87
- screenReaderText: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
88
- };
89
- Icon.defaultProps = {
90
- src: null,
91
- svgAttrs: {},
92
- id: undefined,
93
- hidden: true,
94
- screenReaderText: undefined,
95
- size: undefined,
96
- className: undefined
97
- };
98
- export default withDeprecatedProps(Icon, 'Icon', {
99
- className: {
100
- deprType: DeprTypes.FORMAT,
101
- expect: value => typeof value === 'string',
102
- transform: value => Array.isArray(value) ? value.join(' ') : value,
103
- message: 'It should be a string.'
104
- }
105
- });
54
+ export default Icon;
106
55
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","PropTypes","classNames","newId","withDeprecatedProps","DeprTypes","Icon","src","Component","id","className","hidden","screenReaderText","svgAttrs","size","attrs","hasAriaLabel","mergedSvgProps","undefined","createElement","role","focusable","Fragment","propTypes","elementType","shape","string","oneOf","bool","oneOfType","element","defaultProps","deprType","FORMAT","expect","value","transform","Array","isArray","join","message"],"sources":["../../src/Icon/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\n\nimport newId from '../utils/newId';\nimport withDeprecatedProps, { DeprTypes } from '../withDeprecatedProps';\n\n/**\n * An svg with an \"img\" role must satisfy the following a11y requirements\n * - It needs a text alternative in the form of aria-label, aria-labelledby, or screen-reader only text.\n * - If no label is desired, aria-label will be set to an empty string and aria-hidden to \"true\".\n * - focusable is set to false on the svg in all cases as a workaround for an ie11 bug\n */\n\nfunction Icon({\n src: Component,\n id,\n className,\n hidden,\n screenReaderText,\n svgAttrs,\n size,\n ...attrs\n}) {\n if (Component) {\n // If no aria label is specified, hide this icon from screenreaders\n const hasAriaLabel = svgAttrs['aria-label'] || svgAttrs['aria-labelledby'];\n\n const mergedSvgProps = { ...svgAttrs };\n\n if (!hasAriaLabel) {\n mergedSvgProps['aria-label'] = undefined;\n mergedSvgProps['aria-hidden'] = true;\n }\n\n return (\n <span\n className={classNames('pgn__icon', { [`pgn__icon__${size}`]: !!size }, className)}\n id={id}\n {...attrs}\n >\n <Component\n role=\"img\"\n focusable={false}\n {...mergedSvgProps}\n />\n {screenReaderText && (\n <span className=\"sr-only\">\n {screenReaderText}\n </span>\n )}\n </span>\n );\n }\n\n return (\n <>\n <span\n id={id || newId('Icon')}\n className={className}\n aria-hidden={hidden}\n />\n {screenReaderText && (\n <span className=\"sr-only\">\n {screenReaderText}\n </span>\n )}\n </>\n );\n}\n\nIcon.propTypes = {\n /**\n * An icon component to render.\n * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`\n */\n src: PropTypes.elementType,\n /** HTML element attributes to pass through to the underlying svg element */\n svgAttrs: PropTypes.shape({\n 'aria-label': PropTypes.string,\n 'aria-labelledby': PropTypes.string,\n }),\n /**\n * the `id` property of the Icon element, by default this value is generated\n * with the `newId` function with the `prefix` of `Icon`.\n */\n id: PropTypes.string,\n /** The size of the icon. */\n size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg']),\n /** A class name that will define what the Icon looks like. */\n className: PropTypes.string,\n /**\n * a boolean that determines the value of `aria-hidden` attribute on the Icon span,\n * this value is `true` by default.\n */\n hidden: PropTypes.bool,\n /**\n * a string or an element that will be used on a secondary span leveraging the `sr-only` style\n * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless\n * the Icon is being used in a way that is purely decorative or provides no additional context for screen\n * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.\n */\n screenReaderText: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n};\n\nIcon.defaultProps = {\n src: null,\n svgAttrs: {},\n id: undefined,\n hidden: true,\n screenReaderText: undefined,\n size: undefined,\n className: undefined,\n};\n\nexport default withDeprecatedProps(Icon, 'Icon', {\n className: {\n deprType: DeprTypes.FORMAT,\n expect: value => typeof value === 'string',\n transform: value => (Array.isArray(value) ? value.join(' ') : value),\n message: 'It should be a string.',\n },\n});\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","classNames","newId","Icon","src","Component","id","className","hidden","screenReaderText","svgAttrs","size","attrs","hasAriaLabel","mergedSvgProps","undefined","createElement","role","focusable","Fragment"],"sources":["../../src/Icon/index.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\n\nimport newId from '../utils/newId';\n\n/**\n * An svg with an \"img\" role must satisfy the following a11y requirements\n * - It needs a text alternative in the form of aria-label, aria-labelledby, or screen-reader only text.\n * - If no label is desired, aria-label will be set to an empty string and aria-hidden to \"true\".\n * - focusable is set to false on the svg in all cases as a workaround for an ie11 bug\n */\n\ninterface SvgAttrs extends React.SVGAttributes<SVGElement> {\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n 'aria-hidden'?: boolean;\n}\n\nexport interface IconProps extends Omit<React.ComponentPropsWithoutRef<'span'>, 'id' | 'className'> {\n /**\n * An icon component to render.\n * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`\n */\n src?: React.ComponentType<any>;\n /** HTML element attributes to pass through to the underlying `svg` element */\n svgAttrs?: SvgAttrs;\n /**\n * the `id` property of the Icon element, by default this value is generated\n * with the `newId` function with the `prefix` of `Icon`.\n */\n id?: string;\n /** The size of the icon. */\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'inline';\n /** A class name that will define what the Icon looks like. */\n className?: string;\n /**\n * a boolean that determines the value of `aria-hidden` attribute on the Icon span,\n * this value is `true` by default.\n */\n hidden?: boolean;\n /**\n * a string or an element that will be used on a secondary span leveraging the `sr-only` style\n * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless\n * the Icon is being used in a way that is purely decorative or provides no additional context for screen\n * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.\n */\n screenReaderText?: React.ReactNode;\n}\n\nfunction Icon({\n src: Component,\n id,\n className,\n hidden = true,\n screenReaderText,\n svgAttrs = {},\n size,\n ...attrs\n}: IconProps) {\n if (Component) {\n // If no aria label is specified, hide this icon from screenreaders\n const hasAriaLabel = svgAttrs['aria-label'] || svgAttrs['aria-labelledby'];\n\n const mergedSvgProps = { ...svgAttrs };\n\n if (!hasAriaLabel) {\n mergedSvgProps['aria-label'] = undefined;\n mergedSvgProps['aria-hidden'] = true;\n }\n\n return (\n <span\n className={classNames('pgn__icon', { [`pgn__icon__${size}`]: !!size }, className)}\n id={id}\n {...attrs}\n >\n <Component\n role=\"img\"\n focusable={false}\n {...mergedSvgProps}\n />\n {screenReaderText && (\n <span className=\"sr-only\">\n {screenReaderText}\n </span>\n )}\n </span>\n );\n }\n\n return (\n <>\n <span\n id={id || newId('Icon')}\n className={className}\n aria-hidden={hidden}\n />\n {screenReaderText && (\n <span className=\"sr-only\">\n {screenReaderText}\n </span>\n )}\n </>\n );\n}\n\nexport default Icon;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AAEnC,OAAOC,KAAK,MAAM,gBAAgB;;AAElC;AACA;AACA;AACA;AACA;AACA;;AAuCA,SAASC,IAAIA,CAAC;EACZC,GAAG,EAAEC,SAAS;EACdC,EAAE;EACFC,SAAS;EACTC,MAAM,GAAG,IAAI;EACbC,gBAAgB;EAChBC,QAAQ,GAAG,CAAC,CAAC;EACbC,IAAI;EACJ,GAAGC;AACM,CAAC,EAAE;EACZ,IAAIP,SAAS,EAAE;IACb;IACA,MAAMQ,YAAY,GAAGH,QAAQ,CAAC,YAAY,CAAC,IAAIA,QAAQ,CAAC,iBAAiB,CAAC;IAE1E,MAAMI,cAAc,GAAG;MAAE,GAAGJ;IAAS,CAAC;IAEtC,IAAI,CAACG,YAAY,EAAE;MACjBC,cAAc,CAAC,YAAY,CAAC,GAAGC,SAAS;MACxCD,cAAc,CAAC,aAAa,CAAC,GAAG,IAAI;IACtC;IAEA,oBACEd,KAAA,CAAAgB,aAAA;MACET,SAAS,EAAEN,UAAU,CAAC,WAAW,EAAE;QAAE,CAAC,cAAcU,IAAI,EAAE,GAAG,CAAC,CAACA;MAAK,CAAC,EAAEJ,SAAS,CAAE;MAClFD,EAAE,EAAEA,EAAG;MAAA,GACHM;IAAK,gBAETZ,KAAA,CAAAgB,aAAA,CAACX,SAAS;MACRY,IAAI,EAAC,KAAK;MACVC,SAAS,EAAE,KAAM;MAAA,GACbJ;IAAc,CACnB,CAAC,EACDL,gBAAgB,iBACfT,KAAA,CAAAgB,aAAA;MAAMT,SAAS,EAAC;IAAS,GACtBE,gBACG,CAEJ,CAAC;EAEX;EAEA,oBACET,KAAA,CAAAgB,aAAA,CAAAhB,KAAA,CAAAmB,QAAA,qBACEnB,KAAA,CAAAgB,aAAA;IACEV,EAAE,EAAEA,EAAE,IAAIJ,KAAK,CAAC,MAAM,CAAE;IACxBK,SAAS,EAAEA,SAAU;IACrB,eAAaC;EAAO,CACrB,CAAC,EACDC,gBAAgB,iBACfT,KAAA,CAAAgB,aAAA;IAAMT,SAAS,EAAC;EAAS,GACtBE,gBACG,CAER,CAAC;AAEP;AAEA,eAAeN,IAAI","ignoreList":[]}
package/lib/build-scss.js CHANGED
@@ -90,7 +90,12 @@ const compileAndWriteStyleSheets = ({
90
90
  if (!url.startsWith('~')) {
91
91
  return null;
92
92
  }
93
- return new URL(url.substring(1), `${pathToFileURL('node_modules')}/node_modules`);
93
+ const specifier = url.substring(1);
94
+ // The package name is an optional '@scope/' prefix followed by one more path segment.
95
+ const packageName = specifier.match(/^(?:@[^/]+\/)?[^/]+/)[0];
96
+ const searchPaths = require.resolve.paths(packageName) || [];
97
+ const dir = searchPaths.find((nodeModules) => fs.existsSync(path.join(nodeModules, packageName)));
98
+ return dir ? pathToFileURL(path.join(dir, specifier)) : null;
94
99
  },
95
100
  }],
96
101
  // For now we can't resolve these warnings as we need to upgrade our 'bootstrap' dependency to do so:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "23.23.0",
3
+ "version": "23.23.1",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -30,6 +30,9 @@
30
30
  },
31
31
  "scripts": {
32
32
  "build": "make build",
33
+ "build-incremental": "make build-incremental",
34
+ "clean": "make clean",
35
+ "watch:build": "nodemon -x \"npm run build-incremental\"",
33
36
  "build-docs": "make build-docs",
34
37
  "commit": "commit",
35
38
  "debug-test": "node --inspect-brk node_modules/.bin/jest --runInBand --coverage",
@@ -133,7 +136,6 @@
133
136
  "@types/jest": "^29.5.10",
134
137
  "@types/react": "^18",
135
138
  "@types/react-dom": "^18",
136
- "@types/react-responsive": "^9.0.0",
137
139
  "@types/react-table": "^7.7.19",
138
140
  "@types/react-test-renderer": "^18.0.0",
139
141
  "@types/uuid": "^9.0.0",
@@ -154,6 +156,7 @@
154
156
  "jest-cli": "^29.7.0",
155
157
  "jest-environment-jsdom": "^29.7.0",
156
158
  "markdown-loader-jest": "^0.1.1",
159
+ "nodemon": "^3.1.14",
157
160
  "react": "^18",
158
161
  "react-intl": "^10.1.20",
159
162
  "react-test-renderer": "^18",
@@ -6,10 +6,7 @@ import { type IconName } from '../../icons';
6
6
  import Icon from './index';
7
7
 
8
8
  const testId = 'testId';
9
- const classNames = [
10
- 'fa',
11
- 'fa-check',
12
- ];
9
+ const className = 'fa fa-check';
13
10
  const srTest = 'srTest';
14
11
 
15
12
  function BlankSrc() {
@@ -53,28 +50,17 @@ describe('<Icon />', () => {
53
50
 
54
51
  describe('props received correctly', () => {
55
52
  it('receives required props', () => {
56
- const { container } = render(<Icon className={classNames} />);
53
+ const { container } = render(<Icon className={className} />);
57
54
  const iconSpans = container.querySelectorAll('span');
58
55
  const iconSpan = iconSpans[0];
59
56
 
60
57
  expect(iconSpan.getAttribute('id')).toContain('Icon');
61
- expect(iconSpan.classList.contains(classNames[0])).toEqual(true);
62
- expect(iconSpan.classList.contains(classNames[1])).toEqual(true);
63
- });
64
-
65
- it('handles null id properly', () => {
66
- const nullId = null;
67
- const { container } = render(<Icon id={nullId} className={classNames} />);
68
- const iconSpans = container.querySelectorAll('span');
69
- const iconSpan = iconSpans[0];
70
-
71
- expect(iconSpan.getAttribute('id')).toContain('Icon');
72
- expect(iconSpan.classList.contains(classNames[0])).toEqual(true);
73
- expect(iconSpan.classList.contains(classNames[1])).toEqual(true);
58
+ expect(iconSpan.classList.contains('fa')).toEqual(true);
59
+ expect(iconSpan.classList.contains('fa-check')).toEqual(true);
74
60
  });
75
61
 
76
62
  it('generates unique ids when no id is provided', () => {
77
- const { container } = render(<><Icon className={classNames} /><Icon className={classNames} /></>);
63
+ const { container } = render(<><Icon className={className} /><Icon className={className} /></>);
78
64
  const iconSpans = container.querySelectorAll('span');
79
65
  const iconSpan1 = iconSpans[0];
80
66
  const iconSpan2 = iconSpans[1];
@@ -87,7 +73,7 @@ describe('<Icon />', () => {
87
73
  });
88
74
 
89
75
  it('handles screenReaderText correctly', () => {
90
- const { container } = render(<Icon id={testId} className={classNames} screenReaderText={srTest} />);
76
+ const { container } = render(<Icon id={testId} className={className} screenReaderText={srTest} />);
91
77
  const iconSpans = container.querySelectorAll('span');
92
78
 
93
79
  expect(iconSpans.length).toEqual(2);
@@ -96,7 +82,7 @@ describe('<Icon />', () => {
96
82
  });
97
83
 
98
84
  it('receives size prop correctly', () => {
99
- const { container } = render(<Icon src={BlankSrc} className={classNames} size="xs" />);
85
+ const { container } = render(<Icon src={BlankSrc} className={className} size="xs" />);
100
86
  const iconSpans = container.querySelectorAll('span');
101
87
  const iconSpan = iconSpans[0];
102
88
 
@@ -1,9 +1,7 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import classNames from 'classnames';
4
3
 
5
4
  import newId from '../utils/newId';
6
- import withDeprecatedProps, { DeprTypes } from '../withDeprecatedProps';
7
5
 
8
6
  /**
9
7
  * An svg with an "img" role must satisfy the following a11y requirements
@@ -12,16 +10,53 @@ import withDeprecatedProps, { DeprTypes } from '../withDeprecatedProps';
12
10
  * - focusable is set to false on the svg in all cases as a workaround for an ie11 bug
13
11
  */
14
12
 
13
+ interface SvgAttrs extends React.SVGAttributes<SVGElement> {
14
+ 'aria-label'?: string;
15
+ 'aria-labelledby'?: string;
16
+ 'aria-hidden'?: boolean;
17
+ }
18
+
19
+ export interface IconProps extends Omit<React.ComponentPropsWithoutRef<'span'>, 'id' | 'className'> {
20
+ /**
21
+ * An icon component to render.
22
+ * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`
23
+ */
24
+ src?: React.ComponentType<any>;
25
+ /** HTML element attributes to pass through to the underlying `svg` element */
26
+ svgAttrs?: SvgAttrs;
27
+ /**
28
+ * the `id` property of the Icon element, by default this value is generated
29
+ * with the `newId` function with the `prefix` of `Icon`.
30
+ */
31
+ id?: string;
32
+ /** The size of the icon. */
33
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'inline';
34
+ /** A class name that will define what the Icon looks like. */
35
+ className?: string;
36
+ /**
37
+ * a boolean that determines the value of `aria-hidden` attribute on the Icon span,
38
+ * this value is `true` by default.
39
+ */
40
+ hidden?: boolean;
41
+ /**
42
+ * a string or an element that will be used on a secondary span leveraging the `sr-only` style
43
+ * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless
44
+ * the Icon is being used in a way that is purely decorative or provides no additional context for screen
45
+ * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.
46
+ */
47
+ screenReaderText?: React.ReactNode;
48
+ }
49
+
15
50
  function Icon({
16
51
  src: Component,
17
52
  id,
18
53
  className,
19
- hidden,
54
+ hidden = true,
20
55
  screenReaderText,
21
- svgAttrs,
56
+ svgAttrs = {},
22
57
  size,
23
58
  ...attrs
24
- }) {
59
+ }: IconProps) {
25
60
  if (Component) {
26
61
  // If no aria label is specified, hide this icon from screenreaders
27
62
  const hasAriaLabel = svgAttrs['aria-label'] || svgAttrs['aria-labelledby'];
@@ -69,55 +104,4 @@ function Icon({
69
104
  );
70
105
  }
71
106
 
72
- Icon.propTypes = {
73
- /**
74
- * An icon component to render.
75
- * Example import of a Paragon icon component: `import { Check } from '@openedx/paragon/icons';`
76
- */
77
- src: PropTypes.elementType,
78
- /** HTML element attributes to pass through to the underlying svg element */
79
- svgAttrs: PropTypes.shape({
80
- 'aria-label': PropTypes.string,
81
- 'aria-labelledby': PropTypes.string,
82
- }),
83
- /**
84
- * the `id` property of the Icon element, by default this value is generated
85
- * with the `newId` function with the `prefix` of `Icon`.
86
- */
87
- id: PropTypes.string,
88
- /** The size of the icon. */
89
- size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg']),
90
- /** A class name that will define what the Icon looks like. */
91
- className: PropTypes.string,
92
- /**
93
- * a boolean that determines the value of `aria-hidden` attribute on the Icon span,
94
- * this value is `true` by default.
95
- */
96
- hidden: PropTypes.bool,
97
- /**
98
- * a string or an element that will be used on a secondary span leveraging the `sr-only` style
99
- * for screenreader only text, this value is `undefined` by default. This value is recommended for use unless
100
- * the Icon is being used in a way that is purely decorative or provides no additional context for screen
101
- * reader users. This field should be thought of the same way an `alt` attribute would be used for `image` tags.
102
- */
103
- screenReaderText: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
104
- };
105
-
106
- Icon.defaultProps = {
107
- src: null,
108
- svgAttrs: {},
109
- id: undefined,
110
- hidden: true,
111
- screenReaderText: undefined,
112
- size: undefined,
113
- className: undefined,
114
- };
115
-
116
- export default withDeprecatedProps(Icon, 'Icon', {
117
- className: {
118
- deprType: DeprTypes.FORMAT,
119
- expect: value => typeof value === 'string',
120
- transform: value => (Array.isArray(value) ? value.join(' ') : value),
121
- message: 'It should be a string.',
122
- },
123
- });
107
+ export default Icon;
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
-
3
- export interface IconProps extends React.ComponentPropsWithoutRef<'span'> {
4
- // Note: React.ComponentType is what we want here. React.ElementType would allow some element type strings like "div",
5
- // but we only want to allow components like 'Add' (a specific icon component function/class)
6
- src?: React.ComponentType;
7
- svgAttrs?: {
8
- 'aria-label'?: string;
9
- 'aria-labelledby'?: string;
10
- };
11
- id?: string | null;
12
- size?: 'xs' | 'sm' | 'md' | 'lg' | 'inline';
13
- className?: string | string[];
14
- hidden?: boolean;
15
- screenReaderText?: React.ReactNode;
16
- }
17
-
18
- declare const Icon: React.FC<IconProps>;
19
-
20
- export default Icon;