react#TextareaHTMLAttributes TypeScript Examples

The following examples show how to use react#TextareaHTMLAttributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageFormatEditor.tsx    From project-loved-web with MIT License 6 votes vote down vote up
export default function MessageFormatEditor({
  className,
  readOnly,
  setValue,
  value,
  ...props
}: MessageFormatEditorProps & TextareaHTMLAttributes<HTMLDivElement>) {
  const editor = useMemo(() => withReact(createEditor()), []);

  return (
    <Slate
      editor={editor}
      onChange={(value) => {
        if (!readOnly) {
          setValue!(((value[0] as Element).children[0] as Text).text);
        }
      }}
      value={[{ children: [{ text: value, type: 0 }] }]}
    >
      <Editable
        {...props}
        className={`slate-editor${readOnly ? '' : ' editable'} ${className ?? ''}`}
        decorate={decorate}
        onKeyDown={onKeyDown}
        readOnly={readOnly}
        renderLeaf={renderLeaf}
      />
    </Slate>
  );
}
Example #2
Source File: atoms.tsx    From jeffjadulco.com with MIT License 6 votes vote down vote up
TextArea = ({
  labelText,
  name,
  ...props
}: { labelText: string } & TextareaHTMLAttributes<HTMLTextAreaElement>) => {
  return (
    <div className="group">
      <label
        className="text-sm font-medium transition-colors duration-200 text-fore-secondary group-hover:text-accent"
        htmlFor={name}
      >
        {labelText}
      </label>
      <textarea
        className="block w-full p-3 mt-1 border rounded-md outline-none border-back-subtle bg-back-primary focus:border-accent text-fore-primary disabled:opacity-50"
        style={{ minHeight: '80px' }}
        name={name}
        {...props}
      />
    </div>
  )
}
Example #3
Source File: Inputs.tsx    From crosshare with GNU Affero General Public License v3.0 6 votes vote down vote up
LengthLimitedTextarea = ({
  maxLength,
  updateValue,
  ...props
}: LengthLimitedProps &
  DetailedHTMLProps<
    TextareaHTMLAttributes<HTMLTextAreaElement>,
    HTMLTextAreaElement
  >) => {
  return (
    <textarea
      {...props}
      onChange={(e) => updateValue(e.target.value.substring(0, maxLength))}
    />
  );
}
Example #4
Source File: useTextField.ts    From use-platform with MIT License 6 votes vote down vote up
export function useTextField<T extends HTMLInputElement | HTMLTextAreaElement>(
  props: CommonTextFieldProps,
  inputRef: RefObject<T>,
): T extends HTMLTextAreaElement
  ? UseTextFieldResult<TextareaHTMLAttributes<T>>
  : UseTextFieldResult<InputHTMLAttributes<T>> {
  const { as: elementType = 'input', type = 'text', autoComplete = 'off', ...restProps } = props
  const { focusableProps } = useFocusable(props, inputRef)

  let additionalProps: InputHTMLAttributes<HTMLInputElement> = {}

  if (elementType === 'input') {
    additionalProps = { type }
  }

  useLayoutEffect(() => {
    // By default autofocus set cursor at start position when element type is textarea.
    if (elementType === 'textarea') {
      setCursorToEnd(inputRef.current)
    }
  }, [elementType, inputRef, props.autoFocus])

  return {
    inputProps: {
      autoComplete,
      ...restProps,
      ...focusableProps,
      ...additionalProps,
    },
  } as any
}
Example #5
Source File: FeInput.tsx    From frontegg-react with MIT License 4 votes vote down vote up
FeInput = forwardRef<HTMLInputElement, InputProps>((props, forwardRef) => {
  const {
    size,
    label,
    error,
    inForm,
    variant,
    className,
    multiline,
    fullWidth,
    prefixIcon,
    suffixIcon,
    labelButton,
    onSearch: propsOnSearch,
    type: propsType = 'text',
    ...restProps
  } = props;
  const { iconAction, ...propsWithoutJunk } = restProps;

  const [showPassword, setShowPassword] = useState(false);
  const togglePassword = useCallback(() => setShowPassword((_) => !_), []);

  const [text, setText] = useState(props.value);
  const changeText = useCallback((e: ChangeEvent<HTMLInputElement>) => setText(e.target.value), []);

  const onSearch = useCallback(() => propsOnSearch?.(text as string), [text]);

  const withPrefixIcon = !!prefixIcon;
  const withSuffixIcon = propsType === 'password' || propsType === 'search' || !!suffixIcon;

  const classes = ClassNameGenerator.generate(
    {
      prefixCls,
      className,
      isFullWidth: fullWidth,
    },
    inForm && 'in-form',
    withPrefixIcon && `with-prefix-icon`,
    withSuffixIcon && `with-suffix-icon`
  );

  const innerClasses = ClassNameGenerator.generate(
    {
      prefixCls: `${prefixCls}__inner`,
      className,
      size,
      theme: props.disabled ? 'disabled' : variant,
    },
    multiline && 'multi',
    error && 'error'
  );

  const clickableIconClasses = ClassNameGenerator.generate({
    prefixCls: 'fe-icon',
    isClickable: true,
  });

  const element = multiline ? 'textarea' : 'input';
  const type = propsType === 'password' && showPassword ? 'text' : propsType === 'search' ? 'text' : propsType;

  return (
    <div className={classes}>
      {(label || labelButton) && (
        <div className={`${prefixCls}__header`}>
          {label && <div className={`${prefixCls}__label`}>{label}</div>}

          {labelButton && (
            <FeButton
              tabIndex={-1}
              className={classNames(`${prefixCls}__label-button`, labelButton.className)}
              {...labelButton}
            />
          )}
        </div>
      )}

      <div className={innerClasses}>
        {prefixIcon}

        {React.createElement<InputHTMLAttributes<HTMLInputElement> | TextareaHTMLAttributes<HTMLTextAreaElement>>(
          element,
          {
            ...propsWithoutJunk,
            className: `${prefixCls}__input`,
            value: props.hasOwnProperty('value') ? props.value : text,
            onChange: props.onChange || changeText,
            type,
            ref: forwardRef,
          } as any
        )}

        {propsType === 'password' && (
          <FeIcon
            className={clickableIconClasses}
            name={showPassword ? 'visibility' : 'visibility-off'}
            onClick={togglePassword}
          />
        )}

        {propsType === 'search' && <FeIcon className={clickableIconClasses} name='search' onClick={onSearch} />}

        {suffixIcon}
      </div>

      {error && <div className={`${prefixCls}__error`}>{error}</div>}
    </div>
  );
})