@axinom/mosaic-ui 0.66.0-rc.2 → 0.66.0-rc.20

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.
Files changed (122) hide show
  1. package/dist/components/DynamicDataList/DynamicListHeader/DynamicListHeader.d.ts.map +1 -1
  2. package/dist/components/Explorer/BulkEdit/FormFieldsConfigConverter.d.ts.map +1 -1
  3. package/dist/components/FieldSelection/FieldSelection.d.ts.map +1 -1
  4. package/dist/components/Filters/Filter/Filter.d.ts.map +1 -1
  5. package/dist/components/Filters/Filters.model.d.ts +5 -0
  6. package/dist/components/Filters/Filters.model.d.ts.map +1 -1
  7. package/dist/components/Filters/SelectionTypes/DateTimeFilter/DateTimeFilter.d.ts +2 -0
  8. package/dist/components/Filters/SelectionTypes/DateTimeFilter/DateTimeFilter.d.ts.map +1 -1
  9. package/dist/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.d.ts +2 -0
  10. package/dist/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.d.ts.map +1 -1
  11. package/dist/components/Filters/SelectionTypes/MultiOptionFilter/MultiOptionFilter.d.ts +2 -0
  12. package/dist/components/Filters/SelectionTypes/MultiOptionFilter/MultiOptionFilter.d.ts.map +1 -1
  13. package/dist/components/Filters/SelectionTypes/NumericTextFilter/NumericTextFilter.d.ts +2 -0
  14. package/dist/components/Filters/SelectionTypes/NumericTextFilter/NumericTextFilter.d.ts.map +1 -1
  15. package/dist/components/Filters/SelectionTypes/OptionsFilter/OptionsFilter.d.ts +2 -0
  16. package/dist/components/Filters/SelectionTypes/OptionsFilter/OptionsFilter.d.ts.map +1 -1
  17. package/dist/components/Filters/SelectionTypes/SearcheableOptionsFilter/SearcheableOptionsFilter.d.ts +2 -0
  18. package/dist/components/Filters/SelectionTypes/SearcheableOptionsFilter/SearcheableOptionsFilter.d.ts.map +1 -1
  19. package/dist/components/FormElements/Radio/Radio.d.ts.map +1 -1
  20. package/dist/components/FormElements/ToggleButton/ToggleButton.d.ts.map +1 -1
  21. package/dist/components/Hub/Tile/Tile.d.ts.map +1 -1
  22. package/dist/components/Icons/Icons.d.ts +4 -9
  23. package/dist/components/Icons/Icons.d.ts.map +1 -1
  24. package/dist/components/LandingPageTiles/TileLarge/TileLarge.d.ts.map +1 -1
  25. package/dist/components/LandingPageTiles/TileSmall/TileSmall.d.ts.map +1 -1
  26. package/dist/components/List/ListCheckBox/ListCheckBox.d.ts.map +1 -1
  27. package/dist/components/List/ListHeader/ColumnLabel/ColumnLabel.d.ts.map +1 -1
  28. package/dist/components/List/ListHeader/ListHeader.d.ts.map +1 -1
  29. package/dist/components/List/ListRow/ListRow.d.ts.map +1 -1
  30. package/dist/components/List/ListRow/ListRowCell/ListRowCell.d.ts +15 -0
  31. package/dist/components/List/ListRow/ListRowCell/ListRowCell.d.ts.map +1 -0
  32. package/dist/components/List/ListRow/ListRowCell/renderData.d.ts +9 -0
  33. package/dist/components/List/ListRow/ListRowCell/renderData.d.ts.map +1 -0
  34. package/dist/components/List/ListRow/Renderers/TagsRenderer/TagsRenderer.d.ts.map +1 -1
  35. package/dist/components/Loaders/ImageLoader/ImageLoader.d.ts.map +1 -1
  36. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.d.ts.map +1 -1
  37. package/dist/components/VisualElements/ImgElement.d.ts +50 -0
  38. package/dist/components/VisualElements/ImgElement.d.ts.map +1 -0
  39. package/dist/components/VisualElements/SvgElement.d.ts +14 -0
  40. package/dist/components/VisualElements/SvgElement.d.ts.map +1 -0
  41. package/dist/components/VisualElements/index.d.ts +3 -0
  42. package/dist/components/VisualElements/index.d.ts.map +1 -0
  43. package/dist/components/index.d.ts +1 -0
  44. package/dist/components/index.d.ts.map +1 -1
  45. package/dist/helpers/idleCallbackHelpers.d.ts +42 -0
  46. package/dist/helpers/idleCallbackHelpers.d.ts.map +1 -0
  47. package/dist/helpers/index.d.ts +1 -0
  48. package/dist/helpers/index.d.ts.map +1 -1
  49. package/dist/hooks/useResize/ResizeIndicator.d.ts +8 -0
  50. package/dist/hooks/useResize/ResizeIndicator.d.ts.map +1 -0
  51. package/dist/hooks/useResize/useResize.d.ts +5 -2
  52. package/dist/hooks/useResize/useResize.d.ts.map +1 -1
  53. package/dist/index.es.js +4 -4
  54. package/dist/index.es.js.map +1 -1
  55. package/dist/index.js +4 -4
  56. package/dist/index.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/components/DynamicDataList/DynamicListHeader/DynamicListHeader.spec.tsx +2 -0
  59. package/src/components/DynamicDataList/DynamicListHeader/DynamicListHeader.tsx +62 -50
  60. package/src/components/Explorer/BulkEdit/FormFieldsConfigConverter.tsx +5 -21
  61. package/src/components/Explorer/Explorer.stories.tsx +17 -0
  62. package/src/components/FieldSelection/FieldSelection.scss +4 -0
  63. package/src/components/FieldSelection/FieldSelection.tsx +1 -0
  64. package/src/components/Filters/Filter/Filter.scss +34 -15
  65. package/src/components/Filters/Filter/Filter.spec.tsx +1 -1
  66. package/src/components/Filters/Filter/Filter.tsx +46 -34
  67. package/src/components/Filters/Filters.model.ts +6 -0
  68. package/src/components/Filters/SelectionTypes/DateTimeFilter/DateTimeFilter.tsx +6 -1
  69. package/src/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.tsx +4 -0
  70. package/src/components/Filters/SelectionTypes/MultiOptionFilter/MultiOptionFilter.tsx +9 -1
  71. package/src/components/Filters/SelectionTypes/NumericTextFilter/NumericTextFilter.tsx +5 -0
  72. package/src/components/Filters/SelectionTypes/OptionsFilter/OptionsFilter.scss +6 -10
  73. package/src/components/Filters/SelectionTypes/OptionsFilter/OptionsFilter.tsx +8 -0
  74. package/src/components/Filters/SelectionTypes/SearcheableOptionsFilter/SearcheableOptionsFilter.tsx +6 -1
  75. package/src/components/FormElements/Radio/Radio.tsx +3 -2
  76. package/src/components/FormElements/Select/Select.scss +11 -6
  77. package/src/components/FormElements/ToggleButton/ToggleButton.tsx +32 -27
  78. package/src/components/Hub/Hub.stories.tsx +3 -2
  79. package/src/components/Hub/Tile/Tile.spec.tsx +7 -2
  80. package/src/components/Hub/Tile/Tile.tsx +2 -1
  81. package/src/components/Icons/Icons.scss +1 -0
  82. package/src/components/Icons/Icons.spec.tsx +90 -41
  83. package/src/components/Icons/Icons.tsx +357 -765
  84. package/src/components/InfoTooltip/InfoTooltip.scss +1 -1
  85. package/src/components/InlineMenu/InlineMenu.scss +1 -1
  86. package/src/components/LandingPageTiles/LandingPageTiles.stories.tsx +3 -2
  87. package/src/components/LandingPageTiles/TileLarge/TileLarge.spec.tsx +5 -1
  88. package/src/components/LandingPageTiles/TileLarge/TileLarge.tsx +2 -1
  89. package/src/components/LandingPageTiles/TileSmall/TileSmall.spec.tsx +7 -2
  90. package/src/components/LandingPageTiles/TileSmall/TileSmall.tsx +2 -1
  91. package/src/components/List/ListCheckBox/ListCheckBox.tsx +1 -0
  92. package/src/components/List/ListHeader/ColumnLabel/ColumnLabel.spec.tsx +6 -6
  93. package/src/components/List/ListHeader/ColumnLabel/ColumnLabel.tsx +10 -13
  94. package/src/components/List/ListHeader/ListHeader.scss +0 -1
  95. package/src/components/List/ListHeader/ListHeader.spec.tsx +2 -0
  96. package/src/components/List/ListHeader/ListHeader.tsx +57 -51
  97. package/src/components/List/ListRow/ListRow.scss +0 -27
  98. package/src/components/List/ListRow/ListRow.spec.tsx +10 -8
  99. package/src/components/List/ListRow/ListRow.tsx +20 -152
  100. package/src/components/List/ListRow/ListRowCell/ListRowCell.scss +26 -0
  101. package/src/components/List/ListRow/ListRowCell/ListRowCell.spec.tsx +491 -0
  102. package/src/components/List/ListRow/ListRowCell/ListRowCell.tsx +57 -0
  103. package/src/components/List/ListRow/ListRowCell/renderData.tsx +124 -0
  104. package/src/components/List/ListRow/Renderers/TagsRenderer/TagsRenderer.scss +2 -1
  105. package/src/components/List/ListRow/Renderers/TagsRenderer/TagsRenderer.spec.tsx +187 -104
  106. package/src/components/List/ListRow/Renderers/TagsRenderer/TagsRenderer.tsx +134 -80
  107. package/src/components/Loaders/ImageLoader/ImageLoader.spec.tsx +13 -14
  108. package/src/components/Loaders/ImageLoader/ImageLoader.tsx +5 -3
  109. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.tsx +13 -2
  110. package/src/components/Utils/Postgraphile/CreateConnectionRenderer.spec.ts +22 -75
  111. package/src/components/VisualElements/ImgElement.spec.tsx +92 -0
  112. package/src/components/VisualElements/ImgElement.tsx +72 -0
  113. package/src/components/VisualElements/SvgElement.spec.tsx +160 -0
  114. package/src/components/VisualElements/SvgElement.tsx +40 -0
  115. package/src/components/VisualElements/index.ts +7 -0
  116. package/src/components/index.ts +1 -0
  117. package/src/helpers/idleCallbackHelpers.ts +66 -0
  118. package/src/helpers/index.ts +5 -0
  119. package/src/hooks/useResize/ResizeIndicator.scss +7 -0
  120. package/src/hooks/useResize/ResizeIndicator.tsx +39 -0
  121. package/src/hooks/useResize/{useResize.ts → useResize.tsx} +38 -6
  122. package/src/styles/variables.scss +7 -6
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { shallow } from 'enzyme';
2
+ import { mount, shallow } from 'enzyme';
3
3
  import React, { ReactNode, SyntheticEvent } from 'react';
