@okta/odyssey-react-mui 0.16.1 → 0.17.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +6 -2
  3. package/dist/Link.d.ts +1 -1
  4. package/dist/Link.d.ts.map +1 -1
  5. package/dist/Link.js +2 -15
  6. package/dist/Link.js.map +1 -1
  7. package/dist/OdysseyCacheProvider.d.ts +23 -0
  8. package/dist/OdysseyCacheProvider.d.ts.map +1 -0
  9. package/dist/OdysseyCacheProvider.js +36 -0
  10. package/dist/OdysseyCacheProvider.js.map +1 -0
  11. package/dist/OdysseyThemeProvider.d.ts +17 -0
  12. package/dist/OdysseyThemeProvider.d.ts.map +1 -0
  13. package/dist/OdysseyThemeProvider.js +29 -0
  14. package/dist/OdysseyThemeProvider.js.map +1 -0
  15. package/dist/PasswordInput.d.ts +1 -1
  16. package/dist/ThemeProvider.d.ts +3 -2
  17. package/dist/ThemeProvider.d.ts.map +1 -1
  18. package/dist/ThemeProvider.js +12 -6
  19. package/dist/ThemeProvider.js.map +1 -1
  20. package/dist/createUniqueAlphabeticalId.d.ts +14 -0
  21. package/dist/createUniqueAlphabeticalId.d.ts.map +1 -0
  22. package/dist/createUniqueAlphabeticalId.js +14 -0
  23. package/dist/createUniqueAlphabeticalId.js.map +1 -0
  24. package/dist/createUniqueId.d.ts.map +1 -1
  25. package/dist/createUniqueId.js.map +1 -1
  26. package/dist/index.d.ts +5 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -2
  29. package/dist/index.js.map +1 -1
  30. package/dist/theme/components.d.ts.map +1 -1
  31. package/dist/theme/components.js +145 -73
  32. package/dist/theme/components.js.map +1 -1
  33. package/dist/useUniqueAlphabeticalId.d.ts +13 -0
  34. package/dist/useUniqueAlphabeticalId.d.ts.map +1 -0
  35. package/dist/useUniqueAlphabeticalId.js +18 -0
  36. package/dist/useUniqueAlphabeticalId.js.map +1 -0
  37. package/dist/useUniqueId.d.ts.map +1 -1
  38. package/dist/useUniqueId.js +1 -1
  39. package/dist/useUniqueId.js.map +1 -1
  40. package/package.json +7 -6
  41. package/src/Link.tsx +22 -24
  42. package/src/OdysseyCacheProvider.test.tsx +38 -0
  43. package/src/OdysseyCacheProvider.tsx +48 -0
  44. package/src/OdysseyThemeProvider.tsx +24 -0
  45. package/src/ThemeProvider.tsx +11 -5
  46. package/src/createUniqueAlphabeticalId.test.ts +22 -0
  47. package/src/createUniqueAlphabeticalId.ts +19 -0
  48. package/src/createUniqueId.ts +1 -1
  49. package/src/index.ts +5 -1
  50. package/src/theme/components.tsx +69 -2
  51. package/src/useUniqueAlphabeticalId.ts +21 -0
  52. package/src/useUniqueId.ts +2 -2
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * Copyright (c) 2022-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
+ declare global {
14
+ interface Window {
15
+ cspNonce: string;
16
+ }
17
+ }
18
+
19
+ import createCache from "@emotion/cache";
20
+ import { CacheProvider } from "@emotion/react";
21
+ import { memo, ReactElement, useMemo } from "react";
22
+
23
+ import { useUniqueAlphabeticalId } from "./useUniqueAlphabeticalId";
24
+
25
+ const OdysseyCacheProvider = ({
26
+ children,
27
+ nonce,
28
+ }: {
29
+ children: ReactElement;
30
+ nonce?: string;
31
+ }) => {
32
+ const uniqueAlphabeticalId = useUniqueAlphabeticalId();
33
+
34
+ const emotionCache = useMemo(
35
+ () =>
36
+ createCache({
37
+ key: uniqueAlphabeticalId,
38
+ nonce: nonce || window.cspNonce,
39
+ }),
40
+ [nonce, uniqueAlphabeticalId]
41
+ );
42
+
43
+ return <CacheProvider value={emotionCache}>{children}</CacheProvider>;
44
+ };
45
+
46
+ const MemoizedOdysseyCacheProvider = memo(OdysseyCacheProvider);
47
+
48
+ export { MemoizedOdysseyCacheProvider as OdysseyCacheProvider };
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright (c) 2022-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 { ThemeProvider as MuiThemeProvider } from "@mui/material/styles";
14
+ import { memo, ReactElement } from "react";
15
+
16
+ import { odysseyTheme } from "./theme";
17
+
18
+ const OdysseyThemeProvider = ({ children }: { children: ReactElement }) => (
19
+ <MuiThemeProvider theme={odysseyTheme}>{children}</MuiThemeProvider>
20
+ );
21
+
22
+ const MemoizedOdysseyThemeProvider = memo(OdysseyThemeProvider);
23
+
24
+ export { MemoizedOdysseyThemeProvider as OdysseyThemeProvider };
@@ -10,11 +10,17 @@
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { ThemeProvider as MuiThemeProvider } from "@mui/material/styles";
14
- import { ReactElement } from "react";
13
+ import { memo, ReactElement } from "react";
15
14
 
