@npm_leadtech/legal-lib-components 7.22.12 → 7.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/dist/css/styles.css +0 -3
- package/dist/images/componentsSvg/CloseIcon.d.ts +6 -0
- package/dist/images/componentsSvg/CloseIcon.js +2 -0
- package/dist/images/componentsSvg/CloseIcon.tsx +14 -0
- package/dist/images/svg/close-grey-24px.svg +3 -0
- package/dist/images/svg/search_24px.svg +3 -0
- package/dist/src/components/atoms/DialogMenuIcon/DialogMenuIcon.styled.js +1 -1
- package/dist/src/components/atoms/DialogMenuIcon/DialogMenuIcon.styled.ts +1 -1
- package/dist/src/components/atoms/DropdownInput/DropdownInput.d.ts +1 -1
- package/dist/src/components/atoms/DropdownInput/DropdownInput.js +9 -7
- package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.js +48 -36
- package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.ts +48 -37
- package/dist/src/components/atoms/DropdownInput/DropdownInput.tsx +55 -51
- package/dist/src/components/atoms/DropdownInput/DropdownInputProps.types.d.ts +1 -0
- package/dist/src/components/atoms/DropdownInput/DropdownInputProps.types.ts +1 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.d.ts +8 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.js +44 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.d.ts +1 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.js +48 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.ts +49 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.tsx +77 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.d.ts +37 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.js +1 -0
- package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.ts +40 -0
- package/dist/src/components/molecules/DesktopSearchBar/index.d.ts +2 -0
- package/dist/src/components/molecules/DesktopSearchBar/index.js +1 -0
- package/dist/src/components/molecules/DesktopSearchBar/index.ts +2 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.d.ts +3 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.js +38 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.d.ts +1 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.js +17 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.ts +18 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.tsx +55 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.d.ts +37 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.js +1 -0
- package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.ts +40 -0
- package/dist/src/components/molecules/MobileSearchBar/index.d.ts +2 -0
- package/dist/src/components/molecules/MobileSearchBar/index.js +1 -0
- package/dist/src/components/molecules/MobileSearchBar/index.ts +2 -0
- package/dist/src/components/molecules/SearchBar/SearchBar.js +17 -29
- package/dist/src/components/molecules/SearchBar/SearchBar.styled.js +4 -55
- package/dist/src/components/molecules/SearchBar/SearchBar.styled.ts +4 -55
- package/dist/src/components/molecules/SearchBar/SearchBar.tsx +31 -61
- package/dist/src/components/molecules/TextInput/Input.d.ts +0 -1
- package/dist/src/components/molecules/TextInput/Input.js +5 -4
- package/dist/src/components/molecules/TextInput/Input.tsx +7 -8
- package/dist/src/components/molecules/TextInput/TextInput.js +2 -2
- package/dist/src/components/molecules/TextInput/TextInput.scss +0 -4
- package/dist/src/components/molecules/TextInput/TextInput.tsx +1 -3
- package/dist/src/components/molecules/TextInput/TextInputProps.types.d.ts +0 -1
- package/dist/src/components/molecules/TextInput/TextInputProps.types.ts +0 -1
- package/dist/src/hooks/useSearchFunction.d.ts +10 -0
- package/dist/src/hooks/useSearchFunction.js +28 -0
- package/dist/src/hooks/useSearchFunction.tsx +63 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,72 +1,42 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
2
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
3
|
+
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
1
4
|
import React, { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { SearchIcon } from '../../../../images/componentsSvg/SearchIcon'
|
|
5
|
-
import { useWindowSize } from '../../../hooks/useWindowSize'
|
|
6
|
-
|
|
5
|
+
import { DesktopSearchBar } from '../DesktopSearchBar'
|
|
6
|
+
import { MobileSearchBar } from '../MobileSearchBar'
|
|
7
7
|
import { type SearchBarProps } from './SearchBarProps.types'
|
|
8
8
|
import { SearchBarStyled } from './SearchBar.styled'
|
|
9
|
+
import search from '../../../../images/svg/search_24px.svg'
|
|
9
10
|
|
|
10
|
-
export const SearchBar: React.FC<SearchBarProps> = (
|
|
11
|
-
const [
|
|
11
|
+
export const SearchBar: React.FC<SearchBarProps> = (props) => {
|
|
12
|
+
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
-
const _placeholder = windowSize.width === null || windowSize.width >= 720 ? '' : searchBarTexts.placeholder
|
|
15
|
-
const searchFunction = (text: string): void => {
|
|
16
|
-
const searchTerm = text.toLowerCase()
|
|
17
|
-
|
|
18
|
-
const productsFiltered = products.filter((item) => item.linkText.toLowerCase().includes(searchTerm))
|
|
19
|
-
const results = productsFiltered
|
|
20
|
-
.map((item) => {
|
|
21
|
-
const product = item.linkText
|
|
22
|
-
const preMatch = product.slice(0, product.toLowerCase().indexOf(searchTerm))
|
|
23
|
-
const match = product.slice(product.toLowerCase().indexOf(searchTerm), preMatch.length + searchTerm.length)
|
|
24
|
-
const postMatch = product.slice(product.toLowerCase().indexOf(searchTerm) + searchTerm.length, product.length)
|
|
25
|
-
const link = item.categoryUrl ? `${item.categoryUrl}/${item.slug}` : item.slug
|
|
26
|
-
return (
|
|
27
|
-
<li key={searchBarTexts.title} className='dropdown_input__item'>
|
|
28
|
-
<a
|
|
29
|
-
href={routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link)}
|
|
30
|
-
className='dropdown_input__link'
|
|
31
|
-
key={item.linkText}
|
|
32
|
-
onClick={(e) => {
|
|
33
|
-
e.preventDefault()
|
|
34
|
-
handleResultClick(product, routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link))
|
|
35
|
-
}}
|
|
36
|
-
title={product}
|
|
37
|
-
>
|
|
38
|
-
{preMatch}
|
|
39
|
-
<strong className='dropdown_input__link__emphasis'>{match}</strong>
|
|
40
|
-
{postMatch}
|
|
41
|
-
</a>
|
|
42
|
-
</li>
|
|
43
|
-
)
|
|
44
|
-
})
|
|
45
|
-
.slice(0, 9)
|
|
46
|
-
|
|
47
|
-
results.push(
|
|
48
|
-
<li key={searchBarTexts.title} className='dropdown_input__item'>
|
|
49
|
-
<a className='dropdown_input__link--all' title={searchBarTexts.title} href={routes.LEGAL_DOCUMENTS}>
|
|
50
|
-
{searchBarTexts.title}
|
|
51
|
-
</a>
|
|
52
|
-
</li>
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
setResults(results)
|
|
56
|
-
}
|
|
14
|
+
const closeModal = () => setIsModalOpen(false)
|
|
57
15
|
|
|
58
16
|
return (
|
|
59
17
|
<SearchBarStyled>
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
18
|
+
<div style={{ position: 'relative', display: 'flex' }}>
|
|
19
|
+
<a
|
|
20
|
+
onClick={() => setIsModalOpen(true)}
|
|
21
|
+
style={{
|
|
22
|
+
cursor: 'pointer',
|
|
23
|
+
width: '20px',
|
|
24
|
+
height: '20px'
|
|
25
|
+
}}
|
|
26
|
+
className='search-icon-container'
|
|
27
|
+
>
|
|
28
|
+
<img
|
|
29
|
+
src={search}
|
|
30
|
+
alt='search-icon-primary'
|
|
31
|
+
style={{
|
|
32
|
+
width: '100%',
|
|
33
|
+
height: '100%'
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
</a>
|
|
37
|
+
<DesktopSearchBar {...props} isOpen={isModalOpen} onClose={closeModal} />
|
|
38
|
+
<MobileSearchBar {...props} />
|
|
39
|
+
</div>
|
|
70
40
|
</SearchBarStyled>
|
|
71
41
|
)
|
|
72
42
|
}
|
|
@@ -14,7 +14,6 @@ interface InputProps {
|
|
|
14
14
|
onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
15
15
|
onKeyUp: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
16
16
|
country: string;
|
|
17
|
-
currrencySymbol?: string;
|
|
18
17
|
}
|
|
19
18
|
export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
20
19
|
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
|
+
import currencyEuro from '../../../../images/svg/currencyDE.svg';
|
|
4
|
+
import currencyOthers from '../../../../images/svg/currencyUS.svg';
|
|
3
5
|
import eyeCloseIcon from '../../../../images/svg/eye-close.svg';
|
|
4
6
|
import eyeIcon from '../../../../images/svg/eye-24-px.svg';
|
|
5
7
|
import percent from '../../../../images/svg/percent.svg';
|
|
6
|
-
export const Input = React.forwardRef(({ value, name, placeholder, className, onChange, onClick, onBlur, onKeyDown, onKeyUp, disabled, type = 'text', maxLength, country, prefix
|
|
8
|
+
export const Input = React.forwardRef(({ value, name, placeholder, className, onChange, onClick, onBlur, onKeyDown, onKeyUp, disabled, type = 'text', maxLength, country, prefix }, ref) => {
|
|
7
9
|
const [hidden, setHidden] = useState(true);
|
|
8
10
|
const showPassword = () => {
|
|
9
11
|
if (value !== null)
|
|
@@ -23,13 +25,12 @@ export const Input = React.forwardRef(({ value, name, placeholder, className, on
|
|
|
23
25
|
else if (isPercent) {
|
|
24
26
|
finalClassName += ' has-percent-suffix';
|
|
25
27
|
}
|
|
26
|
-
return (_jsxs(_Fragment, { children: [isCurrency && !!prefix && otherCurrency &&
|
|
28
|
+
return (_jsxs(_Fragment, { children: [isCurrency && !!prefix && otherCurrency && (_jsx("div", { className: 'input-icon-currency-prefix', children: _jsx("img", { src: currencyOthers, alt: 'currency' }) })), _jsx("input", { type: !hidden && type === 'password' ? 'text' : type, name: name, id: name, className: finalClassName, maxLength: maxLength, placeholder: placeholder, onChange: onChange, onClick: onClick, onKeyDown: onKeyDown, onKeyUp: onKeyUp, onBlur: onBlur, value: value, "data-qa": name, disabled: disabled, ref: ref }), type === 'password' && (_jsx("button", { type: 'button', className: 'input-icon-password-button', onClick: showPassword, onKeyDown: (e) => {
|
|
27
29
|
if (e.key === 'Enter')
|
|
28
30
|
showPassword();
|
|
29
31
|
}, children: _jsx("img", { src: hidden ? eyeIcon : eyeCloseIcon, alt: '' }) })), isCurrency
|
|
30
32
|
? !!prefix &&
|
|
31
|
-
euro &&
|
|
32
|
-
currrencySymbol && (_jsx("div", { className: 'input-icon-currency-suffix', children: _jsx("span", { children: currrencySymbol }) }))
|
|
33
|
+
euro && (_jsx("div", { className: 'input-icon-currency-suffix', children: _jsx("img", { src: currencyEuro, alt: 'currency' }) }))
|
|
33
34
|
: isPercent && (_jsx("div", { className: 'input-icon-percent-suffix', children: _jsx("img", { src: percent, alt: 'percent' }) }))] }));
|
|
34
35
|
});
|
|
35
36
|
Input.displayName = 'Input';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { useState } from 'react'
|
|
2
2
|
|
|
3
|
+
import currencyEuro from '../../../../images/svg/currencyDE.svg'
|
|
4
|
+
import currencyOthers from '../../../../images/svg/currencyUS.svg'
|
|
3
5
|
import eyeCloseIcon from '../../../../images/svg/eye-close.svg'
|
|
4
6
|
import eyeIcon from '../../../../images/svg/eye-24-px.svg'
|
|
5
7
|
import percent from '../../../../images/svg/percent.svg'
|
|
@@ -19,7 +21,6 @@ interface InputProps {
|
|
|
19
21
|
onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void
|
|
20
22
|
onKeyUp: (e: React.KeyboardEvent<HTMLInputElement>) => void
|
|
21
23
|
country: string
|
|
22
|
-
currrencySymbol?: string
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
@@ -38,8 +39,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
38
39
|
type = 'text',
|
|
39
40
|
maxLength,
|
|
40
41
|
country,
|
|
41
|
-
prefix
|
|
42
|
-
currrencySymbol
|
|
42
|
+
prefix
|
|
43
43
|
}: InputProps,
|
|
44
44
|
ref
|
|
45
45
|
) => {
|
|
@@ -66,9 +66,9 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
66
66
|
|
|
67
67
|
return (
|
|
68
68
|
<>
|
|
69
|
-
{isCurrency && !!prefix && otherCurrency &&
|
|
69
|
+
{isCurrency && !!prefix && otherCurrency && (
|
|
70
70
|
<div className='input-icon-currency-prefix'>
|
|
71
|
-
<
|
|
71
|
+
<img src={currencyOthers} alt='currency' />
|
|
72
72
|
</div>
|
|
73
73
|
)}
|
|
74
74
|
<input
|
|
@@ -102,10 +102,9 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
102
102
|
)}
|
|
103
103
|
{isCurrency
|
|
104
104
|
? !!prefix &&
|
|
105
|
-
euro &&
|
|
106
|
-
currrencySymbol && (
|
|
105
|
+
euro && (
|
|
107
106
|
<div className='input-icon-currency-suffix'>
|
|
108
|
-
<
|
|
107
|
+
<img src={currencyEuro} alt='currency' />
|
|
109
108
|
</div>
|
|
110
109
|
)
|
|
111
110
|
: isPercent && (
|
|
@@ -6,7 +6,7 @@ import { Input } from './Input';
|
|
|
6
6
|
import { TextInputLabel } from './TextInputLabel';
|
|
7
7
|
import { TextInputMessage } from './TextInputMessage';
|
|
8
8
|
import { TextInputTooltip } from './TextInputTooltip';
|
|
9
|
-
const TextInput = React.forwardRef(({ label, value, validate = true, isValidGroup = true, format = undefined, name, placeholder, onChange, onClick, onBlur, onKeyDown, onKeyUp, prefix = '', disabled, type = 'text', maxLength, errorMessage = '', notes, dialogMenuTip, tooltip = '', givenClass = '', children, country
|
|
9
|
+
const TextInput = React.forwardRef(({ label, value, validate = true, isValidGroup = true, format = undefined, name, placeholder, onChange, onClick, onBlur, onKeyDown, onKeyUp, prefix = '', disabled, type = 'text', maxLength, errorMessage = '', notes, dialogMenuTip, tooltip = '', givenClass = '', children, country }, ref) => {
|
|
10
10
|
const classnames = classNames('e-text', {
|
|
11
11
|
[givenClass]: givenClass,
|
|
12
12
|
'e-text--is-invalid': !validate,
|
|
@@ -26,7 +26,7 @@ const TextInput = React.forwardRef(({ label, value, validate = true, isValidGrou
|
|
|
26
26
|
if (Boolean(format) && type !== 'number' && type !== 'tel') {
|
|
27
27
|
return (_jsx(NumericFormat, { name: name, id: name, placeholder: placeholder, className: 'e-text-input', onChange: onChange, onClick: onClick, value: value, "data-qa": name, disabled: disabled, maxLength: maxLength, onBlur: onBlur }));
|
|
28
28
|
}
|
|
29
|
-
return (_jsx(Input, { name: name ?? '', type: type, prefix: prefix, placeholder: placeholder ?? '', className: 'e-text-input', onChange: handleChange, onClick: onClick ?? (() => { }), value: value, "data-qa": name, disabled: disabled ?? false, maxLength: maxLength, onBlur: onBlur ?? (() => { }), ref: ref, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, country: country
|
|
29
|
+
return (_jsx(Input, { name: name ?? '', type: type, prefix: prefix, placeholder: placeholder ?? '', className: 'e-text-input', onChange: handleChange, onClick: onClick ?? (() => { }), value: value, "data-qa": name, disabled: disabled ?? false, maxLength: maxLength, onBlur: onBlur ?? (() => { }), ref: ref, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, country: country }));
|
|
30
30
|
};
|
|
31
31
|
return (_jsxs("div", { className: classnames, children: [Boolean(children) && _jsx("div", { className: 'e-text__children', children: children }), _jsx(TextInputTooltip, { tooltip: tooltip }), _jsx(TextInputMessage, { errorMessage: errorMessage, validate: validate }), renderInput(), _jsx(TextInputLabel, { label: label, htmlFor: name, notes: notes, dialogMenuTip: dialogMenuTip })] }));
|
|
32
32
|
});
|
|
@@ -33,8 +33,7 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
|
|
|
33
33
|
tooltip = '',
|
|
34
34
|
givenClass = '',
|
|
35
35
|
children,
|
|
36
|
-
country
|
|
37
|
-
currrencySymbol
|
|
36
|
+
country
|
|
38
37
|
}: TextInputProps,
|
|
39
38
|
ref
|
|
40
39
|
) => {
|
|
@@ -94,7 +93,6 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
|
|
|
94
93
|
onKeyDown={handleKeyDown}
|
|
95
94
|
onKeyUp={handleKeyUp}
|
|
96
95
|
country={country}
|
|
97
|
-
currrencySymbol={currrencySymbol}
|
|
98
96
|
/>
|
|
99
97
|
)
|
|
100
98
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type SearchBarProps } from '../components/molecules/SearchBar/SearchBarProps.types';
|
|
3
|
+
interface SearchFunctionProps extends SearchBarProps {
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const useSearchFunction: (props: SearchFunctionProps) => {
|
|
7
|
+
results: React.JSX.Element[];
|
|
8
|
+
searchFunction: (text: string) => void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
export const useSearchFunction = (props) => {
|
|
4
|
+
const [results, setResults] = useState([]);
|
|
5
|
+
const searchFunction = (text) => {
|
|
6
|
+
const { products, searchBarTexts, routes, handleResultClick, onClose } = props;
|
|
7
|
+
const searchTerm = text.toLowerCase();
|
|
8
|
+
const productsFiltered = products.filter((item) => item.linkText.toLowerCase().includes(searchTerm));
|
|
9
|
+
const newResults = productsFiltered
|
|
10
|
+
.map((item) => {
|
|
11
|
+
const product = item.linkText;
|
|
12
|
+
const preMatch = product.slice(0, product.toLowerCase().indexOf(searchTerm));
|
|
13
|
+
const match = product.slice(product.toLowerCase().indexOf(searchTerm), preMatch.length + searchTerm.length);
|
|
14
|
+
const postMatch = product.slice(product.toLowerCase().indexOf(searchTerm) + searchTerm.length, product.length);
|
|
15
|
+
const link = item.categoryUrl ? `${item.categoryUrl}/${item.slug}` : item.slug;
|
|
16
|
+
return (_jsx("li", { className: 'dropdown_input__item', children: _jsxs("a", { href: routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link), className: 'dropdown_input__link', onClick: (e) => {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
handleResultClick(product, routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link));
|
|
19
|
+
if (onClose)
|
|
20
|
+
onClose();
|
|
21
|
+
}, title: product, children: [preMatch, _jsx("strong", { className: 'dropdown_input__link__emphasis', children: match }), postMatch] }) }, item.linkText));
|
|
22
|
+
})
|
|
23
|
+
.slice(0, 9);
|
|
24
|
+
newResults.push(_jsx("li", { className: 'dropdown_input__item', children: _jsx("a", { className: 'dropdown_input__link--all', title: searchBarTexts.title, href: routes.LEGAL_DOCUMENTS, onClick: onClose, children: searchBarTexts.title }) }, searchBarTexts.title));
|
|
25
|
+
setResults(newResults);
|
|
26
|
+
};
|
|
27
|
+
return { results, searchFunction };
|
|
28
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { type SearchBarProps } from '../components/molecules/SearchBar/SearchBarProps.types'
|
|
3
|
+
|
|
4
|
+
interface SearchFunctionProps extends SearchBarProps {
|
|
5
|
+
onClose?: () => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useSearchFunction = (props: SearchFunctionProps) => {
|
|
9
|
+
const [results, setResults] = useState<React.JSX.Element[]>([])
|
|
10
|
+
|
|
11
|
+
const searchFunction = (text: string): void => {
|
|
12
|
+
const { products, searchBarTexts, routes, handleResultClick, onClose } = props
|
|
13
|
+
const searchTerm = text.toLowerCase()
|
|
14
|
+
|
|
15
|
+
const productsFiltered = products.filter((item) => item.linkText.toLowerCase().includes(searchTerm))
|
|
16
|
+
|
|
17
|
+
const newResults = productsFiltered
|
|
18
|
+
.map((item) => {
|
|
19
|
+
const product = item.linkText
|
|
20
|
+
const preMatch = product.slice(0, product.toLowerCase().indexOf(searchTerm))
|
|
21
|
+
const match = product.slice(product.toLowerCase().indexOf(searchTerm), preMatch.length + searchTerm.length)
|
|
22
|
+
const postMatch = product.slice(product.toLowerCase().indexOf(searchTerm) + searchTerm.length, product.length)
|
|
23
|
+
const link = item.categoryUrl ? `${item.categoryUrl}/${item.slug}` : item.slug
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<li key={item.linkText} className='dropdown_input__item'>
|
|
27
|
+
<a
|
|
28
|
+
href={routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link)}
|
|
29
|
+
className='dropdown_input__link'
|
|
30
|
+
onClick={(e) => {
|
|
31
|
+
e.preventDefault()
|
|
32
|
+
handleResultClick(product, routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link))
|
|
33
|
+
if (onClose) onClose()
|
|
34
|
+
}}
|
|
35
|
+
title={product}
|
|
36
|
+
>
|
|
37
|
+
{preMatch}
|
|
38
|
+
<strong className='dropdown_input__link__emphasis'>{match}</strong>
|
|
39
|
+
{postMatch}
|
|
40
|
+
</a>
|
|
41
|
+
</li>
|
|
42
|
+
)
|
|
43
|
+
})
|
|
44
|
+
.slice(0, 9)
|
|
45
|
+
|
|
46
|
+
newResults.push(
|
|
47
|
+
<li key={searchBarTexts.title} className='dropdown_input__item'>
|
|
48
|
+
<a
|
|
49
|
+
className='dropdown_input__link--all'
|
|
50
|
+
title={searchBarTexts.title}
|
|
51
|
+
href={routes.LEGAL_DOCUMENTS}
|
|
52
|
+
onClick={onClose}
|
|
53
|
+
>
|
|
54
|
+
{searchBarTexts.title}
|
|
55
|
+
</a>
|
|
56
|
+
</li>
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
setResults(newResults)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { results, searchFunction }
|
|
63
|
+
}
|