@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
60 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.radioButtonState = exports.getState = void 0;
const state_1 = require("../components/radioButton/types/state");
/**
* Get the state of the radioButton
* @param checked
* @param disabled
* @param error
* @param state
* @returns {RadioButtonStateType}
* @constructor
* @internal
*/
// deprecated - Remove `state` param when `state` prop is removed from `RadioButton`
const getState = (checked = false, disabled = false, error = false, state) => {
const hasError = error || state === state_1.RadioButtonStateType.ERROR || state === state_1.RadioButtonStateType.ERROR_SELECTED;
const isDisabled = disabled ||
state === state_1.RadioButtonStateType.DISABLED ||
state === state_1.RadioButtonStateType.DISABLED_SELECTED;
const selected = checked ||
state === state_1.RadioButtonStateType.SELECTED ||
state === state_1.RadioButtonStateType.DISABLED_SELECTED ||
state === state_1.RadioButtonStateType.ERROR_SELECTED;
if (hasError && !selected) {
return state_1.RadioButtonStateType.ERROR;
}
if (hasError && selected) {
return state_1.RadioButtonStateType.ERROR_SELECTED;
}
if (isDisabled && !selected) {
return state_1.RadioButtonStateType.DISABLED;
}
if (isDisabled && selected) {
return state_1.RadioButtonStateType.DISABLED_SELECTED;
}
if (selected) {
return state_1.RadioButtonStateType.SELECTED;
}
return state_1.RadioButtonStateType.DEFAULT;
};
exports.getState = getState;
/**
* Get the state of the radioButton
* @param state
* @returns {{isChecked: boolean, isDisabled: boolean, hasError: boolean}}
* @constructor
* @internal
*/
// deprecated - Remove the method when `state` prop is removed from `RadioButton`
const radioButtonState = (state) => {
const isChecked = state === state_1.RadioButtonStateType.SELECTED ||
state === state_1.RadioButtonStateType.DISABLED_SELECTED ||
state === state_1.RadioButtonStateType.ERROR_SELECTED;
const isDisabled = state === state_1.RadioButtonStateType.DISABLED || state === state_1.RadioButtonStateType.DISABLED_SELECTED;
const hasError = state === state_1.RadioButtonStateType.ERROR || state === state_1.RadioButtonStateType.ERROR_SELECTED;
return { isChecked, isDisabled, hasError };
};
exports.radioButtonState = radioButtonState;
//# sourceMappingURL=state.utils.js.map