@graphcommerce/graphql 9.0.0-canary.99 → 9.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.
@@ -1,92 +0,0 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- import { cssFlag, cssNotFlag, useIsSSR } from '@graphcommerce/next-ui'
3
- import { Box, Skeleton, SkeletonOwnProps, SkeletonProps, SxProps, Theme } from '@mui/material'
4
- import type { OverrideProps } from '@mui/material/OverridableComponent'
5
- import React, { createContext, useContext, useMemo } from 'react'
6
-
7
- type MaskProp = { skeleton?: SkeletonProps }
8
-
9
- interface InContextMaskTypeMap<
10
- AdditionalProps = MaskProp,
11
- RootComponent extends React.ElementType = 'div',
12
- > {
13
- props: AdditionalProps & SkeletonOwnProps
14
- defaultComponent: RootComponent
15
- }
16
-
17
- export type InContextMaskProps<
18
- RootComponent extends React.ElementType = InContextMaskTypeMap['defaultComponent'],
19
- AdditionalProps = MaskProp,
20
- > = OverrideProps<InContextMaskTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
21
- component?: React.ElementType
22
- }
23
-
24
- type InContextMaskContextType = { mask: boolean }
25
-
26
- export const InContextMaskContext = createContext<InContextMaskContextType | undefined>(undefined)
27
-
28
- export function useInContextInputMask(): InContextMaskContextType {
29
- const context = useContext(InContextMaskContext)
30
-
31
- // eslint-disable-next-line react-hooks/rules-of-hooks
32
- const isSSR = process.env.NODE_ENV === 'development' ? useIsSSR() : false
33
-
34
- if (!context) {
35
- if (isSSR)
36
- console.warn(
37
- "useInContextInputMask was used without a InContextMaskProvider, this means that customer specific pricing probably isn't working.",
38
- )
39
-
40
- return { mask: false }
41
- }
42
- return context
43
- }
44
-
45
- export function InContextMaskProvider(props: { mask: boolean; children: React.ReactNode }) {
46
- const { mask = false, children } = props
47
- return (
48
- <InContextMaskContext.Provider value={useMemo(() => ({ mask }), [mask])}>
49
- {children}
50
- </InContextMaskContext.Provider>
51
- )
52
- }
53
-
54
- export function useInContextInputMaskSx(props: { sx?: SxProps<Theme>; skeleton?: SkeletonProps }) {
55
- const { sx = [], skeleton } = props
56
- const { mask } = useInContextInputMask()
57
-
58
- return {
59
- mask,
60
- componentSx: [
61
- mask && {
62
- [cssFlag('in-context')]: { display: 'none' },
63
- },
64
- ...(Array.isArray(sx) ? sx : [sx]),
65
- ],
66
- maskSx: [
67
- {
68
- display: 'inline-block',
69
- [cssNotFlag('in-context')]: { display: 'none' },
70
- },
71
- ...(Array.isArray(sx) ? sx : [sx]),
72
- ...(Array.isArray(skeleton?.sx) ? skeleton.sx : [skeleton?.sx]),
73
- ],
74
- }
75
- }
76
-
77
- /**
78
- * A component that renders a skeleton mask when the user is signed in.
79
- */
80
- export function InContextMask(props: InContextMaskProps) {
81
- const { skeleton, children, ...rest } = props
82
- const { mask, componentSx, maskSx } = useInContextInputMaskSx(props)
83
-
84
- return (
85
- <>
86
- <Box {...rest} sx={componentSx}>
87
- {children}
88
- </Box>
89
- {mask && <Skeleton {...rest} {...skeleton} sx={maskSx} />}
90
- </>
91
- )
92
- }
@@ -1,17 +0,0 @@
1
- import { ApolloClient } from '@apollo/client'
2
- import type { InContextInput } from '@graphcommerce/graphql-mesh'
3
-
4
- export function getInContextInput(client: ApolloClient<any>): InContextInput | null {
5
- return null
6
- }
7
-
8
- /**
9
- * Defines a method to handle the current context for the query.
10
- *
11
- * Other plugins should be able to define their own scopes and create a plugin on this method to augment the specific scope.
12
- *
13
- * @see @graphcommerce/magento-customer/plugins/magentoCustomerGetInContext.ts
14
- *
15
- * Note: ONLY return a value if the frontend should use the inContext directive.
16
- */
17
- export const useInContextInput = (): InContextInput | null => null