Skip to content

Commit

Permalink
Crée un composant Section et utilise le sur la page d'accueil + suppr…
Browse files Browse the repository at this point in the history
…ime les sections non voulues
  • Loading branch information
martinratinaud committed Feb 13, 2025
1 parent f09fffe commit 046f2ee
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 112 deletions.
8 changes: 5 additions & 3 deletions src/components/GenericContent/AvantagesChauffageUrbain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import Text from '@/components/ui/Text';
const AvantagesChauffageUrbain = ({ title }: { title?: string }) => {
return (
<Box className="fr-container">
<Heading as="h2" center>
{title ? title : 'Les avantages du chauffage urbain'}
</Heading>
{title && (
<Heading as="h2" center>
{title}
</Heading>
)}
<Box className="fr-grid-row fr-grid-row--gutters" mt="10w">
<Box display="flex" flexDirection="column" alignItems="center" className="fr-col-12 fr-col-lg-6 fr-col-xl-3">
<Image src="/img/copro_avantages_1.webp" alt="" width={160} height={125} priority className="img-object-contain" />
Expand Down
91 changes: 43 additions & 48 deletions src/components/Partners/Partners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import ButtonsGroup from '@codegouvfr/react-dsfr/ButtonsGroup';
import { useCallback, useEffect, useState } from 'react';

import Box from '@/components/ui/Box';
import Heading from '@/components/ui/Heading';
import Icon from '@/components/ui/Icon';
import Text from '@/components/ui/Text';
import Section, { SectionSubtitle, SectionTitle, type SectionProps } from '@/components/ui/Section';
import { partenaires } from '@/data/partenaires/partnerData';
import { shuffleArray } from '@/utils/array';

import { Arrow, PartnerImage, PartnerImages, PartnerLink } from './Partners.style';

const Partners = () => {
const Partners: React.FC<SectionProps> = (props) => {
const [firstLogo, setFirstLogo] = useState(0);
const [logos, setLogos] = useState(partenaires);

Expand All @@ -31,55 +30,51 @@ const Partners = () => {
}, [setNextLogo]);

return (
<Box py="10w" id="partenaires">
<Box className="fr-container">
<Heading as="h2" center>
Notre réseau de partenaires
</Heading>
<Text textAlign="center" maxWidth="80w" className="fr-m-md-auto">
Plusieurs acteurs soutiennent France Chaleur Urbaine : ils contribuent au développement du service, apportent des données,
utilisent le service ou s’en font le relais.
</Text>
<Section id="partenaires" {...props}>
<SectionTitle>Notre réseau de partenaires</SectionTitle>
<SectionSubtitle>
Plusieurs acteurs soutiennent France Chaleur Urbaine : ils contribuent au développement du service, apportent des données, utilisent
le service ou s’en font le relais.
</SectionSubtitle>

<Box display="flex" alignItems="center" gap="16px" mt="8w">
<Arrow onClick={() => setNextLogo(-1)}>
<Icon name="ri-arrow-left-circle-line" size="lg" />
</Arrow>
<PartnerImages>
{logos.map(({ image, title, link }, index) => (
<PartnerLink show={index >= firstLogo} href={link} target="_blank" rel="noreferrer noopener" key={title}>
<PartnerImage src={image} alt={title} loading="lazy" className="max-w-none" />
</PartnerLink>
))}
</PartnerImages>
<Arrow onClick={() => setNextLogo(1)}>
<Icon name="ri-arrow-right-circle-line" size="lg" />
</Arrow>
</Box>
<Box display="flex" alignItems="center" gap="16px" mt="8w">
<Arrow onClick={() => setNextLogo(-1)}>
<Icon name="ri-arrow-left-circle-line" size="lg" />
</Arrow>
<PartnerImages>
{logos.map(({ image, title, link }, index) => (
<PartnerLink show={index >= firstLogo} href={link} target="_blank" rel="noreferrer noopener" key={title}>
<PartnerImage src={image} alt={title} loading="lazy" className="max-w-none" />
</PartnerLink>
))}
</PartnerImages>
<Arrow onClick={() => setNextLogo(1)}>
<Icon name="ri-arrow-right-circle-line" size="lg" />
</Arrow>
</Box>

<ButtonsGroup
className="fr-mt-8w"
inlineLayoutWhen="sm and up"
alignment="center"
buttons={[
{
children: 'Rejoindre notre réseau',
linkProps: {
href: '/contact',
},
<ButtonsGroup
className="fr-mt-8w"
inlineLayoutWhen="sm and up"
alignment="center"
buttons={[
{
children: 'Rejoindre notre réseau',
linkProps: {
href: '/contact',
},
{
children: 'Notre dossier de présentation',
priority: 'secondary',
linkProps: {
href: '/documentation/dossier-presse.pdf',
target: '_blank',
},
},
{
children: 'Notre dossier de présentation',
priority: 'secondary',
linkProps: {
href: '/documentation/dossier-presse.pdf',
target: '_blank',
},
]}
/>
</Box>
</Box>
},
]}
/>
</Section>
);
};

Expand Down
133 changes: 133 additions & 0 deletions src/components/ui/Section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { cva, type VariantProps } from 'class-variance-authority';
import React from 'react';

import cx from '@/utils/cx';

import Box from './Box';
import Heading from './Heading';
import type Text from './Text';

const sectionVariants = cva('', {
variants: {
size: {
sm: '',
md: 'py-10w',
lg: '',
},
color: {
normal: '',
light: 'bg-blueFrance-_975_75',
accent: 'bg-blueFrance-main525 text-white',
},
},
defaultVariants: {
size: 'md',
color: 'normal',
},
});

export type SectionProps = React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof sectionVariants>;

const SectionContext = React.createContext<VariantProps<typeof sectionVariants>>({});

const Section = ({ children, className, size, color, ...props }: SectionProps) => {
return (
<SectionContext.Provider value={{ size, color }}>
<section className={cx(sectionVariants({ size, color }), className)} {...props}>
<div className="fr-container">{children}</div>
</section>
</SectionContext.Provider>
);
};

const headingVariants = cva('', {
variants: {
color: {
normal: '!text-blue',
light: '!text-black',
accent: '!text-white',
},
},
defaultVariants: {
color: 'normal',
},
});

const titleVariants = (props: VariantProps<typeof headingVariants>) => cx('text-center', headingVariants(props));

export type SectionTitleProps = React.ComponentProps<typeof Heading> & VariantProps<typeof titleVariants>;

export const SectionTitle = ({ children, className, ...props }: React.ComponentProps<typeof Heading>) => {
const contextVariants = React.useContext(SectionContext);

return (
<Heading as="h2" size="h2" className={cx(titleVariants(contextVariants), className)} {...props}>
{children}
</Heading>
);
};

const subtitleVariants = cva('text-center max-w-[640px] mx-auto', {
variants: {
size: {
sm: 'text-sm mb-2w',
md: 'text-base mb-6w',
lg: 'text-lg mb-8w',
},
color: {
normal: '!text-gray-900',
light: '!text-gray-900',
accent: '!text-gray-100',
},
},
defaultVariants: {
color: 'normal',
size: 'md',
},
});

export const SectionSubtitle = ({ children, className, ...props }: React.ComponentProps<typeof Text>) => {
const contextVariants = React.useContext(SectionContext);
return (
<p className={cx(subtitleVariants(contextVariants), className)} {...props}>
{children}
</p>
);
};

export const SectionHeading = ({ children, className, ...props }: React.ComponentProps<typeof Heading>) => {
const contextVariants = React.useContext(SectionContext);
return (
<Heading className={cx(headingVariants(contextVariants), className)} {...props}>
{children}
</Heading>
);
};

const twoColumnsVariants = cva('flex flex-col lg:flex-row [&>*]:flex-1', {
variants: {
size: {
sm: '',
md: 'my-10w gap-8',
lg: '',
},
},
defaultVariants: {
size: 'md',
},
});

export const SectionTwoColumns = ({ children, className, ...props }: React.ComponentProps<typeof Heading>) => {
const contextVariants = React.useContext(SectionContext);
return (
<div className={cx(twoColumnsVariants(contextVariants), className)} {...props}>
{children}
</div>
);
};

export const SectionContent = ({ children, ...props }: React.ComponentProps<typeof Box>) => {
return <Box {...props}>{children}</Box>;
};

export default Section;
Loading

0 comments on commit 046f2ee

Please sign in to comment.