This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TextArea): added textarea component
- Loading branch information
Cecilia Woodward
committed
Aug 28, 2021
1 parent
255e484
commit 7cc8a47
Showing
3 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@use './variables' as *; | ||
@use './mixins' as *; | ||
|
||
.textArea { | ||
@include hover(); | ||
|
||
position: relative; | ||
min-width: 150px; | ||
overflow: hidden; | ||
|
||
border-radius: $border-radius; | ||
height: 70px; | ||
background-color: $secondary-accent; | ||
color: $primary-accent; | ||
|
||
textarea { | ||
border: none; | ||
outline: none; | ||
box-sizing: border-box; | ||
margin: 0; | ||
background: transparent; | ||
height: $min-component-size; | ||
width: 100%; | ||
height: 100%; | ||
color: inherit; | ||
font-size: $font-size; | ||
resize: none; | ||
|
||
padding: $padding $border-radius; | ||
line-height: 1; | ||
|
||
&::placeholder { | ||
color: $disabled; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import classNames from 'classnames'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Keys, UpdateOn } from './constants'; | ||
import { noop } from './utils/noop'; | ||
import styles from './TextArea.scss'; | ||
|
||
export interface TextAreaProps { | ||
className?: string, | ||
value?: string; | ||
placeholder?: string; | ||
rows?: number; | ||
|
||
/** | ||
* Invoked when the checkbox checked value is modified internally. | ||
*/ | ||
onChange?: (value: string) => void; | ||
submitKeys?: Keys[]; | ||
|
||
updateOn?: UpdateOn; | ||
} | ||
|
||
export function TextArea({ | ||
className, | ||
value, | ||
placeholder, | ||
onChange = noop, | ||
updateOn = UpdateOn.Blur, | ||
}: TextAreaProps): JSX.Element { | ||
const [internalValue, setInternalValue] = useState<string>(); | ||
|
||
useEffect(() => { | ||
setInternalValue(value); | ||
}, [value]); | ||
|
||
return ( | ||
<div | ||
className={classNames( | ||
styles.textArea, | ||
className, | ||
)} | ||
> | ||
<textarea | ||
placeholder={placeholder} | ||
value={internalValue || ''} | ||
onBlur={updateOn === UpdateOn.Blur ? () => onChange(internalValue) : null} | ||
onChange={(event) => { | ||
const updatedValue = event.target.value; | ||
setInternalValue(updatedValue); | ||
|
||
if (updateOn === UpdateOn.Input) { | ||
onChange(updatedValue); | ||
} | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |