@okta/odyssey-react-mui 1.7.1 → 1.8.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 +12 -0
- package/dist/@types/react-augment.d.js +2 -0
- package/dist/@types/react-augment.d.js.map +1 -0
- package/dist/Autocomplete.js +32 -23
- package/dist/Autocomplete.js.map +1 -1
- package/dist/Checkbox.js +33 -18
- package/dist/Checkbox.js.map +1 -1
- package/dist/NativeSelect.js +22 -8
- package/dist/NativeSelect.js.map +1 -1
- package/dist/PasswordField.js +19 -5
- package/dist/PasswordField.js.map +1 -1
- package/dist/RadioGroup.js +11 -8
- package/dist/RadioGroup.js.map +1 -1
- package/dist/SearchField.js +17 -16
- package/dist/SearchField.js.map +1 -1
- package/dist/Select.js +34 -18
- package/dist/Select.js.map +1 -1
- package/dist/TextField.js +20 -6
- package/dist/TextField.js.map +1 -1
- package/dist/inputUtils.js +46 -0
- package/dist/inputUtils.js.map +1 -0
- package/dist/labs/VirtualizedAutocomplete.js +29 -23
- package/dist/labs/VirtualizedAutocomplete.js.map +1 -1
- package/dist/src/Autocomplete.d.ts +0 -1
- package/dist/src/Autocomplete.d.ts.map +1 -1
- package/dist/src/Checkbox.d.ts +5 -1
- package/dist/src/Checkbox.d.ts.map +1 -1
- package/dist/src/NativeSelect.d.ts +19 -44
- package/dist/src/NativeSelect.d.ts.map +1 -1
- package/dist/src/PasswordField.d.ts +10 -2
- package/dist/src/PasswordField.d.ts.map +1 -1
- package/dist/src/RadioGroup.d.ts.map +1 -1
- package/dist/src/SearchField.d.ts +10 -2
- package/dist/src/SearchField.d.ts.map +1 -1
- package/dist/src/Select.d.ts +5 -1
- package/dist/src/Select.d.ts.map +1 -1
- package/dist/src/TextField.d.ts +8 -0
- package/dist/src/TextField.d.ts.map +1 -1
- package/dist/src/inputUtils.d.ts +47 -0
- package/dist/src/inputUtils.d.ts.map +1 -0
- package/dist/src/labs/VirtualizedAutocomplete.d.ts.map +1 -1
- package/dist/tsconfig.production.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/@types/react-augment.d.ts +19 -0
- package/src/Autocomplete.tsx +49 -43
- package/src/Checkbox.tsx +41 -22
- package/src/NativeSelect.tsx +78 -25
- package/src/PasswordField.tsx +32 -4
- package/src/RadioGroup.tsx +12 -10
- package/src/SearchField.tsx +24 -18
- package/src/Select.tsx +43 -25
- package/src/TextField.tsx +33 -5
- package/src/inputUtils.ts +76 -0
- package/src/labs/VirtualizedAutocomplete.tsx +48 -42
- package/dist/src/useControlledState.d.ts +0 -28
- package/dist/src/useControlledState.d.ts.map +0 -1
- package/dist/useControlledState.js +0 -33
- package/dist/useControlledState.js.map +0 -1
- package/src/useControlledState.ts +0 -56
|
@@ -1,56 +0,0 @@
|
|
|
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 { useEffect, useRef, useState } from "react";
|
|
14
|
-
|
|
15
|
-
type UseControlledStateProps<Value> = {
|
|
16
|
-
controlledValue?: Value; // isChecked
|
|
17
|
-
uncontrolledValue?: Value; // isDefaultChecked
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Use the same way as `useState`. Returns a stateful value, and a function to update it.
|
|
22
|
-
* When `initialState` is passed, the returned function to update it does nothing. This is
|
|
23
|
-
* useful to handle values in components that may be controlled externally when that value is
|
|
24
|
-
* passed in props and thus wish to prevent internal updates of the same value.
|
|
25
|
-
*
|
|
26
|
-
* @param initialState
|
|
27
|
-
* @see https://react.dev/reference/react/useState
|
|
28
|
-
*/
|
|
29
|
-
export const useControlledState = <Value>({
|
|
30
|
-
controlledValue,
|
|
31
|
-
uncontrolledValue,
|
|
32
|
-
}: UseControlledStateProps<Value>) => {
|
|
33
|
-
const isControlledMode = useRef(controlledValue !== undefined);
|
|
34
|
-
const [stateValue, setStateValue] = useState(
|
|
35
|
-
isControlledMode.current ? controlledValue : uncontrolledValue
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (isControlledMode.current) {
|
|
40
|
-
setStateValue(controlledValue);
|
|
41
|
-
}
|
|
42
|
-
}, [controlledValue]);
|
|
43
|
-
|
|
44
|
-
const setState: typeof setStateValue = (value) => {
|
|
45
|
-
if (!isControlledMode.current) {
|
|
46
|
-
setStateValue(value);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return [
|
|
51
|
-
stateValue,
|
|
52
|
-
// If `value` is controlled externally, ignore calls to the setter.
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
-
setState,
|
|
55
|
-
] as const;
|
|
56
|
-
};
|