UNPKG

@porsche-design-system/components-react

Version:

Porsche Design System is a component library designed to help developers create the best experience for software or services distributed by Dr. Ing. h.c. F. Porsche AG.

39 lines (36 loc) 2.35 kB
"use client"; import { jsx } from 'react/jsx-runtime'; import { forwardRef, useRef } from 'react'; import { useEventCallback, usePrefix, useTheme, useBrowserLayoutEffect, useMergedClass } from '../../hooks.mjs'; import { syncRef } from '../../utils.mjs'; import { DSRTextarea } from '../dsr-components/textarea.mjs'; const PTextarea = /*#__PURE__*/ forwardRef(({ autoComplete = '', description = '', disabled = false, form, hideLabel = false, label = '', maxLength, message = '', minLength, name, onBlur, onChange, onInput, placeholder = '', readOnly = false, required = false, resize = 'vertical', rows = 7, showCounter = true, spellCheck, state = 'none', theme, value = '', wrap = 'soft', className, children, ...rest }, ref) => { const elementRef = useRef(undefined); useEventCallback(elementRef, 'blur', onBlur); useEventCallback(elementRef, 'change', onChange); useEventCallback(elementRef, 'input', onInput); const WebComponentTag = usePrefix('p-textarea'); const propsToSync = [autoComplete, description, disabled, form, hideLabel, label, maxLength, message, minLength, name, placeholder, readOnly, required, resize, rows, showCounter, spellCheck, state, theme || useTheme(), value, wrap]; useBrowserLayoutEffect(() => { const { current } = elementRef; ['autoComplete', 'description', 'disabled', 'form', 'hideLabel', 'label', 'maxLength', 'message', 'minLength', 'name', 'placeholder', 'readOnly', 'required', 'resize', 'rows', 'showCounter', 'spellCheck', 'state', 'theme', 'value', 'wrap'].forEach((propName, i) => (current[propName] = propsToSync[i])); }, propsToSync); const props = { ...rest, // @ts-ignore ...(!process.browser ? { children: (jsx(DSRTextarea, { autoComplete, description, disabled, form, hideLabel, label, maxLength, message, minLength, name, placeholder, readOnly, required, resize, rows, showCounter, spellCheck, state, theme: theme || useTheme(), value, wrap, children })), } : { children, suppressHydrationWarning: true, }), 'data-ssr': '', class: useMergedClass(elementRef, className), ref: syncRef(elementRef, ref) }; // @ts-ignore return jsx(WebComponentTag, { ...props }); }); export { PTextarea };