@axinom/mosaic-ui 0.55.0-rc.0 → 0.55.0-rc.10

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 (34) hide show
  1. package/dist/components/DynamicDataList/helpers/useColumnDefs.d.ts +1 -1
  2. package/dist/components/DynamicDataList/helpers/useColumnDefs.d.ts.map +1 -1
  3. package/dist/components/FormElements/Select/Select.d.ts +15 -11
  4. package/dist/components/FormElements/Select/Select.d.ts.map +1 -1
  5. package/dist/components/FormElements/Select/SelectField.d.ts.map +1 -1
  6. package/dist/components/FormElements/SingleLineText/SingleLineText.d.ts.map +1 -1
  7. package/dist/components/FormElements/Tags/Tags.d.ts +2 -2
  8. package/dist/components/FormElements/Tags/Tags.d.ts.map +1 -1
  9. package/dist/components/FormElements/Tags/TagsField.d.ts +1 -1
  10. package/dist/components/FormElements/Tags/TagsField.d.ts.map +1 -1
  11. package/dist/index.es.js +4 -4
  12. package/dist/index.es.js.map +1 -1
  13. package/dist/index.js +4 -4
  14. package/dist/index.js.map +1 -1
  15. package/package.json +4 -3
  16. package/src/components/DynamicDataList/DynamicDataList.spec.tsx +1 -5
  17. package/src/components/DynamicDataList/DynamicDataList.tsx +1 -1
  18. package/src/components/DynamicDataList/DynamicListDataEntry/Renderers/createSelectRenderer/createSelectRenderer.spec.tsx +9 -4
  19. package/src/components/DynamicDataList/DynamicListDataEntry/Renderers/createSelectRenderer/createSelectRenderer.tsx +2 -2
  20. package/src/components/DynamicDataList/helpers/useColumnDefs.ts +4 -2
  21. package/src/components/FormElements/FileUploadControl/FileUploadControl.scss +2 -3
  22. package/src/components/FormElements/FileUploadControl/FileUploadControl.stories.tsx +0 -1
  23. package/src/components/FormElements/FileUploadControl/FileUploadControl.tsx +2 -2
  24. package/src/components/FormElements/Select/Select.scss +108 -59
  25. package/src/components/FormElements/Select/Select.spec.tsx +52 -43
  26. package/src/components/FormElements/Select/Select.stories.tsx +8 -10
  27. package/src/components/FormElements/Select/Select.tsx +138 -52
  28. package/src/components/FormElements/Select/SelectField.tsx +1 -0
  29. package/src/components/FormElements/SingleLineText/SingleLineText.tsx +23 -7
  30. package/src/components/FormElements/Tags/Tags.scss +16 -76
  31. package/src/components/FormElements/Tags/Tags.spec.tsx +69 -80
  32. package/src/components/FormElements/Tags/Tags.tsx +54 -62
  33. package/src/components/FormElements/Tags/TagsField.tsx +3 -13
  34. package/src/styles/variables.scss +8 -0
@@ -1,8 +1,9 @@
1
1
  import clsx from 'clsx';
2
2
  import React, {
3
- FormEvent,
3
+ ChangeEvent,
4
4
  PropsWithChildren,
5
5
  useEffect,
6
+ useMemo,
6
7
  useRef,
7
8
  useState,
8
9
  } from 'react';
@@ -10,13 +11,14 @@ import { CSSTransition, TransitionGroup } from 'react-transition-group';
10
11
  import { noop } from '../../../helpers/utils';
11
12
  import { Button, ButtonContext } from '../../Buttons';
12
13
  import { IconName } from '../../Icons';
13
- import { BaseFormControl, BaseSelectEvents } from '../Form.models';
14
+ import { BaseFormControl, BaseInputEvents } from '../Form.models';
14
15
  import { FormElementContainer } from '../FormElementContainer';
16
+ import { Select, SelectOption } from '../Select/Select';
15
17
  import classes from './Tags.scss';
16
18
 
17
19
  export interface TagsProps<T = string>
18
20
  extends BaseFormControl,
19
- BaseSelectEvents {
21
+ BaseInputEvents {
20
22
  /** If set, sets the form control value */
21
23
  value?: string[];
22
24
  /** Array of options that can be selected from */
@@ -52,33 +54,54 @@ export const Tags = <T,>({
52
54
 
53
55
  const [shouldAnimate, setShouldAnimate] = useState<boolean>(false);
54
56
 
55
- const ref = useRef<FormEvent<HTMLSelectElement>>();
57
+ const ref = useRef<ChangeEvent<HTMLInputElement>>();
58
+
59
+ const transformedOptions: SelectOption[] = useMemo(() => {
60
+ return tagsOptions.map((option) => {
61
+ if (valueKey && displayKey) {
62
+ return {
63
+ value: String(option[valueKey]),
64
+ label: String(option[displayKey]),
65
+ };
66
+ }
67
+ return { value: String(option), label: String(option) };
68
+ });
69
+ }, [displayKey, tagsOptions, valueKey]);
70
+
71
+ const visibleOptions = useMemo(() => {
72
+ return transformedOptions.filter(
73
+ (option) => !currentTags.includes(String(option.value)),
74
+ );
75
+ }, [currentTags, transformedOptions]);
56
76
 
57
77
  useEffect(() => {
58
78
  setCurrentTags(value);
59
79
  }, [value]);
60
80
 
61
- const errorMsg: string | undefined = error;
62
-
63
81
  useEffect(() => {
64
82
  // Only emit if there is a current event
65
83
  if (ref.current) {
66
84
  onChange({
67
85
  ...ref.current,
68
-
69
- currentTarget: { value: currentTags as unknown as string },
70
- } as React.FormEvent<HTMLSelectElement>);
86
+ target: {
87
+ ...ref.current.target,
88
+ value: currentTags as unknown as string,
89
+ name,
90
+ id,
91
+ },
92
+ currentTarget: { name, id, value: currentTags as unknown as string },
93
+ } as ChangeEvent<HTMLInputElement>);
71
94
 
72
95
  // Resets event data
73
96
  ref.current = undefined;
74
97
  }
75
- }, [currentTags, onChange]);
98
+ }, [currentTags, id, name, onChange]);
76
99
 
