@axinom/mosaic-ui 0.32.0-rc.1 → 0.32.0-rc.11

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 (100) hide show
  1. package/dist/components/Actions/Action/Action.d.ts.map +1 -1
  2. package/dist/components/Actions/Actions.models.d.ts +4 -16
  3. package/dist/components/Actions/Actions.models.d.ts.map +1 -1
  4. package/dist/components/Buttons/Button/Button.d.ts +9 -10
  5. package/dist/components/Buttons/Button/Button.d.ts.map +1 -1
  6. package/dist/components/Buttons/Button/Button.model.d.ts +21 -0
  7. package/dist/components/Buttons/Button/Button.model.d.ts.map +1 -0
  8. package/dist/components/Buttons/Button/index.d.ts +3 -0
  9. package/dist/components/Buttons/Button/index.d.ts.map +1 -0
  10. package/dist/components/Buttons/Button.model.d.ts +69 -7
  11. package/dist/components/Buttons/Button.model.d.ts.map +1 -1
  12. package/dist/components/Buttons/CompositeButton/CompositeButton.d.ts +5 -14
  13. package/dist/components/Buttons/CompositeButton/CompositeButton.d.ts.map +1 -1
  14. package/dist/components/Buttons/CompositeButton/CompositeButton.model.d.ts +20 -0
  15. package/dist/components/Buttons/CompositeButton/CompositeButton.model.d.ts.map +1 -0
  16. package/dist/components/Buttons/CompositeButton/index.d.ts +3 -0
  17. package/dist/components/Buttons/CompositeButton/index.d.ts.map +1 -0
  18. package/dist/components/Buttons/TextButton/TextButton.d.ts +5 -9
  19. package/dist/components/Buttons/TextButton/TextButton.d.ts.map +1 -1
  20. package/dist/components/Buttons/TextButton/TextButton.model.d.ts +18 -0
  21. package/dist/components/Buttons/TextButton/TextButton.model.d.ts.map +1 -0
  22. package/dist/components/Buttons/TextButton/index.d.ts +3 -0
  23. package/dist/components/Buttons/TextButton/index.d.ts.map +1 -0
  24. package/dist/components/Buttons/index.d.ts +3 -3
  25. package/dist/components/Buttons/index.d.ts.map +1 -1
  26. package/dist/components/Explorer/Explorer.d.ts.map +1 -1
  27. package/dist/components/Explorer/Explorer.model.d.ts +2 -2
  28. package/dist/components/Explorer/Explorer.model.d.ts.map +1 -1
  29. package/dist/components/Explorer/NavigationExplorer/NavigationExplorer.d.ts +13 -3
  30. package/dist/components/Explorer/NavigationExplorer/NavigationExplorer.d.ts.map +1 -1
  31. package/dist/components/FormElements/ToggleButton/ToggleButton.d.ts +2 -2
  32. package/dist/components/FormElements/ToggleButton/ToggleButton.d.ts.map +1 -1
  33. package/dist/components/List/List.d.ts +1 -1
  34. package/dist/components/List/List.d.ts.map +1 -1
  35. package/dist/components/List/ListRow/ListRow.d.ts.map +1 -1
  36. package/dist/components/PageHeader/PageHeader.d.ts +1 -22
  37. package/dist/components/PageHeader/PageHeader.d.ts.map +1 -1
  38. package/dist/components/PageHeader/PageHeader.model.d.ts +23 -0
  39. package/dist/components/PageHeader/PageHeader.model.d.ts.map +1 -0
  40. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.d.ts +20 -33
  41. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.d.ts.map +1 -1
  42. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.model.d.ts +47 -0
  43. package/dist/components/PageHeader/PageHeaderAction/PageHeaderAction.model.d.ts.map +1 -0
  44. package/dist/components/PageHeader/PageHeaderAction/index.d.ts +3 -0
  45. package/dist/components/PageHeader/PageHeaderAction/index.d.ts.map +1 -0
  46. package/dist/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.d.ts +2 -2
  47. package/dist/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.d.ts.map +1 -1
  48. package/dist/components/PageHeader/index.d.ts +3 -2
  49. package/dist/components/PageHeader/index.d.ts.map +1 -1
  50. package/dist/components/models.d.ts +22 -0
  51. package/dist/components/models.d.ts.map +1 -1
  52. package/dist/index.es.js +3 -3
  53. package/dist/index.es.js.map +1 -1
  54. package/dist/index.js +3 -3
  55. package/dist/index.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/components/Actions/Action/Action.spec.tsx +16 -2
  58. package/src/components/Actions/Action/Action.tsx +6 -3
  59. package/src/components/Actions/Actions.models.ts +4 -23
  60. package/src/components/Buttons/Button/Button.model.ts +30 -0
  61. package/src/components/Buttons/Button/Button.scss +3 -1
  62. package/src/components/Buttons/Button/Button.spec.tsx +254 -83
  63. package/src/components/Buttons/Button/Button.stories.tsx +20 -0
  64. package/src/components/Buttons/Button/Button.tsx +103 -32
  65. package/src/components/Buttons/Button/index.ts +2 -0
  66. package/src/components/Buttons/Button.model.ts +84 -9
  67. package/src/components/Buttons/CompositeButton/CompositeButton.model.ts +32 -0
  68. package/src/components/Buttons/CompositeButton/CompositeButton.scss +6 -1
  69. package/src/components/Buttons/CompositeButton/CompositeButton.spec.tsx +277 -89
  70. package/src/components/Buttons/CompositeButton/CompositeButton.stories.tsx +20 -0
  71. package/src/components/Buttons/CompositeButton/CompositeButton.tsx +94 -30
  72. package/src/components/Buttons/CompositeButton/index.ts +2 -0
  73. package/src/components/Buttons/TextButton/TextButton.model.ts +27 -0
  74. package/src/components/Buttons/TextButton/TextButton.scss +3 -1
  75. package/src/components/Buttons/TextButton/TextButton.spec.tsx +198 -87
  76. package/src/components/Buttons/TextButton/TextButton.stories.tsx +20 -0
  77. package/src/components/Buttons/TextButton/TextButton.tsx +74 -20
  78. package/src/components/Buttons/TextButton/index.ts +2 -0
  79. package/src/components/Buttons/index.ts +3 -6
  80. package/src/components/Explorer/Explorer.model.ts +2 -2
  81. package/src/components/Explorer/Explorer.tsx +21 -16
  82. package/src/components/Explorer/NavigationExplorer/NavigationExplorer.tsx +32 -11
  83. package/src/components/FormElements/CustomTags/CustomTags.spec.tsx +26 -16
  84. package/src/components/FormElements/ToggleButton/ToggleButton.tsx +3 -3
  85. package/src/components/List/List.spec.tsx +23 -0
  86. package/src/components/List/List.stories.tsx +8 -0
  87. package/src/components/List/List.tsx +15 -3
  88. package/src/components/List/ListRow/ListRow.tsx +18 -13
  89. package/src/components/PageHeader/PageHeader.model.ts +23 -0
  90. package/src/components/PageHeader/PageHeader.stories.tsx +2 -1
  91. package/src/components/PageHeader/PageHeader.tsx +2 -26
  92. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.model.ts +60 -0
  93. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.spec.tsx +550 -383
  94. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.stories.tsx +12 -1
  95. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.tsx +95 -45
  96. package/src/components/PageHeader/PageHeaderAction/index.ts +2 -0
  97. package/src/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.spec.tsx +2 -2
  98. package/src/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.tsx +56 -43
  99. package/src/components/PageHeader/index.ts +3 -2
  100. package/src/components/models.ts +30 -0
