Merged in monorepo-step-1 (pull request #1080)

Migrate to a monorepo setup - step 1

* Move web to subfolder /apps/scandic-web

* Yarn + transitive deps

- Move to yarn
- design-system package removed for now since yarn doesn't
support the parameter for token (ie project currently broken)
- Add missing transitive dependencies as Yarn otherwise
prevents these imports
- VS Code doesn't pick up TS path aliases unless you open
/apps/scandic-web instead of root (will be fixed with monorepo)

* Pin framer-motion to temporarily fix typing issue

https://github.com/adobe/react-spectrum/issues/7494

* Pin zod to avoid typ error

There seems to have been a breaking change in the types
returned by zod where error is now returned as undefined
instead of missing in the type. We should just handle this
but to avoid merge conflicts just pin the dependency for
now.

* Pin react-intl version

Pin version of react-intl to avoid tiny type issue where formatMessage
does not accept a generic any more. This will be fixed in a future
commit, but to avoid merge conflicts just pin for now.

* Pin typescript version

Temporarily pin version as newer versions as stricter and results in
a type error. Will be fixed in future commit after merge.

* Setup workspaces

* Add design-system as a monorepo package

* Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN

* Fix husky for monorepo setup

* Update netlify.toml

* Add lint script to root package.json

* Add stub readme

* Fix react-intl formatMessage types

* Test netlify.toml in root

* Remove root toml

* Update netlify.toml publish path

* Remove package-lock.json

* Update build for branch/preview builds


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-02-26 10:36:17 +00:00
committed by Linus Flood
parent 667cab6fb6
commit 80100e7631
2731 changed files with 30986 additions and 23708 deletions

View File

@@ -0,0 +1,65 @@
import { useIntl } from "react-intl"
import useDropdownStore from "@/stores/main-menu"
import { ChevronLeftIcon } from "@/components/Icons"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import styles from "./languageSwitcherContainer.module.css"
import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"
import {
type LanguageSwitcherContainerProps,
LanguageSwitcherTypesEnum,
} from "@/types/components/languageSwitcher/languageSwitcher"
export default function LanguageSwitcherContainer({
children,
type,
}: LanguageSwitcherContainerProps) {
const { toggleDropdown } = useDropdownStore()
const intl = useIntl()
const isFooter = type === LanguageSwitcherTypesEnum.Footer
const isMobileHeader = type === LanguageSwitcherTypesEnum.MobileHeader
const position = isFooter
? DropdownTypeEnum.FooterLanguageSwitcher
: DropdownTypeEnum.HamburgerMenu
return (
<div>
{isMobileHeader ? (
<div className={styles.backWrapper}>
<button
type="button"
className={styles.backButton}
onClick={() => toggleDropdown(position)}
>
<ChevronLeftIcon color="red" height={20} width={20} />
<Subtitle type="one" asChild>
<span>
{intl.formatMessage({
id: "Main menu",
})}
</span>
</Subtitle>
</button>
</div>
) : null}
{isFooter ? (
<div className={styles.closeWrapper}>
<button
type="button"
className={styles.closeButton}
aria-label={intl.formatMessage({
id: "Close menu",
})}
onClick={() => toggleDropdown(position)}
>
<span className={styles.bar} />
</button>
</div>
) : null}
{children}
</div>
)
}

View File

@@ -0,0 +1,70 @@
.backWrapper {
background-color: var(--Base-Surface-Secondary-light-Normal);
padding: var(--Spacing-x2);
}
.backButton {
background-color: transparent;
border: none;
padding: 0;
cursor: pointer;
display: flex;
align-items: center;
gap: var(--Spacing-x1);
}
.closeWrapper {
display: flex;
justify-content: flex-end;
padding: var(--Spacing-x2);
border-bottom: 1px solid var(--Base-Border-Subtle);
}
.closeButton {
background-color: transparent;
border: none;
cursor: pointer;
justify-self: flex-start;
padding: 11px var(--Spacing-x1) var(--Spacing-x2);
user-select: none;
}
.bar,
.bar::after,
.bar::before {
background: var(--Base-Text-High-contrast);
border-radius: 2.3px;
display: inline-block;
height: 3px;
position: relative;
transition: all 0.3s;
width: var(--Spacing-x4);
}
.bar::after,
.bar::before {
content: "";
left: 0;
position: absolute;
top: 0;
transform-origin: 50% 50%;
width: var(--Spacing-x4);
}
.bar {
background: transparent;
}
.bar::after {
transform: rotate(-45deg);
}
.bar::before {
transform: rotate(45deg);
}
@media screen and (min-width: 768px) {
.closeWrapper {
display: none;
}
}

View File

@@ -0,0 +1,62 @@
"use client"
import { usePathname } from "next/navigation"
import { useIntl } from "react-intl"
import { type Lang, languages } from "@/constants/languages"
import { CheckIcon } from "@/components/Icons"
import Link from "@/components/TempDesignSystem/Link"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import useLang from "@/hooks/useLang"
import { useTrapFocus } from "@/hooks/useTrapFocus"
import { replaceUrlPart } from "./utils"
import styles from "./languageSwitcherContent.module.css"
import type { LanguageSwitcherContentProps } from "@/types/components/languageSwitcher/languageSwitcher"
export default function LanguageSwitcherContent({
urls,
onLanguageSwitch,
}: LanguageSwitcherContentProps) {
const intl = useIntl()
const currentLanguage = useLang()
const languageSwitcherRef = useTrapFocus()
const urlKeys = Object.keys(urls) as Lang[]
const pathname = usePathname()
return (
<div className={styles.languageSwitcherContent} ref={languageSwitcherRef}>
<div className={styles.languageWrapper}>
<Subtitle className={styles.subtitle} type="two">
{intl.formatMessage({ id: "Select your language" })}
</Subtitle>
<ul className={styles.list}>
{urlKeys.map((key) => {
const url = urls[key]?.url
const isActive = currentLanguage === key
if (url) {
return (
<li key={key}>
<Link
className={`${styles.link} ${isActive ? styles.active : ""}`}
href={replaceUrlPart(pathname, url)}
onClick={onLanguageSwitch}
keepSearchParams
>
{languages[key]}
{isActive ? <CheckIcon color="burgundy" /> : null}
</Link>
</li>
)
}
})}
</ul>
</div>
</div>
)
}

View File

@@ -0,0 +1,57 @@
.languageWrapper {
display: grid;
gap: var(--Spacing-x3);
padding: var(--Spacing-x3) var(--Spacing-x2);
}
.subtitle {
font-family: var(--typography-Subtitle-2-fontFamily);
font-size: var(--typography-Subtitle-2-Mobile-fontSize);
font-weight: var(--typography-Subtitle-2-fontWeight);
color: var(--Base-Text-High-contrast);
}
.list {
list-style: none;
}
.link {
color: var(--Scandic-Brand-Burgundy);
font-family: var(--typography-Body-Regular-fontFamily);
font-size: var(--typography-Body-Regular-fontSize);
line-height: var(--typography-Body-Regular-lineHeight);
letter-spacing: var(--typography-Body-Regular-letterSpacing);
padding: var(--Spacing-x1);
border-radius: var(--Corner-radius-Medium);
display: flex;
gap: var(--Spacing-x1);
justify-content: space-between;
align-items: center;
text-decoration: none;
border-radius: var(--Corner-radius-Medium);
}
.link.active,
.link:hover {
background-color: var(--Base-Surface-Primary-light-Hover-alt);
font-weight: 500; /* Should be fixed when variables starts working: var(--typography-Body-Bold-fontWeight); */
}
@media screen and (min-width: 768px) {
.backWrapper,
.backButton {
display: none;
}
.languageWrapper {
padding: var(--Spacing-x2) var(--Spacing-x3);
}
.subtitle {
display: none;
}
.link.active:not(:hover) {
background-color: transparent;
}
}

View File

@@ -0,0 +1,19 @@
export function replaceUrlPart(currentPath: string, newPart: string): string {
const pathSegments = currentPath.split("/").filter((segment) => segment)
const newPathSegments = newPart
.replace(/\/$/, "")
.split("/")
.filter((segment) => segment)
const isFullPathReplacement = newPathSegments.length > 1
if (isFullPathReplacement) {
return `/${newPathSegments.join("/")}`
}
const updatedPathSegments = pathSegments.slice(1)
const updatedPath = `/${newPathSegments.concat(updatedPathSegments).join("/")}`
return updatedPath
}

View File

@@ -0,0 +1,132 @@
"use client"
import { usePathname } from "next/navigation"
import { useRef } from "react"
import { useIntl } from "react-intl"
import { languages } from "@/constants/languages"
import { trpc } from "@/lib/trpc/client"
import useDropdownStore from "@/stores/main-menu"
import { ChevronDownSmallIcon, GlobeIcon } from "@/components/Icons"
import useClickOutside from "@/hooks/useClickOutside"
import { useHandleKeyUp } from "@/hooks/useHandleKeyUp"
import useLang from "@/hooks/useLang"
import SkeletonShimmer from "../SkeletonShimmer"
import Caption from "../TempDesignSystem/Text/Caption"
import LanguageSwitcherContainer from "./LanguageSwitcherContainer"
import LanguageSwitcherContent from "./LanguageSwitcherContent"
import { languageSwitcherVariants } from "./variants"
import styles from "./languageSwitcher.module.css"
import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"
import {
type LanguageSwitcherProps,
LanguageSwitcherTypesEnum,
} from "@/types/components/languageSwitcher/languageSwitcher"
export default function LanguageSwitcher({ type }: LanguageSwitcherProps) {
const intl = useIntl()
const currentLanguage = useLang()
const {
toggleDropdown,
isFooterLanguageSwitcherOpen,
isHeaderLanguageSwitcherMobileOpen,
isHeaderLanguageSwitcherOpen,
} = useDropdownStore()
const pathName = usePathname()
const { data: languagesResponse, isLoading } =
trpc.contentstack.languageSwitcher.get.useQuery({
pathName,
lang: currentLanguage,
})
const languageSwitcherRef = useRef<HTMLDivElement>(null)
const isFooter = type === LanguageSwitcherTypesEnum.Footer
const isHeader = !isFooter
const globeIconSize = type === "desktopHeader" ? 16 : 20
const position = isFooter ? "footer" : "header"
const dropdownType = {
footer: DropdownTypeEnum.FooterLanguageSwitcher,
desktopHeader: DropdownTypeEnum.HeaderLanguageSwitcher,
mobileHeader: DropdownTypeEnum.HeaderLanguageSwitcherMobile,
}[type]
const isLanguageSwitcherOpen =
(isFooter && isFooterLanguageSwitcherOpen) ||
(isHeader &&
(isHeaderLanguageSwitcherOpen || isHeaderLanguageSwitcherMobileOpen))
useHandleKeyUp((event: KeyboardEvent) => {
if (event.key === "Escape" && isLanguageSwitcherOpen) {
toggleDropdown(dropdownType)
}
})
function handleClick() {
const scrollPosition = window.scrollY
toggleDropdown(dropdownType)
requestAnimationFrame(() => {
window.scrollTo(0, scrollPosition)
})
}
useClickOutside(
languageSwitcherRef,
isLanguageSwitcherOpen && !isHeaderLanguageSwitcherMobileOpen,
() => toggleDropdown(dropdownType)
)
const classNames = languageSwitcherVariants({ position })
const closeMsg = intl.formatMessage({ id: "Close language menu" })
const openMsg = intl.formatMessage({ id: "Open language menu" })
if (isLoading) {
return <SkeletonShimmer width="12ch" />
}
if (!languagesResponse?.urls) {
return null
}
return (
<div className={classNames} ref={languageSwitcherRef}>
<button
type="button"
className={styles.button}
aria-label={isLanguageSwitcherOpen ? closeMsg : openMsg}
onClick={handleClick}
>
<GlobeIcon width={globeIconSize} height={globeIconSize} />
<Caption className={styles.buttonText} type="regular" asChild>
<span>{languages[currentLanguage]}</span>
</Caption>
<ChevronDownSmallIcon
className={`${styles.chevron} ${isLanguageSwitcherOpen ? styles.isExpanded : ""}`}
width={20}
height={20}
/>
</button>
<div
className={`${styles.dropdown} ${isLanguageSwitcherOpen ? styles.isExpanded : ""}`}
>
{isLanguageSwitcherOpen ? (
<LanguageSwitcherContainer type={type}>
<LanguageSwitcherContent
urls={languagesResponse.urls}
onLanguageSwitch={() => toggleDropdown(dropdownType)}
/>
</LanguageSwitcherContainer>
) : null}
</div>
</div>
)
}

View File

@@ -0,0 +1,123 @@
.button {
--language-switcher-color: var(--Base-Text-Medium-contrast);
--language-switcher-hover-color: var(--Base-Text-High-contrast);
background-color: transparent;
border-width: 0;
padding: 0;
cursor: pointer;
display: grid;
grid-template-columns: repeat(2, max-content) 1fr;
align-items: center;
width: 100%;
color: var(--language-switcher-color);
}
.button *,
.button svg * {
fill: var(--language-switcher-color);
}
.button:hover {
color: var(--language-switcher-hover-color);
}
.button:hover *,
.button:hover svg * {
fill: var(--language-switcher-hover-color);
}
.buttonText {
color: inherit !important;
margin-left: var(--Spacing-x1);
margin-right: var(--Spacing-x-quarter);
}
.footer .button {
--language-switcher-color: var(--Primary-Dark-On-Surface-Text);
--language-switcher-hover-color: var(--Primary-Dark-On-Surface-Text);
}
.chevron {
justify-self: end;
transition: transform 0.3s;
}
.chevron.isExpanded {
transform: rotate(180deg);
}
.dropdown {
position: fixed;
width: 100%;
background-color: var(--Base-Surface-Primary-light-Normal);
z-index: var(--menu-overlay-z-index);
}
.header .dropdown {
right: -100vw;
top: calc(
var(--main-menu-mobile-height) + var(--sitewide-alert-height) + 1px
);
bottom: 0;
transition: right 0.3s;
}
.header .dropdown.isExpanded {
display: block;
right: 0;
}
.footer .dropdown {
transition: transform 0.3s;
width: 100%;
height: 100vh;
left: 0;
bottom: 0;
transform: translateY(100%);
}
.footer .dropdown.isExpanded {
transform: translateY(0);
}
@media screen and (min-width: 768px) {
.languageSwitcher {
position: relative;
}
.dropdown {
position: absolute;
background-color: var(--Base-Surface-Primary-light-Normal);
border-radius: var(--Corner-radius-Large);
box-shadow: 0 0 14px 6px rgba(0, 0, 0, 0.1);
display: none;
min-width: 12.5rem;
z-index: var(--header-z-index);
}
.header .dropdown {
top: 2.25rem;
bottom: auto;
}
.header .dropdown::before {
top: -1.25rem;
transform: rotate(180deg);
}
.footer .dropdown {
transition: none;
height: auto;
left: -100%;
bottom: 2.25rem;
}
.footer .dropdown.isExpanded {
display: block;
}
.footer .dropdown::before {
top: 100%;
}
.button {
grid-template-columns: repeat(3, max-content);
}
}

View File

@@ -0,0 +1,15 @@
import { cva } from "class-variance-authority"
import styles from "./languageSwitcher.module.css"
export const languageSwitcherVariants = cva(styles.languageSwitcher, {
variants: {
position: {
header: styles.header,
footer: styles.footer,
},
defaultVariants: {
position: "header",
},
},
})