From 5a139598052e1dff2913f3f41b70a2b26a142bdc Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 24 Oct 2020 00:32:23 -0700 Subject: [PATCH] fix bug with zone badge wrapping Oops, the component is nice, but it uses React.Children to apply margin to its _direct_ children, and our badges are not always direct children! (See the new `ZoneBadgeList`.) I poked my head into how `Wrap` works, and it's honestly pretty simple, so I've applied the same styles manually. Ta da! --- src/app/ItemPage.js | 10 +++---- src/app/ModelingPage.js | 7 +++-- src/app/components/ItemCard.js | 53 ++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/app/ItemPage.js b/src/app/ItemPage.js index 8b14798..8822dcb 100644 --- a/src/app/ItemPage.js +++ b/src/app/ItemPage.js @@ -2,7 +2,6 @@ import React from "react"; import { css } from "emotion"; import { AspectRatio, - Badge, Button, Box, IconButton, @@ -29,6 +28,7 @@ import { useQuery, useMutation } from "@apollo/client"; import { useParams } from "react-router-dom"; import { + ItemBadge, ItemBadgeList, ItemThumbnail, NcBadge, @@ -160,14 +160,14 @@ function ItemPageBadges({ item, isEmbedded }) { // empty). isLoaded={item.createdAt !== undefined} > - {item.createdAt && } - + ) } @@ -249,7 +249,7 @@ function ItemPageBadges({ item, isEmbedded }) { function LinkBadge({ children, href, isEmbedded }) { return ( - : } - + ); } diff --git a/src/app/ModelingPage.js b/src/app/ModelingPage.js index 7145581..1208a69 100644 --- a/src/app/ModelingPage.js +++ b/src/app/ModelingPage.js @@ -1,5 +1,5 @@ import React from "react"; -import { Badge, Box, Tooltip } from "@chakra-ui/core"; +import { Box, Tooltip } from "@chakra-ui/core"; import gql from "graphql-tag"; import { useQuery } from "@apollo/client"; @@ -7,6 +7,7 @@ import { Delay } from "./util"; import HangerSpinner from "./components/HangerSpinner"; import { Heading1, Heading2, usePageTitle } from "./util"; import ItemCard, { + ItemBadge, ItemBadgeList, ItemCardList, NcBadge, @@ -173,7 +174,7 @@ function ItemModelBadges({ item, currentUserOwnsItem }) { {item.isNc && } {currentUserOwnsItem && } {item.speciesThatNeedModels.map((species) => ( - {species.name} + {species.name} ))} ); @@ -191,7 +192,7 @@ function NewItemBadge({ createdAt }) { placement="top" openDelay={400} > - New! + New! ); } diff --git a/src/app/components/ItemCard.js b/src/app/components/ItemCard.js index 9bffeb3..c6bb58c 100644 --- a/src/app/components/ItemCard.js +++ b/src/app/components/ItemCard.js @@ -201,9 +201,32 @@ export function ItemCardList({ children }) { export function ItemBadgeList({ children }) { return ( - + + ! The individual + // ItemBadges have their own `margin="1"`, which we counteract here for + // consistency. + // + // The difference between this and `Wrap` is that `Wrap` uses + // React.Children to wrap its children in containers with `margin="1"`, + // but that doesn't work when the badges aren't _direct_ children, like + // in `ZoneBadgeList`. The badges are what we want to have wrap, not + // whatever component happens to be the direct child! + margin="-1" + display="flex" + flexWrap="wrap" + > + {children} + + + ); +} + +export function ItemBadge({ children, ...props }) { + return ( + {children} - + ); } @@ -222,9 +245,9 @@ export function ItemBadgeTooltip({ label, children }) { export function NcBadge() { return ( - + NC - + ); } @@ -234,14 +257,14 @@ export function NpBadge() { // default of inline-block. return ( - NP + NP ); } export function YouOwnThisBadge({ variant = "long" }) { let badge = ( - {variant === "long" && You own this!} - + ); if (variant === "short") { @@ -261,7 +284,7 @@ export function YouOwnThisBadge({ variant = "long" }) { export function YouWantThisBadge({ variant = "long" }) { let badge = ( - {variant === "long" && You want this!} - + ); if (variant === "short") { @@ -294,11 +317,11 @@ function ZoneBadge({ variant, zoneLabel }) { - + {shorthand} - + ); } @@ -306,12 +329,12 @@ function ZoneBadge({ variant, zoneLabel }) { if (shorthand !== zoneLabel) { return ( - {shorthand} + {shorthand} ); } - return {shorthand}; + return {shorthand}; } export function ZoneBadgeList({ zones, variant }) { @@ -329,14 +352,14 @@ export function ZoneBadgeList({ zones, variant }) { export function MaybeAnimatedBadge() { return ( - - + ); }