-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ui: Added "textTransform: 'uppercase'" to Typography plugin for h1,2,3 cmmc: moved context to a dir at the top level CommerceContextValue now has the Service, and a CommerceUI store new useCommerceUI to access store
- Loading branch information
1 parent
fa83fc1
commit f4f33b5
Showing
21 changed files
with
7,410 additions
and
5,709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
action, | ||
computed, | ||
makeObservable, | ||
observable, | ||
} from 'mobx' | ||
|
||
interface CommerceUI { | ||
showBuyOptions: (skuPath: string) => void | ||
hideBuyOptions: () => void | ||
|
||
get buyOptionsShowing(): boolean | ||
|
||
get skuPath(): string | undefined | ||
clearSkuPath: () => void | ||
} | ||
|
||
class CommerceUIStore implements CommerceUI { | ||
|
||
_skuPath: string | undefined = undefined | ||
_optionsShowing: boolean = false | ||
|
||
constructor() { | ||
makeObservable(this, { | ||
_skuPath: observable, | ||
_optionsShowing: observable, | ||
showBuyOptions: action, | ||
hideBuyOptions: action, | ||
buyOptionsShowing: computed, | ||
skuPath: computed, | ||
clearSkuPath: action | ||
}) | ||
} | ||
|
||
showBuyOptions = (skuPath: string): void => { | ||
this._skuPath = skuPath | ||
this._optionsShowing = true | ||
} | ||
|
||
hideBuyOptions = (): void => { | ||
this._optionsShowing = false | ||
} | ||
|
||
get buyOptionsShowing(): boolean { | ||
return this._optionsShowing | ||
} | ||
|
||
get skuPath(): string | undefined { | ||
return this._skuPath | ||
} | ||
|
||
clearSkuPath = (): void => { | ||
this._skuPath = undefined | ||
this._optionsShowing = false | ||
} | ||
} | ||
|
||
export { | ||
CommerceUIStore, | ||
type CommerceUI | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use client' | ||
import React, { | ||
createContext, | ||
useContext, | ||
useRef, | ||
type PropsWithChildren | ||
} from 'react' | ||
|
||
// https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18 | ||
import { enableStaticRendering } from 'mobx-react-lite' | ||
enableStaticRendering(typeof window === "undefined") | ||
|
||
import type { ServiceOptions } from '..' | ||
import type CommerceService from '../types/commerce-service' | ||
import getInstance from '../service/get-instance' | ||
import type { Family, CategoryNode, SelectionUISpecifier } from '../types' | ||
import { type CommerceUI, CommerceUIStore } from './commerce-ui' | ||
|
||
type CommerceContextValue = { | ||
service: CommerceService | ||
ui: CommerceUI | ||
} | ||
|
||
const CommerceContext = createContext<CommerceContextValue | undefined>(undefined) | ||
|
||
const useCommerce = (): CommerceService => { | ||
return (useContext(CommerceContext) as CommerceContextValue)?.service | ||
} | ||
|
||
const useCommerceUI = (): CommerceUI => { | ||
return (useContext(CommerceContext) as CommerceContextValue)?.ui | ||
} | ||
|
||
const CommerceProvider: React.FC<PropsWithChildren & { | ||
families: Family[] | ||
rootNode: CategoryNode | ||
options?: ServiceOptions | ||
uiSpecs?: Record<string, SelectionUISpecifier> | ||
}> = ({ | ||
children, | ||
families, | ||
rootNode, | ||
options, | ||
uiSpecs | ||
}) => { | ||
|
||
// TODO: Inject Promo fixture here from siteDef | ||
const serviceRef = useRef<CommerceContextValue>({ | ||
service: getInstance(families, rootNode, options, uiSpecs), | ||
ui: new CommerceUIStore() | ||
}) | ||
return ( | ||
<CommerceContext.Provider value={serviceRef.current}> | ||
{children} | ||
</CommerceContext.Provider> | ||
) | ||
} | ||
|
||
export { | ||
useCommerce, | ||
useCommerceUI, | ||
CommerceProvider | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.