@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
package/dist/css/styles.css
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M15.2462 5.92913C15.5706 5.60466 15.5706 5.07859 15.2462 4.75413C14.9217 4.42966 14.3956 4.42966 14.0712 4.75413L10.0003 8.82496L5.92949 4.75413C5.60503 4.42966 5.07896 4.42966 4.75449 4.75413C4.43002 5.07859 4.43003 5.60466 4.75449 5.92913L8.82533 9.99996L4.75449 14.0708C4.43003 14.3953 4.43002 14.9213 4.75449 15.2458C5.07896 15.5703 5.60502 15.5703 5.92949 15.2458L10.0003 11.175L14.0712 15.2458C14.3956 15.5703 14.9217 15.5703 15.2462 15.2458C15.5706 14.9213 15.5706 14.3953 15.2462 14.0708L11.1753 9.99996L15.2462 5.92913Z" fill="#B5BABD"/>
|
|
3
|
+
</svg>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DropdownInputProps } from './DropdownInputProps.types';
|
|
3
|
-
export declare const DropdownInput: React.
|
|
3
|
+
export declare const DropdownInput: React.ForwardRefExoticComponent<DropdownInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
3
|
-
import React, { useState } from 'react';
|
|
3
|
+
import React, { forwardRef, useState } from 'react';
|
|
4
4
|
import { DropdownInputStyled } from './DropdownInput.styled';
|
|
5
|
-
export const DropdownInput = ({ onChange, results, className = '', name, icon, placeholder }) => {
|
|
5
|
+
export const DropdownInput = forwardRef(({ onChange, results, className = '', name, icon, placeholder }, ref) => {
|
|
6
6
|
const [searchTerm, setSearchTerm] = useState('');
|
|
7
7
|
const updateInput = (e) => {
|
|
8
8
|
setSearchTerm(e.target.value);
|
|
@@ -11,7 +11,7 @@ export const DropdownInput = ({ onChange, results, className = '', name, icon, p
|
|
|
11
11
|
const resetInput = () => {
|
|
12
12
|
setSearchTerm('');
|
|
13
13
|
};
|
|
14
|
-
return (_jsxs(DropdownInputStyled, { className: `dropdown_input ${className}`, children: [_jsxs("div", { className: 'dropdown_input__container', children: [_jsx("input", { className: `dropdown_input__container__text_input ${icon ? 'with-icon' : ''}`, type: 'text', name: `dropdown_input_${name}`, placeholder: placeholder, value: searchTerm, onChange: (e) => {
|
|
14
|
+
return (_jsxs(DropdownInputStyled, { className: `dropdown_input ${className}`, children: [_jsxs("div", { className: 'dropdown_input__container', children: [_jsx("input", { ref: ref, className: `dropdown_input__container__text_input ${icon ? 'with-icon' : ''}`, type: 'text', name: `dropdown_input_${name}`, placeholder: placeholder, value: searchTerm, onChange: (e) => {
|
|
15
15
|
updateInput(e);
|
|
16
16
|
} }), _jsxs("div", { className: `dropdown_input__container__icon ${searchTerm ? 'active' : ''}`, children: [icon &&
|
|
17
17
|
React.cloneElement(icon, {
|
|
@@ -21,4 +21,5 @@ export const DropdownInput = ({ onChange, results, className = '', name, icon, p
|
|
|
21
21
|
}, onKeyDown: () => {
|
|
22
22
|
resetInput();
|
|
23
23
|
} }))] })] }), searchTerm && !!results?.length && _jsx("ul", { className: 'dropdown_input__results', children: results })] }));
|
|
24
|
-
};
|
|
24
|
+
});
|
|
25
|
+
DropdownInput.displayName = 'DropdownInput';
|
|
@@ -2,32 +2,13 @@ import { device } from '../../../globalStyles/breakpoints';
|
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
export const DropdownInputStyled = styled.div `
|
|
4
4
|
position: relative;
|
|
5
|
-
padding-left: 1.5rem;
|
|
6
|
-
padding-right: 1.5rem;
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
@media ${device['landscape-tablets']} {
|
|
7
|
+
padding: 1rem 2rem;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.dropdown_input__container {
|
|
15
|
-
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.dropdown_input__results {
|
|
19
|
-
opacity: 1;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.dropdown_input__container__icon {
|
|
24
|
-
color: var(--primary-main);
|
|
25
|
-
|
|
26
|
-
svg {
|
|
27
|
-
fill: var(--primary-main);
|
|
28
|
-
stroke: var(--primary-main);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
10
|
+
a {
|
|
11
|
+
text-decoration: none;
|
|
31
12
|
}
|
|
32
13
|
|
|
33
14
|
.dropdown_input__container {
|
|
@@ -41,6 +22,23 @@ export const DropdownInputStyled = styled.div `
|
|
|
41
22
|
border-bottom: 2px solid transparent;
|
|
42
23
|
}
|
|
43
24
|
|
|
25
|
+
&:focus-within {
|
|
26
|
+
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
27
|
+
|
|
28
|
+
@media ${device['landscape-tablets']} {
|
|
29
|
+
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.dropdown_input__container__icon {
|
|
33
|
+
color: var(--primary-main);
|
|
34
|
+
|
|
35
|
+
svg {
|
|
36
|
+
fill: var(--primary-main);
|
|
37
|
+
stroke: var(--primary-main);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
44
42
|
.dropdown_input__container__text_input {
|
|
45
43
|
width: 100%;
|
|
46
44
|
height: 100%;
|
|
@@ -55,7 +53,7 @@ export const DropdownInputStyled = styled.div `
|
|
|
55
53
|
color: var(--neutral-neutral-3);
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
|
|
56
|
+
&.with-icon {
|
|
59
57
|
padding-right: 2rem;
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -79,6 +77,7 @@ export const DropdownInputStyled = styled.div `
|
|
|
79
77
|
height: 1.5rem;
|
|
80
78
|
opacity: 1;
|
|
81
79
|
margin-right: 0.25rem;
|
|
80
|
+
cursor: pointer;
|
|
82
81
|
|
|
83
82
|
path {
|
|
84
83
|
transition: all 0.25s;
|
|
@@ -115,21 +114,27 @@ export const DropdownInputStyled = styled.div `
|
|
|
115
114
|
.dropdown_input__results {
|
|
116
115
|
transition: all 0.25s;
|
|
117
116
|
display: flex;
|
|
118
|
-
position: relative;
|
|
119
117
|
flex-direction: column;
|
|
120
118
|
width: 100%;
|
|
121
|
-
border-radius:
|
|
122
|
-
margin-top: 1rem;
|
|
119
|
+
border-radius: 8px;
|
|
123
120
|
background: var(--others-white);
|
|
124
121
|
min-width: 20rem;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
position: absolute;
|
|
123
|
+
top: 100%;
|
|
124
|
+
left: 0;
|
|
125
|
+
z-index: 10;
|
|
126
|
+
background-color: var(--others-white);
|
|
127
|
+
border-top: none;
|
|
128
|
+
padding: 1rem 2rem;
|
|
129
|
+
|
|
130
|
+
@media ${device['laptop']} {
|
|
131
|
+
opacity: 1;
|
|
129
132
|
left: 0;
|
|
130
133
|
top: 100%;
|
|
131
|
-
box-shadow:
|
|
132
|
-
|
|
134
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
135
|
+
margin-top: 0;
|
|
136
|
+
border: none;
|
|
137
|
+
border-radius: 0 0 8px 8px;
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
& > li > * {
|
|
@@ -1,35 +1,15 @@
|
|
|
1
1
|
import { device } from '../../../globalStyles/breakpoints'
|
|
2
|
-
|
|
3
2
|
import styled from 'styled-components'
|
|
4
3
|
|
|
5
4
|
export const DropdownInputStyled = styled.div`
|
|
6
5
|
position: relative;
|
|
7
|
-
padding-left: 1.5rem;
|
|
8
|
-
padding-right: 1.5rem;
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
@media ${device['landscape-tablets']} {
|
|
8
|
+
padding: 1rem 2rem;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.dropdown_input__container {
|
|
17
|
-
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.dropdown_input__results {
|
|
21
|
-
opacity: 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.dropdown_input__container__icon {
|
|
26
|
-
color: var(--primary-main);
|
|
27
|
-
|
|
28
|
-
svg {
|
|
29
|
-
fill: var(--primary-main);
|
|
30
|
-
stroke: var(--primary-main);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
11
|
+
a {
|
|
12
|
+
text-decoration: none;
|
|
33
13
|
}
|
|
34
14
|
|
|
35
15
|
.dropdown_input__container {
|
|
@@ -43,6 +23,23 @@ export const DropdownInputStyled = styled.div`
|
|
|
43
23
|
border-bottom: 2px solid transparent;
|
|
44
24
|
}
|
|
45
25
|
|
|
26
|
+
&:focus-within {
|
|
27
|
+
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
28
|
+
|
|
29
|
+
@media ${device['landscape-tablets']} {
|
|
30
|
+
border-bottom: 2px var(--neutral-neutral-4) solid;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.dropdown_input__container__icon {
|
|
34
|
+
color: var(--primary-main);
|
|
35
|
+
|
|
36
|
+
svg {
|
|
37
|
+
fill: var(--primary-main);
|
|
38
|
+
stroke: var(--primary-main);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
46
43
|
.dropdown_input__container__text_input {
|
|
47
44
|
width: 100%;
|
|
48
45
|
height: 100%;
|
|
@@ -57,7 +54,7 @@ export const DropdownInputStyled = styled.div`
|
|
|
57
54
|
color: var(--neutral-neutral-3);
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
&.with-icon {
|
|
61
58
|
padding-right: 2rem;
|
|
62
59
|
}
|
|
63
60
|
}
|
|
@@ -81,6 +78,7 @@ export const DropdownInputStyled = styled.div`
|
|
|
81
78
|
height: 1.5rem;
|
|
82
79
|
opacity: 1;
|
|
83
80
|
margin-right: 0.25rem;
|
|
81
|
+
cursor: pointer;
|
|
84
82
|
|
|
85
83
|
path {
|
|
86
84
|
transition: all 0.25s;
|
|
@@ -117,21 +115,27 @@ export const DropdownInputStyled = styled.div`
|
|
|
117
115
|
.dropdown_input__results {
|
|
118
116
|
transition: all 0.25s;
|
|
119
117
|
display: flex;
|
|
120
|
-
position: relative;
|
|
121
118
|
flex-direction: column;
|
|
122
119
|
width: 100%;
|
|
123
|
-
border-radius:
|
|
124
|
-
margin-top: 1rem;
|
|
120
|
+
border-radius: 8px;
|
|
125
121
|
background: var(--others-white);
|
|
126
122
|
min-width: 20rem;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
position: absolute;
|
|
124
|
+
top: 100%;
|
|
125
|
+
left: 0;
|
|
126
|
+
z-index: 10;
|
|
127
|
+
background-color: var(--others-white);
|
|
128
|
+
border-top: none;
|
|
129
|
+
padding: 1rem 2rem;
|
|
130
|
+
|
|
131
|
+
@media ${device['laptop']} {
|
|
132
|
+
opacity: 1;
|
|
131
133
|
left: 0;
|
|
132
134
|
top: 100%;
|
|
133
|
-
box-shadow:
|
|
134
|
-
|
|
135
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
136
|
+
margin-top: 0;
|
|
137
|
+
border: none;
|
|
138
|
+
border-radius: 0 0 8px 8px;
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
& > li > * {
|
|
@@ -1,60 +1,57 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
2
|
-
|
|
3
|
-
import React, { useState } from 'react'
|
|
2
|
+
import React, { forwardRef, useState } from 'react'
|
|
4
3
|
import { DropdownInputProps } from './DropdownInputProps.types'
|
|
5
4
|
import { DropdownInputStyled } from './DropdownInput.styled'
|
|
6
5
|
|
|
7
|
-
export const DropdownInput
|
|
8
|
-
onChange,
|
|
9
|
-
|
|
10
|
-
className = '',
|
|
11
|
-
name,
|
|
12
|
-
icon,
|
|
13
|
-
placeholder
|
|
14
|
-
}) => {
|
|
15
|
-
const [searchTerm, setSearchTerm] = useState('')
|
|
6
|
+
export const DropdownInput = forwardRef<HTMLInputElement, DropdownInputProps>(
|
|
7
|
+
({ onChange, results, className = '', name, icon, placeholder }, ref) => {
|
|
8
|
+
const [searchTerm, setSearchTerm] = useState('')
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const updateInput = (e): void => {
|
|
11
|
+
setSearchTerm(e.target.value)
|
|
12
|
+
onChange(e.target.value)
|
|
13
|
+
}
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const resetInput = (): void => {
|
|
16
|
+
setSearchTerm('')
|
|
17
|
+
}
|
|
25
18
|
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
19
|
+
return (
|
|
20
|
+
<DropdownInputStyled className={`dropdown_input ${className}`}>
|
|
21
|
+
<div className='dropdown_input__container'>
|
|
22
|
+
<input
|
|
23
|
+
ref={ref}
|
|
24
|
+
className={`dropdown_input__container__text_input ${icon ? 'with-icon' : ''}`}
|
|
25
|
+
type='text'
|
|
26
|
+
name={`dropdown_input_${name}`}
|
|
27
|
+
placeholder={placeholder}
|
|
28
|
+
value={searchTerm}
|
|
29
|
+
onChange={(e) => {
|
|
30
|
+
updateInput(e)
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
<div className={`dropdown_input__container__icon ${searchTerm ? 'active' : ''}`}>
|
|
34
|
+
{icon &&
|
|
35
|
+
React.cloneElement(icon, {
|
|
36
|
+
className: 'dropdown_input__container__icon__main'
|
|
37
|
+
})}
|
|
38
|
+
{searchTerm && (
|
|
39
|
+
<div
|
|
40
|
+
className='icon-cross main-color dropdown_input__container__icon__clear'
|
|
41
|
+
onClick={() => {
|
|
42
|
+
resetInput()
|
|
43
|
+
}}
|
|
44
|
+
onKeyDown={() => {
|
|
45
|
+
resetInput()
|
|
46
|
+
}}
|
|
47
|
+
></div>
|
|
48
|
+
)}
|
|
49
|
+
</div>
|
|
55
50
|
</div>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
{searchTerm && !!results?.length && <ul className='dropdown_input__results'>{results}</ul>}
|
|
52
|
+
</DropdownInputStyled>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
DropdownInput.displayName = 'DropdownInput'
|
|
@@ -1,33 +1,90 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
3
|
+
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
4
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
6
|
import { DropdownInput } from '../../atoms/DropdownInput/DropdownInput';
|
|
4
7
|
import { SearchIcon } from '../../../../images/componentsSvg/SearchIcon';
|
|
5
8
|
import { useWindowSize } from '../../../hooks/useWindowSize';
|
|
6
9
|
import { SearchBarStyled } from './SearchBar.styled';
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
import { useSearchFunction } from '../../../hooks/useSearchFunction';
|
|
11
|
+
const DesktopSearchBar = ({ products, searchBarTexts, routes, handleResultClick, isOpen, onClose }) => {
|
|
12
|
+
const { results, searchFunction } = useSearchFunction({
|
|
13
|
+
products,
|
|
14
|
+
searchBarTexts,
|
|
15
|
+
routes,
|
|
16
|
+
handleResultClick,
|
|
17
|
+
onClose
|
|
18
|
+
});
|
|
19
|
+
const searchInputRef = useRef(null);
|
|
20
|
+
const searchBarContainerRef = useRef(null);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const handleKeyDown = (event) => {
|
|
23
|
+
if (event.key === 'Escape') {
|
|
24
|
+
onClose();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const handleClickOutside = (event) => {
|
|
28
|
+
if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target)) {
|
|
29
|
+
onClose();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (isOpen) {
|
|
33
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
34
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
35
|
+
if (searchInputRef.current) {
|
|
36
|
+
searchInputRef.current.focus();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return () => {
|
|
40
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
41
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
42
|
+
};
|
|
43
|
+
}, [isOpen, onClose]);
|
|
44
|
+
if (!isOpen) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return (_jsx(SearchBarStyled, { ref: searchBarContainerRef, className: 'modal_searchbar', children: _jsx("div", { className: 'modal_searchbar__content', children: _jsx(DropdownInput, { ref: searchInputRef, name: 'search', className: 'search', placeholder: searchBarTexts.placeholder, icon: _jsx(SearchIcon, {}), onChange: searchFunction, results: results }) }) }));
|
|
48
|
+
};
|
|
49
|
+
const MobileSearchBar = ({ products, searchBarTexts, routes, handleResultClick }) => {
|
|
50
|
+
const { results, searchFunction } = useSearchFunction({
|
|
51
|
+
products,
|
|
52
|
+
searchBarTexts,
|
|
53
|
+
routes,
|
|
54
|
+
handleResultClick
|
|
55
|
+
});
|
|
56
|
+
const searchInputRef = useRef(null);
|
|
57
|
+
const searchBarContainerRef = useRef(null);
|
|
58
|
+
const isResultsVisible = Array.isArray(results) && results.length > 0;
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const handleKeyDown = (event) => {
|
|
61
|
+
if (event.key === 'Escape') {
|
|
62
|
+
searchFunction('');
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const handleClickOutside = (event) => {
|
|
66
|
+
if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target)) {
|
|
67
|
+
searchFunction('');
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (isResultsVisible) {
|
|
71
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
72
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
73
|
+
}
|
|
74
|
+
return () => {
|
|
75
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
76
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
77
|
+
};
|
|
78
|
+
}, [isResultsVisible, searchFunction]);
|
|
79
|
+
return (_jsx(SearchBarStyled, { ref: searchBarContainerRef, children: _jsx(DropdownInput, { ref: searchInputRef, name: 'search', className: 'search', placeholder: searchBarTexts.placeholder, icon: _jsx(SearchIcon, {}), onChange: searchFunction, results: results }) }));
|
|
80
|
+
};
|
|
81
|
+
export const SearchBar = (props) => {
|
|
9
82
|
const windowSize = useWindowSize();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const preMatch = product.slice(0, product.toLowerCase().indexOf(searchTerm));
|
|
18
|
-
const match = product.slice(product.toLowerCase().indexOf(searchTerm), preMatch.length + searchTerm.length);
|
|
19
|
-
const postMatch = product.slice(product.toLowerCase().indexOf(searchTerm) + searchTerm.length, product.length);
|
|
20
|
-
const link = item.categoryUrl ? `${item.categoryUrl}/${item.slug}` : item.slug;
|
|
21
|
-
return (_jsx("li", { className: 'dropdown_input__item', children: _jsxs("a", { href: routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link), className: 'dropdown_input__link', onClick: (e) => {
|
|
22
|
-
e.preventDefault();
|
|
23
|
-
handleResultClick(product, routes.CUSTOM_URL_FROM_TARGET_ADDRESS(link));
|
|
24
|
-
}, title: product, children: [preMatch, _jsx("strong", { className: 'dropdown_input__link__emphasis', children: match }), postMatch] }, item.linkText) }, searchBarTexts.title));
|
|
25
|
-
})
|
|
26
|
-
.slice(0, 9);
|
|
27
|
-
results.push(_jsx("li", { className: 'dropdown_input__item', children: _jsx("a", { className: 'dropdown_input__link--all', title: searchBarTexts.title, href: routes.LEGAL_DOCUMENTS, children: searchBarTexts.title }) }, searchBarTexts.title));
|
|
28
|
-
setResults(results);
|
|
29
|
-
};
|
|
30
|
-
return (_jsx(SearchBarStyled, { children: _jsx(DropdownInput, { name: 'search', className: 'search', placeholder: _placeholder, icon: _jsx(SearchIcon, {}), onChange: (text) => {
|
|
31
|
-
searchFunction(text);
|
|
32
|
-
}, results: results }) }));
|
|
83
|
+
const isDesktop = !!windowSize.width && windowSize.width >= 960;
|
|
84
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
85
|
+
const closeModal = () => setIsModalOpen(false);
|
|
86
|
+
if (isDesktop) {
|
|
87
|
+
return (_jsxs("div", { style: { position: 'relative' }, children: [_jsx("a", { onClick: () => setIsModalOpen(true), className: 'search-toggle-link', children: _jsx(SearchIcon, {}) }), _jsx(DesktopSearchBar, { ...props, isOpen: isModalOpen, onClose: closeModal })] }));
|
|
88
|
+
}
|
|
89
|
+
return _jsx(MobileSearchBar, { ...props });
|
|
33
90
|
};
|
|
@@ -5,58 +5,72 @@ export const SearchBarStyled = styled.div `
|
|
|
5
5
|
.search {
|
|
6
6
|
width: calc(100% - 3rem);
|
|
7
7
|
margin: 0 1.5rem;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
@media ${device['landscape-tablets']} {
|
|
12
|
+
.search-toggle-link {
|
|
13
|
+
display: inline-block;
|
|
14
|
+
width: 20px;
|
|
15
|
+
height: 20px;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
line-height: 20px;
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
margin: 0 1.5rem 0 0;
|
|
19
|
+
& > svg {
|
|
20
|
+
transition: fill 0.25s;
|
|
21
|
+
fill: currentColor;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
&:hover > svg {
|
|
25
|
+
fill: var(--primary-main);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
min-width: 100%;
|
|
26
|
-
width: max-content;
|
|
28
|
+
.modal_searchbar + .search-toggle-link > svg {
|
|
29
|
+
fill: #078080;
|
|
27
30
|
}
|
|
31
|
+
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
&.modal_searchbar {
|
|
34
|
+
position: absolute;
|
|
35
|
+
top: 8px;
|
|
36
|
+
left: 32px;
|
|
37
|
+
z-index: 10000;
|
|
38
|
+
width: 400px;
|
|
39
|
+
max-width: 90vw;
|
|
40
|
+
background: none;
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
.modal_searchbar__content {
|
|
43
|
+
background-color: var(--neutral-white);
|
|
44
|
+
padding: 1.5rem;
|
|
45
|
+
border-radius: 8px;
|
|
46
|
+
width: 100%;
|
|
47
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
color: var(--others-black);
|
|
49
|
+
@media ${device['laptop']} {
|
|
50
|
+
padding: 0;
|
|
51
|
+
border-radius: 8px 8px 0 0;
|
|
41
52
|
}
|
|
53
|
+
}
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
.modal_searchbar__header {
|
|
56
|
+
display: flex;
|
|
57
|
+
justify-content: space-between;
|
|
58
|
+
align-items: center;
|
|
59
|
+
margin-bottom: 1rem;
|
|
47
60
|
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
.modal_searchbar__title {
|
|
63
|
+
font-size: 1.5rem;
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
color: var(--others-black);
|
|
66
|
+
}
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
.dropdown_input {
|
|
69
|
+
.search {
|
|
70
|
+
width: 100%;
|
|
71
|
+
margin: 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
60
74
|
}
|
|
61
75
|
}
|
|
62
76
|
`;
|