@okta/odyssey-react-mui 1.23.0 → 1.24.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 +21 -0
- package/dist/Autocomplete.js +2 -0
- package/dist/Autocomplete.js.map +1 -1
- package/dist/Banner.js +6 -2
- package/dist/Banner.js.map +1 -1
- package/dist/Callout.js +6 -2
- package/dist/Callout.js.map +1 -1
- package/dist/ContrastModeProvider.js +86 -0
- package/dist/ContrastModeProvider.js.map +1 -0
- package/dist/FieldHint.js +20 -6
- package/dist/FieldHint.js.map +1 -1
- package/dist/Link.js.map +1 -1
- package/dist/OdysseyProvider.js +40 -20
- package/dist/OdysseyProvider.js.map +1 -1
- package/dist/Stack.js +32 -0
- package/dist/Stack.js.map +1 -0
- package/dist/Tag.js +64 -22
- package/dist/Tag.js.map +1 -1
- package/dist/Typography.js +27 -6
- package/dist/Typography.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.scss +8 -4
- package/dist/labs/datePickerTheme.js +3 -6
- package/dist/labs/datePickerTheme.js.map +1 -1
- package/dist/src/Autocomplete.d.ts +7 -1
- package/dist/src/Autocomplete.d.ts.map +1 -1
- package/dist/src/Banner.d.ts +16 -12
- package/dist/src/Banner.d.ts.map +1 -1
- package/dist/src/Callout.d.ts +9 -9
- package/dist/src/Callout.d.ts.map +1 -1
- package/dist/src/ContrastModeProvider.d.ts +34 -0
- package/dist/src/ContrastModeProvider.d.ts.map +1 -0
- package/dist/src/FieldHint.d.ts.map +1 -1
- package/dist/src/Link.d.ts +3 -1
- package/dist/src/Link.d.ts.map +1 -1
- package/dist/src/OdysseyProvider.d.ts +5 -3
- package/dist/src/OdysseyProvider.d.ts.map +1 -1
- package/dist/src/Stack.d.ts +33 -0
- package/dist/src/Stack.d.ts.map +1 -0
- package/dist/src/Tag.d.ts.map +1 -1
- package/dist/src/Typography.d.ts +3 -2
- package/dist/src/Typography.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/labs/datePickerTheme.d.ts.map +1 -1
- package/dist/src/theme/components.d.ts.map +1 -1
- package/dist/src/theme/palette.d.ts.map +1 -1
- package/dist/src/theme/palette.types.d.ts +2 -0
- package/dist/src/theme/palette.types.d.ts.map +1 -1
- package/dist/theme/components.js +276 -273
- package/dist/theme/components.js.map +1 -1
- package/dist/theme/palette.js +2 -1
- package/dist/theme/palette.js.map +1 -1
- package/dist/theme/palette.types.js.map +1 -1
- package/dist/tsconfig.production.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Autocomplete.tsx +13 -0
- package/src/Banner.tsx +29 -14
- package/src/Callout.tsx +18 -11
- package/src/ContrastModeProvider.tsx +131 -0
- package/src/FieldHint.tsx +28 -4
- package/src/Link.tsx +3 -1
- package/src/OdysseyProvider.tsx +54 -27
- package/src/Stack.tsx +56 -0
- package/src/Tag.tsx +65 -21
- package/src/Typography.test.tsx +26 -0
- package/src/Typography.tsx +38 -6
- package/src/index.ts +4 -0
- package/src/labs/datePickerTheme.tsx +2 -6
- package/src/theme/components.tsx +285 -283
- package/src/theme/palette.ts +2 -1
- package/src/theme/palette.types.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okta/odyssey-react-mui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "React MUI components for Odyssey, Okta's design system",
|
|
5
5
|
"author": "Okta, Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@mui/system": "^5.15.9",
|
|
59
59
|
"@mui/utils": "^5.15.9",
|
|
60
60
|
"@mui/x-date-pickers": "^7.2.0",
|
|
61
|
-
"@okta/odyssey-design-tokens": "^1.
|
|
61
|
+
"@okta/odyssey-design-tokens": "^1.24.0",
|
|
62
62
|
"@types/luxon": "^3.4.2",
|
|
63
63
|
"date-fns": "^2.30.0",
|
|
64
64
|
"dom-accessibility-api": "^0.7.0",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react": "^18.2.0",
|
|
74
74
|
"react-dom": "^18.2.0"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "60a0ba720c9b7766c8f3599047f6c77b9470d33b"
|
|
77
77
|
}
|
package/src/Autocomplete.tsx
CHANGED
|
@@ -92,6 +92,17 @@ export type AutocompleteProps<
|
|
|
92
92
|
undefined,
|
|
93
93
|
IsCustomValueAllowed
|
|
94
94
|
>["defaultValue"];
|
|
95
|
+
/**
|
|
96
|
+
* Used to determine the string value for a given option. It's used to fill the input (and the list box options if renderOption is not provided). If used in free solo mode, it must accept both the type of the options and a string.
|
|
97
|
+
*
|
|
98
|
+
* `function(option: Value) => string`
|
|
99
|
+
*/
|
|
100
|
+
getOptionLabel?: UseAutocompleteProps<
|
|
101
|
+
OptionType,
|
|
102
|
+
HasMultipleChoices,
|
|
103
|
+
undefined,
|
|
104
|
+
IsCustomValueAllowed
|
|
105
|
+
>["getOptionLabel"];
|
|
95
106
|
/**
|
|
96
107
|
* Enables multiple choice selection
|
|
97
108
|
*/
|
|
@@ -249,6 +260,7 @@ const Autocomplete = <
|
|
|
249
260
|
defaultValue,
|
|
250
261
|
errorMessage,
|
|
251
262
|
errorMessageList,
|
|
263
|
+
getOptionLabel,
|
|
252
264
|
hasMultipleChoices,
|
|
253
265
|
id: idOverride,
|
|
254
266
|
inputValue,
|
|
@@ -571,6 +583,7 @@ const Autocomplete = <
|
|
|
571
583
|
disabled={isDisabled}
|
|
572
584
|
freeSolo={isCustomValueAllowed}
|
|
573
585
|
filterSelectedOptions={true}
|
|
586
|
+
getOptionLabel={getOptionLabel}
|
|
574
587
|
id={idOverride}
|
|
575
588
|
fullWidth={isFullWidth}
|
|
576
589
|
loading={isLoading}
|
package/src/Banner.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import { useTranslation } from "react-i18next";
|
|
|
15
15
|
import { Alert, AlertColor, AlertTitle, AlertProps } from "@mui/material";
|
|
16
16
|
|
|
17
17
|
import type { HtmlProps } from "./HtmlProps";
|
|
18
|
-
import { Link } from "./Link";
|
|
18
|
+
import { Link, LinkProps } from "./Link";
|
|
19
19
|
import { ScreenReaderText } from "./ScreenReaderText";
|
|
20
20
|
|
|
21
21
|
export const bannerRoleValues = ["status", "alert"] as const;
|
|
@@ -27,16 +27,6 @@ export const bannerSeverityValues: AlertColor[] = [
|
|
|
27
27
|
];
|
|
28
28
|
|
|
29
29
|
export type BannerProps = {
|
|
30
|
-
/**
|
|
31
|
-
* If linkUrl is not undefined, this is the text of the link.
|
|
32
|
-
* If left blank, it defaults to "Learn more".
|
|
33
|
-
* Note that linkText does nothing if linkUrl is not defined
|
|
34
|
-
*/
|
|
35
|
-
linkText?: string;
|
|
36
|
-
/**
|
|
37
|
-
* If defined, the alert will include a link to the URL
|
|
38
|
-
*/
|
|
39
|
-
linkUrl?: string;
|
|
40
30
|
/**
|
|
41
31
|
* The function that's fired when the user clicks the close button. If undefined,
|
|
42
32
|
* the close button will not be shown.
|
|
@@ -56,11 +46,30 @@ export type BannerProps = {
|
|
|
56
46
|
* The text content of the alert
|
|
57
47
|
*/
|
|
58
48
|
text: string;
|
|
59
|
-
} & Pick<HtmlProps, "testId" | "translate"
|
|
49
|
+
} & Pick<HtmlProps, "testId" | "translate"> &
|
|
50
|
+
(
|
|
51
|
+
| {
|
|
52
|
+
linkRel?: LinkProps["rel"];
|
|
53
|
+
linkTarget?: LinkProps["target"];
|
|
54
|
+
linkText: string;
|
|
55
|
+
/**
|
|
56
|
+
* If defined, the Banner will include a link to the URL
|
|
57
|
+
*/
|
|
58
|
+
linkUrl: LinkProps["href"];
|
|
59
|
+
}
|
|
60
|
+
| {
|
|
61
|
+
linkRel?: never;
|
|
62
|
+
linkTarget?: never;
|
|
63
|
+
linkText?: never;
|
|
64
|
+
linkUrl?: never;
|
|
65
|
+
}
|
|
66
|
+
);
|
|
60
67
|
|
|
61
68
|
const Banner = ({
|
|
62
|
-
|
|
69
|
+
linkRel,
|
|
70
|
+
linkTarget,
|
|
63
71
|
linkText,
|
|
72
|
+
linkUrl,
|
|
64
73
|
onClose,
|
|
65
74
|
role,
|
|
66
75
|
severity,
|
|
@@ -83,7 +92,13 @@ const Banner = ({
|
|
|
83
92
|
</ScreenReaderText>
|
|
84
93
|
<AlertTitle translate={translate}>{text}</AlertTitle>
|
|
85
94
|
{linkUrl && (
|
|
86
|
-
<Link
|
|
95
|
+
<Link
|
|
96
|
+
href={linkUrl}
|
|
97
|
+
rel={linkRel}
|
|
98
|
+
target={linkTarget}
|
|
99
|
+
translate={translate}
|
|
100
|
+
variant="monochrome"
|
|
101
|
+
>
|
|
87
102
|
{linkText}
|
|
88
103
|
</Link>
|
|
89
104
|
)}
|
package/src/Callout.tsx
CHANGED
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import styled from "@emotion/styled";
|
|
14
|
-
import { Alert, AlertTitle, Box
|
|
14
|
+
import { Alert, AlertTitle, Box } from "@mui/material";
|
|
15
15
|
import { memo, ReactNode } from "react";
|
|
16
16
|
import { useTranslation } from "react-i18next";
|
|
17
17
|
|
|
18
18
|
import type { HtmlProps } from "./HtmlProps";
|
|
19
|
+
import { Link, LinkProps } from "./Link";
|
|
19
20
|
import {
|
|
20
21
|
DesignTokens,
|
|
21
22
|
useOdysseyDesignTokens,
|
|
@@ -92,18 +93,17 @@ export type CalloutProps = {
|
|
|
92
93
|
) &
|
|
93
94
|
(
|
|
94
95
|
| {
|
|
96
|
+
linkRel?: LinkProps["rel"];
|
|
97
|
+
linkTarget?: LinkProps["target"];
|
|
98
|
+
linkText: string;
|
|
95
99
|
/**
|
|
96
|
-
* If
|
|
97
|
-
* If left blank, it defaults to "Learn more".
|
|
98
|
-
* Note that linkText does nothing if linkUrl is not defined
|
|
99
|
-
*/
|
|
100
|
-
linkUrl: string;
|
|
101
|
-
/**
|
|
102
|
-
* If defined, the Toast will include a link to the URL
|
|
100
|
+
* If defined, the Callout will include a link to the URL
|
|
103
101
|
*/
|
|
104
|
-
|
|
102
|
+
linkUrl: LinkProps["href"];
|
|
105
103
|
}
|
|
106
104
|
| {
|
|
105
|
+
linkRel?: never;
|
|
106
|
+
linkTarget?: never;
|
|
107
107
|
linkUrl?: never;
|
|
108
108
|
linkText?: never;
|
|
109
109
|
}
|
|
@@ -120,6 +120,8 @@ const ContentContainer = styled("div", {
|
|
|
120
120
|
|
|
121
121
|
const Callout = ({
|
|
122
122
|
children,
|
|
123
|
+
linkRel,
|
|
124
|
+
linkTarget,
|
|
123
125
|
linkText,
|
|
124
126
|
linkUrl,
|
|
125
127
|
role,
|
|
@@ -153,9 +155,14 @@ const Callout = ({
|
|
|
153
155
|
{text && <Paragraph>{text}</Paragraph>}
|
|
154
156
|
{linkUrl && (
|
|
155
157
|
<Box>
|
|
156
|
-
<
|
|
158
|
+
<Link
|
|
159
|
+
href={linkUrl}
|
|
160
|
+
rel={linkRel}
|
|
161
|
+
target={linkTarget}
|
|
162
|
+
variant="monochrome"
|
|
163
|
+
>
|
|
157
164
|
{linkText}
|
|
158
|
-
</
|
|
165
|
+
</Link>
|
|
159
166
|
</Box>
|
|
160
167
|
)}
|
|
161
168
|
</ContentContainer>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
3
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
4
|
+
*
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
*
|
|
10
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import React, {
|
|
14
|
+
createContext,
|
|
15
|
+
useContext,
|
|
16
|
+
useRef,
|
|
17
|
+
useLayoutEffect,
|
|
18
|
+
useState,
|
|
19
|
+
useMemo,
|
|
20
|
+
ReactNode,
|
|
21
|
+
} from "react";
|
|
22
|
+
import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles";
|
|
23
|
+
import * as Tokens from "@okta/odyssey-design-tokens";
|
|
24
|
+
|
|
25
|
+
declare module "@mui/material/styles" {
|
|
26
|
+
interface Theme {
|
|
27
|
+
odysseyContrastMode: ContrastMode;
|
|
28
|
+
}
|
|
29
|
+
interface ThemeOptions {
|
|
30
|
+
odysseyContrastMode?: ContrastMode;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ContrastMode = "lowContrast" | "highContrast";
|
|
35
|
+
|
|
36
|
+
export type ContrastModeContextType = {
|
|
37
|
+
contrastMode: ContrastMode;
|
|
38
|
+
parentBackgroundColor: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const ContrastModeContext = createContext<ContrastModeContextType>({
|
|
42
|
+
contrastMode: "highContrast",
|
|
43
|
+
parentBackgroundColor: "",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const useContrastContext = () => useContext(ContrastModeContext);
|
|
47
|
+
|
|
48
|
+
const hexToRgb = (hex: string): string => {
|
|
49
|
+
const bigint = parseInt(hex.slice(1), 16);
|
|
50
|
+
const r = (bigint >> 16) & 255;
|
|
51
|
+
const g = (bigint >> 8) & 255;
|
|
52
|
+
const b = bigint & 255;
|
|
53
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const useParentBackgroundColor = (ref: React.RefObject<HTMLElement>) => {
|
|
57
|
+
const [backgroundColor, setBackgroundColor] = useState("");
|
|
58
|
+
|
|
59
|
+
const hueNeutral50Rgb = useMemo(() => hexToRgb(Tokens.HueNeutral50), []);
|
|
60
|
+
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
if (ref.current) {
|
|
63
|
+
let element: HTMLElement | null = ref.current;
|
|
64
|
+
while (element) {
|
|
65
|
+
const bgColor = window.getComputedStyle(element).backgroundColor;
|
|
66
|
+
|
|
67
|
+
if (bgColor !== "rgba(0, 0, 0, 0)" && bgColor !== "transparent") {
|
|
68
|
+
if (bgColor === hueNeutral50Rgb) {
|
|
69
|
+
setBackgroundColor(Tokens.HueNeutral50);
|
|
70
|
+
} else {
|
|
71
|
+
setBackgroundColor(bgColor);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
element = element.parentElement;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, [ref, hueNeutral50Rgb]);
|
|
79
|
+
|
|
80
|
+
return backgroundColor;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type ContrastModeProviderProps = {
|
|
84
|
+
children: ReactNode;
|
|
85
|
+
contrastMode?: ContrastMode;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const ContrastModeProvider = ({
|
|
89
|
+
children,
|
|
90
|
+
contrastMode: explicitContrastMode,
|
|
91
|
+
}: ContrastModeProviderProps) => {
|
|
92
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
93
|
+
const parentBackgroundColor = useParentBackgroundColor(ref);
|
|
94
|
+
const [contrastMode, setContrastMode] =
|
|
95
|
+
useState<ContrastMode>("highContrast");
|
|
96
|
+
|
|
97
|
+
useLayoutEffect(() => {
|
|
98
|
+
if (explicitContrastMode) {
|
|
99
|
+
setContrastMode(explicitContrastMode);
|
|
100
|
+
} else {
|
|
101
|
+
const isLowContrast = parentBackgroundColor === Tokens.HueNeutral50;
|
|
102
|
+
setContrastMode(isLowContrast ? "lowContrast" : "highContrast");
|
|
103
|
+
}
|
|
104
|
+
}, [parentBackgroundColor, explicitContrastMode]);
|
|
105
|
+
|
|
106
|
+
const contextValue = useMemo<ContrastModeContextType>(
|
|
107
|
+
() => ({
|
|
108
|
+
contrastMode,
|
|
109
|
+
parentBackgroundColor,
|
|
110
|
+
}),
|
|
111
|
+
[contrastMode, parentBackgroundColor],
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const existingTheme = useTheme();
|
|
115
|
+
const theme = useMemo(
|
|
116
|
+
() =>
|
|
117
|
+
createTheme({
|
|
118
|
+
...existingTheme,
|
|
119
|
+
odysseyContrastMode: contrastMode,
|
|
120
|
+
}),
|
|
121
|
+
[existingTheme, contrastMode],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div ref={ref}>
|
|
126
|
+
<ContrastModeContext.Provider value={contextValue}>
|
|
127
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
128
|
+
</ContrastModeContext.Provider>
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
package/src/FieldHint.tsx
CHANGED
|
@@ -11,11 +11,32 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { memo } from "react";
|
|
14
|
-
|
|
14
|
+
import styled from "@emotion/styled";
|
|
15
15
|
import { FormHelperText } from "@mui/material";
|
|
16
16
|
|
|
17
17
|
import { FieldComponentProps } from "./FieldComponentProps";
|
|
18
18
|
import type { HtmlProps } from "./HtmlProps";
|
|
19
|
+
import {
|
|
20
|
+
useOdysseyDesignTokens,
|
|
21
|
+
DesignTokens,
|
|
22
|
+
} from "./OdysseyDesignTokensContext";
|
|
23
|
+
|
|
24
|
+
const HintLinkContainer = styled.span<{ odysseyDesignTokens: DesignTokens }>(
|
|
25
|
+
({ odysseyDesignTokens }) => ({
|
|
26
|
+
a: {
|
|
27
|
+
color: odysseyDesignTokens.TypographyColorBody,
|
|
28
|
+
textDecoration: "underline",
|
|
29
|
+
|
|
30
|
+
"&:visited": {
|
|
31
|
+
color: odysseyDesignTokens.TypographyColorBody,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
"&:hover": {
|
|
35
|
+
color: odysseyDesignTokens.TypographyColorSubordinate,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
19
40
|
|
|
20
41
|
export type FieldHintProps = {
|
|
21
42
|
LinkComponent?: FieldComponentProps["HintLinkComponent"];
|
|
@@ -30,13 +51,16 @@ const FieldHint = ({
|
|
|
30
51
|
text,
|
|
31
52
|
translate,
|
|
32
53
|
}: FieldHintProps) => {
|
|
54
|
+
const odysseyDesignTokens = useOdysseyDesignTokens();
|
|
55
|
+
|
|
33
56
|
return (
|
|
34
57
|
<FormHelperText data-se={testId} id={id} translate={translate}>
|
|
35
58
|
{text}
|
|
36
59
|
{LinkComponent && (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
<HintLinkContainer odysseyDesignTokens={odysseyDesignTokens}>
|
|
61
|
+
{" "}
|
|
62
|
+
{LinkComponent}
|
|
63
|
+
</HintLinkContainer>
|
|
40
64
|
)}
|
|
41
65
|
</FormHelperText>
|
|
42
66
|
);
|
package/src/Link.tsx
CHANGED
|
@@ -41,7 +41,9 @@ export type LinkProps = {
|
|
|
41
41
|
*/
|
|
42
42
|
onClick?: MuiLinkProps["onClick"];
|
|
43
43
|
/**
|
|
44
|
-
* The
|
|
44
|
+
* The rel attribute defines the relationship between a linked resource and the current document
|
|
45
|
+
*
|
|
46
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
|
|
45
47
|
*/
|
|
46
48
|
rel?: string;
|
|
47
49
|
/**
|
package/src/OdysseyProvider.tsx
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { memo, ReactNode } from "react";
|
|
13
|
+
import { memo, ReactNode, useMemo } from "react";
|
|
14
14
|
import { ScopedCssBaseline } from "@mui/material";
|
|
15
15
|
|
|
16
16
|
import {
|
|
@@ -26,6 +26,11 @@ import {
|
|
|
26
26
|
OdysseyTranslationProviderProps,
|
|
27
27
|
} from "./OdysseyTranslationProvider";
|
|
28
28
|
import { DefaultSupportedLanguages } from "./OdysseyTranslationProvider.types";
|
|
29
|
+
import {
|
|
30
|
+
ContrastMode,
|
|
31
|
+
ContrastModeProvider,
|
|
32
|
+
useContrastContext,
|
|
33
|
+
} from "./ContrastModeProvider";
|
|
29
34
|
|
|
30
35
|
const scopedCssBaselineStyles = {
|
|
31
36
|
height: "inherit",
|
|
@@ -37,9 +42,10 @@ export type OdysseyProviderProps<
|
|
|
37
42
|
OdysseyThemeProviderProps &
|
|
38
43
|
OdysseyTranslationProviderProps<SupportedLanguages> & {
|
|
39
44
|
children: ReactNode;
|
|
45
|
+
contrastMode?: ContrastMode;
|
|
40
46
|
};
|
|
41
47
|
|
|
42
|
-
const
|
|
48
|
+
const OdysseyProviderInner = <SupportedLanguages extends string>({
|
|
43
49
|
children,
|
|
44
50
|
designTokensOverride,
|
|
45
51
|
emotionRoot,
|
|
@@ -51,32 +57,53 @@ const OdysseyProvider = <SupportedLanguages extends string>({
|
|
|
51
57
|
stylisPlugins,
|
|
52
58
|
themeOverride,
|
|
53
59
|
translationOverrides,
|
|
54
|
-
}: OdysseyProviderProps<SupportedLanguages>) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
}: OdysseyProviderProps<SupportedLanguages>) => {
|
|
61
|
+
const { contrastMode } = useContrastContext();
|
|
62
|
+
|
|
63
|
+
const memoizedThemeProps = useMemo(
|
|
64
|
+
() => ({
|
|
65
|
+
...themeOverride,
|
|
66
|
+
odysseyContrastMode: contrastMode,
|
|
67
|
+
}),
|
|
68
|
+
[themeOverride, contrastMode],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<OdysseyCacheProvider
|
|
73
|
+
emotionRoot={emotionRoot}
|
|
74
|
+
emotionRootElement={emotionRootElement}
|
|
75
|
+
hasShadowDom={Boolean(shadowRootElement || shadowDomElement)}
|
|
76
|
+
nonce={nonce}
|
|
77
|
+
stylisPlugins={stylisPlugins}
|
|
66
78
|
>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
<OdysseyThemeProvider
|
|
80
|
+
designTokensOverride={designTokensOverride}
|
|
81
|
+
shadowDomElement={shadowDomElement}
|
|
82
|
+
shadowRootElement={shadowRootElement}
|
|
83
|
+
themeOverride={memoizedThemeProps}
|
|
84
|
+
>
|
|
85
|
+
<ScopedCssBaseline sx={scopedCssBaselineStyles}>
|
|
86
|
+
<OdysseyTranslationProvider<SupportedLanguages>
|
|
87
|
+
languageCode={languageCode}
|
|
88
|
+
translationOverrides={translationOverrides}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
</OdysseyTranslationProvider>
|
|
92
|
+
</ScopedCssBaseline>
|
|
93
|
+
</OdysseyThemeProvider>
|
|
94
|
+
</OdysseyCacheProvider>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const OdysseyProvider = <SupportedLanguages extends string>({
|
|
99
|
+
contrastMode,
|
|
100
|
+
...providerProps
|
|
101
|
+
}: OdysseyProviderProps<SupportedLanguages>) => (
|
|
102
|
+
<ContrastModeProvider contrastMode={contrastMode}>
|
|
103
|
+
<OdysseyProviderInner {...providerProps} />
|
|
104
|
+
</ContrastModeProvider>
|
|
78
105
|
);
|
|
79
106
|
|
|
80
|
-
const
|
|
107
|
+
const MemoizedOdysseyProvider = memo(OdysseyProvider) as typeof OdysseyProvider;
|
|
81
108
|
|
|
82
|
-
export {
|
|
109
|
+
export { MemoizedOdysseyProvider as OdysseyProvider };
|
package/src/Stack.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
3
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
4
|
+
*
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
*
|
|
10
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { memo } from "react";
|
|
14
|
+
import { Stack as MuiStack, StackProps as MuiStackProps } from "@mui/material";
|
|
15
|
+
|
|
16
|
+
export const stackSpacingValues = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as const;
|
|
17
|
+
export const stackDirectionValues = [
|
|
18
|
+
"row",
|
|
19
|
+
"row-reverse",
|
|
20
|
+
"column",
|
|
21
|
+
"column-reverse",
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
export type OdysseyStackProps = {
|
|
25
|
+
children?: MuiStackProps["children"];
|
|
26
|
+
/**
|
|
27
|
+
* The component used for the root node. Either a string to use a HTML element or a component.
|
|
28
|
+
*/
|
|
29
|
+
component?: MuiStackProps["component"];
|
|
30
|
+
/**
|
|
31
|
+
* Defines the flex-direction style property. It is applied for all screen sizes.
|
|
32
|
+
*/
|
|
33
|
+
direction?: (typeof stackDirectionValues)[number];
|
|
34
|
+
/**
|
|
35
|
+
* Defines the space between immediate children.
|
|
36
|
+
*/
|
|
37
|
+
spacing?: (typeof stackSpacingValues)[number];
|
|
38
|
+
sx?: MuiStackProps["sx"];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const Stack = ({
|
|
42
|
+
children,
|
|
43
|
+
direction = "column",
|
|
44
|
+
spacing = 2,
|
|
45
|
+
}: OdysseyStackProps) => {
|
|
46
|
+
return (
|
|
47
|
+
<MuiStack direction={direction} spacing={spacing}>
|
|
48
|
+
{children}
|
|
49
|
+
</MuiStack>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const MemoizedStack = memo(Stack);
|
|
54
|
+
MemoizedStack.displayName = "Stack";
|
|
55
|
+
|
|
56
|
+
export { MemoizedStack as Stack };
|