@xqmsg/ui-core 0.24.3 → 0.24.4

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>
@@ -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"
@@ -51,6 +51,7 @@ export interface InputProps<T extends FieldValues = FieldValues>
51
51
  rightElement?: React.ReactNode;
52
52
  variant?: string;
53
53
  separators?: string[];
54
+ loadingOptions?: boolean;
54
55
  }
55
56
 
56
57
  /**
@@ -84,6 +85,7 @@ export function Input<T extends FieldValues>({
84
85
  setError,
85
86
  clearErrors,
86
87
  separators,
88
+ loadingOptions = false,
87
89
  }: InputProps<T>) {
88
90
  function selectedInputField<T extends Element = Element>(
89
91
  onChange: ((e: ChangeEvent<T>) => void) | ((v?: string) => void),
@@ -150,6 +152,7 @@ export function Input<T extends FieldValues>({
150
152
  defaultValue={defaultValue}
151
153
  placeholder={placeholder}
152
154
  fullOptions={fullOptions}
155
+ loadingOptions={loadingOptions}
153
156
  />
154
157
  );
155
158
  case 'textarea':
@@ -207,6 +210,7 @@ export function Input<T extends FieldValues>({
207
210
  setError={setError as UseFormSetError<FieldValues>}
208
211
  clearErrors={clearErrors as UseFormClearErrors<FieldValues>}
209
212
  placeholder={placeholder}
213
+ loadingOptions={loadingOptions}
210
214
  />
211
215
  );
212
216
  case 'pilled-text':