-
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.
- Loading branch information
Showing
21 changed files
with
399 additions
and
95 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 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
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
78 changes: 78 additions & 0 deletions
78
src/components/shareable/overScreens/AlimentationIntegrate.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,78 @@ | ||
'use client' | ||
|
||
import { useTranslations } from 'next-intl' | ||
import React, { useEffect, useMemo, useState } from 'react' | ||
import useParamContext from 'src/providers/ParamProvider' | ||
import ClipboardBox from 'components/base/ClipboardBox' | ||
import AlimentationListParam from './AlimentationListParam' | ||
import CustomParam, { CustomParamValue } from './CustomParam' | ||
import styles from './CustomParam.module.css' | ||
import IntegratePreview from './IntegratePreview' | ||
import shareStyles from './Share.module.css' | ||
|
||
const AlimentationIntegrate = () => { | ||
const t = useTranslations('alimentation.integrate') | ||
const { theme, language, alimentation: alimentationParams } = useParamContext() | ||
|
||
const [hideButtons, setHideButtons] = useState(false) | ||
const [category, setCategory] = useState(alimentationParams.category) | ||
const [customList, setCustomList] = useState(alimentationParams.customList) | ||
const [equivalents, setEquivalents] = useState(alimentationParams.equivalents) | ||
|
||
useEffect(() => { | ||
setCategory(alimentationParams.category) | ||
}, [alimentationParams.category]) | ||
|
||
const search = useMemo(() => { | ||
const result = `&theme=${theme}&language=${language}` | ||
const hideButtonsParam = hideButtons ? '&hideButtons=true' : '' | ||
if (customList) { | ||
return `alimentationEquivalents=${equivalents.join(',')}${hideButtonsParam}${result}` | ||
} | ||
return `alimentationCategory=${category}${hideButtonsParam}${result}` | ||
}, [category, customList, equivalents, hideButtons, theme, language]) | ||
|
||
return ( | ||
<> | ||
<form id='alimentation-integrate'> | ||
<CustomParam | ||
tracking='Alimentation' | ||
slug='alimentationCategoryIntegrate' | ||
integration | ||
visible | ||
disabled={customList} | ||
param={{ value: category, setter: setCategory } as CustomParamValue} | ||
/> | ||
<div className={shareStyles.separator} /> | ||
<fieldset> | ||
<legend className={styles.title}>{t('customList')}</legend> | ||
<CustomParam | ||
tracking='Alimentation' | ||
slug='customList' | ||
integration | ||
visible | ||
param={{ value: customList, setter: setCustomList } as CustomParamValue} | ||
/> | ||
{customList && <AlimentationListParam equivalents={equivalents} setEquivalents={setEquivalents} />} | ||
</fieldset> | ||
<div className={shareStyles.separator} /> | ||
<fieldset> | ||
<legend className={styles.title}>{t('hideButtons')}</legend> | ||
<CustomParam | ||
tracking='Alimentation' | ||
slug='hideButtons' | ||
integration | ||
visible | ||
param={{ value: hideButtons, setter: setHideButtons } as CustomParamValue} | ||
/> | ||
</fieldset> | ||
</form> | ||
<ClipboardBox | ||
form='alimentation-integrate' | ||
tracking='Alimentation'>{`<script name="impact-co2" src="${process.env.NEXT_PUBLIC_URL}/iframe.js" data-type="/alimentation" data-search="?${search}"></script>`}</ClipboardBox> | ||
<IntegratePreview path='/alimentation' urlParams={search} /> | ||
</> | ||
) | ||
} | ||
|
||
export default AlimentationIntegrate |
21 changes: 21 additions & 0 deletions
21
src/components/shareable/overScreens/AlimentationListParam.module.css
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,21 @@ | ||
.categories { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 2.25rem; | ||
margin-top: -0.5rem; | ||
} | ||
|
||
.category { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
.categoryName { | ||
color: var(--neutral-50); | ||
font-size: 0.875rem; | ||
font-weight: 500; | ||
line-height: 1.5rem; | ||
text-transform: uppercase; | ||
} |
72 changes: 72 additions & 0 deletions
72
src/components/shareable/overScreens/AlimentationListParam.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,72 @@ | ||
import classNames from 'classnames' | ||
import { useTranslations } from 'next-intl' | ||
import { SetStateAction } from 'preact/compat' | ||
import React, { Dispatch } from 'react' | ||
import useParamContext from 'src/providers/ParamProvider' | ||
import { getNameWithoutSuffix } from 'utils/Equivalent/equivalent' | ||
import { AlimentationCategories, equivalentsByCategory } from 'utils/alimentation' | ||
import EquivalentIcon from 'components/base/EquivalentIcon' | ||
import Button from 'components/base/buttons/Button' | ||
import CheckboxInput from 'components/form/CheckboxInput' | ||
import styles from './AlimentationListParam.module.css' | ||
import listStyles from './TransportListParam.module.css' | ||
|
||
const AlimentationListParam = ({ | ||
equivalents, | ||
setEquivalents, | ||
}: { | ||
equivalents: string[] | ||
setEquivalents: Dispatch<SetStateAction<string[]>> | ||
}) => { | ||
const t = useTranslations('alimentation') | ||
const { language } = useParamContext() | ||
return ( | ||
<ul className={styles.categories}> | ||
{equivalentsByCategory[AlimentationCategories.Group].map((category) => ( | ||
<li key={category.name} className={styles.list}> | ||
<div className={styles.category}> | ||
<p className={styles.categoryName}>{t(category.name)}</p> | ||
<Button | ||
asLink | ||
type='button' | ||
onClick={() => | ||
setEquivalents( | ||
equivalents.filter((equivalent) => category.equivalents.every(({ slug }) => equivalent !== slug)) | ||
) | ||
}> | ||
{t('deselect')} | ||
</Button> | ||
</div> | ||
<ul className={listStyles.equivalents}> | ||
{category.equivalents.map((equivalent) => ( | ||
<li key={equivalent.slug} className={listStyles.list}> | ||
<CheckboxInput | ||
id={`alimentation-list-${equivalent.slug}-checkbox`} | ||
reversed | ||
className={classNames(listStyles.mode, listStyles.active)} | ||
labelClassName={listStyles.modeLabel} | ||
checked={equivalents.includes(equivalent.slug)} | ||
setChecked={(checked) => | ||
setEquivalents( | ||
checked | ||
? [...equivalents, equivalent.slug] | ||
: equivalents.filter((value) => value !== equivalent.slug) | ||
) | ||
} | ||
label={ | ||
<span className={listStyles.left}> | ||
<EquivalentIcon equivalent={equivalent} height={2.5} /> | ||
<span className={listStyles.name}>{getNameWithoutSuffix(language, equivalent)}</span> | ||
</span> | ||
} | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} | ||
|
||
export default AlimentationListParam |
Oops, something went wrong.