|
1 |
| -import { CheckboxStateType } from '../types'; |
| 1 | +import { CheckboxPropsStateStylesType, CheckboxStateType } from '../types'; |
2 | 2 |
|
3 | 3 | // eslint-disable-next-line complexity
|
4 | 4 | const getCheckBoxState = (
|
5 | 5 | checked = false,
|
6 | 6 | disabled = false,
|
7 |
| - isError = false |
| 7 | + error = false, |
| 8 | + // deprecated - Remove style from de method when the deprecated ERROR state is removed |
| 9 | + styles?: CheckboxPropsStateStylesType |
8 | 10 | ): CheckboxStateType => {
|
9 |
| - if (isError) { |
| 11 | + if (error && !checked && styles?.[CheckboxStateType.ERROR_UNSELECTED]) { |
| 12 | + return CheckboxStateType.ERROR_UNSELECTED; |
| 13 | + } |
| 14 | + if (error && checked && styles?.[CheckboxStateType.ERROR_SELECTED]) { |
| 15 | + return CheckboxStateType.ERROR_SELECTED; |
| 16 | + } |
| 17 | + // deprecated - This `error` state will be deprecated in the future |
| 18 | + if (error) { |
10 | 19 | return CheckboxStateType.ERROR;
|
11 | 20 | }
|
12 | 21 | if (disabled && !checked) {
|
@@ -36,11 +45,17 @@ export const checkboxState = (
|
36 | 45 | hasError: boolean;
|
37 | 46 | } => {
|
38 | 47 | const isChecked =
|
39 |
| - state === CheckboxStateType.DEFAULT_SELECTED || state === CheckboxStateType.DISABLED_SELECTED; |
| 48 | + state === CheckboxStateType.DEFAULT_SELECTED || |
| 49 | + state === CheckboxStateType.DISABLED_SELECTED || |
| 50 | + state === CheckboxStateType.ERROR_SELECTED; |
40 | 51 | const isDisabled =
|
41 | 52 | state === CheckboxStateType.DISABLED_UNSELECTED ||
|
42 | 53 | state === CheckboxStateType.DISABLED_SELECTED;
|
43 |
| - const hasError = state === CheckboxStateType.ERROR; |
| 54 | + const hasError = |
| 55 | + state === CheckboxStateType.ERROR_SELECTED || |
| 56 | + state === CheckboxStateType.ERROR_UNSELECTED || |
| 57 | + // deprecated - This `error` state will be deprecated in the future |
| 58 | + state === CheckboxStateType.ERROR; |
44 | 59 | return { isChecked, isDisabled, hasError };
|
45 | 60 | };
|
46 | 61 |
|
|
0 commit comments