UNPKG

@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

50 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCheckBoxState = exports.checkboxState = void 0; const state_1 = require("../types/state"); const getCheckBoxState = (checked = false, disabled = false, error = false, // deprecated - Remove style from de method when the deprecated ERROR state is removed styles) => { if (error && !checked && styles?.[state_1.CheckboxStateType.ERROR_UNSELECTED]) { return state_1.CheckboxStateType.ERROR_UNSELECTED; } if (error && checked && styles?.[state_1.CheckboxStateType.ERROR_SELECTED]) { return state_1.CheckboxStateType.ERROR_SELECTED; } // deprecated - This `error` state will be deprecated in the future if (error) { return state_1.CheckboxStateType.ERROR; } if (disabled && !checked) { return state_1.CheckboxStateType.DISABLED_UNSELECTED; } if (disabled && checked) { return state_1.CheckboxStateType.DISABLED_SELECTED; } if (checked) { return state_1.CheckboxStateType.DEFAULT_SELECTED; } return state_1.CheckboxStateType.DEFAULT_UNSELECTED; }; exports.getCheckBoxState = getCheckBoxState; /** * Get the state of the checkbox * @param state * @returns {{isChecked: boolean, isDisabled: boolean, hasError: boolean}} * @constructor * @internal */ const checkboxState = (state) => { const isChecked = state === state_1.CheckboxStateType.DEFAULT_SELECTED || state === state_1.CheckboxStateType.DISABLED_SELECTED || state === state_1.CheckboxStateType.ERROR_SELECTED; const isDisabled = state === state_1.CheckboxStateType.DISABLED_UNSELECTED || state === state_1.CheckboxStateType.DISABLED_SELECTED; const hasError = state === state_1.CheckboxStateType.ERROR_SELECTED || state === state_1.CheckboxStateType.ERROR_UNSELECTED || // deprecated - This `error` state will be deprecated in the future state === state_1.CheckboxStateType.ERROR; return { isChecked, isDisabled, hasError }; }; exports.checkboxState = checkboxState; //# sourceMappingURL=state.utils.js.map