-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
629 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
{ | ||
"georgia_political_view_desc": { | ||
"text": "" | ||
}, | ||
"cyprus_political_view_desc": { | ||
"text": "" | ||
}, | ||
"palestine_political_view_desc": { | ||
"text": "" | ||
}, | ||
"greece_political_view_desc": { | ||
"text": "" | ||
} | ||
} | ||
{} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
src/atomicui/atoms/MapLanguageDropdown/MapLanguageDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { FC, useCallback, useEffect, useRef, useState } from "react"; | ||
|
||
import { Flex, Text } from "@aws-amplify/ui-react"; | ||
import { IconArrow } from "@demo/assets/svgs"; | ||
import { appConfig } from "@demo/core/constants"; | ||
import { useMap } from "@demo/hooks"; | ||
import { useTranslation } from "react-i18next"; | ||
import "./styles.scss"; | ||
|
||
const { | ||
MAP_RESOURCES: { MAP_LANGUAGES } | ||
} = appConfig; | ||
|
||
interface MapLanguageDropdownProps { | ||
bordered?: boolean; | ||
arrowIconColor?: string; | ||
width?: string; | ||
disabled?: boolean; | ||
} | ||
|
||
const MapLanguageDropdown: FC<MapLanguageDropdownProps> = ({ | ||
bordered = false, | ||
arrowIconColor, | ||
width = "100%", | ||
disabled = false | ||
}) => { | ||
const [open, setOpen] = useState(false); | ||
const dropdownRef = useRef<HTMLDivElement>(null); | ||
const { i18n, t } = useTranslation(); | ||
const { mapLanguage, setMapLanguage } = useMap(); | ||
const mapLanguageDir = i18n.dir(mapLanguage.value); | ||
|
||
const handleClickOutside = (event: MouseEvent) => { | ||
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { | ||
setOpen(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener("mousedown", handleClickOutside); | ||
|
||
return () => { | ||
document.removeEventListener("mousedown", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
const handleClick = useCallback( | ||
(option: { value: string; label: string }) => { | ||
setMapLanguage(option); | ||
setOpen(false); | ||
}, | ||
[setMapLanguage] | ||
); | ||
|
||
return ( | ||
<div ref={dropdownRef} className="dropdown-container" style={{ width }}> | ||
<div | ||
data-testid="dropdown-trigger-map-language" | ||
style={{ cursor: disabled ? "not-allowed" : "pointer", backgroundColor: disabled ? "#ddd" : "" }} | ||
className={bordered ? `trigger bordered dropdown-${open}` : "trigger"} | ||
onClick={() => !disabled && setOpen(!open)} | ||
> | ||
<p data-testid="dropdown-label" className="dropdown-label" dir={mapLanguageDir}> | ||
{mapLanguage.label} | ||
</p> | ||
<IconArrow | ||
style={{ | ||
transform: open ? "rotate(180deg)" : "rotate(0deg)", | ||
width: bordered ? "1rem" : "1.23rem", | ||
height: bordered ? "" : "1.23rem", | ||
fill: arrowIconColor ? arrowIconColor : "var(--primary-color)" | ||
}} | ||
/> | ||
</div> | ||
{open && ( | ||
<ul data-testid="dropdown-options" className={bordered ? "options bordered" : "options"}> | ||
{MAP_LANGUAGES.map(({ value, label }) => { | ||
return ( | ||
<li | ||
data-testid={value} | ||
key={value} | ||
style={{ display: "flex", justifyContent: "start" }} | ||
onClick={() => handleClick({ value, label })} | ||
> | ||
<Flex gap={0} direction="column" padding="0.46rem 1.23rem"> | ||
<Text className="bold small-text" color="var(--tertiary-color)"> | ||
{t(label)} | ||
</Text> | ||
</Flex> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MapLanguageDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as MapLanguageDropdown } from "./MapLanguageDropdown"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */ | ||
/* SPDX-License-Identifier: MIT-0 */ | ||
|
||
.dropdown-container { | ||
position: relative; | ||
display: inline-block; | ||
|
||
.trigger { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
max-width: 18.15rem; | ||
height: 2.46rem; | ||
outline: none; | ||
cursor: pointer; | ||
background-color: transparent; | ||
padding: 0.62rem 1rem; | ||
|
||
@media only screen and (max-width: 1023px) { | ||
max-width: unset; | ||
} | ||
|
||
&.bordered { | ||
padding: 12px 16px; | ||
min-width: 100%; | ||
border: 1px solid var(--grey-color-3); | ||
border-radius: 7px; | ||
height: 40px; | ||
justify-content: space-between; | ||
|
||
.dropdown-label { | ||
color: var(--grey-color); | ||
font-family: "AmazonEmber-Regular"; | ||
font-weight: 400; | ||
font-size: 1.08rem; | ||
width: 90%; | ||
} | ||
} | ||
|
||
&.bordered.dropdown-true { | ||
border-color: var(--primary-color); | ||
} | ||
|
||
&.bordered.dropdown-false { | ||
background-color: var(--grey-color-4); | ||
border: 1px solid var(--grey-color-3); | ||
|
||
p { | ||
color: var(--tertiary-color); | ||
} | ||
} | ||
|
||
p { | ||
font-family: "AmazonEmber-Bold"; | ||
font-size: 1.08rem; | ||
color: var(--primary-color); | ||
margin-right: 0.5rem; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
|
||
.options { | ||
position: absolute; | ||
right: 0; | ||
display: flex; | ||
flex-direction: column; | ||
width: 21.5rem; | ||
height: 16rem; | ||
overflow: auto; | ||
list-style: none; | ||
background-color: var(--white-color); | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.202633); | ||
border-radius: 0.62rem; | ||
margin-top: 0.62rem; | ||
padding: 0; | ||
z-index: 1; | ||
|
||
@media only screen and (max-width: 562px) { | ||
width: 12rem; | ||
left: -10%; | ||
} | ||
|
||
&.bordered { | ||
left: 0; | ||
height: auto; | ||
width: 100%; | ||
border-radius: 4px; | ||
max-height: calc(100vh - 40rem); | ||
box-shadow: none; | ||
border: 1px solid var(--grey-color-5); | ||
|
||
li { | ||
padding: 0; | ||
|
||
&:hover { | ||
background-color: var(--primary-alpha-light-color); | ||
} | ||
} | ||
} | ||
|
||
li { | ||
cursor: pointer; | ||
padding: 8px 16px; | ||
user-select: none; | ||
|
||
&:hover { | ||
background-color: var(--primary-alpha-light-color); | ||
|
||
@media only screen and (min-width: 1023px) { | ||
background-color: rgba(0, 130, 150, 0.08); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.