From d6993c9212e949775c4d538e8563b743da2c024d Mon Sep 17 00:00:00 2001 From: Jerred Shepherd Date: Thu, 26 Nov 2026 10:23:43 -0800 Subject: [PATCH 1/2] feat(scout-for-lol): add hero, duel hero, face, strip, bar and rank lockup components Why The redesigned pages share a handful of domain pieces: a lead panel with a champion fading in, a matchup lead with two champions, round faces for champions and people, the last-games strip, a win-rate bar and a rank lockup. They belong in the design system, built once on the soft surface primitives. What - `domain/profile/`: `HeroPanel` (art, `align`, an `action` slot, works with no art) and `DuelHero`; `ChampionFace` (sizes 26 to 92, win/loss mark) and `PersonInitial` (sizes, `you`, live dot, champion badge); `ResultStrip` (oldest to newest, hollow loss rings, soft current-streak highlight, accessible summary); `WinRateBar` (a filled bar, or a dot on a track with an optional 50% mark and likely range); `RankLockup`. - Art takes `face` (the way the champion in the source art looks) and a `mirrored` override, so a later facing file can flip the art toward the words without touching call sites. No facing data exists yet; art is shown as it is until `face` is given. - `RankDisplay` gains `size` and `detail`; `RankLockup` wraps it. - `styles/friendly-domain.css` carries the rules, values from d9, d10 and d11 CSS, plus a `--scout-loss-soft` variable beside `--scout-win-soft`. - A story per component with real champion art, long names, empty and no-art cases; the catalog test runs them in its three themes. - `text-scout-warning` was used by the app but never mapped, so it rendered as inherited text. Mapping it to the fill would be 2.3:1 (modern) and 3.6:1 (classic) on the dark themes, so this adds a `warningOnSurface` token to all four themes (light: the existing value; dark: #E0A24F and #D9A04F, at least 6:1 on every ground), the schema and the generator, and maps `scout-warning` to it in the app. A test holds the contrast. Verification - bunx turbo run build typecheck test lint --filter=@scout-for-lol/design-system --filter=@scout-for-lol/app --filter=@scout-for-lol/frontend --filter=@scout-for-lol/design-audit. - bun run test:e2e in the design-system package: every new story in modern dark, modern light and classic light with axe. - Stories rendered and inspected in modern dark and light at 1440 and 390. - Extended tier: none of the touched packages has extended steps. - Not run: live deployment; no page uses these components yet. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_011u9pQk6p4o3DxofkiZXg8y --- .../packages/app/src/styles/global.css | 3 + .../design-system/scripts/generate-tokens.ts | 3 + .../domain/profile/champion-face.stories.tsx | 96 +++ .../src/domain/profile/champion-face.tsx | 69 ++ .../src/domain/profile/duel-hero.stories.tsx | 122 ++++ .../src/domain/profile/duel-hero.tsx | 36 + .../src/domain/profile/hero-art.tsx | 56 ++ .../src/domain/profile/hero-panel.stories.tsx | 136 ++++ .../src/domain/profile/hero-panel.tsx | 49 ++ .../domain/profile/person-initial.stories.tsx | 97 +++ .../src/domain/profile/person-initial.tsx | 72 ++ .../src/domain/profile/profile.test.tsx | 347 ++++++++++ .../domain/profile/rank-lockup.stories.tsx | 60 ++ .../src/domain/profile/rank-lockup.tsx | 39 ++ .../domain/profile/result-strip.stories.tsx | 75 ++ .../src/domain/profile/result-strip.tsx | 101 +++ .../domain/profile/win-rate-bar.stories.tsx | 109 +++ .../src/domain/profile/win-rate-bar.tsx | 174 +++++ .../design-system/src/domain/rank-display.tsx | 13 +- .../design-system/src/friendly-styles.test.ts | 19 + .../design-system/src/generated/tokens.ts | 4 + .../design-system/styles/friendly-domain.css | 646 ++++++++++++++++++ .../design-system/styles/friendly.css | 5 + .../design-system/styles/generated/tokens.css | 4 + .../packages/design-system/styles/index.css | 1 + .../packages/design-system/tokens/themes.json | 4 + .../design-system/tokens/themes.schema.json | 4 + 27 files changed, 2343 insertions(+), 1 deletion(-) create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/hero-art.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/rank-lockup.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/rank-lockup.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.tsx create mode 100644 packages/scout-for-lol/packages/design-system/styles/friendly-domain.css diff --git a/packages/scout-for-lol/packages/app/src/styles/global.css b/packages/scout-for-lol/packages/app/src/styles/global.css index e596d69d63f..097c0f28e7e 100644 --- a/packages/scout-for-lol/packages/app/src/styles/global.css +++ b/packages/scout-for-lol/packages/app/src/styles/global.css @@ -33,6 +33,9 @@ --color-scout-danger-ink: var(--scout-color-danger-text); --color-scout-success: var(--scout-color-success-on-surface); --color-scout-success-fill: var(--scout-color-success); + /* `text-scout-warning` was used without being mapped, so it rendered as + inherited text. Like success and danger, the readable-as-text colour. */ + --color-scout-warning: var(--scout-color-warning-on-surface); --color-scout-border: var(--scout-color-border); --color-scout-focus: var(--scout-color-focus); /* Match outcomes. `win`/`loss` read as text on a surface; the `-fill` diff --git a/packages/scout-for-lol/packages/design-system/scripts/generate-tokens.ts b/packages/scout-for-lol/packages/design-system/scripts/generate-tokens.ts index 349a64d5e5d..3834e25ac93 100644 --- a/packages/scout-for-lol/packages/design-system/scripts/generate-tokens.ts +++ b/packages/scout-for-lol/packages/design-system/scripts/generate-tokens.ts @@ -28,6 +28,9 @@ const ColorsSchema = z.object({ successOnSurface: HexColorSchema, warning: HexColorSchema, warningText: HexColorSchema, + // Same split as danger and success: warning-coloured text on an ordinary + // background, where the fill is too dark to read on the dark themes. + warningOnSurface: HexColorSchema, danger: HexColorSchema, dangerText: HexColorSchema, // `danger` fills a surface and `dangerText` is the text on that fill. Danger diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx new file mode 100644 index 00000000000..b05eb701b34 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx @@ -0,0 +1,96 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { + CHAMPION_FACE_SIZES, + ChampionFace, + type ChampionFaceResult, +} from "./champion-face.tsx"; + +const meta = { + title: "Domain/ChampionFace", + component: ChampionFace, + tags: ["autodocs"], + args: { champion: "Ahri" }, +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = {}; + +export const Win: Story = { args: { result: "win" } }; + +export const Loss: Story = { args: { result: "loss" } }; + +export const ByNumericId: Story = { args: { champion: 103, result: "win" } }; + +export const Decorative: Story = { + args: { champion: "Syndra", alt: "" }, +}; + +const champions = ["Ahri", "Syndra", "Jinx", "Thresh", "Nunu", "Renata"]; + +export const Sizes: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ {CHAMPION_FACE_SIZES.map((size) => ( + + ))} +
+ ), +}; + +export const SizesWithResults: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ {(["win", "loss"] satisfies ChampionFaceResult[]).map((result) => ( +
+ {CHAMPION_FACE_SIZES.map((size) => ( + + ))} +
+ ))} +
+ ), +}; + +export const InAFeed: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
    + {champions.map((champion, index) => ( +
  • + + + {index % 3 === 1 ? "Lost" : "Won"} as {champion} + +
  • + ))} +