16
- import { odysseyTheme } from "./theme";
15
+ import { OdysseyCacheProvider } from "./OdysseyCacheProvider";
16
+ import { OdysseyThemeProvider } from "./OdysseyThemeProvider";
17
17
 
18
- export const ThemeProvider = ({ children }: { children: ReactElement }) => (
19
- <MuiThemeProvider theme={odysseyTheme}>{children}</MuiThemeProvider>
18
+ const ThemeProvider = ({ children }: { children: ReactElement }) => (
19
+ <OdysseyCacheProvider>
20
+ <OdysseyThemeProvider>{children}</OdysseyThemeProvider>
21
+ </OdysseyCacheProvider>
20
22
  );
23
+
24
+ const MemoizedThemeProvider = memo(ThemeProvider);
25
+
26
+ export { MemoizedThemeProvider as ThemeProvider };
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * Copyright (c) 2021-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 { createUniqueAlphabeticalId } from "./createUniqueAlphabeticalId";
14
+
15
+ describe("createUniqueAlphabeticalId", () => {
16
+ it("only has lowercase letters", () => {
17
+ const uniqueAlphabeticalId = createUniqueAlphabeticalId();
18
+
19
+ expect(uniqueAlphabeticalId.match(/[a-z]/)).not.toBeNull();
20
+ expect(uniqueAlphabeticalId.toLowerCase()).toBe(uniqueAlphabeticalId);
21
+ });
22
+ });
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * Copyright (c) 2021-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
+ // This is a random number chosen to shrink down the unique ID to an arbitrary length.
14
+ export const uniqueIdLength = 6;
15
+
16
+ export const createUniqueAlphabeticalId = () =>
17
+ Math.random()
18
+ .toString(36)
19
+ .replace(/[\d\.]/g, "");
@@ -13,5 +13,5 @@
13
13
  // This is a random number chosen to shrink down the unique ID to an arbitrary length.
14
14
  export const uniqueIdLength = 6;
15
15
 
16
- export const createUniqueId = (): string =>
16
+ export const createUniqueId = () =>
17
17
  Math.random().toString(36).slice(-uniqueIdLength);
package/src/index.ts CHANGED
@@ -14,6 +14,8 @@ export * from "./createUniqueId";
14
14
  export * from "./Icon";
15
15
  export * from "./iconDictionary";
16
16
  export * from "./Link";
17
+ export * from "./OdysseyCacheProvider";
18
+ export * from "./OdysseyThemeProvider";
17
19
  export * from "./PasswordInput";
18
20
  export * from "./theme";
19
21
  export * from "./ThemeProvider";
@@ -25,6 +27,7 @@ export {
25
27
  Box,
26
28
  Button,
27
29
  Checkbox,
30
+ Chip,
28
31
  CircularProgress,
29
32
  CssBaseline,
30
33
  Dialog,
@@ -67,6 +70,7 @@ export type {
67
70
  BoxProps,
68
71
  ButtonProps,
69
72
  CheckboxProps,
73
+ ChipProps,
70
74
  CircularProgressProps,
71
75
  CssBaselineProps,
72
76
  DialogProps,
@@ -106,6 +110,6 @@ export { TabContext, TabList, TabPanel } from "@mui/lab";
106
110
 
107
111
  export type { TabContextProps, TabListProps, TabPanelProps } from "@mui/lab";
108
112
 
109
- export { Favorite as FavoriteIcon } from "@mui/icons-material";
113
+ export { default as FavoriteIcon } from "@mui/icons-material/Favorite";
110
114
 
111
115
  export { visuallyHidden } from "@mui/utils";
@@ -13,6 +13,7 @@
13
13
  import type { ThemeOptions } from "@mui/material";
14
14
  import type {} from "@mui/lab/themeAugmentation";
15
15
  //import radioClasses from "@mui/material";
16
+ import { chipClasses } from "@mui/material/Chip";
16
17
  import { dialogActionsClasses } from "@mui/material/DialogActions";
17
18
  import { inputBaseClasses } from "@mui/material/InputBase";
18
19
  import { tableBodyClasses } from "@mui/material/TableBody";
@@ -25,6 +26,7 @@ import {
25
26
  AlertTriangleFilledIcon,
26
27
  ArrowDownIcon,
27
28
  CheckCircleFilledIcon,
29
+ CloseCircleFilledIcon,
28
30
  InformationCircleFilledIcon,
29
31
  } from "../iconDictionary";
30
32
 
@@ -293,7 +295,7 @@ export const components: ThemeOptions["components"] = {
293
295
  fontWeight: 600,
294
296
  minWidth: "unset",
295
297
  padding: `calc(${theme.spacing(3)} - 1px) ${theme.spacing(3)}`,
296
- display: "inline-block",
298
+ display: "inline-flex",
297
299
  position: "relative",
298
300
  marginBlock: "0",
299
301
  marginInline: "0",
@@ -326,9 +328,14 @@ export const components: ThemeOptions["components"] = {
326
328
  },
327
329
 
328
330
  ".MuiButton-startIcon > *:nth-of-type(1)": {
329
- fontSize: "inherit",
331
+ fontSize: "1.14285714em",
330
332
  },
331
333
  }),
334
+ startIcon: ({ theme }) => ({
335
+ display: "inline-flex",
336
+ margin: 0,
337
+ marginInlineEnd: theme.spacing(2),
338
+ }),
332
339
  },
333
340
  },
