-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from incubateur-ademe/add-particuliers-mention…
…-on-homepage
- Loading branch information
Showing
10 changed files
with
1,223 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Que Faire de Mes Déchets | CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test-and-build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
- run: yarn test | ||
- run: yarn build |
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,7 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: "jsdom", | ||
transform: { | ||
"^.+.tsx?$": ["ts-jest", {}], | ||
}, | ||
}; |
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,100 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
type AccordionItem = { | ||
title: string | ||
content: string | ||
} | ||
|
||
const TitleWrapper = styled.h3` | ||
margin: 0; | ||
padding: 0; | ||
` | ||
const Title = styled.button<{ $expanded?: boolean }>` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
jutify-content: space-between; | ||
padding: 1rem; | ||
cursor: pointer; | ||
transition: .25s; | ||
user-select: none; | ||
-webkit-user-select: none; | ||
-webkit-appearance: button; | ||
background: none; | ||
border: none; | ||
&:hover { | ||
background: #fafafa; | ||
} | ||
${({ $expanded }) => $expanded && `background: #E3E3FD;`} | ||
` | ||
|
||
const Chevron = styled.svg<{ $expanded: boolean }>` | ||
---rotation: rotate(180deg); | ||
width: 10px; | ||
height: 10px; | ||
margin-left: auto; | ||
transition: .25s; | ||
will-change: transform; | ||
transform: var(---rotation); | ||
${({ $expanded }) => $expanded && `---rotation: rotate(0deg);`} | ||
` | ||
|
||
const AccordionItemWrapper = styled.div` | ||
border-top: 1px solid rgba(0, 0, 0, .1); | ||
border-bottom: 1px solid rgba(0, 0, 0, .1); | ||
` | ||
|
||
|
||
const Content = styled.p<{ $expanded?: boolean; }> ` | ||
display: none; | ||
padding: 1rem; | ||
${({ $expanded }) => $expanded && `display: block;`} | ||
` | ||
|
||
export default function Accordion({ items }: { items: AccordionItem[] }) { | ||
const [expandedItem, setExpandedItem] = useState<number | null>(null) | ||
|
||
return ( | ||
<div> | ||
{items.map(({ title, content }, index) => { | ||
const expanded = expandedItem === index | ||
const id = `accordion-item-${index}` | ||
return ( | ||
<AccordionItemWrapper key={id}> | ||
<TitleWrapper | ||
> | ||
<Title | ||
$expanded={expanded} | ||
onClick={() => setExpandedItem(expanded ? null : index)} | ||
aria-expanded={expanded} | ||
aria-controls={id} | ||
id={`${id}-button`} | ||
data-testid={`accordion-button`} | ||
type="button" | ||
> | ||
{title} | ||
|
||
<Chevron $expanded={expanded} | ||
width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path fillRule="evenodd" clipRule="evenodd" d="M4.99999 2.21883L1.69999 5.51883L0.757324 4.57616L4.99999 0.333496L9.24266 4.57616L8.29999 5.51883L4.99999 2.21883Z" fill="#000091" /> | ||
</Chevron> | ||
</Title> | ||
</TitleWrapper> | ||
<Content | ||
aria-labelledby={`${id}-button`} | ||
aria-hidden={!expanded} | ||
id={id} | ||
$expanded={expanded} | ||
data-testid={`accordion-content`} | ||
>{content}</Content> | ||
</AccordionItemWrapper> | ||
) | ||
})} | ||
</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
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,15 @@ | ||
import React from "react"; | ||
import Accordion from "components/base/Accordion"; | ||
import styled from "styled-components"; | ||
|
||
const Wrapper = styled.div` | ||
margin-top: 1rem; | ||
` | ||
|
||
export default function ProDisclaimer() { | ||
return ( | ||
<Wrapper> | ||
<Accordion items={[{ title: "Je suis un professionnel", content: "Actuellement, l’ensemble des recommandations ne concerne que les particuliers. " }]} /> | ||
</Wrapper> | ||
); | ||
} |
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,15 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import '@testing-library/jest-dom' | ||
import Accordion from '../src/components/base/Accordion' | ||
|
||
test('Accordion : un clic sur le titre affiche le contenu', async () => { | ||
render( | ||
<Accordion items={[{ title: "Je suis un professionnel", content: "Actuellement, l’ensemble des recommandations ne concerne que les particuliers. " }]} /> | ||
) | ||
|
||
expect(screen.getByTestId('accordion-content')).not.toBeVisible() | ||
await userEvent.click(screen.getByTestId('accordion-button')) | ||
expect(screen.getByTestId('accordion-content')).toBeVisible() | ||
}) |
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,2 @@ | ||
// In your own jest-setup.js (or any other name) | ||
import "@testing-library/jest-dom"; |
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.