@graphcommerce/magento-cart 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { ApolloErrorFullPage, ApolloErrorFullPageProps } from '@graphcommerce/ecommerce-ui'
2
2
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
3
- import { iconSadFace, SvgIcon } from '@graphcommerce/next-ui'
3
+ import { iconSadFace, IconSvg } from '@graphcommerce/next-ui'
4
4
  import { Button } from '@mui/material'
5
5
  import { useClearCurrentCartId } from '../../hooks/useClearCurrentCartId'
6
6
 
@@ -16,7 +16,7 @@ export function ApolloCartErrorFullPage(props: ApolloCartErrorFullPageProps) {
16
16
  return (
17
17
  <ApolloErrorFullPage
18
18
  error={error}
19
- icon={<SvgIcon src={iconSadFace} size='xxl' />}
19
+ icon={<IconSvg src={iconSadFace} size='xxl' />}
20
20
  button={action}
21
21
  {...passedProps}
22
22
  />
@@ -5,7 +5,7 @@ import { CartAddressFragment } from '../CartAddress/CartAddress.gql'
5
5
 
6
6
  export type CartAddressMultiLineProps = Partial<CartAddressFragment>
7
7
 
8
- export default function CartAddressMultiLine(props: CartAddressMultiLineProps) {
8
+ export function CartAddressMultiLine(props: CartAddressMultiLineProps) {
9
9
  const { country, region, ...addressProps } = props
10
10
  return (
11
11
  <AddressMultiLine
@@ -5,7 +5,7 @@ import { CartAddressFragment } from '../CartAddress/CartAddress.gql'
5
5
 
6
6
  export type CartAddressSingleLineProps = CartAddressFragment & { locale?: CountryCodeEnum }
7
7
 
8
- export default function CartAddressSingleLine(props: CartAddressSingleLineProps) {
8
+ export function CartAddressSingleLine(props: CartAddressSingleLineProps) {
9
9
  const { locale } = props
10
10
  return <AddressSingleLine {...props} country_code={locale} />
11
11
  }
@@ -24,12 +24,12 @@ import { CartAgreementsDocument } from './CartAgreements.gql'
24
24
 
25
25
  export type CartAgreementsFormProps = Pick<UseFormComposeOptions, 'step'> & { sx?: SxProps<Theme> }
26
26
 
27
- const name = 'CartAgreementsForm' as const
27
+ const componentName = 'CartAgreementsForm' as const
28
28
  const parts = ['form', 'formInner', 'formControlRoot', 'manualCheck'] as const
29
- const { classes } = extendableComponent(name, parts)
29
+ const { classes } = extendableComponent(componentName, parts)
30
30
 
31
- export default function CartAgreementsForm(props: CartAgreementsFormProps) {
32
- const { step } = props
31
+ export function CartAgreementsForm(props: CartAgreementsFormProps) {
32
+ const { step, sx = [] } = props
33
33
  const { data } = useQuery(CartAgreementsDocument)
34
34
 
35
35
  // sort conditions so checkboxes will be placed first
@@ -51,7 +51,10 @@ export default function CartAgreementsForm(props: CartAgreementsFormProps) {
51
51
  useFormCompose({ form, step, submit, key: 'PaymentAgreementsForm' })
52
52
 
53
53
  return (
54
- <FormDiv className={classes.form} sx={(theme) => ({ pt: theme.spacings.md })}>
54
+ <FormDiv
55
+ className={classes.form}
56
+ sx={[(theme) => ({ pt: theme.spacings.md }), ...(Array.isArray(sx) ? sx : [sx])]}
57
+ >
55
58
  <form noValidate onSubmit={submit} name='cartAgreements'>
56
59
  <Box className={classes.formInner} sx={{ typography: 'body1', display: 'inline-block' }}>
57
60
  {data?.checkoutAgreements &&
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  extendableComponent,
3
3
  iconShoppingBag,
4
- responsiveVal,
5
4
  DesktopHeaderBadge,
6
- SvgIcon,
5
+ IconSvg,
7
6
  useScrollY,
7
+ useFabSize,
8
8
  } from '@graphcommerce/next-ui'
9
9
  import { t } from '@lingui/macro'
10
10
  import { alpha, Fab, FabProps, NoSsr, styled, useTheme, Box, SxProps, Theme } from '@mui/material'
@@ -18,13 +18,14 @@ import { CartTotalQuantityFragment } from './CartTotalQuantity.gql'
18
18
  export type CartFabProps = {
19
19
  icon?: React.ReactNode
20
20
  sx?: SxProps<Theme>
21
- }
21
+ } & Pick<FabProps, 'color' | 'size' | 'variant'>
22
22
 
23
23
  type CartFabContentProps = CartFabProps & CartTotalQuantityFragment
24
24
 
25
25
  const MotionDiv = styled(m.div)({})
26
26
 
27
27
  const MotionFab = m(
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
29
  React.forwardRef<any, Omit<FabProps, 'style' | 'onDrag'>>((props, ref) => (
29
30
  <Fab {...props} ref={ref} />
30
31
  )),
@@ -43,8 +44,8 @@ function CartFabContent(props: CartFabContentProps) {
43
44
  const paper1 = alpha(theme2.palette.background.paper, 1)
44
45
  const backgroundColor = useTransform(scrollY, [0, 10], [paper0, paper1])
45
46
 
46
- const cartIcon = icon ?? <SvgIcon src={iconShoppingBag} size='large' />
47
- const fabIconSize = responsiveVal(42, 56) // @todo generalize this
47
+ const cartIcon = icon ?? <IconSvg src={iconShoppingBag} size='large' />
48
+ const fabIconSize = useFabSize('responsive')
48
49
 
49
50
  return (
50
51
  <Box
@@ -57,18 +58,16 @@ function CartFabContent(props: CartFabContentProps) {
57
58
  <PageLink href='/cart' passHref>
58
59
  <MotionFab
59
60
  className={classes.cart}
60
- {...fabProps}
61
61
  aria-label={t`Cart`}
62
62
  color='inherit'
63
- size='large'
63
+ size='responsive'
64
64
  style={{ backgroundColor }}
65
65
  sx={(theme) => ({
66
- width: fabIconSize,
67
- height: fabIconSize,
68
66
  [theme.breakpoints.down('md')]: {
69
67
  backgroundColor: `${theme.palette.background.paper} !important`,
70
68
  },
71
69
  })}
70
+ {...fabProps}
72
71
  >
73
72
  {total_quantity > 0 ? (
74
73
  <DesktopHeaderBadge color='primary' variant='dot' overlap='circular'>
@@ -87,7 +86,7 @@ function CartFabContent(props: CartFabContentProps) {
87
86
  position: 'absolute',
88
87
  height: '100%',
89
88
  width: '100%',
90
- boxShadow: theme.shadows[6],
89
+ boxShadow: 6,
91
90
  top: 0,
92
91
  [theme.breakpoints.down('md')]: {
93
92
  opacity: '1 !important',
@@ -109,7 +108,7 @@ function CartFabContent(props: CartFabContentProps) {
109
108
  * immediately start fetching. Why? There is a time between creating a cart and adding the first
110
109
  * product to the cart. This would mean that it would immediately start executing this query.
111
110
  */
112
- export default function CartFab(props: CartFabProps) {
111
+ export function CartFab(props: CartFabProps) {
113
112
  const { data } = useCartQuery(CartFabDocument, {
114
113
  fetchPolicy: 'cache-only',
115
114
  nextFetchPolicy: 'cache-first',
@@ -5,14 +5,14 @@ import {
5
5
  iconChevronRight,
6
6
  responsiveVal,
7
7
  SectionContainer,
8
- SvgIcon,
8
+ IconSvg,
9
9
  extendableComponent,
10
10
  } from '@graphcommerce/next-ui'
11
11
  import { Trans } from '@lingui/macro'
12
12
  import { Box, Divider, SxProps, Theme } from '@mui/material'
13
13
  import React from 'react'
14
14
  import { useCartQuery } from '../../hooks'
15
- import CartTotals from '../CartTotals/CartTotals'
15
+ import { CartTotals } from '../CartTotals/CartTotals'
16
16
  import { CartItemSummaryDocument } from './GetCartItemSummary.gql'
17
17
 
18
18
  const name = 'CartItemSummary' as const
@@ -32,7 +32,7 @@ const { classes } = extendableComponent(name, parts)
32
32
 
33
33
  type OrderSummaryProps = { sx?: SxProps<Theme> }
34
34
 
35
- export default function CartItemSummary(props: OrderSummaryProps) {
35
+ export function CartItemSummary(props: OrderSummaryProps) {
36
36
  const { sx = [] } = props
37
37
  const { data } = useCartQuery(CartItemSummaryDocument, { allowUrl: true })
38
38
 
@@ -83,7 +83,7 @@ export default function CartItemSummary(props: OrderSummaryProps) {
83
83
  left: 8,
84
84
  }}
85
85
  >
86
- <SvgIcon src={iconChevronLeft} />
86
+ <IconSvg src={iconChevronLeft} />
87
87
  </ScrollerButton>
88
88
  <Box className={classes.scrollerContainer} sx={{ padding: '1px' }}>
89
89
  <Scroller className={classes.scroller}>
@@ -125,7 +125,7 @@ export default function CartItemSummary(props: OrderSummaryProps) {
125
125
  right: 8,
126
126
  }}
127
127
  >
128
- <SvgIcon src={iconChevronRight} />
128
+ <IconSvg src={iconChevronRight} />
129
129
  </ScrollerButton>
130
130
  </ScrollerProvider>
131
131
  </Box>
@@ -1,5 +1,5 @@
1
1
  import { Money } from '@graphcommerce/magento-store'
2
- import { iconChevronRight, SvgIcon, extendableComponent } from '@graphcommerce/next-ui'
2
+ import { iconChevronRight, IconSvg, extendableComponent } from '@graphcommerce/next-ui'
3
3
  import { Trans } from '@lingui/macro'
4
4
  import { Box, Button, SxProps, Theme } from '@mui/material'
5
5
  import PageLink from 'next/link'
@@ -19,7 +19,7 @@ const parts = [
19
19
  ] as const
20
20
  const { classes } = extendableComponent(name, parts)
21
21
 
22
- export default function CartStartCheckout(props: CartStartCheckoutProps) {
22
+ export function CartStartCheckout(props: CartStartCheckoutProps) {
23
23
  const { prices, children, sx = [] } = props
24
24
 
25
25
  const hasTotals = (prices?.grand_total?.value ?? 0) > 0
@@ -34,7 +34,7 @@ export default function CartStartCheckout(props: CartStartCheckoutProps) {
34
34
  color='secondary'
35
35
  size='large'
36
36
  className={classes.checkoutButton}
37
- endIcon={<SvgIcon src={iconChevronRight} />}
37
+ endIcon={<IconSvg src={iconChevronRight} />}
38
38
  disabled={!hasTotals}
39
39
  sx={(theme) => ({
40
40
  marginTop: theme.spacings.md,
@@ -5,7 +5,7 @@ import { Box, Link, SxProps, Theme, Typography } from '@mui/material'
5
5
  import PageLink from 'next/link'
6
6
  import React from 'react'
7
7
  import { useCartQuery } from '../../hooks'
8
- import CartAddressMultiLine from '../CartAddressMultiLine'
8
+ import { CartAddressMultiLine } from '../CartAddressMultiLine/CartAddressMultiLine'
9
9
  import { GetCartSummaryDocument } from './GetCartSummary.gql'
10
10
 
11
11
  export type CartSummaryProps = {
@@ -19,7 +19,7 @@ const compName = 'CartSummary' as const
19
19
  const parts = ['root', 'detailsContainer', 'sectionHeaderWrapper'] as const
20
20
  const { classes } = extendableComponent<OwnerState, typeof compName, typeof parts>(compName, parts)
21
21
 
22
- export default function CartSummary(props: CartSummaryProps) {
22
+ export function CartSummary(props: CartSummaryProps) {
23
23
  const { children, editable } = props
24
24
 
25
25
  const { data } = useCartQuery(GetCartSummaryDocument, { allowUrl: true })
@@ -27,7 +27,7 @@ const { withState } = extendableComponent<OwnerProps, typeof name, typeof parts>
27
27
  *
28
28
  * @see https://github.com/magento/magento2/issues/33848
29
29
  */
30
- export default function CartTotals(props: CartTotalsProps) {
30
+ export function CartTotals(props: CartTotalsProps) {
31
31
  const { data } = useCartQuery(GetCartTotalsDocument, { allowUrl: true })
32
32
  const { containerMargin, sx = [] } = props
33
33
 
@@ -95,11 +95,11 @@ export default function CartTotals(props: CartTotalsProps) {
95
95
  return (
96
96
  <AnimatedRow
97
97
  key={discount?.label}
98
- sx={(theme) => ({
98
+ sx={{
99
99
  display: 'flex',
100
100
  justifyContent: 'space-between',
101
101
  typography: 'subtitle1',
102
- })}
102
+ }}
103
103
  >
104
104
  <Box>{discount?.label}</Box>
105
105
  <Box className={classes.money} sx={{ whiteSpace: 'nowrap' }}>
@@ -1,17 +1,17 @@
1
- import { FullPageMessage, SvgIcon, iconShoppingBag } from '@graphcommerce/next-ui'
1
+ import { FullPageMessage, IconSvg, iconShoppingBag } from '@graphcommerce/next-ui'
2
2
  import { Trans } from '@lingui/macro'
3
3
  import { Button } from '@mui/material'
4
4
  import Link from 'next/link'
5
5
  import React from 'react'
6
6
 
7
7
  type EmptyCartProps = { children?: React.ReactNode }
8
- export default function EmptyCart(props: EmptyCartProps) {
8
+ export function EmptyCart(props: EmptyCartProps) {
9
9
  const { children } = props
10
10
 
11
11
  return (
12
12
  <FullPageMessage
13
13
  title={<Trans>Your cart is empty</Trans>}
14
- icon={<SvgIcon src={iconShoppingBag} size='xxl' />}
14
+ icon={<IconSvg src={iconShoppingBag} size='xxl' />}
15
15
  button={
16
16
  <Link href='/' passHref>
17
17
  <Button variant='pill' color='secondary' size='large'>
@@ -22,7 +22,7 @@ const name = 'InlineAccount' as const
22
22
  const parts = ['root', 'innerContainer', 'form', 'button', 'title'] as const
23
23
  const { classes } = extendableComponent(name, parts)
24
24
 
25
- export default function InlineAccount(props: InlineAccountProps) {
25
+ export function InlineAccount(props: InlineAccountProps) {
26
26
  const { title, description, accountHref, sx = [] } = props
27
27
 
28
28
  const [toggled, setToggled] = useState<boolean>(false)
@@ -1,30 +1,12 @@
1
+ export * from './ApolloCartError'
2
+ export * from './CartAddressMultiLine/CartAddressMultiLine'
3
+ export * from './CartAddressSingleLine/CartAddressSingleLine'
4
+ export * from './CartAgreementsForm/CartAgreements.gql'
5
+ export * from './CartAgreementsForm/CartAgreementsForm'
1
6
  export * from './CartFab/CartFab'
2
- export { default as CartFab } from './CartFab/CartFab'
3
-
7
+ export * from './CartItemSummary/CartItemSummary'
4
8
  export * from './CartStartCheckout/CartStartCheckout'
5
- export { default as CartStartCheckout } from './CartStartCheckout/CartStartCheckout'
6
-
9
+ export * from './CartSummary/CartSummary'
7
10
  export * from './CartTotals/CartTotals'
8
- export { default as CartTotals } from './CartTotals/CartTotals'
9
-
10
- export { default as EmptyCart } from './EmptyCart/EmptyCart'
11
-
12
- export * from './ApolloCartError'
13
-
14
- export * from './CartSummary'
15
- export { default as CartSummary } from './CartSummary'
16
-
17
- export { default as CartItemSummary } from './CartItemSummary'
18
-
19
- export * from './InlineAccount'
20
- export { default as InlineAccount } from './InlineAccount'
21
-
22
- export * from './CartAddressMultiLine'
23
- export { default as CartAddressMultiLine } from './CartAddressMultiLine'
24
-
25
- export * from './CartAddressSingleLine'
26
- export { default as CartAddressSingleLine } from './CartAddressSingleLine'
27
-
28
- export * from './CartAgreementsForm/CartAgreementsForm'
29
- export { default as CartAgreementsForm } from './CartAgreementsForm/CartAgreementsForm'
30
- export * from './CartAgreementsForm/CartAgreements.gql'
11
+ export * from './EmptyCart/EmptyCart'
12
+ export * from './InlineAccount/InlineAccount'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.1.2",
5
+ "version": "4.2.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,22 +12,22 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.0.3",
16
- "@graphcommerce/prettier-config-pwa": "^4.0.2",
15
+ "@graphcommerce/eslint-config-pwa": "^4.0.5",
16
+ "@graphcommerce/prettier-config-pwa": "^4.0.3",
17
17
  "@graphcommerce/typescript-config-pwa": "^4.0.2",
18
- "@playwright/test": "^1.19.1"
18
+ "@playwright/test": "^1.19.2"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "^1.0.1",
22
- "@graphcommerce/framer-next-pages": "^3.1.0",
23
- "@graphcommerce/framer-scroller": "^2.0.3",
24
- "@graphcommerce/graphql": "^3.0.3",
25
- "@graphcommerce/image": "^3.1.0",
26
- "@graphcommerce/magento-customer": "^4.1.2",
27
- "@graphcommerce/magento-graphql": "^3.0.3",
28
- "@graphcommerce/magento-store": "^4.0.3",
29
- "@graphcommerce/next-ui": "^4.1.2",
30
- "@graphcommerce/react-hook-form": "^3.0.3"
21
+ "@graphcommerce/ecommerce-ui": "^1.0.3",
22
+ "@graphcommerce/framer-next-pages": "^3.1.2",
23
+ "@graphcommerce/framer-scroller": "^2.1.0",
24
+ "@graphcommerce/graphql": "^3.0.4",
25
+ "@graphcommerce/image": "^3.1.1",
26
+ "@graphcommerce/magento-customer": "^4.1.5",
27
+ "@graphcommerce/magento-graphql": "^3.0.4",
28
+ "@graphcommerce/magento-store": "^4.1.3",
29
+ "@graphcommerce/next-ui": "^4.3.0",
30
+ "@graphcommerce/react-hook-form": "^3.0.4"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@lingui/macro": "^3.13.2",