@okta/odyssey-react-mui 0.21.3 → 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 (158) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/Autocomplete.js +58 -0
  3. package/dist/Autocomplete.js.map +1 -0
  4. package/dist/Banner.js +2 -3
  5. package/dist/Banner.js.map +1 -1
  6. package/dist/Button.js +46 -0
  7. package/dist/Button.js.map +1 -0
  8. package/dist/CheckboxGroup.js +2 -3
  9. package/dist/CheckboxGroup.js.map +1 -1
  10. package/dist/CircularProgress.js +12 -0
  11. package/dist/CircularProgress.js.map +1 -0
  12. package/dist/Field.js +59 -0
  13. package/dist/Field.js.map +1 -0
  14. package/dist/FieldError.js +34 -0
  15. package/dist/FieldError.js.map +1 -0
  16. package/dist/FieldHint.js +29 -0
  17. package/dist/FieldHint.js.map +1 -0
  18. package/dist/FieldLabel.js +32 -0
  19. package/dist/FieldLabel.js.map +1 -0
  20. package/dist/Infobox.js +2 -3
  21. package/dist/Infobox.js.map +1 -1
  22. package/dist/MenuButton.js +2 -2
  23. package/dist/MenuButton.js.map +1 -1
  24. package/dist/MenuItem.js +0 -1
  25. package/dist/MenuItem.js.map +1 -1
  26. package/dist/PasswordField.js +68 -0
  27. package/dist/PasswordField.js.map +1 -0
  28. package/dist/RadioGroup.js +2 -3
  29. package/dist/RadioGroup.js.map +1 -1
  30. package/dist/ScreenReaderText.js +30 -0
  31. package/dist/ScreenReaderText.js.map +1 -0
  32. package/dist/SearchField.js +54 -0
  33. package/dist/SearchField.js.map +1 -0
  34. package/dist/Tag.js +28 -0
  35. package/dist/Tag.js.map +1 -0
  36. package/dist/TagList.js +26 -0
  37. package/dist/TagList.js.map +1 -0
  38. package/dist/TagListContext.js +16 -0
  39. package/dist/TagListContext.js.map +1 -0
  40. package/dist/TextField.js +26 -62
  41. package/dist/TextField.js.map +1 -1
  42. package/dist/index.js +12 -2
  43. package/dist/index.js.map +1 -1
  44. package/dist/src/Autocomplete.d.ts +27 -0
  45. package/dist/src/Autocomplete.d.ts.map +1 -0
  46. package/dist/src/Button.d.ts +31 -0
  47. package/dist/src/Button.d.ts.map +1 -0
  48. package/dist/src/CircularProgress.d.ts +16 -0
  49. package/dist/src/CircularProgress.d.ts.map +1 -0
  50. package/dist/src/Field.d.ts +54 -0
  51. package/dist/src/Field.d.ts.map +1 -0
  52. package/dist/src/FieldError.d.ts +19 -0
  53. package/dist/src/FieldError.d.ts.map +1 -0
  54. package/dist/src/FieldHint.d.ts +19 -0
  55. package/dist/src/FieldHint.d.ts.map +1 -0
  56. package/dist/src/FieldLabel.d.ts +23 -0
  57. package/dist/src/FieldLabel.d.ts.map +1 -0
  58. package/dist/src/Icon.d.ts +1 -1
  59. package/dist/src/Link.d.ts +1 -1
  60. package/dist/src/MenuButton.d.ts.map +1 -1
  61. package/dist/src/MenuItem.d.ts +1 -1
  62. package/dist/src/MenuItem.d.ts.map +1 -1
  63. package/dist/src/PasswordField.d.ts +75 -0
  64. package/dist/src/PasswordField.d.ts.map +1 -0
  65. package/dist/src/RadioGroup.d.ts.map +1 -1
  66. package/dist/src/ScreenReaderText.d.ts +21 -0
  67. package/dist/src/ScreenReaderText.d.ts.map +1 -0
  68. package/dist/src/SearchField.d.ts +59 -0
  69. package/dist/src/SearchField.d.ts.map +1 -0
  70. package/dist/src/Tag.d.ts +22 -0
  71. package/dist/src/Tag.d.ts.map +1 -0
  72. package/dist/src/TagList.d.ts +19 -0
  73. package/dist/src/TagList.d.ts.map +1 -0
  74. package/dist/src/TagListContext.d.ts +18 -0
  75. package/dist/src/TagListContext.d.ts.map +1 -0
  76. package/dist/src/TextField.d.ts +3 -8
  77. package/dist/src/TextField.d.ts.map +1 -1
  78. package/dist/src/iconDictionary/Add.d.ts +1 -1
  79. package/dist/src/iconDictionary/AddCircle.d.ts +1 -1
  80. package/dist/src/iconDictionary/AlertCircle.d.ts +1 -1
  81. package/dist/src/iconDictionary/AlertCircleFilled.d.ts +1 -1
  82. package/dist/src/iconDictionary/AlertTriangleFilled.d.ts +1 -1
  83. package/dist/src/iconDictionary/Anchor.d.ts +1 -1
  84. package/dist/src/iconDictionary/ArrowDown.d.ts +1 -1
  85. package/dist/src/iconDictionary/ArrowLeft.d.ts +1 -1
  86. package/dist/src/iconDictionary/ArrowRight.d.ts +1 -1
  87. package/dist/src/iconDictionary/ArrowUp.d.ts +1 -1
  88. package/dist/src/iconDictionary/ArrowUpDown.d.ts +1 -1
  89. package/dist/src/iconDictionary/Calendar.d.ts +1 -1
  90. package/dist/src/iconDictionary/Check.d.ts +1 -1
  91. package/dist/src/iconDictionary/CheckCircleFilled.d.ts +1 -1
  92. package/dist/src/iconDictionary/ChevronDown.d.ts +1 -1
  93. package/dist/src/iconDictionary/ChevronUp.d.ts +1 -1
  94. package/dist/src/iconDictionary/Close.d.ts +1 -1
  95. package/dist/src/iconDictionary/CloseCircleFilled.d.ts +1 -1
  96. package/dist/src/iconDictionary/Copy.d.ts +1 -1
  97. package/dist/src/iconDictionary/Delete.d.ts +1 -1
  98. package/dist/src/iconDictionary/Download.d.ts +1 -1
  99. package/dist/src/iconDictionary/DragHandle.d.ts +1 -1
  100. package/dist/src/iconDictionary/Edit.d.ts +1 -1
  101. package/dist/src/iconDictionary/ExternalLink.d.ts +1 -1
  102. package/dist/src/iconDictionary/Eye.d.ts +1 -1
  103. package/dist/src/iconDictionary/EyeOff.d.ts +1 -1
  104. package/dist/src/iconDictionary/Filter.d.ts +1 -1
  105. package/dist/src/iconDictionary/Globe.d.ts +1 -1
  106. package/dist/src/iconDictionary/Home.d.ts +1 -1
  107. package/dist/src/iconDictionary/InformationCircle.d.ts +1 -1
  108. package/dist/src/iconDictionary/InformationCircleFilled.d.ts +1 -1
  109. package/dist/src/iconDictionary/Notification.d.ts +1 -1
  110. package/dist/src/iconDictionary/OverflowVertical.d.ts +1 -1
  111. package/dist/src/iconDictionary/QuestionCircle.d.ts +1 -1
  112. package/dist/src/iconDictionary/QuestionCircleFilled.d.ts +1 -1
  113. package/dist/src/iconDictionary/Search.d.ts +1 -1
  114. package/dist/src/iconDictionary/Settings.d.ts +1 -1
  115. package/dist/src/iconDictionary/Subtract.d.ts +1 -1
  116. package/dist/src/iconDictionary/User.d.ts +1 -1
  117. package/dist/src/iconDictionary/UserGroup.d.ts +1 -1
  118. package/dist/src/iconDictionary/index.d.ts +40 -40
  119. package/dist/src/index.d.ts +13 -3
  120. package/dist/src/index.d.ts.map +1 -1
  121. package/dist/src/theme/components.d.ts.map +1 -1
  122. package/dist/src/theme/components.types.d.ts +0 -8
  123. package/dist/src/theme/components.types.d.ts.map +1 -1
  124. package/dist/theme/components.js +217 -124
  125. package/dist/theme/components.js.map +1 -1
  126. package/dist/theme/components.types.js.map +1 -1
  127. package/dist/tsconfig.production.tsbuildinfo +1 -1
  128. package/package.json +3 -3
  129. package/src/Autocomplete.tsx +132 -0
  130. package/src/Banner.tsx +2 -2
  131. package/src/Button.tsx +75 -0
  132. package/src/CheckboxGroup.tsx +2 -2
  133. package/src/CircularProgress.tsx +24 -0
  134. package/src/Field.tsx +112 -0
  135. package/src/FieldError.tsx +34 -0
  136. package/src/FieldHint.tsx +28 -0
  137. package/src/FieldLabel.tsx +57 -0
  138. package/src/Infobox.tsx +2 -2
  139. package/src/MenuButton.tsx +2 -3
  140. package/src/MenuItem.tsx +0 -1
  141. package/src/OdysseyCacheProvider.test.tsx +1 -1
  142. package/src/PasswordField.tsx +174 -0
  143. package/src/RadioGroup.tsx +2 -2
  144. package/src/ScreenReaderText.tsx +36 -0
  145. package/src/SearchField.tsx +136 -0
  146. package/src/Tag.tsx +41 -0
  147. package/src/TagList.tsx +43 -0
  148. package/src/TagListContext.tsx +23 -0
  149. package/src/TextField.tsx +43 -101
  150. package/src/index.ts +11 -5
  151. package/src/theme/components.tsx +87 -18
  152. package/src/theme/components.types.ts +0 -8
  153. package/dist/PasswordInput.js +0 -87
  154. package/dist/PasswordInput.js.map +0 -1
  155. package/dist/src/PasswordInput.d.ts +0 -21
  156. package/dist/src/PasswordInput.d.ts.map +0 -1
  157. package/src/PasswordInput.test.tsx +0 -51
  158. package/src/PasswordInput.tsx +0 -111
