-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
🪟 🎨 Add Text component #15570
Conversation
}; | ||
|
||
export const Text: React.FC<TextProps> = ({ | ||
as = "span", |
There was a problem hiding this comment.
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 />
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like as
here
There was a problem hiding this comment.
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.
5c38263
to
30acdc6
Compare
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. |
56fae12
to
a8482a8
Compare
There was a problem hiding this 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
Co-authored-by: Krishna Glick <krishna@airbyte.io>
a8482a8
to
74f66dd
Compare
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. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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">>) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
… `as` is required to infer heading
* 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>
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, divcentered
- if the text needs to be centeredbold
- does not apply to headingsclassName
Usage:
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
Text.tsx
Tests