@npm_leadtech/legal-lib-components 7.23.0 → 7.23.2

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.
Files changed (45) hide show
  1. package/dist/images/componentsSvg/CloseIcon.d.ts +6 -0
  2. package/dist/images/componentsSvg/CloseIcon.js +2 -0
  3. package/dist/images/componentsSvg/CloseIcon.tsx +14 -0
  4. package/dist/images/svg/close-grey-24px.svg +3 -0
  5. package/dist/images/svg/search_24px.svg +3 -0
  6. package/dist/src/components/atoms/DropdownInput/DropdownInput.d.ts +1 -1
  7. package/dist/src/components/atoms/DropdownInput/DropdownInput.js +9 -7
  8. package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.js +52 -36
  9. package/dist/src/components/atoms/DropdownInput/DropdownInput.styled.ts +52 -37
  10. package/dist/src/components/atoms/DropdownInput/DropdownInput.tsx +55 -51
  11. package/dist/src/components/atoms/DropdownInput/DropdownInputProps.types.d.ts +1 -0
  12. package/dist/src/components/atoms/DropdownInput/DropdownInputProps.types.ts +1 -0
  13. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.d.ts +8 -0
  14. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.js +44 -0
  15. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.d.ts +1 -0
  16. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.js +48 -0
  17. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.styled.ts +49 -0
  18. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBar.tsx +77 -0
  19. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.d.ts +37 -0
  20. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.js +1 -0
  21. package/dist/src/components/molecules/DesktopSearchBar/DesktopSearchBarProps.types.ts +40 -0
  22. package/dist/src/components/molecules/DesktopSearchBar/index.d.ts +2 -0
  23. package/dist/src/components/molecules/DesktopSearchBar/index.js +1 -0
  24. package/dist/src/components/molecules/DesktopSearchBar/index.ts +2 -0
  25. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.d.ts +3 -0
  26. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.js +38 -0
  27. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.d.ts +1 -0
  28. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.js +17 -0
  29. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.styled.ts +18 -0
  30. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBar.tsx +55 -0
  31. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.d.ts +37 -0
  32. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.js +1 -0
  33. package/dist/src/components/molecules/MobileSearchBar/MobileSearchBarProps.types.ts +40 -0
  34. package/dist/src/components/molecules/MobileSearchBar/index.d.ts +2 -0
  35. package/dist/src/components/molecules/MobileSearchBar/index.js +1 -0
  36. package/dist/src/components/molecules/MobileSearchBar/index.ts +2 -0
  37. package/dist/src/components/molecules/SearchBar/SearchBar.js +17 -29
  38. package/dist/src/components/molecules/SearchBar/SearchBar.styled.js +4 -55
  39. package/dist/src/components/molecules/SearchBar/SearchBar.styled.ts +4 -55
  40. package/dist/src/components/molecules/SearchBar/SearchBar.tsx +31 -61
  41. package/dist/src/hooks/useSearchFunction.d.ts +10 -0
  42. package/dist/src/hooks/useSearchFunction.js +28 -0
  43. package/dist/src/hooks/useSearchFunction.tsx +63 -0
  44. package/dist/tsconfig.build.tsbuildinfo +1 -1
  45. 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 { DropdownInput } from '../../atoms/DropdownInput/DropdownInput'
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> = ({ products, searchBarTexts, routes, handleResultClick }) => {
11
- const [results, setResults] = useState<React.JSX.Element[]>([])
11
+ export const SearchBar: React.FC<SearchBarProps> = (props) => {
12
+ const [isModalOpen, setIsModalOpen] = useState(false)
12
13
 
13
- const windowSize = useWindowSize()
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
- <DropdownInput
61
- name='search'
62
- className='search'
63
- placeholder={_placeholder}
64
- icon={<SearchIcon />}
65
- onChange={(text: string) => {
66
- searchFunction(text)
67
- }}
68
- results={results}
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
  }
@@ -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
+ }