@@ -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 };
@@ -17,8 +17,8 @@ import {
17
17
  FormControl,
18
18
  FormLabel,
19
19
  FormHelperText,
20
- visuallyHidden,
21
20
  Radio,
21
+ ScreenReaderText,
22
22
  useUniqueId,
23
23
  RadioProps,
24
24
  } from ".";
@@ -104,7 +104,7 @@ const RadioGroup = ({
104
104
  </MuiRadioGroup>
105
105
  {errorMessage && (
106
106
  <FormHelperText id={`${uniqueName}-error`} error>
107
- <span style={visuallyHidden}>Error:</span> {errorMessage}
107
+ <ScreenReaderText>Error:</ScreenReaderText> {errorMessage}
108
108
  </FormHelperText>
109
109
  )}
110
110
  </FormControl>
@@ -0,0 +1,36 @@
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, ReactNode } from "react";
14
+ import { Box, visuallyHidden } from "./";
15
+
16
+ export type ScreenReaderTextProps = {
17
+ /**
18
+ * The visually-hidden text.
19
+ */
20
+ children: ReactNode;
21
+ };
22
+
23
+ /**
24
+ * MUI sx expects you pass in a CSS object, not an object with CSS.
25
+ * They seem identical, but only if you create a new object like this will MUI be happy with the type of visuallyHidden.
26
+ * It's otherwise a regular object with CSS properties.
27
+ */
28
+ const style = { ...visuallyHidden };
29
+
30
+ const ScreenReaderText = ({ children }: ScreenReaderTextProps) => (
31
+ <Box sx={style}>{children}</Box>
32
+ );
33
+
34
+ const MemoizedScreenReaderText = memo(ScreenReaderText);
35
+
36
+ export { MemoizedScreenReaderText as ScreenReaderText };
@@ -0,0 +1,136 @@
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
+ InputHTMLAttributes,
19
+ memo,
20
+ useCallback,
21
+ } from "react";
22
+
23
+ import { SearchIcon } from "./";
24
+ import { Field } from "./Field";
25
+
26
+ export type SearchFieldProps = {
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?: InputHTMLAttributes<HTMLInputElement>["autoComplete"];
37
+ /**
38
+ * The id of the `input` element.
39
+ */
40
+ id?: string;
41
+ /**
42
+ * If `true`, the component is disabled.
43
+ */
44
+ isDisabled?: boolean;
45
+ /**
46
+ * This label won't show up visually, but it's required for accessibility.
47
+ */
48
+ label: string;
49
+ /**
50
+ * Callback fired when the `input` element loses focus.
51
+ */
52
+ onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
53
+ /**
54
+ * Callback fired when the value is changed.
55
+ */
56
+ onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
57
+ /**
58
+ * Callback fired when the `input` element get focus.
59
+ */
60
+ onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
61
+ /**
62
+ * The short hint displayed in the `input` before the user enters a value.
63
+ */
64
+ placeholder?: string;
65
+ /**
66
+ * The value of the `input` element, required for a controlled component.
67
+ */
68
+ value?: string;
69
+ };
70
+
71
+ const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
72
+ (
73
+ {
74
+ autoCompleteType,
75
+ autoFocus,
76
+ id: idOverride,
77
+ isDisabled = false,
78
+ label,
79
+ onChange,
80
+ onFocus,
81
+ onBlur,
82
+ placeholder,
83
+ value,
84
+ },
85
+ ref
86
+ ) => {
87
+ const renderFieldComponent = useCallback(
88
+ ({ ariaDescribedBy, id }) => (
89
+ <InputBase
90
+ aria-describedby={ariaDescribedBy}
91
+ autoComplete={autoCompleteType}
92
+ /* eslint-disable-next-line jsx-a11y/no-autofocus */
93
+ autoFocus={autoFocus}
94
+ id={id}
95
+ onChange={onChange}
96
+ onFocus={onFocus}
97
+ onBlur={onBlur}
98
+ placeholder={placeholder}
99
+ ref={ref}
100
+ startAdornment={
101
+ <InputAdornment position="start">
102
+ <SearchIcon />
103
+ </InputAdornment>
104
+ }
105
+ type="search"
106
+ value={value}
107
+ />
108
+ ),
109
+ [
110
+ autoCompleteType,
111
+ autoFocus,
112
+ onChange,
113
+ onFocus,
114
+ onBlur,
115
+ placeholder,
116
+ ref,
117
+ value,
118
+ ]
119
+ );
120
+
121
+ return (
122
+ <Field
123
+ hasVisibleLabel={false}
124
+ id={idOverride}
125
+ isDisabled={isDisabled}
126
+ isRequired={false}
127
+ label={label}
128
+ renderFieldComponent={renderFieldComponent}
129
+ />
130
+ );
131
+ }
132
+ );
133
+
134
+ const MemoizedSearchField = memo(SearchField);
135
+
136
+ export { MemoizedSearchField as SearchField };
package/src/Tag.tsx ADDED
@@ -0,0 +1,41 @@
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 { Chip, ChipProps } from "@mui/material";
14
+ import { memo, useContext } from "react";
15
+ import { TagListContext } from "./TagListContext";
16
+
17
+ export type TagProps = {
18
+ isDisabled?: boolean;
19
+ label: string;
20
+ onClick?: ChipProps["onClick"];
21
+ onRemove?: ChipProps["onDelete"];
22
+ };
23
+
24
+ const Tag = ({ isDisabled, label, onClick, onRemove }: TagProps) => {
25
+ const { chipElementType } = useContext(TagListContext);
26
+
27
+ return (
28
+ <Chip
29
+ label={label}
30
+ clickable={onClick ? true : false}
31
+ component={chipElementType}
32
+ disabled={isDisabled}
33
+ onClick={onClick}
34
+ onDelete={onRemove}
35
+ />
36
+ );
37
+ };
38
+
39
+ const MemoizedTag = memo(Tag);
40
+
41
+ export { MemoizedTag as Tag };
@@ -0,0 +1,43 @@
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 { Tag } from "./";
14
+ import { Stack } from "@mui/material";
15
+ import { memo, ReactElement, useMemo } from "react";
16
+ import { ChipElementType, TagListContext } from "./TagListContext";
17
+
18
+ export type TagListProps = {
19
+ children: ReactElement<typeof Tag> | Array<ReactElement<typeof Tag>>;
20
+ };
21
+
22
+ const TagList = ({ children }: TagListProps) => {
23
+ const providerValue = useMemo<{
24
+ chipElementType: ChipElementType;
25
+ }>(
26
+ () => ({
27
+ chipElementType: "li",
28
+ }),
29
+ []
30
+ );
31
+
32
+ return (
33
+ <Stack component="ul" direction="row" spacing={2}>
34
+ <TagListContext.Provider value={providerValue}>
35
+ {children}
36
+ </TagListContext.Provider>
37
+ </Stack>
38
+ );
39
+ };
40
+
41
+ const MemoizedTagList = memo(TagList);
42
+
43
+ export { MemoizedTagList as TagList };
@@ -0,0 +1,23 @@
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 { createContext } from "react";
14
+
15
+ export type ChipElementType = "li" | "div";
16
+
17
+ export type TagListContextType = {
18
+ chipElementType: ChipElementType;
19
+ };
20
+
21
+ export const TagListContext = createContext<TagListContextType>({
22
+ chipElementType: "div",
23
+ });
package/src/TextField.tsx CHANGED
@@ -10,12 +10,7 @@
10
10
  * See the License for the specific language governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {
14
- InputAdornment,
15
- InputBase,
16
- InputBaseProps,
17
- InputLabel,
18
- } from "@mui/material";
13
+ import { InputBase } from "@mui/material";
19
14
  import {
20
15
  ChangeEventHandler,
21
16
  FocusEventHandler,
@@ -24,22 +19,9 @@ import {
24
19
  memo,
25
20
  ReactNode,
26
21
  useCallback,
27
- useEffect,
28
- useMemo,
29
- useState,
30
22
  } from "react";
31
23
 
32
- import {
33
- EyeIcon,
34
- EyeOffIcon,
35
- FormControl,
36
- FormHelperText,
37
- IconButton,
38
- SearchIcon,
39
- Typography,
40
- useUniqueId,
41
- visuallyHidden,
42
- } from "./";
24
+ import { Field } from "./Field";
43
25
 
44
26
  export type TextFieldProps = {
45
27
  /**
@@ -68,10 +50,6 @@ export type TextFieldProps = {
68
50
  * The id of the `input` element.
69
51
  */
70
52
  id?: string;
71
- /**
72
- * Props that go onto the HTML `input` element.
73
- */
74
- inputProps?: InputBaseProps["inputProps"];
75
53
  /**
76
54
  * If `true`, the component is disabled.
77
55
  */
@@ -91,7 +69,7 @@ export type TextFieldProps = {
91
69
  /**
92
70
  * The label for the `input` element.
93
71
  */
94
- label?: string;
72
+ label: string;
95
73
  /**
96
74
  * Callback fired when the `input` element loses focus.
97
75
  */
@@ -119,11 +97,11 @@ export type TextFieldProps = {
119
97
  /**
120
98
  * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
121
99
  */
122
- type?: string;
100
+ type?: "email" | "number" | "tel" | "text" | "url";
123
101
  /**
124
102
  * The value of the `input` element, required for a controlled component.
125
103
  */
126
- value?: unknown;
104
+ value?: string;
127
105
  };
128
106
 
129
107
  const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
@@ -135,15 +113,14 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
135
113
  errorMessage,
136
114
  hint,
137
115
  id: idOverride,
138
- inputProps = {},
139
116
  isDisabled = false,
140
117
  isMultiline = false,
141
118
  isReadOnly,
142
119
  isRequired = true,
143
120
  label,
121
+ onBlur,
144
122
  onChange,
145
123
  onFocus,
146
- onBlur,
147
124
  optionalLabel,
148
125
  placeholder,
149
126
  startAdornment,
@@ -152,91 +129,56 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
152
129
  },
153
130
  ref
154
131
  ) => {
155
- const [inputType, setInputType] = useState(type);
156
-
157
- useEffect(() => {
158
- setInputType(type);
159
- }, [type]);
160
-
161
- const togglePasswordVisibility = useCallback(() => {
162
- setInputType((currentType) =>
163
- currentType === "password" ? "text" : "password"
164
- );
165
- }, []);
166
-
167
- const id = useUniqueId(idOverride);
168
- const hintId = hint ? `${id}-hint` : undefined;
169
- const errorId = errorMessage ? `${id}-error` : undefined;
170
- const labelId = label ? `${id}-label` : undefined;
171
-
172
- const localInputProps = useMemo(() => {
173
- const ariaDescribedBy =
174
- errorId && hintId ? `${hintId} ${errorId}` : errorId || hintId;
175
-
176
- return {
177
- ...inputProps,
178
- "aria-describedby":
179
- inputProps["aria-describedby"]?.concat(` ${ariaDescribedBy}`) ??
180
- ariaDescribedBy,
181
- };
182
- }, [errorId, hintId, inputProps]);
183
-
184
- return (
185
- <FormControl disabled={isDisabled} error={Boolean(errorMessage)}>
186
- <InputLabel htmlFor={id} id={labelId}>
187
- {label}
188
- {!isRequired && (
189
- <Typography variant="subtitle1">{optionalLabel}</Typography>
190
- )}
191
- </InputLabel>
192
- {hint && <FormHelperText id={hintId}>{hint}</FormHelperText>}
132
+ const renderFieldComponent = useCallback(
133
+ ({ ariaDescribedBy, id }) => (
193
134
  <InputBase
135
+ aria-describedby={ariaDescribedBy}
194
136
  autoComplete={autoCompleteType}
195
137
  /* eslint-disable-next-line jsx-a11y/no-autofocus */
196
138
  autoFocus={autoFocus}
197
- endAdornment={
198
- type === "password" ? (
199
- <InputAdornment position="end">
200
- <IconButton
201
- aria-label="toggle password visibility"
202
- edge="end"
203
- onClick={togglePasswordVisibility}
204
- >
205
- {inputType === "password" ? <EyeIcon /> : <EyeOffIcon />}
206
- </IconButton>
207
- </InputAdornment>
208
- ) : (
209
- endAdornment
210
- )
211
- }
139
+ endAdornment={endAdornment}
212
140
  id={id}
213
- inputProps={localInputProps}
214
141
  multiline={isMultiline}
142
+ onBlur={onBlur}
215
143
  onChange={onChange}
216
144
  onFocus={onFocus}
217
- onBlur={onBlur}
218
145
  placeholder={placeholder}
219
146
  readOnly={isReadOnly}
220
147
  ref={ref}
221
- startAdornment={
222
- inputType === "search" ? (
223
- <InputAdornment position="start">
224
- <SearchIcon />
225
- </InputAdornment>
226
- ) : (
227
- startAdornment
228
- )
229
- }
230
- type={inputType}
148
+ startAdornment={startAdornment}
149
+ type={type}
231
150
  value={value}
232
151
  />
233
- {errorMessage && (
234
- <FormHelperText error id={errorId}>
235
- <span style={visuallyHidden}>Error:</span>
236
- {errorMessage}
237
- </FormHelperText>
238
- )}
239
- </FormControl>
152
+ ),
153
+ [
154
+ autoCompleteType,
155
+ autoFocus,
156
+ endAdornment,
157
+ isMultiline,
158
+ onChange,
159
+ onFocus,
160
+ onBlur,
161
+ placeholder,
162
+ isReadOnly,
163
+ ref,
164
+ startAdornment,
165
+ type,
166
+ value,
167
+ ]
168
+ );
169
+
170
+ return (
171
+ <Field
172
+ errorMessage={errorMessage}
173
+ hasVisibleLabel
174
+ hint={hint}
175
+ id={idOverride}
176
+ isDisabled={isDisabled}
177
+ isRequired={isRequired}
178
+ label={label}
179
+ optionalLabel={optionalLabel}
180
+ renderFieldComponent={renderFieldComponent}
181
+ />
240
182
  );
241
183
  }
242
184
  );