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

🪟 🎨 Add Text component #15570

Merged
merged 12 commits into from
Aug 18, 2022
Merged

🪟 🎨 Add Text component #15570

merged 12 commits into from
Aug 18, 2022

Conversation

edmundito
Copy link
Contributor

@edmundito edmundito commented Aug 11, 2022

What

Closes #14848

Add <Text /> component to render text that matches the design system. Updates the auth pages as an example of how to use it.

Properties include:

  • as - h1, h2... or p, span, div
  • centered - if the text needs to be centered
  • bold - does not apply to headings
  • className

Usage:

<Text as="h1" size="lg">This is a large heading</Text>
<Text>This is regular text</Text>
<Text as="p">This is a paragarph</Text>
<Text size="lg" bold>This is large bold text</Text>

How

Component implementation is split to accept properties for a heading vs. regular text so that the use is simplified to one component. The styles are split into two modules because this allows applying style more easily override in components that apply class names to this and keeps the implementation cleaner.

Recommended reading order

  1. Text.tsx
  2. Rest of code

Tests

  • Added storybook
  • Verified with auth pages
  • Verified that styles can be overridden without specificity

@edmundito edmundito changed the title Add Text component 🪟 🎨 Add Text component Aug 11, 2022
@github-actions github-actions bot added area/platform issues related to the platform area/frontend Related to the Airbyte webapp labels Aug 11, 2022
};

export const Text: React.FC<TextProps> = ({
as = "span",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any data on what our default text container is? Should it be <p />?

Copy link
Contributor Author

@edmundito edmundito Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question I wanted to ask! I'm not sure what the default element style should be. I considered paragraph as one of them; maybe that's the one that makes the most sense.

type TextElementType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "div";

interface TextProps {
as?: TextElementType;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was inspired by styled components to call this as but is the name clear? Alternatively, I thought of element or type as well. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as feels fairly standard, though some other opinions would definitely be useful :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like as here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ for as as well, as it feels pretty standard as of today.

@edmundito edmundito force-pushed the edmundito/text-component branch 2 times, most recently from 5c38263 to 30acdc6 Compare August 15, 2022 20:56
@edmundito
Copy link
Contributor Author

Paired with @krishnaglick to resolve some issues regarding styling, updated the component to distinguish props between heading and text, and used the sign in pages as samples for using the text components.

@edmundito edmundito force-pushed the edmundito/text-component branch from 56fae12 to a8482a8 Compare August 16, 2022 13:30
@edmundito edmundito marked this pull request as ready for review August 16, 2022 14:14
@edmundito edmundito requested a review from a team as a code owner August 16, 2022 14:14
@edmundito edmundito requested a review from krishnaglick August 16, 2022 14:22
Copy link
Contributor

@krishnaglick krishnaglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I paired w/ Edmundo for some of this so we should get another pair of 👀
But LGTM

@edmundito edmundito requested a review from a team August 16, 2022 19:22
@edmundito edmundito force-pushed the edmundito/text-component branch from a8482a8 to 74f66dd Compare August 17, 2022 14:07
@edmundito
Copy link
Contributor Author

Updated the heading line-heights after reviewing with Nico, which should be the last change. I would like to get another review from someone else in @airbytehq/frontend before I call this done.

Copy link
Contributor

@lmossman lmossman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a couple of small questions, but otherwise I think this looks great!

type TextElementType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "div";

interface TextProps {
as?: TextElementType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like as here


export const Text: React.FC<TextProps | HeadingProps> = React.memo((props) => {
const isHeading = isHeadingType(props);
const { as = isHeading ? "h1" : "p", centered = false, children } = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as = isHeading ? "h1" : "p"

This was slightly confusing to me, because isHeading will only ever be true if props.as is set, and its value is like hX. So it seems like we don't need to have a condition in the default value of as for when isHeading is true, because if it is true then we know props.as is set, so the default value will not be used.

Therefore, maybe it make sense to just set the default value here to p? Lmk if I'm misunderstanding anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. Probably Edmundo just coding defensively!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Typing is a bit tricky here if we don't check for the heading type, that's why it partially destructuring the props. However, I realized that this is not needed and we can indeed assign 'p' to it.

size?: HeadingSize;
}

const getTextClassNames = ({ size, centered, bold }: Required<Pick<TextProps, "size" | "centered" | "bold">>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required<Pick<TextProps, "size" | "centered" | "bold">>

To confirm my understanding - the purpose of this is basically to remove the as and className fields from TextProps, because we don't actually want those to be class names on the component that we are returning below, correct?

If so, would it potentially be better to do something like Required<Omit<TextProps, "className" | "as">> instead, so that if we add more classname props to those types in the future we don't need to also edit these function signatures? Probably not a huge deal either way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd need to add the new property to the destructure anyway.
No matter what method, there's type safety if size, centered, or bold are changed in TextProps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case that the props were to expand, this would continue to work with Pick over using Omit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point that the new props would need to be added to the destructure, I forgot about that. This looks good to me then!

@edmundito edmundito merged commit 11583d3 into master Aug 18, 2022
@edmundito edmundito deleted the edmundito/text-component branch August 18, 2022 16:15
rodireich pushed a commit that referenced this pull request Aug 25, 2022
* Add Text component

* Fix regexp for heading matching in Text component

Co-authored-by: Krishna Glick <krishna@airbyte.io>

* Reset margin and padding on text elements

* Update default text element to p

* Split scss for heading and text

* Split types between Text and Heading

* Rename text scss

* Rename text scsss module

* Remove font-weight from FormTitle

* Split Text md size out of default style, fix typing issues

* Update line heights on headings and remove override from SignupPage

* Remove default heading type assignment when destructuring props since `as` is required to infer heading

Co-authored-by: Krishna Glick <krishna@airbyte.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend Related to the Airbyte webapp area/platform issues related to the platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup common text styles and heading sizes
4 participants