-
Notifications
You must be signed in to change notification settings - Fork 377
feat(Hero): added component #12131
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
feat(Hero): added component #12131
Changes from 6 commits
4ba98fd
7d570bc
13e7033
213f6be
5ffe512
af884b4
d281ae6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,87 +1,18 @@ | ||
| import styles from '@patternfly/react-styles/css/components/Compass/compass'; | ||
| import { css } from '@patternfly/react-styles'; | ||
|
|
||
| import compassHeroBackgroundImageLight from '@patternfly/react-tokens/dist/esm/c_compass__hero_BackgroundImage_light'; | ||
| import compassHeroBackgroundImageDark from '@patternfly/react-tokens/dist/esm/c_compass__hero_BackgroundImage_dark'; | ||
| import compassHeroGradientStop1Light from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_1_light'; | ||
| import compassHeroGradientStop2Light from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_2_light'; | ||
| import compassHeroGradientStop3Light from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_3_light'; | ||
| import compassHeroGradientStop1Dark from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_1_dark'; | ||
| import compassHeroGradientStop2Dark from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_2_dark'; | ||
| import compassHeroGradientStop3Dark from '@patternfly/react-tokens/dist/esm/c_compass__hero_gradient_stop_3_dark'; | ||
|
|
||
| /** A wrapper component to pass a PatternFly Hero component into. */ | ||
| interface CompassHeroProps extends Omit<React.HTMLProps<HTMLDivElement>, 'content'> { | ||
| /** Content of the hero */ | ||
| children?: React.ReactNode; | ||
| /** Additional classes added to the hero */ | ||
| className?: string; | ||
| /** Light theme background image path of the hero */ | ||
| backgroundSrcLight?: string; | ||
| /** Dark theme background image path of the hero */ | ||
| backgroundSrcDark?: string; | ||
| /** Light theme gradient of the hero */ | ||
| gradientLight?: { | ||
| stop1?: string; | ||
| stop2?: string; | ||
| stop3?: string; | ||
| }; | ||
| /** Dark theme gradient of the hero */ | ||
| gradientDark?: { | ||
| stop1?: string; | ||
| stop2?: string; | ||
| stop3?: string; | ||
| }; | ||
| } | ||
|
|
||
| export const CompassHero: React.FunctionComponent<CompassHeroProps> = ({ | ||
| className, | ||
| children, | ||
| backgroundSrcLight, | ||
| backgroundSrcDark, | ||
| gradientLight, | ||
| gradientDark, | ||
| ...props | ||
| }) => { | ||
| const backgroundImageStyles: { [key: string]: string } = {}; | ||
| if (backgroundSrcLight) { | ||
| backgroundImageStyles[compassHeroBackgroundImageLight.name] = `url(${backgroundSrcLight})`; | ||
| } | ||
| if (backgroundSrcDark) { | ||
| backgroundImageStyles[compassHeroBackgroundImageDark.name] = `url(${backgroundSrcDark})`; | ||
| } | ||
|
|
||
| if (gradientLight) { | ||
| if (gradientLight.stop1) { | ||
| backgroundImageStyles[compassHeroGradientStop1Light.name] = gradientLight.stop1; | ||
| } | ||
| if (gradientLight.stop2) { | ||
| backgroundImageStyles[compassHeroGradientStop2Light.name] = gradientLight.stop2; | ||
| } | ||
| if (gradientLight.stop3) { | ||
| backgroundImageStyles[compassHeroGradientStop3Light.name] = gradientLight.stop3; | ||
| } | ||
| } | ||
| if (gradientDark) { | ||
| if (gradientDark.stop1) { | ||
| backgroundImageStyles[compassHeroGradientStop1Dark.name] = gradientDark.stop1; | ||
| } | ||
| if (gradientDark.stop2) { | ||
| backgroundImageStyles[compassHeroGradientStop2Dark.name] = gradientDark.stop2; | ||
| } | ||
| if (gradientDark.stop3) { | ||
| backgroundImageStyles[compassHeroGradientStop3Dark.name] = gradientDark.stop3; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={css(styles.compassPanel, styles.compassHero, className)} | ||
| style={{ ...props.style, ...backgroundImageStyles }} | ||
| {...props} | ||
| > | ||
| <div className={css(styles.compassHeroBody)}>{children}</div> | ||
| </div> | ||
| ); | ||
| }; | ||
| export const CompassHero: React.FunctionComponent<CompassHeroProps> = ({ className, children, ...props }) => ( | ||
| <div className={css(`${styles.compass}__hero`, className)} {...props}> | ||
| {children} | ||
| </div> | ||
| ); | ||
|
|
||
| CompassHero.displayName = 'CompassHero'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import styles from '@patternfly/react-styles/css/components/Hero/hero'; | ||
| import { css } from '@patternfly/react-styles'; | ||
| import heroBackgroundImageLight from '@patternfly/react-tokens/dist/esm/c_hero_BackgroundImage_light'; | ||
| import heroBackgroundImageDark from '@patternfly/react-tokens/dist/esm/c_hero_BackgroundImage_dark'; | ||
| import heroGradientStop1Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_1_light'; | ||
| import heroGradientStop2Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_2_light'; | ||
| import heroGradientStop3Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_3_light'; | ||
| import heroGradientStop1Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_1_dark'; | ||
| import heroGradientStop2Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_2_dark'; | ||
| import heroGradientStop3Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_3_dark'; | ||
| import heroBodyWidth from '@patternfly/react-tokens/dist/esm/c_hero__body_Width'; | ||
| import heroBodyMaxWidth from '@patternfly/react-tokens/dist/esm/c_hero__body_MaxWidth'; | ||
|
|
||
| /** The main Hero component that allows adjusting of its background images and gradients in different color modes (such as light and dark). */ | ||
|
|
||
| export interface HeroProps extends Omit<React.HTMLProps<HTMLDivElement>, 'content'> { | ||
| /** Content of the hero */ | ||
| children?: React.ReactNode; | ||
| /** Additional classes added to the hero */ | ||
| className?: string; | ||
| /** Light theme background image path of the hero */ | ||
| backgroundSrcLight?: string; | ||
| /** Dark theme background image path of the hero */ | ||
| backgroundSrcDark?: string; | ||
| /** Light theme gradient of the hero, taking any valid CSS color values for each stop property. */ | ||
| gradientLight?: { | ||
| stop1?: string; | ||
| stop2?: string; | ||
| stop3?: string; | ||
| }; | ||
| /** Dark theme gradient of the hero, taking any valid CSS color values for each stop property. */ | ||
| gradientDark?: { | ||
| stop1?: string; | ||
| stop2?: string; | ||
| stop3?: string; | ||
| }; | ||
| /** Flag indicating whether glass styles are removed from the hero when a glass theme is applied. */ | ||
| hasNoGlass?: boolean; | ||
| /** Modifies the width of the hero body. */ | ||
| bodyWidth?: string; | ||
| /** Modifies the max-width of the hero body. */ | ||
| bodyMaxWidth?: string; | ||
| } | ||
|
|
||
| export const Hero: React.FunctionComponent<HeroProps> = ({ | ||
| className, | ||
| children, | ||
| backgroundSrcLight, | ||
| backgroundSrcDark, | ||
| gradientLight, | ||
| gradientDark, | ||
| hasNoGlass = false, | ||
| bodyWidth, | ||
| bodyMaxWidth, | ||
| ...props | ||
| }) => { | ||
| const customStyles: { [key: string]: string } = {}; | ||
| if (backgroundSrcLight) { | ||
| customStyles[heroBackgroundImageLight.name] = `url(${backgroundSrcLight})`; | ||
| } | ||
| if (backgroundSrcDark) { | ||
| customStyles[heroBackgroundImageDark.name] = `url(${backgroundSrcDark})`; | ||
| } | ||
|
|
||
| if (gradientLight?.stop1) { | ||
| customStyles[heroGradientStop1Light.name] = gradientLight.stop1; | ||
| } | ||
| if (gradientLight?.stop2) { | ||
| customStyles[heroGradientStop2Light.name] = gradientLight.stop2; | ||
| } | ||
| if (gradientLight?.stop3) { | ||
| customStyles[heroGradientStop3Light.name] = gradientLight.stop3; | ||
| } | ||
| if (gradientDark?.stop1) { | ||
| customStyles[heroGradientStop1Dark.name] = gradientDark.stop1; | ||
| } | ||
| if (gradientDark?.stop2) { | ||
| customStyles[heroGradientStop2Dark.name] = gradientDark.stop2; | ||
| } | ||
| if (gradientDark?.stop3) { | ||
| customStyles[heroGradientStop3Dark.name] = gradientDark.stop3; | ||
| } | ||
|
|
||
| if (bodyWidth) { | ||
| customStyles[heroBodyWidth.name] = bodyWidth; | ||
| } | ||
| if (bodyMaxWidth) { | ||
| customStyles[heroBodyMaxWidth.name] = bodyMaxWidth; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={css(styles.hero, hasNoGlass && styles.modifiers.noGlass, className)} | ||
| style={{ ...props.style, ...customStyles }} | ||
|
Contributor
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. cc @mcoker Do we need to set the two hero body widths on the hero body element or is it fine to set them all on the hero element? Just wanted to check.
Contributor
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. Either way. I would probably put them on the hero wrapper since that's where we suggest consumers put their customizations*. * To expand on that, this is the hero component CSS var block. It renders this in the CSS:
The way we want consumers to customize components is the same way. In their CSS that loads after patternfly CSS (after so that it overrides ours), they should write something like: So when we have a component prop that customizes some CSS var for that component, we're effectively just doing that customization for them, so you'd do it the same way. You don't have to though if it's difficult - like a nested thing where it isn't easy to pass a style object back up to a parent wrapper. Another good use case for adding the vars directly to a hero body would be - if we went back to having a |
||
| {...props} | ||
| > | ||
| <div className={css(styles.heroBody)}>{children}</div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Hero.displayName = 'Hero'; | ||

Uh oh!
There was an error while loading. Please reload this page.