@openedx/paragon 23.23.0 → 23.23.2

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":[]}
@@ -1,5 +1,11 @@
1
1
  {
2
2
  "themeUrls": {
3
+ "core": {
4
+ "paths": {
5
+ "default": "./core.css",
6
+ "minified": "./core.min.css"
7
+ }
8
+ },
3
9
  "defaults": {
4
10
  "light": "light"
5
11
  },
@@ -10,12 +16,6 @@
10
16
  "minified": "./light.min.css"
11
17
  }
12
18
  }
13
- },
14
- "core": {
15
- "paths": {
16
- "default": "./core.css",
17
- "minified": "./core.min.css"
18
- }
19
19
  }
20
20
  }
21
21
  }
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const { spawn } = require('node:child_process');
4
4
  const os = require('os');
5
5
  const sass = require('sass');
6
+ const postCSS = require('postcss');
6
7
 
7
8
  const buildScssCommand = require('../build-scss');
8
9
  const { updateParagonThemeOutput } = require('../build-scss');
@@ -21,8 +22,25 @@ jest.mock('ora', () => jest.fn(() => ({
21
22
  start: jest.fn().mockReturnThis(),
22
23
  succeed: jest.fn().mockReturnThis(),
23
24
  fail: jest.fn().mockReturnThis(),
25
+ stop: jest.fn().mockReturnThis(),
24
26
  })));
25
27
 
