@ssa-ui-kit/core 2.8.0 → 2.8.2
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.
- package/dist/components/Popover/types.d.ts +1 -0
- package/dist/components/Typeahead/Typeahead.d.ts +1 -1
- package/dist/components/Typeahead/types.d.ts +4 -2
- package/dist/components/Typeahead/useTypeahead.d.ts +1 -1
- package/dist/index.js +33 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,4 +8,4 @@ import { TypeaheadProps } from './types';
|
|
|
8
8
|
* Aria attributes are set according to
|
|
9
9
|
* https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
|
|
10
10
|
**/
|
|
11
|
-
export declare const Typeahead: ({ name, label,
|
|
11
|
+
export declare const Typeahead: ({ name, label, selectedItems, isOpen, isDisabled, isMultiple, children, className, startIcon, endIcon, error, success, helperText, validationSchema, placeholder, startIconClassName, endIconClassName, optionsClassName, wrapperClassName, width, setValue, register, onChange, onEmptyChange, onClearAll, onRemoveSelectedClick, renderOption, }: TypeaheadProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { FieldError, FieldValues, UseFormReturn, UseFormSetValue } from 'react-h
|
|
|
3
3
|
export type TypeaheadValue = string | number;
|
|
4
4
|
export type TypeaheadOptionProps = Record<string, TypeaheadValue>;
|
|
5
5
|
export interface TypeaheadProps {
|
|
6
|
-
|
|
6
|
+
selectedItems?: Array<TypeaheadValue>;
|
|
7
7
|
isMultiple?: boolean;
|
|
8
8
|
isDisabled?: boolean;
|
|
9
9
|
children?: React.ReactNode;
|
|
@@ -26,6 +26,8 @@ export interface TypeaheadProps {
|
|
|
26
26
|
setValue?: UseFormSetValue<FieldValues>;
|
|
27
27
|
register?: UseFormReturn['register'];
|
|
28
28
|
onChange?: (selectedItem: TypeaheadValue, isSelected: boolean) => void;
|
|
29
|
+
onClearAll?: () => void;
|
|
30
|
+
onRemoveSelectedClick?: (selectedItem: TypeaheadValue) => void;
|
|
29
31
|
onEmptyChange?: (isEmpty?: boolean) => void;
|
|
30
32
|
renderOption?: (data: {
|
|
31
33
|
value: string | number;
|
|
@@ -33,7 +35,7 @@ export interface TypeaheadProps {
|
|
|
33
35
|
label: string;
|
|
34
36
|
}) => React.ReactNode;
|
|
35
37
|
}
|
|
36
|
-
export type UseTypeaheadProps = Pick<TypeaheadProps, '
|
|
38
|
+
export type UseTypeaheadProps = Pick<TypeaheadProps, 'selectedItems' | 'isDisabled' | 'children' | 'isMultiple' | 'onChange' | 'onClearAll' | 'onRemoveSelectedClick' | 'onEmptyChange' | 'renderOption' | 'isOpen' | 'className' | 'startIcon' | 'endIcon' | 'startIconClassName' | 'endIconClassName' | 'name' | 'register' | 'setValue' | 'validationSchema' | 'error' | 'success' | 'placeholder'>;
|
|
37
39
|
export interface TypeaheadItemsListProps extends CommonProps {
|
|
38
40
|
children?: React.ReactNode;
|
|
39
41
|
noItemsMessage?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { MouseEventHandler } from 'react';
|
|
2
2
|
import { UseTypeaheadProps } from './types';
|
|
3
|
-
export declare const useTypeahead: ({ name, isOpen: isInitOpen,
|
|
3
|
+
export declare const useTypeahead: ({ name, isOpen: isInitOpen, selectedItems, isDisabled, isMultiple, children, className, startIcon, endIcon, startIconClassName, endIconClassName, validationSchema, error, success, placeholder, register, setValue, onChange, onClearAll, onRemoveSelectedClick, onEmptyChange, renderOption, }: UseTypeaheadProps) => {
|
|
4
4
|
isOpen: boolean;
|
|
5
5
|
isDisabled: boolean | undefined;
|
|
6
6
|
optionsWithKey: Record<string | number, Record<string, string | number>>;
|
package/dist/index.js
CHANGED
|
@@ -8309,6 +8309,7 @@ const usePopover = ({
|
|
|
8309
8309
|
modal,
|
|
8310
8310
|
open: controlledOpen,
|
|
8311
8311
|
onOpenChange: setControlledOpen,
|
|
8312
|
+
keyboardHandlers = true,
|
|
8312
8313
|
floatingOptions = {},
|
|
8313
8314
|
interactionsEnabled = 'click'
|
|
8314
8315
|
} = {}) => {
|
|
@@ -8332,7 +8333,8 @@ const usePopover = ({
|
|
|
8332
8333
|
});
|
|
8333
8334
|
const context = data.context;
|
|
8334
8335
|
const click = (0,external_floating_ui_react_namespaceObject.useClick)(context, {
|
|
8335
|
-
enabled: controlledOpen == null && ['click', 'both'].includes(interactionsEnabled)
|
|
8336
|
+
enabled: controlledOpen == null && ['click', 'both'].includes(interactionsEnabled),
|
|
8337
|
+
keyboardHandlers
|
|
8336
8338
|
});
|
|
8337
8339
|
const dismiss = (0,external_floating_ui_react_namespaceObject.useDismiss)(context, {
|
|
8338
8340
|
referencePress: true,
|
|
@@ -13357,6 +13359,7 @@ const FiltersMultiSelect = ({
|
|
|
13357
13359
|
}), (0,jsx_runtime_namespaceObject.jsx)(FieldControl, {
|
|
13358
13360
|
controlRef: inputRef,
|
|
13359
13361
|
children: (0,jsx_runtime_namespaceObject.jsxs)(Popover, {
|
|
13362
|
+
keyboardHandlers: false,
|
|
13360
13363
|
floatingOptions: {
|
|
13361
13364
|
onOpenChange: (open, event, reason) => {
|
|
13362
13365
|
if (disabled) return;
|
|
@@ -16090,7 +16093,7 @@ const useTypeaheadContext = () => external_react_namespaceObject.useContext(Type
|
|
|
16090
16093
|
const useTypeahead = ({
|
|
16091
16094
|
name = 'typeahead-input',
|
|
16092
16095
|
isOpen: isInitOpen,
|
|
16093
|
-
|
|
16096
|
+
selectedItems,
|
|
16094
16097
|
isDisabled,
|
|
16095
16098
|
isMultiple,
|
|
16096
16099
|
children,
|
|
@@ -16106,14 +16109,16 @@ const useTypeahead = ({
|
|
|
16106
16109
|
register,
|
|
16107
16110
|
setValue,
|
|
16108
16111
|
onChange,
|
|
16112
|
+
onClearAll,
|
|
16113
|
+
onRemoveSelectedClick,
|
|
16109
16114
|
onEmptyChange,
|
|
16110
16115
|
renderOption
|
|
16111
16116
|
}) => {
|
|
16112
16117
|
const inputName = `${name}-text`;
|
|
16113
16118
|
const [isOpen, setIsOpen] = (0,external_react_namespaceObject.useState)(isInitOpen || false);
|
|
16114
|
-
const [selected, setSelected] = (0,external_react_namespaceObject.useState)(
|
|
16119
|
+
const [selected, setSelected] = (0,external_react_namespaceObject.useState)(selectedItems || []);
|
|
16115
16120
|
const [optionsWithKey, setOptionsWithKey] = (0,external_react_namespaceObject.useState)({});
|
|
16116
|
-
const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)();
|
|
16121
|
+
const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)(true);
|
|
16117
16122
|
const [isFirstRender, setFirstRender] = (0,external_react_namespaceObject.useState)(true);
|
|
16118
16123
|
const [items, setItems] = (0,external_react_namespaceObject.useState)();
|
|
16119
16124
|
const [inputValue, setInputValue] = (0,external_react_namespaceObject.useState)('');
|
|
@@ -16140,13 +16145,8 @@ const useTypeahead = ({
|
|
|
16140
16145
|
shouldDirty: !isFirstRender
|
|
16141
16146
|
});
|
|
16142
16147
|
}
|
|
16143
|
-
|
|
16144
|
-
setIsEmpty(!selected.length);
|
|
16145
|
-
}
|
|
16148
|
+
handleOnEmptyChange(!selected.length);
|
|
16146
16149
|
}, [selected]);
|
|
16147
|
-
(0,external_react_namespaceObject.useEffect)(() => {
|
|
16148
|
-
onEmptyChange?.(isEmpty);
|
|
16149
|
-
}, [isEmpty]);
|
|
16150
16150
|
(0,external_react_namespaceObject.useEffect)(() => {
|
|
16151
16151
|
if (isDisabled && isOpen) {
|
|
16152
16152
|
setIsOpen(false);
|
|
@@ -16178,7 +16178,10 @@ const useTypeahead = ({
|
|
|
16178
16178
|
setOptionsWithKey(keyedOptions);
|
|
16179
16179
|
setItems(childItems);
|
|
16180
16180
|
setFirstRender(false);
|
|
16181
|
-
}, [
|
|
16181
|
+
}, [selectedItems, children]);
|
|
16182
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
16183
|
+
setSelected(selectedItems || []);
|
|
16184
|
+
}, [selectedItems]);
|
|
16182
16185
|
(0,external_react_namespaceObject.useEffect)(() => {
|
|
16183
16186
|
const childrenArray = external_react_default().Children.toArray(children).filter(Boolean);
|
|
16184
16187
|
const filteredOptions = [...childrenArray];
|
|
@@ -16248,6 +16251,14 @@ const useTypeahead = ({
|
|
|
16248
16251
|
}
|
|
16249
16252
|
}
|
|
16250
16253
|
}, [inputValue, items, selected]);
|
|
16254
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
16255
|
+
onEmptyChange?.(isEmpty);
|
|
16256
|
+
}, [isEmpty]);
|
|
16257
|
+
const handleOnEmptyChange = newIsEmptyValue => {
|
|
16258
|
+
if (newIsEmptyValue !== isEmpty) {
|
|
16259
|
+
setIsEmpty(newIsEmptyValue);
|
|
16260
|
+
}
|
|
16261
|
+
};
|
|
16251
16262
|
const handleOpenChange = open => {
|
|
16252
16263
|
if (!isDisabled) {
|
|
16253
16264
|
setIsOpen(open);
|
|
@@ -16276,9 +16287,7 @@ const useTypeahead = ({
|
|
|
16276
16287
|
setStatus('basic');
|
|
16277
16288
|
useFormResult.clearErrors(name);
|
|
16278
16289
|
useFormResult.trigger(name);
|
|
16279
|
-
|
|
16280
|
-
onChange(changingValue, isNewSelected);
|
|
16281
|
-
}
|
|
16290
|
+
onChange?.(changingValue, isNewSelected);
|
|
16282
16291
|
};
|
|
16283
16292
|
const handleClearAll = event => {
|
|
16284
16293
|
if (isDisabled) {
|
|
@@ -16292,6 +16301,7 @@ const useTypeahead = ({
|
|
|
16292
16301
|
setFirstSuggestion('');
|
|
16293
16302
|
useFormResult.trigger(name);
|
|
16294
16303
|
inputRef.current?.focus();
|
|
16304
|
+
onClearAll?.();
|
|
16295
16305
|
};
|
|
16296
16306
|
const handleInputClick = event => {
|
|
16297
16307
|
if (!isDisabled) {
|
|
@@ -16332,6 +16342,7 @@ const useTypeahead = ({
|
|
|
16332
16342
|
const handleRemoveSelectedClick = selectedItem => event => {
|
|
16333
16343
|
event.stopPropagation();
|
|
16334
16344
|
handleChange(selectedItem);
|
|
16345
|
+
onRemoveSelectedClick?.(selectedItem);
|
|
16335
16346
|
};
|
|
16336
16347
|
return {
|
|
16337
16348
|
isOpen,
|
|
@@ -16696,7 +16707,7 @@ var Typeahead_ref = true ? {
|
|
|
16696
16707
|
const Typeahead = ({
|
|
16697
16708
|
name = 'typeahead-search',
|
|
16698
16709
|
label,
|
|
16699
|
-
|
|
16710
|
+
selectedItems,
|
|
16700
16711
|
isOpen,
|
|
16701
16712
|
isDisabled,
|
|
16702
16713
|
isMultiple,
|
|
@@ -16718,12 +16729,14 @@ const Typeahead = ({
|
|
|
16718
16729
|
register,
|
|
16719
16730
|
onChange,
|
|
16720
16731
|
onEmptyChange,
|
|
16732
|
+
onClearAll,
|
|
16733
|
+
onRemoveSelectedClick,
|
|
16721
16734
|
renderOption
|
|
16722
16735
|
}) => {
|
|
16723
16736
|
const theme = (0,react_namespaceObject.useTheme)();
|
|
16724
16737
|
const hookResult = useTypeahead({
|
|
16725
16738
|
name,
|
|
16726
|
-
|
|
16739
|
+
selectedItems,
|
|
16727
16740
|
isOpen,
|
|
16728
16741
|
isDisabled,
|
|
16729
16742
|
isMultiple,
|
|
@@ -16741,7 +16754,9 @@ const Typeahead = ({
|
|
|
16741
16754
|
register,
|
|
16742
16755
|
onChange,
|
|
16743
16756
|
onEmptyChange,
|
|
16744
|
-
renderOption
|
|
16757
|
+
renderOption,
|
|
16758
|
+
onRemoveSelectedClick,
|
|
16759
|
+
onClearAll
|
|
16745
16760
|
});
|
|
16746
16761
|
return (0,jsx_runtime_namespaceObject.jsx)(TypeaheadContext.Provider, {
|
|
16747
16762
|
value: hookResult,
|
|
@@ -16759,6 +16774,7 @@ const Typeahead = ({
|
|
|
16759
16774
|
"data-testid": "typeahead-label",
|
|
16760
16775
|
children: label
|
|
16761
16776
|
}), (0,jsx_runtime_namespaceObject.jsxs)(Popover, {
|
|
16777
|
+
keyboardHandlers: false,
|
|
16762
16778
|
floatingOptions: {
|
|
16763
16779
|
onOpenChange: hookResult.handleOpenChange,
|
|
16764
16780
|
open: hookResult.isOpen
|