@okta/odyssey-react-mui 1.7.0 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okta/odyssey-react-mui",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "React MUI components for Odyssey, Okta's design system",
5
5
  "author": "Okta, Inc.",
6
6
  "license": "Apache-2.0",
@@ -51,7 +51,7 @@
51
51
  "@mui/system": "^5.14.9",
52
52
  "@mui/utils": "^5.11.2",
53
53
  "@mui/x-date-pickers": "^5.0.15",
54
- "@okta/odyssey-design-tokens": "1.7.0",
54
+ "@okta/odyssey-design-tokens": "1.8.0",
55
55
  "date-fns": "^2.30.0",
56
56
  "i18next": "^23.5.1",
57
57
  "material-react-table": "^2.0.2",
@@ -63,5 +63,5 @@
63
63
  "react": ">=17 <19",
64
64
  "react-dom": ">=17 <19"
65
65
  },
66
- "gitHead": "edc15e98af7428f68d2cd4bf68bbb81a520a7cb8"
66
+ "gitHead": "279ce97d18cf87719c03592ff66e341441b51c10"
67
67
  }
package/src/Badge.tsx ADDED
@@ -0,0 +1,99 @@
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 { CSSProperties, memo, useMemo } from "react";
14
+
15
+ import {
16
+ useOdysseyDesignTokens,
17
+ DesignTokens,
18
+ } from "./OdysseyDesignTokensContext";
19
+ import { Box } from "./Box";
20
+ import type { SeleniumProps } from "./SeleniumProps";
21
+
22
+ export const badgeTypeValues = ["default", "attention", "danger"] as const;
23
+
24
+ export type BadgeProps = {
25
+ badgeContent: number;
26
+ badgeContentMax?: number;
27
+ type?: (typeof badgeTypeValues)[number];
28
+ } & SeleniumProps;
29
+
30
+ const badgeTypeColors = (odysseyTokens: DesignTokens) => ({
31
+ default: {
32
+ background: odysseyTokens.HueNeutral200,
33
+ font: odysseyTokens.TypographyColorBody,
34
+ },
35
+ attention: {
36
+ background: odysseyTokens.PalettePrimaryMain,
37
+ font: odysseyTokens.TypographyColorInverse,
38
+ },
39
+ danger: {
40
+ background: odysseyTokens.PaletteDangerMain,
41
+ font: odysseyTokens.TypographyColorInverse,
42
+ },
43
+ });
44
+
45
+ const Badge = ({
46
+ badgeContent,
47
+ badgeContentMax = 999,
48
+ type = "default",
49
+ }: BadgeProps) => {
50
+ const odysseyDesignTokens = useOdysseyDesignTokens();
51
+
52
+ const greaterThanZeroContentMax = badgeContentMax > 0 ? badgeContentMax : 1;
53
+ const threeDigitLimitedMax =
54
+ greaterThanZeroContentMax > 999 ? 999 : greaterThanZeroContentMax;
55
+ const isOverContentMax = Boolean(
56
+ badgeContent && badgeContent > threeDigitLimitedMax
57
+ );
58
+ const overContentMaxMessage = `${greaterThanZeroContentMax}+`;
59
+ const formattedContent = isOverContentMax
60
+ ? overContentMaxMessage
61
+ : badgeContent;
62
+ const contentIsLongerThanOneChar = formattedContent?.toString()?.length > 1;
63
+
64
+ const badgeStyles = useMemo<CSSProperties>(
65
+ () => ({
66
+ display: "inline-flex",
67
+ alignItems: "center",
68
+ justifyContent: "center",
69
+ minWidth: `calc(${odysseyDesignTokens.Spacing4} + ${odysseyDesignTokens.Spacing1})`,
70
+ height: `calc(${odysseyDesignTokens.Spacing4} + ${odysseyDesignTokens.Spacing1})`,
71
+ minHeight: `calc(${odysseyDesignTokens.Spacing4} + ${odysseyDesignTokens.Spacing1})`,
72
+ // 6px horizontal padding per design requirements
73
+ padding: `0 calc(${odysseyDesignTokens.Spacing1} * 1.5)`,
74
+ backgroundColor: badgeTypeColors(odysseyDesignTokens)[type].background,
75
+ color: badgeTypeColors(odysseyDesignTokens)[type].font,
76
+ borderRadius: contentIsLongerThanOneChar
77
+ ? `${odysseyDesignTokens.BorderRadiusOuter}`
78
+ : "50%",
79
+ fontSize: `${odysseyDesignTokens.TypographyScale0}`,
80
+ fontFamily: `${odysseyDesignTokens.TypographyFamilyMono}`,
81
+ fontWeight: `${odysseyDesignTokens.TypographyWeightBodyBold}`,
82
+ lineHeight: 1,
83
+ }),
84
+ [type, contentIsLongerThanOneChar, odysseyDesignTokens]
85
+ );
86
+
87
+ const shouldHideBadge = badgeContent <= 0 || !badgeContent;
88
+
89
+ if (shouldHideBadge) {
90
+ return null;
91
+ }
92
+
93
+ return <Box sx={badgeStyles}>{formattedContent}</Box>;
94
+ };
95
+
96
+ const MemoizedBadge = memo(Badge);
97
+ MemoizedBadge.displayName = "Badge";
98
+
99
+ export { MemoizedBadge as Badge };
package/src/Checkbox.tsx CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  Checkbox as MuiCheckbox,
17
17
  CheckboxProps as MuiCheckboxProps,
