@ssa-ui-kit/core 2.8.1 → 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.
@@ -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, selectedItems, isOpen, isDisabled, isMultiple, children, className, startIcon, endIcon, error, success, helperText, validationSchema, placeholder, startIconClassName, endIconClassName, optionsClassName, wrapperClassName, width, setValue, register, onChange, onEmptyChange, renderOption, }: TypeaheadProps) => import("@emotion/react/jsx-runtime").JSX.Element;
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;
@@ -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, 'selectedItems' | 'isDisabled' | 'children' | 'isMultiple' | 'onChange' | 'onEmptyChange' | 'renderOption' | 'isOpen' | 'className' | 'startIcon' | 'endIcon' | 'startIconClassName' | 'endIconClassName' | 'name' | 'register' | 'setValue' | 'validationSchema' | 'error' | 'success' | 'placeholder'>;
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, selectedItems, isDisabled, isMultiple, children, className, startIcon, endIcon, startIconClassName, endIconClassName, validationSchema, error, success, placeholder, register, setValue, onChange, onEmptyChange, renderOption, }: UseTypeaheadProps) => {
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
@@ -16109,6 +16109,8 @@ const useTypeahead = ({
16109
16109
  register,
16110
16110
  setValue,
16111
16111
  onChange,
16112
+ onClearAll,
16113
+ onRemoveSelectedClick,
16112
16114
  onEmptyChange,
16113
16115
  renderOption
16114
16116
  }) => {
@@ -16116,7 +16118,7 @@ const useTypeahead = ({
16116
16118
  const [isOpen, setIsOpen] = (0,external_react_namespaceObject.useState)(isInitOpen || false);
16117
16119
  const [selected, setSelected] = (0,external_react_namespaceObject.useState)(selectedItems || []);
16118
16120
  const [optionsWithKey, setOptionsWithKey] = (0,external_react_namespaceObject.useState)({});
16119
- const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)();
16121
+ const [isEmpty, setIsEmpty] = (0,external_react_namespaceObject.useState)(true);
16120
16122
  const [isFirstRender, setFirstRender] = (0,external_react_namespaceObject.useState)(true);
16121
16123
  const [items, setItems] = (0,external_react_namespaceObject.useState)();
16122
16124
  const [inputValue, setInputValue] = (0,external_react_namespaceObject.useState)('');
@@ -16143,13 +16145,8 @@ const useTypeahead = ({
16143
16145
  shouldDirty: !isFirstRender
16144
16146
  });
16145
16147
  }
16146
- if (!isFirstRender) {
16147
- setIsEmpty(!selected.length);
16148
- }
16148
+ handleOnEmptyChange(!selected.length);
16149
16149
  }, [selected]);
16150
- (0,external_react_namespaceObject.useEffect)(() => {
16151
- onEmptyChange?.(isEmpty);
16152
- }, [isEmpty]);
16153
16150
  (0,external_react_namespaceObject.useEffect)(() => {
16154
16151
  if (isDisabled && isOpen) {
16155
16152
  setIsOpen(false);
@@ -16254,6 +16251,14 @@ const useTypeahead = ({
16254
16251
  }
16255
16252
  }
16256
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
+ };
16257
16262
  const handleOpenChange = open => {
16258
16263
  if (!isDisabled) {
16259
16264
  setIsOpen(open);
@@ -16282,9 +16287,7 @@ const useTypeahead = ({
16282
16287
  setStatus('basic');
16283
16288
  useFormResult.clearErrors(name);
16284
16289
  useFormResult.trigger(name);
16285
- if (onChange) {
16286
- onChange(changingValue, isNewSelected);
16287
- }
16290
+ onChange?.(changingValue, isNewSelected);
16288
16291
  };
16289
16292
  const handleClearAll = event => {
16290
16293
  if (isDisabled) {
@@ -16298,6 +16301,7 @@ const useTypeahead = ({
16298
16301
  setFirstSuggestion('');
16299
16302
  useFormResult.trigger(name);
16300
16303
  inputRef.current?.focus();
16304
+ onClearAll?.();
16301
16305
  };
16302
16306
  const handleInputClick = event => {
16303
16307
  if (!isDisabled) {
@@ -16338,6 +16342,7 @@ const useTypeahead = ({
16338
16342
  const handleRemoveSelectedClick = selectedItem => event => {
16339
16343
  event.stopPropagation();
16340
16344
  handleChange(selectedItem);
16345
+ onRemoveSelectedClick?.(selectedItem);
16341
16346
  };
16342
16347
  return {
16343
16348
  isOpen,
@@ -16724,6 +16729,8 @@ const Typeahead = ({
16724
16729
  register,
16725
16730
  onChange,
16726
16731
  onEmptyChange,
16732
+ onClearAll,
16733
+ onRemoveSelectedClick,
16727
16734
  renderOption
16728
16735
  }) => {
16729
16736
  const theme = (0,react_namespaceObject.useTheme)();
@@ -16747,7 +16754,9 @@ const Typeahead = ({
16747
16754
  register,
16748
16755
  onChange,
16749
16756
  onEmptyChange,
16750
- renderOption
16757
+ renderOption,
16758
+ onRemoveSelectedClick,
16759
+ onClearAll
16751
16760
  });
16752
16761
  return (0,jsx_runtime_namespaceObject.jsx)(TypeaheadContext.Provider, {
16753
16762
  value: hookResult,