@axinom/mosaic-ui 0.78.0-rc.9 → 0.78.0

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 (46) hide show
  1. package/dist/cjs/components/FormElements/BooleanView/BooleanViewField.d.ts +5 -1
  2. package/dist/cjs/components/FormElements/BooleanView/BooleanViewField.d.ts.map +1 -1
  3. package/dist/cjs/components/FormElements/StatusView/StatusView.d.ts +28 -0
  4. package/dist/cjs/components/FormElements/StatusView/StatusView.d.ts.map +1 -0
  5. package/dist/cjs/components/FormElements/StatusView/StatusView.models.d.ts +39 -0
  6. package/dist/cjs/components/FormElements/StatusView/StatusView.models.d.ts.map +1 -0
  7. package/dist/cjs/components/FormElements/StatusView/StatusViewField.d.ts +37 -0
  8. package/dist/cjs/components/FormElements/StatusView/StatusViewField.d.ts.map +1 -0
  9. package/dist/cjs/components/FormElements/index.d.ts +3 -0
  10. package/dist/cjs/components/FormElements/index.d.ts.map +1 -1
  11. package/dist/cjs/components/Icons/Icons.d.ts.map +1 -1
  12. package/dist/cjs/components/Icons/Icons.models.d.ts +27 -26
  13. package/dist/cjs/components/Icons/Icons.models.d.ts.map +1 -1
  14. package/dist/cjs/index.js +4 -4
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/esm/components/FormElements/BooleanView/BooleanViewField.d.ts +5 -1
  17. package/dist/esm/components/FormElements/BooleanView/BooleanViewField.d.ts.map +1 -1
  18. package/dist/esm/components/FormElements/StatusView/StatusView.d.ts +28 -0
  19. package/dist/esm/components/FormElements/StatusView/StatusView.d.ts.map +1 -0
  20. package/dist/esm/components/FormElements/StatusView/StatusView.models.d.ts +39 -0
  21. package/dist/esm/components/FormElements/StatusView/StatusView.models.d.ts.map +1 -0
  22. package/dist/esm/components/FormElements/StatusView/StatusViewField.d.ts +37 -0
  23. package/dist/esm/components/FormElements/StatusView/StatusViewField.d.ts.map +1 -0
  24. package/dist/esm/components/FormElements/index.d.ts +3 -0
  25. package/dist/esm/components/FormElements/index.d.ts.map +1 -1
  26. package/dist/esm/components/Icons/Icons.d.ts.map +1 -1
  27. package/dist/esm/components/Icons/Icons.models.d.ts +27 -26
  28. package/dist/esm/components/Icons/Icons.models.d.ts.map +1 -1
  29. package/dist/esm/index.js +4 -4
  30. package/dist/esm/index.js.map +1 -1
  31. package/package.json +2 -2
  32. package/src/components/Badge/Badge.stories.tsx +23 -0
  33. package/src/components/FormElements/BooleanView/BooleanViewField.spec.tsx +40 -24
  34. package/src/components/FormElements/BooleanView/BooleanViewField.tsx +26 -23
  35. package/src/components/FormElements/StatusView/StatusView.models.ts +62 -0
  36. package/src/components/FormElements/StatusView/StatusView.module.scss +44 -0
  37. package/src/components/FormElements/StatusView/StatusView.spec.tsx +165 -0
  38. package/src/components/FormElements/StatusView/StatusView.stories.tsx +118 -0
  39. package/src/components/FormElements/StatusView/StatusView.tsx +80 -0
  40. package/src/components/FormElements/StatusView/StatusViewField.spec.tsx +97 -0
  41. package/src/components/FormElements/StatusView/StatusViewField.stories.tsx +136 -0
  42. package/src/components/FormElements/StatusView/StatusViewField.tsx +66 -0
  43. package/src/components/FormElements/index.ts +6 -0
  44. package/src/components/Icons/Icons.models.ts +1 -0
  45. package/src/components/Icons/Icons.tsx +10 -0
  46. package/src/components/FormElements/BooleanView/BooleanViewField.module.scss +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-ui",
