@okta/odyssey-react-mui 1.6.21 → 1.7.1
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 +8 -0
- package/dist/Badge.js +73 -0
- package/dist/Badge.js.map +1 -0
- package/dist/OdysseyDesignTokensContext.js.map +1 -1
- package/dist/labs/DataTable.js +1 -1
- package/dist/labs/DataTable.js.map +1 -1
- package/dist/src/Badge.d.ts +22 -0
- package/dist/src/Badge.d.ts.map +1 -0
- package/dist/src/OdysseyDesignTokensContext.d.ts +1 -0
- package/dist/src/OdysseyDesignTokensContext.d.ts.map +1 -1
- package/dist/src/labs/DataTable.d.ts.map +1 -1
- package/dist/src/theme/components.d.ts.map +1 -1
- package/dist/theme/components.js +5 -3
- package/dist/theme/components.js.map +1 -1
- package/dist/tsconfig.production.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Badge.tsx +99 -0
- package/src/OdysseyDesignTokensContext.tsx +2 -1
- package/src/labs/DataTable.tsx +3 -1
- package/src/theme/components.tsx +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okta/odyssey-react-mui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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.
|
|
54
|
+
"@okta/odyssey-design-tokens": "1.7.1",
|
|
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": "
|
|
66
|
+
"gitHead": "ba092e8f00431e0280b372b95da29a0345afede6"
|
|
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 };
|
|
@@ -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
|
|
16
|
+
export type DesignTokens = typeof Tokens;
|
|
17
|
+
export const OdysseyDesignTokensContext = createContext<DesignTokens>(Tokens);
|
|
17
18
|
|
|
18
19
|
export const useOdysseyDesignTokens = () =>
|
|
19
20
|
useContext(OdysseyDesignTokensContext);
|
package/src/labs/DataTable.tsx
CHANGED
|
@@ -456,7 +456,9 @@ const DataTable = ({
|
|
|
456
456
|
onSortingChange: handleSortingChange,
|
|
457
457
|
onRowSelectionChange: handleRowSelectionChange,
|
|
458
458
|
enableRowActions:
|
|
459
|
-
hasRowReordering || rowActionButtons || rowActionMenuItems
|
|
459
|
+
hasRowReordering === true || rowActionButtons || rowActionMenuItems
|
|
460
|
+
? true
|
|
461
|
+
: false,
|
|
460
462
|
positionActionsColumn: "last",
|
|
461
463
|
|
|
462
464
|
muiTableHeadCellProps: ({ column }) => ({
|
package/src/theme/components.tsx
CHANGED
|
@@ -2208,7 +2208,6 @@ export const components = ({
|
|
|
2208
2208
|
styleOverrides: {
|
|
2209
2209
|
root: ({ theme, ownerState }) => ({
|
|
2210
2210
|
...theme.typography.body1,
|
|
2211
|
-
maxWidth: odysseyTokens.TypographyLineLengthMax,
|
|
2212
2211
|
borderBottom: `${odysseyTokens.BorderWidthMain} ${odysseyTokens.BorderStyleMain} ${odysseyTokens.HueNeutral100}`,
|
|
2213
2212
|
textAlign: "start",
|
|
2214
2213
|
verticalAlign: "baseline",
|
|
@@ -2333,8 +2332,10 @@ export const components = ({
|
|
|
2333
2332
|
},
|
|
2334
2333
|
|
|
2335
2334
|
[`& .${dividerClasses.vertical}`]: {
|
|
2336
|
-
borderStyle: "dotted",
|
|
2335
|
+
borderStyle: "none none none dotted",
|
|
2337
2336
|
borderWidth: 2,
|
|
2337
|
+
borderRadius: 0,
|
|
2338
|
+
marginRight: 2,
|
|
2338
2339
|
},
|
|
2339
2340
|
}),
|
|
2340
2341
|
},
|
|
@@ -2352,6 +2353,7 @@ export const components = ({
|
|
|
2352
2353
|
marginBlockEnd: odysseyTokens.Spacing4,
|
|
2353
2354
|
marginInline: 0,
|
|
2354
2355
|
overflowX: "auto",
|
|
2356
|
+
display: "block !important",
|
|
2355
2357
|
|
|
2356
2358
|
"&:last-child": {
|
|
2357
2359
|
marginBlock: 0,
|