feat: change project title input to auto-grow on content change

This commit is contained in:
Jordan Knott 2021-01-05 18:53:48 -06:00
parent ff15e7fb53
commit c2a0f5e5d0
2 changed files with 30 additions and 14 deletions

View File

@ -1,11 +1,9 @@
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import TextareaAutosize from 'react-autosize-textarea';
import { mixin } from 'shared/utils/styles'; import { mixin } from 'shared/utils/styles';
import Button from 'shared/components/Button'; import Button from 'shared/components/Button';
import { Taskcafe } from 'shared/icons'; import { Taskcafe } from 'shared/icons';
import { NavLink, Link } from 'react-router-dom'; import { NavLink, Link } from 'react-router-dom';
import TaskAssignee from 'shared/components/TaskAssignee'; import TaskAssignee from 'shared/components/TaskAssignee';
import { useRef } from 'react';
export const ProjectMember = styled(TaskAssignee)<{ zIndex: number }>` export const ProjectMember = styled(TaskAssignee)<{ zIndex: number }>`
z-index: ${props => props.zIndex}; z-index: ${props => props.zIndex};
@ -163,7 +161,20 @@ export const ProjectName = styled.h1`
padding: 3px 10px 3px 8px; padding: 3px 10px 3px 8px;
margin: -4px 0; margin: -4px 0;
`; `;
export const ProjectNameTextarea = styled(TextareaAutosize)`
export const ProjectNameWrapper = styled.div`
position: relative;
`;
export const ProjectNameSpan = styled.div`
padding: 3px 10px 3px 8px;
font-weight: 600;
font-size: 20px;
`;
export const ProjectNameTextarea = styled.input`
position: absolute;
width: 100%;
left: 0;
top: 0;
border: none; border: none;
resize: none; resize: none;
overflow: hidden; overflow: hidden;
@ -171,7 +182,7 @@ export const ProjectNameTextarea = styled(TextareaAutosize)`
background: transparent; background: transparent;
border-radius: 3px; border-radius: 3px;
box-shadow: none; box-shadow: none;
margin: -4px 0; margin: 0;
letter-spacing: normal; letter-spacing: normal;
word-spacing: normal; word-spacing: normal;

View File

@ -13,6 +13,8 @@ import {
LogoContainer, LogoContainer,
NavSeparator, NavSeparator,
IconContainerWrapper, IconContainerWrapper,
ProjectNameWrapper,
ProjectNameSpan,
ProjectNameTextarea, ProjectNameTextarea,
InviteButton, InviteButton,
GlobalActions, GlobalActions,
@ -73,7 +75,7 @@ const ProjectHeading: React.FC<ProjectHeadingProps> = ({
}) => { }) => {
const [isEditProjectName, setEditProjectName] = useState(false); const [isEditProjectName, setEditProjectName] = useState(false);
const [projectName, setProjectName] = useState(initialProjectName); const [projectName, setProjectName] = useState(initialProjectName);
const $projectName = useRef<HTMLTextAreaElement>(null); const $projectName = useRef<HTMLInputElement>(null);
useEffect(() => { useEffect(() => {
if (isEditProjectName && $projectName && $projectName.current) { if (isEditProjectName && $projectName && $projectName.current) {
$projectName.current.focus(); $projectName.current.focus();
@ -84,7 +86,7 @@ const ProjectHeading: React.FC<ProjectHeadingProps> = ({
setProjectName(initialProjectName); setProjectName(initialProjectName);
}, [initialProjectName]); }, [initialProjectName]);
const onProjectNameChange = (event: React.FormEvent<HTMLTextAreaElement>): void => { const onProjectNameChange = (event: React.FormEvent<HTMLInputElement>): void => {
setProjectName(event.currentTarget.value); setProjectName(event.currentTarget.value);
}; };
const onProjectNameBlur = () => { const onProjectNameBlur = () => {
@ -106,6 +108,8 @@ const ProjectHeading: React.FC<ProjectHeadingProps> = ({
return ( return (
<> <>
{isEditProjectName ? ( {isEditProjectName ? (
<ProjectNameWrapper>
<ProjectNameSpan>{projectName}</ProjectNameSpan>
<ProjectNameTextarea <ProjectNameTextarea
ref={$projectName} ref={$projectName}
onChange={onProjectNameChange} onChange={onProjectNameChange}
@ -114,6 +118,7 @@ const ProjectHeading: React.FC<ProjectHeadingProps> = ({
spellCheck={false} spellCheck={false}
value={projectName} value={projectName}
/> />
</ProjectNameWrapper>
) : ( ) : (
<ProjectName <ProjectName
onClick={() => { onClick={() => {