@npm_leadtech/legal-lib-components 7.22.3 → 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.
@@ -1,43 +1,50 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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
10
  import { useSearchFunction } from '../../../hooks/useSearchFunction';
8
- const DesktopSearchBar = ({ products, searchBarTexts, routes, handleResultClick }) => {
11
+ const DesktopSearchBar = ({ products, searchBarTexts, routes, handleResultClick, isOpen, onClose }) => {
9
12
  const { results, searchFunction } = useSearchFunction({
10
13
  products,
11
14
  searchBarTexts,
12
15
  routes,
13
- handleResultClick
16
+ handleResultClick,
17
+ onClose
14
18
  });
15
19
  const searchInputRef = useRef(null);
16
20
  const searchBarContainerRef = useRef(null);
17
- const isResultsVisible = Array.isArray(results) && results.length > 0;
18
21
  useEffect(() => {
19
22
  const handleKeyDown = (event) => {
20
23
  if (event.key === 'Escape') {
21
- searchFunction('');
24
+ onClose();
22
25
  }
23
26
  };
24
27
  const handleClickOutside = (event) => {
25
28
  if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target)) {
26
- searchFunction('');
29
+ onClose();
27
30
  }
28
31
  };
29
- if (isResultsVisible) {
32
+ if (isOpen) {
30
33
  document.addEventListener('keydown', handleKeyDown);
31
34
  document.addEventListener('mousedown', handleClickOutside);
35
+ if (searchInputRef.current) {
36
+ searchInputRef.current.focus();
37
+ }
32
38
  }
33
39
  return () => {
34
40
  document.removeEventListener('keydown', handleKeyDown);
35
41
  document.removeEventListener('mousedown', handleClickOutside);
36
42
  };
37
- }, [isResultsVisible, searchFunction]);
38
- 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: (text) => {
39
- searchFunction(text);
40
- }, results: results }) }) }));
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 }) }) }));
41
48
  };
42
49
  const MobileSearchBar = ({ products, searchBarTexts, routes, handleResultClick }) => {
43
50
  const { results, searchFunction } = useSearchFunction({
@@ -69,15 +76,15 @@ const MobileSearchBar = ({ products, searchBarTexts, routes, handleResultClick }
69
76
  document.removeEventListener('mousedown', handleClickOutside);
70
77
  };
71
78
  }, [isResultsVisible, searchFunction]);
72
- return (_jsx(SearchBarStyled, { ref: searchBarContainerRef, children: _jsx(DropdownInput, { ref: searchInputRef, name: 'search', className: 'search', placeholder: searchBarTexts.placeholder, icon: _jsx(SearchIcon, {}), onChange: (text) => {
73
- searchFunction(text);
74
- }, results: results }) }));
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 }) }));
75
80
  };
76
81
  export const SearchBar = (props) => {
77
82
  const windowSize = useWindowSize();
78
83
  const isDesktop = !!windowSize.width && windowSize.width >= 960;
84
+ const [isModalOpen, setIsModalOpen] = useState(false);
85
+ const closeModal = () => setIsModalOpen(false);
79
86
  if (isDesktop) {
80
- return _jsx(DesktopSearchBar, { ...props });
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 })] }));
81
88
  }
82
89
  return _jsx(MobileSearchBar, { ...props });
83
90
  };
@@ -9,28 +9,44 @@ export const SearchBarStyled = styled.div `
9
9
  }
10
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;
18
+
19
+ & > svg {
20
+ transition: fill 0.25s;
21
+ fill: currentColor;
22
+ }
23
+
24
+ &:hover > svg {
25
+ fill: var(--primary-main);
26
+ }
27
+
28
+ .modal_searchbar + .search-toggle-link > svg {
29
+ fill: #078080;
30
+ }
31
+ }
32
+
12
33
  &.modal_searchbar {
13
- position: fixed;
14
- top: 0;
15
- left: 0;
16
- width: 100vw;
17
- height: 100vh;
18
- background: rgba(255, 255, 255, 0.95);
19
- z-index: 9999;
20
- display: flex;
21
- justify-content: center;
22
- align-items: flex-start;
23
- padding-top: 100px;
34
+ position: absolute;
35
+ top: 8px;
36
+ left: 32px;
37
+ z-index: 10000;
38
+ width: 400px;
39
+ max-width: 90vw;
40
+ background: none;
24
41
 
25
42
  .modal_searchbar__content {
26
43
  background-color: var(--neutral-white);
27
44
  padding: 1.5rem;
28
45
  border-radius: 8px;
29
- width: 90%;
30
- max-width: 768px;
46
+ width: 100%;
31
47
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
32
48
 
33
- @media ${device['landscape-tablets']} {
49
+ @media ${device['laptop']} {
34
50
  padding: 0;
35
51
  border-radius: 8px 8px 0 0;
36
52
  }
@@ -10,28 +10,44 @@ export const SearchBarStyled = styled.div`
10
10
  }
