From 19723856c3af3aa469dd9a5a1b2df7735e1a53a1 Mon Sep 17 00:00:00 2001 From: Christian Andolf Date: Mon, 31 Mar 2025 11:47:53 +0200 Subject: [PATCH] refactor(SW-1877): a bit of cleanup of code to maintain patterns and separate components and types --- .../components/Breadcrumbs/index.tsx | 10 +-- .../Breadcrumbs/Breadcrumb.tsx | 37 ++++++++++ .../Breadcrumbs/breadcrumbs.module.css | 26 +++---- .../Breadcrumbs/breadcrumbs.ts | 15 ++-- .../TempDesignSystem/Breadcrumbs/index.tsx | 70 ++++--------------- .../TempDesignSystem/Breadcrumbs/utils.ts | 12 ++++ 6 files changed, 91 insertions(+), 79 deletions(-) create mode 100644 apps/scandic-web/components/TempDesignSystem/Breadcrumbs/Breadcrumb.tsx create mode 100644 apps/scandic-web/components/TempDesignSystem/Breadcrumbs/utils.ts diff --git a/apps/scandic-web/components/Breadcrumbs/index.tsx b/apps/scandic-web/components/Breadcrumbs/index.tsx index e9a616561..b804b31b5 100644 --- a/apps/scandic-web/components/Breadcrumbs/index.tsx +++ b/apps/scandic-web/components/Breadcrumbs/index.tsx @@ -3,13 +3,13 @@ import { serverClient } from "@/lib/trpc/server" import BreadcrumbsComp from "@/components/TempDesignSystem/Breadcrumbs" import { generateBreadcrumbsSchema } from "@/utils/jsonSchemas" -import type { Breadcrumbs } from "@/types/trpc/routers/contentstack/breadcrumbs" import type { BreadcrumbsProps } from "@/components/TempDesignSystem/Breadcrumbs/breadcrumbs" -export default async function Breadcrumbs({ - variant, - subpageTitle, -}: Pick) { +interface Props extends Pick { + subpageTitle?: string +} + +export default async function Breadcrumbs({ variant, subpageTitle }: Props) { const breadcrumbs = await serverClient().contentstack.breadcrumbs.get() if (!breadcrumbs?.length) { return null diff --git a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/Breadcrumb.tsx b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/Breadcrumb.tsx new file mode 100644 index 000000000..0c4cf8800 --- /dev/null +++ b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/Breadcrumb.tsx @@ -0,0 +1,37 @@ +import { cx } from "class-variance-authority" +import { Breadcrumb as AriaBreadcrumb } from "react-aria-components" + +import { MaterialIcon } from "@scandic-hotels/design-system/Icons" + +import Link from "@/components/TempDesignSystem/Link" + +import styles from "./breadcrumbs.module.css" + +import type { BreadcrumbProps } from "./breadcrumbs" + +export function Breadcrumb({ + className = "", + href, + children, + ...props +}: BreadcrumbProps) { + return ( + + {href ? ( + <> + + {children} + + + ) +} diff --git a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.module.css b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.module.css index 08a7149fe..d90869754 100644 --- a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.module.css +++ b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.module.css @@ -27,6 +27,12 @@ padding-inline-start: 0; } +.list .listItem:last-of-type { + flex: 1; + max-width: 100%; + min-width: 0; +} + .listItem { align-items: center; display: flex; @@ -43,19 +49,6 @@ flex-shrink: 0; } -.last { - flex: 1; - max-width: 100%; - min-width: 0; -} - -.last > button { - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - text-align: left; -} - .button { border: none; background: transparent; @@ -103,6 +96,13 @@ } } +.tooltipTrigger { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + text-align: left; +} + .tooltip { background-color: var(--Surface-UI-Fill-Intense); padding: var(--Spacing-x-half) var(--Spacing-x1); diff --git a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.ts b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.ts index 25cf14250..7f42e146d 100644 --- a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.ts +++ b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/breadcrumbs.ts @@ -1,15 +1,22 @@ import type { VariantProps } from "class-variance-authority" +import type { PropsWithChildren } from "react" +import type { BreadcrumbProps as AriaBreadcrumbProps } from "react-aria-components" import type { breadcrumbsVariants } from "./variants" -export type Breadcrumb = { +export type { Breadcrumb, BreadcrumbProps, BreadcrumbsProps } + +type Breadcrumb = { title: string uid: string href?: string } -export interface BreadcrumbsProps - extends VariantProps { - subpageTitle?: string +interface BreadcrumbsProps extends VariantProps { breadcrumbs: Breadcrumb[] } + +interface BreadcrumbProps extends PropsWithChildren { + className?: string + href?: string +} diff --git a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/index.tsx b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/index.tsx index e73049e59..7c9311b7c 100644 --- a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/index.tsx @@ -1,10 +1,9 @@ "use client" import { cx } from "class-variance-authority" -import { type PropsWithChildren, useEffect, useState } from "react" +import { useEffect, useState } from "react" import { - Breadcrumb as AriaBreadcrumb, - Breadcrumbs as AriaBreadCrumbs, + Breadcrumbs as AriaBreadcrumbs, Button, Dialog, DialogTrigger, @@ -15,19 +14,18 @@ import { import { MaterialIcon } from "@scandic-hotels/design-system/Icons" import { Typography } from "@scandic-hotels/design-system/Typography" -import Link from "@/components/TempDesignSystem/Link" -import Footnote from "@/components/TempDesignSystem/Text/Footnote" import { debounce } from "@/utils/debounce" +import Link from "../Link" import { Arrow } from "../Popover/Arrow" +import Footnote from "../Text/Footnote" +import { Breadcrumb } from "./Breadcrumb" +import { splitBreadcrumbs } from "./utils" import { breadcrumbsVariants } from "./variants" import styles from "./breadcrumbs.module.css" -import type { - Breadcrumb, - BreadcrumbsProps, -} from "@/components/TempDesignSystem/Breadcrumbs/breadcrumbs" +import type { BreadcrumbsProps } from "./breadcrumbs" export default function Breadcrumbs({ breadcrumbs, @@ -69,7 +67,7 @@ export default function Breadcrumbs({ return ( ) } - -function Breadcrumb({ - className = "", - href, - children, - ...props -}: PropsWithChildren<{ - className?: string - href?: string -}>) { - return ( - - {href ? ( - <> - - {children} - - - ) -} - -function splitBreadcrumbs( - breadcrumbs: Breadcrumb[] -): [Breadcrumb, Breadcrumb[], Breadcrumb] { - const copy = breadcrumbs.slice(0) - const first = copy.shift()! - const last = copy.pop()! - return [first, copy, last] -} diff --git a/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/utils.ts b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/utils.ts new file mode 100644 index 000000000..53c765f11 --- /dev/null +++ b/apps/scandic-web/components/TempDesignSystem/Breadcrumbs/utils.ts @@ -0,0 +1,12 @@ +import type { Breadcrumb } from "./breadcrumbs" + +export { splitBreadcrumbs } + +function splitBreadcrumbs( + breadcrumbs: Breadcrumb[] +): [Breadcrumb, Breadcrumb[], Breadcrumb] { + const copy = breadcrumbs.slice(0) + const first = copy.shift()! + const last = copy.pop()! + return [first, copy, last] +}