Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added Textarea component

Blue Mouse1dc8430a7cf9
diff --git a/app/ui/Textarea.tsx b/app/ui/Textarea.tsx
new file mode 100644
index 000000000..47ea48b4d
--- /dev/null
+++ b/app/ui/Textarea.tsx
@@ -0,0 +1,102 @@
+import React, { memo } from 'react'
+import cx from 'clsx'
+import _isEmpty from 'lodash/isEmpty'
+import PropTypes from 'prop-types'
+import { ExclamationCircleIcon } from '@heroicons/react/24/solid'
+import Beta from 'ui/Beta'
+
+interface ITextarea {
+ value: string | number,
+ label?: string,
+ hint?: string,
+ placeholder?: string,
+ onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void,
+ id?: string,
+ type?: string,
+ className?: string,
+ error?: string | boolean,
+ name?: string,
+ disabled?: boolean,
+ isBeta?: boolean,
+}
+
+const Textarea = ({
+ label, hint, placeholder, type, id, name, className, onChange, error, value, disabled, isBeta,
+}: ITextarea) => {
+ const identifier = `textarea-${id || name || type}`
+ const isError = !_isEmpty(error)
+
+ return (
+ <div className={className}>
+ {label && (
+ <label htmlFor={identifier} className='flex text-sm font-medium text-gray-700 dark:text-gray-200'>
+ {label}
+ {isBeta && (
+ <div className='ml-5'>
+ <Beta />
+ </div>
+ )}
+ </label>
+ )}
+ <div className='mt-1 relative'>
+ <textarea
+ rows={4}
+ name={identifier}
+ id={identifier}
+ className={cx('shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:text-gray-50 dark:placeholder-gray-400 dark:border-slate-800/25 dark:bg-slate-800 rounded-md', {
+ 'border-red-300 text-red-900 placeholder-red-300': isError,
+ 'cursor-text': disabled,
+ })}
+ value={value}
+ onChange={onChange}
+ placeholder={placeholder}
+ disabled={disabled}
+ />
+ {isError && (
+ <div className='absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none'>
+ <ExclamationCircleIcon className='h-5 w-5 text-red-500' aria-hidden />
+ </div>
+ )}
+ </div>
+ <p className='mt-2 text-sm text-gray-500 dark:text-gray-300 whitespace-pre-line' id={`${identifier}-optional`}>{hint}</p>
+ {isError && (
+ <p className='mt-2 text-sm text-red-600 dark:text-red-500' id='email-error'>{error}</p>
+ )}
+ </div>
+ )
+}
+
+Textarea.propTypes = {
+ value: PropTypes.oneOfType([
+ PropTypes.string, PropTypes.number,
+ ]).isRequired,
+ label: PropTypes.string,
+ hint: PropTypes.string,
+ placeholder: PropTypes.string,
+ onChange: PropTypes.func,
+ id: PropTypes.string,
+ type: PropTypes.string,
+ className: PropTypes.string,
+ error: PropTypes.oneOfType([
+ PropTypes.string, PropTypes.bool,
+ ]),
+ name: PropTypes.string,
+ disabled: PropTypes.bool,
+ isBeta: PropTypes.bool,
+}
+
+Textarea.defaultProps = {
+ label: '',
+ hint: '',
+ placeholder: '',
+ onChange: () => { },
+ id: '',
+ type: '',
+ className: '',
+ error: null,
+ name: '',
+ disabled: false,
+ isBeta: false,
+}
+
+export default memo(Textarea)