-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add organization carousel to front page
- Loading branch information
Showing
8 changed files
with
178 additions
and
35 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
apps/data-norge/src/app/components/frontpage/organization-carousel/index.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,71 @@ | ||
'use client'; | ||
|
||
import organizations from './organizations.json'; | ||
import styles from './organization-carousel.module.scss'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Popover } from '@digdir/designsystemet-react'; | ||
import { Dictionary } from '@fdk-frontend/dictionaries'; | ||
|
||
type Props = { | ||
dictionary: Dictionary; | ||
}; | ||
|
||
const OrganizationCarousel = ({ dictionary }: Props) => { | ||
const INITIAL_INDEX = 0; | ||
const FADE_DURATION = 500; | ||
const INTERVAL = 6000; | ||
|
||
const [currentIndex, setCurrentIndex] = useState<number>(INITIAL_INDEX); | ||
const [fade, setFade] = useState<boolean>(true); | ||
const [isPaused, setIsPaused] = useState<boolean>(false); | ||
const [open, setOpen] = useState<boolean>(false); | ||
const [shuffledOrganizations, setShuffledOrganizations] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
const shuffled = [...organizations].sort(() => Math.random() - 0.5); | ||
setShuffledOrganizations(shuffled); | ||
}, []); | ||
|
||
const handleRotation = () => { | ||
setFade(false); | ||
setTimeout(() => { | ||
setCurrentIndex((prevIndex) => (prevIndex + 1) % shuffledOrganizations.length); | ||
setFade(true); | ||
}, FADE_DURATION); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isPaused) return; | ||
const intervalId = setInterval(handleRotation, INTERVAL); | ||
return () => clearInterval(intervalId); | ||
}, [isPaused, currentIndex, shuffledOrganizations]); | ||
|
||
return ( | ||
<div> | ||
<Popover | ||
open={open} | ||
placement='left' | ||
variant='info' | ||
> | ||
<Popover.Trigger asChild> | ||
<span | ||
role='button' | ||
tabIndex={0} | ||
onMouseEnter={() => setOpen(true)} | ||
onMouseLeave={() => setOpen(false)} | ||
onClick={() => setIsPaused((prevState) => !prevState)} | ||
onKeyDown={(e) => e.key === 'Enter' && setIsPaused((prevState) => !prevState)} | ||
className={`${fade ? styles['fade-in'] : styles['fade-out']}`} | ||
> | ||
{`${dictionary.shareDataBanner.doLike} ${shuffledOrganizations[currentIndex]}`} | ||
</span> | ||
</Popover.Trigger> | ||
<Popover.Content> | ||
{isPaused ? dictionary.shareDataBanner.popover.start : dictionary.shareDataBanner.popover.pause} | ||
</Popover.Content> | ||
</Popover> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrganizationCarousel; |
14 changes: 14 additions & 0 deletions
14
...orge/src/app/components/frontpage/organization-carousel/organization-carousel.module.scss
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,14 @@ | ||
.fade-in { | ||
opacity: 1; | ||
transition: | ||
opacity 0.5s, | ||
transform 1s; | ||
transition-delay: 0.5s; | ||
} | ||
|
||
.fade-out { | ||
opacity: 0; | ||
transition: | ||
opacity 0.5s, | ||
transform 1s; | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/data-norge/src/app/components/frontpage/organization-carousel/organizations.json
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,35 @@ | ||
[ | ||
"Arbeids- og velferdsetaten", | ||
"Arbeidstilsynet", | ||
"Artsdatabanken", | ||
"Bergen kommune", | ||
"Digitaliseringsdirektoratet", | ||
"Direktoratet for internasjonalisering og kvalitetsutvikling i høyere utdanning (DIKU)", | ||
"Direktoratet for samfunnssikkerhet og beredskap (DSB)", | ||
"Fiskeridirektoratet", | ||
"Folkehelseinstituttet", | ||
"Fredrikstad kommune", | ||
"Havforskningsinstituttet", | ||
"Høgskulen på Vestlandet", | ||
"Kystverket", | ||
"Landbruksdirektoratet", | ||
"Mattilsynet", | ||
"Meteorologisk institutt", | ||
"Miljødirektoratet", | ||
"Nasjonalbiblioteket", | ||
"Nibio - Norsk Institutt for Bioøkonomi", | ||
"Norges geologiske undersøkelse", | ||
"Norges vassdrags- og energidirektorat (NVE)", | ||
"Norsk polarinstitutt", | ||
"Oslo kommune", | ||
"Registerenheten i Brønnøysund", | ||
"Riksantikvaren", | ||
"Sokkeldirektoratet", | ||
"Statens kartverk", | ||
"Statens lånekasse for utdanning", | ||
"Statens vegvesen", | ||
"Statistisk sentralbyrå", | ||
"Stavanger kommune", | ||
"Tolletaten", | ||
"Utdanningsdirektoratet" | ||
] |
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 |
---|---|---|
@@ -1,31 +1,41 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"jsx": "preserve", | ||
"allowJs": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.js", | ||
"**/*.jsx", | ||
"next-env.d.ts", | ||
".next/types/**/*.ts", | ||
"../../dist/apps/data.norge.no/.next/types/**/*.ts" | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"jsx": "preserve", | ||
"allowJs": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"exclude": ["node_modules", "jest.config.ts", "**/*.spec.ts", "**/*.test.ts", "**/*.stories.tsx"] | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.js", | ||
"**/*.jsx", | ||
"next-env.d.ts", | ||
".next/types/**/*.ts", | ||
"../../dist/apps/data.norge.no/.next/types/**/*.ts", | ||
"../../dist/apps/data-norge/.next/types/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"jest.config.ts", | ||
"**/*.spec.ts", | ||
"**/*.test.ts", | ||
"**/*.stories.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
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