@openedx/paragon 23.22.2 → 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.
- package/README.md +25 -54
- package/dist/Icon/index.d.ts +39 -15
- package/dist/Icon/index.js +3 -54
- package/dist/Icon/index.js.map +1 -1
- package/lib/__tests__/build-scss.test.js +1 -1
- package/lib/__tests__/install-theme.test.js +2 -2
- package/lib/build-scss.js +6 -1
- package/lib/install-theme.js +1 -1
- package/package.json +8 -5
- package/src/Icon/Icon.test.tsx +7 -21
- package/src/Icon/{index.jsx → index.tsx} +41 -57
- package/src/Icon/index.d.ts +0 -20
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ Use `paragon help` to see more information.
|
|
|
90
90
|
|
|
91
91
|
## Internationalization
|
|
92
92
|
|
|
93
|
-
Paragon supports internationalization for its components out of the box with the support of [react-intl](https://formatjs.io/docs/react-intl/). You may view translated strings for each component on the documentation website by switching languages in the settings.
|
|
93
|
+
Paragon supports internationalization for its components out of the box with the support of [react-intl](https://formatjs.io/docs/react-intl/). ``react-intl`` 5.x, 6.x, or 10.1.20+ may be used. You may view translated strings for each component on the documentation website by switching languages in the settings.
|
|
94
94
|
|
|
95
95
|
Due to Paragon's dependence on ``react-intl``, that means that your whole app needs to be wrapped in its provider, e.g.:
|
|
96
96
|
|
|
@@ -265,59 +265,30 @@ When developing a new component you should generally follow three rules:
|
|
|
265
265
|
/>
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
- For places where the display string has to be a plain JavaScript string use ``formatMessage``, this would require access to ``intl`` object from ``react-intl``,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export default injectIntl(MyClassComponent);
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
- For functional components use ``useIntl`` hook
|
|
298
|
-
|
|
299
|
-
```javascript
|
|
300
|
-
import { useIntl } from 'react-intl';
|
|
301
|
-
|
|
302
|
-
const MyFunctionComponent = ({ altText }) => {
|
|
303
|
-
const intls = useIntl();
|
|
304
|
-
const intlAltText = altText || intl.formatMessage({
|
|
305
|
-
id: 'pgn.MyComponent.altText',
|
|
306
|
-
defaultMessage: 'Close',
|
|
307
|
-
description: 'Close label for Toast component',
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
return (
|
|
311
|
-
<IconButton
|
|
312
|
-
alt={intlCloseLabel}
|
|
313
|
-
onClick={() => {}}
|
|
314
|
-
variant="primary"
|
|
315
|
-
/>
|
|
316
|
-
)
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export default MyFunctionComponent;
|
|
320
|
-
```
|
|
268
|
+
- For places where the display string has to be a plain JavaScript string use ``formatMessage``, this would require access to ``intl`` object from ``react-intl``, which is provided by the ``useIntl`` hook (the ``injectIntl`` HOC must not be used, as it was removed in ``react-intl`` 10)
|
|
269
|
+
|
|
270
|
+
```javascript
|
|
271
|
+
import { useIntl } from 'react-intl';
|
|
272
|
+
|
|
273
|
+
const MyFunctionComponent = ({ altText }) => {
|
|
274
|
+
const intl = useIntl();
|
|
275
|
+
const intlAltText = altText || intl.formatMessage({
|
|
276
|
+
id: 'pgn.MyComponent.altText',
|
|
277
|
+
defaultMessage: 'Close',
|
|
278
|
+
description: 'Close label for Toast component',
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<IconButton
|
|
283
|
+
alt={intlAltText}
|
|
284
|
+
onClick={() => {}}
|
|
285
|
+
variant="primary"
|
|
286
|
+
/>
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export default MyFunctionComponent;
|
|
291
|
+
```
|
|
321
292
|
|
|
322
293
|
**Notes on the format above**:
|
|
323
294
|
- `id` is required and must be a dot-separated string of the format `pgn.<componentName>.<subcomponentName>.<propName>`
|
package/dist/Icon/index.d.ts
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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;
|
package/dist/Icon/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
package/dist/Icon/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","
|
|
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":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const inquirer = require('inquirer');
|
|
2
|
-
const childProcess = require('child_process');
|
|
2
|
+
const childProcess = require('node:child_process');
|
|
3
3
|
|
|
4
4
|
const themeCommand = require('../install-theme');
|
|
5
5
|
|
|
6
6
|
jest.mock('inquirer');
|
|
7
|
-
jest.mock('child_process');
|
|
7
|
+
jest.mock('node:child_process');
|
|
8
8
|
|
|
9
9
|
describe('install-theme', () => {
|
|
10
10
|
beforeEach(() => {
|
package/lib/build-scss.js
CHANGED
|
@@ -90,7 +90,12 @@ const compileAndWriteStyleSheets = ({
|
|
|
90
90
|
if (!url.startsWith('~')) {
|
|
91
91
|
return null;
|
|
92
92
|
}
|
|
93
|
-
|
|
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/lib/install-theme.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openedx/paragon",
|
|
3
|
-
"version": "23.
|
|
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",
|
|
@@ -67,7 +70,6 @@
|
|
|
67
70
|
"axios": "^1.0.0",
|
|
68
71
|
"bootstrap": "^4.6.2",
|
|
69
72
|
"chalk": "^4.1.2",
|
|
70
|
-
"child_process": "^1.0.2",
|
|
71
73
|
"chroma-js": "^3.0.0",
|
|
72
74
|
"classnames": "^2.3.1",
|
|
73
75
|
"cli-progress": "^3.12.0",
|
|
@@ -110,7 +112,7 @@
|
|
|
110
112
|
"peerDependencies": {
|
|
111
113
|
"react": "^16.8.6 || ^17 || ^18",
|
|
112
114
|
"react-dom": "^16.8.6 || ^17 || ^18",
|
|
113
|
-
"react-intl": "^5.25.1 || ^6.4.0"
|
|
115
|
+
"react-intl": "^5.25.1 || ^6.4.0 || ^10.1.20"
|
|
114
116
|
},
|
|
115
117
|
"devDependencies": {
|
|
116
118
|
"@babel/cli": "^7.16.8",
|
|
@@ -134,7 +136,6 @@
|
|
|
134
136
|
"@types/jest": "^29.5.10",
|
|
135
137
|
"@types/react": "^18",
|
|
136
138
|
"@types/react-dom": "^18",
|
|
137
|
-
"@types/react-responsive": "^9.0.0",
|
|
138
139
|
"@types/react-table": "^7.7.19",
|
|
139
140
|
"@types/react-test-renderer": "^18.0.0",
|
|
140
141
|
"@types/uuid": "^9.0.0",
|
|
@@ -155,7 +156,9 @@
|
|
|
155
156
|
"jest-cli": "^29.7.0",
|
|
156
157
|
"jest-environment-jsdom": "^29.7.0",
|
|
157
158
|
"markdown-loader-jest": "^0.1.1",
|
|
159
|
+
"nodemon": "^3.1.14",
|
|
158
160
|
"react": "^18",
|
|
161
|
+
"react-intl": "^10.1.20",
|
|
159
162
|
"react-test-renderer": "^18",
|
|
160
163
|
"regenerator-runtime": "^0.14.0",
|
|
161
164
|
"semantic-release": "^25.0.0",
|
|
@@ -197,7 +200,7 @@
|
|
|
197
200
|
"/component-generator/"
|
|
198
201
|
],
|
|
199
202
|
"transformIgnorePatterns": [
|
|
200
|
-
"/node_modules/(?!(@openedx/paragon)/).*/"
|
|
203
|
+
"/node_modules/(?!(@openedx/paragon|react-intl|@formatjs|intl-messageformat)/).*/"
|
|
201
204
|
]
|
|
202
205
|
},
|
|
203
206
|
"browserslist": [
|
package/src/Icon/Icon.test.tsx
CHANGED
|
@@ -6,10 +6,7 @@ import { type IconName } from '../../icons';
|
|
|
6
6
|
import Icon from './index';
|
|
7
7
|
|
|
8
8
|
const testId = 'testId';
|
|
9
|
-
const
|
|
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={
|
|
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(
|
|
62
|
-
expect(iconSpan.classList.contains(
|
|
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={
|
|
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={
|
|
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={
|
|
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
|
-
|
|
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;
|
package/src/Icon/index.d.ts
DELETED
|
@@ -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;
|