28
+ const processedResult = {
29
+ css: '.processed { color: black; }',
30
+ map: {
31
+ toString: () => 'minified sourcemap content',
32
+ },
33
+ };
34
+
35
+ // The minify pass is the only `process` call that asks for an external source map.
36
+ const isMinifyCall = (options) => options.map && options.map.inline === false;
37
+
38
+ const mockPostCss = (processImpl) => {
39
+ postCSS.mockImplementation(() => ({ process: jest.fn(processImpl) }));
40
+ };
41
+
42
+ const writtenFiles = () => fs.writeFileSync.mock.calls.map(([filePath]) => filePath);
43
+
26
44
  describe('updateParagonThemeOutput', () => {
27
45
  it('should add core theme correctly', () => {
28
46
  const input = {
@@ -104,6 +122,8 @@ describe('updateParagonThemeOutput', () => {
104
122
  describe('buildScssCommand', () => {
105
123
  beforeEach(() => {
106
124
  jest.clearAllMocks();
125
+ mockPostCss(() => Promise.resolve(processedResult));
126
+ fs.writeFileSync.mockImplementation(() => {});
107
127
  fs.existsSync.mockReturnValue(false);
108
128
  fs.readdirSync.mockReturnValue([
109
129
  { name: 'light', isDirectory: () => true },
@@ -117,7 +137,7 @@ describe('buildScssCommand', () => {
117
137
  });
118
138
  });
119
139
 
120
- it('should compile core and theme stylesheets', () => {
140
+ it('should compile core and theme stylesheets', async () => {
121
141
  const args = [
122
142
  '--corePath=styles/core.scss',
123
143
  '--themesPath=styles/themes',
@@ -125,7 +145,7 @@ describe('buildScssCommand', () => {
125
145
  '--defaultThemeVariants=light',
126
146
  ];
127
147
 
128
- buildScssCommand(args);
148
+ await buildScssCommand(args);
129
149
 
130
150
  expect(sass.compile).toHaveBeenCalledWith(
131
151
  expect.stringContaining('core.scss'),
@@ -160,6 +180,74 @@ describe('buildScssCommand', () => {
160
180
  expect.objectContaining({ withFileTypes: true }),
161
181
  );
162
182
  });
183
+ it('should resolve only after every stylesheet, minified file and source map is written', async () => {
184
+ mockPostCss((css, options) => {
185
+ if (isMinifyCall(options)) {
186
+ return new Promise((resolve) => { setTimeout(() => resolve(processedResult), 20); });
187
+ }
188
+ return Promise.resolve(processedResult);
189
+ });
190
+
191
+ await buildScssCommand(['--outDir=dist']);
192
+
193
+ expect(writtenFiles()).toEqual(expect.arrayContaining(
194
+ ['core', 'light', 'dark'].flatMap((name) => [
195
+ `dist/${name}.css`,
196
+ `dist/${name}.min.css`,
197
+ `dist/${name}.css.map`,
198
+ ]),
199
+ ));
200
+ });
201
+
202
+ it('should list core and every theme variant in theme-urls.json', async () => {
203
+ const files = {};
204
+ fs.writeFileSync.mockImplementation((filePath, content) => { files[filePath] = content; });
205
+ fs.existsSync.mockImplementation((filePath) => filePath in files);
206
+ fs.readFileSync.mockImplementation((filePath) => files[filePath]);
207
+
208
+ await buildScssCommand(['--outDir=dist', '--defaultThemeVariants=light']);
209
+
210
+ const { themeUrls } = JSON.parse(files['dist/theme-urls.json']);
211
+ expect(themeUrls.core.paths.minified).toBe('./core.min.css');
212
+ expect(Object.keys(themeUrls.variants)).toEqual(['light', 'dark']);
213
+ expect(themeUrls.defaults).toEqual({ light: 'light' });
214
+ });
215
+
216
+ it('should reject when Sass compilation fails', async () => {
217
+ sass.compile.mockImplementation(() => { throw new Error('Undefined variable.'); });
218
+
219
+ await expect(buildScssCommand(['--outDir=dist'])).rejects.toThrow('Undefined variable.');
220
+ });
221
+
222
+ it('should reject when PostCSS processing fails', async () => {
223
+ mockPostCss(() => Promise.reject(new Error('PostCSS failed')));
224
+
225
+ await expect(buildScssCommand(['--outDir=dist'])).rejects.toThrow('PostCSS failed');
226
+ });
227
+
228
+ it('should reject when minification fails', async () => {
229
+ mockPostCss((css, options) => (
230
+ isMinifyCall(options) ? Promise.reject(new Error('Minify failed')) : Promise.resolve(processedResult)
231
+ ));
232
+
233
+ await expect(buildScssCommand(['--outDir=dist'])).rejects.toThrow('Minify failed');
234
+ });
235
+
236
+ it('should reject when the output directory does not exist', async () => {
237
+ fs.writeFileSync.mockImplementation((filePath) => {
238
+ throw new Error(`ENOENT: no such file or directory, open '${filePath}'`);
239
+ });
240
+
241
+ await expect(buildScssCommand(['--outDir=missing'])).rejects.toThrow('ENOENT');
242
+ });
243
+
244
+ it('should not build theme variants after the core stylesheet fails', async () => {
245
+ mockPostCss(() => Promise.reject(new Error('PostCSS failed')));
246
+
247
+ await expect(buildScssCommand(['--outDir=dist'])).rejects.toThrow();
248
+
249
+ expect(sass.compile).toHaveBeenCalledTimes(1);
250
+ });
163
251
  });
164
252
 
165
253
  describe('SIGINT handling', () => {
package/lib/build-scss.js CHANGED
@@ -75,6 +75,7 @@ const updateParagonThemeOutput = ({
75
75
  * @param {string} outDir - indicates where to output compiled files
76
76
  * @param {boolean} isThemeVariant - indicates whether the stylesheet is a theme variant
77
77
  * @param {boolean} isDefaultThemeVariant - indicates whether the stylesheet is a default theme variant
78
+ * @returns {Promise<void>} Resolves once all files are written; rejects if any step fails.
78
79
  */
79
80
  const compileAndWriteStyleSheets = ({
80
81
  name,
@@ -90,7 +91,12 @@ const compileAndWriteStyleSheets = ({
90
91
  if (!url.startsWith('~')) {
91
92
  return null;
92
93
  }
93
- return new URL(url.substring(1), `${pathToFileURL('node_modules')}/node_modules`);
94
+ const specifier = url.substring(1);
95
+ // The package name is an optional '@scope/' prefix followed by one more path segment.
96
+ const packageName = specifier.match(/^(?:@[^/]+\/)?[^/]+/)[0];
97
+ const searchPaths = require.resolve.paths(packageName) || [];
98
+ const dir = searchPaths.find((nodeModules) => fs.existsSync(path.join(nodeModules, packageName)));
99
+ return dir ? pathToFileURL(path.join(dir, specifier)) : null;
94
100
  },
95
101
  }],
96
102
  // For now we can't resolve these warnings as we need to upgrade our 'bootstrap' dependency to do so:
@@ -104,17 +110,17 @@ const compileAndWriteStyleSheets = ({
104
110
  ];
105
111
 
106
112
  const postCSSCompilation = ora(`Compilation for ${capitalize(name)} stylesheet...`).start();
107
- postCSS(commonPostCssPlugins)
113
+ return postCSS(commonPostCssPlugins)
108
114
  .process(compiledStyleSheet.css, { from: stylesPath, map: false })
109
115
  .then((result) => {
110
116
  postCSSCompilation.succeed(`Successfully compiled ${capitalize(name)} theme stylesheet`);
111
117
  fs.writeFileSync(`${outDir}/${name}.css`, result.css);
112
- postCSS([postCSSMinify()])
113
- .process(result.css, { from: `${name}.css`, map: { inline: false } })
114
- .then((minifiedResult) => {
115
- fs.writeFileSync(`${outDir}/${name}.css.map`, minifiedResult.map.toString());
116
- fs.writeFileSync(`${outDir}/${name}.min.css`, minifiedResult.css);
117
- });
118
+ return postCSS([postCSSMinify()])
119
+ .process(result.css, { from: `${name}.css`, map: { inline: false } });
120
+ })
121
+ .then((minifiedResult) => {
122
+ fs.writeFileSync(`${outDir}/${name}.css.map`, minifiedResult.map.toString());
123
+ fs.writeFileSync(`${outDir}/${name}.min.css`, minifiedResult.css);
118
124
 
119
125
  const hasExistingParagonThemeOutput = fs.existsSync(`${outDir}/${paragonThemeOutputFilename}`);
120
126
  let paragonThemeOutput;
@@ -142,7 +148,11 @@ const compileAndWriteStyleSheets = ({
142
148
  ora().succeed(chalk.underline.bold.green(`Successfully built stylesheet for ${capitalize(name)} theme!\n`));
143
149
  })
144
150
  .catch((error) => {
151
+ if (postCSSCompilation.isSpinning) {
152
+ postCSSCompilation.stop();
153
+ }
145
154
  ora().fail(chalk.bold(`Failed to build stylesheets for ${capitalize(name)}: ${error.message}`));
155
+ throw error;
146
156
  });
147
157
  };
148
158
 
@@ -151,7 +161,7 @@ const compileAndWriteStyleSheets = ({
151
161
  *
152
162
  * @param {Array<string>} commandArgs - Command line arguments for building SCSS stylesheets.
153
163
  */
154
- function buildScssCommand(commandArgs) {
164
+ async function buildScssCommand(commandArgs) {
155
165
  const defaultArgs = {
156
166
  corePath: path.resolve(process.cwd(), 'styles/scss/core/core.scss'),
157
167
  excludeCore: false,
@@ -170,7 +180,7 @@ function buildScssCommand(commandArgs) {
170
180
 
171
181
  // Core CSS
172
182
  if (!excludeCore) {
173
- compileAndWriteStyleSheets({
183
+ await compileAndWriteStyleSheets({
174
184
  name: 'core',
175
185
  stylesPath: corePath,
176
186
  outDir,
@@ -181,8 +191,10 @@ function buildScssCommand(commandArgs) {
181
191
  const themeDirs = fs.readdirSync(themesPath, { withFileTypes: true })
182
192
  .filter((item) => item.isDirectory());
183
193
 
194
+ // Built one at a time so the first failure stops the build.
184
195
  for (const themeDir of themeDirs) {
185
- compileAndWriteStyleSheets({
196
+ // eslint-disable-next-line no-await-in-loop
197
+ await compileAndWriteStyleSheets({
186
198
  name: themeDir.name,
187
199
  stylesPath: `${themesPath}/${themeDir.name}/index.css`,
188
200
  outDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "23.23.0",
3
+ "version": "23.23.2",
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;