Fix card menu styles on small screens (#1813)

* Move cardMenu to page header

* Update tests

* Fix extension menu items

* Refactor card menu in page header

* Update tests

* Apply new page styling to gift cards list
This commit is contained in:
Wojciech Mista 2022-02-03 13:59:36 +01:00 committed by GitHub
parent f1575ac179
commit 9f3dfe3bcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 2560 additions and 1495 deletions

View file

@ -68,7 +68,9 @@ export const ButtonWithSelect: React.FC<ButtonWithSelectProps> = ({
aria-label="button with select" aria-label="button with select"
{...props} {...props}
> >
<Button onClick={onClick}>{children}</Button> <Button onClick={onClick} style={{ width: "100%" }}>
{children}
</Button>
{options.length > 0 && ( {options.length > 0 && (
<Button <Button
color="primary" color="primary"

View file

@ -6,10 +6,7 @@ import React from "react";
const useStyles = makeStyles( const useStyles = makeStyles(
theme => ({ theme => ({
action: { action: {
flex: "0 0 auto", flex: "0 0 auto"
[theme.breakpoints.down("sm")]: {
marginTop: theme.spacing()
}
}, },
block: { block: {
[theme.breakpoints.down("xs")]: { [theme.breakpoints.down("xs")]: {
@ -41,9 +38,12 @@ const useStyles = makeStyles(
display: "flex", display: "flex",
marginBottom: theme.spacing(2) marginBottom: theme.spacing(2)
}, },
title: { titleRow: {
flex: 1, flex: 1,
paddingBottom: theme.spacing(2) display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between"
} }
}), }),
{ {
@ -83,7 +83,7 @@ const ExtendedPageHeader: React.FC<ExtendedPageHeaderProps> = props => {
[classes.underline]: underline [classes.underline]: underline
})} })}
> >
{title} <div className={classes.titleRow}>{title}</div>
<div className={classNames(classes.action, childrenWrapperClassName)}> <div className={classNames(classes.action, childrenWrapperClassName)}>
{children} {children}
</div> </div>

View file

@ -27,11 +27,9 @@ const useStyles = makeStyles(
title: { title: {
[theme.breakpoints.down("sm")]: { [theme.breakpoints.down("sm")]: {
fontSize: 20, fontSize: 20,
marginTop: theme.spacing(2),
padding: 0 padding: 0
}, },
fontWeight: 700, fontWeight: 700,
alignSelf: "flex-start",
flex: 1, flex: 1,
whiteSpace: "nowrap", whiteSpace: "nowrap",
overflow: "hidden", overflow: "hidden",
@ -48,10 +46,19 @@ interface PageHeaderProps {
underline?: boolean; underline?: boolean;
limitText?: string; limitText?: string;
title?: React.ReactNode; title?: React.ReactNode;
cardMenu?: React.ReactNode;
} }
const PageHeader: React.FC<PageHeaderProps> = props => { const PageHeader: React.FC<PageHeaderProps> = props => {
const { children, className, inline, underline, limitText, title } = props; const {
children,
className,
inline,
underline,
limitText,
title,
cardMenu
} = props;
const classes = useStyles(props); const classes = useStyles(props);
@ -62,9 +69,16 @@ const PageHeader: React.FC<PageHeaderProps> = props => {
inline={inline} inline={inline}
underline={underline} underline={underline}
title={ title={
<Typography className={classes.title} variant="h1"> <>
{title !== undefined ? title : <Skeleton style={{ width: "10em" }} />} <Typography className={classes.title} variant="h1">
</Typography> {title !== undefined ? (
title
) : (
<Skeleton style={{ width: "10em" }} />
)}
</Typography>
{cardMenu}
</>
} }
> >
<div className={classes.root}> <div className={classes.root}>

View file

@ -1,5 +1,4 @@
import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer"; import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer";
import VerticalSpacer from "@saleor/apps/components/VerticalSpacer";
import CardMenu, { CardMenuItem } from "@saleor/components/CardMenu"; import CardMenu, { CardMenuItem } from "@saleor/components/CardMenu";
import PageHeader from "@saleor/components/PageHeader"; import PageHeader from "@saleor/components/PageHeader";
import useNavigator from "@saleor/hooks/useNavigator"; import useNavigator from "@saleor/hooks/useNavigator";
@ -45,8 +44,10 @@ const GiftCardsListHeader: React.FC = () => {
return ( return (
<> <>
<PageHeader title={intl.formatMessage(sectionNames.giftCards)}> <PageHeader
<CardMenu menuItems={menuItems} data-test="menu" /> title={intl.formatMessage(sectionNames.giftCards)}
cardMenu={<CardMenu menuItems={menuItems} data-test="menu" />}
>
<HorizontalSpacer spacing={2} /> <HorizontalSpacer spacing={2} />
<Button <Button
variant="primary" variant="primary"
@ -57,7 +58,6 @@ const GiftCardsListHeader: React.FC = () => {
</Button> </Button>
</PageHeader> </PageHeader>
<GiftCardsListHeaderAlert /> <GiftCardsListHeaderAlert />
<VerticalSpacer spacing={2} />
</> </>
); );
}; };

View file

@ -229,9 +229,8 @@ const OrderDetailsPage: React.FC<OrderDetailsPageProps> = props => {
<OrderStatusChip order={order} /> <OrderStatusChip order={order} />
</PageTitleWithStatusChip> </PageTitleWithStatusChip>
} }
> cardMenu={<CardMenu outlined menuItems={selectCardMenuItems} />}
<CardMenu outlined menuItems={selectCardMenuItems} /> />
</PageHeader>
<div className={classes.date}> <div className={classes.date}>
{order && order.created ? ( {order && order.created ? (
<Typography variant="body2"> <Typography variant="body2">

View file

@ -77,21 +77,23 @@ const OrderListPage: React.FC<OrderListPageProps> = ({
} }
) )
} }
cardMenu={
!!onSettingsOpen && (
<CardMenu
className={classes.settings}
menuItems={[
{
label: intl.formatMessage({
defaultMessage: "Order Settings",
description: "button"
}),
onSelect: onSettingsOpen
}
]}
/>
)
}
> >
{!!onSettingsOpen && (
<CardMenu
className={classes.settings}
menuItems={[
{
label: intl.formatMessage({
defaultMessage: "Order Settings",
description: "button"
}),
onSelect: onSettingsOpen
}
]}
/>
)}
<Button <Button
disabled={limitsReached} disabled={limitsReached}
variant="primary" variant="primary"

View file

@ -71,7 +71,9 @@ const useStyles = makeStyles(
} }
}, },
settings: { settings: {
marginRight: theme.spacing(2) [theme.breakpoints.up("sm")]: {
marginRight: theme.spacing(2)
}
} }
}), }),
{ name: "ProductListPage" } { name: "ProductListPage" }
@ -148,6 +150,23 @@ export const ProductListPage: React.FC<ProductListPageProps> = props => {
return ( return (
<Container> <Container>
<PageHeader <PageHeader
cardMenu={
<CardMenu
className={classes.settings}
menuItems={[
{
label: intl.formatMessage({
defaultMessage: "Export Products",
description: "export products to csv file, button"
}),
onSelect: onExport,
testId: "export"
},
...extensionMenuItems
]}
data-test="menu"
/>
}
title={intl.formatMessage(sectionNames.products)} title={intl.formatMessage(sectionNames.products)}
limitText={ limitText={
hasLimits(limits, "productVariants") && hasLimits(limits, "productVariants") &&
@ -163,21 +182,6 @@ export const ProductListPage: React.FC<ProductListPageProps> = props => {
) )
} }
> >
<CardMenu
className={classes.settings}
menuItems={[
{
label: intl.formatMessage({
defaultMessage: "Export Products",
description: "export products to csv file, button"
}),
onSelect: onExport,
testId: "export"
},
...extensionMenuItems
]}
data-test="menu"
/>
<ColumnPicker <ColumnPicker
className={classes.columnPicker} className={classes.columnPicker}
columns={columns} columns={columns}

File diff suppressed because it is too large Load diff