3
- "version": "0.78.0-rc.9",
3
+ "version": "0.78.0",
4
4
  "engines": {
5
5
  "node": ">=20.19.0"
6
6
  },
@@ -119,5 +119,5 @@
119
119
  "publishConfig": {
120
120
  "access": "public"
121
121
  },
122
- "gitHead": "4ce8052ce288d7facf56061549fd4882390a101f"
122
+ "gitHead": "435be295e4c3bb53fb78f9964e55cc07148afd02"
123
123
  }
@@ -24,6 +24,25 @@ const meta: Meta<typeof Badge> = {
24
24
  </div>
25
25
  ),
26
26
  ],
27
+ argTypes: {
28
+ // `content` is `string | number`, so Storybook would infer a number control
29
+ // from the default arg. A text control allows both kinds of input.
30
+ content: { control: 'text' },
31
+ },
32
+ // The text control always yields strings, so numeric input is converted back
33
+ // to a number to keep `max` (which only caps numbers) working.
34
+ render: ({ content, ...args }) => (
35
+ <Badge
36
+ {...args}
37
+ content={
38
+ typeof content === 'string' &&
39
+ content.trim() !== '' &&
40
+ !isNaN(Number(content))
41
+ ? Number(content)
42
+ : content
43
+ }
44
+ />
45
+ ),
27
46
  args: {
28
47
  content: 5,
29
48
  position: 'top-right',
@@ -38,6 +57,10 @@ export const MultiDigitCapped: StoryObj<typeof Badge> = {
38
57
  args: { content: 1000, max: 99 },
39
58
  };
40
59
 
60
+ export const StringContent: StoryObj<typeof Badge> = {
61
+ args: { content: 'New' },
62
+ };
63
+
41
64
  export const BottomLeftFlush: StoryObj<typeof Badge> = {
42
65
  args: { position: 'bottom-left', overlap: false },
43
66
  };
@@ -4,6 +4,12 @@ import { describe, expect, it } from 'vitest';
4
4
  import { IconName } from '../../Icons';
5
5
  import { BooleanViewField } from './BooleanViewField';
6
6
 
7
+ const trueColor = 'var(--mosaic-neutral-1)';
8
+ const falseColor = 'var(--mosaic-neutral)';
9
+
10
+ const getValue = (container: HTMLElement): HTMLElement | null =>
11
+ container.querySelector('[data-test-id="form-field-value"]');
12
+
7
13
  describe('BooleanViewField', () => {
8
14
  it('renders the component without crashing', () => {
9
15
  const { container } = render(<BooleanViewField />);
@@ -22,14 +28,12 @@ describe('BooleanViewField', () => {
22
28
 
23
29
  it('displays default true, false label values', () => {
24
30
  const { container: container1 } = render(<BooleanViewField value={true} />);
25
- const text1 = container1.querySelector('[data-test-id="form-field-value"]');
26
- expect(text1?.textContent).toBe('True');
31
+ expect(getValue(container1)?.textContent).toBe('True');
27
32
 
28
33
  const { container: container2 } = render(
29
34
  <BooleanViewField value={false} />,
30
35
  );
31
- const text2 = container2.querySelector('[data-test-id="form-field-value"]');
32
- expect(text2?.textContent).toBe('False');
36
+ expect(getValue(container2)?.textContent).toBe('False');
33
37
  });
34
38
 
35
39
  it('renders value: true', () => {
@@ -44,13 +48,10 @@ describe('BooleanViewField', () => {
44
48
  />,
45
49
  );
46
50
 
47
- const green = container.querySelector('.true');
48
- const red = container.querySelector('.false');
49
- const text = container.querySelector('[data-test-id="form-field-value"]');
50
-
51
- expect(green).toBeInTheDocument();
52
- expect(red).not.toBeInTheDocument();
53
- expect(text?.textContent).toBe(trueLabel);
51
+ expect(container.querySelector('.status-view')).toHaveStyle({
52
+ '--status-color': trueColor,
53
+ });
54
+ expect(getValue(container)?.textContent).toBe(trueLabel);
54
55
  });
55
56
 
56
57
  it('renders value: false', () => {
@@ -65,23 +66,18 @@ describe('BooleanViewField', () => {
65
66
  />,
66
67
  );
67
68
 
68
- const green = container.querySelector('.true');
69
- const red = container.querySelector('.false');
70
- const text = container.querySelector('[data-test-id="form-field-value"]');
71
-
72
- expect(green).not.toBeInTheDocument();
73
- expect(red).toBeInTheDocument();
74
- expect(text?.textContent).toBe(falseLabel);
69
+ expect(container.querySelector('.status-view')).toHaveStyle({
70
+ '--status-color': falseColor,
71
+ });
72
+ expect(getValue(container)?.textContent).toBe(falseLabel);
75
73
  });
76
74
 
77
- it('defaults to show red circle', () => {
75
+ it('defaults to the false state', () => {
78
76
  const { container } = render(<BooleanViewField />);
79
77
 
80
- const green = container.querySelector('.true');
81
- const red = container.querySelector('.false');
82
-
83
- expect(green).not.toBeInTheDocument();
84
- expect(red).toBeInTheDocument();
78
+ expect(container.querySelector('.status-view')).toHaveStyle({
79
+ '--status-color': falseColor,
80
+ });
85
81
  });
86
82
 
87
83
  it('renders a custom trueIcon/falseIcon when provided', () => {
@@ -103,4 +99,24 @@ describe('BooleanViewField', () => {
103
99
  );
104
100
  expect(container2.querySelector('svg')).toBeInTheDocument();
105
101
  });
102
+
103
+ // The E2E selectors in lib-e2e-ui-selectors find the field by its type and
104
+ // read the value straight off these attributes, so they are a contract.
105
+ it('keeps the BooleanView field type for E2E selectors', () => {
106
+ const { container } = render(<BooleanViewField value={true} />);
107
+
108
+ expect(
109
+ container.querySelector('[data-test-id="form-field"]'),
110
+ ).toHaveAttribute('data-test-type', 'BooleanView');
111
+ });
112
+
113
+ it('exposes the value as a "true"/"false" attribute for E2E selectors', () => {
114
+ const { container: container1 } = render(<BooleanViewField value={true} />);
115
+ expect(getValue(container1)).toHaveAttribute('data-test-value', 'true');
116
+
117
+ const { container: container2 } = render(
118
+ <BooleanViewField value={false} />,
119
+ );
120
+ expect(getValue(container2)).toHaveAttribute('data-test-value', 'false');
121
+ });
106
122
  });
@@ -1,16 +1,16 @@
1
1
  import clsx from 'clsx';
2
2
  import React from 'react';
3
- import { IconName, Icons, type IconComponent } from '../../Icons';
3
+ import { IconName, type IconComponent } from '../../Icons';
4
4
  import type { BaseFormElement } from '../Form.models';
5
- import { FormElementContainer } from '../FormElementContainer';
6
- import classes from './BooleanViewField.module.scss';
5
+ import type { StatusDefinition } from '../StatusView/StatusView.models';
6
+ import { StatusViewField } from '../StatusView/StatusViewField';
7
7
 
8
8
  export interface BooleanViewFieldProps extends BaseFormElement {
9
9
  /** Value to be displayed */
10
10
  value?: boolean;
11
11
  /** text to be displayed when value is true */
12
12
  trueLabel?: string;
13
- /** text to be displayed when value is true */
13
+ /** text to be displayed when value is false */
14
14
  falseLabel?: string;
15
15
  /** icon to be displayed when value is true (default: a checkmark) */
16
16
  trueIcon?: IconComponent;
@@ -18,6 +18,10 @@ export interface BooleanViewFieldProps extends BaseFormElement {
18
18
  falseIcon?: IconComponent;
19
19
  }
20
20
 
21
+ /**
22
+ * Renders a boolean as an icon and a text into a form. A specialization of the
23
+ * {@link StatusViewField} with one status for each of the two values.
24
+ */
21
25
  export const BooleanViewField: React.FC<BooleanViewFieldProps> = ({
22
26
  value = false,
23
27
  trueLabel = 'True',
@@ -27,27 +31,26 @@ export const BooleanViewField: React.FC<BooleanViewFieldProps> = ({
27
31
  className = '',
28
32
  ...rest
29
33
  }) => {
34
+ const statuses: Record<'true' | 'false', StatusDefinition> = {
35
+ true: {
36
+ label: trueLabel,
37
+ icon: trueIcon,
38
+ color: 'var(--mosaic-neutral-1)',
39
+ },
40
+ false: {
41
+ label: falseLabel,
42
+ icon: falseIcon,
43
+ color: 'var(--mosaic-neutral)',
44
+ },
45
+ };
46
+
30
47
  return (
31
- <FormElementContainer
48
+ <StatusViewField
32
49
  {...rest}
33
- className={clsx(
34
- classes.container,
35
- 'boolean-view-field-container',
36
- className,
37
- )}
38
- minHeight={'20px'}
50
+ value={value ? 'true' : 'false'}
51
+ statuses={statuses}
52
+ className={clsx('boolean-view-field-container', className)}
39
53
  dataTestFieldType="BooleanView"
40
- >
41
- <div className={clsx(classes.value)}>
42
- <div
43
- className={clsx(classes.icon, value ? classes.true : classes.false)}
44
- >
45
- <Icons icon={value ? trueIcon : falseIcon} />
46
- </div>
47
- <div data-test-id="form-field-value" data-test-value={value}>
48
- {value ? trueLabel : falseLabel}
49
- </div>
50
- </div>
51
- </FormElementContainer>
54
+ />
52
55
  );
53
56
  };
@@ -0,0 +1,62 @@
1
+ import type { IconComponent } from '../../Icons';
2
+
3
+ /** Describes how a single status value should be displayed. */
4
+ export interface StatusDefinition {
5
+ /** Text to be displayed (default: the raw value) */
6
+ label?: string;
7
+ /**
8
+ * Icon to be displayed in front of the text. Omit to render text only.
9
+ *
10
+ * Icons carry no color of their own, so an icon without a `color` is
11
+ * rendered in the default neutral tone.
12
+ */
13
+ icon?: IconComponent;
14
+ /**
15
+ * Any CSS color, applied to the icon (default: `var(--mosaic-neutral)`).
16
+ * Prefer the branding custom properties so that a status follows the active
17
+ * theme: `var(--mosaic-success)`, `var(--mosaic-error)`,
18
+ * `var(--mosaic-warning)`, `var(--mosaic-secondary)`,
19
+ * `var(--mosaic-neutral-1)`, `var(--mosaic-neutral)`.
20
+ */
21
+ color?: string;
22
+ /** Text shown on hover (default: the label) */
23
+ title?: string;
24
+ }
25
+
26
+ /** A status definition with all display values resolved. */
27
+ export interface ResolvedStatus {
28
+ label: string;
29
+ icon?: IconComponent;
30
+ color?: string;
31
+ title: string;
32
+ }
33
+
34
+ /** The custom property through which the status color reaches the stylesheet. */
35
+ export const statusColorProperty = '--status-color';
36
+
37
+ /**
38
+ * Looks a value up in the status map and fills in the display defaults. Returns
39
+ * `undefined` when there is neither a matching status nor a value to fall back
40
+ * on, which is what lets the callers hide themselves entirely.
41
+ */
42
+ export const resolveStatus = <T extends string = string>(
43
+ value: T | null | undefined,
44
+ statuses: Partial<Record<T, StatusDefinition>> = {},
45
+ fallback?: StatusDefinition,
46
+ ): ResolvedStatus | undefined => {
47
+ const hasValue = value !== null && value !== undefined && value !== '';
48
+ const definition = (hasValue ? statuses[value] : undefined) ?? fallback;
49
+
50
+ if (definition === undefined && !hasValue) {
51
+ return undefined;
52
+ }
53
+
54
+ const label = definition?.label ?? (hasValue ? value : '');
55
+
56
+ return {
57
+ label,
58
+ icon: definition?.icon,
59
+ color: definition?.color,
60
+ title: definition?.title ?? label,
61
+ };
62
+ };
@@ -0,0 +1,44 @@
1
+ @import '../../../styles/common.scss';
2
+
3
+ .container {
4
+ display: grid;
5
+ grid-template-columns: 25px auto;
6
+ // the icon now fills its column, so the spacing has to come from the gap
7
+ gap: 5px;
8
+ align-items: center;
9
+ color: var(--input-color, $input-color);
10
+ font-size: var(--label-font-size, $label-font-size);
11
+
12
+ &.textOnly {
13
+ grid-template-columns: auto;
14
+ }
15
+
16
+ .icon {
17
+ // centers the svg in the box, and blockifies it so that it does not sit on
18
+ // the text baseline and leave a descender gap underneath
19
+ display: flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ height: 25px;
23
+ width: 25px;
24
+
25
+ svg {
26
+ height: 100%;
27
+ width: 100%;
28
+ }
29
+
30
+ // Icons paint their shapes white by default, so every shape element the
31
+ // icon set uses has to be claimed back here for the status color.
32
+ svg rect,
33
+ svg polygon,
34
+ svg polyline,
35
+ svg path,
36
+ svg circle {
37
+ stroke: var(--status-color, var(--mosaic-neutral));
38
+ }
39
+ }
40
+
41
+ .text {
42
+ overflow-wrap: anywhere;
43
+ }
44
+ }
@@ -0,0 +1,165 @@
1
+ import { render } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { IconName } from '../../Icons';
5
+ import { StatusView } from './StatusView';
6
+ import type { StatusDefinition } from './StatusView.models';
7
+
8
+ enum MockStatus {
9
+ Ready = 'READY',
10
+ Failed = 'FAILED',
11
+ // deliberately left out of the status map below
12
+ Unhandled = 'UNHANDLED',
13
+ }
14
+
15
+ const statuses: Partial<Record<MockStatus, StatusDefinition>> = {
16
+ [MockStatus.Ready]: {
17
+ label: 'Ready',
18
+ icon: IconName.Success,
19
+ color: 'var(--mosaic-success)',
20
+ },
21
+ [MockStatus.Failed]: {
22
+ label: 'Failed',
23
+ icon: IconName.Error,
24
+ color: 'var(--mosaic-error)',
25
+ },
26
+ };
27
+
28
+ const getValue = (container: HTMLElement): HTMLElement | null =>
29
+ container.querySelector('[data-test-id="form-field-value"]');
30
+
31
+ describe('StatusView', () => {
32
+ it('renders the component without crashing', () => {
33
+ const { container } = render(
34
+ <StatusView value={MockStatus.Ready} statuses={statuses} />,
35
+ );
36
+
37
+ expect(container).toBeTruthy();
38
+ });
39
+
40
+ it('displays the label and the icon of the matching status', () => {
41
+ const { container } = render(
42
+ <StatusView value={MockStatus.Failed} statuses={statuses} />,
43
+ );
44
+
45
+ expect(getValue(container)?.textContent).toBe('Failed');
46
+ expect(container.querySelector('svg')).toBeInTheDocument();
47
+ });
48
+
49
+ it('exposes the value for E2E tests', () => {
50
+ const { container } = render(
51
+ <StatusView value={MockStatus.Ready} statuses={statuses} />,
52
+ );
53
+
54
+ expect(getValue(container)).toHaveAttribute(
55
+ 'data-test-value',
56
+ MockStatus.Ready,
57
+ );
58
+ });
59
+
60
+ it('hands a branding custom property to the stylesheet', () => {
61
+ const { container } = render(
62
+ <StatusView value={MockStatus.Ready} statuses={statuses} />,
63
+ );
64
+
65
+ expect(container.querySelector('.status-view')).toHaveStyle({
66
+ '--status-color': 'var(--mosaic-success)',
67
+ });
68
+ });
69
+
70
+ it('hands a plain CSS color to the stylesheet', () => {
71
+ const { container } = render(
72
+ <StatusView
73
+ value={MockStatus.Ready}
74
+ statuses={{ [MockStatus.Ready]: { label: 'Ready', color: '#123456' } }}
75
+ />,
76
+ );
77
+
78
+ expect(container.querySelector('.status-view')).toHaveStyle({
79
+ '--status-color': '#123456',
80
+ });
81
+ });
82
+
83
+ it('leaves the color to the stylesheet default when none is given', () => {
84
+ const { container } = render(
85
+ <StatusView
86
+ value={MockStatus.Ready}
87
+ statuses={{
88
+ [MockStatus.Ready]: { label: 'Ready', icon: IconName.Success },
89
+ }}
90
+ />,
91
+ );
92
+
93
+ expect(container.querySelector('.status-view')).not.toHaveAttribute(
94
+ 'style',
95
+ );
96
+ });
97
+
98
+ it('displays the raw value when it is not part of the status map', () => {
99
+ const { container } = render(
100
+ <StatusView value={MockStatus.Unhandled} statuses={statuses} />,
101
+ );
102
+
103
+ expect(getValue(container)?.textContent).toBe('UNHANDLED');
104
+ expect(container.querySelector('svg')).not.toBeInTheDocument();
105
+ });
106
+
107
+ it('displays the fallback when the value is not part of the status map', () => {
108
+ const { container } = render(
109
+ <StatusView
110
+ value={MockStatus.Unhandled}
111
+ statuses={statuses}
112
+ fallback={{ label: 'Unknown', icon: IconName.Warning }}
113
+ />,
114
+ );
115
+
116
+ expect(getValue(container)?.textContent).toBe('Unknown');
117
+ expect(container.querySelector('svg')).toBeInTheDocument();
118
+ });
119
+
120
+ it('survives a value which is not part of the enum at all', () => {
121
+ // the API can start returning states the generated enum does not know yet
122
+ const { container } = render(
123
+ <StatusView
124
+ value={'FROM_THE_FUTURE' as MockStatus}
125
+ statuses={statuses}
126
+ fallback={{ label: 'Unknown' }}
127
+ />,
128
+ );
129
+
130
+ expect(getValue(container)?.textContent).toBe('Unknown');
131
+ });
132
+
133
+ it('renders nothing when there is no value and no fallback', () => {
134
+ const { container: empty } = render(<StatusView statuses={statuses} />);
135
+ const { container: nulled } = render(
136
+ <StatusView value={null} statuses={statuses} />,
137
+ );
138
+
139
+ expect(getValue(empty)).not.toBeInTheDocument();
140
+ expect(getValue(nulled)).not.toBeInTheDocument();
141
+ });
142
+
143
+ it('renders the fallback when there is no value', () => {
144
+ const { container } = render(
145
+ <StatusView statuses={statuses} fallback={{ label: 'Not set' }} />,
146
+ );
147
+
148
+ expect(getValue(container)?.textContent).toBe('Not set');
149
+ });
150
+
151
+ it('displays a title on hover, defaulting to the label', () => {
152
+ const { container: defaulted } = render(
153
+ <StatusView value={MockStatus.Ready} statuses={statuses} />,
154
+ );
155
+ const { container: custom } = render(
156
+ <StatusView
157
+ value={MockStatus.Ready}
158
+ statuses={{ [MockStatus.Ready]: { label: 'Ready', title: 'All done' } }}
159
+ />,
160
+ );
161
+
162
+ expect(getValue(defaulted)).toHaveAttribute('title', 'Ready');
163
+ expect(getValue(custom)).toHaveAttribute('title', 'All done');
164
+ });
165
+ });
@@ -0,0 +1,118 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import React from 'react';
3
+ import { createGroups } from '../../../helpers/storybook';
4
+ import { IconName } from '../../Icons';
5
+ import { StatusView } from './StatusView';
6
+ import type { StatusDefinition } from './StatusView.models';
7
+
8
+ enum ValidationStatus {
9
+ Valid = 'VALID',
10
+ Outdated = 'OUTDATED',
11
+ Invalid = 'INVALID',
12
+ }
13
+
14
+ const validationStatuses: Partial<Record<ValidationStatus, StatusDefinition>> =
15
+ {
16
+ [ValidationStatus.Valid]: {
17
+ label: 'Valid',
18
+ icon: IconName.Success,
19
+ color: 'var(--mosaic-success)',
20
+ },
21
+ [ValidationStatus.Outdated]: {
22
+ label: 'Outdated',
23
+ icon: IconName.Warning,
24
+ color: 'var(--mosaic-warning)',
25
+ },
26
+ [ValidationStatus.Invalid]: {
27
+ label: 'Invalid',
28
+ icon: IconName.Error,
29
+ color: 'var(--mosaic-error)',
30
+ },
31
+ };
32
+
33
+ const groups = createGroups({
34
+ Content: ['value', 'statuses', 'fallback'],
35
+ Styling: ['className'],
36
+ });
37
+
38
+ const meta: Meta<typeof StatusView> = {
39
+ title: 'Primary Components/Form Elements/StatusView',
40
+ component: StatusView,
41
+ argTypes: {
42
+ ...groups,
43
+ value: {
44
+ control: { type: 'select' },
45
+ options: Object.values(ValidationStatus),
46
+ },
47
+ },
48
+ };
49
+ export default meta;
50
+
51
+ export const Main: StoryObj<typeof StatusView> = {
52
+ args: {
53
+ value: ValidationStatus.Valid,
54
+ statuses: validationStatuses,
55
+ },
56
+ };
57
+
58
+ /**
59
+ * Without the form chrome the component can be used anywhere a status has to be
60
+ * shown, for example as an explorer column renderer.
61
+ */
62
+ export const ColumnRenderer: StoryObj<typeof StatusView> = {
63
+ parameters: {
64
+ controls: { hideNoControlsWarning: true, exclude: /.*/g },
65
+ },
66
+ render: () => (
67
+ <table style={{ borderSpacing: '20px 10px' }}>
68
+ <tbody>
69
+ {Object.values(ValidationStatus).map((status, index) => (
70
+ <tr key={status}>
71
+ <td>Entity {index + 1}</td>
72
+ <td>
73
+ <StatusView value={status} statuses={validationStatuses} />
74
+ </td>
75
+ </tr>
76
+ ))}
77
+ </tbody>
78
+ </table>
79
+ ),
80
+ };
81
+
82
+ /**
83
+ * `color` takes any CSS color. Prefer the branding custom properties, so that a
84
+ * status follows the active theme.
85
+ */
86
+ export const BrandingColors: StoryObj<typeof StatusView> = {
87
+ parameters: {
88
+ controls: { hideNoControlsWarning: true, exclude: /.*/g },
89
+ },
90
+ render: () => (
91
+ <div style={{ display: 'grid', gridGap: 10 }}>
92
+ {[
93
+ 'var(--mosaic-success)',
94
+ 'var(--mosaic-error)',
95
+ 'var(--mosaic-warning)',
96
+ 'var(--mosaic-secondary)',
97
+ 'var(--mosaic-neutral-1)',
98
+ 'var(--mosaic-neutral)',
99
+ ].map((color) => (
100
+ <StatusView
101
+ key={color}
102
+ value={color}
103
+ statuses={{ [color]: { icon: IconName.Success, color } }}
104
+ />
105
+ ))}
106
+ </div>
107
+ ),
108
+ };
109
+
110
+ /** Without a `color` the icon falls back to the default neutral tone. */
111
+ export const WithoutColor: StoryObj<typeof StatusView> = {
112
+ args: {
113
+ value: ValidationStatus.Valid,
114
+ statuses: {
115
+ [ValidationStatus.Valid]: { label: 'Valid', icon: IconName.Success },
116
+ },
117
+ },
118
+ };