11
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;
19
+
20
+ & > svg {
21
+ transition: fill 0.25s;
22
+ fill: currentColor;
23
+ }
24
+
25
+ &:hover > svg {
26
+ fill: var(--primary-main);
27
+ }
28
+
29
+ .modal_searchbar + .search-toggle-link > svg {
30
+ fill: #078080;
31
+ }
32
+ }
33
+
13
34
  &.modal_searchbar {
14
- position: fixed;
15
- top: 0;
16
- left: 0;
17
- width: 100vw;
18
- height: 100vh;
19
- background: rgba(255, 255, 255, 0.95);
20
- z-index: 9999;
21
- display: flex;
22
- justify-content: center;
23
- align-items: flex-start;
24
- padding-top: 100px;
35
+ position: absolute;
36
+ top: 8px;
37
+ left: 32px;
38
+ z-index: 10000;
39
+ width: 400px;
40
+ max-width: 90vw;
41
+ background: none;
25
42
 
26
43
  .modal_searchbar__content {
27
44
  background-color: var(--neutral-white);
28
45
  padding: 1.5rem;
29
46
  border-radius: 8px;
30
- width: 90%;
31
- max-width: 768px;
47
+ width: 100%;
32
48
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
33
49
 
34
- @media ${device['landscape-tablets']} {
50
+ @media ${device['laptop']} {
35
51
  padding: 0;
36
52
  border-radius: 8px 8px 0 0;
37
53
  }
@@ -1,4 +1,7 @@
1
- import React, { useEffect, useRef } from 'react'
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'
2
5
  import { DropdownInput } from '../../atoms/DropdownInput/DropdownInput'
3
6
  import { SearchIcon } from '../../../../images/componentsSvg/SearchIcon'
4
7
  import { useWindowSize } from '../../../hooks/useWindowSize'
@@ -7,39 +10,58 @@ import { type SearchBarProps } from './SearchBarProps.types'
7
10
  import { SearchBarStyled } from './SearchBar.styled'
8
11
  import { useSearchFunction } from '../../../hooks/useSearchFunction'
9
12
 
10
- const DesktopSearchBar: React.FC<SearchBarProps> = ({ products, searchBarTexts, routes, handleResultClick }) => {
13
+ interface DesktopSearchBarProps extends SearchBarProps {
14
+ isOpen: boolean
15
+ onClose: () => void
16
+ }
17
+
18
+ const DesktopSearchBar: React.FC<DesktopSearchBarProps> = ({
19
+ products,
20
+ searchBarTexts,
21
+ routes,
22
+ handleResultClick,
23
+ isOpen,
24
+ onClose
25
+ }) => {
11
26
  const { results, searchFunction } = useSearchFunction({
12
27
  products,
13
28
  searchBarTexts,
14
29
  routes,
15
- handleResultClick
30
+ handleResultClick,
31
+ onClose
16
32
  })
17
33
  const searchInputRef = useRef<HTMLInputElement>(null)
18
34
  const searchBarContainerRef = useRef<HTMLDivElement>(null)
19
- const isResultsVisible = Array.isArray(results) && results.length > 0
20
35
 
21
36
  useEffect(() => {
22
37
  const handleKeyDown = (event: KeyboardEvent) => {
23
38
  if (event.key === 'Escape') {
24
- searchFunction('')
39
+ onClose()
25
40
  }
26
41
  }
27
42
  const handleClickOutside = (event: MouseEvent) => {
28
43
  if (searchBarContainerRef.current && !searchBarContainerRef.current.contains(event.target as Node)) {
29
- searchFunction('')
44
+ onClose()
30
45
  }
31
46
  }
32
47
 
33
- if (isResultsVisible) {
48
+ if (isOpen) {
34
49
  document.addEventListener('keydown', handleKeyDown)
35
50
  document.addEventListener('mousedown', handleClickOutside)
51
+ if (searchInputRef.current) {
52
+ searchInputRef.current.focus()
53
+ }
36
54
  }
37
55
 
38
56
  return () => {
39
57
  document.removeEventListener('keydown', handleKeyDown)
40
58
  document.removeEventListener('mousedown', handleClickOutside)
41
59
  }
42
- }, [isResultsVisible, searchFunction])
60
+ }, [isOpen, onClose])
61
+
62
+ if (!isOpen) {
63
+ return null
64
+ }
43
65
 
44
66
  return (
45
67
  <SearchBarStyled ref={searchBarContainerRef} className='modal_searchbar'>
@@ -50,9 +72,7 @@ const DesktopSearchBar: React.FC<SearchBarProps> = ({ products, searchBarTexts,
50
72
  className='search'
51
73
  placeholder={searchBarTexts.placeholder}
52
74
  icon={<SearchIcon />}
53
- onChange={(text: string) => {
54
- searchFunction(text)
55
- }}
75
+ onChange={searchFunction}
56
76
  results={results}
57
77
  />
58
78
  </div>
@@ -102,9 +122,7 @@ const MobileSearchBar: React.FC<SearchBarProps> = ({ products, searchBarTexts, r
102
122
  className='search'
103
123
  placeholder={searchBarTexts.placeholder}
104
124
  icon={<SearchIcon />}
105
- onChange={(text: string) => {
106
- searchFunction(text)
107
- }}
125
+ onChange={searchFunction}
108
126
  results={results}
109
127
  />
110
128
  </SearchBarStyled>
@@ -114,9 +132,19 @@ const MobileSearchBar: React.FC<SearchBarProps> = ({ products, searchBarTexts, r
114
132
  export const SearchBar: React.FC<SearchBarProps> = (props) => {
115
133
  const windowSize = useWindowSize()
116
134
  const isDesktop = !!windowSize.width && windowSize.width >= 960
135
+ const [isModalOpen, setIsModalOpen] = useState(false)
136
+
137
+ const closeModal = () => setIsModalOpen(false)
117
138
 
118
139
  if (isDesktop) {
119
- return <DesktopSearchBar {...props} />
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
+ )
120
148
  }
121
149
 
122
150
  return <MobileSearchBar {...props} />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npm_leadtech/legal-lib-components",
3
- "version": "7.22.3",
3
+ "version": "7.22.4",
4
4
  "license": "ISC",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",