@xqmsg/ui-core 0.24.3 → 0.24.5

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.
@@ -18,6 +18,7 @@ export interface StackedSelectProps extends StackedInputProps {
18
18
  setValue: UseFormSetValue<FieldValues>;
19
19
  control: Control<FieldValues, any>;
20
20
  handleOnChange: (value?: string) => void;
21
+ loadingOptions?: boolean;
21
22
  }
22
23
 
23
24
  /**
@@ -34,6 +35,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
34
35
  disabled,
35
36
  value,
36
37
  fullOptions,
38
+ loadingOptions,
37
39
  ...props
38
40
  },
39
41
  _ref
@@ -91,7 +93,10 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
91
93
  };
92
94
 
93
95
  const handleOnKeyDown: KeyboardEventHandler<HTMLInputElement> = e => {
94
- const initialOptionIndex = options[0].value === 'section_header' ? 1 : 0;
96
+ const initialOptionIndex =
97
+ filteredOptions.length && filteredOptions[0].value === 'section_header'
98
+ ? 1
99
+ : 0;
95
100
 
96
101
  if (
97
102
  !isFocussed &&
@@ -101,7 +106,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
101
106
  return setOptionIndex(initialOptionIndex);
102
107
  }
103
108
 
104
- if (isFocussed) {
109
+ if (isFocussed && filteredOptions.length > 0) {
105
110
  if (
106
111
  optionIndex === null &&
107
112
  (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')
@@ -111,8 +116,8 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
111
116
 
112
117
  if (e.key === 'ArrowUp' && optionIndex !== null && optionIndex > 0) {
113
118
  const incrementValue =
114
- options[optionIndex - 1] &&
115
- options[optionIndex - 1].value === 'section_header'
119
+ filteredOptions[optionIndex - 1] &&
120
+ filteredOptions[optionIndex - 1].value === 'section_header'
116
121
  ? 2
117
122
  : 1;
118
123
  setOptionIndex(optionIndex - incrementValue);
@@ -126,11 +131,11 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
126
131
  if (
127
132
  e.key === 'ArrowDown' &&
128
133
  optionIndex !== null &&
129
- optionIndex < options.length
134
+ optionIndex < filteredOptions.length
130
135
  ) {
131
136
  const incrementValue =
132
- options[optionIndex + 1] &&
133
- options[optionIndex + 1].value === 'section_header'
137
+ filteredOptions[optionIndex + 1] &&
138
+ filteredOptions[optionIndex + 1].value === 'section_header'
134
139
  ? 2
135
140
  : 1;
136
141
  setOptionIndex(optionIndex + incrementValue);
@@ -142,7 +147,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
142
147
  }
143
148
 
144
149
  if (e.key === 'Enter' && optionIndex !== null) {
145
- const option = options.find((_, idx) => optionIndex === idx);
150
+ const option = filteredOptions.find((_, idx) => optionIndex === idx);
146
151
  if (!option) return;
147
152
 
148
153
  if (handleOnChange) {
@@ -191,12 +196,13 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
191
196
 
192
197
  const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {
193
198
  const initialOptionIndex =
194
- filteredOptions[0]?.value === 'section_header' ? 1 : 0;
199
+ filteredOptions.length && filteredOptions[0]?.value === 'section_header'
200
+ ? 1
201
+ : 0;
195
202
  setOptionIndex(initialOptionIndex);
196
203
  const { value } = e.target;
197
204
  setSearchValue(value);
198
205
  };
199
- console.log(searchValue);
200
206
 
201
207
  return (
202
208
  <Box ref={dropdownRef} position="relative">
@@ -206,7 +212,8 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
206
212
  {...props}
207
213
  ref={_ref}
208
214
  onClick={() => setIsFocussed(!isFocussed)}
209
- cursor={isFocussed ? 'select' : 'pointer'}
215
+ cursor={isFocussed ? 'default' : 'pointer'}
216
+ color={loadingOptions ? 'transparent' : 'inital'}
210
217
  fontSize="13px"
211
218
  value={isFocussed ? searchValue : selectedOption}
212
219
  autoComplete="off"
@@ -227,6 +234,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
227
234
  onSelectItem={handleOnSelectItem}
228
235
  options={filteredOptions}
229
236
  optionIndex={optionIndex}
237
+ loading={loadingOptions}
230
238
  />
231
239
  )}
232
240
  </Box>
@@ -4,7 +4,6 @@ import { TextareaFieldProps } from '../InputTypes';
4
4
 
5
5
  export interface StackedTextareaProps extends TextareaFieldProps {
6
6
  isRequired?: boolean;
7
- allowDefault?: boolean;
8
7
  variant: string;
9
8
  label?: string;
10
9
  }
@@ -15,7 +14,7 @@ export interface StackedTextareaProps extends TextareaFieldProps {
15
14
  const StackedTextarea = React.forwardRef<
16
15
  HTMLTextAreaElement,
17
16
  StackedTextareaProps
18
- >(({ isRequired, allowDefault, variant, label, ...props }, _ref) => {
17
+ >(({ isRequired, variant, label, ...props }, _ref) => {
19
18
  const isMobile = variant === 'mobile';
20
19
  if (isMobile) {
21
20
  return (
@@ -26,30 +25,11 @@ const StackedTextarea = React.forwardRef<
26
25
  variant={variant}
27
26
  fontSize="17px"
28
27
  placeholder={label ?? ''}
29
- onKeyDown={e => {
30
- if (e.key === 'Enter' && !allowDefault) {
31
- e.stopPropagation();
32
- e.preventDefault();
33
- }
34
- }}
35
28
  />
36
29
  </Flex>
37
30
  );
38
31
  }
39
- return (
40
- <Textarea
41
- ref={_ref}
42
- {...props}
43
- variant={variant}
44
- fontSize="13px"
45
- onKeyDown={e => {
46
- if (e.key === 'Enter' && !allowDefault) {
47
- e.stopPropagation();
48
- e.preventDefault();
49
- }
50
- }}
51
- />
52
- );
32
+ return <Textarea ref={_ref} {...props} variant={variant} fontSize="13px" />;
53
33
  });
54
34
 
55
35
  export default StackedTextarea;
@@ -1,5 +1,5 @@
1
1
  import React, { RefObject, useMemo } from 'react';
2
- import { Box, Flex } from '@chakra-ui/react';
2
+ import { Box, Flex, Spinner } from '@chakra-ui/react';
3
3
  import colors from '../../../../../src/theme/foundations/colors';
4
4
  import { FieldOption, FieldOptions } from '../../InputTypes';
5
5
 
@@ -10,6 +10,7 @@ export interface DropdownProps {
10
10
  position: 'top' | 'bottom';
11
11
  optionIndex?: number | null;
12
12
  children?: React.ReactNode;
13
+ loading?: boolean;
13
14
  }
14
15
 
15
16
  /**
@@ -22,9 +23,29 @@ export const Dropdown: React.FC<DropdownProps> = ({
22
23
  position,
23
24
  optionIndex,
24
25
  children,
26
+ loading = false,
25
27
  }) => {
26
28
  const DropdownContent = useMemo(() => {
27
- if (!options || options.length === 0) {
29
+ if (loading) {
30
+ return (
31
+ <Box
32
+ borderRadius="inherit"
33
+ fontSize="13px"
34
+ px="8px"
35
+ py="4px"
36
+ width="100%"
37
+ color={colors.label.primary.light}
38
+ bg="inherit"
39
+ whiteSpace="nowrap"
40
+ >
41
+ <Flex alignItems="center">
42
+ Loading
43
+ <Spinner size="xs" opacity={0.5} ml={2} />
44
+ </Flex>
45
+ </Box>
46
+ );
47
+ }
48
+ if (!loading && (!options || options.length === 0)) {
28
49
  return (
29
50
  <Box
30
51
  borderRadius="inherit"
@@ -47,10 +47,10 @@ export interface InputProps<T extends FieldValues = FieldValues>
47
47
  setError: UseFormSetError<T>;
48
48
  clearErrors: UseFormClearErrors<T>;
49
49
  leftElement?: React.ReactNode;
50
- allowDefault?: boolean;
51
50
  rightElement?: React.ReactNode;
52
51
  variant?: string;
53
52
  separators?: string[];
53
+ loadingOptions?: boolean;
54
54
  }
55
55
 
56
56
  /**
@@ -77,13 +77,13 @@ export function Input<T extends FieldValues>({
77
77
  disabled,
78
78
  rightElement,
79
79
  leftElement,
80
- allowDefault,
81
80
  variant = 'default',
82
81
  onChange,
83
82
  setValue,
84
83
  setError,
85
84
  clearErrors,
86
85
  separators,
86
+ loadingOptions = false,
87
87
  }: InputProps<T>) {
88
88
  function selectedInputField<T extends Element = Element>(
89
89
  onChange: ((e: ChangeEvent<T>) => void) | ((v?: string) => void),
@@ -111,7 +111,6 @@ export function Input<T extends FieldValues>({
111
111
  disabled={disabled}
112
112
  defaultValue={defaultValue}
113
113
  value={value}
114
- allowDefault={allowDefault}
115
114
  variant={variant}
116
115
  label={label as string}
117
116
  />
@@ -150,6 +149,7 @@ export function Input<T extends FieldValues>({
150
149
  defaultValue={defaultValue}
151
150
  placeholder={placeholder}
152
151
  fullOptions={fullOptions}
152
+ loadingOptions={loadingOptions}
153
153
  />
154
154
  );
155
155
  case 'textarea':
@@ -207,6 +207,7 @@ export function Input<T extends FieldValues>({
207
207
  setError={setError as UseFormSetError<FieldValues>}
208
208
  clearErrors={clearErrors as UseFormClearErrors<FieldValues>}
209
209
  placeholder={placeholder}
210
+ loadingOptions={loadingOptions}
210
211
  />
211
212
  );
212
213
  case 'pilled-text':
@@ -38,7 +38,6 @@ export interface SelectNativeProps<T extends FieldValues>
38
38
  setValue: UseFormSetValue<T>;
39
39
  setError: UseFormSetError<T>;
40
40
  clearErrors: UseFormClearErrors<T>;
41
- allowDefault?: boolean;
42
41
  }
43
42
 
44
43
  /**