From f56d66570f62ca49634edfef97dbc47221fafe75 Mon Sep 17 00:00:00 2001 From: ninaflaaten Date: Fri, 6 Nov 2026 15:16:36 +0100 Subject: [PATCH 1/7] Update plantcard design for better readability --- .../src/components/plantCard/PlantCard.css | 368 +++++++++--------- .../src/components/plantCard/PlantCard.tsx | 181 +++++---- frontend/src/i18n/locales/en/translation.json | 9 +- frontend/src/i18n/locales/no/translation.json | 9 +- .../src/pages/explorePlants/ExplorePlants.css | 5 - .../src/pages/myMatches/MyMatchesPage.css | 10 +- .../src/pages/plantMatch/PlantMatchPage.css | 4 +- frontend/src/tests/PlantCard.test.tsx | 29 +- 8 files changed, 319 insertions(+), 296 deletions(-) diff --git a/frontend/src/components/plantCard/PlantCard.css b/frontend/src/components/plantCard/PlantCard.css index 0a177f6b..51b3f7d6 100644 --- a/frontend/src/components/plantCard/PlantCard.css +++ b/frontend/src/components/plantCard/PlantCard.css @@ -1,12 +1,48 @@ .plant-card-flipper { --card-name-height: clamp(100px, 8vh, 86px); - --card-image-height: 270px; + --card-fold: 64px; + --card-flap-color: #5e7f5b; + --card-hint-space: 60px; + --card-border-width: 2px; + position: relative; width: 100%; height: 100%; + + filter: drop-shadow(0 6px 14px rgba(30, 50, 35, 0.22)); } -.plant-card-flipper .plant-card { +.plant-card-flip-target { + position: absolute; + inset: 0; + + border-radius: 32px; + + cursor: pointer; + -webkit-tap-highlight-color: transparent; +} + +.plant-card-flip-target:focus { + outline: none; +} + +.plant-card-flip-target:focus-visible { + outline: 3px solid var(--dark-green); + outline-offset: 4px; +} + +.plant-card-flip-target:focus-visible { + --card-fold: 80px; +} + +@media (hover: hover) { + .plant-card-flip-target:hover { + --card-fold: 80px; + } +} + + +.plant-card-face { position: absolute; inset: 0; @@ -16,24 +52,18 @@ transition: transform 0.6s ease; } -.plant-card-back { +.plant-card-face-back { transform: rotateY(180deg); } -.plant-card-flipper.is-flipped .plant-card-front { +.plant-card-flipper.is-flipped .plant-card-face-front { transform: rotateY(-180deg); } -.plant-card-flipper.is-flipped .plant-card-back { +.plant-card-flipper.is-flipped .plant-card-face-back { transform: rotateY(0deg); } -@media (prefers-reduced-motion: reduce) { - .plant-card-flipper .plant-card { - transition: none; - } -} - .plant-card { box-sizing: border-box; @@ -45,7 +75,7 @@ background: var(--light-green); - border: none; + border: var(--card-border-width) solid var(--dark-green); border-radius: 32px; overflow: hidden; @@ -53,81 +83,103 @@ font-family: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif; } -.plant-card-bookmark { - display: none; +.plant-card-face > .plant-card { + clip-path: polygon( + 0 0, + 100% 0, + 100% calc(100% - var(--card-fold)), + calc(100% - var(--card-fold)) 100%, + 0 100% + ); + transition: clip-path 0.2s ease; } -.plant-card-front { - position: relative; - padding: 0; - height: 100%; -} +.plant-card-flap { + position: absolute; + right: 0; + bottom: 0; -.plant-card-front .plant-card-panel { - flex: none; + width: var(--card-fold); + height: var(--card-fold); - width: 100%; - padding: 0; + --flap-fill: var(--card-flap-color); - display: flex; - flex-direction: column; - gap: 0; - background: transparent; + background: linear-gradient( + to bottom right, + var(--flap-fill) calc(50% - var(--card-border-width)), + var(--dark-green) calc(50% - var(--card-border-width)) + ); + clip-path: polygon(0 0, 100% 0, 0 100%); - border-radius: 0; + pointer-events: none; - overflow: hidden; + transition: + width 0.2s ease, + height 0.2s ease; +} + +@media (prefers-reduced-motion: reduce) { + .plant-card-face, + .plant-card-face > .plant-card, + .plant-card-flap { + transition: none; + } } .plant-card-name { box-sizing: border-box; width: 100%; + margin: 0; + + color: var(--light-green); + + font-weight: 700; + line-height: 1.1; + text-align: center; +} + +.plant-card-front .plant-card-panel { + flex: 1 1 auto; + min-height: 0; + + width: 100%; + + display: flex; + flex-direction: column; +} + +.plant-card-front .plant-card-name { + flex: none; height: var(--card-name-height); - margin: 0; padding: 5px 40px; display: flex; align-items: center; justify-content: center; - color: var(--dark-green); + background: var(--dark-green); font-size: 1.5rem; - font-weight: 700; - line-height: 1.1; - text-align: center; overflow: hidden; } -.plant-card-front .plant-card-name { - background: var(--dark-green); - color: var(--light-green); -} - .plant-card-image { display: block; width: 100%; - height: var(--card-image-height); - - flex: none; + flex: 1 1 0; + min-height: 0; object-fit: cover; - - border-radius: 0; } .plant-card-image-missing { position: relative; - width: 100%; - height: var(--card-image-height); - flex: none; overflow: hidden; - border-radius: 0; } .plant-card-image-missing::before { @@ -137,45 +189,6 @@ background: url("/plant-placeholder.png") center / cover no-repeat; } -.plant-card-info-button { - flex: none; - align-self: center; - width: 95%; - height: 60px; - margin-top: 18px; - padding: 0 24px; - display: flex; - align-items: center; - justify-content: center; - gap: 14px; - background: var(--dark-green); - color: var(--text-on-green); - border: none; - border-radius: 999px; - font-family: inherit; - font-size: 1.25rem; - font-weight: 700; - cursor: pointer; - transition: - transform 0.2s ease, - background-color 0.2s ease; -} - -.plant-card-info-button:hover { - background: var(--accent-green-hover); - transform: translateY(-2px); -} - -.plant-card-info-arrow { - display: flex; - align-items: center; - justify-content: center; - - font-size: 1.8rem; - font-weight: 400; - line-height: 1; -} - .plant-card-front .plant-card-preferences { flex: none; @@ -183,7 +196,7 @@ box-sizing: border-box; margin: 0; - padding: 14px 18px 18px; + padding: 14px 18px 4px; display: flex; flex-wrap: wrap; @@ -192,78 +205,97 @@ align-content: flex-start; gap: 8px; - - overflow: visible; -} - -.plant-card-back { - background: var(--light-green); } -.plant-card-back .plant-card-panel { - box-sizing: border-box; +.plant-card-hint { flex: none; - height: calc(var(--card-name-height) + var(--card-image-height)); - min-height: 0; - padding: 20px; + margin: auto 0 0; + padding: 12px var(--card-hint-space) 26px 20px; - display: flex; - flex-direction: column; - align-items: stretch; + color: var(--dark-green); - gap: 12px; + font-size: 1rem; + font-weight: 600; + line-height: 1.3; +} - background: var(--dark-green); - color: var(--light-green); - border-radius: 20px 20px 0 0; +.plant-card-back { + background: var(--card-flap-color); + color: var(--text-light); +} - overflow-y: auto; +.plant-card-face-back .plant-card-flap { + --flap-fill: var(--light-green); } -.plant-card-details:focus-visible { - outline: 3px solid var(--light-green); - outline-offset: -6px; +.plant-card-back .plant-card-hint, +.plant-card-back .plant-card-details, +.plant-card-back .plant-card-facts dt { + color: var(--text-light); } -.plant-card-back .plant-card-name { - height: auto; - min-height: 62px; +.plant-card-back-header { + flex: none; - padding: 0 24px; + padding: 20px 28px 16px; + background: var(--dark-green); color: var(--light-green); +} - font-size: 1.7rem; +.plant-card-back .plant-card-name { + font-size: 1.6rem; + overflow-wrap: anywhere; } .plant-card-scientific { - margin: -4px 0 6px; - - color: var(--light-green); + margin: 6px 0 0; font-size: 1rem; font-style: italic; text-align: center; + overflow-wrap: anywhere; +} + +.plant-card-details { + flex: 1 1 auto; + min-height: 0; + + padding: 18px 22px 4px; + + overflow-y: auto; + overscroll-behavior: contain; + + color: var(--text-dark); +} + +.plant-card-description { + margin: 0 0 16px; + + font-size: 18px; + line-height: 1.65; } .plant-card-facts { - margin: 5px 0 10px; + margin: 0; display: grid; grid-template-columns: auto 1fr; - column-gap: 14px; - row-gap: 7px; + row-gap: 4px; - color: var(--light-green); + font-size: 16px; + line-height: 1.45; +} - font-size: 0.95rem; - line-height: 1.25; +.plant-card-facts > div { + display: contents; } .plant-card-facts dt { + color: var(--dark-green); font-weight: 700; } @@ -271,90 +303,36 @@ margin: 0; } -.plant-card-description { - color: var(--light-green); - font-size: 0.9rem; - line-height: 1.4; - margin-bottom: 40px; -} - @media (max-width: 767px) { .plant-card-flipper { --card-name-height: 68px; - --card-image-height: 175px; } - .plant-card { + .plant-card, + .plant-card-flip-target { border-radius: 24px; } - .plant-card-name { - height: var(--card-name-height); - + .plant-card-front .plant-card-name { padding: 10px 16px; - font-size: 1.25rem; } - /* The card has a fixed height, so the image only gets the space left - after the name, button and preferences. Otherwise a tall image pushes - the preferences out of the card. */ - .plant-card-front .plant-card-panel { - flex: 1 1 auto; - min-height: 0; - } - - .plant-card-front .plant-card-name { - flex: none; - } - - .plant-card-front .plant-card-image, - .plant-card-front .plant-card-image-missing { - width: 100%; - height: auto; - flex: 1 1 0; - min-height: 0; - object-fit: cover; - } - - .plant-card-info-button { - width: 82%; - height: 44px; - - margin-top: 12px; - - padding: 0 16px; - - gap: 9px; - - font-size: 1rem; - } - - .plant-card-info-arrow { - font-size: 1.4rem; - } - .plant-card-front .plant-card-preferences { - padding: 12px 12px 14px; - + padding: 12px 12px 4px; gap: 6px; } - .plant-card-back { - padding: 0; + .plant-card-hint { + padding: 10px var(--card-hint-space) 20px 14px; + font-size: 0.9rem; } - .plant-card-back .plant-card-panel { - padding: 14px; - - gap: 8px; - - border-radius: 18px; + .plant-card-back-header { + padding: 16px 16px 12px; } .plant-card-back .plant-card-name { - min-height: 45px; - font-size: 1.3rem; } @@ -362,15 +340,17 @@ font-size: 0.85rem; } - .plant-card-facts { - font-size: 0.8rem; - - column-gap: 8px; - row-gap: 4px; + .plant-card-details { + padding: 14px 14px 4px; } .plant-card-description { - font-size: 0.78rem; - line-height: 1.3; + font-size: 17px; + line-height: 1.6; + } + + .plant-card-facts { + font-size: 15px; + column-gap: 10px; } } diff --git a/frontend/src/components/plantCard/PlantCard.tsx b/frontend/src/components/plantCard/PlantCard.tsx index b40bac11..461bb6b8 100644 --- a/frontend/src/components/plantCard/PlantCard.tsx +++ b/frontend/src/components/plantCard/PlantCard.tsx @@ -1,4 +1,5 @@ -import { useState } from "react"; +import { useId, useRef, useState } from "react"; +import type { KeyboardEvent } from "react"; import { useTranslation } from "react-i18next"; import "./PlantCard.css"; import PlantPreferenceChips from "../PlantPreferenceChips/PlantPreferenceChips"; @@ -25,94 +26,124 @@ export default function PlantCard({ onInfo, }: Props) { const { t } = useTranslation(); + const detailsId = useId(); + const detailsRef = useRef(null); const [isFlipped, setIsFlipped] = useState(false); - function handleInfoClick() { - setIsFlipped(!isFlipped); + function flip() { + setIsFlipped((flipped) => !flipped); onInfo?.(); } + function handleKeyDown(event: KeyboardEvent) { + if (event.key === "Enter" || event.key === " ") { + event.preventDefault(); + flip(); + return; + } + + if (isFlipped && (event.key === "ArrowDown" || event.key === "ArrowUp")) { + event.preventDefault(); + detailsRef.current?.scrollBy({ + top: event.key === "ArrowDown" ? 40 : -40, + }); + } + } + + const plantName = name ?? ""; + const label = isFlipped + ? t("plantCard.backLabel", { name: plantName }) + : t("plantCard.frontLabel", { name: plantName }); + return (
-
- - -
-

{name}

- - {imageURL ? ( - {name - ) : ( -
- )} +
+
+

{name}

+ + {imageURL ? ( + {plantName} + ) : ( +
+ )} +
+ + + +

{t("plantCard.tapForDetails")}

+
+
- - - -
- -
-

{name}

- - {scientificName && scientificName.length > 0 && ( -

{scientificName.join(", ")}

- )} - -
-
{t("plantCard.watering")}
-
{watering ?? t("plantCard.unknown")}
- -
{t("plantCard.sunlight")}
-
- {sunlight && sunlight.length > 0 - ? sunlight.join(", ") - : t("plantCard.unknown")} -
- -
{t("plantCard.careLevel")}
-
{careLevel ?? t("plantCard.unknown")}
-
- - {description && ( -

{description}

- )} +
+
+

{name}

+ + {scientificName && scientificName.length > 0 && ( +

+ {scientificName.join(", ")} +

+ )} +
+ +
+ {description && ( +

{description}

+ )} + +
+
+
{t("plantCard.watering")}
+
{watering ?? t("plantCard.unknown")}
+
+ +
+
{t("plantCard.sunlight")}
+
+ {sunlight && sunlight.length > 0 + ? sunlight.join(", ") + : t("plantCard.unknown")} +
+
+ +
+
{t("plantCard.careLevel")}
+
{careLevel ?? t("plantCard.unknown")}
+
+
+
+ +

{t("plantCard.tapToFlipBack")}

+
+
- - -
+
); } diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 6d468c2e..b3d76bc1 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -101,13 +101,14 @@ "plantCard": { "preferences": "Plant preferences", "matchesPreferences": "Matches your saved preferences", - "information": "Information", - "save": "Save plant", - "back": "Back", "watering": "Watering", "sunlight": "Sunlight", "careLevel": "Care level", - "unknown": "Unknown" + "unknown": "Unknown", + "tapForDetails": "Tap the card for details", + "tapToFlipBack": "Tap to flip back", + "frontLabel": "{{name}}. Tap to see details", + "backLabel": "{{name}}, details. Tap to flip back" }, "plantQuiz": { "title": "What kind of plant owner are you?", diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json index ab65d1a8..208c4c10 100644 --- a/frontend/src/i18n/locales/no/translation.json +++ b/frontend/src/i18n/locales/no/translation.json @@ -101,13 +101,14 @@ "plantCard": { "preferences": "Plantepreferanser", "matchesPreferences": "Matcher dine lagrede preferanser", - "information": "Informasjon", - "save": "Lagre plante", - "back": "Tilbake", "watering": "Vanning", "sunlight": "Sollys", "careLevel": "Stell", - "unknown": "Ukjent" + "unknown": "Ukjent", + "tapForDetails": "Trykk på kortet for detaljer", + "tapToFlipBack": "Trykk for å snu tilbake", + "frontLabel": "{{name}}. Trykk for å se detaljer", + "backLabel": "{{name}}, detaljer. Trykk for å snu tilbake" }, "plantQuiz": { "title": "Hvilken type planteeier er du?", diff --git a/frontend/src/pages/explorePlants/ExplorePlants.css b/frontend/src/pages/explorePlants/ExplorePlants.css index 36b86fe7..0f6f5a32 100644 --- a/frontend/src/pages/explorePlants/ExplorePlants.css +++ b/frontend/src/pages/explorePlants/ExplorePlants.css @@ -159,11 +159,6 @@ transform-origin: top left; } -/* Sets the card apart from the pink background */ -.explore-plant-item .plant-card { - border: 3px solid var(--dark-green); -} - .pagination { display: flex; flex-wrap: wrap; diff --git a/frontend/src/pages/myMatches/MyMatchesPage.css b/frontend/src/pages/myMatches/MyMatchesPage.css index 4763642f..fc555145 100644 --- a/frontend/src/pages/myMatches/MyMatchesPage.css +++ b/frontend/src/pages/myMatches/MyMatchesPage.css @@ -46,16 +46,10 @@ width: calc(390px * var(--card-scale)); height: calc(620px * var(--card-scale)); + /* The card draws its own shadow that follows the folded corner */ border-radius: 32px; - box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1); - transition: - transform 0.2s ease, - box-shadow 0.2s ease; -} - -.plant-card-match:hover { - box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14); + transition: transform 0.2s ease; } .plant-card-match .plant-card-flipper { diff --git a/frontend/src/pages/plantMatch/PlantMatchPage.css b/frontend/src/pages/plantMatch/PlantMatchPage.css index 3287c977..0408f4d8 100644 --- a/frontend/src/pages/plantMatch/PlantMatchPage.css +++ b/frontend/src/pages/plantMatch/PlantMatchPage.css @@ -21,7 +21,7 @@ .plant-card-container { position: relative; width: 310px; - height: 550px; + height: 510px; display: flex; justify-content: center; align-items: center; @@ -195,7 +195,7 @@ .plant-card-container { width: min(280px, 62vw); - height: 550px; + height: 510px; flex: 0 0 auto; } diff --git a/frontend/src/tests/PlantCard.test.tsx b/frontend/src/tests/PlantCard.test.tsx index 75b957da..026201e4 100644 --- a/frontend/src/tests/PlantCard.test.tsx +++ b/frontend/src/tests/PlantCard.test.tsx @@ -6,7 +6,10 @@ import PlantCard from "../components/plantCard/PlantCard"; const { useUser } = vi.hoisted(() => ({ useUser: vi.fn() })); vi.mock("../context/UserContext", () => ({ useUser })); vi.mock("react-i18next", () => ({ - useTranslation: () => ({ t: (key: string) => key }), + useTranslation: () => ({ + t: (key: string, options?: { name?: string }) => + options?.name ? `${key}:${options.name}` : key, + }), })); useUser.mockReturnValue({ userId: null, user: null, loading: false }); @@ -18,7 +21,7 @@ const chips = () => ); describe("PlantCard", () => { - it("shows the full plant on the back after clicking information", async () => { + it("flips to the details when the card is clicked, and back again", async () => { const user = userEvent.setup(); const onInfo = vi.fn(); const { container } = render( @@ -40,7 +43,7 @@ describe("PlantCard", () => { ); await user.click( - screen.getByRole("button", { name: "plantCard.information" }), + screen.getByRole("button", { name: "plantCard.frontLabel:Orchid" }), ); expect(onInfo).toHaveBeenCalledTimes(1); @@ -49,8 +52,26 @@ describe("PlantCard", () => { expect(screen.getByText("A flowering plant")).toBeInTheDocument(); expect(screen.getByText("Full sun, Part shade")).toBeInTheDocument(); - await user.click(screen.getByRole("button", { name: "plantCard.back" })); + await user.click( + screen.getByRole("button", { name: "plantCard.backLabel:Orchid" }), + ); + + expect(container.firstChild).not.toHaveClass("is-flipped"); + }); + + it("flips with Enter and Space from the keyboard", async () => { + const user = userEvent.setup(); + const { container } = render(); + + await user.tab(); + expect( + screen.getByRole("button", { name: "plantCard.frontLabel:Fern" }), + ).toHaveFocus(); + + await user.keyboard("{Enter}"); + expect(container.firstChild).toHaveClass("is-flipped"); + await user.keyboard(" "); expect(container.firstChild).not.toHaveClass("is-flipped"); }); From 5295769b8136fab9570a36e8913028cbc24fee98 Mon Sep 17 00:00:00 2001 From: ninaflaaten Date: Fri, 6 Nov 2026 15:27:42 +0100 Subject: [PATCH 2/7] Icrease readibility, remove * from plant names --- backend/src/resolvers.ts | 3 +- .../src/components/plantCard/PlantCard.css | 51 ++++++++++++++++--- .../src/components/plantCard/PlantCard.tsx | 46 +++++++++-------- .../src/pages/explorePlants/ExplorePlants.css | 23 +-------- .../src/pages/explorePlants/ExplorePlants.tsx | 10 +--- .../src/pages/myMatches/MyMatchesPage.css | 42 +-------------- .../src/pages/myMatches/MyMatchesPage.tsx | 10 +--- .../src/pages/plantMatch/PlantMatchPage.css | 6 +-- .../src/pages/plantMatch/PlantMatchPage.tsx | 11 +--- frontend/src/tests/ExplorePage.test.tsx | 4 +- frontend/src/tests/PlantCard.test.tsx | 51 ++++++++++++++----- 11 files changed, 116 insertions(+), 141 deletions(-) diff --git a/backend/src/resolvers.ts b/backend/src/resolvers.ts index 2a9c06e6..8adb4696 100644 --- a/backend/src/resolvers.ts +++ b/backend/src/resolvers.ts @@ -58,7 +58,8 @@ const users = db.collection("users"); const toPlant = (doc: WithId): Plant => ({ id: doc._id.toString(), - name: doc.commonName, + // Some names from Perenual have a "*", which should not be shown + name: doc.commonName.replace(/\*/g, "").replace(/\s+/g, " ").trim(), imageURL: doc.imageData ?? doc.imageURL ?? null, scientificName: doc.scientificName, description: doc.description, diff --git a/frontend/src/components/plantCard/PlantCard.css b/frontend/src/components/plantCard/PlantCard.css index 51b3f7d6..b30c7953 100644 --- a/frontend/src/components/plantCard/PlantCard.css +++ b/frontend/src/components/plantCard/PlantCard.css @@ -1,3 +1,13 @@ +:root { + /* Card size, also used by pages that place things next to the card */ + --plant-card-width: 310px; + --plant-card-height: 510px; + + /* Compact cards (grids) keep the layout of a 390x620 card, drawn at 80 % */ + --plant-card-compact-scale: 0.8; + --plant-card-compact-width: calc(390px * var(--plant-card-compact-scale)); +} + .plant-card-flipper { --card-name-height: clamp(100px, 8vh, 86px); --card-fold: 64px; @@ -6,8 +16,8 @@ --card-border-width: 2px; position: relative; - width: 100%; - height: 100%; + width: var(--plant-card-width); + height: var(--plant-card-height); filter: drop-shadow(0 6px 14px rgba(30, 50, 35, 0.22)); } @@ -41,7 +51,6 @@ } } - .plant-card-face { position: absolute; inset: 0; @@ -104,7 +113,6 @@ --flap-fill: var(--card-flap-color); - background: linear-gradient( to bottom right, var(--flap-fill) calc(50% - var(--card-border-width)), @@ -220,7 +228,6 @@ line-height: 1.3; } - .plant-card-back { background: var(--card-flap-color); color: var(--text-light); @@ -272,14 +279,15 @@ } .plant-card-description { - margin: 0 0 16px; + margin: 0; font-size: 18px; line-height: 1.65; } .plant-card-facts { - margin: 0; + /* Facts first, then the description below */ + margin: 0 0 16px; display: grid; grid-template-columns: auto 1fr; @@ -303,11 +311,40 @@ margin: 0; } +/* zoom (not transform: scale) so the card also takes up less room in the layout */ +.plant-card-flipper.is-compact { + --plant-card-width: 390px; + --plant-card-height: 620px; + zoom: var(--plant-card-compact-scale); +} + +/* The zoom also shrinks the small texts, so they are made a bit bigger + here to stay readable (about 13px and 14px on screen) */ +@media (min-width: 768px) { + .plant-card-flipper.is-compact .plant-preference-chip { + font-size: 16px; + } + + .plant-card-flipper.is-compact .plant-card-hint { + font-size: 1.125rem; + } +} + @media (max-width: 767px) { + :root { + --plant-card-width: min(280px, 62vw); + } + .plant-card-flipper { --card-name-height: 68px; } + .plant-card-flipper.is-compact { + --plant-card-width: min(280px, 62vw); + --plant-card-height: 502px; + zoom: 1; + } + .plant-card, .plant-card-flip-target { border-radius: 24px; diff --git a/frontend/src/components/plantCard/PlantCard.tsx b/frontend/src/components/plantCard/PlantCard.tsx index 461bb6b8..416bf5ba 100644 --- a/frontend/src/components/plantCard/PlantCard.tsx +++ b/frontend/src/components/plantCard/PlantCard.tsx @@ -3,28 +3,28 @@ import type { KeyboardEvent } from "react"; import { useTranslation } from "react-i18next"; import "./PlantCard.css"; import PlantPreferenceChips from "../PlantPreferenceChips/PlantPreferenceChips"; +import type { Plant } from "../../types/Plant"; + +// The card only shows these fields, so the id is not needed +type PlantCardData = Omit; type Props = { - name: string | null; - imageURL: string | null; - scientificName?: string[] | null; - description?: string | null; - watering?: string | null; - sunlight?: string[] | null; - careLevel?: string | null; + plant: PlantCardData; + // "compact" is the smaller card used in the grids on Explore and My Matches + size?: "large" | "compact"; onInfo?: () => void; }; -export default function PlantCard({ - name, - imageURL, - scientificName, - description, - watering, - sunlight, - careLevel, - onInfo, -}: Props) { +export default function PlantCard({ plant, size = "large", onInfo }: Props) { + const { + name, + imageURL, + scientificName, + description, + watering, + sunlight, + careLevel, + } = plant; const { t } = useTranslation(); const detailsId = useId(); const detailsRef = useRef(null); @@ -57,7 +57,9 @@ export default function PlantCard({ : t("plantCard.frontLabel", { name: plantName }); return ( -
+
- {description && ( -

{description}

- )} -
{t("plantCard.watering")}
@@ -137,6 +135,10 @@ export default function PlantCard({
{careLevel ?? t("plantCard.unknown")}
+ + {description && ( +

{description}

+ )}

{t("plantCard.tapToFlipBack")}

diff --git a/frontend/src/pages/explorePlants/ExplorePlants.css b/frontend/src/pages/explorePlants/ExplorePlants.css index 0f6f5a32..9562ae1b 100644 --- a/frontend/src/pages/explorePlants/ExplorePlants.css +++ b/frontend/src/pages/explorePlants/ExplorePlants.css @@ -11,7 +11,6 @@ gap: 30px; font-family: Georgia, serif; - --card-scale: 0.8; } .visually-hidden { @@ -140,25 +139,16 @@ display: grid; grid-template-columns: repeat( auto-fill, - minmax(calc(390px * var(--card-scale)), 1fr) + minmax(var(--plant-card-compact-width), 1fr) ); gap: 30px 20px; } .explore-plant-item { - width: calc(390px * var(--card-scale)); - height: calc(620px * var(--card-scale)); justify-self: center; position: relative; } -.explore-plant-item .plant-card-flipper { - width: 390px; - height: 620px; - transform: scale(var(--card-scale)); - transform-origin: top left; -} - .pagination { display: flex; flex-wrap: wrap; @@ -336,17 +326,6 @@ gap: 20px; } - .explore-plant-item { - width: min(280px, 62vw); - height: 502px; - } - - .explore-plant-item .plant-card-flipper { - width: 100%; - height: 100%; - transform: none; - } - .add-match-button { width: 35px; height: 35px; diff --git a/frontend/src/pages/explorePlants/ExplorePlants.tsx b/frontend/src/pages/explorePlants/ExplorePlants.tsx index 9690cd79..d136a628 100644 --- a/frontend/src/pages/explorePlants/ExplorePlants.tsx +++ b/frontend/src/pages/explorePlants/ExplorePlants.tsx @@ -218,15 +218,7 @@ export default function ExplorePlants() { return (
  • - + {/* Sibling of the card (not inside it), so no nested buttons */}
  • @@ -100,6 +107,7 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) {
    @@ -112,7 +120,7 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) { )}
    -
    +
    {t("plantCard.watering")}
    @@ -139,7 +147,14 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) { )}
    -

    {t("plantCard.tapToFlipBack")}

    +
    diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index b3d76bc1..1a97e785 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -106,9 +106,7 @@ "careLevel": "Care level", "unknown": "Unknown", "tapForDetails": "Tap the card for details", - "tapToFlipBack": "Tap to flip back", - "frontLabel": "{{name}}. Tap to see details", - "backLabel": "{{name}}, details. Tap to flip back" + "tapToFlipBack": "Tap to flip back" }, "plantQuiz": { "title": "What kind of plant owner are you?", diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json index a7eb55a6..7abdcdf3 100644 --- a/frontend/src/i18n/locales/no/translation.json +++ b/frontend/src/i18n/locales/no/translation.json @@ -106,9 +106,7 @@ "careLevel": "Stell", "unknown": "Ukjent", "tapForDetails": "Trykk på kortet for detaljer", - "tapToFlipBack": "Trykk for å snu tilbake", - "frontLabel": "{{name}}. Trykk for å se detaljer", - "backLabel": "{{name}}, detaljer. Trykk for å snu tilbake" + "tapToFlipBack": "Trykk for å snu tilbake" }, "plantQuiz": { "title": "Hvilken type planteeier er du?", diff --git a/frontend/src/tests/PlantCard.test.tsx b/frontend/src/tests/PlantCard.test.tsx index 543dc8c9..d3255da3 100644 --- a/frontend/src/tests/PlantCard.test.tsx +++ b/frontend/src/tests/PlantCard.test.tsx @@ -57,7 +57,7 @@ describe("PlantCard", () => { ); await user.click( - screen.getByRole("button", { name: "plantCard.frontLabel:Orchid" }), + screen.getByRole("button", { name: "plantCard.tapForDetails" }), ); expect(onInfo).toHaveBeenCalledTimes(1); @@ -67,7 +67,7 @@ describe("PlantCard", () => { expect(screen.getByText("Full sun, Part shade")).toBeInTheDocument(); await user.click( - screen.getByRole("button", { name: "plantCard.backLabel:Orchid" }), + screen.getByRole("button", { name: "plantCard.tapToFlipBack" }), ); expect(container.firstChild).not.toHaveClass("is-flipped"); @@ -81,14 +81,21 @@ describe("PlantCard", () => { await user.tab(); expect( - screen.getByRole("button", { name: "plantCard.frontLabel:Fern" }), + screen.getByRole("button", { name: "plantCard.tapForDetails" }), ).toHaveFocus(); await user.keyboard("{Enter}"); expect(container.firstChild).toHaveClass("is-flipped"); + // Focus follows to the button on the face that is now visible + expect( + screen.getByRole("button", { name: "plantCard.tapToFlipBack" }), + ).toHaveFocus(); await user.keyboard(" "); expect(container.firstChild).not.toHaveClass("is-flipped"); + expect( + screen.getByRole("button", { name: "plantCard.tapForDetails" }), + ).toHaveFocus(); }); it("shows unknown for missing facts and no image", () => {