-
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
🪟 🐛 Split Heading and Text components #17992
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef28268
split Text and Heading components
josephkmh fee8180
replace Text with Heading where appropriate
josephkmh 734e1a1
Merge branch 'master' into joey/split-heading-text-components
josephkmh 9d95a50
fix merge conflict
josephkmh c8c8cb8
Merge branch 'master' into joey/split-heading-text-components
josephkmh a4ffdef
update heading usage
josephkmh 696176f
update heading usage
josephkmh bb5aa80
fix Text usage
josephkmh 64fc5f5
Update Titles.tsx
josephkmh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
17 changes: 17 additions & 0 deletions
17
airbyte-webapp/src/components/ui/Heading/Heading.stories.tsx
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,17 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
|
||
import { Heading } from "./Heading"; | ||
|
||
export default { | ||
title: "Ui/Heading", | ||
component: Heading, | ||
} as ComponentMeta<typeof Heading>; | ||
|
||
const Template: ComponentStory<typeof Heading> = (args) => <Heading {...args} />; | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = { | ||
size: "md", | ||
children: | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
}; |
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,37 @@ | ||
import classNames from "classnames"; | ||
import React from "react"; | ||
|
||
import styles from "./heading.module.scss"; | ||
|
||
type HeadingSize = "sm" | "md" | "lg" | "xl"; | ||
type HeadingElementType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; | ||
|
||
interface HeadingProps { | ||
className?: string; | ||
centered?: boolean; | ||
as: HeadingElementType; | ||
size?: HeadingSize; | ||
} | ||
|
||
const getHeadingClassNames = ({ size, centered }: Required<Pick<HeadingProps, "size" | "centered">>) => { | ||
const sizes: Record<HeadingSize, string> = { | ||
sm: styles.sm, | ||
md: styles.md, | ||
lg: styles.lg, | ||
xl: styles.xl, | ||
}; | ||
|
||
return classNames(styles.heading, sizes[size], centered && styles.centered); | ||
}; | ||
|
||
export const Heading: React.FC<React.PropsWithChildren<HeadingProps>> = React.memo( | ||
({ as, centered = false, children, className: classNameProp, size = "md", ...remainingProps }) => { | ||
const className = classNames(getHeadingClassNames({ centered, size }), classNameProp); | ||
|
||
return React.createElement(as, { | ||
...remainingProps, | ||
className, | ||
children, | ||
}); | ||
} | ||
); |
File renamed without changes.
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 @@ | ||
export { Heading } from "./Heading"; |
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
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 |
---|---|---|
@@ -1,69 +1,45 @@ | ||
import classNames from "classnames"; | ||
import React from "react"; | ||
|
||
import headingStyles from "./heading.module.scss"; | ||
import textStyles from "./text.module.scss"; | ||
import styles from "./text.module.scss"; | ||
|
||
type TextSize = "sm" | "md" | "lg"; | ||
type HeadingSize = TextSize | "xl"; | ||
type TextElementType = "p" | "span" | "div"; | ||
type HeadingElementType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; | ||
|
||
interface BaseProps { | ||
interface TextProps { | ||
className?: string; | ||
centered?: boolean; | ||
} | ||
|
||
interface TextProps extends BaseProps { | ||
as?: TextElementType; | ||
size?: TextSize; | ||
bold?: boolean; | ||
} | ||
|
||
interface HeadingProps extends BaseProps { | ||
as: HeadingElementType; | ||
size?: HeadingSize; | ||
} | ||
|
||
const getTextClassNames = ({ size, centered, bold }: Required<Pick<TextProps, "size" | "centered" | "bold">>) => { | ||
const sizes: Record<TextSize, string> = { | ||
sm: textStyles.sm, | ||
md: textStyles.md, | ||
lg: textStyles.lg, | ||
}; | ||
|
||
return classNames(textStyles.text, sizes[size], centered && textStyles.centered, bold && textStyles.bold); | ||
}; | ||
|
||
const getHeadingClassNames = ({ size, centered }: Required<Pick<HeadingProps, "size" | "centered">>) => { | ||
const sizes: Record<HeadingSize, string> = { | ||
sm: headingStyles.sm, | ||
md: headingStyles.md, | ||
lg: headingStyles.lg, | ||
xl: headingStyles.xl, | ||
sm: styles.sm, | ||
md: styles.md, | ||
lg: styles.lg, | ||
}; | ||
|
||
return classNames(headingStyles.heading, sizes[size], centered && headingStyles.centered); | ||
}; | ||
|
||
const isHeadingType = (props: TextProps | HeadingProps): props is HeadingProps => { | ||
return props.as ? /^h[0-6]$/.test(props.as) : false; | ||
return classNames(styles.text, sizes[size], centered && styles.centered, bold && styles.bold); | ||
}; | ||
|
||
export const Text: React.FC<React.PropsWithChildren<TextProps | HeadingProps>> = React.memo((props) => { | ||
const isHeading = isHeadingType(props); | ||
const { as = "p", centered = false, children, className: classNameProp, ...remainingProps } = props; | ||
|
||
const className = classNames( | ||
isHeading | ||
? getHeadingClassNames({ centered, size: props.size ?? "md" }) | ||
: getTextClassNames({ centered, size: props.size ?? "md", bold: props.bold ?? false }), | ||
classNameProp | ||
); | ||
|
||
return React.createElement(as, { | ||
...remainingProps, | ||
className, | ||
export const Text: React.FC<React.PropsWithChildren<TextProps>> = React.memo( | ||
({ | ||
as = "p", | ||
bold = false, | ||
centered = false, | ||
children, | ||
}); | ||
}); | ||
className: classNameProp, | ||
size = "md", | ||
...remainingProps | ||
}) => { | ||
const className = classNames(getTextClassNames({ centered, size, bold }), classNameProp); | ||
|
||
return React.createElement(as, { | ||
...remainingProps, | ||
className, | ||
children, | ||
}); | ||
} | ||
); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@use "../../../scss/colors"; | ||
@use "scss/colors"; | ||
|
||
.text { | ||
color: colors.$dark-blue; | ||
|
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ import React from "react"; | |||||
import { FormattedMessage } from "react-intl"; | ||||||
|
||||||
import HeadTitle from "components/HeadTitle"; | ||||||
import { Text } from "components/ui/Text"; | ||||||
import { Heading } from "components/ui/Heading"; | ||||||
|
||||||
import { PageTrackingCodes, useTrackPage } from "hooks/services/Analytics"; | ||||||
|
||||||
|
@@ -20,7 +20,7 @@ const SignupPage: React.FC<SignupPageProps> = ({ highlightStyle }) => { | |||||
return ( | ||||||
<div> | ||||||
<HeadTitle titles={[{ id: "login.signup" }]} /> | ||||||
<Text as="h1" size="xl" className={styles.title}> | ||||||
<Heading as="h1" size="xl" className={styles.title}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<FormattedMessage | ||||||
id="login.activateAccess" | ||||||
values={{ | ||||||
|
@@ -31,7 +31,7 @@ const SignupPage: React.FC<SignupPageProps> = ({ highlightStyle }) => { | |||||
), | ||||||
}} | ||||||
/> | ||||||
</Text> | ||||||
</Heading> | ||||||
<SpecialBlock /> | ||||||
<SignupForm /> | ||||||
<OAuthLogin isSignUpPage /> | ||||||
|
6 changes: 3 additions & 3 deletions
6
airbyte-webapp/src/packages/cloud/views/auth/components/FormTitle/FormTitle.tsx
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 | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,11 @@ | ||||||
import React from "react"; | ||||||
|
||||||
import { Text } from "components/ui/Text"; | ||||||
import { Heading } from "components/ui/Heading"; | ||||||
|
||||||
import styles from "./FormTitle.module.scss"; | ||||||
|
||||||
export const FormTitle: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => ( | ||||||
<Text as="h1" size="xl" className={styles.title}> | ||||||
<Heading as="h1" size="xl" className={styles.title}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{children} | ||||||
</Text> | ||||||
</Heading> | ||||||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Super nit: don't need it anymore 😊