334
341
  MuiButtonBase: {
@@ -374,6 +381,66 @@ export const components: ThemeOptions["components"] = {
374
381
  }),
375
382
  },
376
383
  },
384
+ MuiChip: {
385
+ defaultProps: {
386
+ deleteIcon: <CloseCircleFilledIcon />,
387
+ },
388
+ styleOverrides: {
389
+ root: ({ theme, ownerState }) => ({
390
+ height: "auto",
391
+ paddingBlock: theme.spacing(2),
392
+ paddingInline: theme.spacing(3),
393
+ fontSize: theme.typography.body1.fontSize,
394
+ lineHeight: "1.14285714",
395
+ borderRadius: "1.5em",
396
+ backgroundColor: theme.palette.grey[100],
397
+
398
+ ...(ownerState.onDelete && {
399
+ paddingInlineEnd: theme.spacing(2),
400
+ }),
401
+
402
+ [`& .${chipClasses.deleteIcon}`]: {
403
+ WebkitTapHighlightColor: "transparent",
404
+ color: theme.palette.text.secondary,
405
+ fontSize: "1em",
406
+ cursor: "pointer",
407
+ margin: "0",
408
+ marginInlineStart: theme.spacing(2),
409
+
410
+ "&:hover": {
411
+ color: theme.palette.text.primary,
412
+ },
413
+ },
414
+
415
+ [`&.${chipClasses.disabled}`]: {
416
+ opacity: 1,
417
+ pointerEvents: "none",
418
+ backgroundColor: theme.palette.grey[50],
419
+ color: theme.palette.text.secondary,
420
+ },
421
+
422
+ ...(ownerState.clickable && {
423
+ "&:hover": {
424
+ backgroundColor: theme.palette.grey[200],
425
+ },
426
+ [`&.${chipClasses.focusVisible}`]: {
427
+ backgroundColor: theme.palette.grey[200],
428
+ outlineColor: theme.palette.primary.main,
429
+ outlineOffset: "2px",
430
+ outlineStyle: "solid",
431
+ outlineWidth: "2px",
432
+ },
433
+ "&:active": {
434
+ boxShadow: "none",
435
+ backgroundColor: theme.palette.grey[300],
436
+ },
437
+ }),
438
+ }),
439
+ label: {
440
+ padding: 0,
441
+ },
442
+ },
443
+ },
377
444
  MuiCircularProgress: {
378
445
  defaultProps: {
379
446
  // TODO: defaultProps cannot take a theme object; needs workaround
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Copyright (c) 2022-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 { useMemo } from "react";
14
+
15
+ import { createUniqueAlphabeticalId } from "./createUniqueAlphabeticalId";
16
+
17
+ export const useUniqueAlphabeticalId = (id?: string) => {
18
+ const uniqueAlphabeticalId = useMemo(() => createUniqueAlphabeticalId(), []);
19
+
20
+ return id ?? uniqueAlphabeticalId;
21
+ };
@@ -14,8 +14,8 @@ import { useMemo } from "react";
14
14
 
15
15
  import { createUniqueId } from "./createUniqueId";
16
16
 
17
- export const useUniqueId = (id?: string): string => {
17
+ export const useUniqueId = (id?: string) => {
18
18
  const uniqueId = useMemo(() => createUniqueId(), []);
19
19
 
20
- return id || uniqueId;
20
+ return id ?? uniqueId;
21
21
  };