@graphcommerce/ecommerce-ui 1.0.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.
- package/CHANGELOG.md +43 -0
- package/README.md +4 -0
- package/components/ApolloError/ApolloErrorAlert.tsx +58 -0
- package/components/ApolloError/ApolloErrorFullPage.tsx +31 -0
- package/components/ApolloError/ApolloErrorSnackbar.tsx +35 -0
- package/components/ApolloError/index.ts +3 -0
- package/components/ComposedSubmitButton/ComposedSubmitButton.tsx +36 -0
- package/components/ComposedSubmitButton/ComposedSubmitLinkOrButton.tsx +32 -0
- package/components/ComposedSubmitButton/index.ts +2 -0
- package/components/index.ts +2 -0
- package/index.ts +2 -0
- package/package.json +33 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @graphcommerce/ecommerce-ui
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
### Major Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#1274](https://github.com/ho-nl/m2-pwa/pull/1274) [`351347afe`](https://github.com/ho-nl/m2-pwa/commit/351347afeae5bd837408d46c7593bcf5473dc621) Thanks [@paales](https://github.com/paales)! - Created new `@graphcommerce/ecommerce-ui` package to connect generic components
|
|
9
|
+
from `@graphcommerce/next-ui` to `@graphcommerce/react-hook-form` and
|
|
10
|
+
`@graphcommerce/graphql`
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
- [#1274](https://github.com/ho-nl/m2-pwa/pull/1274) [`381e4c86a`](https://github.com/ho-nl/m2-pwa/commit/381e4c86a8321ce96e1fa5c7d3c0a0c0ff3e02c7) Thanks [@paales](https://github.com/paales)! - Moved `ApolloErrorAlert`, `ApolloErrorFullPage` and `ApolloErrorSnackbar` to the
|
|
17
|
+
ecommerce-ui package.
|
|
18
|
+
|
|
19
|
+
Created `ComposedSubmitButton` and `ComposedSubmitLinkOrButton` to reduce
|
|
20
|
+
complexity from `magento-graphcms` example.
|
|
21
|
+
|
|
22
|
+
Removed dependency an `@graphcommerce/react-hook-form` from `magento-graphcms`
|
|
23
|
+
example.
|
|
24
|
+
|
|
25
|
+
Added dependency `@graphcommerce/ecommerce-ui` from `magento-graphcms` example.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
- [#1276](https://github.com/ho-nl/m2-pwa/pull/1276) [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2) Thanks [@paales](https://github.com/paales)! - We've moved lots of internal packages from `dependencies` to `peerDependencies`.
|
|
29
|
+
The result of this is that there will be significantly less duplicate packages
|
|
30
|
+
in the node_modules folders.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
- [#1276](https://github.com/ho-nl/m2-pwa/pull/1276) [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d) Thanks [@paales](https://github.com/paales)! - Upgraded to [NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for
|
|
34
|
+
compatibility, but we'll be implementing
|
|
35
|
+
[On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta)
|
|
36
|
+
soon.
|
|
37
|
+
|
|
38
|
+
This will greatly reduce the requirement to rebuid stuff and we'll add a
|
|
39
|
+
management UI on the frontend to be able to revalidate pages manually.
|
|
40
|
+
- Updated dependencies [[`381e4c86a`](https://github.com/ho-nl/m2-pwa/commit/381e4c86a8321ce96e1fa5c7d3c0a0c0ff3e02c7), [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2), [`e7c8e2756`](https://github.com/ho-nl/m2-pwa/commit/e7c8e2756d637cbcd2e793d62ef5721d35d9fa7b), [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)]:
|
|
41
|
+
- @graphcommerce/next-ui@4.1.1
|
|
42
|
+
- @graphcommerce/react-hook-form@3.0.2
|
|
43
|
+
- @graphcommerce/graphql@3.0.2
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
+
import { AnimatedRow } from '@graphcommerce/next-ui/AnimatedRow'
|
|
3
|
+
import { extendableComponent } from '@graphcommerce/next-ui/Styles/extendableComponent'
|
|
4
|
+
import { AlertProps, Alert, Box, SxProps, Theme } from '@mui/material'
|
|
5
|
+
import { AnimatePresence } from 'framer-motion'
|
|
6
|
+
|
|
7
|
+
const { classes, selectors } = extendableComponent('ApolloErrorAlert', ['root', 'alert'] as const)
|
|
8
|
+
|
|
9
|
+
export type ApolloErrorAlertProps = {
|
|
10
|
+
error?: ApolloError
|
|
11
|
+
graphqlErrorAlertProps?: Omit<AlertProps, 'severity'>
|
|
12
|
+
networkErrorAlertProps?: Omit<AlertProps, 'severity'>
|
|
13
|
+
sx?: SxProps<Theme>
|
|
14
|
+
}
|
|
15
|
+
export function ApolloErrorAlert(props: ApolloErrorAlertProps) {
|
|
16
|
+
const { error, graphqlErrorAlertProps, networkErrorAlertProps, sx } = props
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<AnimatePresence initial={false}>
|
|
20
|
+
{error && (
|
|
21
|
+
<AnimatedRow key='alerts'>
|
|
22
|
+
<Box sx={sx} className={classes.root}>
|
|
23
|
+
<AnimatePresence initial={false}>
|
|
24
|
+
{error.graphQLErrors.map((e, index) => (
|
|
25
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
26
|
+
<AnimatedRow key={index}>
|
|
27
|
+
<div className={classes.alert}>
|
|
28
|
+
<Alert severity='error' {...graphqlErrorAlertProps}>
|
|
29
|
+
{e.message}
|
|
30
|
+
</Alert>
|
|
31
|
+
</div>
|
|
32
|
+
</AnimatedRow>
|
|
33
|
+
))}
|
|
34
|
+
{error.networkError && (
|
|
35
|
+
<AnimatedRow key='networkError'>
|
|
36
|
+
<Box
|
|
37
|
+
sx={(theme) => ({
|
|
38
|
+
paddingTop: theme.spacings.xxs,
|
|
39
|
+
paddingBottom: theme.spacings.xxs,
|
|
40
|
+
})}
|
|
41
|
+
className={classes.alert}
|
|
42
|
+
key='networkError'
|
|
43
|
+
>
|
|
44
|
+
<Alert severity='error' {...networkErrorAlertProps}>
|
|
45
|
+
Network Error: {error.networkError.message}
|
|
46
|
+
</Alert>
|
|
47
|
+
</Box>
|
|
48
|
+
</AnimatedRow>
|
|
49
|
+
)}
|
|
50
|
+
</AnimatePresence>
|
|
51
|
+
</Box>
|
|
52
|
+
</AnimatedRow>
|
|
53
|
+
)}
|
|
54
|
+
</AnimatePresence>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ApolloErrorAlert.selectors = selectors
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
+
import { FullPageMessage, FullPageMessageProps } from '@graphcommerce/next-ui/FullPageMessage'
|
|
3
|
+
import { AlertProps } from '@mui/material'
|
|
4
|
+
import { ApolloErrorAlert } from './ApolloErrorAlert'
|
|
5
|
+
|
|
6
|
+
export type ApolloErrorFullPageProps = {
|
|
7
|
+
error?: ApolloError
|
|
8
|
+
graphqlErrorAlertProps?: Omit<AlertProps, 'severity'>
|
|
9
|
+
networkErrorAlertProps?: Omit<AlertProps, 'severity'>
|
|
10
|
+
} & Omit<FullPageMessageProps, 'title' | 'description'>
|
|
11
|
+
|
|
12
|
+
export function ApolloErrorFullPage(props: ApolloErrorFullPageProps) {
|
|
13
|
+
const {
|
|
14
|
+
error,
|
|
15
|
+
graphqlErrorAlertProps,
|
|
16
|
+
networkErrorAlertProps,
|
|
17
|
+
children,
|
|
18
|
+
...fullPageMessageProps
|
|
19
|
+
} = props
|
|
20
|
+
|
|
21
|
+
const singleError = error?.graphQLErrors.length === 1
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<FullPageMessage
|
|
25
|
+
title={singleError ? error?.graphQLErrors[0].message : 'Several errors occured'}
|
|
26
|
+
{...fullPageMessageProps}
|
|
27
|
+
>
|
|
28
|
+
{singleError ? children : <ApolloErrorAlert error={error} />}
|
|
29
|
+
</FullPageMessage>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ApolloError } from '@graphcommerce/graphql'
|
|
2
|
+
import { MessageSnackbar } from '@graphcommerce/next-ui/Snackbar/MessageSnackbar'
|
|
3
|
+
import { MessageSnackbarImplProps } from '@graphcommerce/next-ui/Snackbar/MessageSnackbarImpl'
|
|
4
|
+
import { Trans } from '@lingui/macro'
|
|
5
|
+
import { Button } from '@mui/material'
|
|
6
|
+
|
|
7
|
+
export type ApolloErrorSnackbarProps = {
|
|
8
|
+
error?: ApolloError
|
|
9
|
+
} & Pick<MessageSnackbarImplProps, 'action' | 'onClose'>
|
|
10
|
+
|
|
11
|
+
export function ApolloErrorSnackbar(props: ApolloErrorSnackbarProps) {
|
|
12
|
+
const { error, action, ...passedProps } = props
|
|
13
|
+
|
|
14
|
+
if (!error) return null
|
|
15
|
+
return (
|
|
16
|
+
<MessageSnackbar
|
|
17
|
+
variant='pill'
|
|
18
|
+
severity='error'
|
|
19
|
+
{...passedProps}
|
|
20
|
+
open={!!error}
|
|
21
|
+
action={
|
|
22
|
+
action ?? (
|
|
23
|
+
<Button size='medium' variant='pill' color='secondary'>
|
|
24
|
+
<Trans>Ok</Trans>
|
|
25
|
+
</Button>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
<>
|
|
30
|
+
{error.graphQLErrors.map((e) => e.message)}
|
|
31
|
+
{error.networkError && <>Network Error: {error.networkError.message}</>}
|
|
32
|
+
</>
|
|
33
|
+
</MessageSnackbar>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
iconChevronRight,
|
|
3
|
+
LinkOrButton,
|
|
4
|
+
LinkOrButtonProps,
|
|
5
|
+
SvgIcon,
|
|
6
|
+
Button,
|
|
7
|
+
ButtonProps,
|
|
8
|
+
} from '@graphcommerce/next-ui'
|
|
9
|
+
import { ComposedSubmitRenderComponentProps } from '@graphcommerce/react-hook-form'
|
|
10
|
+
import { forwardRef } from 'react'
|
|
11
|
+
|
|
12
|
+
type ComposedSubmitButtonProps = ComposedSubmitRenderComponentProps &
|
|
13
|
+
Omit<ButtonProps, 'loading' | 'onSubmit'>
|
|
14
|
+
|
|
15
|
+
/** Makes a ComposedSubmitRenderComponent rendered as a LinkOrButton */
|
|
16
|
+
export const ComposedSubmitButton = forwardRef<HTMLButtonElement, ComposedSubmitButtonProps>(
|
|
17
|
+
({ buttonState, submit, error, children, ...otherProps }, ref) => {
|
|
18
|
+
const loading =
|
|
19
|
+
buttonState.isSubmitting || (buttonState.isSubmitSuccessful && !error) ? true : undefined
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Button
|
|
23
|
+
ref={ref}
|
|
24
|
+
color='secondary'
|
|
25
|
+
variant='pill'
|
|
26
|
+
endIcon={<SvgIcon src={iconChevronRight} />}
|
|
27
|
+
type='submit'
|
|
28
|
+
{...otherProps}
|
|
29
|
+
loading={loading}
|
|
30
|
+
onClick={submit}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</Button>
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { iconChevronRight, LinkOrButton, LinkOrButtonProps, SvgIcon } from '@graphcommerce/next-ui'
|
|
2
|
+
import { ComposedSubmitRenderComponentProps } from '@graphcommerce/react-hook-form'
|
|
3
|
+
import { forwardRef } from 'react'
|
|
4
|
+
|
|
5
|
+
type ComposedLinkOrButtonProps = ComposedSubmitRenderComponentProps &
|
|
6
|
+
Omit<LinkOrButtonProps, 'loading'>
|
|
7
|
+
|
|
8
|
+
/** Makes a ComposedSubmitRenderComponent rendered as a LinkOrButton */
|
|
9
|
+
export const ComposedSubmitLinkOrButton = forwardRef<
|
|
10
|
+
HTMLButtonElement & HTMLAnchorElement,
|
|
11
|
+
ComposedLinkOrButtonProps
|
|
12
|
+
>(({ buttonState, submit, error, children, button, ...otherProps }, ref) => {
|
|
13
|
+
const loading =
|
|
14
|
+
buttonState.isSubmitting || (buttonState.isSubmitSuccessful && !error) ? true : undefined
|
|
15
|
+
return (
|
|
16
|
+
<LinkOrButton
|
|
17
|
+
ref={ref}
|
|
18
|
+
button={{
|
|
19
|
+
variant: 'pill',
|
|
20
|
+
endIcon: <SvgIcon src={iconChevronRight} />,
|
|
21
|
+
...button,
|
|
22
|
+
type: 'submit',
|
|
23
|
+
}}
|
|
24
|
+
loading={loading}
|
|
25
|
+
color='secondary'
|
|
26
|
+
onClick={submit}
|
|
27
|
+
{...otherProps}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</LinkOrButton>
|
|
31
|
+
)
|
|
32
|
+
})
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/ecommerce-ui",
|
|
3
|
+
"homepage": "https://www.graphcommerce.org/",
|
|
4
|
+
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
|
+
"eslintConfig": {
|
|
9
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
10
|
+
"parserOptions": {
|
|
11
|
+
"project": "./tsconfig.json"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@graphcommerce/next-ui": "^4.1.1",
|
|
16
|
+
"@graphcommerce/react-hook-form": "^3.0.2",
|
|
17
|
+
"@graphcommerce/graphql": "^3.0.2"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@graphcommerce/eslint-config-pwa": "^4.0.2",
|
|
21
|
+
"@graphcommerce/prettier-config-pwa": "^4.0.1",
|
|
22
|
+
"@graphcommerce/typescript-config-pwa": "^4.0.1",
|
|
23
|
+
"@playwright/test": "^1.19.1"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@mui/material": "^5.4.1",
|
|
27
|
+
"@lingui/macro": "^3.13.2",
|
|
28
|
+
"framer-motion": "^6.2.4",
|
|
29
|
+
"next": "^12.0.10",
|
|
30
|
+
"react": "^17.0.2",
|
|
31
|
+
"react-dom": "^17.0.2"
|
|
32
|
+
}
|
|
33
|
+
}
|