@graphcommerce/magento-product-grouped 8.1.0-canary.17 → 8.1.0-canary.19

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.1.0-canary.19
4
+
5
+ ## 8.1.0-canary.18
6
+
3
7
  ## 8.1.0-canary.17
4
8
 
5
9
  ## 8.1.0-canary.16
@@ -0,0 +1,11 @@
1
+ fragment GroupedProduct on GroupedProduct {
2
+ items {
3
+ position
4
+ qty
5
+ product {
6
+ uid
7
+ __typename
8
+ ...ProductListItem
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,167 @@
1
+ import { NumberFieldElement } from '@graphcommerce/ecommerce-ui'
2
+ import { Image } from '@graphcommerce/image'
3
+ import { ProductPageItemFragment } from '@graphcommerce/magento-product/Api/ProductPageItem.gql'
4
+ import {
5
+ AddToCartItemSelector,
6
+ useFormAddProductsToCart,
7
+ } from '@graphcommerce/magento-product/components'
8
+ import { Money } from '@graphcommerce/magento-store'
9
+ import { ActionCard, ActionCardProps, responsiveVal } from '@graphcommerce/next-ui'
10
+ import { Box, Link } from '@mui/material'
11
+
12
+ export type GroupedProductActionCardProps = ProductPageItemFragment &
13
+ Omit<ActionCardProps, 'value' | 'image' | 'price' | 'title' | 'action'> &
14
+ AddToCartItemSelector
15
+
16
+ export const productImageSizes = {
17
+ small: responsiveVal(60, 80),
18
+ medium: responsiveVal(60, 80),
19
+ large: responsiveVal(100, 120),
20
+ }
21
+
22
+ const typographySizes = {
23
+ small: 'body2',
24
+ medium: 'body1',
25
+ large: 'subtitle1',
26
+ }
27
+
28
+ export function GroupedProductActionCard(props: GroupedProductActionCardProps) {
29
+ const {
30
+ uid,
31
+ name,
32
+ small_image,
33
+ price_range,
34
+ url_key,
35
+ sx = [],
36
+ size = 'large',
37
+ index = 0,
38
+ sku,
39
+ url_rewrites,
40
+ ...rest
41
+ } = props
42
+
43
+ const { control, register } = useFormAddProductsToCart()
44
+ if (!sku) return null
45
+ const hasUrl = (url_rewrites ?? []).length > 0
46
+ return (
47
+ <>
48
+ <input type='hidden' {...register(`cartItems.${index}.sku`)} value={sku} />
49
+ <ActionCard
50
+ variant='default'
51
+ value={uid}
52
+ sx={[
53
+ (theme) => ({
54
+ '&.ActionCard-root': {
55
+ px: 0,
56
+ py: theme.spacings.xs,
57
+ },
58
+ '& .ActionCard-title': {
59
+ width: '100%',
60
+ },
61
+ '& .MuiBox-root': {
62
+ justifyContent: 'space-between',
63
+ alignItems: 'stretch',
64
+ },
65
+ '&.sizeSmall': {
66
+ px: 0,
67
+ },
68
+ '& .ActionCard-end': {
69
+ justifyContent: 'space-between',
70
+ },
71
+ '& .ActionCard-action': {
72
+ pr: theme.spacings.xs,
73
+ },
74
+ '& .ActionCard-image': {
75
+ alignSelf: 'flex-start',
76
+ },
77
+ '& .ActionCard-secondaryAction': {
78
+ typography: typographySizes[size],
79
+ display: 'flex',
80
+ alignItems: 'center',
81
+ color: 'text.secondary',
82
+ gap: '10px',
83
+ justifyContent: 'start',
84
+ },
85
+ '& .ActionCard-price': {
86
+ typography: typographySizes[size],
87
+ pr: theme.spacings.xs,
88
+ mb: { xs: 0.5, sm: 0 },
89
+ },
90
+ }),
91
+ ...(Array.isArray(sx) ? sx : [sx]),
92
+ ]}
93
+ image={
94
+ small_image?.url && (
95
+ <Image
96
+ layout='fill'
97
+ src={small_image?.url}
98
+ sx={{
99
+ width: productImageSizes[size],
100
+ height: productImageSizes[size],
101
+ display: 'block',
102
+ borderRadius: 1,
103
+ objectFit: 'contain',
104
+ }}
105
+ sizes={productImageSizes[size]}
106
+ />
107
+ )
108
+ }
109
+ title={
110
+ url_key && hasUrl ? (
111
+ <Link
112
+ href={url_key}
113
+ underline='hover'
114
+ sx={{
115
+ color: 'inherit',
116
+ flexWrap: 'nowrap',
117
+ maxWidth: 'max-content',
118
+ }}
119
+ >
120
+ {name}
121
+ </Link>
122
+ ) : (
123
+ name
124
+ )
125
+ }
126
+ secondaryAction={
127
+ <NumberFieldElement
128
+ size='small'
129
+ inputProps={{ min: 0 }}
130
+ defaultValue={1}
131
+ control={control}
132
+ sx={{
133
+ width: responsiveVal(80, 120),
134
+ mt: 2,
135
+ '& .MuiFormHelperText-root': {
136
+ margin: 1,
137
+ width: '100%',
138
+ },
139
+ }}
140
+ name={`cartItems.${index}.quantity`}
141
+ onMouseDown={(e) => e.stopPropagation()}
142
+ />
143
+ }
144
+ price={
145
+ <Box>
146
+ <Box>
147
+ <Money {...price_range.minimum_price.final_price} />
148
+ </Box>
149
+ {price_range.minimum_price.final_price.value !==
150
+ price_range.minimum_price.regular_price.value && (
151
+ <Box
152
+ component='span'
153
+ sx={{
154
+ textDecoration: 'line-through',
155
+ color: 'text.disabled',
156
+ }}
157
+ >
158
+ <Money {...price_range.minimum_price.regular_price} />
159
+ </Box>
160
+ )}
161
+ </Box>
162
+ }
163
+ {...rest}
164
+ />
165
+ </>
166
+ )
167
+ }
@@ -0,0 +1,30 @@
1
+ import { ActionCardLayout, filterNonNullableKeys } from '@graphcommerce/next-ui'
2
+ import { useMemo } from 'react'
3
+ import { ProductPageGroupedQueryFragment } from '../ProductPageGroupedQueryFragment.gql'
4
+ import { GroupedProductActionCard } from './GroupedProductActionCard'
5
+
6
+ type GroupedProductsProps = {
7
+ product: NonNullable<NonNullable<ProductPageGroupedQueryFragment['typeProducts']>['items']>[0]
8
+ }
9
+
10
+ export function GroupedProducts(props: GroupedProductsProps) {
11
+ const { product } = props
12
+ const productItems = useMemo(() => {
13
+ if (product?.__typename !== 'GroupedProduct') return null
14
+ const { items } = product
15
+ return filterNonNullableKeys(items, ['product']).map((item, i) => ({
16
+ ...item.product,
17
+ value: item.product.sku ?? '',
18
+ index: i,
19
+ }))
20
+ }, [product])
21
+ if (!productItems) return null
22
+
23
+ return (
24
+ <ActionCardLayout>
25
+ {productItems.map((item) => (
26
+ <GroupedProductActionCard {...item} key={item.value ?? ''} size='medium' />
27
+ ))}
28
+ </ActionCardLayout>
29
+ )
30
+ }
@@ -3,19 +3,7 @@ fragment ProductPageGroupedQueryFragment on Query {
3
3
  items {
4
4
  __typename
5
5
  uid
6
- ... on GroupedProduct {
7
- items {
8
- position
9
- qty
10
- product {
11
- uid
12
- __typename
13
- ...ProductListItem
14
- ...ProductListItemSimple
15
- ...ProductListItemVirtual
16
- }
17
- }
18
- }
6
+ ...GroupedProduct
19
7
  }
20
8
  }
21
9
  }
package/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './GroupedProductPage.gql'
2
2
  export * from './ProductListItemGrouped'
3
+ export * from './GroupedProducts/GroupedProducts'
4
+ export * from './GroupedProducts/GroupedProductActionCard'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product-grouped",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.17",
5
+ "version": "8.1.0-canary.19",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,17 +12,22 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.17",
16
- "@graphcommerce/graphql": "^8.1.0-canary.17",
17
- "@graphcommerce/magento-cart": "^8.1.0-canary.17",
18
- "@graphcommerce/magento-product": "^8.1.0-canary.17",
19
- "@graphcommerce/magento-product-simple": "^8.1.0-canary.17",
20
- "@graphcommerce/magento-product-virtual": "^8.1.0-canary.17",
21
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.17",
22
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.17",
15
+ "@graphcommerce/ecommerce-ui": "^8.1.0-canary.19",
16
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.19",
17
+ "@graphcommerce/graphql": "^8.1.0-canary.19",
18
+ "@graphcommerce/image": "^8.1.0-canary.19",
19
+ "@graphcommerce/magento-cart": "^8.1.0-canary.19",
20
+ "@graphcommerce/magento-product": "^8.1.0-canary.19",
21
+ "@graphcommerce/magento-product-simple": "^8.1.0-canary.19",
22
+ "@graphcommerce/magento-product-virtual": "^8.1.0-canary.19",
23
+ "@graphcommerce/magento-store": "^8.1.0-canary.19",
24
+ "@graphcommerce/next-ui": "^8.1.0-canary.19",
25
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.19",
26
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.19",
23
27
  "@lingui/core": "^4.2.1",
24
28
  "@lingui/macro": "^4.2.1",
25
29
  "@lingui/react": "^4.2.1",
30
+ "@mui/material": "5.15.17 ",
26
31
  "next": "*",
27
32
  "react": "^18.2.0",
28
33
  "react-dom": "^18.2.0"