@linzjs/lui 21.22.0 → 21.23.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [21.23.1](https://github.com/linz/lui/compare/v21.23.0...v21.23.1) (2024-02-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Splitter:** stop flashing behavior ([#1074](https://github.com/linz/lui/issues/1074)) ([3ebae79](https://github.com/linz/lui/commit/3ebae794183327d144d0d6c8d8985f3bb3326fdf))
7
+
8
+ # [21.23.0](https://github.com/linz/lui/compare/v21.22.0...v21.23.0) (2024-02-21)
9
+
10
+
11
+ ### Features
12
+
13
+ * **Extend pros for SearchInput:** TI-1738 ([#1099](https://github.com/linz/lui/issues/1099)) ([794be11](https://github.com/linz/lui/commit/794be111ff52e03a043e043722c0bba0f473bd43))
14
+
1
15
  # [21.22.0](https://github.com/linz/lui/compare/v21.21.0...v21.22.0) (2024-02-15)
2
16
 
3
17
 
@@ -1,6 +1,6 @@
1
1
  import React, { ReactElement } from 'react';
2
2
  import { LuiButtonProps } from '../LuiButton/LuiButton';
3
- import { ISearchResult, ISearchGroupedResult } from '../LuiSearchInput/LuiSearchInput';
3
+ import { ISearchGroupedResult, ISearchResult } from '../LuiSearchInput/ResultsDisplay';
4
4
  export interface ISearchMenuOption {
5
5
  name?: string;
6
6
  groupTitle?: string;
@@ -1,21 +1,12 @@
1
1
  import React, { ReactElement } from 'react';
2
2
  import 'react-loading-skeleton/dist/skeleton.css';
3
- export interface ISearchResult {
4
- id: string;
5
- description: string;
6
- }
7
- export interface ISearchGroupedResult {
8
- id: string;
9
- description: string;
10
- label: string;
11
- items: ISearchResult[];
12
- }
13
- export interface ISearchInputProps {
3
+ import { ISearchGroupedResult, ISearchResult } from './ResultsDisplay';
4
+ export interface ISearchInputProps<SearchResult extends ISearchResult = ISearchResult> {
14
5
  minCharactersForSearch: number;
15
6
  placeholderText: string;
16
- onSelectOption: (selectedOption: ISearchResult) => void;
17
- getOptions: (inputValue: string) => Promise<ISearchResult[] | ISearchGroupedResult[]>;
18
- renderItem: (item: ISearchResult) => ReactElement;
7
+ onSelectOption: (selectedOption: SearchResult) => void;
8
+ getOptions: (inputValue: string) => Promise<SearchResult[] | ISearchGroupedResult<SearchResult>[]>;
9
+ renderItem: (item: SearchResult) => ReactElement;
19
10
  disclaimer?: string;
20
11
  initialValue?: string;
21
12
  inputTransformer?: (input: string) => string;
@@ -23,5 +14,4 @@ export interface ISearchInputProps {
23
14
  focusUpdate?: boolean;
24
15
  onClearCallback?: () => void;
25
16
  }
26
- export declare function isGroupedResult(result: ISearchResult[] | ISearchGroupedResult[]): result is ISearchGroupedResult[];
27
- export declare const LuiSearchInput: React.FC<React.PropsWithChildren<ISearchInputProps>>;
17
+ export declare const LuiSearchInput: <SearchResult extends ISearchResult = ISearchResult>(props: React.PropsWithChildren<ISearchInputProps<SearchResult>>) => JSX.Element;
@@ -1,13 +1,23 @@
1
1
  import React, { ReactElement, RefObject } from 'react';
2
- import { ISearchGroupedResult, ISearchResult } from './LuiSearchInput';
3
- export interface IResultsProps {
2
+ export interface ISearchResult {
3
+ id: string;
4
+ description: string;
5
+ }
6
+ export interface ISearchGroupedResult<SearchResult extends ISearchResult = ISearchResult> {
7
+ id: string;
8
+ description: string;
9
+ label: string;
10
+ items: SearchResult[];
11
+ }
12
+ export interface IResultsProps<SearchResult extends ISearchResult = ISearchResult> {
4
13
  selectedId: string;
5
14
  isLoading: boolean;
6
15
  onClick: (id: string) => void;
7
16
  setSelectedId: (id: string) => void;
8
- renderItem: (item: ISearchResult) => ReactElement;
9
- results: ISearchResult[] | ISearchGroupedResult[];
17
+ renderItem: (item: SearchResult) => ReactElement;
18
+ results: SearchResult[] | ISearchGroupedResult<SearchResult>[];
10
19
  selectedRef: RefObject<HTMLDivElement>;
11
20
  }
12
- declare const ResultsDisplay: React.FC<React.PropsWithChildren<IResultsProps>>;
21
+ export declare function isGroupedResult<SearchResult extends ISearchResult = ISearchResult>(result: SearchResult[] | ISearchGroupedResult<SearchResult>[]): result is ISearchGroupedResult<SearchResult>[];
22
+ declare const ResultsDisplay: <SearchResults extends ISearchResult = ISearchResult>({ isLoading, onClick, children, selectedId, selectedRef, setSelectedId, results, renderItem, }: React.PropsWithChildren<IResultsProps<SearchResults>>) => ReactElement;
13
23
  export default ResultsDisplay;
@@ -2,6 +2,8 @@ import { RefObject } from 'react';
2
2
  /**
3
3
  * Ensures valueNow is set to a valid value within its allowed boundaries.
4
4
  * If boundaries and/or initialRatio are not specified, they will be defaulted.
5
+ * It's possible that multiple events trigger setValueNow simultaneosly with the same value.
6
+ * This multiple calls are expected, and setValueNow will resize only once.
5
7
  */
6
8
  export declare const useValueSeparator: ({ separator, ratio, onResized, boundaries: { min, max }, }: {
7
9
  ratio?: number | undefined;
@@ -0,0 +1,5 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * Calls setValueNow when the separator attributes change.
4
+ */
5
+ export declare const useValueSeparatorEffects: (setValueNow: (val?: number) => void, separator: RefObject<HTMLDivElement>, ratio?: number) => void;
package/dist/index.d.ts CHANGED
@@ -37,7 +37,8 @@ export * from './components/LuiHeaderMenu/LuiHeaderMenus';
37
37
  export * from './components/LuiHeaderMenuV2/LuiHeaderMenusV2';
38
38
  export { LuiUpdatesSplashModal } from './components/LuiUpdateSplashModal/LuiUpdatesSplashModal';
39
39
  export { LuiModal, LuiAlertModal, LuiAlertModalButtons, } from './components/LuiModal/LuiModal';
40
- export { type ISearchInputProps, type ISearchGroupedResult, type ISearchResult, LuiSearchInput, } from './components/LuiSearchInput/LuiSearchInput';
40
+ export { type ISearchInputProps, LuiSearchInput, } from './components/LuiSearchInput/LuiSearchInput';
41
+ export { type ISearchGroupedResult, type ISearchResult, } from './components/LuiSearchInput/ResultsDisplay';
41
42
  export { type ISearchMenuOption, type ILuiSearchBoxProps, LuiSearchBox, } from './components/LuiSearchBox/LuiSearchBox';
42
43
  export { type ILuiSplitButtonProps, type ILuiSplitButtonMenuItemProps, LuiSplitButtonPosition, LuiSplitButtonMenuItem, LuiSplitButton, } from './components/LuiSplitButton/LuiSplitButton';
43
44
  export { LuiErrorPage } from './components/LuiErrorPage/LuiErrorPage';
package/dist/index.js CHANGED
@@ -42336,6 +42336,12 @@ function Skeleton({ count = 1, wrapper: Wrapper, className: customClassName, con
42336
42336
  }
42337
42337
 
42338
42338
  var SKELETON_COUNT = 3;
42339
+ function isGroupedResult(result) {
42340
+ if (result && result.length) {
42341
+ return (result[0].items !== undefined);
42342
+ }
42343
+ return false;
42344
+ }
42339
42345
  var ResultsDisplay = function (_a) {
42340
42346
  var isLoading = _a.isLoading, onClick = _a.onClick, children = _a.children, selectedId = _a.selectedId, selectedRef = _a.selectedRef, setSelectedId = _a.setSelectedId, results = _a.results, renderItem = _a.renderItem;
42341
42347
  var ResultLine = function (result) {
@@ -42367,12 +42373,6 @@ var ResultsDisplay = function (_a) {
42367
42373
  children));
42368
42374
  };
42369
42375
 
42370
- function isGroupedResult(result) {
42371
- if (result && result.length) {
42372
- return result[0].items !== undefined;
42373
- }
42374
- return false;
42375
- }
42376
42376
  function flatten(items) {
42377
42377
  if (isGroupedResult(items)) {
42378
42378
  return items.flatMap(function (item) { return item.items; });
@@ -58680,25 +58680,23 @@ var animateSeparator = function (separatorRef, animate) {
58680
58680
  };
58681
58681
 
58682
58682
  /**
58683
- * Ensures valueNow is set to a valid value within its allowed boundaries.
58684
- * If boundaries and/or initialRatio are not specified, they will be defaulted.
58683
+ * Moves separator as per ratio changes. Centers on first render if ratio is undefined.
58685
58684
  */
58686
- var useValueSeparator = function (_a) {
58687
- var separator = _a.separator, ratio = _a.ratio, onResized = _a.onResized, _b = _a.boundaries, min = _b.min, max = _b.max;
58688
- var prev = React.useRef();
58689
- var setValueNow = React.useCallback(function (val) {
58690
- var valueNow = getSeparatorAttributes({ ref: separator }).valueNow;
58691
- var value = val !== null && val !== void 0 ? val : (valueNow || min + (max - min) / 2);
58692
- var newValue = clampSeparator({ value: value, max: max, min: min });
58693
- resize(separator, newValue);
58694
- if (prev.current !== newValue) {
58695
- prev.current = newValue;
58696
- onResized === null || onResized === void 0 ? void 0 : onResized(newValue);
58697
- }
58698
- }, [onResized, min, max, prev]);
58685
+ var useRatioEffect = function (setValueNow, ratio) {
58686
+ var firstRun = React.useRef(true);
58699
58687
  React.useEffect(function () {
58700
- setValueNow(ratio);
58701
- }, [setValueNow, ratio]);
58688
+ if (firstRun.current || ratio !== undefined) {
58689
+ firstRun.current = false;
58690
+ // If ratio is undefined, setValueNow will place the separator in the middle as a starting point.
58691
+ // Whatever value is `the middle` will be determined by setValueNow
58692
+ setValueNow(ratio);
58693
+ }
58694
+ }, [setValueNow, ratio, firstRun]);
58695
+ };
58696
+ /**
58697
+ * Re-arranges the splitter if the limits or orientation change.
58698
+ */
58699
+ var useConfigEffect = function (setValueNow, separator) {
58702
58700
  React.useEffect(function () {
58703
58701
  var callback = function () {
58704
58702
  var value = getSeparatorAttributes({ ref: separator }).valueNow;
@@ -58711,6 +58709,11 @@ var useValueSeparator = function (_a) {
58711
58709
  });
58712
58710
  return function () { return observer.disconnect(); };
58713
58711
  }, [separator, setValueNow]);
58712
+ };
58713
+ /**
58714
+ * Broadcasts changes if separator aria-valuenow was altered.
58715
+ */
58716
+ var useValueNowEffect = function (setValueNow, separator) {
58714
58717
  React.useEffect(function () {
58715
58718
  var observer = new MutationObserver(function (_a) {
58716
58719
  var target = _a[0].target;
@@ -58725,6 +58728,36 @@ var useValueSeparator = function (_a) {
58725
58728
  observer.observe(separator.current, { attributeFilter: attributeFilter });
58726
58729
  return function () { return observer.disconnect(); };
58727
58730
  }, [separator, setValueNow]);
58731
+ };
58732
+ /**
58733
+ * Calls setValueNow when the separator attributes change.
58734
+ */
58735
+ var useValueSeparatorEffects = function (setValueNow, separator, ratio) {
58736
+ useRatioEffect(setValueNow, ratio);
58737
+ useConfigEffect(setValueNow, separator);
58738
+ useValueNowEffect(setValueNow, separator);
58739
+ };
58740
+
58741
+ /**
58742
+ * Ensures valueNow is set to a valid value within its allowed boundaries.
58743
+ * If boundaries and/or initialRatio are not specified, they will be defaulted.
58744
+ * It's possible that multiple events trigger setValueNow simultaneosly with the same value.
58745
+ * This multiple calls are expected, and setValueNow will resize only once.
58746
+ */
58747
+ var useValueSeparator = function (_a) {
58748
+ var separator = _a.separator, ratio = _a.ratio, onResized = _a.onResized, _b = _a.boundaries, min = _b.min, max = _b.max;
58749
+ var prev = React.useRef(null);
58750
+ var setValueNow = React.useCallback(function (val) {
58751
+ var valueNow = getSeparatorAttributes({ ref: separator }).valueNow;
58752
+ var value = val !== null && val !== void 0 ? val : (valueNow || min + (max - min) / 2);
58753
+ var newValue = clampSeparator({ value: value, max: max, min: min });
58754
+ resize(separator, newValue);
58755
+ if (prev.current !== newValue) {
58756
+ prev.current = newValue;
58757
+ onResized === null || onResized === void 0 ? void 0 : onResized(newValue);
58758
+ }
58759
+ }, [onResized, min, max, prev]);
58760
+ useValueSeparatorEffects(setValueNow, separator, ratio);
58728
58761
  return { setValueNow: setValueNow };
58729
58762
  };
58730
58763
  var resize = function (separator, value) {