@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
42 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDisabled = exports.hasError = exports.getState = void 0;
const inputTheme_1 = require("../types/inputTheme");
const getState = (value, focus, disabled = false, error = false, informationAssociated) => {
const valueCheck = (stateFilled, stateEmpty) => {
return value ? stateFilled : stateEmpty;
};
if (disabled) {
if (value && informationAssociated) {
return inputTheme_1.InputState.DISABLED_FILLED_WITH_INFO;
}
return valueCheck(inputTheme_1.InputState.DISABLED_FILLED, inputTheme_1.InputState.DISABLED_EMPTY);
}
if (error) {
if (value && informationAssociated) {
return inputTheme_1.InputState.ERROR_FILLED_WITH_INFO;
}
if (focus) {
return inputTheme_1.InputState.ERROR_ACTIVE;
}
return valueCheck(inputTheme_1.InputState.ERROR_FILLED, inputTheme_1.InputState.ERROR_EMPTY);
}
if (focus) {
return inputTheme_1.InputState.ACTIVE;
}
return valueCheck(inputTheme_1.InputState.FILLED, inputTheme_1.InputState.EMPTY);
};
exports.getState = getState;
const hasError = (state) => {
return (state === inputTheme_1.InputState.ERROR_EMPTY ||
state === inputTheme_1.InputState.ERROR_FILLED ||
state === inputTheme_1.InputState.ERROR_ACTIVE);
};
exports.hasError = hasError;
const isDisabled = (state) => {
return (state === inputTheme_1.InputState.DISABLED_EMPTY ||
state === inputTheme_1.InputState.DISABLED_FILLED ||
state === inputTheme_1.InputState.DISABLED_FILLED_WITH_INFO);
};
exports.isDisabled = isDisabled;
//# sourceMappingURL=state.utils.js.map