@via-profit/ui-kit 0.1.0-rc.50 → 0.1.0-rc.51

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.
@@ -42,11 +42,39 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
42
42
  * Field placeholder
43
43
  */
44
44
  readonly placeholder?: string;
45
+ /**
46
+ * If is true then the asterisk will be displayed in label\
47
+ * If is ReactNode then ReactNode will be displayed in label
48
+ */
49
+ readonly requiredAsterisk?: boolean | React.ReactNode;
50
+ /**
51
+ * If true then TextField will be filled in full width on horizontal
52
+ */
53
+ readonly fullWidth?: boolean;
54
+ /**
55
+ * Native <input> element reference
56
+ */
57
+ readonly inputRef?: React.MutableRefObject<HTMLInputElement | null> | React.RefCallback<HTMLInputElement>;
58
+ /**
59
+ * End icon component
60
+ */
61
+ readonly endIcon?: React.ReactElement;
62
+ /**
63
+ * Start icon component
64
+ */
65
+ readonly startIcon?: React.ReactElement;
45
66
  /**
46
67
  * Field label text or element
47
68
  */
48
69
  readonly label?: TextFieldProps['label'];
70
+ /**
71
+ * If true then `errorText` value will be displayed under the TextField element
72
+ */
49
73
  readonly error?: TextFieldProps['error'];
74
+ /**
75
+ * Text or ReactNode to show in error element\
76
+ * Will be displaed only if `error` property is tru
77
+ */
50
78
  readonly errorText?: TextFieldProps['errorText'];
51
79
  readonly filterItems?: FilterItems<T>;
52
80
  readonly onChange?: OnChange<T, Multiple>;
@@ -34,9 +34,9 @@ const Spinner_1 = __importDefault(require("../LoadingIndicator/Spinner"));
34
34
  const IconClear_1 = __importDefault(require("./IconClear"));
35
35
  const context_1 = __importStar(require("./context"));
36
36
  const Autocomplete = react_1.default.forwardRef((props, ref) => {
37
- const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', placeholder, label, error, errorText, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, } = props;
37
+ const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, } = props;
38
38
  const menuRef = react_1.default.useRef(null);
39
- const inputRef = react_1.default.useRef(null);
39
+ const fieldInputRef = react_1.default.useRef(null);
40
40
  const isFocusedRef = react_1.default.useRef(false);
41
41
  const { state, dispatch } = (0, context_1.default)();
42
42
  const { currentOpen, filteredItems, inputValue, currentValue, anchorElement, currentLoading } = state;
@@ -51,7 +51,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
51
51
  }));
52
52
  setTimeout(() => {
53
53
  var _a;
54
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
54
+ (_a = fieldInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
55
55
  }, 15);
56
56
  }, [dispatch, onChange, items, multiple]);
57
57
  /**
@@ -144,11 +144,19 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
144
144
  dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading, filteredItems: items }));
145
145
  }, [isOpen, isLoading, items, dispatch]);
146
146
  return (react_1.default.createElement("div", null,
147
- react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, { placeholder: placeholder, label: label, error: error, errorText: errorText, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
147
+ react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, { placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
148
148
  if (anchorElement !== el) {
149
149
  dispatch((0, context_1.actionSetPartial)({ anchorElement: el }));
150
150
  }
151
- }, inputRef: inputRef, value: inputValue, onBlur: () => {
151
+ }, inputRef: el => {
152
+ fieldInputRef.current = el;
153
+ if (typeof inputRef === 'function') {
154
+ inputRef(el);
155
+ }
156
+ if (inputRef && typeof inputRef === 'object') {
157
+ inputRef.current = el;
158
+ }
159
+ }, value: inputValue, onBlur: () => {
152
160
  isFocusedRef.current = false;
153
161
  if (clearIfNotSelected) {
154
162
  dispatch((0, context_1.actionSetPartial)({
@@ -182,16 +190,20 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
182
190
  } })), [
183
191
  placeholder,
184
192
  label,
185
- multiple,
186
193
  error,
194
+ requiredAsterisk,
187
195
  errorText,
196
+ fullWidth,
197
+ startIcon,
188
198
  currentLoading,
189
199
  inputKeydownEvent,
190
200
  inputValue,
191
201
  clear,
192
202
  anchorElement,
193
203
  dispatch,
204
+ inputRef,
194
205
  clearIfNotSelected,
206
+ multiple,
195
207
  value,
196
208
  selectedItemToString,
197
209
  onRequestOpen,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.1.0-rc.50",
3
+ "version": "0.1.0-rc.51",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",