-
Notifications
You must be signed in to change notification settings - Fork 33
Legg til konfigurerbar forside i portalen #5885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 +1,51 @@ | ||
| export default function FrontPage() { | ||
| return <h1>Wheee!</h1>; | ||
| import { | ||
| FrontPageImageStrip, | ||
| FrontPageLogo, | ||
| FrontPageNewsSection, | ||
| FrontPagePortalSections, | ||
| } from "@/components/frontpage"; | ||
| import styles from "@/components/frontpage/frontpagePage.module.scss"; | ||
| import { sanityFetch } from "@/sanity/lib/live"; | ||
| import { frontpageQuery } from "@/sanity/queries/frontpage"; | ||
| import type { FrontpageQueryResult } from "@/sanity/types"; | ||
|
|
||
| const DEFAULT_HERO_TEXT = "Jøkul Designsystem"; | ||
|
|
||
| const getHeroText = (frontpage?: FrontpageQueryResult["frontpage"]) => { | ||
| if (frontpage?.hero?.useCustomText && frontpage.hero.text) { | ||
| return frontpage.hero.text; | ||
| } | ||
|
|
||
| return DEFAULT_HERO_TEXT; | ||
| }; | ||
|
|
||
| export default async function FrontPage() { | ||
| const { data } = await sanityFetch({ | ||
| query: frontpageQuery, | ||
| requestTag: "frontpage", | ||
| tags: [ | ||
| "jokul_frontpage", | ||
| "jokul_component", | ||
| "jokul_fundamentals", | ||
| "jokul_blog_post", | ||
| ], | ||
| }); | ||
| const frontpageData = data as FrontpageQueryResult | null; | ||
| const frontpage = frontpageData?.frontpage || null; | ||
| const latestUpdatedDocuments = frontpageData?.latestUpdatedDocuments || []; | ||
|
|
||
| return ( | ||
| <div className={styles.frontPage}> | ||
| <section> | ||
| <h1 className="jkl-sr-only">Jøkul Designsystem</h1> | ||
| <FrontPageLogo text={getHeroText(frontpage)} delay={100} /> | ||
| </section> | ||
| <FrontPagePortalSections links={frontpage?.portalLinks} /> | ||
| <FrontPageImageStrip images={frontpage?.gridImages} /> | ||
| <FrontPageNewsSection | ||
| featuredDocument={frontpage?.highlightedEntry} | ||
| documents={latestUpdatedDocuments} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
portal/src/components/frontpage/FrontPageImageStrip/FrontPageImageStrip.tsx
This file contains hidden or 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,69 @@ | ||
| import { client } from "@/sanity/lib/client"; | ||
| import type { FrontpageQueryResult } from "@/sanity/types"; | ||
| import { Flex } from "@fremtind/jokul/flex"; | ||
| import { createImageUrlBuilder } from "@sanity/image-url"; | ||
| import styles from "./frontPageImageStrip.module.scss"; | ||
|
|
||
| const builder = createImageUrlBuilder(client); | ||
|
|
||
| type FrontPageImage = NonNullable< | ||
| NonNullable<FrontpageQueryResult["frontpage"]>["gridImages"] | ||
| >[number]; | ||
|
|
||
| type FrontPageImageStripProps = { | ||
| images?: FrontPageImage[] | null; | ||
| }; | ||
|
|
||
| export const FrontPageImageStrip = ({ images }: FrontPageImageStripProps) => { | ||
| const resolvedImages = | ||
| images?.flatMap((image) => { | ||
| if (!image.asset?._ref) { | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| key: image.asset._ref, | ||
| src: builder.image(image).width(1600).auto("format").url(), | ||
| }, | ||
| ]; | ||
| }) || []; | ||
|
|
||
| if (!resolvedImages.length) { | ||
| return null; | ||
| } | ||
|
|
||
| const marqueeSeedImages = Array.from( | ||
| { | ||
| length: Math.ceil( | ||
| Math.max(resolvedImages.length, 6) / | ||
| resolvedImages.length, | ||
| ), | ||
| }, | ||
| () => resolvedImages, | ||
| ) | ||
| .flat() | ||
| .slice(0, Math.max(resolvedImages.length, 6)); | ||
| const animationDuration = `${Math.max(marqueeSeedImages.length * 12, 24)}s`; | ||
| const marqueeImages = [...marqueeSeedImages, ...marqueeSeedImages]; | ||
|
|
||
| return ( | ||
| <section className={styles.imageStripViewport} aria-hidden="true" inert> | ||
| <Flex | ||
| alignItems="center" | ||
| gap="s" | ||
| className={styles.imageStripTrack} | ||
| style={{ animationDuration }} | ||
| > | ||
| {marqueeImages.map((image, index) => ( | ||
| <img | ||
| key={`${image.key}-${index}`} | ||
| src={image.src} | ||
| alt="" | ||
| loading="lazy" | ||
| /> | ||
| ))} | ||
| </Flex> | ||
| </section> | ||
| ); | ||
| }; |
39 changes: 39 additions & 0 deletions
39
portal/src/components/frontpage/FrontPageImageStrip/frontPageImageStrip.module.scss
This file contains hidden or 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,39 @@ | ||
| @use "@fremtind/jokul/styles/core/jkl"; | ||
|
|
||
| @keyframes image-strip-marquee { | ||
| from { | ||
| transform: translateX(0); | ||
| } | ||
|
|
||
| to { | ||
| transform: translateX(-50%); | ||
| } | ||
| } | ||
|
|
||
| .imageStripViewport { | ||
| --image-strip-item-width: 33svw; | ||
| width: 100vw; | ||
| margin-inline: calc(50% - 50vw); | ||
| padding-bottom: jkl.$spacing-xs; | ||
| overflow: hidden; | ||
|
|
||
| .imageStripTrack { | ||
| width: max-content; | ||
| will-change: transform; | ||
| animation: image-strip-marquee 30s linear infinite; | ||
| height: 100%; | ||
|
|
||
| @media (prefers-reduced-motion: reduce) { | ||
| animation: none; | ||
| } | ||
|
|
||
| img { | ||
| flex: 0 0 var(--image-strip-item-width); | ||
| width: var(--image-strip-item-width); | ||
| display: block; | ||
| height: auto; | ||
| border-radius: jkl.$border-radius-m; | ||
| background-color: jkl.$color-background-container-high; | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
portal/src/components/frontpage/FrontPageLogo/FrontPageLogo.tsx
This file contains hidden or 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,24 @@ | ||
| import { Flex } from "@fremtind/jokul/flex"; | ||
| import { FrontPageLogoText } from "./FrontPageLogoText"; | ||
| import styles from "./frontPageLogo.module.scss"; | ||
|
|
||
| interface FrontPageLogoProps { | ||
| text: string; | ||
| delay: number; | ||
| } | ||
|
|
||
| export const FrontPageLogo = ({ text, delay }: FrontPageLogoProps) => { | ||
| return ( | ||
| <Flex | ||
| as="section" | ||
| alignItems="center" | ||
| className={styles.logoText} | ||
| aria-hidden="true" | ||
| > | ||
| <div className={styles.logoTextShell}> | ||
| <div className={styles.logoTextMeasure}>{text}</div> | ||
| <FrontPageLogoText text={text} delay={delay} /> | ||
| </div> | ||
| </Flex> | ||
| ); | ||
| }; |
61 changes: 61 additions & 0 deletions
61
portal/src/components/frontpage/FrontPageLogo/FrontPageLogoText.tsx
This file contains hidden or 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,61 @@ | ||
| "use client"; | ||
|
|
||
| import { useBrowserPreferences } from "@fremtind/jokul/hooks"; | ||
| import clsx from "clsx"; | ||
| import { useEffect, useState } from "react"; | ||
| import styles from "./frontPageLogo.module.scss"; | ||
|
|
||
| const sanitizeAnimatedText = (text: string) => | ||
| text.replace(/\u200B|\u200C|\u200D|\u2060|\uFEFF/g, ""); | ||
|
|
||
| interface FrontPageLogoTextProps { | ||
| text: string; | ||
| delay: number; | ||
| } | ||
|
|
||
| export const FrontPageLogoText = ({ text, delay }: FrontPageLogoTextProps) => { | ||
| const { prefersReducedMotion } = useBrowserPreferences(); | ||
| const cleanText = sanitizeAnimatedText(text); | ||
| const [displayedText, setDisplayedText] = useState(""); | ||
|
|
||
| useEffect(() => { | ||
| if (prefersReducedMotion || !cleanText.length) { | ||
| setDisplayedText(cleanText); | ||
| return; | ||
| } | ||
|
|
||
| setDisplayedText(""); | ||
| let index = 0; | ||
| let timeout = 0; | ||
|
|
||
| const scheduleNextCharacter = () => { | ||
| timeout = window.setTimeout( | ||
| () => { | ||
| index += 1; | ||
| setDisplayedText(cleanText.slice(0, index)); | ||
|
|
||
| if (index < cleanText.length) { | ||
| scheduleNextCharacter(); | ||
| } | ||
| }, | ||
| Math.max(delay, Math.round(Math.random() * delay + delay / 2)), | ||
| ); | ||
| }; | ||
|
|
||
| scheduleNextCharacter(); | ||
|
|
||
| return () => { | ||
| window.clearTimeout(timeout); | ||
| }; | ||
| }, [cleanText, delay, prefersReducedMotion]); | ||
|
|
||
| return ( | ||
| <div | ||
| className={clsx(styles.logoTextContent, { | ||
| [styles.logoTextContentDone]: displayedText === cleanText, | ||
| })} | ||
| > | ||
| {displayedText} | ||
| </div> | ||
| ); | ||
| }; |
45 changes: 45 additions & 0 deletions
45
portal/src/components/frontpage/FrontPageLogo/frontPageLogo.module.scss
This file contains hidden or 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,45 @@ | ||
| @use "@fremtind/jokul/styles/core/jkl"; | ||
|
|
||
| .logoText { | ||
| font-size: clamp(4rem, 12vw, 11rem); | ||
| max-width: 100%; | ||
|
|
||
| @include jkl.from-medium-device { | ||
| max-width: 85vw; | ||
| min-height: min(68vh, 42rem); | ||
| } | ||
| } | ||
|
|
||
| .logoTextShell { | ||
| position: relative; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .logoTextMeasure, | ||
| .logoTextContent { | ||
| padding-top: jkl.$spacing-l; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .logoTextMeasure { | ||
| visibility: hidden; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .logoTextContent { | ||
| position: absolute; | ||
| inset: 0; | ||
|
|
||
| &::after { | ||
| @include jkl.decorative($content: "_"); | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| .logoTextContentDone { | ||
| &::after { | ||
| @include jkl.motion("exit"); | ||
| transition-property: opacity; | ||
| opacity: 0; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data as FrontpageQueryResultomgår typesikkerhet og kan skjule mismatch mellom GROQ-query og genererte typer. Andre sider brukersanityFetchuten type-assertion (f.eks.portal/src/app/(frontend)/blog/page.tsx), så vurder å lasanityFetch/defineQueryinferere typen direkte eller angi generisk type i fetch-kallet.