-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename editors to the correct namespace
- Loading branch information
Showing
8 changed files
with
172 additions
and
177 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,90 @@ | ||
import React, { CSSProperties, useState } from 'react' | ||
import { Popover, TextField, TextareaAutosize } from '@material-ui/core' | ||
import { NavigationKey } from '../enums/navigation-key.enum' | ||
import { isCaretAtEndPosition } from '../utils/utils' | ||
|
||
interface Props { | ||
value: string | ||
onCommit: (value: string, navigationKey?: NavigationKey) => void | ||
onCommitCancel: (navigationKey?: NavigationKey) => void | ||
anchorRef: Element | ||
cellStyle: CSSProperties | ||
maxHeight: number | ||
maxLength: number | ||
editor: any | ||
} | ||
|
||
/** | ||
* @todo Needs to be created | ||
* @param value | ||
* @param maxHeight | ||
* @param cellStyle | ||
* @param onCommit | ||
* @param onCommitCancel | ||
* @param anchorRef | ||
* @param maxLength | ||
* @param editor | ||
* @constructor | ||
*/ | ||
export function BaseEditor({ | ||
value, | ||
maxHeight, | ||
cellStyle, | ||
onCommit, | ||
onCommitCancel, | ||
anchorRef, | ||
maxLength, | ||
editor, | ||
}: Props) { | ||
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.key === 'Enter' || NavigationKey[e.key]) { | ||
const cursorStart = e.target['selectionStart'] | ||
const cursorEnd = e.target['selectionEnd'] | ||
console.log({ | ||
cursorStart, | ||
cursorEnd, | ||
}) | ||
if ( | ||
e.key === NavigationKey.ArrowRight && | ||
!isCaretAtEndPosition( | ||
0, | ||
e.target['value'].length, | ||
) | ||
) { | ||
return console.log('Not in the end so') | ||
} | ||
e.preventDefault() | ||
const newValue = e.target['value'] | ||
if (newValue !== value) { | ||
return onCommit( | ||
newValue, | ||
NavigationKey[e.key], | ||
) | ||
} | ||
return onCommitCancel(NavigationKey[e.key]) | ||
} | ||
} | ||
|
||
return ( | ||
<Popover | ||
anchorEl={anchorRef} | ||
open | ||
//Review because this is enforced just to prevent tsc error | ||
onClose={() => onCommitCancel(NavigationKey.ArrowUp)} | ||
anchorOrigin={{ | ||
vertical: 'center', | ||
horizontal: 'center', | ||
}} | ||
transformOrigin={{ | ||
vertical: 'center', | ||
horizontal: 'center', | ||
}} | ||
> | ||
<div style={{ width: cellStyle.width, height: maxHeight }}> | ||
{editor(value, onKeyDown, maxLength)} | ||
</div> | ||
</Popover> | ||
) | ||
} | ||
|
||
export default BaseEditor |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.