@linzjs/lui 21.53.0 → 21.53.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 +7 -0
- package/dist/components/LuiSearchBox/LuiSearchBox.d.ts +8 -0
- package/dist/components/LuiSearchInput/LuiPassiveSearchInput.d.ts +9 -0
- package/dist/components/LuiSearchInput/LuiSearchInput.d.ts +3 -0
- package/dist/index.js +63 -60
- package/dist/index.js.map +1 -1
- package/dist/lui.css +40 -0
- package/dist/lui.css.map +1 -1
- package/dist/lui.esm.js +63 -60
- package/dist/lui.esm.js.map +1 -1
- package/dist/scss/Components/LuiSearchInput/LuiSearchInput.scss +33 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [21.53.1](https://github.com/linz/lui/compare/v21.53.0...v21.53.1) (2024-11-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **searchbox:** style padding for passive search input ([#1170](https://github.com/linz/lui/issues/1170)) ([1854c9f](https://github.com/linz/lui/commit/1854c9f46da1d42a189f7cbd1e2b6a77e2a02e79))
|
|
7
|
+
|
|
1
8
|
# [21.53.0](https://github.com/linz/lui/compare/v21.52.0...v21.53.0) (2024-11-04)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
2
|
import { LuiButtonProps } from '../LuiButton/LuiButton';
|
|
3
3
|
import { ISearchGroupedResult, ISearchResult } from '../LuiSearchInput/ResultsDisplay';
|
|
4
|
+
import { InputValidationResult } from '../LuiSearchInput/LuiPassiveSearchInput';
|
|
4
5
|
export interface ISearchMenuOption {
|
|
5
6
|
name?: string;
|
|
6
7
|
groupTitle?: string | ReactElement;
|
|
@@ -14,6 +15,13 @@ export interface ISearchMenuOption {
|
|
|
14
15
|
renderItem?: (item: any) => ReactElement;
|
|
15
16
|
icon?: ReactElement;
|
|
16
17
|
columnBreak?: boolean;
|
|
18
|
+
onSearch?: (searchString: string) => void;
|
|
19
|
+
validateInput?: (input: string) => InputValidationResult | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated customizedInput was designed to enhance search box input component diversity.
|
|
22
|
+
* But considering to keep the input memory be consistent among all the input components,
|
|
23
|
+
* uncontrolled customized components are hard to be coordinated.
|
|
24
|
+
*/
|
|
17
25
|
customizedInput?: React.ReactElement;
|
|
18
26
|
}
|
|
19
27
|
export interface ILuiSearchBoxProps {
|
|
@@ -16,4 +16,13 @@ export interface IPassiveSearchInputProps {
|
|
|
16
16
|
onClickInput?: () => void;
|
|
17
17
|
validateInput?: (input: string) => InputValidationResult | undefined;
|
|
18
18
|
}
|
|
19
|
+
export declare const ControlledPassiveSearchInputComponent: (props: IPassiveSearchInputProps & {
|
|
20
|
+
typedValue: string;
|
|
21
|
+
setTypedValue: (value: string) => void;
|
|
22
|
+
}) => JSX.Element;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This was created for client to easily customize the passive input component.
|
|
25
|
+
* But that is hard to keep input memory to be consistent with other input components.
|
|
26
|
+
* Has extracted the controlled version and let LuiSearchInput to align the input value.
|
|
27
|
+
*/
|
|
19
28
|
export declare const LuiPassiveSearchInput: (props: React.PropsWithChildren<IPassiveSearchInputProps>) => JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
2
|
import 'react-loading-skeleton/dist/skeleton.css';
|
|
3
3
|
import { ISearchGroupedResult, ISearchResult } from './ResultsDisplay';
|
|
4
|
+
import { InputValidationResult } from './LuiPassiveSearchInput';
|
|
4
5
|
export interface ISearchInputProps<SearchResult extends ISearchResult = ISearchResult> {
|
|
5
6
|
minCharactersForSearch: number;
|
|
6
7
|
placeholderText: string;
|
|
@@ -15,5 +16,7 @@ export interface ISearchInputProps<SearchResult extends ISearchResult = ISearchR
|
|
|
15
16
|
onClearCallback?: () => void;
|
|
16
17
|
onClickInput?: () => void;
|
|
17
18
|
externalSearch?: boolean;
|
|
19
|
+
onSearch?: (searchString: string) => void;
|
|
20
|
+
validateInput?: (input: string) => InputValidationResult | undefined;
|
|
18
21
|
}
|
|
19
22
|
export declare const LuiSearchInput: <SearchResult extends ISearchResult = ISearchResult>(props: React.PropsWithChildren<ISearchInputProps<SearchResult>>) => JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -42490,6 +42490,67 @@ var ResultsDisplay = function (_a) {
|
|
|
42490
42490
|
children));
|
|
42491
42491
|
};
|
|
42492
42492
|
|
|
42493
|
+
var ControlledPassiveSearchInputComponent = function (props) {
|
|
42494
|
+
var _a = React.useState(), inputValidationResult = _a[0], setInputValidationResult = _a[1];
|
|
42495
|
+
var inputRef = React.useRef(null);
|
|
42496
|
+
var typedValue = props.typedValue, setTypedValue = props.setTypedValue;
|
|
42497
|
+
// set focus to input box
|
|
42498
|
+
React.useEffect(function () {
|
|
42499
|
+
var _a;
|
|
42500
|
+
if (props.focusUpdate !== undefined)
|
|
42501
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
42502
|
+
}, [props.focusUpdate]);
|
|
42503
|
+
// validate input
|
|
42504
|
+
React.useEffect(function () {
|
|
42505
|
+
setInputValidationResult((props.validateInput && props.validateInput(typedValue)) || undefined);
|
|
42506
|
+
}, [typedValue]);
|
|
42507
|
+
function setInputValue(value) {
|
|
42508
|
+
setTypedValue(props.inputTransformer ? props.inputTransformer(value) : value);
|
|
42509
|
+
}
|
|
42510
|
+
function handleKeyDown(event) {
|
|
42511
|
+
switch (event.key) {
|
|
42512
|
+
case 'Enter':
|
|
42513
|
+
if (inputValidationResult &&
|
|
42514
|
+
inputValidationResult.stopProgress === true)
|
|
42515
|
+
return;
|
|
42516
|
+
props.onSearch(typedValue);
|
|
42517
|
+
}
|
|
42518
|
+
}
|
|
42519
|
+
var cancelIcon = typedValue !== '' ? (React__default["default"].createElement(LuiIcon, { alt: "clear", name: "ic_cancel_clear", size: "md", color: '#6b6966', spanProps: {
|
|
42520
|
+
onClick: function () {
|
|
42521
|
+
var _a;
|
|
42522
|
+
setInputValue('');
|
|
42523
|
+
(_a = props.onClearCallback) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
42524
|
+
}
|
|
42525
|
+
} })) : null;
|
|
42526
|
+
var searchIcon = typedValue === '' || (inputValidationResult === null || inputValidationResult === void 0 ? void 0 : inputValidationResult.stopProgress) === true ? (React__default["default"].createElement("div", { className: "LuiSearchInput-search-button-disabled" },
|
|
42527
|
+
React__default["default"].createElement(LuiIcon, { name: "ic_search", size: "md", alt: "search", color: '#989189' }))) : (React__default["default"].createElement("div", { onClick: function () { return props.onSearch(typedValue); }, className: "LuiSearchInput-search-button" },
|
|
42528
|
+
React__default["default"].createElement(LuiIcon, { name: "ic_search", size: "md", alt: "search", color: '#FFFFFF' })));
|
|
42529
|
+
return (React__default["default"].createElement("div", { className: "LuiSearchInput", onClick: props.onClickInput },
|
|
42530
|
+
React__default["default"].createElement("span", { className: "LuiSearchInput-inputWrapper" },
|
|
42531
|
+
React__default["default"].createElement("input", { type: "text", className: clsx('LuiSearchPassiveInput-input'), ref: inputRef, value: typedValue, placeholder: props.placeholderText, "aria-label": "Search", onChange: function (e) { return setInputValue(e.target.value); }, onKeyDown: handleKeyDown, onFocus: function (e) {
|
|
42532
|
+
e.target.select();
|
|
42533
|
+
}, style: { pointerEvents: 'auto' } }),
|
|
42534
|
+
React__default["default"].createElement("div", { className: "LuiSearchPassiveInput-buttons-panel" },
|
|
42535
|
+
cancelIcon,
|
|
42536
|
+
searchIcon)),
|
|
42537
|
+
inputValidationResult && inputValidationResult.userMessage && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
42538
|
+
React__default["default"].createElement("hr", { className: "LuiSearchInput-resultSeparator" }),
|
|
42539
|
+
React__default["default"].createElement("div", { "data-testid": "no-result-msg", className: "LuiSearchInput-disclaimer" }, inputValidationResult.userMessage))),
|
|
42540
|
+
props.disclaimer && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
42541
|
+
React__default["default"].createElement("hr", { className: "LuiSearchInput-resultSeparator" }),
|
|
42542
|
+
React__default["default"].createElement("div", { "data-testid": "disclaimer", className: "LuiSearchInput-disclaimer" }, props.disclaimer)))));
|
|
42543
|
+
};
|
|
42544
|
+
/**
|
|
42545
|
+
* @deprecated This was created for client to easily customize the passive input component.
|
|
42546
|
+
* But that is hard to keep input memory to be consistent with other input components.
|
|
42547
|
+
* Has extracted the controlled version and let LuiSearchInput to align the input value.
|
|
42548
|
+
*/
|
|
42549
|
+
var LuiPassiveSearchInput = function (props) {
|
|
42550
|
+
var _a = React.useState(props.initialValue ? props.initialValue : ''), typedValue = _a[0], setTypedValue = _a[1];
|
|
42551
|
+
return (React__default["default"].createElement(ControlledPassiveSearchInputComponent, __assign({ typedValue: typedValue, setTypedValue: setTypedValue }, props)));
|
|
42552
|
+
};
|
|
42553
|
+
|
|
42493
42554
|
function flatten(items) {
|
|
42494
42555
|
if (isGroupedResult(items)) {
|
|
42495
42556
|
return items.flatMap(function (item) { return item.items; });
|
|
@@ -42663,7 +42724,7 @@ var LuiSearchInput = function (props) {
|
|
|
42663
42724
|
else
|
|
42664
42725
|
return null;
|
|
42665
42726
|
}
|
|
42666
|
-
return (React__default["default"].createElement("div", { className: "LuiSearchInput", onClick: props.onClickInput },
|
|
42727
|
+
return props.onSearch ? (React__default["default"].createElement(ControlledPassiveSearchInputComponent, __assign({ typedValue: typedValue, setTypedValue: setTypedValue }, props, { minCharactersForSearch: props.minCharactersForSearch, placeholderText: props.placeholderText, onSearch: props.onSearch, disclaimer: props.disclaimer, initialValue: props.initialValue, inputTransformer: props.inputTransformer, focusUpdate: props.focusUpdate, onClearCallback: props.onClearCallback, onClickInput: props.onClickInput, validateInput: props.validateInput }))) : (React__default["default"].createElement("div", { className: "LuiSearchInput", onClick: props.onClickInput },
|
|
42667
42728
|
React__default["default"].createElement("span", { className: "LuiSearchInput-inputWrapper" },
|
|
42668
42729
|
searchIcon,
|
|
42669
42730
|
React__default["default"].createElement("input", { type: "text", className: clsx('LuiSearchInput-input'), ref: inputRef, value: typedValue, placeholder: props.placeholderText, "aria-label": "Search", onChange: function (e) { return setInputValue(e.target.value); }, onKeyDown: handleKeyDown, onFocus: function (e) {
|
|
@@ -42688,64 +42749,6 @@ var LuiSearchInput = function (props) {
|
|
|
42688
42749
|
React__default["default"].createElement("div", { "data-testid": "disclaimer", className: "LuiSearchInput-disclaimer" }, props.disclaimer)))));
|
|
42689
42750
|
};
|
|
42690
42751
|
|
|
42691
|
-
var LuiPassiveSearchInput = function (props) {
|
|
42692
|
-
var _a = React.useState(props.initialValue ? props.initialValue : ''), typedValue = _a[0], setTypedValue = _a[1];
|
|
42693
|
-
var _b = React.useState(), inputValidationResult = _b[0], setInputValidationResult = _b[1];
|
|
42694
|
-
var inputRef = React.useRef(null);
|
|
42695
|
-
// set focus to input box
|
|
42696
|
-
React.useEffect(function () {
|
|
42697
|
-
var _a;
|
|
42698
|
-
if (props.focusUpdate !== undefined)
|
|
42699
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
42700
|
-
}, [props.focusUpdate]);
|
|
42701
|
-
// validate input
|
|
42702
|
-
React.useEffect(function () {
|
|
42703
|
-
setInputValidationResult((props.validateInput && props.validateInput(typedValue)) || undefined);
|
|
42704
|
-
}, [typedValue]);
|
|
42705
|
-
function setInputValue(value) {
|
|
42706
|
-
setTypedValue(props.inputTransformer ? props.inputTransformer(value) : value);
|
|
42707
|
-
}
|
|
42708
|
-
function handleKeyDown(event) {
|
|
42709
|
-
switch (event.key) {
|
|
42710
|
-
case 'Enter':
|
|
42711
|
-
if (inputValidationResult &&
|
|
42712
|
-
inputValidationResult.stopProgress === true)
|
|
42713
|
-
return;
|
|
42714
|
-
props.onSearch(typedValue);
|
|
42715
|
-
}
|
|
42716
|
-
}
|
|
42717
|
-
var cancelIcon = typedValue !== '' ? (React__default["default"].createElement(LuiIcon, { alt: "clear", name: "ic_cancel_clear", size: "md", color: '#6b6966', spanProps: {
|
|
42718
|
-
onClick: function () {
|
|
42719
|
-
var _a;
|
|
42720
|
-
setInputValue('');
|
|
42721
|
-
(_a = props.onClearCallback) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
42722
|
-
}
|
|
42723
|
-
} })) : null;
|
|
42724
|
-
var searchIcon = typedValue === '' || (inputValidationResult === null || inputValidationResult === void 0 ? void 0 : inputValidationResult.stopProgress) === true ? (React__default["default"].createElement("div", { className: "LuiSearchInput-search-button-disabled" },
|
|
42725
|
-
React__default["default"].createElement(LuiIcon, { name: "ic_search", size: "md", alt: "search", color: '#989189' }))) : (React__default["default"].createElement("div", { onClick: function () { return props.onSearch(typedValue); }, className: "LuiSearchInput-search-button" },
|
|
42726
|
-
React__default["default"].createElement(LuiIcon, { name: "ic_search", size: "md", alt: "search", color: '#FFFFFF' })));
|
|
42727
|
-
return (React__default["default"].createElement("div", { className: "LuiSearchInput", onClick: props.onClickInput },
|
|
42728
|
-
React__default["default"].createElement("span", { className: "LuiSearchInput-inputWrapper" },
|
|
42729
|
-
React__default["default"].createElement("input", { type: "text", className: clsx('LuiSearchInput-input'), ref: inputRef, value: typedValue, placeholder: props.placeholderText, "aria-label": "Search", onChange: function (e) { return setInputValue(e.target.value); }, onKeyDown: handleKeyDown, onFocus: function (e) {
|
|
42730
|
-
e.target.select();
|
|
42731
|
-
}, style: { pointerEvents: 'auto' } }),
|
|
42732
|
-
React__default["default"].createElement("div", { style: {
|
|
42733
|
-
display: 'flex',
|
|
42734
|
-
flexDirection: 'row',
|
|
42735
|
-
paddingRight: '8px',
|
|
42736
|
-
gap: '14px',
|
|
42737
|
-
alignItems: 'center'
|
|
42738
|
-
} },
|
|
42739
|
-
cancelIcon,
|
|
42740
|
-
searchIcon)),
|
|
42741
|
-
inputValidationResult && inputValidationResult.userMessage && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
42742
|
-
React__default["default"].createElement("hr", { className: "LuiSearchInput-resultSeparator" }),
|
|
42743
|
-
React__default["default"].createElement("div", { "data-testid": "no-result-msg", className: "LuiSearchInput-disclaimer" }, inputValidationResult.userMessage))),
|
|
42744
|
-
props.disclaimer && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
42745
|
-
React__default["default"].createElement("hr", { className: "LuiSearchInput-resultSeparator" }),
|
|
42746
|
-
React__default["default"].createElement("div", { "data-testid": "disclaimer", className: "LuiSearchInput-disclaimer" }, props.disclaimer)))));
|
|
42747
|
-
};
|
|
42748
|
-
|
|
42749
42752
|
var resultStyle = { verticalAlign: 'middle' };
|
|
42750
42753
|
/**
|
|
42751
42754
|
* LuiSearchBox is a search input with select menu.
|
|
@@ -42823,7 +42826,7 @@ var LuiSearchBox = function (_a) {
|
|
|
42823
42826
|
? selectedMenuOption.renderItem
|
|
42824
42827
|
: function (item) {
|
|
42825
42828
|
return React__default["default"].createElement("span", { style: resultStyle }, item.description);
|
|
42826
|
-
}, disclaimer: selectedMenuOption.disclaimer, focusUpdate: autoFocus && isFocus ? focusUpdate : undefined, externalSearch: externalSearch, initialValue: !!externalSearch ? searchString : undefined, onClickInput: onClickInput, onClearCallback: onClearInput })))));
|
|
42829
|
+
}, disclaimer: selectedMenuOption.disclaimer, focusUpdate: autoFocus && isFocus ? focusUpdate : undefined, externalSearch: externalSearch, initialValue: !!externalSearch ? searchString : undefined, onClickInput: onClickInput, onClearCallback: onClearInput, onSearch: selectedMenuOption.onSearch, validateInput: selectedMenuOption.validateInput })))));
|
|
42827
42830
|
};
|
|
42828
42831
|
var LuiSearchBoxButton = React__default["default"].forwardRef(function (props, ref) {
|
|
42829
42832
|
var button = React.useMemo(function () {
|