hensei-web/components/common/Textarea/index.tsx
Justin Edmund bb81a54055 Added new Textarea component
This is a content editable div to prepare for when we add tagging and formatting
2023-06-30 22:17:34 -07:00

40 lines
886 B
TypeScript

import React, { useState } from 'react'
import classNames from 'classnames'
import styles from './index.module.scss'
interface Props extends React.ComponentProps<'div'> {
bound?: boolean
placeholder?: string
value?: string
}
const Textarea = React.forwardRef<HTMLDivElement, Props>(function textarea(
{ bound, value: initialValue, ...props }: Props,
forwardedRef
) {
// State
const [value, setValue] = useState(initialValue || '')
// Classes
const classes = classNames(
{
[styles.textarea]: true,
[styles.bound]: bound,
},
props.className?.split(' ').map((className) => styles[className])
)
// Methods: Rendering
return (
<div
{...props}
contentEditable={true}
suppressContentEditableWarning={true}
className={classes}
ref={forwardedRef}
>
{value}
</div>
)
})
export default Textarea