Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CryptoMetrics_L02_GRP15
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
L02_GRP15
CryptoMetrics_L02_GRP15
Commits
c6679e60
Commit
c6679e60
authored
3 years ago
by
Aggarwal Himanshu
Browse files
Options
Downloads
Patches
Plain Diff
Add dropdown component
parent
dab25230
No related branches found
No related tags found
2 merge requests
!17
Merge develop into main
,
!10
Add ability to select two cryptocurrencies for comparison
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cryptometrics/components/dropdown/Dropdown.js
+70
-0
70 additions, 0 deletions
src/cryptometrics/components/dropdown/Dropdown.js
with
70 additions
and
0 deletions
src/cryptometrics/components/dropdown/Dropdown.js
0 → 100644
+
70
−
0
View file @
c6679e60
import
React
,
{
useState
,
useEffect
}
from
"
react
"
;
import
classNames
from
"
classnames
"
;
import
{
ChevronDownIcon
}
from
"
@heroicons/react/outline
"
;
function
getCoin
(
list
,
id
)
{
for
(
let
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(
list
[
i
].
id
==
id
)
{
return
list
[
i
];
}
}
return
null
;
}
function
Dropdown
({
list
,
value
,
setValue
})
{
const
[
open
,
setOpen
]
=
useState
(
false
);
useEffect
(()
=>
{
setOpen
(
false
);
},
[
value
]);
return
(
<
div
className
=
"
relative
"
>
<
button
className
=
{
classNames
(
"
px-3 py-2 rounded-md font-light
"
,
{
"
dark:bg-white dark:text-gray-800
"
:
false
,
"
dark:bg-black dark:text-gray-400
"
:
true
,
})}
onClick
=
{()
=>
setOpen
(
!
open
)}
>
<
div
className
=
"
flex flex-row items-center space-x-2
"
>
<
p
>
{
getCoin
(
list
,
value
).
name
}
<
/p
>
<
ChevronDownIcon
className
=
"
h-5 w-5
"
/>
<
/div
>
<
/button
>
{
open
&&
(
<
div
className
=
"
absolute h-fit max-h-52 min-w-[9rem] w-fit bg-dark-900 top-12 right-0 rounded-xl z-50 overflow-y-scroll
"
>
<
div
className
=
"
my-2
"
>
{
list
.
map
((
coin
,
index
)
=>
{
return
(
<
DropdownItem
onClick
=
{()
=>
setValue
(
coin
.
id
)}
key
=
{
index
}
selected
=
{
coin
.
id
===
value
}
>
{
coin
.
name
}
<
/DropdownItem
>
);
})}
<
/div
>
<
/div
>
)}
<
/div
>
);
}
function
DropdownItem
({
children
,
onClick
,
selected
})
{
return
(
<
div
className
=
{
classNames
(
"
py-2 px-4 rounded-xl mx-2
"
,
{
"
bg-white dark:text-black
"
:
selected
,
"
hover:bg-dark-600 dark:text-white
"
:
!
selected
,
})}
onClick
=
{
!
selected
&&
onClick
}
>
{
children
}
<
/div
>
);
}
export
default
Dropdown
;
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