@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
@@ -0,0 +1,80 @@
1
+ import clsx from 'clsx';
2
+ import React, { type CSSProperties } from 'react';
3
+ import { Icons } from '../../Icons';
4
+ import {
5
+ resolveStatus,
6
+ statusColorProperty,
7
+ type StatusDefinition,
8
+ } from './StatusView.models';
9
+ import classes from './StatusView.module.scss';
10
+
11
+ export interface StatusViewProps<T extends string = string> {
12
+ /** Value to be displayed */
13
+ value?: T | null;
14
+ /** Maps each value of an enum (or plain string) to the way it is displayed */
15
+ statuses?: Partial<Record<T, StatusDefinition>>;
16
+ /** Used for values which are not part of the status map */
17
+ fallback?: StatusDefinition;
18
+ /** CSS Class name for additional styles */
19
+ className?: string;
20
+ }
21
+
22
+ /**
23
+ * Renders a status as an icon and a text. The presentation of every value is
24
+ * declared through the `statuses` map, which can be keyed by a string enum.
25
+ * @example
26
+ * <StatusView
27
+ * value={encodingState}
28
+ * statuses={{
29
+ * [EncodingState.Ready]: {
30
+ * label: 'Ready',
31
+ * icon: IconName.Success,
32
+ * color: 'var(--mosaic-success)',
33
+ * },
34
+ * }}
35
+ * />
36
+ */
37
+ export const StatusView = <T extends string = string>({
38
+ value,
39
+ statuses = {},
40
+ fallback,
41
+ className = '',
42
+ }: StatusViewProps<T>): JSX.Element | null => {
43
+ const status = resolveStatus(value, statuses, fallback);
44
+
45
+ if (status === undefined) {
46
+ return null;
47
+ }
48
+
49
+ const hasIcon = status.icon !== undefined;
50
+
51
+ return (
52
+ <div
53
+ className={clsx(
54
+ classes.container,
55
+ { [classes.textOnly]: !hasIcon },
56
+ 'status-view',
57
+ className,
58
+ )}
59
+ style={
60
+ status.color
61
+ ? ({ [statusColorProperty]: status.color } as CSSProperties)
62
+ : undefined
63
+ }
64
+ >
65
+ {hasIcon && (
66
+ <div className={clsx(classes.icon)}>
67
+ <Icons icon={status.icon} title={status.title} />
68
+ </div>
69
+ )}
70
+ <div
71
+ className={clsx(classes.text)}
72
+ data-test-id="form-field-value"
73
+ data-test-value={value ?? ''}
74
+ title={status.title}
75
+ >
76
+ {status.label}
77
+ </div>
78
+ </div>
79
+ );
80
+ };
@@ -0,0 +1,97 @@
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 type { StatusDefinition } from './StatusView.models';
6
+ import { StatusViewField } from './StatusViewField';
7
+
8
+ enum MockStatus {
9
+ Ready = 'READY',
10
+ Failed = 'FAILED',
11
+ }
12
+
13
+ const statuses: Partial<Record<MockStatus, StatusDefinition>> = {
14
+ [MockStatus.Ready]: {
15
+ label: 'Ready',
16
+ icon: IconName.Success,
17
+ color: 'var(--mosaic-success)',
18
+ },
19
+ [MockStatus.Failed]: {
20
+ label: 'Failed',
21
+ icon: IconName.Error,
22
+ color: 'var(--mosaic-error)',
23
+ },
24
+ };
25
+
26
+ describe('StatusViewField', () => {
27
+ it('renders the component without crashing', () => {
28
+ const { container } = render(<StatusViewField statuses={statuses} />);
29
+
30
+ expect(container).toBeTruthy();
31
+ });
32
+
33
+ it('displays a label', () => {
34
+ const mockLabel = 'mockLabel';
35
+ const { container } = render(
36
+ <StatusViewField label={mockLabel} statuses={statuses} />,
37
+ );
38
+
39
+ expect(container.querySelector('label')?.textContent).toBe(mockLabel);
40
+ });
41
+
42
+ it('displays the value of the matching status', () => {
43
+ const { container } = render(
44
+ <StatusViewField value={MockStatus.Failed} statuses={statuses} />,
45
+ );
46
+
47
+ const value = container.querySelector('[data-test-id="form-field-value"]');
48
+
49
+ expect(value?.textContent).toBe('Failed');
50
+ expect(container.querySelector('svg')).toBeInTheDocument();
51
+ });
52
+
53
+ it('identifies itself as a StatusView form element', () => {
54
+ const { container } = render(
55
+ <StatusViewField value={MockStatus.Ready} statuses={statuses} />,
56
+ );
57
+
58
+ expect(
59
+ container.querySelector('[data-test-id="form-field"]'),
60
+ ).toHaveAttribute('data-test-type', 'StatusView');
61
+ });
62
+
63
+ it('renders the field when there is nothing to show', () => {
64
+ const { container } = render(
65
+ <StatusViewField label="Status" statuses={statuses} />,
66
+ );
67
+
68
+ expect(
69
+ container.querySelector('[data-test-id="form-field"]'),
70
+ ).toBeInTheDocument();
71
+ });
72
+
73
+ it('hides the field when there is nothing to show and hideIfEmpty is set', () => {
74
+ const { container } = render(
75
+ <StatusViewField label="Status" statuses={statuses} hideIfEmpty />,
76
+ );
77
+
78
+ expect(
79
+ container.querySelector('[data-test-id="form-field"]'),
80
+ ).not.toBeInTheDocument();
81
+ });
82
+
83
+ it('keeps the field when hideIfEmpty is set but a fallback applies', () => {
84
+ const { container } = render(
85
+ <StatusViewField
86
+ label="Status"
87
+ statuses={statuses}
88
+ fallback={{ label: 'Not set' }}
89
+ hideIfEmpty
90
+ />,
91
+ );
92
+
93
+ expect(
94
+ container.querySelector('[data-test-id="form-field-value"]')?.textContent,
95
+ ).toBe('Not set');
96
+ });
97
+ });
@@ -0,0 +1,136 @@
1
+ import { faker } from '@faker-js/faker';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import React from 'react';
4
+ import { createGroups } from '../../../helpers/storybook';
5
+ import { IconName } from '../../Icons';
6
+ import type { StatusDefinition } from './StatusView.models';
7
+ import { StatusViewField } from './StatusViewField';
8
+
9
+ enum EncodingState {
10
+ NotStarted = 'NOT_STARTED',
11
+ Waiting = 'WAITING',
12
+ InProgress = 'IN_PROGRESS',
13
+ Ready = 'READY',
14
+ Error = 'ERROR',
15
+ }
16
+
17
+ const encodingStatuses: Partial<Record<EncodingState, StatusDefinition>> = {
18
+ [EncodingState.NotStarted]: {
19
+ label: 'Not Started',
20
+ icon: IconName.CircleMinus,
21
+ color: 'var(--mosaic-neutral)',
22
+ },
23
+ [EncodingState.Waiting]: {
24
+ label: 'Waiting',
25
+ icon: IconName.Pause,
26
+ color: 'var(--mosaic-neutral-1)',
27
+ },
28
+ [EncodingState.InProgress]: {
29
+ label: 'In Progress',
30
+ icon: IconName.InProgress,
31
+ color: 'var(--mosaic-secondary)',
32
+ },
33
+ [EncodingState.Ready]: {
34
+ label: 'Ready',
35
+ icon: IconName.Success,
36
+ color: 'var(--mosaic-success)',
37
+ },
38
+ [EncodingState.Error]: {
39
+ label: 'Error',
40
+ icon: IconName.Error,
41
+ color: 'var(--mosaic-error)',
42
+ },
43
+ };
44
+
45
+ const groups = createGroups({
46
+ Behavior: ['inlineMode', 'id', 'hideIfEmpty'],
47
+ Content: ['label', 'tooltipContent', 'value', 'statuses', 'fallback'],
48
+ Styling: ['className'],
49
+ });
50
+
51
+ const meta: Meta<typeof StatusViewField> = {
52
+ title: 'Primary Components/Form Elements/StatusViewField',
53
+ component: StatusViewField,
54
+ argTypes: {
55
+ ...groups,
56
+ value: {
57
+ control: { type: 'select' },
58
+ options: Object.values(EncodingState),
59
+ },
60
+ },
61
+ };
62
+ export default meta;
63
+
64
+ export const Main: StoryObj<typeof StatusViewField> = {
65
+ args: {
66
+ label: 'Encoding',
67
+ value: EncodingState.Ready,
68
+ statuses: encodingStatuses,
69
+ tooltipContent: faker.lorem.paragraph(2),
70
+ },
71
+ };
72
+
73
+ export const AllStates: StoryObj<typeof StatusViewField> = {
74
+ parameters: {
75
+ controls: { hideNoControlsWarning: true, exclude: /.*/g },
76
+ },
77
+ render: () => (
78
+ <div style={{ display: 'grid', gridGap: 20 }}>
79
+ {Object.values(EncodingState).map((state) => (
80
+ <StatusViewField
81
+ key={state}
82
+ label="Encoding"
83
+ value={state}
84
+ statuses={encodingStatuses}
85
+ />
86
+ ))}
87
+ </div>
88
+ ),
89
+ };
90
+
91
+ export const TextOnly: StoryObj<typeof StatusViewField> = {
92
+ args: {
93
+ label: 'Publish State',
94
+ value: 'PUBLISHED',
95
+ statuses: { PUBLISHED: { label: 'Published' } },
96
+ },
97
+ };
98
+
99
+ export const CustomColor: StoryObj<typeof StatusViewField> = {
100
+ args: {
101
+ label: 'Encoding',
102
+ value: EncodingState.InProgress,
103
+ statuses: {
104
+ [EncodingState.InProgress]: {
105
+ label: 'In Progress',
106
+ icon: IconName.InProgress,
107
+ color: '#9d7aed',
108
+ },
109
+ },
110
+ },
111
+ };
112
+
113
+ export const UnmappedValue: StoryObj<typeof StatusViewField> = {
114
+ parameters: {
115
+ controls: { hideNoControlsWarning: true, exclude: /.*/g },
116
+ },
117
+ render: () => (
118
+ <div style={{ display: 'grid', gridGap: 20 }}>
119
+ <StatusViewField
120
+ label="No Fallback"
121
+ value="SOMETHING_ELSE"
122
+ statuses={encodingStatuses}
123
+ />
124
+ <StatusViewField
125
+ label="With Fallback"
126
+ value="SOMETHING_ELSE"
127
+ statuses={encodingStatuses}
128
+ fallback={{
129
+ label: 'Unknown',
130
+ icon: IconName.Warning,
131
+ color: 'var(--mosaic-warning)',
132
+ }}
133
+ />
134
+ </div>
135
+ ),
136
+ };
@@ -0,0 +1,66 @@
1
+ import clsx from 'clsx';
2
+ import React from 'react';
3
+ import type { BaseFormElement } from '../Form.models';
4
+ import { FormElementContainer } from '../FormElementContainer';
5
+ import { StatusView } from './StatusView';
6
+ import { resolveStatus, type StatusDefinition } from './StatusView.models';
7
+
8
+ export interface StatusViewFieldProps<T extends string = string>
9
+ extends BaseFormElement {
10
+ /** Value to be displayed */
11
+ value?: T | null;
12
+ /** Maps each value of an enum (or plain string) to the way it is displayed */
13
+ statuses?: Partial<Record<T, StatusDefinition>>;
14
+ /** Used for values which are not part of the status map */
15
+ fallback?: StatusDefinition;
16
+ /** Sets whether the field should not be visible if there is no status to show (default: false) */
17
+ hideIfEmpty?: boolean;
18
+ /**
19
+ * Identifier for E2E testing to identify the form element type (default:
20
+ * `StatusView`). Fields which specialize this one set their own, so that
21
+ * their existing selectors keep working.
22
+ */
23
+ dataTestFieldType?: string;
24
+ }
25
+
26
+ /**
27
+ * Renders a status as an icon and a text into a form. The presentation of every
28
+ * value is declared through the `statuses` map, which can be keyed by a string
29
+ * enum.
30
+ * @example
31
+ * <StatusViewField
32
+ * label="Encoding"
33
+ * value={encodingState}
34
+ * statuses={{
35
+ * [EncodingState.Ready]: {
36
+ * label: 'Ready',
37
+ * icon: IconName.Success,
38
+ * color: 'var(--mosaic-success)',
39
+ * },
40
+ * }}
41
+ * />
42
+ */
43
+ export const StatusViewField = <T extends string = string>({
44
+ value,
45
+ statuses = {},
46
+ fallback,
47
+ hideIfEmpty = false,
48
+ dataTestFieldType = 'StatusView',
49
+ className = '',
50
+ ...rest
51
+ }: StatusViewFieldProps<T>): JSX.Element => {
52
+ if (hideIfEmpty && resolveStatus(value, statuses, fallback) === undefined) {
53
+ return <></>;
54
+ }
55
+
56
+ return (
57
+ <FormElementContainer
58
+ {...rest}
59
+ className={clsx('status-view-field-container', className)}
60
+ minHeight={'25px'}
61
+ dataTestFieldType={dataTestFieldType}
62
+ >
63
+ <StatusView value={value} statuses={statuses} fallback={fallback} />
64
+ </FormElementContainer>
65
+ );
66
+ };
@@ -58,6 +58,12 @@ export {
58
58
  type SingleLineTextProps,
59
59
  } from './SingleLineText/SingleLineText';
