-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9076d7f
commit 6af0194
Showing
22 changed files
with
710 additions
and
23 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ yarn-debug.log* | |
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
ui | ||
node_modules | ||
dist | ||
dist-ssr | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,94 @@ | ||
import { | ||
useCallback, | ||
useContext, | ||
} from 'react'; | ||
import { LinkProps } from 'react-router-dom'; | ||
import { | ||
Button, | ||
ButtonProps, | ||
ConfirmButton, | ||
ConfirmButtonProps, | ||
} from '@ifrc-go/ui'; | ||
import { DropdownMenuContext } from '@ifrc-go/ui/contexts'; | ||
import { isDefined } from '@togglecorp/fujs'; | ||
|
||
type CommonProp = { | ||
persist?: boolean; | ||
} | ||
|
||
type ButtonTypeProps<NAME> = Omit<ButtonProps<NAME>, 'type'> & { | ||
type: 'button'; | ||
} | ||
|
||
type LinkTypeProps = LinkProps & { | ||
type: 'link'; | ||
} | ||
|
||
type ConfirmButtonTypeProps<NAME> = Omit<ConfirmButtonProps<NAME>, 'type'> & { | ||
type: 'confirm-button', | ||
} | ||
|
||
type Props<N> = CommonProp & (ButtonTypeProps<N> | LinkTypeProps | ConfirmButtonTypeProps<N>); | ||
|
||
function DropdownMenuItem<NAME>(props: Props<NAME>) { | ||
const { | ||
type, | ||
onClick, | ||
persist = false, | ||
} = props; | ||
const { setShowDropdown } = useContext(DropdownMenuContext); | ||
|
||
const handleButtonClick = useCallback( | ||
(name: NAME, e: React.MouseEvent<HTMLButtonElement>) => { | ||
if (!persist) { | ||
setShowDropdown(false); | ||
} | ||
if (isDefined(onClick) && type !== 'link') { | ||
onClick(name, e); | ||
} | ||
}, | ||
[setShowDropdown, type, onClick, persist], | ||
); | ||
|
||
if (type === 'button') { | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type: _, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
persist: __, | ||
variant = 'dropdown-item', | ||
...otherProps | ||
} = props; | ||
|
||
return ( | ||
<Button | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...otherProps} | ||
variant={variant} | ||
onClick={handleButtonClick} | ||
/> | ||
); | ||
} | ||
|
||
if (type === 'confirm-button') { | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type: _, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
persist: __, | ||
variant = 'dropdown-item', | ||
...otherProps | ||
} = props; | ||
|
||
return ( | ||
<ConfirmButton | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...otherProps} | ||
variant={variant} | ||
onClick={handleButtonClick} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default DropdownMenuItem; |
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,93 @@ | ||
import { | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
} from 'react'; | ||
import { CheckFillIcon } from '@ifrc-go/icons'; | ||
import { DropdownMenu } from '@ifrc-go/ui'; | ||
import { | ||
type Language, | ||
LanguageContext, | ||
} from '@ifrc-go/ui/contexts'; | ||
import { languageNameMapEn } from '@ifrc-go/ui/utils'; | ||
import { | ||
_cs, | ||
mapToList, | ||
} from '@togglecorp/fujs'; | ||
|
||
import DropdownMenuItem from '#components/DropdownMenuItem'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
// NOTE: these doesn't need to be translated | ||
const languageNameMap: Record<Language, string> = { | ||
en: 'English', | ||
fr: 'Français', | ||
es: 'Español', | ||
ar: 'عربي', | ||
}; | ||
|
||
const languageList = mapToList( | ||
languageNameMap, | ||
(value, key) => ({ key: key as Language, value }), | ||
); | ||
|
||
function LangaugeDropdown() { | ||
const { | ||
currentLanguage, | ||
setCurrentLanguage, | ||
} = useContext(LanguageContext); | ||
|
||
useEffect( | ||
() => { | ||
if (currentLanguage === 'ar') { | ||
document.body.style.direction = 'rtl'; | ||
document.body.setAttribute('dir', 'rtl'); | ||
} else { | ||
document.body.style.direction = 'ltr'; | ||
document.body.setAttribute('dir', 'ltr'); | ||
} | ||
}, | ||
[currentLanguage], | ||
); | ||
|
||
const handleLanguageConfirm = useCallback( | ||
(newLanguage: Language) => { | ||
setCurrentLanguage(newLanguage); | ||
window.location.reload(); | ||
}, | ||
[setCurrentLanguage], | ||
); | ||
|
||
return ( | ||
<DropdownMenu | ||
label={languageNameMapEn[currentLanguage]} | ||
variant="tertiary" | ||
persistent | ||
> | ||
{languageList.map( | ||
(language) => ( | ||
<DropdownMenuItem | ||
type="confirm-button" | ||
key={language.key} | ||
name={language.key} | ||
persist | ||
onConfirm={handleLanguageConfirm} | ||
icons={( | ||
<CheckFillIcon | ||
className={_cs( | ||
styles.icon, | ||
language.key === currentLanguage && styles.active, | ||
)} | ||
/> | ||
)} | ||
> | ||
{language.value} | ||
</DropdownMenuItem> | ||
), | ||
)} | ||
</DropdownMenu> | ||
); | ||
} | ||
|
||
export default LangaugeDropdown; |
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,8 @@ | ||
.icon { | ||
color: transparent; | ||
font-size: var(--go-ui-height-icon-multiplier); | ||
|
||
&.active { | ||
color: var(--go-ui-color-primary-red) | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"namespace": "common", | ||
"strings": { | ||
"headerAppName": "Alert Hub", | ||
"headerLogoAltText": "Alert Hub logo", | ||
"appLogin": "Login", | ||
"appAbout": "About", | ||
"appResources": "Resources" | ||
} | ||
} |
Oops, something went wrong.