From 68f4c7b2cf984ff698149f8cafac76503eba241e Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:24:22 +0200 Subject: [PATCH 1/8] feat: add foundational UI components --- apps/web/src/components/ui/Avatar/Avatar.css | 80 ++++++ apps/web/src/components/ui/Avatar/Avatar.tsx | 104 ++++++++ apps/web/src/components/ui/Button/Button.css | 140 +++++++++++ apps/web/src/components/ui/Button/Button.tsx | 39 +++ .../src/components/ui/IconBadge/IconBadge.css | 143 +++++++++++ .../src/components/ui/IconBadge/IconBadge.tsx | 237 ++++++++++++++++++ .../components/ui/IconButton/IconButton.css | 143 +++++++++++ .../components/ui/IconButton/IconButton.tsx | 68 +++++ .../ui/LoadingIndicator/LoadingIndicator.css | 173 +++++++++++++ .../ui/LoadingIndicator/LoadingIndicator.tsx | 117 +++++++++ 10 files changed, 1244 insertions(+) create mode 100644 apps/web/src/components/ui/Avatar/Avatar.css create mode 100644 apps/web/src/components/ui/Avatar/Avatar.tsx create mode 100644 apps/web/src/components/ui/Button/Button.css create mode 100644 apps/web/src/components/ui/Button/Button.tsx create mode 100644 apps/web/src/components/ui/IconBadge/IconBadge.css create mode 100644 apps/web/src/components/ui/IconBadge/IconBadge.tsx create mode 100644 apps/web/src/components/ui/IconButton/IconButton.css create mode 100644 apps/web/src/components/ui/IconButton/IconButton.tsx create mode 100644 apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.css create mode 100644 apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.tsx diff --git a/apps/web/src/components/ui/Avatar/Avatar.css b/apps/web/src/components/ui/Avatar/Avatar.css new file mode 100644 index 0000000..47f209a --- /dev/null +++ b/apps/web/src/components/ui/Avatar/Avatar.css @@ -0,0 +1,80 @@ +@layer components { + .avatar { + display: inline-flex; + flex: 0 0 auto; + + align-items: center; + justify-content: center; + + overflow: hidden; + + color: + var(--color-brand-primary-active); + + background-color: + var(--color-brand-accent-soft); + + border: + var(--border-width-thin) + solid + var(--color-border-default); + + border-radius: + var(--radius-full); + + user-select: none; + } + + /* Sizes */ + + .avatar--sm { + width: 2rem; + height: 2rem; + + font-size: + var(--font-size-xs); + } + + .avatar--md { + width: 2.75rem; + height: 2.75rem; + + font-size: + var(--font-size-sm); + } + + .avatar--lg { + width: 3.5rem; + height: 3.5rem; + + font-size: + var(--font-size-md); + } + + /* Image */ + + .avatar__image { + display: block; + + width: 100%; + height: 100%; + + object-fit: cover; + } + + /* Initial fallback */ + + .avatar__initials { + display: inline-flex; + align-items: center; + justify-content: center; + + width: 100%; + height: 100%; + + font-weight: + var(--font-weight-semibold); + + line-height: 1; + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Avatar/Avatar.tsx b/apps/web/src/components/ui/Avatar/Avatar.tsx new file mode 100644 index 0000000..1702af5 --- /dev/null +++ b/apps/web/src/components/ui/Avatar/Avatar.tsx @@ -0,0 +1,104 @@ +import { + useState, +} from "react"; + +import "./Avatar.css"; + +export type AvatarSize = + | "sm" + | "md" + | "lg"; + +type AvatarProps = { + name: string; + + src?: string; + alt?: string; + + size?: AvatarSize; + + className?: string; +}; + +function getInitials( + name: string, +) { + const words = name + .trim() + .split(/\s+/) + .filter(Boolean); + + if (words.length === 0) { + return "?"; + } + + if (words.length === 1) { + return words[0] + .slice(0, 2) + .toUpperCase(); + } + + return ( + words[0][0] + + words[words.length - 1][0] + ).toUpperCase(); +} + +function Avatar({ + name, + src, + alt = name, + size = "md", + className = "", +}: AvatarProps) { + const [ + failedSrc, + setFailedSrc, + ] = useState( + undefined, + ); + + const showImage = + Boolean(src) && + failedSrc !== src; + + const classes = [ + "avatar", + `avatar--${size}`, + className, + ] + .filter(Boolean) + .join(" "); + + if (showImage && src) { + return ( + + {alt} + setFailedSrc(src) + } + /> + + ); + } + + return ( + + + + ); +} + +export default Avatar; \ No newline at end of file diff --git a/apps/web/src/components/ui/Button/Button.css b/apps/web/src/components/ui/Button/Button.css new file mode 100644 index 0000000..2ca7f75 --- /dev/null +++ b/apps/web/src/components/ui/Button/Button.css @@ -0,0 +1,140 @@ +@layer components { + .button { + display: inline-flex; + align-items: center; + justify-content: center; + gap: var(--space-2); + + width: fit-content; + max-width: 100%; + padding-inline: var(--space-4); + + font-weight: var(--font-weight-semibold); + line-height: var(--line-height-tight); + text-align: center; + text-decoration: none; + + border: + var(--border-width-thin) + solid + transparent; + + border-radius: var(--radius-md); + + cursor: pointer; + + transition: + color var(--duration-fast) var(--ease-standard), + background-color var(--duration-fast) var(--ease-standard), + border-color var(--duration-fast) var(--ease-standard), + box-shadow var(--duration-fast) var(--ease-standard); + } + + /* Sizes */ + + .button--sm { + min-height: var(--control-height-sm); + padding-inline: var(--space-3); + + font-size: var(--font-size-sm); + } + + .button--md { + min-height: var(--control-height-md); + + font-size: var(--font-size-md); + } + + .button--lg { + min-height: var(--control-height-lg); + padding-inline: var(--space-5); + + font-size: var(--font-size-lg); + } + + /* Wider action buttons */ + + .button--sm.button--wide { + min-inline-size: 7rem; + } + + .button--md.button--wide { + min-inline-size: 8rem; + } + + .button--lg.button--wide { + min-inline-size: 9rem; + } + + /* Primary */ + + .button--primary { + color: var(--color-text-inverse); + background-color: var(--color-brand-primary); + } + + .button--primary:hover:not(:disabled) { + background-color: var(--color-brand-primary-hover); + } + + .button--primary:active:not(:disabled) { + background-color: var(--color-brand-primary-active); + } + + /* Secondary */ + + .button--secondary { + color: var(--color-text-primary); + background-color: var(--color-surface); + border-color: var(--color-border-default); + } + + .button--secondary:hover:not(:disabled) { + background-color: var(--color-surface-hover); + border-color: var(--color-border-input-hover); + } + + .button--secondary:active:not(:disabled) { + background-color: var(--color-surface-pressed); + } + + /* Ghost */ + + .button--ghost { + color: var(--color-text-primary); + background-color: transparent; + } + + .button--ghost:hover:not(:disabled) { + background-color: var(--color-surface-hover); + } + + .button--ghost:active:not(:disabled) { + background-color: var(--color-surface-pressed); + } + + /* Destructive */ + + .button--destructive { + color: var(--color-text-inverse); + background-color: var(--color-feedback-error); + } + + .button--destructive:hover:not(:disabled) { + background-color: var(--color-feedback-error-hover); + } + + .button--destructive:active:not(:disabled) { + background-color: var(--color-feedback-error-active); + } + + /* Disabled */ + + .button:disabled { + color: var(--color-disabled-text); + background-color: var(--color-disabled-surface); + border-color: var(--color-disabled-border); + + cursor: not-allowed; + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Button/Button.tsx b/apps/web/src/components/ui/Button/Button.tsx new file mode 100644 index 0000000..4085a6d --- /dev/null +++ b/apps/web/src/components/ui/Button/Button.tsx @@ -0,0 +1,39 @@ +import type { ComponentPropsWithRef, ReactNode } from "react"; + +import "./Button.css"; + +export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive"; +export type ButtonSize = "sm" | "md" | "lg"; + +export type ButtonProps = ComponentPropsWithRef<"button"> & { + children: ReactNode; + variant?: ButtonVariant; + size?: ButtonSize; + wide?: boolean; +}; + +function Button({ + children, + variant = "primary", + size = "md", + wide = false, + className = "", + type = "button", + ...props +}: ButtonProps) { + const classes = [ + "button", + `button--${variant}`, + `button--${size}`, + wide && "button--wide", + className, + ].filter(Boolean).join(" "); + + return ( + + ); +} + +export default Button; diff --git a/apps/web/src/components/ui/IconBadge/IconBadge.css b/apps/web/src/components/ui/IconBadge/IconBadge.css new file mode 100644 index 0000000..4d8d1c4 --- /dev/null +++ b/apps/web/src/components/ui/IconBadge/IconBadge.css @@ -0,0 +1,143 @@ +@layer components { + .ui-icon-badge { + --ui-icon-badge-size: 3rem; + --ui-icon-badge-radius: var(--radius-lg); + --ui-icon-badge-accent: var(--color-brand-primary); + --ui-icon-badge-foreground: var(--ui-icon-badge-accent); + --ui-icon-badge-background: var(--color-brand-accent-soft); + --ui-icon-badge-border: var(--color-border-subtle); + + display: inline-grid; + place-items: center; + flex: none; + + width: var(--ui-icon-badge-size); + height: var(--ui-icon-badge-size); + + color: var(--ui-icon-badge-foreground); + background: var(--ui-icon-badge-background); + + border: + var(--border-width-thin) + solid + var(--ui-icon-badge-border); + + border-radius: var(--ui-icon-badge-radius); + + /* + * IconBadge is non-interactive. These transitions only smooth + * appearance changes driven by its parent/context. + */ + transition: + color var(--duration-fast) var(--ease-standard), + background-color var(--duration-fast) var(--ease-standard), + border-color var(--duration-fast) var(--ease-standard); + } + + .ui-icon-badge > .ui-icon { + color: inherit; + } + + /* Sizes */ + + .ui-icon-badge--sm { + --ui-icon-badge-size: 2.25rem; + --ui-icon-badge-radius: var(--radius-md); + } + + .ui-icon-badge--md { + --ui-icon-badge-size: 3rem; + --ui-icon-badge-radius: var(--radius-lg); + } + + .ui-icon-badge--lg { + --ui-icon-badge-size: 4rem; + --ui-icon-badge-radius: var(--radius-xl); + } + + /* Shapes */ + + .ui-icon-badge--circle { + --ui-icon-badge-radius: var(--radius-full); + } + + /* Semantic tones */ + + .ui-icon-badge--default { + --ui-icon-badge-accent: var(--color-icon-primary); + --ui-icon-badge-background: var(--color-surface-muted); + --ui-icon-badge-border: var(--color-border-subtle); + } + + .ui-icon-badge--secondary { + --ui-icon-badge-accent: var(--color-icon-secondary); + --ui-icon-badge-background: var(--color-surface-muted); + --ui-icon-badge-border: var(--color-border-subtle); + } + + .ui-icon-badge--muted { + --ui-icon-badge-accent: var(--color-icon-muted); + --ui-icon-badge-background: var(--color-surface-muted); + --ui-icon-badge-border: var(--color-border-subtle); + } + + .ui-icon-badge--brand { + --ui-icon-badge-accent: var(--color-brand-primary); + --ui-icon-badge-background: var(--color-brand-accent-soft); + --ui-icon-badge-border: var(--color-border-subtle); + } + + .ui-icon-badge--success { + --ui-icon-badge-accent: var(--color-feedback-success); + --ui-icon-badge-background: var(--color-feedback-success-surface); + --ui-icon-badge-border: var(--color-feedback-success-border); + } + + .ui-icon-badge--warning { + --ui-icon-badge-accent: var(--color-feedback-warning); + --ui-icon-badge-background: var(--color-feedback-warning-surface); + --ui-icon-badge-border: var(--color-feedback-warning-border); + } + + .ui-icon-badge--error { + --ui-icon-badge-accent: var(--color-feedback-error); + --ui-icon-badge-background: var(--color-feedback-error-surface); + --ui-icon-badge-border: var(--color-feedback-error-border); + } + + .ui-icon-badge--info { + --ui-icon-badge-accent: var(--color-feedback-info); + --ui-icon-badge-background: var(--color-feedback-info-surface); + --ui-icon-badge-border: var(--color-feedback-info-border); + } + + .ui-icon-badge--inverse { + --ui-icon-badge-accent: var(--color-text-inverse); + --ui-icon-badge-background: var(--color-text-primary); + --ui-icon-badge-border: var(--color-text-primary); + } + + /* Surface variants */ + + .ui-icon-badge--soft { + --ui-icon-badge-foreground: var(--ui-icon-badge-accent); + } + + .ui-icon-badge--outline { + --ui-icon-badge-foreground: var(--ui-icon-badge-accent); + --ui-icon-badge-background: transparent; + --ui-icon-badge-border: var(--ui-icon-badge-accent); + } + + .ui-icon-badge--solid { + --ui-icon-badge-foreground: var(--color-text-inverse); + --ui-icon-badge-background: var(--ui-icon-badge-accent); + --ui-icon-badge-border: var(--ui-icon-badge-accent); + } + + .ui-icon-badge--ghost { + --ui-icon-badge-foreground: var(--ui-icon-badge-accent); + --ui-icon-badge-background: transparent; + --ui-icon-badge-border: transparent; + } +} diff --git a/apps/web/src/components/ui/IconBadge/IconBadge.tsx b/apps/web/src/components/ui/IconBadge/IconBadge.tsx new file mode 100644 index 0000000..37fb28a --- /dev/null +++ b/apps/web/src/components/ui/IconBadge/IconBadge.tsx @@ -0,0 +1,237 @@ +import type { + ComponentType, + CSSProperties, + ComponentPropsWithRef, +} from "react"; + +import type { + IconProps as SvgIconProps, +} from "../../../icons/types"; + +import { + Icon, + type IconStroke, + type IconTone, + type UiIconSize, +} from "../Icon/Icon"; + +import "./IconBadge.css"; + +export type IconBadgeSize = + | "sm" + | "md" + | "lg"; + +export type IconBadgeVariant = + | "soft" + | "outline" + | "solid" + | "ghost"; + +export type IconBadgeShape = + | "rounded" + | "circle"; + +/* + * "inherit" makes sense for Icon itself, but IconBadge owns + * its semantic foreground/background treatment, so it is + * intentionally excluded here. + */ +export type IconBadgeTone = Exclude< + IconTone, + "inherit" +>; + +type IconSpecificProps

= Omit< + P, + keyof SvgIconProps +>; + +export interface IconBadgeProps< + P extends SvgIconProps = SvgIconProps, +> extends Omit< + ComponentPropsWithRef<"span">, + "color" + > { + /** + * Raw SVG icon component. + */ + icon: ComponentType

; + + /** + * Props specific to the chosen icon. + * + * Examples: + * { filled: true } + * { variant: "half" } + */ + iconProps?: IconSpecificProps

; + + /** + * Semantic badge color family. + */ + tone?: IconBadgeTone; + + /** + * Surface treatment. + */ + variant?: IconBadgeVariant; + + /** + * Overall badge size. + */ + size?: IconBadgeSize; + + /** + * Optional icon-size override. + */ + iconSize?: UiIconSize; + + /** + * Rounded square or circle. + */ + shape?: IconBadgeShape; + + /** + * Design-system stroke weight. + */ + stroke?: IconStroke; + + /** + * Escape hatch for an explicit numeric stroke width. + */ + strokeWidth?: number; + + /** + * Explicit icon foreground override. + */ + color?: string; + + /** + * Explicit badge background override. + */ + backgroundColor?: string; + + /** + * Explicit badge border override. + */ + borderColor?: string; + + /** + * Accessible title for the SVG itself. + * + * Usually omit this for decorative badges. + */ + iconTitle?: string; +} + +type BadgeCustomProperties = CSSProperties & { + "--ui-icon-badge-foreground"?: string; + "--ui-icon-badge-background"?: string; + "--ui-icon-badge-border"?: string; +}; + +const DEFAULT_ICON_SIZE: Record< + IconBadgeSize, + UiIconSize +> = { + sm: "sm", + md: "lg", + lg: "xl", +}; + +/** + * Non-interactive visual container for an icon. + * + * Use IconBadge for things such as: + * - dialog headings + * - empty states + * - informational cards + * - section headings + * - semantic feedback + * + * If the icon itself performs an action, use IconButton + * instead of making IconBadge clickable. + */ +export function IconBadge< + P extends SvgIconProps, +>({ + icon, + iconProps, + tone = "brand", + variant = "soft", + size = "md", + iconSize, + shape = "rounded", + stroke = "default", + strokeWidth, + color, + backgroundColor, + borderColor, + iconTitle, + className, + style, + ...spanProps +}: IconBadgeProps

) { + const classes = [ + "ui-icon-badge", + `ui-icon-badge--${tone}`, + `ui-icon-badge--${variant}`, + `ui-icon-badge--${size}`, + shape === "circle" ? "ui-icon-badge--circle" : null, + className, + ] + .filter(Boolean) + .join(" "); + + const customStyle: BadgeCustomProperties = { + ...style, + + ...(color + ? { + "--ui-icon-badge-foreground": + color, + } + : {}), + + ...(backgroundColor + ? { + "--ui-icon-badge-background": + backgroundColor, + } + : {}), + + ...(borderColor + ? { + "--ui-icon-badge-border": + borderColor, + } + : {}), + }; + + return ( + + + + ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/IconButton/IconButton.css b/apps/web/src/components/ui/IconButton/IconButton.css new file mode 100644 index 0000000..eb53c18 --- /dev/null +++ b/apps/web/src/components/ui/IconButton/IconButton.css @@ -0,0 +1,143 @@ +@layer components { + .icon-button { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + + padding: 0; + + border: + var(--border-width-thin) + solid + transparent; + + border-radius: var(--radius-md); + + cursor: pointer; + + transition: + color var(--duration-fast) var(--ease-standard), + background-color var(--duration-fast) var(--ease-standard), + border-color var(--duration-fast) var(--ease-standard), + box-shadow var(--duration-fast) var(--ease-standard); + } + + /* Sizes */ + + .icon-button--sm { + width: var(--control-height-sm); + height: var(--control-height-sm); + } + + .icon-button--md { + width: var(--control-height-md); + height: var(--control-height-md); + } + + .icon-button--lg { + width: var(--control-height-lg); + height: var(--control-height-lg); + } + + /* Primary */ + + .icon-button--primary { + color: var(--color-text-inverse); + background-color: var(--color-brand-primary); + } + + .icon-button--primary:hover:not(:disabled) { + background-color: var(--color-brand-primary-hover); + } + + .icon-button--primary:active:not(:disabled) { + background-color: var(--color-brand-primary-active); + } + + /* Secondary */ + + .icon-button--secondary { + color: var(--color-icon-primary); + background-color: var(--color-surface); + border-color: var(--color-border-default); + } + + .icon-button--secondary:hover:not(:disabled) { + background-color: var(--color-surface-hover); + border-color: var(--color-border-input-hover); + } + + .icon-button--secondary:active:not(:disabled) { + background-color: var(--color-surface-pressed); + } + + /* Ghost */ + + .icon-button--ghost { + color: var(--color-icon-primary); + background-color: transparent; + } + + .icon-button--ghost:hover:not(:disabled) { + background-color: var(--color-surface-hover); + } + + .icon-button--ghost:active:not(:disabled) { + background-color: var(--color-surface-pressed); + } + + /* Info */ + + .icon-button--info { + color: var(--color-feedback-info); + background-color: var(--color-feedback-info-surface); + } + + .icon-button--info:hover:not(:disabled) { + border-color: var(--color-feedback-info-border); + } + + .icon-button--info:active:not(:disabled) { + background-color: var(--color-feedback-info-border); + } + + /* Destructive */ + + .icon-button--destructive { + color: var(--color-feedback-error); + background-color: var(--color-feedback-error-surface); + } + + .icon-button--destructive:hover:not(:disabled) { + border-color: var(--color-feedback-error-border); + } + + .icon-button--destructive:active:not(:disabled) { + background-color: var(--color-feedback-error-border); + } + + /* Toggle states */ + + .icon-button--secondary[aria-pressed="true"], + .icon-button--ghost[aria-pressed="true"] { + color: var(--color-brand-primary); + background-color: var(--color-surface-selected); + border-color: var(--color-brand-primary); + } + + .icon-button--secondary[aria-pressed="true"]:hover:not(:disabled), + .icon-button--ghost[aria-pressed="true"]:hover:not(:disabled) { + background-color: var(--color-surface-pressed); + } + + /* Disabled */ + + .icon-button:disabled { + color: var(--color-disabled-text); + background-color: var(--color-disabled-surface); + border-color: var(--color-disabled-border); + + cursor: not-allowed; + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/IconButton/IconButton.tsx b/apps/web/src/components/ui/IconButton/IconButton.tsx new file mode 100644 index 0000000..81628ec --- /dev/null +++ b/apps/web/src/components/ui/IconButton/IconButton.tsx @@ -0,0 +1,68 @@ +import type { ComponentPropsWithRef, ComponentType } from "react"; + +import type { IconProps as SvgIconProps } from "../../../icons/types"; +import { Icon, type IconProps as UiIconProps, type IconStroke, type IconTone, type UiIconSize } from "../Icon/Icon"; +import "./IconButton.css"; + +export type IconButtonVariant = + | "primary" + | "secondary" + | "ghost" + | "info" + | "destructive"; + +export type IconButtonSize = "sm" | "md" | "lg"; + +export type IconButtonProps

= Omit< + ComponentPropsWithRef<"button">, + "children" | "aria-label" +> & { + icon: ComponentType

; + iconProps?: UiIconProps

["iconProps"]; + iconTone?: IconTone; + iconStroke?: IconStroke; + iconSize?: UiIconSize; + "aria-label": string; + variant?: IconButtonVariant; + size?: IconButtonSize; +}; + +const ICON_SIZE_BY_BUTTON: Record = { + sm: "sm", + md: "md", + lg: "lg", +}; + +function IconButton

({ + icon, + iconProps, + iconTone = "inherit", + iconStroke = "default", + iconSize, + variant = "secondary", + size = "md", + className = "", + type = "button", + ...props +}: IconButtonProps

) { + const classes = [ + "icon-button", + `icon-button--${variant}`, + `icon-button--${size}`, + className, + ].filter(Boolean).join(" "); + + return ( + + ); +} + +export default IconButton; diff --git a/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.css b/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.css new file mode 100644 index 0000000..6919556 --- /dev/null +++ b/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.css @@ -0,0 +1,173 @@ +@layer components { + /* ========================================================= + Spinner + ========================================================= */ + + .spinner { + display: inline-block; + flex: 0 0 auto; + + box-sizing: border-box; + + aspect-ratio: 1; + + border-style: solid; + + border-color: + color-mix( + in srgb, + currentColor 22%, + transparent + ); + + border-top-color: + currentColor; + + border-radius: + var(--radius-full); + + animation: + spinner-rotate + 1000ms + linear + infinite; + } + + .spinner--sm { + width: + var(--icon-size-sm); + + border-width: + var(--border-width-medium); + } + + .spinner--md { + width: + var(--icon-size-md); + + border-width: + var(--border-width-medium); + } + + .spinner--lg { + width: + var(--icon-size-xl); + + border-width: + var(--border-width-thick); + } + + .spinner--brand { + color: + var(--color-brand-primary); + } + + .spinner--current { + color: inherit; + } + + @keyframes spinner-rotate { + to { + transform: + rotate(360deg); + } + } + + /* ========================================================= + Loading Indicator + ========================================================= */ + + .loading-indicator { + display: flex; + + color: + var(--color-text-primary); + } + + .loading-indicator__visual { + display: inline-flex; + flex: 0 0 auto; + + align-items: center; + justify-content: center; + + color: + var(--color-brand-primary); + } + + .loading-indicator__content { + display: flex; + flex-direction: column; + gap: var(--space-1); + + min-width: 0; + } + + .loading-indicator__label { + color: + var(--color-text-primary); + + font-size: + var(--font-size-sm); + + font-weight: + var(--font-weight-semibold); + + line-height: + var(--line-height-snug); + } + + .loading-indicator__description { + color: + var(--color-text-secondary); + + font-size: + var(--font-size-sm); + + line-height: + var(--line-height-normal); + } + + /* Inline */ + + .loading-indicator--inline { + align-items: center; + gap: var(--space-3); + } + + /* Stacked */ + + .loading-indicator--stacked { + flex-direction: column; + align-items: center; + justify-content: center; + + gap: var(--space-3); + + width: 100%; + + padding: + var(--space-8) + var(--space-4); + + text-align: center; + } + + .loading-indicator--stacked + .loading-indicator__content { + align-items: center; + + max-width: 28rem; + } + + @media (prefers-reduced-motion: reduce) { + .spinner { + /* + * Keep a small amount of motion so the visual + * still communicates activity, but slow it + * considerably for reduced-motion users. + */ + animation-duration: 1800ms; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.tsx b/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.tsx new file mode 100644 index 0000000..36b5dba --- /dev/null +++ b/apps/web/src/components/ui/LoadingIndicator/LoadingIndicator.tsx @@ -0,0 +1,117 @@ +import type { + ReactNode, +} from "react"; + +import "./LoadingIndicator.css"; + +export type SpinnerSize = + | "sm" + | "md" + | "lg"; + +export type SpinnerTone = + | "brand" + | "current"; + +type SpinnerProps = { + size?: SpinnerSize; + tone?: SpinnerTone; + + /* + * Decorative should be used when nearby visible + * text already communicates the loading state. + */ + decorative?: boolean; + + label?: string; + className?: string; +}; + +export function Spinner({ + size = "md", + tone = "brand", + decorative = false, + label = "Loading", + className = "", +}: SpinnerProps) { + return ( + + ); +} + +export type LoadingIndicatorLayout = + | "inline" + | "stacked"; + +type LoadingIndicatorProps = { + label?: ReactNode; + description?: ReactNode; + + size?: SpinnerSize; + layout?: LoadingIndicatorLayout; +}; + +function LoadingIndicator({ + label = "Loading…", + description, + size = "md", + layout = "inline", +}: LoadingIndicatorProps) { + return ( +

+ + + + +
+ + {label} + + + {description && ( + + {description} + + )} +
+
+ ); +} + +export default LoadingIndicator; \ No newline at end of file From 510fb5bf6acf3ff76b933874790e1414bf67be09 Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:24:41 +0200 Subject: [PATCH 2/8] feat: add shared UI utility components --- .../components/ui/Breadcrumbs/Breadcrumbs.css | 120 ++++++++ .../components/ui/Breadcrumbs/Breadcrumbs.tsx | 79 +++++ apps/web/src/components/ui/Tag/Tag.css | 82 +++++ apps/web/src/components/ui/Tag/Tag.tsx | 38 +++ .../web/src/components/ui/Tooltip/Tooltip.css | 288 ++++++++++++++++++ .../web/src/components/ui/Tooltip/Tooltip.tsx | 70 +++++ 6 files changed, 677 insertions(+) create mode 100644 apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.css create mode 100644 apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.tsx create mode 100644 apps/web/src/components/ui/Tag/Tag.css create mode 100644 apps/web/src/components/ui/Tag/Tag.tsx create mode 100644 apps/web/src/components/ui/Tooltip/Tooltip.css create mode 100644 apps/web/src/components/ui/Tooltip/Tooltip.tsx diff --git a/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.css b/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.css new file mode 100644 index 0000000..9ce0c97 --- /dev/null +++ b/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.css @@ -0,0 +1,120 @@ +@layer components { + .breadcrumbs { + width: 100%; + } + + .breadcrumbs__list { + display: flex; + flex-wrap: wrap; + align-items: center; + + gap: + var(--space-1) + var(--space-2); + + margin: 0; + padding: 0; + + list-style: none; + } + + .breadcrumbs__item { + display: inline-flex; + align-items: center; + gap: var(--space-2); + + min-width: 0; + + color: + var(--color-text-secondary); + + font-size: + var(--font-size-sm); + + line-height: + var(--line-height-snug); + } + + .breadcrumbs__separator { + display: inline-flex; + flex: 0 0 auto; + + align-items: center; + justify-content: center; + + color: + var(--color-icon-muted); + } + + .breadcrumbs__separator > svg { + width: var(--icon-size-sm); + height: var(--icon-size-sm); + } + + .breadcrumbs__link { + color: + var(--color-text-secondary); + + font-weight: + var(--font-weight-medium); + + text-decoration: none; + + border-radius: + var(--radius-sm); + + transition: + color + var(--duration-fast) + var(--ease-standard), + background-color + var(--duration-fast) + var(--ease-standard); + } + + .breadcrumbs__link:hover { + color: + var(--color-brand-primary-active); + + text-decoration: underline; + text-underline-offset: 0.15em; + } + + .breadcrumbs__link:active { + color: + var(--color-brand-primary-active); + } + + .breadcrumbs__label { + color: + var(--color-text-secondary); + } + + .breadcrumbs__current { + color: + var(--color-text-primary); + + font-weight: + var(--font-weight-semibold); + } + + @media (max-width: 30rem) { + .breadcrumbs__list { + column-gap: + var(--space-1); + } + + .breadcrumbs__item { + gap: + var(--space-1); + + font-size: + var(--font-size-xs); + } + + .breadcrumbs__separator > svg { + width: 0.875rem; + height: 0.875rem; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.tsx b/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.tsx new file mode 100644 index 0000000..047364b --- /dev/null +++ b/apps/web/src/components/ui/Breadcrumbs/Breadcrumbs.tsx @@ -0,0 +1,79 @@ +import type { + ReactNode, +} from "react"; + +import { ChevronRightIcon } from "../../../icons/navigation"; +import { Icon } from "../Icon/Icon"; + +import "./Breadcrumbs.css"; + +export type BreadcrumbItem = { + label: ReactNode; + href?: string; +}; + +type BreadcrumbsProps = { + items: BreadcrumbItem[]; + ariaLabel?: string; +}; + +function Breadcrumbs({ + items, + ariaLabel = "Breadcrumb", +}: BreadcrumbsProps) { + if (items.length === 0) { + return null; + } + + return ( + + ); +} + +export default Breadcrumbs; \ No newline at end of file diff --git a/apps/web/src/components/ui/Tag/Tag.css b/apps/web/src/components/ui/Tag/Tag.css new file mode 100644 index 0000000..b67c83c --- /dev/null +++ b/apps/web/src/components/ui/Tag/Tag.css @@ -0,0 +1,82 @@ +@layer components { + .tag { + display: inline-flex; + align-items: center; + gap: var(--space-2); + + width: fit-content; + max-width: 100%; + min-height: 2rem; + + padding-inline: var(--space-3); + + font-size: var(--font-size-sm); + font-weight: var(--font-weight-medium); + line-height: var(--line-height-snug); + + border: + var(--border-width-thin) + solid + transparent; + + border-radius: var(--radius-lg); + } + + .tag__icon { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + } + + .tag__icon > svg { + display: block; + + width: var(--icon-size-sm); + height: var(--icon-size-sm); + } + + .tag__text { + min-width: 0; + } + + /* Neutral */ + + .tag--neutral { + color: var(--color-text-secondary); + background-color: var(--color-surface-muted); + border-color: var(--color-border-subtle); + } + + /* Brand / cuisine-like metadata */ + + .tag--brand { + color: var(--color-brand-primary-active); + background-color: var(--color-brand-accent-soft); + border-color: var(--color-border-subtle); + } + + /* Success / dietary metadata */ + + .tag--success { + color: var(--color-feedback-success); + background-color: var(--color-feedback-success-surface); + border-color: var(--color-feedback-success-border); + } + + /* Info / difficulty-like metadata */ + + .tag--info { + color: var(--color-feedback-info); + background-color: var(--color-feedback-info-surface); + border-color: var(--color-feedback-info-border); + } + + /* Warning / time-like metadata */ + + .tag--warning { + color: var(--color-feedback-warning); + background-color: var(--color-feedback-warning-surface); + border-color: var(--color-feedback-warning-border); + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Tag/Tag.tsx b/apps/web/src/components/ui/Tag/Tag.tsx new file mode 100644 index 0000000..ca8c26a --- /dev/null +++ b/apps/web/src/components/ui/Tag/Tag.tsx @@ -0,0 +1,38 @@ +import type { ComponentPropsWithRef, ComponentType, ReactNode } from "react"; + +import type { IconProps as SvgIconProps } from "../../../icons/types"; +import { Icon } from "../Icon/Icon"; +import "./Tag.css"; + +export type TagTone = "neutral" | "brand" | "success" | "info" | "warning"; + +export type TagProps = ComponentPropsWithRef<"span"> & { + children: ReactNode; + tone?: TagTone; + icon?: ComponentType; + iconProps?: Partial; +}; + +function Tag({ + children, + tone = "neutral", + icon, + iconProps, + className = "", + ...props +}: TagProps) { + const classes = ["tag", `tag--${tone}`, className].filter(Boolean).join(" "); + + return ( + + {icon && ( + + )} + {children} + + ); +} + +export default Tag; diff --git a/apps/web/src/components/ui/Tooltip/Tooltip.css b/apps/web/src/components/ui/Tooltip/Tooltip.css new file mode 100644 index 0000000..7fe6904 --- /dev/null +++ b/apps/web/src/components/ui/Tooltip/Tooltip.css @@ -0,0 +1,288 @@ +@layer components { + .tooltip { + position: relative; + + display: inline-flex; + + /* + * Gives the tooltip a local stacking context + * without requiring a global z-index token yet. + */ + z-index: 1; + } + + .tooltip__bubble { + position: absolute; + + z-index: 2; + + width: max-content; + max-width: 18rem; + + padding: + var(--space-2) + var(--space-3); + + color: + var(--color-text-inverse); + + background-color: + var(--color-text-primary); + + font-size: + var(--font-size-xs); + + font-weight: + var(--font-weight-medium); + + line-height: + var(--line-height-snug); + + text-align: center; + + border-radius: + var(--radius-md); + + box-shadow: + 0 4px 12px + color-mix( + in srgb, + var(--color-shadow) 16%, + transparent + ); + + opacity: 0; + visibility: hidden; + + pointer-events: none; + + transition: + opacity + var(--duration-fast) + var(--ease-standard), + visibility + var(--duration-fast) + var(--ease-standard), + transform + var(--duration-fast) + var(--ease-standard); + } + + .tooltip__bubble::after { + content: ""; + + position: absolute; + + width: 0; + height: 0; + + border-style: solid; + } + + /* + * Show on mouse hover and keyboard focus. + */ + .tooltip:hover + .tooltip__bubble, + .tooltip:focus-within + .tooltip__bubble { + opacity: 1; + visibility: visible; + } + + /* Top */ + + .tooltip--top + .tooltip__bubble { + inset-inline-start: 50%; + inset-block-end: + calc( + 100% + + var(--space-2) + ); + + transform: + translate( + -50%, + var(--space-1) + ); + } + + .tooltip--top:hover + .tooltip__bubble, + .tooltip--top:focus-within + .tooltip__bubble { + transform: + translate(-50%, 0); + } + + .tooltip--top + .tooltip__bubble::after { + inset-inline-start: 50%; + inset-block-start: 100%; + + transform: + translateX(-50%); + + border-width: + 0.3rem + 0.3rem + 0; + + border-color: + var(--color-text-primary) + transparent + transparent; + } + + /* Bottom */ + + .tooltip--bottom + .tooltip__bubble { + inset-inline-start: 50%; + inset-block-start: + calc( + 100% + + var(--space-2) + ); + + transform: + translate( + -50%, + calc( + var(--space-1) * -1 + ) + ); + } + + .tooltip--bottom:hover + .tooltip__bubble, + .tooltip--bottom:focus-within + .tooltip__bubble { + transform: + translate(-50%, 0); + } + + .tooltip--bottom + .tooltip__bubble::after { + inset-inline-start: 50%; + inset-block-end: 100%; + + transform: + translateX(-50%); + + border-width: + 0 + 0.3rem + 0.3rem; + + border-color: + transparent + transparent + var(--color-text-primary); + } + + /* Left */ + + .tooltip--left + .tooltip__bubble { + inset-inline-end: + calc( + 100% + + var(--space-2) + ); + + inset-block-start: 50%; + + transform: + translate( + var(--space-1), + -50% + ); + } + + .tooltip--left:hover + .tooltip__bubble, + .tooltip--left:focus-within + .tooltip__bubble { + transform: + translate(0, -50%); + } + + .tooltip--left + .tooltip__bubble::after { + inset-inline-start: 100%; + inset-block-start: 50%; + + transform: + translateY(-50%); + + border-width: + 0.3rem + 0 + 0.3rem + 0.3rem; + + border-color: + transparent + transparent + transparent + var(--color-text-primary); + } + + /* Right */ + + .tooltip--right + .tooltip__bubble { + inset-inline-start: + calc( + 100% + + var(--space-2) + ); + + inset-block-start: 50%; + + transform: + translate( + calc( + var(--space-1) * -1 + ), + -50% + ); + } + + .tooltip--right:hover + .tooltip__bubble, + .tooltip--right:focus-within + .tooltip__bubble { + transform: + translate(0, -50%); + } + + .tooltip--right + .tooltip__bubble::after { + inset-inline-end: 100%; + inset-block-start: 50%; + + transform: + translateY(-50%); + + border-width: + 0.3rem + 0.3rem + 0.3rem + 0; + + border-color: + transparent + var(--color-text-primary) + transparent + transparent; + } + + @media (prefers-reduced-motion: reduce) { + .tooltip__bubble { + transition: none; + } + } +} \ No newline at end of file diff --git a/apps/web/src/components/ui/Tooltip/Tooltip.tsx b/apps/web/src/components/ui/Tooltip/Tooltip.tsx new file mode 100644 index 0000000..8b3fc0f --- /dev/null +++ b/apps/web/src/components/ui/Tooltip/Tooltip.tsx @@ -0,0 +1,70 @@ +import { + cloneElement, + useId, + type ReactElement, + type ReactNode, +} from "react"; + +import "./Tooltip.css"; + +export type TooltipPlacement = + | "top" + | "right" + | "bottom" + | "left"; + +type TooltipTriggerProps = { + "aria-describedby"?: string; +}; + +type TooltipProps = { + content: ReactNode; + children: ReactElement; + placement?: TooltipPlacement; +}; + +function Tooltip({ + content, + children, + placement = "top", +}: TooltipProps) { + const tooltipId = useId(); + + const existingDescribedBy = + children.props["aria-describedby"]; + + const describedBy = [ + existingDescribedBy, + tooltipId, + ] + .filter(Boolean) + .join(" "); + + const trigger = cloneElement( + children, + { + "aria-describedby": describedBy, + }, + ); + + return ( + + {trigger} + + + {content} + + + ); +} + +export default Tooltip; \ No newline at end of file From a17480488ccc618c8b7f833961de92992903e535 Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:28:54 +0200 Subject: [PATCH 3/8] test: add UI component test setup --- apps/web/src/test/setup.ts | 42 +++++++++ package-lock.json | 173 +++++++++++++++++++++++++++++++++++++ package.json | 4 +- vitest.config.ts | 8 +- 4 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/test/setup.ts diff --git a/apps/web/src/test/setup.ts b/apps/web/src/test/setup.ts new file mode 100644 index 0000000..a59ba25 --- /dev/null +++ b/apps/web/src/test/setup.ts @@ -0,0 +1,42 @@ +/* + * jsdom does not consistently implement the native methods used by + * Dialog and Sheet. Keep this tiny polyfill test-only so production code still + * uses the browser's real dialog API. + */ +if (!HTMLDialogElement.prototype.showModal) { + Object.defineProperty( + HTMLDialogElement.prototype, + "showModal", + { + configurable: true, + value(this: HTMLDialogElement) { + this.setAttribute("open", ""); + }, + }, + ); +} + +if (!HTMLDialogElement.prototype.close) { + Object.defineProperty( + HTMLDialogElement.prototype, + "close", + { + configurable: true, + value(this: HTMLDialogElement) { + this.removeAttribute("open"); + }, + }, + ); +} + +if (!window.requestAnimationFrame) { + window.requestAnimationFrame = (callback) => + window.setTimeout( + () => callback(performance.now()), + 0, + ); + + window.cancelAnimationFrame = (id) => { + window.clearTimeout(id); + }; +} diff --git a/package-lock.json b/package-lock.json index b48ac6b..7f0a70a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@graphql-codegen/typescript-resolvers": "6.1.0", "@graphql-typed-document-node/core": "3.2.0", "@playwright/test": "1.63.0", + "@testing-library/react": "16.3.3", + "@testing-library/user-event": "14.6.7", "@vitejs/plugin-react": "6.0.1", "concurrently": "9.2.1", "drizzle-kit": "0.31.10", @@ -2969,6 +2971,109 @@ "resolved": "apps/web", "link": true }, + "node_modules/@testing-library/dom": { + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.2.tgz", + "integrity": "sha512-yzr2S9HyAIdhz2/6qHgbs665Q7PKVcDF05vsOlHPxG1mo36gKVesdYVeDLnXgfjJ03CrKRk08knc6+E/9m8v2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.10.4", + "@babel/runtime": "^7.12.5", + "@types/aria-query": "^5.0.1", + "aria-query": "5.3.0", + "dom-accessibility-api": "^0.5.9", + "lz-string": "^1.5.0", + "picocolors": "1.1.1", + "pretty-format": "^27.0.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@testing-library/dom/node_modules/@babel/runtime": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz", + "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@testing-library/dom/node_modules/aria-query": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", + "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "dequal": "^2.0.3" + } + }, + "node_modules/@testing-library/react": { + "version": "16.3.3", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.3.3.tgz", + "integrity": "sha512-Uo193NgQbPMz6lrrhtRQQFcMC6Re/ELLFbbuVL30WDlZxlpZf9/lMHTAVxPRLw1q1iu9OJmR1c2BLiENRstdBg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@testing-library/dom": "^10.0.0", + "@types/react": "^18.0.0 || ^19.0.0", + "@types/react-dom": "^18.0.0 || ^19.0.0", + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@testing-library/react/node_modules/@babel/runtime": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz", + "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@testing-library/user-event": { + "version": "14.6.7", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.6.7.tgz", + "integrity": "sha512-MPCpX8bxe8zS+JmmTwLp8jd0dy1rAm60Te/SL8JrQM3qvQJcBOs1d7IefJMyZzqM3EWBrDn/LWDt1BCGu4ASfg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12", + "npm": ">=6" + }, + "peerDependencies": { + "@testing-library/dom": ">=7.21.4" + } + }, + "node_modules/@types/aria-query": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", + "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -4330,6 +4435,17 @@ "node": ">=4" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -4341,6 +4457,14 @@ "node": ">=8" } }, + "node_modules/dom-accessibility-api": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", + "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/drizzle-kit": { "version": "0.31.10", "resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-0.31.10.tgz", @@ -7621,6 +7745,17 @@ "yallist": "^3.0.2" } }, + "node_modules/lz-string": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", + "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "lz-string": "bin/bin.js" + } + }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", @@ -8212,6 +8347,36 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/pretty-format": { + "version": "27.5.1", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", + "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-regex": "^5.0.1", + "ansi-styles": "^5.0.0", + "react-is": "^17.0.1" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + } + }, + "node_modules/pretty-format/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -8243,6 +8408,14 @@ "react": "^19.2.0" } }, + "node_modules/react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/react-router": { "version": "7.9.6", "resolved": "https://registry.npmjs.org/react-router/-/react-router-7.9.6.tgz", diff --git a/package.json b/package.json index 8250f7b..bbabab4 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "@graphql-codegen/typescript-resolvers": "6.1.0", "@graphql-typed-document-node/core": "3.2.0", "@playwright/test": "1.63.0", + "@testing-library/react": "16.3.3", + "@testing-library/user-event": "14.6.7", "@vitejs/plugin-react": "6.0.1", "concurrently": "9.2.1", "drizzle-kit": "0.31.10", @@ -47,9 +49,9 @@ "eslint-plugin-react-refresh": "0.4.24", "jsdom": "27.2.0", "prettier": "3.6.2", + "tsx": "4.20.6", "typescript": "5.9.3", "typescript-eslint": "8.48.0", - "tsx": "4.20.6", "vitest": "4.0.14" } } diff --git a/vitest.config.ts b/vitest.config.ts index fa573e1..fb25b82 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,5 +3,9 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ plugins: [react()], - test: { environment: 'jsdom', include: ['apps/**/*.test.{ts,tsx}'] }, -}); + test: { + environment: 'jsdom', + include: ['apps/**/*.test.{ts,tsx}'], + setupFiles: ['./apps/web/src/test/setup.ts'], + }, +}); \ No newline at end of file From 90bdc12626f2f866bc705f80231199d4e9f67a6a Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:34:08 +0200 Subject: [PATCH 4/8] fix: added cleanup after each test --- apps/web/src/test/setup.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/web/src/test/setup.ts b/apps/web/src/test/setup.ts index a59ba25..3a66914 100644 --- a/apps/web/src/test/setup.ts +++ b/apps/web/src/test/setup.ts @@ -1,3 +1,10 @@ +import { cleanup } from "@testing-library/react"; +import { afterEach } from "vitest"; + +afterEach(() => { + cleanup(); +}); + /* * jsdom does not consistently implement the native methods used by * Dialog and Sheet. Keep this tiny polyfill test-only so production code still From ec5fcc6439d414a4c40899d759ed5254a742c6e3 Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:34:40 +0200 Subject: [PATCH 5/8] test: add foundational UI component verification --- .../ui/__tests__/IconButton.test.tsx | 53 ++ .../components/ui/showcase/AvatarShowcase.tsx | 127 ++++ .../ui/showcase/BreadcrumbsShowcase.tsx | 109 ++++ .../components/ui/showcase/ButtonShowcase.tsx | 567 ++++++++++++++++++ .../ui/showcase/IconBadgeShowcase.tsx | 330 ++++++++++ .../ui/showcase/IconButtonShowcase.tsx | 149 +++++ .../ui/showcase/LoadingIndicatorShowcase.tsx | 150 +++++ .../ui/showcase/ShowcaseSection.tsx | 21 + .../components/ui/showcase/TagShowcase.tsx | 195 ++++++ .../ui/showcase/TooltipShowcase.tsx | 137 +++++ .../ui/showcase/UiShowcaseCatalog.tsx | 32 +- 11 files changed, 1866 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/components/ui/__tests__/IconButton.test.tsx create mode 100644 apps/web/src/components/ui/showcase/AvatarShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/BreadcrumbsShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/ButtonShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/IconBadgeShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/IconButtonShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/LoadingIndicatorShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/ShowcaseSection.tsx create mode 100644 apps/web/src/components/ui/showcase/TagShowcase.tsx create mode 100644 apps/web/src/components/ui/showcase/TooltipShowcase.tsx diff --git a/apps/web/src/components/ui/__tests__/IconButton.test.tsx b/apps/web/src/components/ui/__tests__/IconButton.test.tsx new file mode 100644 index 0000000..f6aee01 --- /dev/null +++ b/apps/web/src/components/ui/__tests__/IconButton.test.tsx @@ -0,0 +1,53 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; + +import { SearchIcon } from "../../../icons/navigation"; + +import IconButton from "../IconButton/IconButton"; + +describe("IconButton", () => { + it("uses its required aria-label as the accessible name and handles clicks", async () => { + const user = userEvent.setup(); + const onClick = vi.fn(); + + render( + , + ); + + const button = screen.getByRole("button", { + name: "Search recipes", + }); + + await user.click(button); + + expect(onClick).toHaveBeenCalledTimes(1); + }); + + it("does not fire its click handler while disabled", async () => { + const user = userEvent.setup(); + const onClick = vi.fn(); + + render( + , + ); + + const button = screen.getByRole("button", { + name: "Search recipes", + }) as HTMLButtonElement; + + await user.click(button); + + expect(button.disabled).toBe(true); + expect(onClick).not.toHaveBeenCalled(); + }); +}); diff --git a/apps/web/src/components/ui/showcase/AvatarShowcase.tsx b/apps/web/src/components/ui/showcase/AvatarShowcase.tsx new file mode 100644 index 0000000..cee16d9 --- /dev/null +++ b/apps/web/src/components/ui/showcase/AvatarShowcase.tsx @@ -0,0 +1,127 @@ +import Avatar from "../Avatar/Avatar"; +import { surfaceStyle } from "./showcaseStyles"; + + +const exampleAvatar = + "https://cdn-icons-png.flaticon.com/512/168/168732.png"; + +export default function AvatarShowcase() { + return ( +
+
+
+

Avatar Showcase

+ +

+ User images with an automatic + initials fallback. +

+
+ +
+

Sizes

+ +
+ + + + + +
+
+ +
+

Initials

+ +
+ + + + + + + +
+
+ +
+

Image

+ +
+ + +
+ + Recipe Author + + + + Recipe creator + +
+
+
+ +
+

Broken Image Fallback

+ +
+ +
+
+ +
+

User Menu Context

+ +
+ + +
+ + Ada Lovelace + + + + ada@example.com + +
+
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/BreadcrumbsShowcase.tsx b/apps/web/src/components/ui/showcase/BreadcrumbsShowcase.tsx new file mode 100644 index 0000000..cab23c2 --- /dev/null +++ b/apps/web/src/components/ui/showcase/BreadcrumbsShowcase.tsx @@ -0,0 +1,109 @@ +import Breadcrumbs from "../Breadcrumbs/Breadcrumbs"; +import { surfaceStyle } from "./showcaseStyles"; + + +export default function BreadcrumbsShowcase() { + return ( +
+
+
+

+ Breadcrumbs Showcase +

+ +

+ A lightweight navigation trail for + showing location within the application. +

+
+ +
+

Basic

+ +
+ +
+
+ +
+

Deeper Hierarchy

+ +
+ +
+
+ +
+

Single Level

+ +
+ +
+
+ +
+

Narrow Layout

+ +
+ +
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/ButtonShowcase.tsx b/apps/web/src/components/ui/showcase/ButtonShowcase.tsx new file mode 100644 index 0000000..98ca8e6 --- /dev/null +++ b/apps/web/src/components/ui/showcase/ButtonShowcase.tsx @@ -0,0 +1,567 @@ +import Button from "../Button/Button"; +import { surfaceStyle, raisedSurfaceStyle } from "./showcaseStyles"; + + + +export default function ButtonShowcase() { + return ( +
+
+
+

Button Showcase

+ +

+ Visual and interaction examples for the shared Button component. +

+
+ + {/* Variants */} + +
+

Variants

+ +

+ Primary, secondary, ghost, and destructive action hierarchy. +

+ +
+ + + + + + + +
+
+ + {/* Sizes */} + +
+

Sizes

+ +
+
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + + + +
+
+
+ + {/* Standard and wide */} + +
+

Standard & Wide

+ +
+
+

Standard

+ +
+ + + + + +
+
+ +
+

Wide

+ +
+ + + + + +
+
+
+
+ + {/* All variants wide */} + +
+

Wide Variants

+ +
+ + + + + + + +
+
+ +
+ + {/* Search */} + +
+

Search Context

+ +
+
+ Search recipes, ingredients, or cuisine... +
+ + +
+
+ + {/* Filter context */} + +
+

Filter Context

+ +
+
+

Recipe Filters

+ +

+ Ghost works well for low-emphasis utility actions. +

+
+ +
+ + + +
+
+
+ + {/* Form actions */} + +
+

Form Actions

+ +
+
+

Add Recipe

+ +

+ Typical hierarchy for form actions. +

+
+ +
+ + + + + +
+
+
+ + {/* Destructive context */} + +
+

Destructive Context

+ +

+ Destructive should be reserved for actions that remove or delete + data. +

+ +
+
+

Delete Recipe?

+ +

+ This action permanently removes the recipe. +

+
+ +
+ + + +
+
+
+ + {/* Secondary destructive-style hierarchy */} + +
+

Recipe Management

+ +
+
+ + Spaghetti Carbonara + + + + Published recipe + +
+ +
+ + + +
+
+
+ + {/* Disabled */} + +
+

Disabled States

+ +
+ + + + + + + +
+
+ + {/* Long labels */} + +
+

Long Labels

+ +
+ + + + + + + +
+
+ + {/* Narrow */} + +
+

Narrow Layout

+ +
+ + + + + + + +
+
+ + {/* Keyboard */} + +
+

Keyboard Focus

+ +

+ Use Tab to move through each variant and inspect the global focus + ring. +

+ +
+ + + + + + + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/IconBadgeShowcase.tsx b/apps/web/src/components/ui/showcase/IconBadgeShowcase.tsx new file mode 100644 index 0000000..27c5054 --- /dev/null +++ b/apps/web/src/components/ui/showcase/IconBadgeShowcase.tsx @@ -0,0 +1,330 @@ + +import { + IconBadge, +} from "../IconBadge/IconBadge"; + +import { BookmarkIcon, DeleteIcon } from "../../../icons/actions"; +import { CookbookIcon } from "../../../icons/navigation"; +import { StarIcon } from "../../../icons/rating"; +import { DietaryIcon } from "../../../icons/recipe"; +import { + AlertTriangleIcon, + InfoIcon, + SuccessIcon, +} from "../../../icons/status"; +import { surfaceStyle, raisedSurfaceStyle } from "./showcaseStyles"; + + + +export default function IconBadgeShowcase() { + return ( +
+
+
+

IconBadge Showcase

+ +

+ Non-interactive icon containers for + dialogs, cards, section headings, + feedback, and other visual emphasis. +

+
+ + {/* Variants */} + +
+
+

Variants

+ +

+ The icon stays the same while the + surrounding surface treatment changes. +

+
+ +
+
+ + soft +
+ +
+ + outline +
+ +
+ + solid +
+ +
+ + ghost +
+
+
+ + {/* Tones */} + +
+

Semantic Tones

+ +
+
+ + brand +
+ +
+ + success +
+ +
+ + warning +
+ +
+ + error +
+ +
+ + info +
+ +
+ + dietary +
+
+
+ + {/* Sizes */} + +
+

Sizes & Shapes

+ +
+
+ + sm +
+ +
+ + md +
+ +
+ + lg +
+ +
+ + circle +
+
+
+ + {/* Stroke */} + +
+
+

Stroke Weight

+ +

+ IconBadge uses the same named + icon-stroke tokens as Icon. +

+
+ +
+
+ + thin +
+ +
+ + default +
+ +
+ + strong +
+
+
+ + {/* Stateful */} + +
+
+

Icon-specific Props

+ +

+ Stateful icon props are forwarded + through iconProps. +

+
+ +
+
+ + Unfilled +
+ +
+ + Filled +
+ +
+ + Half star +
+ +
+ + Full star +
+
+
+ + {/* Context */} + +
+
+

Dialog / Section Context

+ +

+ IconBadge is decorative. Use + IconButton instead when the icon + itself performs an action. +

+
+ +
+ + +
+

Recipe Information

+ +

+ A badge gives an icon more visual + weight without suggesting that the + icon itself can be clicked. +

+
+
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/IconButtonShowcase.tsx b/apps/web/src/components/ui/showcase/IconButtonShowcase.tsx new file mode 100644 index 0000000..c38cf94 --- /dev/null +++ b/apps/web/src/components/ui/showcase/IconButtonShowcase.tsx @@ -0,0 +1,149 @@ +import { useState } from "react"; + +import { + BookmarkIcon, + CloseIcon, + DeleteIcon, + EditIcon, + HeartIcon, + SettingsIcon, + ShareIcon, +} from "../../../icons/actions"; +import { MenuIcon } from "../../../icons/navigation"; +import { InfoIcon } from "../../../icons/status"; +import IconButton, { type IconButtonVariant } from "../IconButton/IconButton"; +import Tooltip from "../Tooltip/Tooltip"; +import ShowcaseSection from "./ShowcaseSection"; +import { raisedSurfaceStyle, surfaceStyle } from "./showcaseStyles"; + +const variants: IconButtonVariant[] = [ + "primary", + "secondary", + "ghost", + "info", + "destructive", +]; + +export default function IconButtonShowcase() { + const [saved, setSaved] = useState(false); + const [favorite, setFavorite] = useState(false); + + return ( +
+
+
+

IconButton Showcase

+

+ Icon-only actions composed from the shared Icon component, with consistent size, color, and state behavior. +

+
+ + +
+ {variants.map((variant) => ( +
+ + {variant} +
+ ))} +
+
+ + +
+ + + +
+
+ + +
+
+ setSaved((value) => !value)} + /> + {saved ? "Saved" : "Not saved"} +
+ +
+ setFavorite((value) => !value)} + /> + {favorite ? "Favorite" : "Not favorite"} +
+
+
+ + +
+ + + + + + + + + + + + + + + + + + +
+
+ + +
+ {variants.map((variant) => ( + + ))} +
+
+ + +
+ + + + +
+
+
+
+ ); +} diff --git a/apps/web/src/components/ui/showcase/LoadingIndicatorShowcase.tsx b/apps/web/src/components/ui/showcase/LoadingIndicatorShowcase.tsx new file mode 100644 index 0000000..49e0679 --- /dev/null +++ b/apps/web/src/components/ui/showcase/LoadingIndicatorShowcase.tsx @@ -0,0 +1,150 @@ +import Button from "../Button/Button"; +import LoadingIndicator, { + Spinner, +} from "../LoadingIndicator/LoadingIndicator"; +import { surfaceStyle } from "./showcaseStyles"; + + +export default function LoadingIndicatorShowcase() { + return ( +
+
+
+

+ LoadingIndicator Showcase +

+ +

+ Loading feedback for asynchronous + actions, lists, and page sections. +

+
+ +
+

Spinner Sizes

+ +
+
+ + + Small +
+ +
+ + + Medium +
+ +
+ + + Large +
+
+
+ +
+

Inline

+ +
+ + + +
+
+ +
+

Section Loading

+ +
+ +
+
+ +
+

Recipe Results

+ +
+ +
+
+ +
+

Future Button Usage

+ +
+ + + +
+ +

+ The spinner can inherit the current + text color, which makes it reusable + inside buttons later. +

+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/ShowcaseSection.tsx b/apps/web/src/components/ui/showcase/ShowcaseSection.tsx new file mode 100644 index 0000000..911b255 --- /dev/null +++ b/apps/web/src/components/ui/showcase/ShowcaseSection.tsx @@ -0,0 +1,21 @@ +import type { ReactNode } from "react"; + +export default function ShowcaseSection({ + title, + description, + children, +}: { + title: ReactNode; + description?: ReactNode; + children: ReactNode; +}) { + return ( +
+
+

{title}

+ {description &&

{description}

} +
+ {children} +
+ ); +} diff --git a/apps/web/src/components/ui/showcase/TagShowcase.tsx b/apps/web/src/components/ui/showcase/TagShowcase.tsx new file mode 100644 index 0000000..93c59c2 --- /dev/null +++ b/apps/web/src/components/ui/showcase/TagShowcase.tsx @@ -0,0 +1,195 @@ +import Tag from "../Tag/Tag"; +import { CategoriesIcon, CookingTimeIcon, DietaryIcon, DifficultyIcon } from "../../../icons/recipe"; +import { surfaceStyle } from "./showcaseStyles"; + + + + + + +export default function TagShowcase() { + return ( +
+
+
+

Tag Showcase

+ +

+ Descriptive recipe metadata. Tags are not interactive. +

+
+ +
+

Tones

+ +
+ + Neutral + + + + Italian + + + + Vegetarian + + + + Easy + + + + 30 min + +
+
+ +
+

With Icons

+ +
+ + Italian + + + + Vegetarian + + + + Easy + + + + 30 min + +
+
+ +
+

Without Icons

+ +
+ + Italian + + + + Vegetarian + + + + Easy + + + + 30 min + +
+
+ +
+

Recipe Card Context

+ +
+
+

Tomato Basil Pasta

+ +

+ A simple, fresh pasta with tomatoes, basil, and garlic. +

+
+ +
+ + Italian + + + + Vegetarian + + + + Easy + + + + 30 min + +
+
+
+ +
+

Wrapping

+ +
+ + Mediterranean + + + + Vegetarian + + + + Beginner friendly + + + + Under 30 minutes + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/TooltipShowcase.tsx b/apps/web/src/components/ui/showcase/TooltipShowcase.tsx new file mode 100644 index 0000000..81f67f4 --- /dev/null +++ b/apps/web/src/components/ui/showcase/TooltipShowcase.tsx @@ -0,0 +1,137 @@ +import Button from "../Button/Button"; +import IconButton from "../IconButton/IconButton"; +import Tooltip from "../Tooltip/Tooltip"; +import { HeartIcon, ShareIcon } from "../../../icons/actions"; +import { MoreIcon } from "../../../icons/navigation"; +import { surfaceStyle } from "./showcaseStyles"; + + + + + +export default function TooltipShowcase() { + return ( +
+
+
+

Tooltip Showcase

+ +

+ Short supplementary descriptions + shown on hover or keyboard focus. +

+
+ +
+

Icon Actions

+ +
+ + + + + + + + + + + +
+
+ +
+

Placements

+ +
+ + + + + + + + + + + + + + + +
+
+ +
+

Longer Text

+ +
+ + + +
+
+ +
+

Keyboard

+ +
+

+ Tab to any tooltip trigger. The + tooltip should appear when the + control receives keyboard focus. +

+
+
+
+
+ ); +} \ No newline at end of file diff --git a/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx index 1950bd0..b7dc047 100644 --- a/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx +++ b/apps/web/src/components/ui/showcase/UiShowcaseCatalog.tsx @@ -1,11 +1,35 @@ -import IconShowcase from './IconShowcase'; +import AvatarShowcase from "./AvatarShowcase"; +import BreadcrumbsShowcase from "./BreadcrumbsShowcase"; +import ButtonShowcase from "./ButtonShowcase"; +import IconBadgeShowcase from "./IconBadgeShowcase"; +import IconButtonShowcase from "./IconButtonShowcase"; +import IconShowcase from "./IconShowcase"; +import LoadingIndicatorShowcase from "./LoadingIndicatorShowcase"; +import TagShowcase from "./TagShowcase"; +import TooltipShowcase from "./TooltipShowcase"; -// Intentionally render every showcase in one scrollable catalog. -// More showcases can be added back here as they are implemented. +// Intentionally render every available showcase in one scrollable catalog. +// This page doubles as a quick visual/responsive review surface. export default function UiShowcaseCatalog() { return (
+ + + + + + + + + + + + + + + +
); -} +} \ No newline at end of file From 7a08c235c8f729603f136a4c66d9eda7529c7b17 Mon Sep 17 00:00:00 2001 From: olestang Date: Tue, 29 Sep 2026 11:38:41 +0200 Subject: [PATCH 6/8] fix: apply Prettier formatting to UI components --- apps/web/src/components/ui/Avatar/Avatar.css | 28 +- apps/web/src/components/ui/Avatar/Avatar.tsx | 71 ++--- .../components/ui/Breadcrumbs/Breadcrumbs.css | 59 ++-- .../components/ui/Breadcrumbs/Breadcrumbs.tsx | 49 +-- apps/web/src/components/ui/Button/Button.css | 7 +- apps/web/src/components/ui/Button/Button.tsx | 26 +- .../src/components/ui/IconBadge/IconBadge.css | 5 +- .../src/components/ui/IconBadge/IconBadge.tsx | 107 +++---- .../components/ui/IconButton/IconButton.css | 15 +- .../components/ui/IconButton/IconButton.tsx | 58 ++-- .../ui/LoadingIndicator/LoadingIndicator.css | 79 ++--- .../ui/LoadingIndicator/LoadingIndicator.tsx | 83 ++--- apps/web/src/components/ui/Tag/Tag.css | 7 +- apps/web/src/components/ui/Tag/Tag.tsx | 18 +- .../web/src/components/ui/Tooltip/Tooltip.css | 225 ++++---------- .../web/src/components/ui/Tooltip/Tooltip.tsx | 57 +--- .../ui/__tests__/IconButton.test.tsx | 24 +- .../components/ui/showcase/AvatarShowcase.tsx | 66 +--- .../ui/showcase/BreadcrumbsShowcase.tsx | 52 ++-- .../components/ui/showcase/ButtonShowcase.tsx | 292 +++++------------- .../ui/showcase/IconBadgeShowcase.tsx | 144 +++------ .../ui/showcase/IconButtonShowcase.tsx | 121 ++++++-- .../ui/showcase/LoadingIndicatorShowcase.tsx | 75 ++--- .../ui/showcase/ShowcaseSection.tsx | 2 +- .../components/ui/showcase/TagShowcase.tsx | 118 ++----- .../ui/showcase/TooltipShowcase.tsx | 76 ++--- .../ui/showcase/UiShowcaseCatalog.tsx | 20 +- apps/web/src/test/setup.ts | 37 +-- vitest.config.ts | 2 +- 29 files changed, 632 insertions(+), 1291 deletions(-) diff --git a/apps/web/src/components/ui/Avatar/Avatar.css b/apps/web/src/components/ui/Avatar/Avatar.css index 47f209a..4ee9db1 100644 --- a/apps/web/src/components/ui/Avatar/Avatar.css +++ b/apps/web/src/components/ui/Avatar/Avatar.css @@ -8,19 +8,13 @@ overflow: hidden; - color: - var(--color-brand-primary-active); + color: var(--color-brand-primary-active); - background-color: - var(--color-brand-accent-soft); + background-color: var(--color-brand-accent-soft); - border: - var(--border-width-thin) - solid - var(--color-border-default); + border: var(--border-width-thin) solid var(--color-border-default); - border-radius: - var(--radius-full); + border-radius: var(--radius-full); user-select: none; } @@ -31,24 +25,21 @@ width: 2rem; height: 2rem; - font-size: - var(--font-size-xs); + font-size: var(--font-size-xs); } .avatar--md { width: 2.75rem; height: 2.75rem; - font-size: - var(--font-size-sm); + font-size: var(--font-size-sm); } .avatar--lg { width: 3.5rem; height: 3.5rem; - font-size: - var(--font-size-md); + font-size: var(--font-size-md); } /* Image */ @@ -72,9 +63,8 @@ width: 100%; height: 100%; - font-weight: - var(--font-weight-semibold); + font-weight: var(--font-weight-semibold); line-height: 1; } -} \ No newline at end of file +} diff --git a/apps/web/src/components/ui/Avatar/Avatar.tsx b/apps/web/src/components/ui/Avatar/Avatar.tsx index 1702af5..1b86f17 100644 --- a/apps/web/src/components/ui/Avatar/Avatar.tsx +++ b/apps/web/src/components/ui/Avatar/Avatar.tsx @@ -1,13 +1,8 @@ -import { - useState, -} from "react"; +import { useState } from 'react'; -import "./Avatar.css"; +import './Avatar.css'; -export type AvatarSize = - | "sm" - | "md" - | "lg"; +export type AvatarSize = 'sm' | 'md' | 'lg'; type AvatarProps = { name: string; @@ -20,55 +15,34 @@ type AvatarProps = { className?: string; }; -function getInitials( - name: string, -) { - const words = name - .trim() - .split(/\s+/) - .filter(Boolean); +function getInitials(name: string) { + const words = name.trim().split(/\s+/).filter(Boolean); if (words.length === 0) { - return "?"; + return '?'; } if (words.length === 1) { - return words[0] - .slice(0, 2) - .toUpperCase(); + return words[0].slice(0, 2).toUpperCase(); } - return ( - words[0][0] + - words[words.length - 1][0] - ).toUpperCase(); + return (words[0][0] + words[words.length - 1][0]).toUpperCase(); } function Avatar({ name, src, alt = name, - size = "md", - className = "", + size = 'md', + className = '', }: AvatarProps) { - const [ - failedSrc, - setFailedSrc, - ] = useState( - undefined, - ); + const [failedSrc, setFailedSrc] = useState(undefined); - const showImage = - Boolean(src) && - failedSrc !== src; + const showImage = Boolean(src) && failedSrc !== src; - const classes = [ - "avatar", - `avatar--${size}`, - className, - ] + const classes = ['avatar', `avatar--${size}`, className] .filter(Boolean) - .join(" "); + .join(' '); if (showImage && src) { return ( @@ -77,28 +51,19 @@ function Avatar({ className="avatar__image" src={src} alt={alt} - onError={() => - setFailedSrc(src) - } + onError={() => setFailedSrc(src)} /> ); } return ( - -