@ssa-ui-kit/core 2.8.1 → 2.8.3

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,
@@ -16381,13 +16386,15 @@ function Typeahead_styles_EMOTION_STRINGIFIED_CSS_ERROR_() { return "You have tr
16381
16386
 
16382
16387
 
16383
16388
 
16389
+ // TODO: automatically calculate max-height
16390
+ // https://github.com/ssagroup/ui-kit/issues/385
16384
16391
  const TypeaheadOptionsBase = /*#__PURE__*/base_default()("ul", true ? {
16385
16392
  target: "e1vig1dw6"
16386
16393
  } : 0)("padding:0;margin:0;list-style:none;background:#fff;border-radius:8px;filter:", ({
16387
16394
  theme
16388
16395
  }) => `drop-shadow(-4px 4px 14px ${theme.colors.greyDarker14})`, ";backdrop-filter:", ({
16389
16396
  theme
16390
- }) => `drop-shadow(-4px 4px 14px ${theme.colors.greyDarker14})`, ";" + ( true ? "" : 0));
16397
+ }) => `drop-shadow(-4px 4px 14px ${theme.colors.greyDarker14})`, ";overflow-y:auto;max-height:350px;" + ( true ? "" : 0));
16391
16398
  const TypeaheadOption = /*#__PURE__*/base_default()("li", true ? {
16392
16399
  target: "e1vig1dw5"
16393
16400
  } : 0)("display:flex;align-items:center;padding:8px 16px;border:none;cursor:pointer;font-size:14px;gap:8px;padding:12px;height:40px;background:", ({
@@ -16724,6 +16731,8 @@ const Typeahead = ({
16724
16731
  register,
16725
16732
  onChange,
16726
16733
  onEmptyChange,
16734
+ onClearAll,
16735
+ onRemoveSelectedClick,
16727
16736
  renderOption
16728
16737
  }) => {
16729
16738
  const theme = (0,react_namespaceObject.useTheme)();
@@ -16747,7 +16756,9 @@ const Typeahead = ({
16747
16756
  register,
16748
16757
  onChange,
16749
16758
  onEmptyChange,
16750
- renderOption
16759
+ renderOption,
16760
+ onRemoveSelectedClick,
16761
+ onClearAll
16751
16762
  });
16752
16763
  return (0,jsx_runtime_namespaceObject.jsx)(TypeaheadContext.Provider, {
16753
16764
  value: hookResult,