Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Default textarea size #71

Open
1 of 5 tasks
igeligel opened this issue Oct 13, 2020 · 2 comments
Open
1 of 5 tasks

Refactoring Default textarea size #71

igeligel opened this issue Oct 13, 2020 · 2 comments
Labels
good first issue Good for newcomers hacktoberfest Hacktoberfest is a yearly developer festival where the participation in Open Source is appreciated help wanted Extra attention is needed refactoring

Comments

@igeligel
Copy link
Owner

Type of Change

  • Name variables and functions well
  • Remove magic numbers
  • Extract each step of logic into a function
  • Extract React component
  • Remove duplicate code

Description

Currently, the left textarea has rows set to 2. This is done so it looks nice on desktop but because we are moving to mobile this behavior should change a bit. See how the size of the red arrows is different in the picture below.

chrome_2020-10-13_23-07-05

The problem with the screenshot above is that the lower box would be 1 row high when the upper one would be 2 rows high. For desktop, the minimum row should be 2 though. Otherwise, that looks weird.

After a bit of investigating I could not find a CSS-Native solution with the rows attribute of <textarea>, so we are forced to use min-height and media queries.

Code Before

const Textarea = styled(TextareaAutosize)<ExampleTextProps>`
  box-sizing: border-box;
  border: 0;
  resize: none;
  flex-grow: 1;
  color: ${(props) => (props.theme.main === "dark" ? "#fff" : "#14213d")};
  background-color: transparent;
  font-family: ${(props) =>
    props.theme && props.theme.font ? props.theme.font : "Roboto"};
  font-size: ${(props) => (props.smallerFont ? "1.2em" : "1.61em")};
  ${(props) => (props.showCopyCursor ? "cursor: text;" : "")};
  width: 100%;

  ::placeholder {
    color: ${(props) =>
      props.theme.main === "dark"
        ? "hsl(221, 51%, 64%)"
        : "rgba(20, 33, 61, 0.4)"};
  }

  :focus {
    outline: none;
  }
`;

// ...

export const InOutTextarea: FC<Props> = (props) => {
  return (
    <>
      {/* ... */}
      <TextAreaContent>
        <TextAreaWrapper>
          <Textarea
            data-test="from-textarea"
            placeholder="..."
            rows={2}
            smallerFont={false}
            value={inValue}
            maxLength={maxContentLength}
            onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {
              if (
                event.target.value === null ||
                event.target.value === undefined
              )
                return;
              onInInput(event.target.value);
            }}
          />
        </TextAreaWrapper>
        {/* ... */}
      </TextAreaContent>
      <TextAreaContent>
        <TextAreaWrapper>
          <Textarea
            disabled
            smallerFont={false}
            showCopyCursor={true}
            value={outValue}
          />
        </TextAreaWrapper>
        {/* ... */}
      </TextAreaContent>
    </>
  );
};

Code Expected after Refactoring

const Textarea = styled(TextareaAutosize)<ExampleTextProps>`
  box-sizing: border-box;
  border: 0;
  resize: none;
  flex-grow: 1;
  color: ${(props) => (props.theme.main === "dark" ? "#fff" : "#14213d")};
  background-color: transparent;
  font-family: ${(props) =>
    props.theme && props.theme.font ? props.theme.font : "Roboto"};
  font-size: ${(props) => (props.smallerFont ? "1.2em" : "1.61em")};
  ${(props) => (props.showCopyCursor ? "cursor: text;" : "")};
  width: 100%;
  min-height: 64px;

  @media (max-width: 720px) {
    min-height: auto;
  }

  ::placeholder {
    color: ${(props) =>
      props.theme.main === "dark"
        ? "hsl(221, 51%, 64%)"
        : "rgba(20, 33, 61, 0.4)"};
  }

  :focus {
    outline: none;
  }
`;

// ...

export const InOutTextarea: FC<Props> = (props) => {
  return (
    <>
      {/* ... */}
      <TextAreaContent>
        <TextAreaWrapper>
          <Textarea
            data-test="from-textarea"
            placeholder="..."
            smallerFont={false}
            value={inValue}
            maxLength={maxContentLength}
            onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {
              if (
                event.target.value === null ||
                event.target.value === undefined
              )
                return;
              onInInput(event.target.value);
            }}
          />
        </TextAreaWrapper>
        {/* ... */}
      </TextAreaContent>
      <TextAreaContent>
        <TextAreaWrapper>
          <Textarea
            disabled
            smallerFont={false}
            showCopyCursor={true}
            value={outValue}
          />
        </TextAreaWrapper>
        {/* ... */}
      </TextAreaContent>
    </>
  );
};

Files involved

@igeligel igeligel added help wanted Extra attention is needed good first issue Good for newcomers refactoring hacktoberfest Hacktoberfest is a yearly developer festival where the participation in Open Source is appreciated hacktoberfest-accepted and removed hacktoberfest-accepted labels Oct 13, 2020
@WulfPlasma
Copy link

WulfPlasma commented Oct 14, 2020

@igeligel Can I work on this?

@igeligel
Copy link
Owner Author

@WulfPlasma thanks for reaching out. Yeah, you can work on it. I will assign the ticket to you now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest Hacktoberfest is a yearly developer festival where the participation in Open Source is appreciated help wanted Extra attention is needed refactoring
Projects
None yet
Development

No branches or pull requests

2 participants