4
4
  import ContentLoader from 'react-content-loader';
5
5
  import { act } from 'react-dom/test-utils';
@@ -18,7 +18,7 @@ describe('ImageLoader', () => {
18
18
  const mockWidth = 'test-width';
19
19
  const mockAlt = 'test-alt';
20
20
 
21
- const wrapper = shallow(
21
+ const wrapper = mount(
22
22
  <ImageLoader
23
23
  imgSrc={mockSrc}
24
24
  alt={mockAlt}
@@ -39,7 +39,7 @@ describe('ImageLoader', () => {
39
39
  });
40
40
 
41
41
  it('renders the loading animation while an image is loading', () => {
42
- const wrapper = shallow(<ImageLoader imgSrc="" />);
42
+ const wrapper = mount(<ImageLoader imgSrc="" />);
43
43
 
44
44
  const loader = wrapper.find(ContentLoader);
45
45
  const imgDisplay = wrapper.find('img').prop('style')?.display;
@@ -49,9 +49,10 @@ describe('ImageLoader', () => {
49
49
  });
50
50
 
51
51
  it('renders the image after loading has completed', () => {
52
- const wrapper = shallow(<ImageLoader imgSrc="" />);
52
+ const wrapper = mount(<ImageLoader imgSrc="" />);
53
53
 
54
54
  wrapper.find('img').prop('onLoad')!({} as SyntheticEvent);
55
+ wrapper.update();
55
56
 
56
57
  const loader = wrapper.find(ContentLoader);
57
58
  const imgDisplay = wrapper.find('img').prop('style')?.display;
@@ -63,7 +64,7 @@ describe('ImageLoader', () => {
63
64
  it('emits onLoad callback with img src after successful load', () => {
64
65
  const spy = jest.fn();
65
66
  const mockUrl = 'mock-url';
66
- const wrapper = shallow(<ImageLoader imgSrc={mockUrl} onLoad={spy} />);
67
+ const wrapper = mount(<ImageLoader imgSrc={mockUrl} onLoad={spy} />);
67
68
 
68
69
  wrapper.find('img').prop('onLoad')!({} as SyntheticEvent);
69
70
 
@@ -77,9 +78,7 @@ describe('ImageLoader', () => {
77
78
  };
78
79
  const spy = jest.fn();
79
80
  const mockUrl = 'mock-url';
80
- const wrapper = shallow(
81
- <ImageLoader imgSrc={mockUrl} onImageClick={spy} />,
82
- );
81
+ const wrapper = mount(<ImageLoader imgSrc={mockUrl} onImageClick={spy} />);
83
82
 
84
83
  const image = wrapper.find('img');
85
84
 
@@ -93,9 +92,10 @@ describe('ImageLoader', () => {
93
92
  });
94
93
 
95
94
  it('renders the fallback background color when loading has failed', () => {
96
- const wrapper = shallow(<ImageLoader imgSrc="" />);
95
+ const wrapper = mount(<ImageLoader imgSrc="" />);
97
96
 
98
97
  wrapper.find('img').prop('onError')!({} as SyntheticEvent);
98
+ wrapper.update();
99
99
 
100
100
  const loader = wrapper.find(ContentLoader);
101
101
  const fallbackContainer = wrapper.find('.container').at(1);
@@ -107,11 +107,12 @@ describe('ImageLoader', () => {
107
107
 
108
108
  it('renders a fallback image when loading has failed', () => {
109
109
  const mockFallbackUrl = 'mock-url';
110
- const wrapper = shallow(
110
+ const wrapper = mount(
111
111
  <ImageLoader imgSrc="" fallbackSrc={mockFallbackUrl} />,
112
112
  );
113
113
 
114
114
  wrapper.find('img').prop('onError')!({} as SyntheticEvent);
115
+ wrapper.update();
115
116
 
116
117
  const loader = wrapper.find(ContentLoader);
117
118
  const images = wrapper.find('img');
@@ -127,7 +128,7 @@ describe('ImageLoader', () => {
127
128
  it('emits onError callback with img src after load failure', () => {
128
129
  const spy = jest.fn();
129
130
  const mockUrl = 'mock-url';
130
- const wrapper = shallow(<ImageLoader imgSrc={mockUrl} onError={spy} />);
131
+ const wrapper = mount(<ImageLoader imgSrc={mockUrl} onError={spy} />);
131
132
 
132
133
  wrapper.find('img').prop('onError')!({} as SyntheticEvent);
133
134
 
@@ -142,9 +143,7 @@ describe('ImageLoader', () => {
142
143
  <circle r="50" />
143
144
  </svg>
144
145
  );
145
- const wrapper = shallow(
146
- <ImageLoader imgSrc="" loadingSkeleton={mockSVG} />,
147
- );
146
+ const wrapper = mount(<ImageLoader imgSrc="" loadingSkeleton={mockSVG} />);
148
147
 
149
148
  const svg = wrapper.find(`#${mockId}`);
150
149
 
@@ -2,6 +2,7 @@ import clsx from 'clsx';
2
2
  import React, { ReactNode, useCallback, useEffect, useState } from 'react';
3
3
  import ContentLoader from 'react-content-loader';
4
4
  import { noop } from '../../../helpers/utils';
5
+ import { ImgElement } from '../../VisualElements/ImgElement';
5
6
  import { SquareOutlineSkeleton } from '../skeletons';
6
7
  import classes from './ImageLoader.scss';
7
8
 
@@ -140,7 +141,7 @@ export const ImageLoader: React.FC<ImageLoaderProps> = ({
140
141
  )}
141
142
  <div className={classes.imageContainer}>
142
143
  {state !== ImageLoaderState.Failed && imgSrc !== undefined && (
143
- <img
144
+ <ImgElement
144
145
  src={imgSrc}
145
146
  height={imgHeight}
146
147
  width={imgWidth}
@@ -149,7 +150,7 @@ export const ImageLoader: React.FC<ImageLoaderProps> = ({
149
150
  objectFit: 'contain',
150
151
  maxWidth: '100%',
151
152
  }}
152
- alt={alt}
153
+ alt={alt ? alt : 'Loaded content image'}
153
154
  onLoad={onLoadHandler}
154
155
  onError={onErrorHandler}
155
156
  onClick={onImageClick}
@@ -159,11 +160,12 @@ export const ImageLoader: React.FC<ImageLoaderProps> = ({
159
160
  )}
160
161
  {state === ImageLoaderState.Failed &&
161
162
  (fallbackSrc ? (
162
- <img
163
+ <ImgElement
163
164
  className={classes.fallBackImage}
164
165
  src={String(fallbackSrc)}
165
166
  height={imgHeight}
166
167
  width={imgWidth}
168
+ alt="Image unavailable"
167
169
  />
168
170
  ) : (
169
171
  <div
@@ -9,6 +9,7 @@ import {
9
9
  useConfirmationDelay,
10
10
  } from '../../ConfirmDialog';
11
11
  import { IconName, Icons } from '../../Icons';
12
+ import { ImgElement } from '../../VisualElements';
12
13
  import {
13
14
  PageHeaderActionProps,
14
15
  PageHeaderActionType,
@@ -142,7 +143,12 @@ const PageHeaderJSAction: React.FC<PageHeaderJsActionProps> = ({
142
143
  <div className={classes.icon}>
143
144
  {!confirmation &&
144
145
  (typeof icon === 'string' ? (
145
- <img src={icon} alt={imgAlt} />
146
+ <ImgElement
147
+ src={icon}
148
+ {...(imgAlt
149
+ ? { alt: imgAlt ?? `${label} icon` }
150
+ : { decorative: true })}
151
+ />
146
152
  ) : (
147
153
  <Icons icon={icon} className={classes.pageHeaderActionsIcons} />
148
154
  ))}
@@ -208,7 +214,12 @@ const PageHeaderNavigationAction: React.FC<PageHeaderNavigationActionProps> = ({
208
214
  >
209
215
  <div className={classes.icon}>
210
216
  {typeof headerIcon === 'string' ? (
211
- <img src={headerIcon} alt={imgAlt} />
217
+ <ImgElement
218
+ src={headerIcon}
219
+ {...(imgAlt
220
+ ? { alt: imgAlt ?? `${label} icon` }
221
+ : { decorative: true })}
222
+ />
212
223
  ) : (
213
224
  <Icons icon={headerIcon} className={classes.pageHeaderActionsIcons} />
214
225
  )}
@@ -1,14 +1,5 @@
1
- import { TagsRenderer } from '../../List';
2
1
  import { createConnectionRenderer } from './CreateConnectionRenderer';
3
2
 
4
- jest.mock('../../List', () => ({
5
- TagsRenderer: jest.fn(),
6
- }));
7
-
8
- const mockTagsRenderer = TagsRenderer as jest.MockedFunction<
9
- typeof TagsRenderer
10
- >;
11
-
12
3
  interface TestConnection {
13
4
  nodes: { id: string; name: string }[];
14
5
  }
@@ -18,70 +9,7 @@ interface StringConnection {
18
9
  }
19
10
 
20
11
  describe('createConnectionRenderer', () => {
21
- beforeEach(() => {
22
- jest.clearAllMocks();
23
- });
24
-
25
- describe('with renderAsTags = true (default)', () => {
26
- it('should call TagsRenderer with mapped values when renderAsTags is true', () => {
27
- const mockReturnValue = 'Mocked Tags JSX Element';
28
- mockTagsRenderer.mockReturnValue(mockReturnValue as any);
29
-
30
- const connection: TestConnection = {
31
- nodes: [
32
- { id: '1', name: 'Item 1' },
33
- { id: '2', name: 'Item 2' },
34
- ],
35
- };
36
-
37
- const selector = (item: { id: string; name: string }) => item.name;
38
- const renderer = createConnectionRenderer<TestConnection>(selector);
39
- const result = renderer(connection);
40
-
41
- expect(mockTagsRenderer).toHaveBeenCalledWith(['Item 1', 'Item 2']);
42
- expect(result).toBe(mockReturnValue);
43
- });
44
-
45
- it('should throw error when nodes is undefined', () => {
46
- const connection = { nodes: undefined } as unknown as TestConnection;
47
- const selector = (item: { id: string; name: string }) => item.name;
48
- const renderer = createConnectionRenderer<TestConnection>(selector);
49
-
50
- expect(() => renderer(connection)).toThrow();
51
- expect(mockTagsRenderer).not.toHaveBeenCalled();
52
- });
53
-
54
- it('should throw error when value is null', () => {
55
- const selector = (item: { id: string; name: string }) => item.name;
56
- const renderer = createConnectionRenderer<TestConnection>(selector);
57
-
58
- expect(() => renderer(null)).toThrow();
59
- expect(mockTagsRenderer).not.toHaveBeenCalled();
60
- });
61
-
62
- it('should throw error when value is undefined', () => {
63
- const selector = (item: { id: string; name: string }) => item.name;
64
- const renderer = createConnectionRenderer<TestConnection>(selector);
65
-
66
- expect(() => renderer(undefined)).toThrow();
67
- expect(mockTagsRenderer).not.toHaveBeenCalled();
68
- });
69
-
70
- it('should call TagsRenderer with empty array when nodes is empty', () => {
71
- const mockReturnValue = 'Empty Tags JSX Element';
72
- mockTagsRenderer.mockReturnValue(mockReturnValue as any);
73
-
74
- const connection: TestConnection = { nodes: [] };
75
- const selector = (item: { id: string; name: string }) => item.name;
76
- const renderer = createConnectionRenderer<TestConnection>(selector);
77
- const result = renderer(connection);
78
-
79
- expect(mockTagsRenderer).toHaveBeenCalledWith([]);
80
- expect(result).toBe(mockReturnValue);
81
- });
82
- });
83
-
84
- describe('with renderAsTags = false', () => {
12
+ describe('basic functionality', () => {
85
13
  it('should return comma-separated string using selector', () => {
86
14
  const connection: TestConnection = {
87
15
  nodes: [
@@ -98,7 +26,6 @@ describe('createConnectionRenderer', () => {
98
26
  );
99
27
  const result = renderer(connection);
100
28
 
101
- expect(mockTagsRenderer).not.toHaveBeenCalled();
102
29
  expect(result).toBe('Item 1, Item 2, Item 3');
103
30
  });
104
31
 
@@ -169,7 +96,7 @@ describe('createConnectionRenderer', () => {
169
96
  expect(result).toBe('100, 200');
170
97
  });
171
98
 
172
- it('should throw error when connection.nodes is undefined and renderAsTags is false', () => {
99
+ it('should throw error when connection.nodes is undefined', () => {
173
100
  const connection = { nodes: undefined } as unknown as TestConnection;
174
101
  const selector = (item: { id: string; name: string }) => item.name;
175
102
  const renderer = createConnectionRenderer<TestConnection>(
@@ -179,6 +106,26 @@ describe('createConnectionRenderer', () => {
179
106
 
180
107
  expect(() => renderer(connection)).toThrow();
181
108
  });
109
+
110
+ it('should throw error when value is null', () => {
111
+ const selector = (item: { id: string; name: string }) => item.name;
112
+ const renderer = createConnectionRenderer<TestConnection>(
113
+ selector,
114
+ false,
115
+ );
116
+
117
+ expect(() => renderer(null)).toThrow();
118
+ });
119
+
120
+ it('should throw error when value is undefined', () => {
121
+ const selector = (item: { id: string; name: string }) => item.name;
122
+ const renderer = createConnectionRenderer<TestConnection>(
123
+ selector,
124
+ false,
125
+ );
126
+
127
+ expect(() => renderer(undefined)).toThrow();
128
+ });
182
129
  });
183
130
 
184
131
  describe('edge cases', () => {
@@ -0,0 +1,92 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { ImgElement } from './ImgElement';
4
+
5
+ describe('ImgElement', () => {
6
+ it('renders meaningful image with alt text', () => {
7
+ const alt = 'Test image';
8
+ const src = '/test.jpg';
9
+ const wrapper = shallow(<ImgElement src={src} alt={alt} />);
10
+
11
+ const img = wrapper.find('img');
12
+ expect(img.prop('src')).toBe(src);
13
+ expect(img.prop('alt')).toBe(alt);
14
+ expect(img.prop('aria-hidden')).toBeUndefined();
15
+ expect(img.prop('role')).toBeUndefined();
16
+ });
17
+
18
+ it('renders decorative image with accessibility attributes', () => {
19
+ const src = '/decorative.jpg';
20
+ const wrapper = shallow(<ImgElement src={src} decorative={true} />);
21
+
22
+ const img = wrapper.find('img');
23
+ expect(img.prop('src')).toBe(src);
24
+ expect(img.prop('alt')).toBe('');
25
+ expect(img.prop('aria-hidden')).toBe('true');
26
+ expect(img.prop('role')).toBe('presentation');
27
+ });
28
+
29
+ it('forwards additional HTML img attributes for meaningful images', () => {
30
+ const width = 100;
31
+ const height = 200;
32
+ const className = 'test-class';
33
+
34
+ const wrapper = shallow(
35
+ <ImgElement
36
+ src="/test.jpg"
37
+ alt="Test image"
38
+ width={width}
39
+ height={height}
40
+ className={className}
41
+ />,
42
+ );
43
+
44
+ const img = wrapper.find('img');
45
+ expect(img.prop('width')).toBe(width);
46
+ expect(img.prop('height')).toBe(height);
47
+ expect(img.prop('className')).toBe(className);
48
+ });
49
+
50
+ it('forwards additional HTML img attributes for decorative images', () => {
51
+ const width = 50;
52
+ const height = 60;
53
+ const className = 'icon';
54
+
55
+ const wrapper = shallow(
56
+ <ImgElement
57
+ src="/decorative.jpg"
58
+ decorative={true}
59
+ width={width}
60
+ height={height}
61
+ className={className}
62
+ />,
63
+ );
64
+
65
+ const img = wrapper.find('img');
66
+ expect(img.prop('width')).toBe(width);
67
+ expect(img.prop('height')).toBe(height);
68
+ expect(img.prop('className')).toBe(className);
69
+ });
70
+
71
+ it('uses meaningful image behavior by default', () => {
72
+ const alt = 'Default behavior';
73
+ const wrapper = shallow(<ImgElement src="/default.jpg" alt={alt} />);
74
+
75
+ const img = wrapper.find('img');
76
+ expect(img.prop('alt')).toBe(alt);
77
+ expect(img.prop('aria-hidden')).toBeUndefined();
78
+ expect(img.prop('role')).toBeUndefined();
79
+ });
80
+
81
+ it('renders with decorative=false explicitly', () => {
82
+ const alt = 'Explicit meaningful';
83
+ const wrapper = shallow(
84
+ <ImgElement src="/explicit.jpg" alt={alt} decorative={false} />,
85
+ );
86
+
87
+ const img = wrapper.find('img');
88
+ expect(img.prop('alt')).toBe(alt);
89
+ expect(img.prop('aria-hidden')).toBeUndefined();
90
+ expect(img.prop('role')).toBeUndefined();
91
+ });
92
+ });
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+
3
+ type BaseImgElementProps = Omit<
4
+ React.ImgHTMLAttributes<HTMLImageElement>,
5
+ 'alt'
6
+ >;
7
+
8
+ /** Props for decorative images - alt text not needed or allowed */
9
+ export interface DecorativeImageProps {
10
+ /** Whether the image is decorative (sets aria-hidden="true", alt="", and role="presentation") */
11
+ decorative: true;
12
+ /** Alt text - not needed when decorative */
13
+ alt?: never;
14
+ }
15
+
16
+ /** Props for meaningful images - alt text is required */
17
+ export interface MeaningfulImageProps {
18
+ /** Whether the image is decorative (sets aria-hidden="true", alt="", and role="presentation") */
19
+ decorative?: false;
20
+ /** Alt text - required for non-decorative images */
21
+ alt: string;
22
+ }
23
+
24
+ /** Union type for all image accessibility configurations */
25
+ export type ImageAccessibilityProps =
26
+ | DecorativeImageProps
27
+ | MeaningfulImageProps;
28
+
29
+ export type ImgElementProps = BaseImgElementProps & ImageAccessibilityProps;
30
+
31
+ /**
32
+ * Centralized image component with proper accessibility handling.
33
+ * Provides consistent image rendering across the application with automatic
34
+ * accessibility attributes based on the decorative flag.
35
+ *
36
+ * For non-decorative images, alt text is required to ensure accessibility.
37
+ * For decorative images, alt text is automatically set to empty string.
38
+ *
39
+ * @example Basic image with required alt text
40
+ * <ImgElement
41
+ * src="/path/to/image.jpg"
42
+ * alt="Description of the image"
43
+ * />
44
+ *
45
+ * @example Decorative image (alt not required or allowed)
46
+ * <ImgElement
47
+ * src="/path/to/decorative.jpg"
48
+ * decorative={true}
49
+ * />
50
+ *
51
+ * @example Navigation icon
52
+ * <ImgElement
53
+ * src="/icons/menu.svg"
54
+ * decorative={true}
55
+ * width={24}
56
+ * height={24}
57
+ * />
58
+ */
59
+ export const ImgElement: React.FC<ImgElementProps> = ({
60
+ decorative = false,
61
+ ...imgProps
62
+ }) => {
63
+ const accessibilityProps = decorative
64
+ ? {
65
+ 'aria-hidden': 'true' as const,
66
+ alt: '',
67
+ role: 'presentation' as const,
68
+ }
69
+ : {};
70
+
71
+ return <img {...accessibilityProps} {...imgProps} />;
72
+ };
@@ -0,0 +1,160 @@
1
+ import { mount, shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { SvgElement, SvgElementProps } from './SvgElement';
4
+
5
+ describe('SvgElement', () => {
6
+ it('renders the component without crashing', () => {
7
+ const wrapper = shallow(<SvgElement />);
8
+
9
+ expect(wrapper).toBeTruthy();
10
+ });
11
+
12
+ it('renders with default viewBox', () => {
13
+ const wrapper = mount(<SvgElement />);
14
+ const svg = wrapper.find('svg');
15
+
16
+ expect(svg.prop('viewBox')).toBe('0 0 40 40');
17
+ });
18
+
19
+ it('renders with custom viewBox', () => {
20
+ const customViewBox = '0 0 24 24';
21
+ const wrapper = mount(<SvgElement viewBox={customViewBox} />);
22
+ const svg = wrapper.find('svg');
23
+
24
+ expect(svg.prop('viewBox')).toBe(customViewBox);
25
+ });
26
+
27
+ it('passes down className to svg element', () => {
28
+ const testClass = 'custom-icon-class';
29
+ const wrapper = mount(<SvgElement className={testClass} />);
30
+ const svg = wrapper.find('svg');
31
+
32
+ expect(svg.hasClass(testClass)).toBe(true);
33
+ });
34
+
35
+ it('renders children inside svg', () => {
36
+ const d = 'M10 10L20 20';
37
+ const cx = 15;
38
+ const cy = 15;
39
+ const r = 5;
40
+ const wrapper = mount(
41
+ <SvgElement>
42
+ <path d={d} />
43
+ <circle cx={cx} cy={cy} r={r} />
44
+ </SvgElement>,
45
+ );
46
+ const circle = wrapper.find('circle');
47
+
48
+ expect(wrapper.find('path')).toHaveLength(1);
49
+ expect(wrapper.find('circle')).toHaveLength(1);
50
+ expect(wrapper.find('path').prop('d')).toBe(d);
51
+ expect(circle.prop('cx')).toBe(cx);
52
+ expect(circle.prop('cy')).toBe(cy);
53
+ expect(circle.prop('r')).toBe(r);
54
+ });
55
+
56
+ it('renders as decorative icon by default', () => {
57
+ const wrapper = mount(<SvgElement />);
58
+ const svg = wrapper.find('svg');
59
+
60
+ expect(svg.prop('role')).toBe('presentation');
61
+ expect(svg.prop('aria-hidden')).toBe('true');
62
+ expect(svg.prop('aria-label')).toBeUndefined();
63
+ });
64
+
65
+ it('renders as semantic icon when aria-label is provided', () => {
66
+ const ariaLabel = 'Custom icon description';
67
+ const wrapper = mount(<SvgElement aria-label={ariaLabel} />);
68
+ const svg = wrapper.find('svg');
69
+
70
+ expect(svg.prop('role')).toBe('img');
71
+ expect(svg.prop('aria-hidden')).toBeUndefined();
72
+ expect(svg.prop('aria-label')).toBe(ariaLabel);
73
+ });
74
+
75
+ it('renders as semantic icon when title is provided', () => {
76
+ const title = 'Icon tooltip';
77
+ const wrapper = mount(<SvgElement title={title} />);
78
+ const svg = wrapper.find('svg');
79
+
80
+ expect(svg.prop('role')).toBe('img');
81
+ expect(svg.prop('aria-hidden')).toBeUndefined();
82
+ expect(wrapper.find('title')).toHaveLength(1);
83
+ expect(wrapper.find('title').text()).toBe(title);
84
+ });
85
+
86
+ it('renders as semantic icon when both aria-label and title are provided', () => {
87
+ const ariaLabel = 'Icon description';
88
+ const title = 'Icon tooltip';
89
+ const wrapper = mount(<SvgElement aria-label={ariaLabel} title={title} />);
90
+ const svg = wrapper.find('svg');
91
+
92
+ expect(svg.prop('role')).toBe('img');
93
+ expect(svg.prop('aria-hidden')).toBeUndefined();
94
+ expect(svg.prop('aria-label')).toBe(ariaLabel);
95
+ expect(wrapper.find('title')).toHaveLength(1);
96
+ expect(wrapper.find('title').text()).toBe(title);
97
+ });
98
+
99
+ it('does not render title element when title prop is not provided', () => {
100
+ const wrapper = mount(<SvgElement aria-label="Icon" />);
101
+
102
+ expect(wrapper.find('title')).toHaveLength(0);
103
+ });
104
+
105
+ it('applies default SVG attributes', () => {
106
+ const wrapper = mount(<SvgElement />);
107
+ const svg = wrapper.find('svg');
108
+
109
+ expect(svg.prop('focusable')).toBe('false');
110
+ });
111
+
112
+ it('passes through additional SVG attributes', () => {
113
+ const customProps: SvgElementProps = {
114
+ id: 'custom-id',
115
+ 'data-testid': 'custom-svg',
116
+ fill: 'currentColor',
117
+ stroke: 'red',
118
+ strokeWidth: '2',
119
+ };
120
+
121
+ const wrapper = mount(<SvgElement {...customProps} />);
122
+ const svg = wrapper.find('svg');
123
+
124
+ expect(svg.prop('id')).toBe('custom-id');
125
+ expect(svg.prop('data-testid')).toBe('custom-svg');
126
+ expect(svg.prop('fill')).toBe('currentColor');
127
+ expect(svg.prop('stroke')).toBe('red');
128
+ expect(svg.prop('strokeWidth')).toBe('2');
129
+ });
130
+
131
+ it('allows overriding default attributes', () => {
132
+ const wrapper = mount(
133
+ <SvgElement
134
+ version="2.0"
135
+ xmlns="http://custom-namespace.com"
136
+ focusable="true"
137
+ />,
138
+ );
139
+ const svg = wrapper.find('svg');
140
+
141
+ expect(svg.prop('version')).toBe('2.0');
142
+ expect(svg.prop('xmlns')).toBe('http://custom-namespace.com');
143
+ expect(svg.prop('focusable')).toBe('true');
144
+ });
145
+
146
+ it('prioritizes explicit role over calculated role', () => {
147
+ const wrapper = mount(<SvgElement role="button" aria-label="Click me" />);
148
+ const svg = wrapper.find('svg');
149
+
150
+ expect(svg.prop('role')).toBe('button');
151
+ });
152
+
153
+ it('prioritizes explicit aria-hidden over calculated value', () => {
154
+ const wrapper = mount(<SvgElement aria-hidden="false" />);
155
+ const svg = wrapper.find('svg');
156
+
157
+ expect(svg.prop('aria-hidden')).toBe('false');
158
+ expect(svg.prop('role')).toBe('presentation'); // Still decorative without label/title
159
+ });
160
+ });
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+
3
+ export interface SvgElementProps extends React.SVGAttributes<SVGElement> {
4
+ /** SVG title (tooltip or additional description shown on hover) */
5
+ title?: string;
6
+ }
7
+
8
+ /**
9
+ * Reusable SVG wrapper with accessibility support and default props.
10
+ * @example
11
+ * <SvgElement aria-label="Custom icon" title="Custom tooltip">
12
+ * <path d="..." />
13
+ * </SvgElement>
14
+ */
15
+ export const SvgElement: React.FC<SvgElementProps> = ({
16
+ children,
17
+ className,
18
+ 'aria-label': ariaLabel,
19
+ title,
20
+ viewBox = '0 0 40 40',
21
+ ...svgProps
22
+ }) => {
23
+ // Determine if this is a decorative icon (no accessible label or title)
24
+ const isDecorative = !ariaLabel && !title;
25
+
26
+ return (
27
+ <svg
28
+ className={className}
29
+ viewBox={viewBox}
30
+ role={isDecorative ? 'presentation' : 'img'}
31
+ aria-hidden={isDecorative ? 'true' : undefined}
32
+ aria-label={ariaLabel}
33
+ focusable="false"
34
+ {...svgProps}
35
+ >
36
+ {title && <title>{title}</title>}
37
+ {children}
38
+ </svg>
39
+ );
40
+ };
@@ -0,0 +1,7 @@
1
+ export {
2
+ DecorativeImageProps,
3
+ ImgElement,
4
+ ImgElementProps,
5
+ MeaningfulImageProps,
6
+ } from './ImgElement';
7
+ export { SvgElement, SvgElementProps } from './SvgElement';
@@ -25,4 +25,5 @@ export * from './PageHeader';
25
25
  export * from './ProgressBar';
26
26
  export * from './Tabs';
27
27
  export * from './Utils';
28
+ export * from './VisualElements';
28
29
  export * from './models';