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

47 lines 2.43 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from 'react'; import { useStyles } from '../../hooks/useStyles/useStyles'; import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary'; import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent'; import { TextAreaStandAlone } from './textAreaStandAlone'; import { getState } from './utils/state.utils'; const TEXT_AREA_STYLES = 'TEXT_AREA_STYLES'; const TextAreaComponent = React.forwardRef(({ disabled = false, error = false, onFocus, onBlur, ctv, ...props }, ref) => { const styles = useStyles(TEXT_AREA_STYLES, props.variant, ctv); const [active, setActive] = React.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 (_jsx(TextAreaStandAlone, { ref: ref, state: getState(disabled, error, props.value, active), styles: styles, onBlur: _onBlur, onFocus: _onFocus, ...props })); }); TextAreaComponent.displayName = 'TextAreaComponent'; const TextareaBoundary = (props, ref) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(TextAreaStandAlone, { ...props, ref: ref }) }), children: _jsx(TextAreaComponent, { ...props, ref: ref }) })); const TextArea = React.forwardRef(TextareaBoundary); export { TextArea }; //# sourceMappingURL=textArea.js.map