18
18
  FormControlLabel,
19
+ FormHelperText,
19
20
  } from "@mui/material";
20
21
 
21
22
  import { FieldComponentProps } from "./FieldComponentProps";
@@ -55,6 +56,10 @@ export type CheckboxProps = {
55
56
  * The label text for the Checkbox
56
57
  */
57
58
  label?: string;
59
+ /**
60
+ * The helper text content
61
+ */
62
+ hint?: string;
58
63
  /**
59
64
  * The checkbox validity, if different from its enclosing group. Defaults to "inherit".
60
65
  */
@@ -77,6 +82,7 @@ const Checkbox = ({
77
82
  isIndeterminate,
78
83
  isRequired,
79
84
  label: labelProp,
85
+ hint,
80
86
  name: nameOverride,
81
87
  onChange: onChangeProp,
82
88
  testId,
@@ -90,19 +96,21 @@ const Checkbox = ({
90
96
  });
91
97
 
92
98
  const label = useMemo(() => {
93
- if (isRequired) {
94
- return (
95
- <>
96
- {labelProp}{" "}
97
- <Typography component="span" color="textSecondary">
98
- ({t("fieldlabel.required.text")})
99
- </Typography>
100
- </>
101
- );
102
- } else {
103
- return <>{labelProp}</>;
104
- }
105
- }, [isRequired, labelProp, t]);
99
+ return (
100
+ <>
101
+ {labelProp}
102
+ {isRequired && (
103
+ <>
104
+ {" "}
105
+ <Typography component="span" color="textSecondary">
106
+ ({t("fieldlabel.required.text")})
107
+ </Typography>
108
+ </>
109
+ )}
110
+ {hint && <FormHelperText>{hint}</FormHelperText>}
111
+ </>
112
+ );
113
+ }, [isRequired, labelProp, hint, t]);
106
114
 
107
115
  const onChange = useCallback<NonNullable<MuiCheckboxProps["onChange"]>>(
108
116
  (event, checked) => {
@@ -114,6 +122,7 @@ const Checkbox = ({
114
122
 
115
123
  return (
116
124
  <FormControlLabel
125
+ sx={{ alignItems: "flex-start" }}
117
126
  aria-label={ariaLabel}
118
127
  aria-labelledby={ariaLabelledBy}
119
128
  className={
@@ -129,6 +138,9 @@ const Checkbox = ({
129
138
  indeterminate={isIndeterminate}
130
139
  onChange={onChange}
131
140
  required={isRequired}
141
+ sx={() => ({
142
+ marginBlockStart: "2px",
143
+ })}
132
144
  />
133
145
  }
134
146
  data-se={testId}
@@ -13,7 +13,8 @@
13
13
  import * as Tokens from "@okta/odyssey-design-tokens";
14
14
  import { createContext, useContext } from "react";
15
15
 
16
- export const OdysseyDesignTokensContext = createContext<typeof Tokens>(Tokens);
16
+ export type DesignTokens = typeof Tokens;
17
+ export const OdysseyDesignTokensContext = createContext<DesignTokens>(Tokens);
17
18
 
18
19
  export const useOdysseyDesignTokens = () =>
19
20
  useContext(OdysseyDesignTokensContext);