Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StylisPlugins to OdysseyCacheProvider #1898

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,33 @@ declare global {
}
}

import createCache from "@emotion/cache";
import createCache, { StylisPlugin } from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import { memo, ReactElement, useMemo } from "react";
import { memo, ReactNode, useMemo } from "react";

import { useUniqueAlphabeticalId } from "./useUniqueAlphabeticalId";

export type OdysseyCacheProviderProps = {
children: ReactNode;
nonce?: string;
stylisPlugins?: StylisPlugin[];
};

const OdysseyCacheProvider = ({
children,
nonce,
}: {
children: ReactElement;
nonce?: string;
}) => {
stylisPlugins,
}: OdysseyCacheProviderProps) => {
const uniqueAlphabeticalId = useUniqueAlphabeticalId();

const emotionCache = useMemo(
() =>
createCache({
key: uniqueAlphabeticalId,
nonce: nonce || window.cspNonce,
stylisPlugins,
}),
[nonce, uniqueAlphabeticalId]
[nonce, stylisPlugins, uniqueAlphabeticalId]
);

return <CacheProvider value={emotionCache}>{children}</CacheProvider>;
Expand Down
33 changes: 17 additions & 16 deletions packages/odyssey-react-mui/src/OdysseyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,37 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

import { memo, ReactElement } from "react";
import { memo, ReactNode } from "react";

import { ThemeOptions } from "@mui/material";
import { DesignTokensOverride } from "../src/theme/index";
import { OdysseyCacheProvider } from "./OdysseyCacheProvider";
import { OdysseyThemeProvider } from "./OdysseyThemeProvider";
import {
OdysseyCacheProvider,
OdysseyCacheProviderProps,
} from "./OdysseyCacheProvider";
import {
OdysseyThemeProvider,
OdysseyThemeProviderProps,
} from "./OdysseyThemeProvider";
import {
OdysseyTranslationProvider,
TranslationOverrides,
OdysseyTranslationProviderProps,
} from "./OdysseyTranslationProvider";
import { SupportedLanguages } from "./OdysseyTranslationProvider.types";

type OdysseyProviderProps = {
children: ReactElement;
designTokensOverride?: DesignTokensOverride;
languageCode?: SupportedLanguages;
nonce?: string;
themeOverride?: ThemeOptions;
translationOverrides?: TranslationOverrides;
};
export type OdysseyProviderProps = OdysseyCacheProviderProps &
OdysseyThemeProviderProps &
OdysseyTranslationProviderProps & {
children: ReactNode;
};

const OdysseyProvider = ({
children,
designTokensOverride,
languageCode,
nonce,
stylisPlugins,
themeOverride,
translationOverrides,
}: OdysseyProviderProps) => (
<OdysseyCacheProvider nonce={nonce}>
<OdysseyCacheProvider nonce={nonce} stylisPlugins={stylisPlugins}>
<OdysseyThemeProvider
themeOverride={themeOverride}
designTokensOverride={designTokensOverride}
Expand Down
14 changes: 8 additions & 6 deletions packages/odyssey-react-mui/src/OdysseyThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ import {
createTheme,
ThemeProvider as MuiThemeProvider,
} from "@mui/material/styles";
import { memo, ReactElement, useMemo } from "react";
import { memo, ReactNode, useMemo } from "react";

import { ThemeOptions } from "@mui/material";
import { deepmerge } from "@mui/utils";
import { createOdysseyMuiTheme, DesignTokensOverride } from "./theme";
import * as Tokens from "@okta/odyssey-design-tokens";

export type OdysseyThemeProviderProps = {
children: ReactNode;
designTokensOverride?: DesignTokensOverride;
themeOverride?: ThemeOptions;
};

const OdysseyThemeProvider = ({
children,
designTokensOverride,
themeOverride,
}: {
children: ReactElement;
designTokensOverride?: DesignTokensOverride;
themeOverride?: ThemeOptions;
}) => {
}: OdysseyThemeProviderProps) => {
const odysseyTokens = { ...Tokens, ...designTokensOverride };
const odysseyTheme = createOdysseyMuiTheme(odysseyTokens);

Expand Down
12 changes: 6 additions & 6 deletions packages/odyssey-react-mui/src/OdysseyTranslationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ export type TranslationOverrides = {
[key in SupportedLanguages]?: Partial<(typeof resources)["en"]>;
};

type OdysseyTranslationProviderProps = {
children: ReactNode;
languageCode?: SupportedLanguages;
translationOverrides?: TranslationOverrides;
};

const mergeBundleOverrides = (
languageCode: SupportedLanguages,
translationOverrides: TranslationOverrides
Expand All @@ -39,6 +33,12 @@ const mergeBundleOverrides = (
};
};

export type OdysseyTranslationProviderProps = {
children: ReactNode;
languageCode?: SupportedLanguages;
translationOverrides?: TranslationOverrides;
};

export const OdysseyTranslationProvider = ({
children,
languageCode,
Expand Down