@okta/odyssey-react-mui 0.21.4 → 0.22.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 (135) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/Autocomplete.js +58 -0
  3. package/dist/Autocomplete.js.map +1 -0
  4. package/dist/Button.js +46 -0
  5. package/dist/Button.js.map +1 -0
  6. package/dist/Field.js +59 -0
  7. package/dist/Field.js.map +1 -0
  8. package/dist/FieldError.js +34 -0
  9. package/dist/FieldError.js.map +1 -0
  10. package/dist/FieldHint.js +29 -0
  11. package/dist/FieldHint.js.map +1 -0
  12. package/dist/FieldLabel.js +32 -0
  13. package/dist/FieldLabel.js.map +1 -0
  14. package/dist/MenuButton.js +2 -2
  15. package/dist/MenuButton.js.map +1 -1
  16. package/dist/MenuItem.js +0 -1
  17. package/dist/MenuItem.js.map +1 -1
  18. package/dist/PasswordField.js +68 -0
  19. package/dist/PasswordField.js.map +1 -0
  20. package/dist/SearchField.js +54 -0
  21. package/dist/SearchField.js.map +1 -0
  22. package/dist/Tag.js +28 -0
  23. package/dist/Tag.js.map +1 -0
  24. package/dist/TagList.js +26 -0
  25. package/dist/TagList.js.map +1 -0
  26. package/dist/TagListContext.js +16 -0
  27. package/dist/TagListContext.js.map +1 -0
  28. package/dist/TextField.js +26 -61
  29. package/dist/TextField.js.map +1 -1
  30. package/dist/index.js +10 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/src/Autocomplete.d.ts +27 -0
  33. package/dist/src/Autocomplete.d.ts.map +1 -0
  34. package/dist/src/Button.d.ts +31 -0
  35. package/dist/src/Button.d.ts.map +1 -0
  36. package/dist/src/Field.d.ts +54 -0
  37. package/dist/src/Field.d.ts.map +1 -0
  38. package/dist/src/FieldError.d.ts +19 -0
  39. package/dist/src/FieldError.d.ts.map +1 -0
  40. package/dist/src/FieldHint.d.ts +19 -0
  41. package/dist/src/FieldHint.d.ts.map +1 -0
  42. package/dist/src/FieldLabel.d.ts +23 -0
  43. package/dist/src/FieldLabel.d.ts.map +1 -0
  44. package/dist/src/Icon.d.ts +1 -1
  45. package/dist/src/Link.d.ts +1 -1
  46. package/dist/src/MenuButton.d.ts.map +1 -1
  47. package/dist/src/MenuItem.d.ts +1 -1
  48. package/dist/src/MenuItem.d.ts.map +1 -1
  49. package/dist/src/PasswordField.d.ts +75 -0
  50. package/dist/src/PasswordField.d.ts.map +1 -0
  51. package/dist/src/SearchField.d.ts +59 -0
  52. package/dist/src/SearchField.d.ts.map +1 -0
  53. package/dist/src/Tag.d.ts +22 -0
  54. package/dist/src/Tag.d.ts.map +1 -0
  55. package/dist/src/TagList.d.ts +19 -0
  56. package/dist/src/TagList.d.ts.map +1 -0
  57. package/dist/src/TagListContext.d.ts +18 -0
  58. package/dist/src/TagListContext.d.ts.map +1 -0
  59. package/dist/src/TextField.d.ts +3 -8
  60. package/dist/src/TextField.d.ts.map +1 -1
  61. package/dist/src/iconDictionary/Add.d.ts +1 -1
  62. package/dist/src/iconDictionary/AddCircle.d.ts +1 -1
  63. package/dist/src/iconDictionary/AlertCircle.d.ts +1 -1
  64. package/dist/src/iconDictionary/AlertCircleFilled.d.ts +1 -1
  65. package/dist/src/iconDictionary/AlertTriangleFilled.d.ts +1 -1
  66. package/dist/src/iconDictionary/Anchor.d.ts +1 -1
  67. package/dist/src/iconDictionary/ArrowDown.d.ts +1 -1
  68. package/dist/src/iconDictionary/ArrowLeft.d.ts +1 -1
  69. package/dist/src/iconDictionary/ArrowRight.d.ts +1 -1
  70. package/dist/src/iconDictionary/ArrowUp.d.ts +1 -1
  71. package/dist/src/iconDictionary/ArrowUpDown.d.ts +1 -1
  72. package/dist/src/iconDictionary/Calendar.d.ts +1 -1
  73. package/dist/src/iconDictionary/Check.d.ts +1 -1
  74. package/dist/src/iconDictionary/CheckCircleFilled.d.ts +1 -1
  75. package/dist/src/iconDictionary/ChevronDown.d.ts +1 -1
  76. package/dist/src/iconDictionary/ChevronUp.d.ts +1 -1
  77. package/dist/src/iconDictionary/Close.d.ts +1 -1
  78. package/dist/src/iconDictionary/CloseCircleFilled.d.ts +1 -1
  79. package/dist/src/iconDictionary/Copy.d.ts +1 -1
  80. package/dist/src/iconDictionary/Delete.d.ts +1 -1
  81. package/dist/src/iconDictionary/Download.d.ts +1 -1
  82. package/dist/src/iconDictionary/DragHandle.d.ts +1 -1
  83. package/dist/src/iconDictionary/Edit.d.ts +1 -1
  84. package/dist/src/iconDictionary/ExternalLink.d.ts +1 -1
  85. package/dist/src/iconDictionary/Eye.d.ts +1 -1
  86. package/dist/src/iconDictionary/EyeOff.d.ts +1 -1
  87. package/dist/src/iconDictionary/Filter.d.ts +1 -1
  88. package/dist/src/iconDictionary/Globe.d.ts +1 -1
  89. package/dist/src/iconDictionary/Home.d.ts +1 -1
  90. package/dist/src/iconDictionary/InformationCircle.d.ts +1 -1
  91. package/dist/src/iconDictionary/InformationCircleFilled.d.ts +1 -1
  92. package/dist/src/iconDictionary/Notification.d.ts +1 -1
  93. package/dist/src/iconDictionary/OverflowVertical.d.ts +1 -1
  94. package/dist/src/iconDictionary/QuestionCircle.d.ts +1 -1
  95. package/dist/src/iconDictionary/QuestionCircleFilled.d.ts +1 -1
  96. package/dist/src/iconDictionary/Search.d.ts +1 -1
  97. package/dist/src/iconDictionary/Settings.d.ts +1 -1
  98. package/dist/src/iconDictionary/Subtract.d.ts +1 -1
  99. package/dist/src/iconDictionary/User.d.ts +1 -1
  100. package/dist/src/iconDictionary/UserGroup.d.ts +1 -1
  101. package/dist/src/iconDictionary/index.d.ts +40 -40
  102. package/dist/src/index.d.ts +11 -3
  103. package/dist/src/index.d.ts.map +1 -1
  104. package/dist/src/theme/components.d.ts.map +1 -1
  105. package/dist/src/theme/components.types.d.ts +0 -8
  106. package/dist/src/theme/components.types.d.ts.map +1 -1
  107. package/dist/theme/components.js +217 -124
  108. package/dist/theme/components.js.map +1 -1
  109. package/dist/theme/components.types.js.map +1 -1
  110. package/dist/tsconfig.production.tsbuildinfo +1 -1
  111. package/package.json +3 -3
  112. package/src/Autocomplete.tsx +132 -0
  113. package/src/Button.tsx +75 -0
  114. package/src/Field.tsx +112 -0
  115. package/src/FieldError.tsx +34 -0
  116. package/src/FieldHint.tsx +28 -0
  117. package/src/FieldLabel.tsx +57 -0
  118. package/src/MenuButton.tsx +2 -3
  119. package/src/MenuItem.tsx +0 -1
  120. package/src/OdysseyCacheProvider.test.tsx +1 -1
  121. package/src/PasswordField.tsx +174 -0
  122. package/src/SearchField.tsx +136 -0
  123. package/src/Tag.tsx +41 -0
  124. package/src/TagList.tsx +43 -0
  125. package/src/TagListContext.tsx +23 -0
  126. package/src/TextField.tsx +43 -101
  127. package/src/index.ts +9 -3
  128. package/src/theme/components.tsx +87 -18
  129. package/src/theme/components.types.ts +0 -8
  130. package/dist/PasswordInput.js +0 -87
  131. package/dist/PasswordInput.js.map +0 -1
  132. package/dist/src/PasswordInput.d.ts +0 -21
  133. package/dist/src/PasswordInput.d.ts.map +0 -1
  134. package/src/PasswordInput.test.tsx +0 -51
  135. package/src/PasswordInput.tsx +0 -111
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okta/odyssey-react-mui",
3
- "version": "0.21.4",
3
+ "version": "0.22.0",
4
4
  "description": "React MUI components for Odyssey, Okta's design system",