+ ), +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.tsx new file mode 100644 index 00000000000..5f794161896 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.tsx @@ -0,0 +1,69 @@ +import { ChampionPortrait } from "#src/assets/index.tsx"; +import { cn } from "#src/lib/cn.ts"; + +/** The diameters the redesigned pages use, in CSS pixels. */ +export const CHAMPION_FACE_SIZES = [26, 36, 40, 46, 76, 92] as const; +export type ChampionFaceSize = (typeof CHAMPION_FACE_SIZES)[number]; + +export type ChampionFaceResult = "win" | "loss"; + +const RESULT_LABEL: Record = { + win: "Won", + loss: "Lost", +}; + +export type ChampionFaceProps = { + /** Champion key, name or numeric id, as the asset helpers accept. */ + champion: string | number; + size?: ChampionFaceSize; + /** A small mark on the lower right: a check for a win, a dash for a loss. */ + result?: ChampionFaceResult; + /** Defaults to the champion's name. Pass "" when the name is beside it. */ + alt?: string; + className?: string; +}; + +/** + * A round champion portrait, with an optional result mark. A face is always a + * face: a champion here, a person in `PersonInitial`. + * + * Rows that change the ground colour on hover set `--scout-face-ground` so the + * ring around the mark follows it. + */ +export function ChampionFace({ + champion, + size = 46, + result, + alt, + className, +}: ChampionFaceProps) { + return ( + + + {result === undefined ? null : ( + + {result === "win" ? ( + + ) : null} + {RESULT_LABEL[result]} + + )} + + ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.stories.tsx new file mode 100644 index 00000000000..e77d35df19a --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.stories.tsx @@ -0,0 +1,122 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { Chip } from "#src/components/surfaces/chip.tsx"; +import { ChampionFace } from "./champion-face.tsx"; +import { DuelHero } from "./duel-hero.tsx"; + +const meta = { + title: "Domain/DuelHero", + component: DuelHero, + tags: ["autodocs"], + parameters: { layout: "fullscreen" }, + decorators: [ + (story) => ( +
+ {story()} +
+ ), + ], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +const h1 = { + margin: 0, + font: "700 clamp(1.75rem, 4.5vw, 3.125rem)/1.05 var(--scout-font-display)", + overflowWrap: "anywhere", +} as const; + +function Verdict(props: { a: string; b: string; id: string }) { + return ( + <> +

+ {props.a}{" "} + + against + {" "} + {props.b} +

+

+ {props.b} has the edge. +

+

+ {props.a} wins 47.8% of 1,050 games against her. +

+
+ + + I'm playing Ahri + + + + I'm playing Syndra + +
+ + ); +} + +export const Default: Story = { + args: { + start: { champion: "Ahri", face: "left" }, + end: { champion: "Syndra", face: "left" }, + "aria-labelledby": "duel-default", + children: , + }, +}; + +export const ArtFacingAway: Story = { + args: { + start: { champion: "Jinx", face: "right" }, + end: { champion: "Thresh", face: "right" }, + "aria-labelledby": "duel-away", + children: , + }, +}; + +export const MirroredByFlag: Story = { + args: { + start: { champion: "Ahri", mirrored: false }, + end: { champion: "Syndra", mirrored: true }, + "aria-labelledby": "duel-flag", + children: , + }, +}; + +export const LongNames: Story = { + args: { + start: { champion: "Nunu", face: "left" }, + end: { champion: "Renata", face: "left" }, + "aria-labelledby": "duel-long", + children: , + }, +}; + +export const WordsOnly: Story = { + args: { + start: { champion: "Ahri" }, + end: { champion: "Syndra" }, + "aria-labelledby": "duel-short", + children: ( +

+ Ahri against Syndra +

+ ), + }, +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.tsx new file mode 100644 index 00000000000..7d49e31fc21 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/duel-hero.tsx @@ -0,0 +1,36 @@ +import type { HTMLAttributes, ReactNode } from "react"; +import { Panel } from "#src/components/surfaces/panel.tsx"; +import { cn } from "#src/lib/cn.ts"; +import { HeroArtImage, type HeroArt } from "./hero-art.tsx"; + +export type DuelHeroProps = Omit, "children"> & { + /** The verdict, centred between the champions: heading, lead, controls. */ + children: ReactNode; + /** The champion on the left, looking right. */ + start: HeroArt; + /** The champion on the right, looking left. */ + end: HeroArt; +}; + +/** + * Two champions facing each other across a centred verdict, as on a matchup + * page. Each one fades in from its own edge. Give it `aria-labelledby` and the + * heading's id so it is a landmark. + */ +export function DuelHero({ + children, + start, + end, + className, + ...props +}: DuelHeroProps) { + return ( + +
+ + +
{children}
+
+
+ ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-art.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-art.tsx new file mode 100644 index 00000000000..380a82cee80 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-art.tsx @@ -0,0 +1,56 @@ +import { ChampionSplashArt } from "#src/assets/index.tsx"; +import { cn } from "#src/lib/cn.ts"; + +/** The way the champion in a piece of art looks. */ +export type ArtFace = "left" | "right"; + +export type HeroArt = { + /** Champion key, name or numeric id. */ + champion: string | number; + /** Decorative by default: the hero's words already name the champion. */ + alt?: string; + /** + * The direction the champion in the source art faces. A hero wants its + * champion to look toward the words, so art that faces away is mirrored. + * Left out when it is not known; the art is then shown as it is. + */ + face?: ArtFace; + /** Forces the mirror on or off, whatever `face` says. */ + mirrored?: boolean; +}; + +/** The side of the hero a champion sits on. */ +export type ArtSide = "start" | "end"; + +/** + * Whether art on `side` is flipped. A champion at the start looks right, toward + * the middle; one at the end looks left. An explicit `mirrored` wins; with + * neither it and `face`, the art is left as it is. + */ +export function isArtMirrored(art: HeroArt, side: ArtSide): boolean { + if (art.mirrored !== undefined) return art.mirrored; + if (art.face === undefined) return false; + const wanted: ArtFace = side === "start" ? "right" : "left"; + return art.face !== wanted; +} + +/** One champion fading in from a side of a hero. Position and mask are CSS. */ +export function HeroArtImage({ + art, + side, + className, +}: { + art: HeroArt; + side: ArtSide; + className?: string; +}) { + return ( +
+ +
+ ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.stories.tsx new file mode 100644 index 00000000000..93b2e458192 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.stories.tsx @@ -0,0 +1,136 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { Search } from "lucide-react"; +import { Chip } from "#src/components/surfaces/chip.tsx"; +import { HeroPanel } from "./hero-panel.tsx"; +import { RankLockup } from "./rank-lockup.tsx"; + +const meta = { + title: "Domain/HeroPanel", + component: HeroPanel, + tags: ["autodocs"], + parameters: { layout: "fullscreen" }, + decorators: [ + (story) => ( +
+ {story()} +
+ ), + ], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +const h1 = { + margin: 0, + font: "700 clamp(2.5rem, 6vw, 3.75rem)/1 var(--scout-font-display)", + overflowWrap: "anywhere", +} as const; + +function Words(props: { name: string; id: string }) { + return ( + <> +

+ {props.name} +

+ +

+ Mid main in Rift Study Group. Mostly plays Ahri, Syndra and Orianna. +

+ + ); +} + +const findAnother = ( + + +); + +export const Default: Story = { + args: { + art: { champion: "Ahri" }, + "aria-labelledby": "hero-default", + action: findAnother, + children: , + }, +}; + +export const WordsOnTheRight: Story = { + args: { + art: { champion: "Syndra" }, + align: "end", + "aria-labelledby": "hero-end", + action: findAnother, + children: , + }, +}; + +export const ArtFacingAway: Story = { + args: { + art: { champion: "Jinx", face: "right" }, + "aria-labelledby": "hero-away", + children: , + }, +}; + +export const ArtFacingTheWords: Story = { + args: { + art: { champion: "Jinx", face: "left" }, + "aria-labelledby": "hero-toward", + children: , + }, +}; + +export const MirroredByFlag: Story = { + args: { + art: { champion: "Thresh", mirrored: true }, + "aria-labelledby": "hero-flag", + children: , + }, +}; + +export const LongName: Story = { + args: { + art: { champion: "Nunu" }, + "aria-labelledby": "hero-long", + action: findAnother, + children: ( + + ), + }, +}; + +export const NoArt: Story = { + args: { + "aria-labelledby": "hero-plain", + action: findAnother, + children: , + }, +}; + +export const NoArtWordsOnly: Story = { + args: { + "aria-labelledby": "hero-bare", + children: ( + <> +

+ Northstar +

+

+ No games recorded yet. +

+ + ), + }, +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.tsx new file mode 100644 index 00000000000..79489188e7a --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/hero-panel.tsx @@ -0,0 +1,49 @@ +import type { HTMLAttributes, ReactNode } from "react"; +import { Panel } from "#src/components/surfaces/panel.tsx"; +import { cn } from "#src/lib/cn.ts"; +import { HeroArtImage, type ArtSide, type HeroArt } from "./hero-art.tsx"; + +export type HeroPanelProps = Omit, "children"> & { + /** The words: a heading and whatever sits under it. */ + children: ReactNode; + /** A champion fading in behind the far side. Omit for a plain hero. */ + art?: HeroArt; + /** Which side the words sit on; the art takes the other. */ + align?: ArtSide; + /** A control that floats over the art side, such as a search chip. */ + action?: ReactNode; +}; + +/** + * The lead panel of a page: words on one side, a champion's splash art fading + * in from the other. Without `art` it is a plain panel of words. Render it as + * a landmark by giving it `aria-labelledby` and the heading's id. + */ +export function HeroPanel({ + children, + art, + align = "start", + action, + className, + ...props +}: HeroPanelProps) { + const artSide: ArtSide = align === "start" ? "end" : "start"; + return ( + +
+ {art === undefined ? null : } +
{children}
+ {action === undefined ? null : ( +
+ {action} +
+ )} +
+
+ ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx new file mode 100644 index 00000000000..31536a2b8be --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx @@ -0,0 +1,97 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { PersonInitial } from "./person-initial.tsx"; + +const meta = { + title: "Domain/PersonInitial", + component: PersonInitial, + tags: ["autodocs"], + args: { name: "RiverQuartz" }, +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = {}; + +export const You: Story = { args: { name: "Northstar", you: true } }; + +export const Live: Story = { args: { live: true } }; + +export const WithChampion: Story = { args: { champion: "Ahri" } }; + +export const LiveYouWithChampion: Story = { + args: { name: "Northstar", you: true, live: true, champion: "Syndra" }, +}; + +const row = { display: "flex", alignItems: "center", gap: "1.5rem" } as const; + +export const Sizes: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ + + + + + +
+ ), +}; + +export const SizesWithBadgeAndLive: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ + + +
+ ), +}; + +export const UnusualNames: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ {[ + "@mapleCarry", + "#1 Fan", + "์œ ๋‚˜", + "รฑandรบ", + "๐Ÿ™‚ smile", + "xX_ExtremelyLongSummonerNameThatKeepsGoing_Xx", + "", + ].map((name) => ( + + ))} +
+ ), +}; + +export const BesideNames: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
    + {["Northstar", "RiverQuartz", "MapleCarry"].map((name, index) => ( +
  • + + {name} +
  • + ))} +
+ ), +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.tsx new file mode 100644 index 00000000000..4b8cd8ad448 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.tsx @@ -0,0 +1,72 @@ +import { ChampionPortrait } from "#src/assets/index.tsx"; +import { cn } from "#src/lib/cn.ts"; + +export type PersonInitialSize = "s" | "m" | "l"; + +const FIRST_LETTER_OR_DIGIT = /[\p{L}\p{N}]/u; + +function firstGrapheme(text: string): string | undefined { + for (const part of new Intl.Segmenter().segment(text)) return part.segment; + return undefined; +} + +/** + * The letter a person's disc shows: the first letter or digit of the name, so + * "@Northstar" and "#river" read as N and R. A name with neither (all symbols + * or emoji) falls back to its first character. + */ +export function initialOf(name: string): string { + const trimmed = name.trim(); + const letter = FIRST_LETTER_OR_DIGIT.exec(trimmed)?.[0]; + const first = letter ?? firstGrapheme(trimmed); + return first === undefined ? "?" : first.toLocaleUpperCase(); +} + +export type PersonInitialProps = { + name: string; + size?: PersonInitialSize; + /** The signed-in viewer: the disc takes the brand colour. */ + you?: boolean; + /** A dot for someone in a game right now. */ + live?: boolean; + /** A small champion badge on the lower right. */ + champion?: string | number; + className?: string; +}; + +/** + * A round initial for a person. The disc is decorative because the name always + * sits beside it; `live` adds its own text for assistive technology. + */ +export function PersonInitial({ + name, + size = "m", + you = false, + live = false, + champion, + className, +}: PersonInitialProps) { + return ( + + + {live ? ( + + In a game now + + ) : null} + {champion === undefined ? null : ( + + )} + + ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx new file mode 100644 index 00000000000..eb0057ada3d --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx @@ -0,0 +1,347 @@ +import { renderToStaticMarkup } from "react-dom/server"; +import { describe, expect, test } from "vitest"; +import { ChampionFace } from "./champion-face.tsx"; +import { DuelHero } from "./duel-hero.tsx"; +import { isArtMirrored } from "./hero-art.tsx"; +import { HeroPanel } from "./hero-panel.tsx"; +import { initialOf, PersonInitial } from "./person-initial.tsx"; +import { RankLockup } from "./rank-lockup.tsx"; +import { + currentStreak, + ResultStrip, + resultStripSummary, + type GameResult, +} from "./result-strip.tsx"; +import { formatPercent, trackPosition, WinRateBar } from "./win-rate-bar.tsx"; + +const win: GameResult = "win"; +const loss: GameResult = "loss"; + +describe("currentStreak", () => { + test("counts the run at the newest end", () => { + expect(currentStreak([loss, win, win, win])).toEqual({ + result: "win", + length: 3, + }); + expect(currentStreak([win, win, loss, loss])).toEqual({ + result: "loss", + length: 2, + }); + }); + + test("is a streak of one for a single game and absent for none", () => { + expect(currentStreak([win])).toEqual({ result: "win", length: 1 }); + expect(currentStreak([])).toBeUndefined(); + }); +}); + +describe("ResultStrip", () => { + const twenty: GameResult[] = [ + loss, + win, + loss, + win, + loss, + win, + win, + loss, + win, + loss, + win, + win, + win, + loss, + loss, + win, + loss, + win, + win, + win, + ]; + + test("summarises the games and the streak for assistive technology", () => { + expect(resultStripSummary(twenty)).toBe( + "The last 20 games, oldest first: loss, win, loss, win, loss, win, win, loss, win, loss, win, win, win, loss, loss, win, loss, win, win, win. Current streak: 3 wins.", + ); + expect(resultStripSummary([])).toBe("No games yet."); + expect(resultStripSummary([win])).toBe( + "The last 1 game, oldest first: win.", + ); + }); + + test("draws one dot per slot and wraps only the streak", () => { + const html = renderToStaticMarkup(); + expect(html.match(/]*>(.*?)<\/span>/.exec(html); + expect(streak?.[1]?.match(/ { + const short = renderToStaticMarkup( + , + ); + expect(short.match(/, + ); + expect(long.match(/ { + const losing = renderToStaticMarkup( + , + ); + expect(losing).toContain( + 'class="scout-result-strip__streak" data-result="loss"', + ); + const single = renderToStaticMarkup( + , + ); + expect(single).not.toContain("scout-result-strip__streak"); + }); + + test("renders with no games", () => { + const html = renderToStaticMarkup(); + expect(html).toContain('aria-label="No games yet."'); + expect(html.match(/ { + test("formats at most one decimal", () => { + expect(formatPercent(65)).toBe("65%"); + expect(formatPercent(51.8)).toBe("51.8%"); + expect(formatPercent(43.14)).toBe("43.1%"); + expect(formatPercent(50.04)).toBe("50%"); + }); + + test("places values on a track the way the public page does", () => { + expect(trackPosition(51.8, [48, 56])).toBeCloseTo(47.5, 5); + expect(trackPosition(43.1, [30, 70])).toBeCloseTo(32.75, 5); + expect(trackPosition(10, [40, 60])).toBe(0); + expect(trackPosition(90, [40, 60])).toBe(100); + }); + + test("renders a filled bar with its value and an accessible summary", () => { + const html = renderToStaticMarkup(); + expect(html).toContain('style="width:65%"'); + expect(html).toContain('aria-label="Win rate 65%."'); + expect(html).toContain('data-you="true"'); + expect(html).toContain("scout-win-rate__even"); + }); + + test("renders a range with a likely band and an even mark", () => { + const html = renderToStaticMarkup( + , + ); + expect(html).toContain( + 'aria-label="51.8%, likely between 50.9% and 52.7%. 50% is an even game."', + ); + expect(html).toContain("left:47.5%"); + expect(html).toContain("left:36.25%"); + expect(html).toContain("width:22.5%"); + expect(html).toContain("50%, even"); + }); + + test("fails loudly on a value outside 0 to 100 or a backwards range", () => { + expect(() => renderToStaticMarkup()).toThrow( + RangeError, + ); + expect(() => + renderToStaticMarkup(), + ).toThrow(RangeError); + expect(() => + renderToStaticMarkup( + , + ), + ).toThrow(RangeError); + }); +}); + +describe("initialOf", () => { + test("takes the first letter or digit and upper-cases it", () => { + expect(initialOf("Northstar")).toBe("N"); + expect(initialOf(" riverQuartz")).toBe("R"); + expect(initialOf("@mapleCarry")).toBe("M"); + expect(initialOf("#1 Fan")).toBe("1"); + expect(initialOf("์œ ๋‚˜")).toBe("์œ "); + }); + + test("falls back to the first character, then to a question mark", () => { + expect(initialOf("!!!")).toBe("!"); + expect(initialOf(" ")).toBe("?"); + }); +}); + +describe("PersonInitial", () => { + test("hides the disc from assistive technology and names the live state", () => { + const html = renderToStaticMarkup( + , + ); + expect(html).toContain('aria-hidden="true">N<'); + expect(html).toContain('data-you="true"'); + expect(html).toContain("In a game now"); + expect(html).toContain("scout-person__badge"); + }); + + test("is plain without the optional parts", () => { + const html = renderToStaticMarkup(); + expect(html).not.toContain("scout-person__live"); + expect(html).not.toContain("scout-person__badge"); + expect(html).not.toContain("data-you"); + }); +}); + +describe("ChampionFace", () => { + test("sizes the face and names the result", () => { + const html = renderToStaticMarkup( + , + ); + expect(html).toContain('data-size="76"'); + expect(html).toContain('alt="Ahri"'); + expect(html).toContain('data-result="win"'); + expect(html).toContain("Won"); + expect(html).toContain(" { + const html = renderToStaticMarkup( + , + ); + expect(html).toContain('data-result="loss"'); + expect(html).toContain("Lost"); + expect(html).not.toContain(" { + test("mirrors art that faces away from the words", () => { + // Art at the end of a hero should look left, toward the words. + expect(isArtMirrored({ champion: "Ahri", face: "left" }, "end")).toBe( + false, + ); + expect(isArtMirrored({ champion: "Ahri", face: "right" }, "end")).toBe( + true, + ); + // Art at the start should look right. + expect(isArtMirrored({ champion: "Ahri", face: "right" }, "start")).toBe( + false, + ); + expect(isArtMirrored({ champion: "Ahri", face: "left" }, "start")).toBe( + true, + ); + }); + + test("leaves art alone without a facing, and lets mirrored override it", () => { + expect(isArtMirrored({ champion: "Ahri" }, "end")).toBe(false); + expect(isArtMirrored({ champion: "Ahri" }, "start")).toBe(false); + expect( + isArtMirrored({ champion: "Ahri", face: "left", mirrored: true }, "end"), + ).toBe(true); + expect( + isArtMirrored( + { champion: "Ahri", face: "right", mirrored: false }, + "end", + ), + ).toBe(false); + }); +}); + +describe("HeroPanel", () => { + test("puts art on the side opposite the words", () => { + const start = renderToStaticMarkup( + +

Northstar

+
, + ); + expect(start).toContain('data-align="start"'); + expect(start).toContain('data-side="end"'); + expect(start).toContain('aria-label="Northstar"'); + const end = renderToStaticMarkup( + +

Northstar

+
, + ); + expect(end).toContain('data-side="start"'); + }); + + test("applies the facing to the art", () => { + const html = renderToStaticMarkup( + +

Northstar

+
, + ); + expect(html).toContain('data-mirrored="true"'); + }); + + test("works with no art and keeps decorative art out of the accessibility tree", () => { + const plain = renderToStaticMarkup( + Find another player}> +

Northstar

+
, + ); + expect(plain).toContain('data-art="none"'); + expect(plain).not.toContain(" +

Northstar

+ , + ); + expect(withArt).toContain('alt=""'); + }); +}); + +describe("DuelHero", () => { + test("shows each champion on its own side around the verdict", () => { + const html = renderToStaticMarkup( + +

Ahri against Syndra

+
, + ); + expect(html).toContain('data-side="start" data-mirrored="true"'); + expect(html).toContain('data-side="end" data-mirrored="false"'); + expect(html).toContain("Ahri against Syndra"); + expect(html.match(/ { + test("shows the rank, LP and the secondary line", () => { + const html = renderToStaticMarkup( + , + ); + expect(html).toContain("Emerald II"); + expect(html).toContain("64 LP"); + expect(html).toContain("Platinum I, 12 LP in Flex"); + expect(html).toContain("scout-rank-lockup"); + expect(html).toContain('width="88"'); + }); + + test("leaves out LP and the secondary line when they are not given", () => { + const html = renderToStaticMarkup(); + expect(html).toContain("Challenger"); + expect(html).not.toContain("LP"); + expect(html).not.toContain("; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: { division: "II", leaguePoints: 64 }, +}; + +export const WithSecondaryLine: Story = { + args: { + division: "II", + leaguePoints: 64, + secondary: "Platinum I, 12 LP in Flex", + }, +}; + +export const Apex: Story = { + args: { + rank: "Challenger", + leaguePoints: 1284, + secondary: "Peak this split: 1,340 LP", + }, +}; + +export const WithoutLeaguePoints: Story = { + args: { rank: "Gold", division: "IV" }, +}; + +export const RankOnly: Story = { + args: { rank: "Iron" }, +}; + +export const LongSecondaryLine: Story = { + args: { + division: "II", + leaguePoints: 64, + secondary: + "Platinum I, 12 LP in Flex, and a long note that has to wrap in a narrow column", + }, + decorators: [(story) =>
{story()}
], +}; + +export const Smaller: Story = { + args: { + division: "II", + leaguePoints: 64, + size: 48, + secondary: "Platinum I, 12 LP in Flex", + }, +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/rank-lockup.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/rank-lockup.tsx new file mode 100644 index 00000000000..72f93ebf64b --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/rank-lockup.tsx @@ -0,0 +1,39 @@ +import type { ReactNode } from "react"; +import type { ScoutRank } from "#src/assets/index.tsx"; +import { cn } from "#src/lib/cn.ts"; +import { RankDisplay } from "#src/domain/rank-display.tsx"; + +export type RankLockupProps = { + rank: ScoutRank; + division?: string; + leaguePoints?: number; + /** The second line: another queue, a peak, a trend. */ + secondary?: ReactNode; + /** Crest width in pixels. */ + size?: number; + className?: string; +}; + +/** + * A crest with the rank and LP in one line and a quieter line beneath, as the + * lead of a player's hero panel. It is `RankDisplay` at hero scale. + */ +export function RankLockup({ + rank, + division, + leaguePoints, + secondary, + size = 88, + className, +}: RankLockupProps) { + return ( + + ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.stories.tsx new file mode 100644 index 00000000000..58605d175e9 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.stories.tsx @@ -0,0 +1,75 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { Panel } from "#src/components/surfaces/panel.tsx"; +import { ResultStrip, type GameResult } from "./result-strip.tsx"; + +const meta = { + title: "Domain/ResultStrip", + component: ResultStrip, + tags: ["autodocs"], + decorators: [ + (story) => {story()}, + ], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +const w: GameResult = "win"; +const l: GameResult = "loss"; + +const mixed: GameResult[] = [ + l, + w, + l, + w, + l, + w, + w, + l, + w, + l, + w, + w, + w, + l, + l, + w, + l, + w, + w, + w, +]; + +export const WinStreak: Story = { args: { results: mixed } }; + +export const LossStreak: Story = { + args: { results: [...mixed.slice(0, 15), w, w, l, l, l] }, +}; + +export const AllWins: Story = { + args: { results: Array.from({ length: 20 }, () => w) }, +}; + +export const AllLosses: Story = { + args: { results: Array.from({ length: 20 }, () => l) }, +}; + +export const NoStreak: Story = { + args: { results: [...mixed.slice(0, 19), l, w] }, +}; + +export const FewGames: Story = { args: { results: [w, l, w, w, w, l, w] } }; + +export const OneGame: Story = { args: { results: [w] } }; + +export const NoGames: Story = { args: { results: [] } }; + +export const MoreThanTwentyKeepsTheNewest: Story = { + args: { results: [...mixed, l, l, w, w] }, +}; + +export const NarrowColumn: Story = { + args: { results: mixed }, + decorators: [(story) =>
{story()}
], +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.tsx new file mode 100644 index 00000000000..ca6ab5aec80 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/result-strip.tsx @@ -0,0 +1,101 @@ +import { cn } from "#src/lib/cn.ts"; + +export type GameResult = "win" | "loss"; + +export type CurrentStreak = { result: GameResult; length: number }; + +/** + * The run of identical results at the newest end of a list ordered oldest to + * newest. A single game is a streak of one; `undefined` only for no games. + */ +export function currentStreak( + results: readonly GameResult[], +): CurrentStreak | undefined { + const newest = results.at(-1); + if (newest === undefined) return undefined; + let length = 0; + for (let index = results.length - 1; index >= 0; index -= 1) { + if (results[index] !== newest) break; + length += 1; + } + return { result: newest, length }; +} + +/** The text a screen reader gets in place of the dots. */ +export function resultStripSummary(results: readonly GameResult[]): string { + if (results.length === 0) return "No games yet."; + const streak = currentStreak(results); + const games = `${String(results.length)} ${results.length === 1 ? "game" : "games"}`; + const list = results.join(", "); + const streakText = + streak === undefined || streak.length < 2 + ? "" + : ` Current streak: ${String(streak.length)} ${streak.result === "win" ? "wins" : "losses"}.`; + return `The last ${games}, oldest first: ${list}.${streakText}`; +} + +export type ResultStripProps = { + /** Oldest first, newest last. Longer lists keep only the newest `slots`. */ + results: readonly GameResult[]; + /** How many dots the strip draws; empty slots sit at the old end. */ + slots?: number; + /** The shortest streak that gets the soft highlight. */ + minStreak?: number; + /** Replaces the generated summary. */ + label?: string; + className?: string; +}; + +/** + * Win and loss dots, oldest to newest, with the current streak softly + * highlighted. Wins are filled discs; losses are hollow rings in the loss + * colour, so the two read apart without relying on hue alone. + */ +export function ResultStrip({ + results, + slots = 20, + minStreak = 2, + label, + className, +}: ResultStripProps) { + const shown = results.slice(-slots); + const empty = Math.max(0, slots - shown.length); + const streak = currentStreak(shown); + const streakLength = + streak !== undefined && streak.length >= minStreak ? streak.length : 0; + const plain = shown.slice(0, shown.length - streakLength); + const run = shown.slice(shown.length - streakLength); + + return ( +
+ {Array.from({ length: empty }, (_, index) => ( + + ))} + {plain.map((result, index) => ( + + ))} + {streakLength === 0 || streak === undefined ? null : ( + + {run.map((result, index) => ( + + ))} + + )} +
+ ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx new file mode 100644 index 00000000000..a1003bc5a3f --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx @@ -0,0 +1,109 @@ +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { Panel } from "#src/components/surfaces/panel.tsx"; +import { ChampionFace } from "./champion-face.tsx"; +import { WinRateBar } from "./win-rate-bar.tsx"; + +const meta = { + title: "Domain/WinRateBar", + component: WinRateBar, + tags: ["autodocs"], + args: { value: 56 }, + decorators: [(story) =>
{story()}
], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = {}; + +export const You: Story = { args: { value: 65, you: true } }; + +export const WithEvenMark: Story = { args: { value: 56, even: true } }; + +export const WithoutValue: Story = { args: { value: 48, showValue: false } }; + +export const Extremes: Story = { + parameters: { controls: { disable: true } }, + render: () => ( +
+ + + +
+ ), +}; + +export const Range: Story = { + args: { + variant: "range", + value: 51.8, + even: true, + range: { low: 50.9, high: 52.7 }, + domain: [48, 56], + }, +}; + +export const RangeBelowEven: Story = { + args: { variant: "range", value: 43.1, even: true, domain: [30, 70] }, +}; + +export const RangeOffTheEdge: Story = { + args: { + variant: "range", + value: 58, + even: true, + range: { low: 56.5, high: 59.5 }, + domain: [40, 60], + }, +}; + +const friends = [ + { name: "Northstar", champion: "Ahri", rate: 65, you: true }, + { name: "RiverQuartz", champion: "Syndra", rate: 61, you: false }, + { name: "MapleCarry", champion: "Orianna", rate: 56, you: false }, + { + name: "A friend with a very long summoner name", + champion: "Jinx", + rate: 48, + you: false, + }, + { name: "Quill", champion: "Thresh", rate: 42, you: false }, +]; + +export const FriendsRanking: Story = { + parameters: { controls: { disable: true } }, + decorators: [ + (story) => {story()}, + ], + render: () => ( +
    + {friends.map((friend) => ( +
  • + + {friend.name} + +
  • + ))} +
+ ), +}; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.tsx new file mode 100644 index 00000000000..2c9505ea525 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.tsx @@ -0,0 +1,174 @@ +import type { CSSProperties } from "react"; +import { cn } from "#src/lib/cn.ts"; + +export type WinRateRange = { low: number; high: number }; + +export type WinRateBarProps = { + /** Win rate in percent, 0 to 100. */ + value: number; + /** + * `bar` fills a track from the left, as in a ranking. `range` marks the value + * with a dot on a track and can show a likely range, as on a public page. + */ + variant?: "bar" | "range"; + /** Fills the bar in the brand colour: the row that is the viewer. */ + you?: boolean; + /** Shows the number beside a `bar`. */ + showValue?: boolean; + /** Marks 50%. A `range` labels it "50%, even". */ + even?: boolean; + /** The likely range, in percent, for a `range`. */ + range?: WinRateRange; + /** The percent span a `range` track covers. Defaults to 40 to 60. */ + domain?: readonly [number, number]; + /** Replaces the generated summary. */ + label?: string; + className?: string; +}; + +/** "65", "51.8": at most one decimal, no trailing zero. */ +export function formatPercent(value: number): string { + return `${String(Number(value.toFixed(1)))}%`; +} + +function assertPercent(name: string, value: number): void { + if (!Number.isFinite(value) || value < 0 || value > 100) { + throw new RangeError( + `${name} must be a percent from 0 to 100: ${String(value)}`, + ); + } +} + +/** Where a percent sits on a track that spans `domain`, as a CSS percent. */ +export function trackPosition( + value: number, + domain: readonly [number, number], +): number { + const [min, max] = domain; + const position = ((value - min) / (max - min)) * 100; + // Three decimals keep the inline style short and free of float noise. + return Math.round(Math.min(100, Math.max(0, position)) * 1000) / 1000; +} + +function summarize(props: { + value: number; + variant: "bar" | "range"; + even: boolean; + range: WinRateRange | undefined; +}): string { + const { value, variant, even, range } = props; + if (variant === "bar") { + return `Win rate ${formatPercent(value)}.`; + } + const rangeText = + range === undefined + ? "" + : `, likely between ${formatPercent(range.low)} and ${formatPercent(range.high)}`; + const evenText = even ? " 50% is an even game." : ""; + return `${formatPercent(value)}${rangeText}.${evenText}`; +} + +function percentStyle(position: number): CSSProperties { + return { left: `${String(position)}%` }; +} + +/** A win rate as a bar or as a dot on a track. */ +export function WinRateBar({ + value, + variant = "bar", + you = false, + showValue = true, + even = false, + range, + domain = [40, 60], + label, + className, +}: WinRateBarProps) { + assertPercent("value", value); + if (range !== undefined) { + assertPercent("range.low", range.low); + assertPercent("range.high", range.high); + if (range.low > range.high) { + throw new RangeError("range.low must not exceed range.high"); + } + } + const summary = label ?? summarize({ value, variant, even, range }); + + if (variant === "bar") { + return ( + + + + {even ? ( + + {showValue ? ( + + ) : null} + + ); + } + + const evenPosition = trackPosition(50, domain); + return ( + + + {even ? ( + + 50%, even + + ) : null} + {range === undefined ? null : ( + <> + + + {formatPercent(range.low)} + + + {formatPercent(range.high)} + + + )} + + + ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/rank-display.tsx b/packages/scout-for-lol/packages/design-system/src/domain/rank-display.tsx index 36dbdb10d03..750af434824 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/rank-display.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/rank-display.tsx @@ -1,3 +1,4 @@ +import type { ReactNode } from "react"; import { RankCrest, type ScoutRank } from "#src/assets/index.tsx"; import { cn } from "#src/lib/cn.ts"; @@ -6,11 +7,18 @@ export function RankDisplay(props: { division?: string; leaguePoints?: number; compact?: boolean; + /** Crest width in pixels; overrides `compact`. */ + size?: number; + /** A further line under the rank, such as the other queue. */ + detail?: ReactNode; className?: string; }) { return ( - + {props.rank} @@ -19,6 +27,9 @@ export function RankDisplay(props: { {props.leaguePoints === undefined ? null : ( {props.leaguePoints} LP )} + {props.detail === undefined ? null : ( + {props.detail} + )} ); diff --git a/packages/scout-for-lol/packages/design-system/src/friendly-styles.test.ts b/packages/scout-for-lol/packages/design-system/src/friendly-styles.test.ts index 2a86e05400d..6834f5290d8 100644 --- a/packages/scout-for-lol/packages/design-system/src/friendly-styles.test.ts +++ b/packages/scout-for-lol/packages/design-system/src/friendly-styles.test.ts @@ -98,6 +98,9 @@ describe("friendly.css surface variables", () => { expect(declaration(css, "--scout-brand-soft")).toBe( "color-mix(in srgb, var(--scout-color-primary) 12%, var(--scout-color-surface))", ); + expect(declaration(css, "--scout-loss-soft")).toBe( + "color-mix(in srgb, var(--scout-color-danger-on-surface) 14%, var(--scout-color-surface))", + ); expect(css).not.toMatch(/#[0-9a-f]{3,8}\b/i); expect(css).not.toMatch(/\brgba?\(/); }); @@ -120,6 +123,15 @@ describe("friendly.css surface variables", () => { contrast(parse(primaryText), parse(primary)), ).toBeGreaterThanOrEqual(4.5); }); + + test(`${name} warning text is readable on every ground`, () => { + const { canvas, surface, surfaceRaised, warningOnSurface } = theme.colors; + for (const ground of [canvas, surface, surfaceRaised]) { + expect( + contrast(parse(warningOnSurface), parse(ground)), + ).toBeGreaterThanOrEqual(4.5); + } + }); } }); @@ -167,4 +179,11 @@ describe("Tailwind token mapping", () => { ); }); } + + test("the app maps warning to the text colour its call sites expect", async () => { + const css = flatten(await read(files.app)); + expect(css).toContain( + "--color-scout-warning: var(--scout-color-warning-on-surface);", + ); + }); }); diff --git a/packages/scout-for-lol/packages/design-system/src/generated/tokens.ts b/packages/scout-for-lol/packages/design-system/src/generated/tokens.ts index 97fe376e48b..afc0dd2b75f 100644 --- a/packages/scout-for-lol/packages/design-system/src/generated/tokens.ts +++ b/packages/scout-for-lol/packages/design-system/src/generated/tokens.ts @@ -21,6 +21,7 @@ export const scoutThemes = { successOnSurface: "#176B45", warning: "#8A4B00", warningText: "#FFFFFF", + warningOnSurface: "#8A4B00", danger: "#992E1E", dangerText: "#FFFFFF", dangerOnSurface: "#992E1E", @@ -76,6 +77,7 @@ export const scoutThemes = { successOnSurface: "#5FBE8C", warning: "#8A4B00", warningText: "#FFFFFF", + warningOnSurface: "#E0A24F", danger: "#A83832", dangerText: "#FFFFFF", dangerOnSurface: "#E8756B", @@ -131,6 +133,7 @@ export const scoutThemes = { successOnSurface: "#32633D", warning: "#7A4700", warningText: "#FFFFFF", + warningOnSurface: "#7A4700", danger: "#84271B", dangerText: "#FFFFFF", dangerOnSurface: "#84271B", @@ -186,6 +189,7 @@ export const scoutThemes = { successOnSurface: "#5FBE8C", warning: "#9A5C16", warningText: "#FFFFFF", + warningOnSurface: "#D9A04F", danger: "#96382A", dangerText: "#FFFFFF", dangerOnSurface: "#E8756B", diff --git a/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css b/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css new file mode 100644 index 00000000000..85dbfdf4b23 --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css @@ -0,0 +1,646 @@ +/* Domain components on the soft surfaces: faces, strips, bars, rank lockups and + the hero panels. Values follow the approved mockups (d9.css, d11*.css) and + draw colour only from the tokens and the variables in friendly.css. */ + +/* ---------- face: a round champion portrait ---------- */ + +.scout-face { + --scout-face-ground: var(--scout-color-surface); + position: relative; + display: inline-block; + flex: none; + width: var(--scout-face-size, 46px); + height: var(--scout-face-size, 46px); + border-radius: 50%; +} + +.scout-face[data-size="26"] { + --scout-face-size: 26px; +} + +.scout-face[data-size="36"] { + --scout-face-size: 36px; +} + +.scout-face[data-size="40"] { + --scout-face-size: 40px; +} + +.scout-face[data-size="46"] { + --scout-face-size: 46px; +} + +.scout-face[data-size="76"] { + --scout-face-size: 76px; +} + +.scout-face[data-size="92"] { + --scout-face-size: 92px; +} + +.scout-face__image { + display: block; + width: 100%; + height: 100%; + border-radius: 50%; + object-fit: cover; +} + +.scout-face__mark { + position: absolute; + right: -4px; + bottom: -4px; + display: grid; + width: clamp(14px, calc(var(--scout-face-size, 46px) * 0.43), 22px); + aspect-ratio: 1; + place-items: center; + border-radius: 50%; + box-shadow: 0 0 0 2.5px var(--scout-face-ground); +} + +.scout-face__mark[data-result="win"] { + background: var(--scout-color-success-on-surface); + color: var(--scout-color-surface); +} + +.scout-face__mark[data-result="loss"] { + background: var(--scout-face-ground); + box-shadow: + 0 0 0 2.5px var(--scout-face-ground), + inset 0 0 0 2px var(--scout-color-danger-on-surface); +} + +.scout-face__mark[data-result="loss"]::after { + width: 8px; + height: 2px; + border-radius: 1px; + background: var(--scout-color-danger-on-surface); + content: ""; +} + +/* ---------- person: a round initial ---------- */ + +.scout-person { + --scout-face-ground: var(--scout-color-surface); + position: relative; + display: inline-block; + flex: none; +} + +.scout-person__initial { + display: grid; + width: 46px; + height: 46px; + place-items: center; + border-radius: 50%; + background: var(--scout-surface-inset-strong); + color: var(--scout-color-text); + font: 700 20px/1 var(--scout-font-display); +} + +.scout-person[data-size="s"] .scout-person__initial { + width: 36px; + height: 36px; + font-size: 16px; +} + +.scout-person[data-size="l"] .scout-person__initial { + width: 60px; + height: 60px; + font-size: 25px; +} + +.scout-person[data-you="true"] .scout-person__initial { + background: var(--scout-color-primary); + color: var(--scout-color-primary-text); +} + +/* On the open ground the disc is a step darker than the canvas, not a panel + tint; "you" keeps its colour. */ +.scout-soft-panel--open + .scout-person:not([data-you="true"]) + .scout-person__initial { + background: color-mix( + in srgb, + var(--scout-color-text) 10%, + var(--scout-color-canvas) + ); +} + +.scout-person__live { + position: absolute; + top: -1px; + right: -1px; + width: 12px; + height: 12px; + border-radius: 50%; + background: var(--scout-color-success-on-surface); + box-shadow: 0 0 0 2.5px var(--scout-face-ground); +} + +.scout-person__badge { + position: absolute; + right: -7px; + bottom: -7px; + width: 24px; + height: 24px; + border-radius: 50%; + box-shadow: 0 0 0 2.5px var(--scout-face-ground); + object-fit: cover; +} + +.scout-person[data-size="s"] .scout-person__badge { + right: -5px; + bottom: -5px; + width: 20px; + height: 20px; +} + +@media (prefers-reduced-motion: no-preference) { + .scout-person__live::after { + position: absolute; + inset: 0; + border-radius: 50%; + animation: scout-live-pulse 1.4s ease-in-out infinite alternate; + content: ""; + } +} + +@keyframes scout-live-pulse { + from { + box-shadow: 0 0 0 1px + color-mix(in srgb, var(--scout-color-success-on-surface) 30%, transparent); + } + + to { + box-shadow: 0 0 0 5px + color-mix(in srgb, var(--scout-color-success-on-surface) 22%, transparent); + } +} + +/* ---------- result strip: the last games, oldest to newest ---------- */ + +.scout-result-strip { + display: flex; + align-items: center; + justify-content: space-between; + gap: 4px; + padding-left: 1px; +} + +.scout-result-strip__dot { + flex: none; + width: 19px; + height: 19px; + border-radius: 50%; + box-shadow: inset 0 0 0 2px + color-mix(in srgb, var(--scout-color-text-muted) 32%, transparent); +} + +.scout-result-strip__dot[data-result="win"] { + background: var(--scout-color-success-on-surface); + box-shadow: none; +} + +.scout-result-strip__dot[data-result="loss"] { + box-shadow: inset 0 0 0 2px + color-mix( + in srgb, + var(--scout-color-danger-on-surface) 58%, + var(--scout-color-surface) + ); +} + +.scout-result-strip__streak { + display: inline-flex; + gap: 8px; + margin: -7px -2px -7px 0; + padding: 7px 9px; + border-radius: var(--scout-radius-pill); + background: var(--scout-win-soft); +} + +.scout-result-strip__streak[data-result="loss"] { + background: var(--scout-loss-soft); +} + +@media (max-width: 720px) { + .scout-result-strip { + gap: 3px; + } + + .scout-result-strip__dot { + flex: 1 1 0; + width: auto; + max-width: 14px; + height: auto; + aspect-ratio: 1; + } + + .scout-result-strip__streak { + flex: 3.7 1 0; + gap: 3px; + margin: -5px -5px -5px 0; + padding: 5px; + } +} + +/* ---------- win rate: a bar, or a dot on a track ---------- */ + +.scout-win-rate[data-variant="bar"] { + display: flex; + width: 100%; + align-items: center; + gap: 14px; +} + +.scout-win-rate__track { + position: relative; + flex: 1; + height: 10px; + overflow: hidden; + border-radius: var(--scout-radius-pill); + background: var(--scout-surface-inset); +} + +.scout-win-rate[data-you="true"] .scout-win-rate__track { + background: var(--scout-color-surface); +} + +.scout-win-rate__fill { + display: block; + height: 100%; + border-radius: var(--scout-radius-pill); + background: color-mix( + in srgb, + var(--scout-color-text-muted) 58%, + var(--scout-color-surface) + ); +} + +.scout-win-rate[data-you="true"] .scout-win-rate__fill { + background: var(--scout-color-primary); +} + +.scout-win-rate[data-variant="bar"] .scout-win-rate__even { + position: absolute; + top: 0; + bottom: 0; + width: 2px; + margin-left: -1px; + background: color-mix( + in srgb, + var(--scout-color-text-muted) 60%, + transparent + ); +} + +.scout-win-rate__value { + flex: none; + width: 46px; + text-align: right; + font: 700 20px/1.3 var(--scout-font-display); +} + +.scout-win-rate[data-variant="range"] { + position: relative; + display: block; + max-width: 420px; + height: 12px; + margin: 18px 0 28px; +} + +.scout-win-rate__rail { + position: absolute; + inset: 0; + border-radius: var(--scout-radius-pill); + background: var(--scout-surface-inset); + box-shadow: var(--scout-ring); +} + +.scout-win-rate__band { + position: absolute; + top: 0; + bottom: 0; + border-radius: var(--scout-radius-pill); + background: color-mix( + in srgb, + var(--scout-color-primary) 44%, + var(--scout-color-surface) + ); +} + +.scout-win-rate__dot { + position: absolute; + top: 50%; + width: 20px; + height: 20px; + margin: -10px 0 0 -10px; + border-radius: 50%; + background: var(--scout-color-primary); + box-shadow: 0 0 0 4px var(--scout-color-surface); +} + +.scout-win-rate[data-variant="range"] .scout-win-rate__even { + position: absolute; + top: -5px; + bottom: -5px; + width: 2px; + margin-left: -1px; + border-radius: 1px; + background: color-mix( + in srgb, + var(--scout-color-text-muted) 60%, + transparent + ); +} + +.scout-win-rate[data-variant="range"] .scout-win-rate__even > span { + position: absolute; + top: 100%; + left: 50%; + margin-top: 2px; + transform: translateX(-88%); + color: var(--scout-color-text-muted); + font-size: 13px; + line-height: 1.2; + white-space: nowrap; +} + +.scout-win-rate__end { + position: absolute; + top: 100%; + margin-top: 7px; + transform: translateX(-50%); + color: var(--scout-color-text-muted); + font-size: 13px; + line-height: 1.2; + white-space: nowrap; +} + +.scout-win-rate__end[data-end="high"] { + transform: translateX(-30%); +} + +/* ---------- rank lockup: the crest, the rank and LP, a quieter line ---------- */ + +.scout-rank-lockup { + gap: 10px; +} + +.scout-rank-lockup > span { + display: block; +} + +.scout-rank-lockup strong, +.scout-rank-lockup small:not(.scout-rank-display__detail) { + color: var(--scout-color-primary); + font: 700 24px/1.25 var(--scout-font-display); +} + +.scout-rank-lockup small:not(.scout-rank-display__detail)::before { + content: ", "; +} + +.scout-rank-lockup .scout-rank-display__detail { + display: block; + color: var(--scout-color-text-muted); + font-size: 15px; + line-height: 1.5; +} + +/* ---------- hero art: a champion fading in from one edge ---------- */ + +.scout-hero-art { + position: absolute; + top: 0; + bottom: 0; + z-index: 0; + --scout-art-x: 50%; +} + +.scout-hero-art img { + display: block; + width: 100%; + height: 100%; + max-width: none; + object-fit: cover; + object-position: var(--scout-art-x) var(--scout-art-y, 50%); +} + +.scout-hero-art[data-mirrored="true"] img { + transform: scaleX(-1); +} + +/* ---------- hero panel: words on one side, art on the other ---------- */ + +.scout-hero-panel .scout-hero-art { + --scout-art-y: 22%; + --scout-art-x: 60%; +} + +.scout-hero-panel .scout-hero-art[data-side="start"][data-mirrored="false"], +.scout-hero-panel .scout-hero-art[data-side="end"][data-mirrored="true"] { + --scout-art-x: 40%; +} + +.scout-hero-panel .scout-hero-art[data-side="end"] { + left: 40%; + right: 0; + mask-image: linear-gradient( + to right, + transparent 0, + color-mix(in srgb, var(--scout-color-text) 35%, transparent) 24%, + var(--scout-color-text) 60% + ); +} + +.scout-hero-panel .scout-hero-art[data-side="start"] { + left: 0; + right: 40%; + mask-image: linear-gradient( + to left, + transparent 0, + color-mix(in srgb, var(--scout-color-text) 35%, transparent) 24%, + var(--scout-color-text) 60% + ); +} + +.scout-hero-panel__text { + box-sizing: border-box; + position: relative; + z-index: 1; + display: flex; + width: 60%; + flex-direction: column; + justify-content: center; + padding: 2.25rem 0 2.25rem 2.75rem; +} + +.scout-hero-panel[data-align="end"] .scout-hero-panel__text { + margin-left: auto; + align-items: flex-end; + padding: 2.25rem 2.75rem 2.25rem 0; + text-align: right; +} + +.scout-hero-panel__action { + position: absolute; + top: 1.375rem; + z-index: 2; +} + +.scout-hero-panel__action[data-side="end"] { + right: 1.5rem; +} + +.scout-hero-panel__action[data-side="start"] { + left: 1.5rem; +} + +.scout-hero-panel[data-art="none"] { + min-height: 0; +} + +.scout-hero-panel[data-art="none"] .scout-hero-panel__text { + width: auto; + padding: 2.125rem 2.75rem; +} + +/* ---------- duel hero: two champions facing each other ---------- */ + +.scout-duel-hero { + min-height: 20rem; +} + +.scout-duel-hero .scout-hero-art { + --scout-art-x: 25%; + width: 37%; +} + +.scout-duel-hero .scout-hero-art[data-side="start"] { + left: 0; + --scout-art-x: 78%; + mask-image: linear-gradient( + to left, + transparent 0, + color-mix(in srgb, var(--scout-color-text) 30%, transparent) 30%, + var(--scout-color-text) 78% + ); +} + +.scout-duel-hero .scout-hero-art[data-side="start"][data-mirrored="true"] { + --scout-art-x: 22%; +} + +.scout-duel-hero .scout-hero-art[data-side="end"] { + right: 0; + mask-image: linear-gradient( + to right, + transparent 0, + color-mix(in srgb, var(--scout-color-text) 30%, transparent) 30%, + var(--scout-color-text) 78% + ); +} + +.scout-duel-hero .scout-hero-art[data-side="end"][data-mirrored="true"] { + --scout-art-x: 75%; +} + +.scout-duel-hero__text { + box-sizing: border-box; + position: relative; + z-index: 1; + display: flex; + width: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 1.75rem 1.5rem 1.875rem; + text-align: center; +} + +/* ---------- narrower ---------- */ + +@media (max-width: 720px) { + .scout-hero-panel .scout-hero-art { + position: relative; + inset: auto; + width: auto; + height: 11.25rem; + --scout-art-x: 62%; + --scout-art-y: 20%; + mask-image: linear-gradient( + to bottom, + var(--scout-color-text) 50%, + transparent + ); + } + + .scout-hero-panel .scout-hero-art[data-side="start"][data-mirrored="false"], + .scout-hero-panel .scout-hero-art[data-side="end"][data-mirrored="true"] { + --scout-art-x: 38%; + } + + .scout-hero-panel__text, + .scout-hero-panel[data-align="end"] .scout-hero-panel__text { + width: auto; + margin-left: 0; + align-items: flex-start; + padding: 0 1.375rem 1.625rem; + text-align: left; + } + + .scout-hero-panel__action { + top: 0.875rem; + } + + .scout-hero-panel__action[data-side="end"] { + right: 0.875rem; + } + + .scout-hero-panel__action[data-side="start"] { + left: 0.875rem; + } + + .scout-hero-panel[data-art="none"] .scout-hero-panel__text { + padding: 4rem 1.375rem 1.5rem; + } + + .scout-duel-hero { + min-height: 0; + } + + .scout-duel-hero .scout-hero-art { + top: 0; + bottom: auto; + width: 50%; + height: 11.875rem; + --scout-art-y: 50%; + mask-image: linear-gradient( + to bottom, + var(--scout-color-text) 45%, + transparent + ); + } + + .scout-duel-hero .scout-hero-art[data-side="start"] { + --scout-art-x: 70%; + } + + .scout-duel-hero .scout-hero-art[data-side="start"][data-mirrored="true"] { + --scout-art-x: 30%; + } + + .scout-duel-hero .scout-hero-art[data-side="end"] { + --scout-art-x: 42%; + } + + .scout-duel-hero .scout-hero-art[data-side="end"][data-mirrored="true"] { + --scout-art-x: 58%; + } + + .scout-duel-hero__text { + padding: 10.75rem 1.25rem 1.625rem; + } +} diff --git a/packages/scout-for-lol/packages/design-system/styles/friendly.css b/packages/scout-for-lol/packages/design-system/styles/friendly.css index 6d2af6e2792..d62fc8739cf 100644 --- a/packages/scout-for-lol/packages/design-system/styles/friendly.css +++ b/packages/scout-for-lol/packages/design-system/styles/friendly.css @@ -38,6 +38,11 @@ var(--scout-color-success-on-surface) 17%, var(--scout-color-surface) ); + --scout-loss-soft: color-mix( + in srgb, + var(--scout-color-danger-on-surface) 14%, + var(--scout-color-surface) + ); /* A hairline ring that lifts an inset pill off its panel, and the floating shadow for panels and raised chips. */ diff --git a/packages/scout-for-lol/packages/design-system/styles/generated/tokens.css b/packages/scout-for-lol/packages/design-system/styles/generated/tokens.css index 4e4b537ab72..ff90979d75f 100644 --- a/packages/scout-for-lol/packages/design-system/styles/generated/tokens.css +++ b/packages/scout-for-lol/packages/design-system/styles/generated/tokens.css @@ -20,6 +20,7 @@ --scout-color-success-on-surface: #176b45; --scout-color-warning: #8a4b00; --scout-color-warning-text: #ffffff; + --scout-color-warning-on-surface: #8a4b00; --scout-color-danger: #992e1e; --scout-color-danger-text: #ffffff; --scout-color-danger-on-surface: #992e1e; @@ -73,6 +74,7 @@ --scout-color-success-on-surface: #5fbe8c; --scout-color-warning: #8a4b00; --scout-color-warning-text: #ffffff; + --scout-color-warning-on-surface: #e0a24f; --scout-color-danger: #a83832; --scout-color-danger-text: #ffffff; --scout-color-danger-on-surface: #e8756b; @@ -126,6 +128,7 @@ --scout-color-success-on-surface: #32633d; --scout-color-warning: #7a4700; --scout-color-warning-text: #ffffff; + --scout-color-warning-on-surface: #7a4700; --scout-color-danger: #84271b; --scout-color-danger-text: #ffffff; --scout-color-danger-on-surface: #84271b; @@ -179,6 +182,7 @@ --scout-color-success-on-surface: #5fbe8c; --scout-color-warning: #9a5c16; --scout-color-warning-text: #ffffff; + --scout-color-warning-on-surface: #d9a04f; --scout-color-danger: #96382a; --scout-color-danger-text: #ffffff; --scout-color-danger-on-surface: #e8756b; diff --git a/packages/scout-for-lol/packages/design-system/styles/index.css b/packages/scout-for-lol/packages/design-system/styles/index.css index 08bac9beff7..c34ab554a90 100644 --- a/packages/scout-for-lol/packages/design-system/styles/index.css +++ b/packages/scout-for-lol/packages/design-system/styles/index.css @@ -2,6 +2,7 @@ @import "./fonts.css"; @import "./components.css"; @import "./friendly.css"; +@import "./friendly-domain.css"; * { border-color: var(--scout-color-border); diff --git a/packages/scout-for-lol/packages/design-system/tokens/themes.json b/packages/scout-for-lol/packages/design-system/tokens/themes.json index 49b93273b95..b26f4916336 100644 --- a/packages/scout-for-lol/packages/design-system/tokens/themes.json +++ b/packages/scout-for-lol/packages/design-system/tokens/themes.json @@ -23,6 +23,7 @@ "successOnSurface": "#176B45", "warning": "#8A4B00", "warningText": "#FFFFFF", + "warningOnSurface": "#8A4B00", "danger": "#992E1E", "dangerText": "#FFFFFF", "dangerOnSurface": "#992E1E", @@ -77,6 +78,7 @@ "successOnSurface": "#5FBE8C", "warning": "#8A4B00", "warningText": "#FFFFFF", + "warningOnSurface": "#E0A24F", "danger": "#A83832", "dangerText": "#FFFFFF", "dangerOnSurface": "#E8756B", @@ -131,6 +133,7 @@ "successOnSurface": "#32633D", "warning": "#7A4700", "warningText": "#FFFFFF", + "warningOnSurface": "#7A4700", "danger": "#84271B", "dangerText": "#FFFFFF", "dangerOnSurface": "#84271B", @@ -185,6 +188,7 @@ "successOnSurface": "#5FBE8C", "warning": "#9A5C16", "warningText": "#FFFFFF", + "warningOnSurface": "#D9A04F", "danger": "#96382A", "dangerText": "#FFFFFF", "dangerOnSurface": "#E8756B", diff --git a/packages/scout-for-lol/packages/design-system/tokens/themes.schema.json b/packages/scout-for-lol/packages/design-system/tokens/themes.schema.json index cdf49966d89..a334d359c2f 100644 --- a/packages/scout-for-lol/packages/design-system/tokens/themes.schema.json +++ b/packages/scout-for-lol/packages/design-system/tokens/themes.schema.json @@ -70,6 +70,7 @@ "successOnSurface", "warning", "warningText", + "warningOnSurface", "danger", "dangerText", "dangerOnSurface", @@ -143,6 +144,9 @@ "warningText": { "$ref": "#/$defs/color" }, + "warningOnSurface": { + "$ref": "#/$defs/color" + }, "danger": { "$ref": "#/$defs/color" }, From d18276fe2bc5bb1ddf2614f8c26d77ef7bf693ba Mon Sep 17 00:00:00 2001 From: Jerred Shepherd Date: Thu, 26 Nov 2026 10:42:38 -0800 Subject: [PATCH 2/2] fix(scout-for-lol): blend the narrow duel hero art and keep names to one line in rows Why Review of the new domain components found two problems at 390 wide: the duel hero's two art halves met in a bright vertical band with the heading sitting over the bottom of the art, and a long name in a win-rate row wrapped to four lines. What - Narrow duel hero: the two champions overlap by a tenth and the end one fades in across the overlap, so the halves blend into each other and never into the panel colour. One fade into the panel runs across both, which gives the heading a clean ground. Stacking a fade on each half had left a seam at the first half's edge. - Narrow hero panel: its rules lost on specificity to the desktop side rules, so the art was offset inside its box and carried a horizontal mask. They now match the desktop specificity. - `NameText`: one line with an ellipsis, the whole name kept as text and in `title`. The win-rate ranking, faces in a feed and people beside names stories use it, with narrow and long-name variants. Verification - bun run test:e2e in the design-system package: 879 passed, every story in modern dark, modern light and classic light with axe. - 83 design-system unit tests pass, including NameText. - eslint, tsc and prettier clean for the touched files. - Stories re-captured at 390 and 1440 in modern dark and light. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_011u9pQk6p4o3DxofkiZXg8y --- .../domain/profile/champion-face.stories.tsx | 41 +++++++++++---- .../src/domain/profile/name-text.tsx | 23 +++++++++ .../domain/profile/person-initial.stories.tsx | 33 +++++++++--- .../src/domain/profile/profile.test.tsx | 18 +++++++ .../domain/profile/win-rate-bar.stories.tsx | 7 ++- .../design-system/styles/friendly-domain.css | 51 ++++++++++++++++--- 6 files changed, 147 insertions(+), 26 deletions(-) create mode 100644 packages/scout-for-lol/packages/design-system/src/domain/profile/name-text.tsx diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx index b05eb701b34..5a83a82fd12 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/champion-face.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react-vite"; +import { NameText } from "./name-text.tsx"; import { CHAMPION_FACE_SIZES, ChampionFace, @@ -28,7 +29,14 @@ export const Decorative: Story = { args: { champion: "Syndra", alt: "" }, }; -const champions = ["Ahri", "Syndra", "Jinx", "Thresh", "Nunu", "Renata"]; +const rows = [ + { key: "Ahri", name: "Ahri" }, + { key: "Syndra", name: "Syndra" }, + { key: "Jinx", name: "Jinx" }, + { key: "Thresh", name: "Thresh" }, + { key: "Nunu", name: "Nunu & Willump" }, + { key: "Renata", name: "Renata Glasc" }, +]; export const Sizes: Story = { parameters: { controls: { disable: true } }, @@ -64,33 +72,46 @@ export const SizesWithResults: Story = { ), }; -export const InAFeed: Story = { - parameters: { controls: { disable: true } }, - render: () => ( +function FeedRows(props: { maxWidth?: string }) { + return (
    - {champions.map((champion, index) => ( + {rows.map((row, index) => (
  • - - {index % 3 === 1 ? "Lost" : "Won"} as {champion} + + + {`${index % 3 === 1 ? "Lost" : "Won"} as ${row.name}, 9/2/11, +21 LP`} +
  • ))}
- ), + ); +} + +export const InAFeed: Story = { + parameters: { controls: { disable: true } }, + render: () => , +}; + +export const LongTextInANarrowFeed: Story = { + parameters: { controls: { disable: true } }, + render: () => , }; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/name-text.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/name-text.tsx new file mode 100644 index 00000000000..c9500f4070c --- /dev/null +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/name-text.tsx @@ -0,0 +1,23 @@ +import { cn } from "#src/lib/cn.ts"; + +export type NameTextProps = { + /** The full name of a person or champion. */ + children: string; + className?: string; +}; + +/** + * A name in a row: one line, cut with an ellipsis when the row is too narrow, + * so every row keeps one height. The whole name stays in the document as text + * and in `title`, so assistive technology and a hover still get it. + * + * It is a block so it can shrink inside a flex or grid row; give the row a + * track that can shrink (`minmax(0, 1fr)`, or `flex: 1; min-width: 0`). + */ +export function NameText({ children, className }: NameTextProps) { + return ( + + {children} + + ); +} diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx index 31536a2b8be..60b659892bb 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/person-initial.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react-vite"; +import { NameText } from "./name-text.tsx"; import { PersonInitial } from "./person-initial.tsx"; const meta = { @@ -70,28 +71,46 @@ export const UnusualNames: Story = { ), }; -export const BesideNames: Story = { - parameters: { controls: { disable: true } }, - render: () => ( +const people = [ + "Northstar", + "RiverQuartz", + "A friend with a very long summoner name that keeps going", +]; + +function BesideRows(props: { maxWidth: string }) { + return (
    - {["Northstar", "RiverQuartz", "MapleCarry"].map((name, index) => ( + {people.map((name, index) => (
  • - {name} + + {name} +
  • ))}
- ), + ); +} + +export const BesideNames: Story = { + parameters: { controls: { disable: true } }, + render: () => , +}; + +export const BesideLongNames: Story = { + parameters: { controls: { disable: true } }, + render: () => , }; diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx index eb0057ada3d..ddcfe5235e1 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/profile.test.tsx @@ -4,6 +4,7 @@ import { ChampionFace } from "./champion-face.tsx"; import { DuelHero } from "./duel-hero.tsx"; import { isArtMirrored } from "./hero-art.tsx"; import { HeroPanel } from "./hero-panel.tsx"; +import { NameText } from "./name-text.tsx"; import { initialOf, PersonInitial } from "./person-initial.tsx"; import { RankLockup } from "./rank-lockup.tsx"; import { @@ -345,3 +346,20 @@ describe("RankLockup", () => { expect(html).not.toContain(" { + test("keeps the whole name as text and in the title", () => { + const name = "A friend with a very long summoner name"; + const html = renderToStaticMarkup({name}); + expect(html).toContain(`title="${name}"`); + expect(html).toContain(`>${name}
`); + expect(html).toContain("scout-name"); + }); + + test("escapes the name in the title", () => { + const html = renderToStaticMarkup( + {'Nunu & "Willump"'}, + ); + expect(html).toContain('title="Nunu & "Willump""'); + }); +}); diff --git a/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx index a1003bc5a3f..900e6d7d3d6 100644 --- a/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx +++ b/packages/scout-for-lol/packages/design-system/src/domain/profile/win-rate-bar.stories.tsx @@ -1,6 +1,7 @@ import type { Meta, StoryObj } from "@storybook/react-vite"; import { Panel } from "#src/components/surfaces/panel.tsx"; import { ChampionFace } from "./champion-face.tsx"; +import { NameText } from "./name-text.tsx"; import { WinRateBar } from "./win-rate-bar.tsx"; const meta = { @@ -91,7 +92,7 @@ export const FriendsRanking: Story = { key={friend.name} style={{ display: "grid", - gridTemplateColumns: "46px minmax(0, 1fr) 11rem", + gridTemplateColumns: "46px minmax(0, 1fr) 7.5rem", alignItems: "center", gap: "0.875rem", padding: "0.4rem 0.75rem", @@ -100,7 +101,9 @@ export const FriendsRanking: Story = { }} > - {friend.name} + + {friend.name} + ))} diff --git a/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css b/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css index 85dbfdf4b23..1d1cbf16bcf 100644 --- a/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css +++ b/packages/scout-for-lol/packages/design-system/styles/friendly-domain.css @@ -78,6 +78,16 @@ content: ""; } +/* ---------- name: one line in a row, cut with an ellipsis ---------- */ + +.scout-name { + display: block; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + /* ---------- person: a round initial ---------- */ .scout-person { @@ -563,7 +573,9 @@ /* ---------- narrower ---------- */ @media (max-width: 720px) { - .scout-hero-panel .scout-hero-art { + /* [data-side] matches the specificity of the desktop side rules, which + set left, right and a horizontal mask, so these replace them. */ + .scout-hero-panel .scout-hero-art[data-side] { position: relative; inset: auto; width: auto; @@ -611,17 +623,42 @@ min-height: 0; } - .scout-duel-hero .scout-hero-art { + /* The two champions share the top edge and overlap by a tenth. The start + one is whole and sits underneath; the end one fades in across the overlap, + so each half blends into the other art, never into the panel colour. The + fade must finish inside the overlap (a tenth of the panel is 18% of one + art box), or the start art's edge shows as a seam. */ + .scout-duel-hero .scout-hero-art[data-side] { top: 0; bottom: auto; - width: 50%; - height: 11.875rem; + width: 55%; + height: 12rem; --scout-art-y: 50%; + mask-image: none; + } + + .scout-duel-hero .scout-hero-art[data-side="end"] { mask-image: linear-gradient( + to right, + transparent 0, + var(--scout-color-text) 16% + ); + } + + /* One fade into the panel across both arts, rather than a mask on each: two + faded layers stacked in the overlap would leave a seam at the start art's + edge. It also leaves the heading a clean ground below the art. */ + .scout-duel-hero::before { + position: absolute; + inset: 0 0 auto; + z-index: 1; + height: 12rem; + background: linear-gradient( to bottom, - var(--scout-color-text) 45%, - transparent + transparent 40%, + var(--scout-color-surface) ); + content: ""; } .scout-duel-hero .scout-hero-art[data-side="start"] { @@ -641,6 +678,6 @@ } .scout-duel-hero__text { - padding: 10.75rem 1.25rem 1.625rem; + padding: 11.75rem 1.25rem 1.625rem; } }