diff --git a/e2e/uiAccessibility.spec.ts b/e2e/uiAccessibility.spec.ts index 78165e65..ac2310e0 100644 --- a/e2e/uiAccessibility.spec.ts +++ b/e2e/uiAccessibility.spec.ts @@ -1,29 +1,284 @@ import { test, expect, type Page } from "@playwright/test"; import AxeBuilder from "@axe-core/playwright"; +import { openSidebar } from "./helpers/navigation"; // Automatic accessibility check with axe against WCAG 2.1 level A and AA, // the level required for the public sector in Norway. // axe only finds part of the problems, so this is combined with manual testing // (keyboard only, 200 % zoom and screen reader), see tests.md. +// +// axe has three gaps that are covered here: +// 1. It only checks text contrast (1.4.3). Contrast of borders, surfaces and +// icons (1.4.11) is checked by checkNonTextContrast below. +// 2. When it cannot find the background of a text, the result is "incomplete" +// instead of a violation. Those results now fail the test too. +// 3. It does not check placeholder text, so checkNonTextContrast does that. const WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"]; -/// Runs axe on the page and lists the violations in a readable form: the rule, -// which elements broke it, and axe's explanation (for contrast: the colours and ratio) -async function checkAccessibility(page: Page) { - const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze(); +// axe can't check text that is only symbols (✿, ✖). checkNonTextContrast +// checks those icons instead, so this incomplete result is expected. +const ICON_ONLY_MESSAGE = "contains only non-text characters"; + +// An open tooltip lies on top of the page, so axe can't find the background of +// the text under it, or of the tooltip itself. Tooltip tests therefore only run +// axe on the tooltip, and its text is checked by checkNonTextContrast. +const OVERLAP_MESSAGE = "overlap"; + +// Runs axe and the extra contrast checks on the page, and lists the problems +// in a readable form: the rule, which elements broke it, and why. +// `only` limits axe to one part of the page, used for tooltips. +async function checkAccessibility(page: Page, only?: string) { + // Both faces of a plant card are stacked on top of each other, so axe can't + // find the background of the text on the visible face. The hidden face is + // removed while axe runs. + await page.addStyleTag({ + content: + '.plant-card-face[aria-hidden="true"] { display: none !important; }', + }); + + const builder = new AxeBuilder({ page }).withTags(WCAG_TAGS); + if (only) builder.include(only); + const results = await builder.analyze(); const violations = results.violations.flatMap((v) => v.nodes.map( (node) => `${v.id}: ${node.target.join(" ")} – ${node.any[0]?.message ?? v.help}`, ), ); - expect(violations).toEqual([]); + const unchecked = results.incomplete + .filter((v) => v.id === "color-contrast") + .flatMap((v) => + v.nodes + .filter((node) => { + const message = node.any[0]?.message ?? ""; + if (message.includes(ICON_ONLY_MESSAGE)) return false; + return !(only && message.includes(OVERLAP_MESSAGE)); + }) + .map( + (node) => + `color-contrast not checked: ${node.target.join(" ")} – ${node.any[0]?.message}`, + ), + ); + + expect([ + ...violations, + ...unchecked, + ...(await checkNonTextContrast(page)), + ]).toEqual([]); +} + +// Components that must be visible against what is behind them (WCAG 1.4.11): +// the background or the border needs at least 3:1 against the background behind. +const BOUNDARY_SELECTORS = [ + '.plant-card-face[aria-hidden="false"] > .plant-card', + ".plant-card.empty-plant-card", + ".swipe-button:not(:disabled)", + ".info-button", + ".add-match-button", + ".reload-button", + ".sidebar-button", + ".plant-preferences button", + ".plant-owner-test-option", + ".sort-button", + ".pagination button:not(:disabled)", + "input", + "select", +]; + +// Buttons that only show a symbol: the symbol needs 3:1 against the button +const ICON_SELECTORS = [ + ".swipe-button:not(:disabled)", + ".info-button", + ".add-match-button", + // The SVG in the theme button, measured against the button behind it + ".theme-icon", +]; + +// Tooltip text that axe can't check while the tooltip is open: 4.5:1 against +// the tooltip background +const TOOLTIP_TEXT_SELECTORS = [ + ".match-info-box h3", + ".match-info-box p", + ".preferences-info-box", + ".add-match-tooltip", +]; + +// Checks contrast that axe does not check, using the colors the browser has +// computed. Returns one line per problem, in the same form as the axe results. +async function checkNonTextContrast(page: Page): Promise { + return page.evaluate( + ({ boundarySelectors, iconSelectors, tooltipTextSelectors }) => { + type Rgba = [number, number, number, number]; + + const parse = (value: string): Rgba | null => { + const m = value.match(/rgba?\(([^)]+)\)/); + if (!m) return null; + const [r, g, b, a = 1] = m[1].split(/[\s,/]+/).map(Number); + return [r, g, b, a]; + }; + + // Puts a (possibly see-through) color on top of a solid color + const blend = (top: Rgba, bottom: Rgba): Rgba => { + const a = top[3]; + return [ + top[0] * a + bottom[0] * (1 - a), + top[1] * a + bottom[1] * (1 - a), + top[2] * a + bottom[2] * (1 - a), + 1, + ]; + }; + + const luminance = ([r, g, b]: Rgba) => { + const lin = (c: number) => { + const s = c / 255; + return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; + }; + return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b); + }; + + const ratio = (a: Rgba, b: Rgba) => { + const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x); + return (hi + 0.05) / (lo + 0.05); + }; + + // The solid color seen behind an element: its ancestors' backgrounds + // stacked on top of each other, starting from white + const backgroundBehind = (el: Element): Rgba => { + const ancestors: Element[] = []; + for (let p = el.parentElement; p; p = p.parentElement) { + ancestors.unshift(p); + } + return ancestors.reduce( + (color, ancestor) => { + const bg = parse(getComputedStyle(ancestor).backgroundColor); + return bg && bg[3] > 0 ? blend(bg, color) : color; + }, + [255, 255, 255, 1], + ); + }; + + const isShown = (el: Element) => { + const rect = el.getBoundingClientRect(); + return ( + rect.width > 0 && + rect.height > 0 && + el.checkVisibility({ + opacityProperty: true, + visibilityProperty: true, + }) + ); + }; + + const describe = (el: Element) => + el.tagName.toLowerCase() + + (el.id ? `#${el.id}` : "") + + [...el.classList].map((c) => `.${c}`).join("") + + (el.getAttribute("aria-label") + ? `[aria-label="${el.getAttribute("aria-label")}"]` + : ""); + + const problems: string[] = []; + const seen = new Set(); + const report = (line: string) => { + if (!seen.has(line)) problems.push(line); + seen.add(line); + }; + + for (const selector of boundarySelectors) { + for (const el of document.querySelectorAll(selector)) { + if (!isShown(el)) continue; + const style = getComputedStyle(el); + const behind = backgroundBehind(el); + const bg = parse(style.backgroundColor); + const own = bg && bg[3] > 0 ? blend(bg, behind) : behind; + const border = parse(style.borderTopColor); + const hasBorder = + parseFloat(style.borderTopWidth) > 0 && + style.borderTopStyle !== "none" && + border && + border[3] > 0; + + const surface = ratio(own, behind); + const edge = hasBorder ? ratio(blend(border, behind), behind) : 0; + if (Math.max(surface, edge) < 3) { + report( + `non-text-contrast: ${describe(el)} – background ${surface.toFixed(2)}:1 and ${hasBorder ? `border ${edge.toFixed(2)}:1` : "no border"} against what is behind, needs 3:1`, + ); + } + } + } + + for (const selector of iconSelectors) { + for (const el of document.querySelectorAll(selector)) { + if (!isShown(el)) continue; + const style = getComputedStyle(el); + const behind = backgroundBehind(el); + const bg = parse(style.backgroundColor); + const own = bg && bg[3] > 0 ? blend(bg, behind) : behind; + const icon = parse(style.color); + if (!icon) continue; + const value = ratio(blend(icon, own), own); + if (value < 3) { + report( + `icon-contrast: ${describe(el)} – icon ${value.toFixed(2)}:1 against what is behind it, needs 3:1`, + ); + } + } + } + + for (const selector of tooltipTextSelectors) { + for (const el of document.querySelectorAll(selector)) { + if (!isShown(el)) continue; + const style = getComputedStyle(el); + const bg = parse(style.backgroundColor); + const behind = backgroundBehind(el); + const own = bg && bg[3] > 0 ? blend(bg, behind) : behind; + const text = parse(style.color); + if (!text) continue; + const value = ratio(blend(text, own), own); + if (value < 4.5) { + report( + `tooltip-contrast: ${describe(el)} – text ${value.toFixed(2)}:1 against the tooltip, needs 4.5:1`, + ); + } + } + } + + // Placeholder text is text, so it needs 4.5:1 against the input + for (const el of document.querySelectorAll( + "input[placeholder]", + )) { + if (!isShown(el) || el.value) continue; + const style = getComputedStyle(el); + const bg = parse(style.backgroundColor); + const own = + bg && bg[3] > 0 + ? blend(bg, backgroundBehind(el)) + : backgroundBehind(el); + const placeholder = parse(getComputedStyle(el, "::placeholder").color); + if (!placeholder) continue; + const value = ratio(blend(placeholder, own), own); + if (value < 4.5) { + report( + `placeholder-contrast: ${describe(el)} – ${value.toFixed(2)}:1 against the input, needs 4.5:1`, + ); + } + } + + return problems; + }, + { + boundarySelectors: BOUNDARY_SELECTORS, + iconSelectors: ICON_SELECTORS, + tooltipTextSelectors: TOOLTIP_TEXT_SELECTORS, + }, + ); } // Sets the theme the same way ThemeToggle does, after the page has loaded. // CSS transitions are turned off first, otherwise axe measures the colours -// halfway between the light and the dark theme. +// halfway between the light and the dark theme, or a tooltip that is fading in. async function setTheme(page: Page, theme: "light" | "dark") { await page.addStyleTag({ content: "*, *::before, *::after { transition: none !important; }", @@ -53,8 +308,7 @@ const PAGES = [ { name: "NotFound", path: "#/does-not-exist", loaded: ".not-found-page" }, ]; -// Colour contrast is the only check that differs between the themes, -// but both themes must meet the contrast requirements +// Both themes must meet the contrast requirements const THEMES = ["light", "dark"] as const; for (const theme of THEMES) { @@ -67,62 +321,142 @@ for (const theme of THEMES) { await checkAccessibility(page); }); } - }); -} -// Content that only appears after an interaction is not checked above + // Content that only appears after an interaction is not checked above -test.describe("after interaction", () => { - test("ExplorePlants with a plant card flipped", async ({ page }) => { - await page.goto("#/explorePlants"); - const firstCard = page.locator(".plant-grid > li").first(); - await firstCard.locator(".plant-card-front .plant-card-hint").click(); - await expect(firstCard.locator(".plant-card-face-back")).toHaveAttribute( - "aria-hidden", - "false", - ); - await checkAccessibility(page); - }); + test.describe("after interaction", () => { + test("ExplorePlants with a plant card flipped", async ({ page }) => { + await page.goto("#/explorePlants"); + const firstCard = page.locator(".plant-grid > li").first(); + await firstCard.locator(".plant-card-front .plant-card-hint").click(); + await expect( + firstCard.locator(".plant-card-face-back"), + ).toHaveAttribute("aria-hidden", "false"); + await setTheme(page, theme); + await checkAccessibility(page); + }); - test("Profile with the edit tab open", async ({ page }) => { - await page.goto("#/profile"); - await page - .getByRole("button", { name: /edit profile|endre profil/i }) - .click(); - await expect(page.locator("#profile-name")).toBeVisible(); - await checkAccessibility(page); - }); + test("ExplorePlants showing the add to matches tooltip", async ({ + page, + }) => { + await page.goto("#/explorePlants"); + await setTheme(page, theme); + const firstItem = page.locator(".plant-grid > li").first(); + await firstItem.locator(".add-match-button").hover(); + await expect(firstItem.locator(".add-match-tooltip")).toBeVisible(); + await checkAccessibility(page, ".add-match-tooltip"); + }); - test("MyMatches with a matched plant", async ({ page }) => { - // A new user has no matches, so add one from ExplorePlants first - await page.goto("#/explorePlants"); - const addButton = page - .locator(".plant-grid > li") - .first() - .locator(".add-match-button"); - await addButton.click(); - await expect(addButton).toHaveClass(/add-match-button--matched/); - - await page.goto("#/my-matches"); - await expect(page.locator(".plant-card-match")).toHaveCount(1); - await checkAccessibility(page); - }); + test("PlantMatch showing the how to match tooltip", async ({ page }) => { + await page.goto(""); + await expect(page.locator(".plant-card-front")).toBeVisible(); + await setTheme(page, theme); + await page.locator(".match-info-button").hover(); + await expect(page.locator(".match-info-box")).toBeVisible(); + await checkAccessibility(page, ".match-info-box"); + }); + + test("PlantMatch with no more plants", async ({ page }) => { + // The backend answers that there are no plants, so the done card shows + await page.route("**/graphql", async (route) => { + if (route.request().postDataJSON()?.operationName === "GetPlants") { + await route.fulfill({ json: { data: { getPlants: [] } } }); + } else { + await route.fallback(); + } + }); + await page.goto(""); + await expect(page.locator(".empty-plant-card")).toBeVisible(); + await expect(page.locator(".reload-button")).toBeVisible(); + await setTheme(page, theme); + await checkAccessibility(page); + }); - test("PlantOwnerTest showing a result", async ({ page }) => { - await page.goto("#/plantOwnerTest"); + test("PlantMatch when the plants can't be loaded", async ({ page }) => { + await page.route("**/graphql", async (route) => { + if (route.request().postDataJSON()?.operationName === "GetPlants") { + await route.abort(); + } else { + await route.fallback(); + } + }); + await page.goto(""); + await expect(page.locator(".empty-plant-card")).toBeVisible(); + await setTheme(page, theme); + await checkAccessibility(page); + }); - const options = page.locator(".plant-owner-test-option"); - const nextButton = page - .locator(".plant-owner-test-navigation button") - .last(); + test("Profile with the edit tab open", async ({ page }) => { + await page.goto("#/profile"); + await page + .getByRole("button", { name: /edit profile|endre profil/i }) + .click(); + await expect(page.locator("#profile-name")).toBeVisible(); + await setTheme(page, theme); + await checkAccessibility(page); + }); - // Picks the first option on all four questions, which gives "cityMinimalist" - for (let question = 0; question < 4; question++) { - await options.first().click(); - await nextButton.click(); - } + test("Profile showing the preferences tooltip", async ({ page }) => { + await page.goto("#/profile"); + await setTheme(page, theme); + await page.locator(".preferences-info-button").hover(); + await expect(page.locator(".preferences-info-box")).toBeVisible(); + await checkAccessibility(page, ".preferences-info-box"); + }); + + test("MyMatches with a matched plant", async ({ page }) => { + // A new user has no matches, so add one from ExplorePlants first + await page.goto("#/explorePlants"); + const addButton = page + .locator(".plant-grid > li") + .first() + .locator(".add-match-button"); + await addButton.click(); + await expect(addButton).toHaveClass(/add-match-button--matched/); + + await page.goto("#/my-matches"); + await expect(page.locator(".plant-card-match")).toHaveCount(1); + await setTheme(page, theme); + await checkAccessibility(page); + }); + + test("PlantOwnerTest showing a result", async ({ page }) => { + await page.goto("#/plantOwnerTest"); + + const options = page.locator(".plant-owner-test-option"); + const nextButton = page + .locator(".plant-owner-test-navigation button") + .last(); + + // Picks the first option on all four questions, which gives "cityMinimalist" + for (let question = 0; question < 4; question++) { + await options.first().click(); + await nextButton.click(); + } - await expect(page.locator(".plant-owner-test-result")).toBeVisible(); - await checkAccessibility(page); + await expect(page.locator(".plant-owner-test-result")).toBeVisible(); + await setTheme(page, theme); + await checkAccessibility(page); + }); + + test("Sidebar open, with the language and theme buttons reachable", async ({ + page, + }) => { + await page.goto(""); + await expect(page.locator(".plant-card-front")).toBeVisible(); + await setTheme(page, theme); + // Only does something on small screens, where the sidebar is a menu + await openSidebar(page); + + // The buttons at the bottom of the sidebar must be possible to scroll to + for (const button of await page + .locator(".sidebar__footer button") + .all()) { + await button.scrollIntoViewIfNeeded(); + await expect(button).toBeInViewport(); + } + await checkAccessibility(page); + }); + }); }); -}); +} diff --git a/e2e/uiMatchAndRemovePlant.spec.ts b/e2e/uiMatchAndRemovePlant.spec.ts index f7bf9bbf..c5012cca 100644 --- a/e2e/uiMatchAndRemovePlant.spec.ts +++ b/e2e/uiMatchAndRemovePlant.spec.ts @@ -122,3 +122,71 @@ test("user can sort the matches in MyMatches and move between pages", async ({ await page.reload(); await expect(matchCards.first()).toContainText("Aloe Vera"); }); + +test("PlantMatch continues from the same card after visiting another page and after a reload", async ({ + page, +}) => { + await page.goto(""); + // Scoped to PlantMatch, so the cards on Explore Plants are not matched + const cardName = page.locator( + ".plant-match .plant-card-front .plant-card-name", + ); + await expect(cardName).toBeVisible(); + + // Skip the first plant, so the deck is on the second card + const firstName = (await cardName.textContent())?.trim(); + await page.locator("button.dislike-button").click(); + await expect(cardName).not.toHaveText(firstName ?? ""); + const currentName = (await cardName.textContent())?.trim(); + + // Visit another page and come back + await openSidebar(page); + await page.locator('a[href$="/explorePlants"]').click(); + await expect(page.locator(".plant-grid > li").first()).toBeVisible(); + await openSidebar(page); + await page + .locator("#sidebar") + .getByRole("link", { name: /plant match|plante-matching/i }) + .click(); + await expect(cardName).toHaveText(currentName ?? ""); + + // sessionStorage is kept when the page is reloaded in the same tab + await page.reload(); + await expect(cardName).toHaveText(currentName ?? ""); +}); + +test("a plant matched on ExplorePlants never shows up in PlantMatch", async ({ + page, +}) => { + await page.goto("#/explorePlants"); + const firstItem = page.locator(".plant-grid > li").first(); + const matchedName = ( + await firstItem.locator(".plant-card-front .plant-card-name").textContent() + )?.trim(); + const addButton = firstItem.locator(".add-match-button"); + await addButton.click(); + await expect(addButton).toHaveClass(/add-match-button--matched/); + + await openSidebar(page); + await page + .locator("#sidebar") + .getByRole("link", { name: /plant match|plante-matching/i }) + .click(); + + // Skip through the whole deck and check every card on the way + const cardName = page.locator( + ".plant-match .plant-card-front .plant-card-name", + ); + const doneCard = page.locator(".empty-plant-card"); + const shown: string[] = []; + while (!(await doneCard.isVisible())) { + await expect(cardName.or(doneCard)).toBeVisible(); + if (await doneCard.isVisible()) break; + const name = (await cardName.textContent())?.trim() ?? ""; + shown.push(name); + await page.locator("button.dislike-button").click(); + await expect(cardName.or(doneCard)).not.toHaveText(name); + } + expect(shown.length).toBeGreaterThan(0); + expect(shown).not.toContain(matchedName); +}); diff --git a/frontend/src/App.css b/frontend/src/App.css index aed689d9..37436bcb 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -8,7 +8,6 @@ border-radius: 8px; background-color: var(--dark-green); color: var(--text-on-green); - font-family: var(--font-ui); text-decoration: none; transform: translateY(-200%); } diff --git a/frontend/src/components/matchButton/MatchButton.css b/frontend/src/components/matchButton/MatchButton.css new file mode 100644 index 00000000..bb68063e --- /dev/null +++ b/frontend/src/components/matchButton/MatchButton.css @@ -0,0 +1,77 @@ +/* The round flower button in the top right corner of a plant card, used on + Explore Plants and My Matches. The parent of the card must be position: relative. */ +.add-match { + position: absolute; + top: -15px; + right: -15px; + z-index: 2; +} + +.add-match-tooltip { + position: absolute; + top: calc(100% + 8px); + right: 0; + z-index: 20; + padding: 8px 12px; + background: var(--light-background); + color: var(--pink-text); + border-radius: 10px; + box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); + font-size: 14px; + white-space: nowrap; + opacity: 0; + visibility: hidden; + pointer-events: none; + transition: + opacity 0.15s ease, + visibility 0.15s ease; +} + +.add-match:hover .add-match-tooltip, +.add-match:focus-within .add-match-tooltip { + opacity: 1; + visibility: visible; +} + +/* A filled dark pink button with a white flower (add) or X (remove) */ +.add-match-button { + width: 50px; + height: 50px; + display: flex; + align-items: center; + justify-content: center; + border: 2px solid var(--dark-pink); + border-radius: 50%; + background-color: var(--dark-pink); + color: var(--text-light); + font-size: 18px; + line-height: 1; + cursor: pointer; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); +} + +/* In dark mode the dark pink border is too close to the dark pink results box + behind the button (2.6:1), so the border and focus ring are white */ +[data-theme="dark"] .add-match-button { + border-color: var(--text-light); +} + +[data-theme="dark"] .add-match-button:focus-visible { + box-shadow: 0 0 0 3px var(--text-light); +} + +.add-match-button:hover { + transform: scale(1.1); +} + +.add-match-button:focus-visible { + outline: none; + box-shadow: 0 0 0 3px var(--dark-pink); +} + +@media (max-width: 767px) { + .add-match-button { + width: 35px; + height: 35px; + } +} diff --git a/frontend/src/components/matchButton/MatchButton.tsx b/frontend/src/components/matchButton/MatchButton.tsx new file mode 100644 index 00000000..2bf563b2 --- /dev/null +++ b/frontend/src/components/matchButton/MatchButton.tsx @@ -0,0 +1,43 @@ +import "./MatchButton.css"; + +type Props = { + isMatched: boolean; + // Says what the button does, shown as a tooltip and read by screen readers + label: string; + onClick: () => void; + className?: string; +}; + +// The round button on a plant card that adds the plant to My Matches (✿), or +// removes it if it is already there (✖). It looks the same on every page. +// Placed next to the card, not inside it, so there are no nested buttons. +export default function MatchButton({ + isMatched, + label, + onClick, + className, +}: Props) { + const classes = [ + "add-match-button", + isMatched && "add-match-button--matched", + className, + ] + .filter(Boolean) + .join(" "); + + return ( + + + + + ); +} diff --git a/frontend/src/components/pagination/Pagination.css b/frontend/src/components/pagination/Pagination.css index f324bb5f..90977b77 100644 --- a/frontend/src/components/pagination/Pagination.css +++ b/frontend/src/components/pagination/Pagination.css @@ -24,7 +24,6 @@ border-radius: 8px; background-color: var(--light-green); color: var(--text-dark); - font-family: var(--font-ui); font-size: 1rem; cursor: pointer; } diff --git a/frontend/src/components/plantCard/PlantCard.css b/frontend/src/components/plantCard/PlantCard.css index 9878818a..0407c3f5 100644 --- a/frontend/src/components/plantCard/PlantCard.css +++ b/frontend/src/components/plantCard/PlantCard.css @@ -92,8 +92,16 @@ border-radius: 32px; overflow: hidden; +} + +/* The back of the card is too close to the page color in dark mode, so it gets + a light green border to show where it ends */ +[data-theme="dark"] .plant-card-back { + border: 2px solid var(--dark-green); +} - font-family: var(--font-card); +.plant-card-front { + background: var(--card-front); } .plant-card-face > .plant-card { @@ -116,8 +124,13 @@ height: var(--card-fold); --flap-fill: var(--card-flap); + /* Same as the fill unless a face sets its own border color */ + --flap-border: var(--flap-fill); + --flap-border-width: 2px; - background: var(--flap-fill); + /* The triangle is drawn in the border color, and a smaller triangle in the + fill color on top. A normal border would not follow the diagonal edge. */ + background: var(--flap-border); clip-path: polygon(0 0, 100% 0, 0 100%); pointer-events: none; @@ -127,6 +140,25 @@ height 0.2s ease; } +.plant-card-flap::after { + /* The diagonal edge is moved in by the border width times sqrt(2) */ + --flap-inset: calc(var(--flap-border-width) * 2.414); + + content: ""; + position: absolute; + inset: 0; + background: var(--flap-fill); + clip-path: polygon( + var(--flap-border-width) var(--flap-border-width), + calc(100% - var(--flap-inset)) var(--flap-border-width), + var(--flap-border-width) calc(100% - var(--flap-inset)) + ); +} + +.plant-card-face-front .plant-card-flap { + --flap-border: var(--soft-green); +} + @media (prefers-reduced-motion: reduce) { .plant-card-flipper, .plant-card-face, @@ -163,7 +195,9 @@ flex: none; height: var(--card-name-height); - padding: 5px 40px; + /* Room on both sides for the round button in the top right corner of the + card, so a long name is not hidden under it */ + padding: 5px 48px; display: flex; align-items: center; @@ -229,14 +263,25 @@ margin: auto 0 0; padding: 18px var(--card-hint-space) 32px 20px; - color: var(--dark-green); + color: var(--card-hint); - font-size: 1rem; + /* The same size as on the compact cards on Explore Plants + (1.125rem at 80 % zoom) */ + font-size: 0.9rem; font-weight: 600; line-height: 1.3; text-align: center; } +/* Always room for two lines, so the card does not move when the text gets + shorter or longer, for example when the language is changed */ +.plant-card-hint-text { + display: flex; + align-items: center; + justify-content: center; + min-height: calc(2 * 1.3em); +} + .plant-card-hint:focus { outline: none; } @@ -247,7 +292,7 @@ } .plant-card-face-back .plant-card-flap { - --flap-fill: var(--light-green); + --flap-fill: var(--cream); } .plant-card-back .plant-card-hint, @@ -259,7 +304,8 @@ .plant-card-back-header { flex: none; - padding: 20px 28px 16px; + /* Room on both sides for the round button in the top right corner */ + padding: 20px 48px 16px; background: var(--dark-green); color: var(--text-on-green); @@ -377,7 +423,7 @@ .plant-card-front .plant-card-name { height: auto; min-height: var(--card-name-height); - padding: 10px 16px; + padding: 10px 24px; font-size: clamp(1.05rem, 6.5cqw, 1.25rem); overflow-wrap: anywhere; } @@ -393,7 +439,7 @@ } .plant-card-back-header { - padding: 16px 16px 12px; + padding: 16px 24px 12px; } .plant-card-back .plant-card-name { diff --git a/frontend/src/components/plantCard/PlantCard.tsx b/frontend/src/components/plantCard/PlantCard.tsx index f4e1d926..1a506d71 100644 --- a/frontend/src/components/plantCard/PlantCard.tsx +++ b/frontend/src/components/plantCard/PlantCard.tsx @@ -98,7 +98,9 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) { className="plant-card-hint" aria-expanded={false} > - {t("plantCard.tapForDetails")} + + {t("plantCard.tapForDetails")} +