Added new Textarea component
This is a content editable div to prepare for when we add tagging and formatting
This commit is contained in:
parent
46a2a5c8f5
commit
bb81a54055
2 changed files with 82 additions and 0 deletions
42
components/common/Textarea/index.module.scss
Normal file
42
components/common/Textarea/index.module.scss
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
.textarea {
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
background-color: var(--input-bg);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-radius: $input-corner;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: var(--text-primary);
|
||||||
|
display: block;
|
||||||
|
font-family: system-ui, -apple-system, 'Helvetica Neue', Helvetica, Arial,
|
||||||
|
sans-serif;
|
||||||
|
font-size: $font-regular;
|
||||||
|
line-height: 1.4;
|
||||||
|
overflow: scroll;
|
||||||
|
min-height: $unit-10x;
|
||||||
|
padding: $unit * 1.5 $unit-2x;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
border: 2px solid $blue;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.bound {
|
||||||
|
background-color: var(--input-bound-bg);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--input-bound-bg-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.editParty {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[contenteditable='true']:empty:before {
|
||||||
|
content: attr(placeholder);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
pointer-events: none;
|
||||||
|
display: block; /* For Firefox */
|
||||||
|
}
|
||||||
|
}
|
||||||
40
components/common/Textarea/index.tsx
Normal file
40
components/common/Textarea/index.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
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
|
||||||
Loading…
Reference in a new issue