-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: déplace le choix de la langue dans une liste dédiée
- Loading branch information
1 parent
ce855e1
commit ed24663
Showing
11 changed files
with
153 additions
and
61 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import clsx from 'clsx' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
export default function LanguagesIcon ({className, height = 24, width = 24}) { | ||
return <svg xmlns="http://www.w3.org/2000/svg" | ||
width={width} | ||
height={height} | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className={clsx("lucide", "lucide-languages", className)}> | ||
<path d="m5 8 6 6"/> | ||
<path d="m4 14 6-6 2-3"/> | ||
<path d="M2 5h12"/> | ||
<path d="M7 2h1"/> | ||
<path d="m22 22-5-10-5 10"/> | ||
<path d="M14 18h6"/> | ||
</svg> | ||
} | ||
|
||
LanguagesIcon.propTypes = { | ||
className: PropTypes.string, | ||
height: PropTypes.number, | ||
width: PropTypes.number, | ||
} |
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,46 @@ | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import useComponentVisible from '../../hooks/componentVisible.js' | ||
import i18n from '../../i18n.js' | ||
import LanguagesIcon from './LanguagesIcon.jsx' | ||
import styles from './LanguagesMenu.module.scss' | ||
|
||
export default function LanguagesMenu () { | ||
const { t } = useTranslation() | ||
const { ref, isComponentVisible, setIsComponentVisible } = useComponentVisible(false) | ||
|
||
const [language, setLanguage] = useState(i18n.language) | ||
|
||
useEffect(() => { | ||
setLanguage(i18n.language) | ||
}, [i18n.language]) | ||
|
||
const handleLanguageChange = useCallback(async (value) => { | ||
await i18n.changeLanguage(value) | ||
setLanguage(value) | ||
}, []) | ||
|
||
useEffect(() => { | ||
setIsComponentVisible(false) | ||
}, []) | ||
|
||
return ( | ||
<div ref={ref} className={styles.container}> | ||
<div className={styles.languagesMenuLink} onClick={() => setIsComponentVisible(!isComponentVisible)}> | ||
<LanguagesIcon width={20} height={20}/> | ||
</div> | ||
{isComponentVisible && <div className={styles.menu}> | ||
<div> | ||
<ul className={styles.languages}> | ||
<li onClick={() => handleLanguageChange('en')} | ||
className={language === 'en' ? styles.activeStyle : ''} title="English">English | ||
</li> | ||
<li onClick={() => handleLanguageChange('fr')} | ||
className={language === 'fr' ? styles.activeStyle : ''} title="Français">Français | ||
</li> | ||
</ul> | ||
</div> | ||
</div>} | ||
</div> | ||
) | ||
} |
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,54 @@ | ||
.container { | ||
display: flex; | ||
gap: 2em; | ||
position: relative; | ||
} | ||
|
||
.languagesMenuLink { | ||
display: flex; | ||
cursor: pointer; | ||
gap: 0.5em; | ||
align-items: center; | ||
} | ||
|
||
.languages { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 0.75em; | ||
font-size: 0.9em; | ||
justify-content: space-around; | ||
} | ||
|
||
.languages > li { | ||
border-bottom: 2px solid transparent; | ||
padding: 0.25em 0.5em; | ||
font-weight: 400; | ||
cursor: pointer; | ||
} | ||
|
||
/* hack: do not change container size when changing font weight */ | ||
/* https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size */ | ||
.languages > li::after { | ||
display: block; | ||
content: attr(title); | ||
font-weight: bold; | ||
height: 1px; | ||
color: transparent; | ||
overflow: hidden; | ||
visibility: hidden; | ||
} | ||
|
||
.languages > li.activeStyle { | ||
border-bottom-color: #eee; | ||
font-weight: 600; | ||
} | ||
|
||
.menu { | ||
position: absolute; | ||
top: 66px; | ||
right: -0.5rem; | ||
background-color: #202020; | ||
padding: 1rem 1.75rem; | ||
z-index: 99; | ||
} |
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