@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
53 lines • 2.96 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextArea = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const useStyles_1 = require("../../hooks/useStyles/useStyles");
const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary");
const fallbackComponent_1 = require("../../provider/errorBoundary/fallbackComponent");
const textAreaStandAlone_1 = require("./textAreaStandAlone");
const state_utils_1 = require("./utils/state.utils");
const TEXT_AREA_STYLES = 'TEXT_AREA_STYLES';
const TextAreaComponent = react_1.default.forwardRef(({ disabled = false, error = false, onFocus, onBlur, ctv, ...props }, ref) => {
const styles = (0, useStyles_1.useStyles)(TEXT_AREA_STYLES, props.variant, ctv);
const [active, setActive] = react_1.default.useState(false);
const _onFocus = event => {
if (styles.labelInsideTextArea) {
const target = event?.target;
const parentElement = target?.parentElement;
if (target && parentElement) {
const targetComputedStyles = window.getComputedStyle(target);
parentElement.style.outline = targetComputedStyles.outline;
parentElement.style.boxShadow = targetComputedStyles.boxShadow;
target.style.outline = 'none';
target.style.boxShadow = 'none';
}
}
setActive(true);
onFocus?.(event);
};
const _onBlur = event => {
if (styles.labelInsideTextArea) {
const target = event?.target;
const parentElement = target?.parentElement;
if (target && parentElement) {
parentElement.style.removeProperty('outline');
parentElement.style.removeProperty('boxShadow');
target.style.removeProperty('outline');
target.style.removeProperty('boxShadow');
}
}
setActive(false);
onBlur?.(event);
};
return ((0, jsx_runtime_1.jsx)(textAreaStandAlone_1.TextAreaStandAlone, { ref: ref, state: (0, state_utils_1.getState)(disabled, error, props.value, active), styles: styles, onBlur: _onBlur, onFocus: _onFocus, ...props }));
});
TextAreaComponent.displayName = 'TextAreaComponent';
const TextareaBoundary = (props, ref) => ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(fallbackComponent_1.FallbackComponent, { children: (0, jsx_runtime_1.jsx)(textAreaStandAlone_1.TextAreaStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(TextAreaComponent, { ...props, ref: ref }) }));
const TextArea = react_1.default.forwardRef(TextareaBoundary);
exports.TextArea = TextArea;
//# sourceMappingURL=textArea.js.map