77
100
  /**
78
101
  * Adds a tag to currently selected list
79
102
  * @param e Select FormEvent
80
103
  */
81
- function addTag(e: FormEvent<HTMLSelectElement>): void {
104
+ function addTag(e: ChangeEvent<HTMLInputElement>): void {
82
105
  setShouldAnimate(true);
83
106
 
84
107
  const newTag = e.currentTarget.value;
@@ -96,7 +119,7 @@ export const Tags = <T,>({
96
119
  */
97
120
  function removeTag(idx: number, e: unknown): void {
98
121
  // Set event data
99
- ref.current = e as FormEvent<HTMLSelectElement>;
122
+ ref.current = e as ChangeEvent<HTMLInputElement>;
100
123
 
101
124
  setCurrentTags((prevState) =>
102
125
  prevState.filter((_: string, i: number) => i !== idx),
@@ -119,59 +142,28 @@ export const Tags = <T,>({
119
142
  <FormElementContainer
120
143
  {...rest}
121
144
  className={clsx(classes.container, 'tags-container', className)}
122
- error={errorMsg}
145
+ error={error}
123
146
  dataTestFieldType="Tags"
124
147
  >
125
148
  <div className={clsx(classes.tagsWrapper)}>
126
- <select
127
- className={clsx({ [classes.hasError]: errorMsg !== undefined })}
128
- id={id}
129
- name={name}
130
- disabled={disabled}
131
- autoFocus={autoFocus}
132
- onBlur={onBlur}
133
- onFocus={onFocus}
134
- onChange={(e) => {
135
- e.persist();
136
- e.target?.blur();
137
- addTag(e);
138
- }}
139
- hidden={currentTags.length === tagsOptions.length}
140
- >
141
- {[
142
- <option key={'eae2713d-1a32-4bdb-8f87-c7e1f7e2a3b2'} value={''}>
143
- {dropDownLabel}
144
- </option>,
145
- ].concat(
146
- tagsOptions
147
- .filter((currentTag: T) => {
148
- if (typeof currentTag === 'string') {
149
- return !currentTags.includes(currentTag);
150
- } else if (valueKey) {
151
- return !currentTags.includes(String(currentTag[valueKey]));
152
- }
153
- })
154
- .map((option) => {
155
- if (typeof option === 'string') {
156
- return (
157
- <option key={option} value={option}>
158
- {option}
159
- </option>
160
- );
161
- } else if (valueKey && displayKey) {
162
- return (
163
- <option
164
- key={String(option[valueKey])}
165
- value={String(option[valueKey])}
166
- >
167
- {String(option[displayKey])}
168
- </option>
169
- );
170
- }
171
- return <></>;
172
- }),
173
- )}
174
- </select>
149
+ {currentTags.length < tagsOptions.length ? (
150
+ <Select
151
+ id={id}
152
+ name={`tags-select-${name}`}
153
+ className={clsx({
154
+ [classes.hasError]: error !== undefined,
155
+ })}
156
+ options={visibleOptions}
157
+ onChange={addTag}
158
+ blurOnSelect
159
+ disabled={disabled}
160
+ onBlur={onBlur}
161
+ onFocus={onFocus}
162
+ autoFocus={autoFocus}
163
+ inlineMode={true}
164
+ placeholder={dropDownLabel}
165
+ />
166
+ ) : null}
175
167
  <TransitionGroup component={null}>
176
168
  {currentTags.map((tag, idx) => (
177
169
  <CSSTransition
@@ -1,20 +1,10 @@
1
- import { useField } from 'formik';
2
1
  import React, { PropsWithChildren } from 'react';
3
2
  import { useFormikError } from '../useFormikError';
4
3
  import { Tags, TagsProps } from './Tags';
5
4
  export const TagsField = <T,>(
6
- props: PropsWithChildren<Omit<TagsProps<T>, 'error' | 'onChange'>>,
5
+ props: PropsWithChildren<Omit<TagsProps<T>, 'error'>>,
7
6
  ): JSX.Element => {
8
- const { name } = props;
9
- const error = useFormikError(name);
10
- const [field, , helpers] = useField(name);
7
+ const error = useFormikError(props.name);
11
8
 
12
- return (
13
- <Tags
14
- {...props}
15
- value={field.value}
16
- error={error}
17
- onChange={(e) => helpers.setValue(e.currentTarget.value)}
18
- />
19
- );
9
+ return <Tags {...props} error={error} />;
20
10
  };
@@ -311,3 +311,11 @@ $context-button-hover-border-color: $blue;
311
311
  $context-button-active-color: $blue;
312
312
  $icon-button-stroke-color: $blue;
313
313
  $icon-button-hover-color: $blue;
314
+
315
+ /* Autocomplete */
316
+ $popper-border-color: $blue;
317
+ $popper-trigger-button-color: $blue;
318
+ $popper-background-color: $light-gray-2;
319
+ $popper-item-font-size: 16px;
320
+ $popper-text-color: $blue;
321
+ $popper-background-selected-color: rgba($blue, 0.15);