60
60
  export { SingleLineTextField } from './SingleLineText/SingleLineTextField';
61
+ export { StatusView, type StatusViewProps } from './StatusView/StatusView';
62
+ export type { StatusDefinition } from './StatusView/StatusView.models';
63
+ export {
64
+ StatusViewField,
65
+ type StatusViewFieldProps,
66
+ } from './StatusView/StatusViewField';
61
67
  export { Tags, type TagsProps } from './Tags/Tags';
62
68
  export { TagsField } from './Tags/TagsField';
63
69
  export { TextArea, type TextAreaProps } from './TextArea/TextArea';
@@ -43,6 +43,7 @@ export enum IconName {
43
43
  Minus,
44
44
  Mute,
45
45
  NavigateRight,
46
+ NewTabCreate,
46
47
  Pause,
47
48
  Play,
48
49
  Plus,
@@ -392,6 +392,15 @@ const NavigateRightIcon: React.FC<SvgElementProps> = (props) => (
392
392
  </SvgElement>
393
393
  );
394
394
 
395
+ const NewTabCreateIcon: React.FC<SvgElementProps> = (props) => (
396
+ <SvgElement {...props}>
397
+ <path
398
+ {...DEFAULT_PATH_PROPS}
399
+ d="M19.4,30.8h12.3v-13.3M23.1,8.2h-13.9v12.9M22.6,17.6l14.7-14.7M26.3,2.9h11v11M2.7,30.7h12.8M9.1,37.1v-12.8"
400
+ />
401
+ </SvgElement>
402
+ );
403
+
395
404
  const PauseIcon: React.FC<SvgElementProps> = (props) => (
396
405
  <SvgElement {...props}>
397
406
  <path
@@ -660,6 +669,7 @@ export const Icons: React.FC<IconsProps> = ({ icon, className, ...props }) => {
660
669
  [IconName.Minus]: MinusIcon,
661
670
  [IconName.Mute]: MuteIcon,
662
671
  [IconName.NavigateRight]: NavigateRightIcon,
672
+ [IconName.NewTabCreate]: NewTabCreateIcon,
663
673
  [IconName.Pause]: PauseIcon,
664
674
  [IconName.Play]: PlayIcon,
665
675
  [IconName.Plus]: PlusIcon,
@@ -1,31 +0,0 @@
1
- @import '../../../styles/common.scss';
2
-
3
- .container {
4
- .value {
5
- display: grid;
6
- grid-template-columns: 25px auto;
7
- color: var(--input-color, $input-color);
8
- font-size: var(--label-font-size, $label-font-size);
9
- align-items: center;
10
-
11
- .icon {
12
- height: 20px;
13
- width: 20px;
14
-
15
- svg {
16
- height: 100%;
17
- width: 100%;
18
- }
19
-
20
- &.true svg path,
21
- &.true svg circle {
22
- stroke: #707070;
23
- }
24
-
25
- &.false svg path,
26
- &.false svg circle {
27
- stroke: #b7b7b7;
28
- }
29
- }
30
- }
31
- }