fix bug with zone badge wrapping
Oops, the <Wrap> 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!
This commit is contained in:
parent
271b1e2ac5
commit
5a13959805
3 changed files with 47 additions and 23 deletions
|
@ -2,7 +2,6 @@ import React from "react";
|
||||||
import { css } from "emotion";
|
import { css } from "emotion";
|
||||||
import {
|
import {
|
||||||
AspectRatio,
|
AspectRatio,
|
||||||
Badge,
|
|
||||||
Button,
|
Button,
|
||||||
Box,
|
Box,
|
||||||
IconButton,
|
IconButton,
|
||||||
|
@ -29,6 +28,7 @@ import { useQuery, useMutation } from "@apollo/client";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ItemBadge,
|
||||||
ItemBadgeList,
|
ItemBadgeList,
|
||||||
ItemThumbnail,
|
ItemThumbnail,
|
||||||
NcBadge,
|
NcBadge,
|
||||||
|
@ -160,14 +160,14 @@ function ItemPageBadges({ item, isEmbedded }) {
|
||||||
// empty).
|
// empty).
|
||||||
isLoaded={item.createdAt !== undefined}
|
isLoaded={item.createdAt !== undefined}
|
||||||
>
|
>
|
||||||
<Badge
|
<ItemBadge
|
||||||
display="block"
|
display="block"
|
||||||
minWidth="5.25em"
|
minWidth="5.25em"
|
||||||
boxSizing="content-box"
|
boxSizing="content-box"
|
||||||
textAlign="center"
|
textAlign="center"
|
||||||
>
|
>
|
||||||
{item.createdAt && <ShortTimestamp when={item.createdAt} />}
|
{item.createdAt && <ShortTimestamp when={item.createdAt} />}
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
</SubtleSkeleton>
|
</SubtleSkeleton>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ function ItemPageBadges({ item, isEmbedded }) {
|
||||||
|
|
||||||
function LinkBadge({ children, href, isEmbedded }) {
|
function LinkBadge({ children, href, isEmbedded }) {
|
||||||
return (
|
return (
|
||||||
<Badge
|
<ItemBadge
|
||||||
as="a"
|
as="a"
|
||||||
href={href}
|
href={href}
|
||||||
display="flex"
|
display="flex"
|
||||||
|
@ -265,7 +265,7 @@ function LinkBadge({ children, href, isEmbedded }) {
|
||||||
// window or not!
|
// window or not!
|
||||||
isEmbedded ? <ExternalLinkIcon marginLeft="1" /> : <ChevronRightIcon />
|
isEmbedded ? <ExternalLinkIcon marginLeft="1" /> : <ChevronRightIcon />
|
||||||
}
|
}
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
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 gql from "graphql-tag";
|
||||||
import { useQuery } from "@apollo/client";
|
import { useQuery } from "@apollo/client";
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import { Delay } from "./util";
|
||||||
import HangerSpinner from "./components/HangerSpinner";
|
import HangerSpinner from "./components/HangerSpinner";
|
||||||
import { Heading1, Heading2, usePageTitle } from "./util";
|
import { Heading1, Heading2, usePageTitle } from "./util";
|
||||||
import ItemCard, {
|
import ItemCard, {
|
||||||
|
ItemBadge,
|
||||||
ItemBadgeList,
|
ItemBadgeList,
|
||||||
ItemCardList,
|
ItemCardList,
|
||||||
NcBadge,
|
NcBadge,
|
||||||
|
@ -173,7 +174,7 @@ function ItemModelBadges({ item, currentUserOwnsItem }) {
|
||||||
{item.isNc && <NcBadge />}
|
{item.isNc && <NcBadge />}
|
||||||
{currentUserOwnsItem && <YouOwnThisBadge />}
|
{currentUserOwnsItem && <YouOwnThisBadge />}
|
||||||
{item.speciesThatNeedModels.map((species) => (
|
{item.speciesThatNeedModels.map((species) => (
|
||||||
<Badge>{species.name}</Badge>
|
<ItemBadge>{species.name}</ItemBadge>
|
||||||
))}
|
))}
|
||||||
</ItemBadgeList>
|
</ItemBadgeList>
|
||||||
);
|
);
|
||||||
|
@ -191,7 +192,7 @@ function NewItemBadge({ createdAt }) {
|
||||||
placement="top"
|
placement="top"
|
||||||
openDelay={400}
|
openDelay={400}
|
||||||
>
|
>
|
||||||
<Badge colorScheme="yellow">New!</Badge>
|
<ItemBadge colorScheme="yellow">New!</ItemBadge>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,9 +201,32 @@ export function ItemCardList({ children }) {
|
||||||
|
|
||||||
export function ItemBadgeList({ children }) {
|
export function ItemBadgeList({ children }) {
|
||||||
return (
|
return (
|
||||||
<Wrap spacing="2" marginTop="1" opacity="0.7">
|
<Box marginTop="1" opacity="0.7">
|
||||||
|
<Box
|
||||||
|
// This is copying the styles of <Wrap spacing="2" />! 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}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ItemBadge({ children, ...props }) {
|
||||||
|
return (
|
||||||
|
<Badge margin="1" {...props}>
|
||||||
{children}
|
{children}
|
||||||
</Wrap>
|
</Badge>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,9 +245,9 @@ export function ItemBadgeTooltip({ label, children }) {
|
||||||
export function NcBadge() {
|
export function NcBadge() {
|
||||||
return (
|
return (
|
||||||
<ItemBadgeTooltip label="Neocash">
|
<ItemBadgeTooltip label="Neocash">
|
||||||
<Badge colorScheme="purple" display="block">
|
<ItemBadge colorScheme="purple" display="block">
|
||||||
NC
|
NC
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
</ItemBadgeTooltip>
|
</ItemBadgeTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -234,14 +257,14 @@ export function NpBadge() {
|
||||||
// default of inline-block.
|
// default of inline-block.
|
||||||
return (
|
return (
|
||||||
<ItemBadgeTooltip label="Neopoints">
|
<ItemBadgeTooltip label="Neopoints">
|
||||||
<Badge display="block">NP</Badge>
|
<ItemBadge display="block">NP</ItemBadge>
|
||||||
</ItemBadgeTooltip>
|
</ItemBadgeTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function YouOwnThisBadge({ variant = "long" }) {
|
export function YouOwnThisBadge({ variant = "long" }) {
|
||||||
let badge = (
|
let badge = (
|
||||||
<Badge
|
<ItemBadge
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
|
@ -249,7 +272,7 @@ export function YouOwnThisBadge({ variant = "long" }) {
|
||||||
>
|
>
|
||||||
<CheckIcon aria-label="Star" />
|
<CheckIcon aria-label="Star" />
|
||||||
{variant === "long" && <Box marginLeft="1">You own this!</Box>}
|
{variant === "long" && <Box marginLeft="1">You own this!</Box>}
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (variant === "short") {
|
if (variant === "short") {
|
||||||
|
@ -261,7 +284,7 @@ export function YouOwnThisBadge({ variant = "long" }) {
|
||||||
|
|
||||||
export function YouWantThisBadge({ variant = "long" }) {
|
export function YouWantThisBadge({ variant = "long" }) {
|
||||||
let badge = (
|
let badge = (
|
||||||
<Badge
|
<ItemBadge
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
|
@ -269,7 +292,7 @@ export function YouWantThisBadge({ variant = "long" }) {
|
||||||
>
|
>
|
||||||
<StarIcon aria-label="Star" />
|
<StarIcon aria-label="Star" />
|
||||||
{variant === "long" && <Box marginLeft="1">You want this!</Box>}
|
{variant === "long" && <Box marginLeft="1">You want this!</Box>}
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (variant === "short") {
|
if (variant === "short") {
|
||||||
|
@ -294,11 +317,11 @@ function ZoneBadge({ variant, zoneLabel }) {
|
||||||
<ItemBadgeTooltip
|
<ItemBadgeTooltip
|
||||||
label={`Restricted: This item can't be worn with ${zoneLabel} items`}
|
label={`Restricted: This item can't be worn with ${zoneLabel} items`}
|
||||||
>
|
>
|
||||||
<Badge>
|
<ItemBadge>
|
||||||
<Box display="flex" alignItems="center">
|
<Box display="flex" alignItems="center">
|
||||||
{shorthand} <NotAllowedIcon marginLeft="1" />
|
{shorthand} <NotAllowedIcon marginLeft="1" />
|
||||||
</Box>
|
</Box>
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
</ItemBadgeTooltip>
|
</ItemBadgeTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -306,12 +329,12 @@ function ZoneBadge({ variant, zoneLabel }) {
|
||||||
if (shorthand !== zoneLabel) {
|
if (shorthand !== zoneLabel) {
|
||||||
return (
|
return (
|
||||||
<ItemBadgeTooltip label={zoneLabel}>
|
<ItemBadgeTooltip label={zoneLabel}>
|
||||||
<Badge>{shorthand}</Badge>
|
<ItemBadge>{shorthand}</ItemBadge>
|
||||||
</ItemBadgeTooltip>
|
</ItemBadgeTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Badge>{shorthand}</Badge>;
|
return <ItemBadge>{shorthand}</ItemBadge>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ZoneBadgeList({ zones, variant }) {
|
export function ZoneBadgeList({ zones, variant }) {
|
||||||
|
@ -329,14 +352,14 @@ export function ZoneBadgeList({ zones, variant }) {
|
||||||
export function MaybeAnimatedBadge() {
|
export function MaybeAnimatedBadge() {
|
||||||
return (
|
return (
|
||||||
<ItemBadgeTooltip label="Maybe animated? (Support only)">
|
<ItemBadgeTooltip label="Maybe animated? (Support only)">
|
||||||
<Badge
|
<ItemBadge
|
||||||
colorScheme="orange"
|
colorScheme="orange"
|
||||||
display="flex"
|
display="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
minHeight="1.5em"
|
minHeight="1.5em"
|
||||||
>
|
>
|
||||||
<Box as={HiSparkles} aria-label="Sparkles" />
|
<Box as={HiSparkles} aria-label="Sparkles" />
|
||||||
</Badge>
|
</ItemBadge>
|
||||||
</ItemBadgeTooltip>
|
</ItemBadgeTooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue