Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gatsby Theme Onegeo
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OneGeo Suite
Libs
Gatsby Theme Onegeo
Commits
975b9233
Commit
975b9233
authored
Jul 28, 2023
by
Julien MARGAIL
Browse files
Options
Downloads
Patches
Plain Diff
fix Search show/hide, add props noResult
parent
a09a545a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.d.ts
+1
-0
1 addition, 0 deletions
index.d.ts
src/components/core/Search.tsx
+77
-69
77 additions, 69 deletions
src/components/core/Search.tsx
with
78 additions
and
69 deletions
index.d.ts
+
1
−
0
View file @
975b9233
...
@@ -143,6 +143,7 @@ interface SearchProps {
...
@@ -143,6 +143,7 @@ interface SearchProps {
options
?:
any
options
?:
any
position
:
"
left
"
|
"
right
"
position
:
"
left
"
|
"
right
"
placeholder
:
string
placeholder
:
string
noResult
:
string
}
}
export
function
Search
(
props
:
SearchProps
):
JSX
.
Element
export
function
Search
(
props
:
SearchProps
):
JSX
.
Element
...
...
...
...
This diff is collapsed.
Click to expand it.
src/components/core/Search.tsx
+
77
−
69
View file @
975b9233
import
React
,
{
useState
,
useEffect
}
from
"
react
"
import
React
,
{
useState
,
useEffect
}
from
"
react
"
import
{
twMerge
}
from
"
tailwind-merge
"
import
{
twMerge
}
from
"
tailwind-merge
"
import
{
Combobox
}
from
"
@headlessui/react
"
import
{
Combobox
,
Transition
}
from
"
@headlessui/react
"
import
{
SearchIcon
}
from
"
@heroicons/react/outline
"
import
{
SearchIcon
}
from
"
@heroicons/react/outline
"
import
{
navigate
}
from
"
gatsby
"
import
{
cleanHtml
,
isBrowser
}
from
"
@onegeo-suite/gatsby-theme-onegeo
"
import
{
cleanHtml
,
isBrowser
}
from
"
@onegeo-suite/gatsby-theme-onegeo
"
interface
Props
{
interface
Props
{
options
?:
any
options
?:
any
position
?:
"
left
"
|
"
right
"
position
?:
"
left
"
|
"
right
"
placeholder
?:
string
placeholder
?:
string
noResult
?:
string
}
}
const
EXPLORER_PATH
=
process
.
env
.
OGS_EXPLORER_PATH
||
"
/explorer
"
const
EXPLORER_PATH
=
process
.
env
.
OGS_EXPLORER_PATH
||
"
/explorer
"
const
Search
=
(
props
:
Props
)
=>
{
const
Search
=
(
props
:
Props
)
=>
{
const
{
position
=
"
left
"
,
placeholder
=
"
Recherche...
"
}
=
props
const
{
position
=
"
left
"
,
placeholder
=
"
Recherche...
"
,
noResult
=
"
Aucun résultat
"
,
}
=
props
const
options
=
props
.
options
??
{}
const
options
=
props
.
options
??
{}
const
oClass
=
options
.
class
|| {}
const
oClass
=
options
.
class
|| {}
...
@@ -39,13 +43,8 @@ const Search = (props: Props) => {
...
@@ -39,13 +43,8 @@ const Search = (props: Props) => {
return
(
return
(
<
div
className
=
{
twMerge
(
""
,
oClass
.
main
)
}
>
<
div
className
=
{
twMerge
(
""
,
oClass
.
main
)
}
>
<
div
className
=
{
twMerge
(
"
bg-base-100 ring-base-content mx-auto max-w-xl divide-y divide-gray-100 overflow-hidden ring-1 ring-opacity-10
"
,
oClass
.
combobox
)
}
>
<
Combobox
<
Combobox
as
=
"div"
value
=
{
null
}
value
=
{
null
}
onChange
=
{
(
item
)
=>
{
onChange
=
{
(
item
)
=>
{
if
(
!
item
)
return
if
(
!
item
)
return
...
@@ -60,6 +59,10 @@ const Search = (props: Props) => {
...
@@ -60,6 +59,10 @@ const Search = (props: Props) => {
window
.
location
=
url
window
.
location
=
url
}
}
}
}
className
=
{
twMerge
(
"
bg-base-100 ring-base-content mx-auto max-w-xl divide-y divide-gray-100 overflow-hidden ring-1 ring-opacity-10
"
,
oClass
.
combobox
)
}
nullable
nullable
>
>
<
div
className
=
{
twMerge
(
"
relative
"
,
oClass
.
body
)
}
>
<
div
className
=
{
twMerge
(
"
relative
"
,
oClass
.
body
)
}
>
...
@@ -91,15 +94,31 @@ const Search = (props: Props) => {
...
@@ -91,15 +94,31 @@ const Search = (props: Props) => {
)
}
)
}
</
div
>
</
div
>
{
items
.
length
>
0
&&
(
<
Transition
enter
=
"transition duration-100 ease-out"
enterFrom
=
"transform scale-95 opacity-0"
enterTo
=
"transform scale-100 opacity-100"
leave
=
"transition duration-75 ease-out"
leaveFrom
=
"transform scale-100 opacity-100"
leaveTo
=
"transform scale-95 opacity-0"
>
<
Combobox
.
Options
<
Combobox
.
Options
static
className
=
{
twMerge
(
className
=
{
twMerge
(
"
text-base-content scrollbar-thin scrollbar-track-base-200 scrollbar-thumb-base-300 max-h-72 overflow-y-auto py-2 text-sm
"
,
"
text-base-content scrollbar-thin scrollbar-track-base-200 scrollbar-thumb-base-300
bg-base-100
max-h-72 overflow-y-auto py-2 text-sm
"
,
oClass
.
options
oClass
.
options
)
}
)
}
>
>
{
items
.
map
((
item
,
idx
)
=>
(
{
items
.
length
===
0
&&
query
!==
""
?
(
<
div
className
=
{
twMerge
(
"
text-base-content p-4 text-sm
"
,
oClass
.
noresult
)
}
>
{
noResult
}
</
div
>
)
:
(
items
.
map
((
item
,
idx
)
=>
(
<
Combobox
.
Option
<
Combobox
.
Option
key
=
{
idx
}
key
=
{
idx
}
value
=
{
item
}
value
=
{
item
}
...
@@ -118,23 +137,12 @@ const Search = (props: Props) => {
...
@@ -118,23 +137,12 @@ const Search = (props: Props) => {
}
}
}
}
/>
/>
</
Combobox
.
Option
>
</
Combobox
.
Option
>
))
}
))
</
Combobox
.
Options
>
)
}
{
query
!==
""
&&
items
.
length
===
0
&&
(
<
p
className
=
{
twMerge
(
"
text-base-content p-4 text-sm
"
,
oClass
.
noresult
)
}
>
Aucun résultat.
</
p
>
)
}
)
}
</
Combobox
.
Options
>
</
Transition
>
</
Combobox
>
</
Combobox
>
</
div
>
</
div
>
</
div
>
)
)
}
}
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment