@npm_leadtech/legal-lib-components 7.22.1 → 7.22.4
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/svg/close-grey-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 +5 -4
- package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.js +38 -33
- package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.ts +38 -34
- package/dist/src/components/atoms/DropdownInput/DropdownInput.tsx +49 -52
- package/dist/src/components/molecules/SearchBar/SearchBar.js +83 -26
- package/dist/src/components/molecules/SearchBar/SearchBar.styled.js +51 -37
- package/dist/src/components/molecules/SearchBar/SearchBar.styled.ts +51 -37
- package/dist/src/components/molecules/SearchBar/SearchBar.tsx +130 -51
- 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
|
@@ -6,58 +6,72 @@ export const SearchBarStyled = styled.div`
|
|
|
6
6
|
.search {
|
|
7
7
|
width: calc(100% - 3rem);
|
|
8
8
|
margin: 0 1.5rem;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
@media ${device['landscape-tablets']} {
|
|
13
|
+
.search-toggle-link {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
width: 20px;
|
|
16
|
+
height: 20px;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
line-height: 20px;
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
margin: 0 1.5rem 0 0;
|
|
20
|
+
& > svg {
|
|
21
|
+
transition: fill 0.25s;
|
|
22
|
+
fill: currentColor;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
&:hover > svg {
|
|
26
|
+
fill: var(--primary-main);
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
min-width: 100%;
|
|
27
|
-
width: max-content;
|
|
29
|
+
.modal_searchbar + .search-toggle-link > svg {
|
|
30
|
+
fill: #078080;
|
|
28
31
|
}
|
|
32
|
+
}
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
&.modal_searchbar {
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 8px;
|
|
37
|
+
left: 32px;
|
|
38
|
+
z-index: 10000;
|
|
39
|
+
width: 400px;
|
|
40
|
+
max-width: 90vw;
|
|
41
|
+
background: none;
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
.modal_searchbar__content {
|
|
44
|
+
background-color: var(--neutral-white);
|
|
45
|
+
padding: 1.5rem;
|
|
46
|
+
border-radius: 8px;
|
|
47
|
+
width: 100%;
|
|
48
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
color: var(--others-black);
|
|
50
|
+
@media ${device['laptop']} {
|
|
51
|
+
padding: 0;
|
|
52
|
+
border-radius: 8px 8px 0 0;
|
|
42
53
|
}
|
|
54
|
+
}
|
|
43
55
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
.modal_searchbar__header {
|
|
57
|
+
display: flex;
|
|
58
|
+
justify-content: space-between;
|
|
59
|
+
align-items: center;
|
|
60
|
+
margin-bottom: 1rem;
|
|
48
61
|
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
62
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
.modal_searchbar__title {
|
|
64
|
+
font-size: 1.5rem;
|
|
65
|
+
font-weight: bold;
|
|
66
|
+
color: var(--others-black);
|
|
67
|
+
}
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
.dropdown_input {
|
|
70
|
+
.search {
|
|
71
|
+
width: 100%;
|
|
72
|
+
margin: 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
`
|
|
@@ -1,72 +1,151 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
2
|
+
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
3
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
4
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
3
5
|
import { DropdownInput } from '../../atoms/DropdownInput/DropdownInput'
|
|
4
6
|
import { SearchIcon } from '../../../../images/componentsSvg/SearchIcon'
|
|
5
7
|
import { useWindowSize } from '../../../hooks/useWindowSize'
|
|
6
8
|
|
|
7
9
|
import { type SearchBarProps } from './SearchBarProps.types'
|
|
8
10
|
import { SearchBarStyled } from './SearchBar.styled'
|
|
11
|
+
import { useSearchFunction } from '../../../hooks/useSearchFunction'
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
interface DesktopSearchBarProps extends SearchBarProps {
|
|
14
|
+
isOpen: boolean
|
|
15
|
+
onClose: () => void
|
|
16
|
+
}
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{searchBarTexts.title}
|
|
51
|
-
</a>
|
|
52
|
-
</li>
|
|
53
|
-
)
|
|
18
|
+
const DesktopSearchBar: React.FC<DesktopSearchBarProps> = ({
|
|
19
|
+
products,
|
|
20
|
+
searchBarTexts,
|
|
21
|
+
routes,
|
|
22
|
+
handleResultClick,
|
|
23
|
+
isOpen,
|
|
24
|
+
onClose
|
|
25
|
+
}) => {
|
|
26
|
+
const { results, searchFunction } = useSearchFunction({
|
|
27
|
+
products,
|
|
28
|
+
searchBarTexts,
|
|
29
|
+
routes,
|
|
30
|
+
handleResultClick,
|
|
31
|
+
onClose
|
|
32
|
+
})
|
|
33
|
+
const searchInputRef = useRef<HTMLInputElement>(null)
|
|
34
|
+
const searchBarContainerRef = useRef<HTMLDivElement>(null)
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
38
|
+
if (event.key === 'Escape') {
|
|
39
|
+
onClose()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
43
|
+
if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target as Node)) {
|
|
44
|
+
onClose()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isOpen) {
|
|
49
|
+
document.addEventListener('keydown', handleKeyDown)
|
|
50
|
+
document.addEventListener('mousedown', handleClickOutside)
|
|
51
|
+
if (searchInputRef.current) {
|
|
52
|
+
searchInputRef.current.focus()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
return () => {
|
|
57
|
+
document.removeEventListener('keydown', handleKeyDown)
|
|
58
|
+
document.removeEventListener('mousedown', handleClickOutside)
|
|
59
|
+
}
|
|
60
|
+
}, [isOpen, onClose])
|
|
61
|
+
|
|
62
|
+
if (!isOpen) {
|
|
63
|
+
return null
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
return (
|
|
59
|
-
<SearchBarStyled>
|
|
67
|
+
<SearchBarStyled ref={searchBarContainerRef} className='modal_searchbar'>
|
|
68
|
+
<div className='modal_searchbar__content'>
|
|
69
|
+
<DropdownInput
|
|
70
|
+
ref={searchInputRef}
|
|
71
|
+
name='search'
|
|
72
|
+
className='search'
|
|
73
|
+
placeholder={searchBarTexts.placeholder}
|
|
74
|
+
icon={<SearchIcon />}
|
|
75
|
+
onChange={searchFunction}
|
|
76
|
+
results={results}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
</SearchBarStyled>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const MobileSearchBar: React.FC<SearchBarProps> = ({ products, searchBarTexts, routes, handleResultClick }) => {
|
|
84
|
+
const { results, searchFunction } = useSearchFunction({
|
|
85
|
+
products,
|
|
86
|
+
searchBarTexts,
|
|
87
|
+
routes,
|
|
88
|
+
handleResultClick
|
|
89
|
+
})
|
|
90
|
+
const searchInputRef = useRef<HTMLInputElement>(null)
|
|
91
|
+
const searchBarContainerRef = useRef<HTMLDivElement>(null)
|
|
92
|
+
const isResultsVisible = Array.isArray(results) && results.length > 0
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
96
|
+
if (event.key === 'Escape') {
|
|
97
|
+
searchFunction('')
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
101
|
+
if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target as Node)) {
|
|
102
|
+
searchFunction('')
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (isResultsVisible) {
|
|
107
|
+
document.addEventListener('keydown', handleKeyDown)
|
|
108
|
+
document.addEventListener('mousedown', handleClickOutside)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return () => {
|
|
112
|
+
document.removeEventListener('keydown', handleKeyDown)
|
|
113
|
+
document.removeEventListener('mousedown', handleClickOutside)
|
|
114
|
+
}
|
|
115
|
+
}, [isResultsVisible, searchFunction])
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<SearchBarStyled ref={searchBarContainerRef}>
|
|
60
119
|
<DropdownInput
|
|
120
|
+
ref={searchInputRef}
|
|
61
121
|
name='search'
|
|
62
122
|
className='search'
|
|
63
|
-
placeholder={
|
|
123
|
+
placeholder={searchBarTexts.placeholder}
|
|
64
124
|
icon={<SearchIcon />}
|
|
65
|
-
onChange={
|
|
66
|
-
searchFunction(text)
|
|
67
|
-
}}
|
|
125
|
+
onChange={searchFunction}
|
|
68
126
|
results={results}
|
|
69
127
|
/>
|
|
70
128
|
</SearchBarStyled>
|
|
71
129
|
)
|
|
72
130
|
}
|
|
131
|
+
|
|
132
|
+
export const SearchBar: React.FC<SearchBarProps> = (props) => {
|
|
133
|
+
const windowSize = useWindowSize()
|
|
134
|
+
const isDesktop = !!windowSize.width && windowSize.width >= 960
|
|
135
|
+
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
136
|
+
|
|
137
|
+
const closeModal = () => setIsModalOpen(false)
|
|
138
|
+
|
|
139
|
+
if (isDesktop) {
|
|
140
|
+
return (
|
|
141
|
+
<div style={{ position: 'relative' }}>
|
|
142
|
+
<a onClick={() => setIsModalOpen(true)} className='search-toggle-link'>
|
|
143
|
+
<SearchIcon />
|
|
144
|
+
</a>
|
|
145
|
+
<DesktopSearchBar {...props} isOpen={isModalOpen} onClose={closeModal} />
|
|
146
|
+
</div>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return <MobileSearchBar {...props} />
|
|
151
|
+
}
|
|
@@ -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
|
+
}
|