@@ -47,18 +47,24 @@ describe('CustomTags', () => {
47
47
 
48
48
  it('should render one plus button', () => {
49
49
  const wrapper = mount(<CustomTags name="test-name" />);
50
-
51
- expect(
52
- wrapper.find({ className: 'plusButton', type: 'button' }),
53
- ).toHaveLength(1);
50
+ const plusButton = wrapper
51
+ .find({
52
+ className: 'plusButton',
53
+ type: 'button',
54
+ })
55
+ .first();
56
+
57
+ expect(plusButton).toHaveLength(1);
54
58
  });
55
59
 
56
60
  it('should disable plus button if there is no value in input field', () => {
57
61
  const wrapper = mount(<CustomTags name="test-name" />);
58
- const plusButton = wrapper.find({
59
- className: 'plusButton',
60
- type: 'button',
61
- });
62
+ const plusButton = wrapper
63
+ .find({
64
+ className: 'plusButton',
65
+ type: 'button',
66
+ })
67
+ .first();
62
68
  expect(plusButton.prop('disabled')).toBeTruthy();
63
69
  });
64
70
 
@@ -149,10 +155,12 @@ describe('CustomTags', () => {
149
155
  input.simulate('change');
150
156
  wrapper.update();
151
157
 
152
- const plusButton = wrapper.find({
153
- className: 'plusButton',
154
- type: 'button',
155
- });
158
+ const plusButton = wrapper
159
+ .find({
160
+ className: 'plusButton',
161
+ type: 'button',
162
+ })
163
+ .first();
156
164
  plusButton.simulate('click');
157
165
 
158
166
  tags = getTagsFromDOM(wrapper);
@@ -1108,10 +1116,12 @@ describe('CustomTags', () => {
1108
1116
  input.simulate('change');
1109
1117
  wrapper.update();
1110
1118
 
1111
- const plusButton = wrapper.find({
1112
- className: 'plusButton',
1113
- type: 'button',
1114
- });
1119
+ const plusButton = wrapper
1120
+ .find({
1121
+ className: 'plusButton',
1122
+ type: 'button',
1123
+ })
1124
+ .first();
1115
1125
  plusButton.simulate('click');
1116
1126
 
1117
1127
  tags = getTagsFromDOM(wrapper);
@@ -1,18 +1,18 @@
1
1
  import clsx from 'clsx';
2
2
  import React, { useEffect, useState } from 'react';
3
3
  import { noop } from '../../../helpers/utils';
4
- import { BaseButtonOptions } from '../../Buttons/Button.model';
4
+ import { CommonJsButtonOptions } from '../../Buttons/Button.model';
5
5
  import {
6
+ ConfirmDialog,
6
7
  ConfirmationConfig,
7
8
  ConfirmationMode,
8
- ConfirmDialog,
9
9
  } from '../../ConfirmDialog';
10
10
  import { BaseFormControl } from '../Form.models';
11
11
  import { FormElementContainer } from '../FormElementContainer';
12
12
  import classes from './ToggleButton.scss';
13
13
 
14
14
  export interface ToggleButtonProps
15
- extends Omit<BaseButtonOptions, 'buttonContext' | 'onButtonClicked'>,
15
+ extends Omit<CommonJsButtonOptions, 'buttonContext' | 'onButtonClicked'>,
16
16
  BaseFormControl {
17
17
  /** Current value. Can be used to control state (default: false) */
18
18
  value?: boolean;
@@ -92,6 +92,29 @@ describe('List', () => {
92
92
  expect(props.columnSizes).toBe('1fr 1fr 1fr');
93
93
  });
94
94
 
95
+ it.each([
96
+ { value: true, visible: true },
97
+ { value: () => true, visible: true },
98
+ { value: () => false, visible: false },
99
+ ])(
100
+ 'does add an extra column if there is an action button',
101
+ ({ value, visible }) => {
102
+ const wrapper = mount(
103
+ <List
104
+ columns={mockListColumns}
105
+ data={mockListData}
106
+ showActionButton={value}
107
+ />,
108
+ );
109
+
110
+ const rows = wrapper.find(ListRow);
111
+ const props = rows.first().props();
112
+
113
+ expect(props.columnSizes).toBe('1fr 1fr 1fr 50px');
114
+ expect(props.showActionButton).toBe(visible);
115
+ },
116
+ );
117
+
95
118
  it.each`
96
119
  data | count
97
120
  ${[{ row: 'one' }, { row: 'two' }, { row: 'three' }]} | ${3}
@@ -124,6 +124,14 @@ const meta: Meta<StoryListType> = {
124
124
  description: `<b>[Storybook only]</b> The number of rows to display.
125
125
  The story will generate the requests amount of items and assign it to the <code>data</code> prop.`,
126
126
  },
127
+ showActionButton: {
128
+ ...groups.showActionButton,
129
+ description: `Whether to show the action button in the header row.`,
130
+ options: [true, false, 'random'],
131
+ mapping: {
132
+ random: (): boolean => (Math.random() > 0.5 ? true : false),
133
+ },
134
+ },
127
135
  },
128
136
  args: {
129
137
  columns: defaultColumns,
@@ -73,7 +73,7 @@ export interface ListProps<T extends Data> {
73
73
  * Defines whether an action button will be rendered (default: true)
74
74
  * Will not render if selectMode is not 'None'
75
75
  */
76
- showActionButton?: boolean;
76
+ showActionButton?: boolean | ((data: T) => boolean);
77
77
  /** Defines when the loading of the next page is triggered. The number represents the number of row left, before a load is triggered. (default: 10) */
78
78
  loadingTriggerOffset?: number;
79
79
  /** Defines how the list data should be sorted */
@@ -245,7 +245,7 @@ export const List = <T extends Data>({
245
245
 
246
246
  const columnSizes = getColumnsSizeDefinition(
247
247
  columns,
248
- showActionButton,
248
+ Boolean(showActionButton),
249
249
  selectionMode,
250
250
  !!inlineMenuActions,
251
251
  );
@@ -345,7 +345,8 @@ export const List = <T extends Data>({
345
345
  verticalTextAlign={verticalTextAlign}
346
346
  selectionMode={selectionMode}
347
347
  showActionButton={
348
- showActionButton && selectionMode === ListSelectMode.None
348
+ selectionMode === ListSelectMode.None &&
349
+ getActionButtonVisibility(item.data, showActionButton)
349
350
  }
350
351
  showCheckMark={selectionMode === ListSelectMode.Single}
351
352
  showItemCheckbox={selectionMode === ListSelectMode.Multi}
@@ -383,3 +384,14 @@ export const List = <T extends Data>({
383
384
  </div>
384
385
  );
385
386
  };
387
+
388
+ function getActionButtonVisibility<T>(
389
+ data: T,
390
+ showActionButton: boolean | ((item: T) => boolean),
391
+ ): boolean {
392
+ if (typeof showActionButton === 'boolean') {
393
+ return showActionButton;
394
+ }
395
+
396
+ return showActionButton(data);
397
+ }
@@ -271,19 +271,24 @@ export const ListRow = <T extends Data>({
271
271
  />
272
272
  )}
273
273
 
274
- {showActionButton && (
275
- <Button
276
- icon={IconName.ChevronRight}
277
- height={actionSize}
278
- width={actionSize}
279
- onButtonClicked={() => {
280
- if (typeof onItemClicked !== 'function') {
281
- history.push(onItemClicked);
282
- }
283
- }}
284
- dataTestId="list-entry-action"
285
- />
286
- )}
274
+ {showActionButton &&
275
+ (typeof onItemClicked !== 'function' ? (
276
+ <Button
277
+ icon={IconName.ChevronRight}
278
+ height={actionSize}
279
+ width={actionSize}
280
+ path={onItemClicked}
281
+ dataTestId="list-entry-action"
282
+ />
283
+ ) : (
284
+ <Button
285
+ icon={IconName.ChevronRight}
286
+ height={actionSize}
287
+ width={actionSize}
288
+ onButtonClicked={onItemClicked as () => void}
289
+ dataTestId="list-entry-action"
290
+ />
291
+ ))}
287
292
  </div>
288
293
  )}
289
294
 
@@ -0,0 +1,23 @@
1
+ import { PageHeaderActionProps } from './PageHeaderAction/PageHeaderAction.model';
2
+
3
+ export interface PageHeaderProps {
4
+ /** Title shown in page header */
5
+ title?: string;
6
+ /** Subtitle shown in page header */
7
+ subtitle?: string;
8
+ /** Array of actions to be rendered. (default: []) */
9
+ actions?: PageHeaderActionProps[];
10
+ /** Array of Bulk Actions to be rendered. If populated, Bulk Actions will become available. (default: []) */
11
+ bulkActions?: PageHeaderActionProps[];
12
+ /** Whether or bulk actions are shown by default. (default: false) */
13
+ openBulkActionsOnStart?: boolean;
14
+ /** Whether or not bulk actions are disabled (default: false)*/
15
+ bulkActionsDisabled?: boolean;
16
+ /**
17
+ * Callback to emit when Bulk Actions is toggled
18
+ * The expanded state is supplied as an argument
19
+ */
20
+ onBulkActionsToggled?: (expanded: boolean) => void;
21
+ /** CSS Class name for additional styles */
22
+ className?: string;
23
+ }
@@ -5,7 +5,8 @@ import { PageHeader } from './PageHeader';
5
5
  import {
6
6
  PageHeaderActionProps,
7
7
  PageHeaderActionType,
8
- } from './PageHeaderAction/PageHeaderAction';
8
+ } from './PageHeaderAction';
9
+ import {} from './PageHeaderAction/PageHeaderAction';
9
10
 
10
11
  const headerActions: PageHeaderActionProps[] = [
11
12
  {
@@ -2,35 +2,11 @@ import clsx from 'clsx';
2
2
  import React, { useEffect, useState } from 'react';
3
3
  import { noop } from '../../helpers/utils';
4
4
  import { useWindowSize } from '../../hooks/useWindowSize/useWindowSize';
5
+ import { PageHeaderProps } from './PageHeader.model';
5
6
  import classes from './PageHeader.scss';
6
- import {
7
- PageHeaderAction,
8
- PageHeaderActionProps,
9
- } from './PageHeaderAction/PageHeaderAction';
7
+ import { PageHeaderAction } from './PageHeaderAction/PageHeaderAction';
10
8
  import { PageHeaderBulkActions } from './PageHeaderBulkActions/PageHeaderBulkActions';
11
9
 
12
- export interface PageHeaderProps {
13
- /** Title shown in page header */
14
- title?: string;
15
- /** Subtitle shown in page header */
16
- subtitle?: string;
17
- /** Array of actions to be rendered. (default: []) */
18
- actions?: PageHeaderActionProps[];
19
- /** Array of Bulk Actions to be rendered. If populated, Bulk Actions will become available. (default: []) */
20
- bulkActions?: PageHeaderActionProps[];
21
- /** Whether or bulk actions are shown by default. (default: false) */
22
- openBulkActionsOnStart?: boolean;
23
- /** Whether or not bulk actions are disabled (default: false)*/
24
- bulkActionsDisabled?: boolean;
25
- /**
26
- * Callback to emit when Bulk Actions is toggled
27
- * The expanded state is supplied as an argument
28
- */
29
- onBulkActionsToggled?: (expanded: boolean) => void;
30
- /** CSS Class name for additional styles */
31
- className?: string;
32
- }
33
-
34
10
  /**
35
11
  * Primary header for stations. Accepts a title, subtitle, actions, and bulk actions.
36
12
  * @example
@@ -0,0 +1,60 @@
1
+ import { Not } from '../../../types';
2
+ import { IconName } from '../../Icons';
3
+ import { ConfirmAction, DefaultHandler, LinkAction } from '../../models';
4
+
5
+ export enum PageHeaderActionType {
6
+ Active,
7
+ Context,
8
+ /**
9
+ * @deprecated This value is no longer necessary for navigation type actions in the
10
+ * `PageHeaderAction` component, and will be removed in the future.
11
+ * To create a navigation link, use the `path` property instead of the `onClick` handler,
12
+ * which will automatically generate an anchor element.
13
+ * @note This deprecation only affects the `Navigation` enum value in the PageHeaderActionType
14
+ */
15
+ Navigation,
16
+ }
17
+
18
+ export type PageHeaderActionProps =
19
+ | PageHeaderJsActionProps
20
+ | PageHeaderNavigationActionProps;
21
+
22
+ export interface PageHeaderJsActionProps
23
+ extends BaseActionOptions,
24
+ HandledAction,
25
+ ConfirmAction,
26
+ Not<LinkAction> {
27
+ /**
28
+ * Whether the action is an 'Active' or 'Context' type.
29
+ * Changes the background color to the corresponding action type. (default: 'Context')
30
+ * Type `Navigation` is deprecated and will be removed in the future
31
+ * define instead of `onClick` handler `path` property to render element with anchor tag
32
+ */
33
+ actionType?: PageHeaderActionType;
34
+ }
35
+
36
+ export interface PageHeaderNavigationActionProps
37
+ extends BaseActionOptions,
38
+ LinkAction,
39
+ Not<ConfirmAction>,
40
+ Not<HandledAction> {}
41
+
42
+ interface HandledAction {
43
+ /**
44
+ * Callback to emit when a user clicks on the component
45
+ */
46
+ onClick: DefaultHandler;
47
+ }
48
+
49
+ interface BaseActionOptions {
50
+ /** The label of the action. */
51
+ label: string;
52
+ /** Optional built in icon. This prop also accepts an img src. */
53
+ icon?: IconName | string;
54
+ /** Optional image alt attribute. */
55
+ imgAlt?: string;
56
+ /** Whether the action is disabled. If set to true, disallows interactions. (default: undefined) */
57
+ disabled?: boolean;
58
+ /** Optional class */
59
+ className?: string;
60
+ }