5
5
  "author": "Okta, Inc.",
6
6
  "license": "Apache-2.0",
@@ -25,7 +25,7 @@
25
25
  "@mui/lab": "^5.0.0-alpha.117",
26
26
  "@mui/material": "^5.11.6",
27
27
  "@mui/utils": "^5.11.2",
28
- "@okta/odyssey-design-tokens": "0.21.4"
28
+ "@okta/odyssey-design-tokens": "0.22.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@emotion/react": "^11",
@@ -33,5 +33,5 @@
33
33
  "react": ">=17 <19",
34
34
  "react-dom": ">=17 <19"
35
35
  },
36
- "gitHead": "facb0d98d72297e662093673a0e0ee8d7e226be2"
36
+ "gitHead": "b1a4a93f7d570162a52e4c28012fb65e31d5bb4b"
37
37
  }
@@ -0,0 +1,132 @@
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 {
14
+ Autocomplete as MuiAutocomplete,
15
+ AutocompleteProps as MuiAutocompleteProps,
16
+ InputBase,
17
+ } from "@mui/material";
18
+ import { memo, useCallback } from "react";
19
+
20
+ import { Field } from "./Field";
21
+
22
+ export type AutocompleteProps<
23
+ OptionType,
24
+ HasMultipleChoices extends boolean | undefined,
25
+ IsCustomValueAllowed extends boolean | undefined
26
+ > = {
27
+ hasMultipleChoices?: MuiAutocompleteProps<
28
+ OptionType,
29
+ HasMultipleChoices,
30
+ undefined,
31
+ IsCustomValueAllowed
32
+ >["multiple"];
33
+ hint?: string;
34
+ isCustomValueAllowed?: MuiAutocompleteProps<
35
+ OptionType,
36
+ HasMultipleChoices,
37
+ undefined,
38
+ IsCustomValueAllowed
39
+ >["freeSolo"];
40
+ isDisabled?: MuiAutocompleteProps<
41
+ OptionType,
42
+ HasMultipleChoices,
43
+ undefined,
44
+ IsCustomValueAllowed
45
+ >["disabled"];
46
+ isLoading?: MuiAutocompleteProps<
47
+ OptionType,
48
+ HasMultipleChoices,
49
+ undefined,
50
+ IsCustomValueAllowed
51
+ >["loading"];
52
+ isReadOnly?: MuiAutocompleteProps<
53
+ OptionType,
54
+ HasMultipleChoices,
55
+ undefined,
56
+ IsCustomValueAllowed
57
+ >["readOnly"];
58
+ label: string;
59
+ onChange?: MuiAutocompleteProps<
60
+ OptionType,
61
+ HasMultipleChoices,
62
+ undefined,
63
+ IsCustomValueAllowed
64
+ >["onChange"];
65
+ options: MuiAutocompleteProps<
66
+ OptionType,
67
+ HasMultipleChoices,
68
+ undefined,
69
+ IsCustomValueAllowed
70
+ >["options"];
71
+ value?: MuiAutocompleteProps<
72
+ OptionType,
73
+ HasMultipleChoices,
74
+ undefined,
75
+ IsCustomValueAllowed
76
+ >["value"];
77
+ };
78
+
79
+ const Autocomplete = <
80
+ OptionType,
81
+ HasMultipleChoices extends boolean | undefined,
82
+ IsCustomValueAllowed extends boolean | undefined
83
+ >({
84
+ isCustomValueAllowed,
85
+ hasMultipleChoices,
86
+ isDisabled,
87
+ isLoading,
88
+ isReadOnly,
89
+ hint,
90
+ label,
91
+ onChange,
92
+ options,
93
+ value,
94
+ }: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {
95
+ const renderInput = useCallback(
96
+ ({ InputLabelProps, InputProps, ...params }) => (
97
+ <Field
98
+ {...InputLabelProps}
99
+ hasVisibleLabel
100
+ hint={hint}
101
+ label={label}
102
+ renderFieldComponent={({ ariaDescribedBy, id }) => (
103
+ <InputBase
104
+ {...params}
105
+ {...InputProps}
106
+ aria-describedby={ariaDescribedBy}
107
+ id={id}
108
+ />
109
+ )}
110
+ />
111
+ ),
112
+ [hint, label]
113
+ );
114
+
115
+ return (
116
+ <MuiAutocomplete
117
+ disabled={isDisabled}
118
+ freeSolo={isCustomValueAllowed}
119
+ loading={isLoading}
120
+ multiple={hasMultipleChoices}
121
+ onChange={onChange}
122
+ options={options}
123
+ readOnly={isReadOnly}
124
+ renderInput={renderInput}
125
+ value={value}
126
+ />
127
+ );
128
+ };
129
+
130
+ const MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete;
131
+
132
+ export { MemoizedAutocomplete as Autocomplete };
package/src/Button.tsx ADDED
@@ -0,0 +1,75 @@
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 { Button as MuiButton } from "@mui/material";
14
+ import type { ButtonProps as MuiButtonProps } from "@mui/material";
15
+ import { Tooltip } from "./";
16
+ import { memo } from "react";
17
+
18
+ export type ButtonProps = {
19
+ endIcon?: React.ReactNode;
20
+ id?: string;
21
+ isDisabled?: boolean;
22
+ isFullWidth?: boolean;
23
+ onClick?: MuiButtonProps["onClick"];
24
+ size?: MuiButtonProps["size"];
25
+ startIcon?: React.ReactNode;
26
+ text?: string;
27
+ /**
28
+ * `tooltipText` determines the text of the tooltip that wraps the button if it's icon-only.
29
+ */
30
+ tooltipText?: string;
31
+ variant?: "primary" | "secondary" | "danger" | "floating";
32
+ };
33
+
34
+ const Button = ({
35
+ endIcon,
36
+ id,
37
+ isDisabled,
38
+ isFullWidth,
39
+ onClick,
40
+ size = "medium",
41
+ startIcon,
42
+ text,
43
+ tooltipText,
44
+ variant,
45
+ }: ButtonProps) => {
46
+ const button = (
47
+ <MuiButton
48
+ disabled={isDisabled}
49
+ endIcon={endIcon}
50
+ fullWidth={isFullWidth}
51
+ id={id}
52
+ onClick={onClick}
53
+ size={size}
54
+ startIcon={startIcon}
55
+ variant={variant}
56
+ >
57
+ {text}
58
+ </MuiButton>
59
+ );
60
+
61
+ return (
62
+ <>
63
+ {tooltipText && (
64
+ <Tooltip describeChild placement="top" title={tooltipText}>
65
+ {button}
66
+ </Tooltip>
67
+ )}
68
+ {!tooltipText && button}
69
+ </>
70
+ );
71
+ };
72
+
73
+ const MemoizedButton = memo(Button);
74
+
75
+ export { MemoizedButton as Button };
package/src/Field.tsx ADDED
@@ -0,0 +1,112 @@
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 { memo, ReactElement, useMemo } from "react";
14
+
15
+ import {
16
+ FieldError,
17
+ FieldHint,
18
+ FieldLabel,
19
+ FormControl,
20
+ useUniqueId,
21
+ } from "./";
22
+
23
+ export type FieldProps = {
24
+ /**
25
+ * If `error` is not undefined, the `input` will indicate an error.
26
+ */
27
+ errorMessage?: string;
28
+ hasVisibleLabel: boolean;
29
+ /**
30
+ * The helper text content.
31
+ */
32
+ hint?: string;
33
+ /**
34
+ * The id of the `input` element.
35
+ */
36
+ id?: string;
37
+ /**
38
+ * If `true`, the component is disabled.
39
+ */
40
+ isDisabled?: boolean;
41
+ /**
42
+ * If `true`, the `input` element is required.
43
+ */
44
+ isRequired?: boolean;
45
+ /**
46
+ * The label for the `input` element.
47
+ */
48
+ label: string;
49
+ /**
50
+ * The label for the `input` element if the it's not optional
51
+ */
52
+ optionalLabel?: string;
53
+ /**
54
+ * The short hint displayed in the `input` before the user enters a value.
55
+ */
56
+ placeholder?: string;
57
+ renderFieldComponent: ({
58
+ ariaDescribedBy,
59
+ id,
60
+ }: {
61
+ ariaDescribedBy?: string;
62
+ id: string;
63
+ }) => ReactElement;
64
+ };
65
+
66
+ const Field = ({
67
+ errorMessage,
68
+ hasVisibleLabel,
69
+ hint,
70
+ id: idOverride,
71
+ isDisabled = false,
72
+ isRequired = true,
73
+ label,
74
+ optionalLabel,
75
+ renderFieldComponent,
76
+ }: FieldProps) => {
77
+ const id = useUniqueId(idOverride);
78
+ const hintId = hint ? `${id}-hint` : undefined;
79
+ const errorId = errorMessage ? `${id}-error` : undefined;
80
+ const labelId = `${id}-label`;
81
+
82
+ const ariaDescribedBy = useMemo(
83
+ () => [hintId, errorId].join(" ").trim() || undefined,
84
+ [errorId, hintId]
85
+ );
86
+
87
+ return (
88
+ <FormControl disabled={isDisabled} error={Boolean(errorMessage)}>
89
+ <FieldLabel
90
+ hasVisibleLabel={hasVisibleLabel}
91
+ id={labelId}
92
+ inputId={id}
93
+ isRequired={isRequired}
94
+ optionalText={optionalLabel}
95
+ text={label}
96
+ />
97
+
98
+ {hint && <FieldHint id={hintId} text={hint} />}
99
+
100
+ {renderFieldComponent({
101
+ ariaDescribedBy,
102
+ id,
103
+ })}
104
+
105
+ {errorMessage && <FieldError id={errorId} text={errorMessage} />}
106
+ </FormControl>
107
+ );
108
+ };
109
+
110
+ const MemoizedField = memo(Field);
111
+
112
+ export { MemoizedField as Field };
@@ -0,0 +1,34 @@
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
+
15
+ import { FormHelperText } from ".";
16
+ import { ScreenReaderText } from "./ScreenReaderText";
17
+
18
+ export type FieldErrorProps = {
19
+ id?: string;
20
+ text: string;
21
+ };
22
+
23
+ const FieldError = ({ id, text }: FieldErrorProps) => {
24
+ return (
25
+ <FormHelperText error id={id}>
26
+ <ScreenReaderText>Error:</ScreenReaderText>
27
+ {text}
28
+ </FormHelperText>
29
+ );
30
+ };
31
+
32
+ const MemoizedFieldError = memo(FieldError);
33
+
34
+ export { MemoizedFieldError as FieldError };
@@ -0,0 +1,28 @@
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
+
15
+ import { FormHelperText } from "./";
16
+
17
+ export type FieldHintProps = {
18
+ id?: string;
19
+ text: string;
20
+ };
21
+
22
+ const FieldHint = ({ id, text }: FieldHintProps) => {
23
+ return <FormHelperText id={id}>{text}</FormHelperText>;
24
+ };
25
+
26
+ const MemoizedFieldHint = memo(FieldHint);
27
+
28
+ export { MemoizedFieldHint as FieldHint };
@@ -0,0 +1,57 @@
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 { InputLabel } from "@mui/material";
14
+ import { memo, useMemo } from "react";
15
+
16
+ import { ScreenReaderText } from "./ScreenReaderText";
17
+ import { Typography } from ".";
18
+
19
+ export type FieldLabelProps = {
20
+ hasVisibleLabel: boolean;
21
+ id: string;
22
+ inputId: string;
23
+ isRequired: boolean;
24
+ optionalText?: string;
25
+ text: string;
26
+ };
27
+
28
+ const FieldLabel = ({
29
+ hasVisibleLabel,
30
+ id,
31
+ inputId,
32
+ isRequired,
33
+ optionalText,
34
+ text,
35
+ }: FieldLabelProps) => {
36
+ const inputLabel = useMemo(
37
+ () => (
38
+ <InputLabel htmlFor={inputId} id={id}>
39
+ {text}
40
+ {!isRequired && (
41
+ <Typography variant="subtitle1">{optionalText}</Typography>
42
+ )}
43
+ </InputLabel>
44
+ ),
45
+ [id, inputId, isRequired, optionalText, text]
46
+ );
47
+
48
+ return hasVisibleLabel ? (
49
+ inputLabel
50
+ ) : (
51
+ <ScreenReaderText>{inputLabel}</ScreenReaderText>
52
+ );
53
+ };
54
+
55
+ const MemoizedFieldLabel = memo(FieldLabel);
56
+
57
+ export { MemoizedFieldLabel as FieldLabel };
@@ -77,10 +77,9 @@ const MenuButton = ({
77
77
  aria-haspopup="true"
78
78
  aria-expanded={open ? "true" : undefined}
79
79
  onClick={handleClick}
80
+ text={buttonLabel}
80
81
  variant={buttonVariant}
81
- >
82
- {buttonLabel}
83
- </Button>
82
+ />
84
83
  <Menu
85
84
  id={`${uniqueId}-menu`}
86
85
  anchorEl={anchorEl}
package/src/MenuItem.tsx CHANGED
@@ -45,6 +45,5 @@ const MenuItem = forwardRef<HTMLLIElement, MenuItemProps>(
45
45
  );
46
46
 
47
47
  const MemoizedMenuItem = memo(MenuItem);
48
- MemoizedMenuItem.displayName = "MenuItem";
49
48
 
50
49
  export { MemoizedMenuItem as MenuItem };
@@ -29,7 +29,7 @@ describe("OdysseyCacheProvider", () => {
29
29
  it("themes a Button", () => {
30
30
  render(
31
31
  <OdysseyCacheProvider>
32
- <Button>text</Button>
32
+ <Button text="text" />
33
33
  </OdysseyCacheProvider>
34
34
  );
35
35
 
@@ -0,0 +1,174 @@
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 { InputAdornment, InputBase } from "@mui/material";
14
+ import {
15
+ ChangeEventHandler,
16
+ FocusEventHandler,
17
+ forwardRef,
18
+ memo,
19
+ useCallback,
20
+ useState,
21
+ } from "react";
22
+
23
+ import { EyeIcon, EyeOffIcon, IconButton } from "./";
24
+ import { Field } from "./Field";
25
+
26
+ export type PasswordFieldProps = {
27
+ /**
28
+ * If `true`, the component will receive focus automatically.
29
+ */
30
+ autoFocus?: boolean;
31
+ /**
32
+ * This prop helps users to fill forms faster, especially on mobile devices.
33
+ * The name can be confusing, as it's more like an autofill.
34
+ * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
35
+ */
36
+ autoCompleteType?: "current-password" | "new-password";
37
+ /**
38
+ * If `error` is not undefined, the `input` will indicate an error.
39
+ */
40
+ errorMessage?: string;
41
+ /**
42
+ * The helper text content.
43
+ */
44
+ hint?: string;
45
+ /**
46
+ * The id of the `input` element.
47
+ */
48
+ id?: string;
49
+ /**
50
+ * If `true`, the component is disabled.
51
+ */
52
+ isDisabled?: boolean;
53
+ /**
54
+ * It prevents the user from changing the value of the field
55
+ */
56
+ isReadOnly?: boolean;
57
+ /**
58
+ * If `true`, the `input` element is required.
59
+ */
60
+ isRequired?: boolean;
61
+ /**
62
+ * The label for the `input` element.
63
+ */
64
+ label: string;
65
+ /**
66
+ * Callback fired when the `input` element loses focus.
67
+ */
68
+ onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
69
+ /**
70
+ * Callback fired when the value is changed.
71
+ */
72
+ onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
73
+ /**
74
+ * Callback fired when the `input` element get focus.
75
+ */
76
+ onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
77
+ /**
78
+ * The short hint displayed in the `input` before the user enters a value.
79
+ */
80
+ placeholder?: string;
81
+ /**
82
+ * The value of the `input` element, required for a controlled component.
83
+ */
84
+ value?: string;
85
+ };
86
+
87
+ const PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(
88
+ (
89
+ {
90
+ autoCompleteType,
91
+ autoFocus,
92
+ errorMessage,
93
+ hint,
94
+ id: idOverride,
95
+ isDisabled = false,
96
+ isReadOnly,
97
+ label,
98
+ onChange,
99
+ onFocus,
100
+ onBlur,
101
+ placeholder,
102
+ value,
103
+ },
104
+ ref
105
+ ) => {
106
+ const [inputType, setInputType] = useState("password");
107
+
108
+ const togglePasswordVisibility = useCallback(() => {
109
+ setInputType((inputType) =>
110
+ inputType === "password" ? "text" : "password"
111
+ );
112
+ }, []);
113
+
114
+ const renderFieldComponent = useCallback(
115
+ ({ ariaDescribedBy, id }) => (
116
+ <InputBase
117
+ aria-describedby={ariaDescribedBy}
118
+ autoComplete={autoCompleteType}
119
+ /* eslint-disable-next-line jsx-a11y/no-autofocus */
120
+ autoFocus={autoFocus}
121
+ endAdornment={
122
+ <InputAdornment position="end">
123
+ <IconButton
124
+ aria-label="toggle password visibility"
125
+ edge="end"
126
+ onClick={togglePasswordVisibility}
127
+ >
128
+ {inputType === "password" ? <EyeIcon /> : <EyeOffIcon />}
129
+ </IconButton>
130
+ </InputAdornment>
131
+ }
132
+ id={id}
133
+ onChange={onChange}
134
+ onFocus={onFocus}
135
+ onBlur={onBlur}
136
+ placeholder={placeholder}
137
+ readOnly={isReadOnly}
138
+ ref={ref}
139
+ type={inputType}
140
+ value={value}
141
+ />
142
+ ),
143
+ [
144
+ autoCompleteType,
145
+ autoFocus,
146
+ togglePasswordVisibility,
147
+ inputType,
148
+ onChange,
149
+ onFocus,
150
+ onBlur,
151
+ placeholder,
152
+ isReadOnly,
153
+ ref,
154
+ value,
155
+ ]
156
+ );
157
+
158
+ return (
159
+ <Field
160
+ errorMessage={errorMessage}
161
+ hasVisibleLabel
162
+ hint={hint}
163
+ id={idOverride}
164
+ isDisabled={isDisabled}
165
+ label={label}
166
+ renderFieldComponent={renderFieldComponent}
167
+ />
168
+ );
169
+ }
170
+ );
171
+
172
+ const MemoizedPasswordField = memo(PasswordField);
173
+
174
+ export { MemoizedPasswordField as PasswordField };