diff --git a/.changeset/beige-dots-protect.md b/.changeset/beige-dots-protect.md new file mode 100644 index 000000000..92752a43e --- /dev/null +++ b/.changeset/beige-dots-protect.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Replace all old Accordion components with new from macaw-ui diff --git a/src/channels/components/AssignmentList/AssignmentList.tsx b/src/channels/components/AssignmentList/AssignmentList.tsx index c124ddc3f..11b6a966e 100644 --- a/src/channels/components/AssignmentList/AssignmentList.tsx +++ b/src/channels/components/AssignmentList/AssignmentList.tsx @@ -1,15 +1,15 @@ // @ts-strict-ignore import Skeleton from "@dashboard/components/Skeleton"; import { ReorderEvent } from "@dashboard/types"; -import { Accordion, Divider, Typography } from "@material-ui/core"; +import { Typography } from "@material-ui/core"; +import { Accordion, Divider } from "@saleor/macaw-ui/next"; import React from "react"; import { defineMessages, useIntl } from "react-intl"; import AssignmentListFooter from "./AssignmentListFooter"; -import AssignmentListHeader from "./AssignmentListHeader"; import Item from "./Item"; import SortableContainer from "./SortableContainer"; -import { useExpanderStyles, useStyles } from "./styles"; +import { useStyles } from "./styles"; import { AssignmentListProps } from "./types"; const messages = defineMessages({ @@ -32,7 +32,6 @@ const AssignmentList: React.FC = props => { const intl = useIntl(); const classes = useStyles(); - const expanderClasses = useExpanderStyles(); const handleSortStart = () => { document.body.classList.add(classes.grabbing); @@ -46,51 +45,61 @@ const AssignmentList: React.FC = props => { const hasMoreItemsToBeSelected = totalCount !== items.length; return ( - - - - {loading ? ( - - ) : ( - <> - -
- {items.map((item, itemIndex) => ( - - ))} -
-
- {hasMoreItemsToBeSelected ? ( - + + + + {loading ? ( + ) : ( - - {intl.formatMessage(messages.allSelectedMessage, { - itemsName: itemsName.toLowerCase(), - })} + + {`${items.length} ${itemsName.toLowerCase()}`} )} - - )} + + + + + + {loading ? ( + + ) : ( + <> + +
+ {items.map((item, itemIndex) => ( + + ))} +
+
+ {hasMoreItemsToBeSelected ? ( + + ) : ( + + {intl.formatMessage(messages.allSelectedMessage, { + itemsName: itemsName.toLowerCase(), + })} + + )} + + )} +
+
); }; diff --git a/src/channels/components/AssignmentList/AssignmentListHeader.tsx b/src/channels/components/AssignmentList/AssignmentListHeader.tsx deleted file mode 100644 index 377e7ff84..000000000 --- a/src/channels/components/AssignmentList/AssignmentListHeader.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import HorizontalSpacer from "@dashboard/components/HorizontalSpacer"; -import Skeleton from "@dashboard/components/Skeleton"; -import { Typography } from "@material-ui/core"; -import { AccordionSummary } from "@saleor/macaw-ui"; -import React from "react"; - -import { useHeaderStyles } from "./styles"; - -interface AssignmentListHeaderProps { - assignCount: number; - itemsName: string; - loading: boolean; -} - -const AssignmentListHeader: React.FC = ({ - assignCount, - itemsName, - loading, -}) => { - const { container, skeleton, ...accordion } = useHeaderStyles(); - - return ( -
- - {loading ? ( - - ) : ( - - {`${assignCount} ${itemsName.toLowerCase()}`} - - )} - - -
- ); -}; - -export default AssignmentListHeader; diff --git a/src/channels/components/AssignmentList/Item.tsx b/src/channels/components/AssignmentList/Item.tsx index 56483294d..37fd4c2e2 100644 --- a/src/channels/components/AssignmentList/Item.tsx +++ b/src/channels/components/AssignmentList/Item.tsx @@ -1,5 +1,5 @@ import DeletableItem from "@dashboard/components/DeletableItem"; -import { Divider, Typography } from "@material-ui/core"; +import { Divider, Text } from "@saleor/macaw-ui/next"; import React from "react"; import { SortableElement, SortableElementProps } from "react-sortable-hoc"; @@ -28,7 +28,7 @@ const Item = SortableElement( data-test-id="button-drag-handle" /> )} - {name} + {name} diff --git a/src/channels/components/AssignmentList/styles.ts b/src/channels/components/AssignmentList/styles.ts index 3a2a3c32c..4f91ee647 100644 --- a/src/channels/components/AssignmentList/styles.ts +++ b/src/channels/components/AssignmentList/styles.ts @@ -53,7 +53,6 @@ export const useHeaderStyles = makeStyles( export const useStyles = makeStyles( theme => ({ container: { - padding: theme.spacing(1, 0), display: "flex", flexDirection: "row", justifyContent: "space-between", diff --git a/src/components/Accordion/Accordion.tsx b/src/components/Accordion/Accordion.tsx index 675335aee..04969c7a5 100644 --- a/src/components/Accordion/Accordion.tsx +++ b/src/components/Accordion/Accordion.tsx @@ -1,39 +1,11 @@ -import { Typography } from "@material-ui/core"; -import AddIcon from "@material-ui/icons/Add"; -import RemoveIcon from "@material-ui/icons/Remove"; -import { IconButton, makeStyles } from "@saleor/macaw-ui"; -import clsx from "clsx"; -import React from "react"; - -import Hr from "../Hr"; - -const useStyles = makeStyles( - theme => ({ - content: { - padding: theme.spacing(3, 0), - }, - expandButton: { - position: "relative", - right: theme.spacing(-2), - top: theme.spacing(0.5), - }, - root: { - border: `1px solid ${theme.palette.divider}`, - borderRadius: 12, - padding: theme.spacing(0, 3), - }, - title: { - display: "flex", - justifyContent: "space-between", - }, - titleText: { - padding: theme.spacing(2, 0), - }, - }), - { - name: "Accordion", - }, -); +import { + Accordion as AccordionMacaw, + Box, + Divider, + sprinkles, + Text, +} from "@saleor/macaw-ui/next"; +import React, { useState } from "react"; export interface AccordionProps { className?: string; @@ -42,38 +14,52 @@ export interface AccordionProps { title: string; } +const AccordionItemId = "accordionItemId"; + const Accordion: React.FC = ({ children, - className, initialExpand, quickPeek, title, - ...props + className, }) => { - const classes = useStyles({}); - const [expanded, setExpanded] = React.useState(!!initialExpand); + const [openedAccordionId, setOpendAccordionId] = useState( + !!initialExpand ? AccordionItemId : undefined, + ); return ( -
-
- {title} -
- setExpanded(!expanded)} - > - {expanded ? : } - -
-
- {(expanded || !!quickPeek) && ( - <> -
-
- {quickPeek ? (expanded ? children : quickPeek) : children} -
- - )} +
+ setOpendAccordionId(value)} + className={sprinkles({ + borderStyle: "solid", + borderWidth: 1, + borderColor: "neutralPlain", + paddingX: 4, + borderRadius: 5, + })} + > + + + + {title} + + + + + + {children} + + + + {!openedAccordionId && !!quickPeek && ( + <> + + {quickPeek} + + )} +
); }; diff --git a/src/components/Attributes/Attributes.tsx b/src/components/Attributes/Attributes.tsx index 2389e025b..dce77c051 100644 --- a/src/components/Attributes/Attributes.tsx +++ b/src/components/Attributes/Attributes.tsx @@ -88,6 +88,7 @@ export const Attributes: React.FC = ({ }} /> + {attributes.length > 0 && ( diff --git a/src/components/ChannelsAvailabilityCard/Channel/ChannelAvailabilityItemWrapper.tsx b/src/components/ChannelsAvailabilityCard/Channel/ChannelAvailabilityItemWrapper.tsx index 51263fff5..e42d08203 100644 --- a/src/components/ChannelsAvailabilityCard/Channel/ChannelAvailabilityItemWrapper.tsx +++ b/src/components/ChannelsAvailabilityCard/Channel/ChannelAvailabilityItemWrapper.tsx @@ -17,9 +17,10 @@ export const ChannelAvailabilityItemWrapper: React.FC< > = ({ data: { name }, messages, children }) => ( - + {name} {children} diff --git a/src/components/Filter/FilterContent/FilterContentBodyNameField.tsx b/src/components/Filter/FilterContent/FilterContentBodyNameField.tsx index c12b307e5..6a9187bcd 100644 --- a/src/components/Filter/FilterContent/FilterContentBodyNameField.tsx +++ b/src/components/Filter/FilterContent/FilterContentBodyNameField.tsx @@ -39,7 +39,7 @@ const FilterContentBodyNameField: React.FC = ({ } label={filter.label} onClick={event => event.stopPropagation()} - onChange={() => + onChange={() => { onFilterPropertyChange({ payload: { name: filter.name, @@ -48,8 +48,8 @@ const FilterContentBodyNameField: React.FC = ({ }, }, type: "set-property", - }) - } + }); + }} />
); diff --git a/src/components/Timeline/TimelineEvent.tsx b/src/components/Timeline/TimelineEvent.tsx index b54cb5acd..fdde2ee85 100644 --- a/src/components/Timeline/TimelineEvent.tsx +++ b/src/components/Timeline/TimelineEvent.tsx @@ -1,80 +1,8 @@ -import { Typography } from "@material-ui/core"; -import { - Accordion, - AccordionDetails, - AccordionSummary, - makeStyles, -} from "@saleor/macaw-ui"; +import { Accordion, Box, sprinkles, Text } from "@saleor/macaw-ui/next"; import React from "react"; import TimelineEventHeader, { TitleElement } from "./TimelineEventHeader"; -const useStyles = makeStyles( - theme => ({ - dot: { - backgroundColor: theme.palette.primary.main, - borderRadius: "100%", - height: 7, - left: -28, - position: "absolute", - top: 6, - width: 7, - }, - panel: { - "& .MuiAccordionDetails-root": { - padding: 0, - paddingTop: theme.spacing(2), - }, - "&.Mui-expanded": { - margin: 0, - minHeight: 0, - }, - "&:before": { - display: "none", - }, - background: "none", - display: "", - margin: 0, - minHeight: 0, - width: "100%", - }, - panelExpander: { - "&.MuiAccordionSummary-root.Mui-expanded": { - minHeight: 0, - }, - "&> .MuiAccordionSummary-content": { - margin: 0, - }, - "&> .MuiAccordionSummary-expandIcon": { - padding: 0, - position: "absolute", - right: theme.spacing(24), - }, - margin: 0, - minHeight: 0, - padding: 0, - }, - root: { - "&:last-child:after": { - background: theme.palette.background.default, - content: "''", - height: "calc(50% - 4px)", - left: -26, - position: "absolute", - top: "calc(50% + 4px)", - width: "2px", - }, - alignItems: "center", - display: "flex", - marginBottom: theme.spacing(3), - marginTop: 0, - position: "relative", - width: "100%", - }, - }), - { name: "TimelineEvent" }, -); - export interface TimelineEventProps { children?: React.ReactNode; date: string; @@ -88,24 +16,48 @@ export const TimelineEvent: React.FC = props => { const { children, date, secondaryTitle, title, titleElements, hasPlainDate } = props; - const classes = useStyles(props); + const hasChildren = + children && React.Children.toArray(children).filter(Boolean).length > 0; return ( -
- - {children ? ( - - - - - - {children} - + + + {hasChildren ? ( + + + + + + + + + {children} + + ) : ( = props => { hasPlainDate={hasPlainDate} /> )} -
+ ); }; TimelineEvent.displayName = "TimelineEvent"; diff --git a/src/components/Timeline/TimelineEventHeader.tsx b/src/components/Timeline/TimelineEventHeader.tsx index cd18f89c4..2e23059a0 100644 --- a/src/components/Timeline/TimelineEventHeader.tsx +++ b/src/components/Timeline/TimelineEventHeader.tsx @@ -1,46 +1,10 @@ import useNavigator from "@dashboard/hooks/useNavigator"; -import { Typography } from "@material-ui/core"; -import { makeStyles } from "@saleor/macaw-ui"; -import React from "react"; +import { Box, sprinkles, Text } from "@saleor/macaw-ui/next"; +import React, { ReactNode } from "react"; import { DateTime } from "../Date"; import Link from "../Link"; -const useStyles = makeStyles( - theme => ({ - container: { - alignItems: "start", - display: "flex", - flexDirection: "row", - justifyContent: "space-between", - width: "100%", - }, - title: { - wordBreak: "break-all", - }, - date: { - color: theme.typography.caption.color, - paddingLeft: 24, - whiteSpace: "nowrap", - }, - elementsContainer: { - alignItems: "center", - display: "flex", - flexDirection: "row", - flexWrap: "wrap", - }, - secondaryTitle: { - color: "#9e9e9e", - fontSize: 14, - marginTop: theme.spacing(2), - }, - titleElement: { - marginRight: theme.spacing(0.5), - }, - }), - { name: "TimelineEventHeader" }, -); - export interface TitleElement { text: string; link?: string; @@ -52,26 +16,43 @@ export interface TimelineEventHeaderProps { titleElements?: TitleElement[]; secondaryTitle?: string; hasPlainDate?: boolean; + children?: ReactNode; } export const TimelineEventHeader: React.FC< TimelineEventHeaderProps > = props => { - const { title, date, titleElements, secondaryTitle, hasPlainDate } = props; + const { title, date, titleElements, secondaryTitle, hasPlainDate, children } = + props; const navigate = useNavigator(); - const classes = useStyles(props); - return ( -
- {title && {title}} + + {title && ( + + {title} + + )} {titleElements && ( -
+ {titleElements.filter(Boolean).map(({ text, link }) => { if (link) { return ( navigate(link)} > {text} @@ -80,20 +61,26 @@ export const TimelineEventHeader: React.FC< } return ( - {text} + + {text} + ); })} -
+
)} - - - - {secondaryTitle && ( - - {secondaryTitle} - - )} -
+ + {children} + + + + + {secondaryTitle && {secondaryTitle}} + ); }; diff --git a/src/giftCards/GiftCardUpdate/GiftCardHistory/styles.ts b/src/giftCards/GiftCardUpdate/GiftCardHistory/styles.ts index 55e5645b3..4ecb22481 100644 --- a/src/giftCards/GiftCardUpdate/GiftCardHistory/styles.ts +++ b/src/giftCards/GiftCardUpdate/GiftCardHistory/styles.ts @@ -9,7 +9,7 @@ const useStyles = makeStyles( marginBottom: vars.spacing.px, }, root: { - marginTop: vars.spacing["s1.5"], + marginTop: vars.spacing[1.5], paddingLeft: vars.spacing[6], paddingRight: vars.spacing[6], }, diff --git a/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/ChannelsList.tsx b/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/ChannelsList.tsx index a036bf94a..a018431b2 100644 --- a/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/ChannelsList.tsx +++ b/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/ChannelsList.tsx @@ -1,13 +1,6 @@ -import { CardContent, Typography } from "@material-ui/core"; -import { Accordion, AccordionSummary } from "@saleor/macaw-ui"; +import { Accordion, sprinkles, Text } from "@saleor/macaw-ui/next"; import React from "react"; -import { - useAccordionStyles, - useExpanderStyles, - useSummaryStyles, -} from "./styles"; - interface ChannelListProps { summary: string; } @@ -15,22 +8,22 @@ interface ChannelListProps { export const ChannelsList: React.FC = ({ summary, children, -}) => { - const classes = useAccordionStyles(); - const expanderClasses = useExpanderStyles({}); - const summaryClasses = useSummaryStyles({}); - - return ( - - - - {summary} - - - {children} - - ); -}; +}) => ( + + + + + {summary} + + + + {children} + + +); diff --git a/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/styles.ts b/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/styles.ts deleted file mode 100644 index 8a73900fe..000000000 --- a/src/products/components/ProductVariantChannels/ChannelsAvailabilityCard/styles.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { makeStyles } from "@saleor/macaw-ui"; - -export const useAccordionStyles = makeStyles( - () => ({ - summaryContent: { - paddingTop: 0, - }, - }), - { name: "VariantDetailsChannelsAvailabilityCard" }, -); - -export const useExpanderStyles = makeStyles( - () => ({ - expanded: {}, - root: { - boxShadow: "none", - margin: 0, - padding: 0, - - "&:before": { - content: "none", - }, - - "&$expanded": { - margin: 0, - border: "none", - }, - }, - }), - { name: "VariantDetailsChannelsAvailabilityCardExpander" }, -); - -export const useSummaryStyles = makeStyles( - () => ({ - expanded: {}, - root: { - width: "100%", - border: "none", - margin: 0, - padding: 0, - minHeight: 0, - - "&$expanded": { - minHeight: 0, - }, - }, - content: { - margin: 0, - - "&$expanded": { - margin: 0, - }, - }, - }), - { name: "VariantDetailsChannelsAvailabilityCardExpanderSummary" }, -);