Debian Codegraph @

node/@patternfly/react-core/src/components/Hero/Hero.tsx

raw
1 import styles from '@patternfly/react-styles/css/components/Hero/hero';
2 import { css } from '@patternfly/react-styles';
3 import heroBackgroundImageLight from '@patternfly/react-tokens/dist/esm/c_hero_BackgroundImage_light';
4 import heroBackgroundImageDark from '@patternfly/react-tokens/dist/esm/c_hero_BackgroundImage_dark';
5 import heroGradientStop1Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_1_light';
6 import heroGradientStop2Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_2_light';
7 import heroGradientStop3Light from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_3_light';
8 import heroGradientStop1Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_1_dark';
9 import heroGradientStop2Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_2_dark';
10 import heroGradientStop3Dark from '@patternfly/react-tokens/dist/esm/c_hero_gradient_stop_3_dark';
11 import heroBodyWidth from '@patternfly/react-tokens/dist/esm/c_hero__body_Width';
12 import heroBodyMaxWidth from '@patternfly/react-tokens/dist/esm/c_hero__body_MaxWidth';
13
14 /** The main Hero component that allows adjusting of its background images and gradients in different color modes (such as light and dark). */
15
16 export interface HeroProps extends Omit<React.HTMLProps<HTMLDivElement>, 'content'> {
17 /** Content of the hero */
18 children?: React.ReactNode;
19 /** Additional classes added to the hero */
20 className?: string;
21 /** Light theme background image path of the hero */
22 backgroundSrcLight?: string;
23 /** Dark theme background image path of the hero */
24 backgroundSrcDark?: string;
25 /** Light theme gradient of the hero, taking any valid CSS color values for each stop property. */
26 gradientLight?: {
27 stop1?: string;
28 stop2?: string;
29 stop3?: string;
30 };
31 /** Dark theme gradient of the hero, taking any valid CSS color values for each stop property. */
32 gradientDark?: {
33 stop1?: string;
34 stop2?: string;
35 stop3?: string;
36 };
37 /** @beta Flag indicating the hero has glass styling when glass theme is applied. */
38 isGlass?: boolean;
39 /** Modifies the width of the hero body. */
40 bodyWidth?: string;
41 /** Modifies the max-width of the hero body. */
42 bodyMaxWidth?: string;
43 }
44
45 export const Hero: React.FunctionComponent<HeroProps> = ({
46 className,
47 children,
48 backgroundSrcLight,
49 backgroundSrcDark,
50 gradientLight,
51 gradientDark,
52 isGlass = false,
53 bodyWidth,
54 bodyMaxWidth,
55 ...props
56 }: HeroProps) => {
57 const customStyles: { [key: string]: string } = {};
58 if (backgroundSrcLight) {
59 customStyles[heroBackgroundImageLight.name] = `url(${backgroundSrcLight})`;
60 }
61 if (backgroundSrcDark) {
62 customStyles[heroBackgroundImageDark.name] = `url(${backgroundSrcDark})`;
63 }
64
65 if (gradientLight?.stop1) {
66 customStyles[heroGradientStop1Light.name] = gradientLight.stop1;
67 }
68 if (gradientLight?.stop2) {
69 customStyles[heroGradientStop2Light.name] = gradientLight.stop2;
70 }
71 if (gradientLight?.stop3) {
72 customStyles[heroGradientStop3Light.name] = gradientLight.stop3;
73 }
74 if (gradientDark?.stop1) {
75 customStyles[heroGradientStop1Dark.name] = gradientDark.stop1;
76 }
77 if (gradientDark?.stop2) {
78 customStyles[heroGradientStop2Dark.name] = gradientDark.stop2;
79 }
80 if (gradientDark?.stop3) {
81 customStyles[heroGradientStop3Dark.name] = gradientDark.stop3;
82 }
83
84 if (bodyWidth) {
85 customStyles[heroBodyWidth.name] = bodyWidth;
86 }
87 if (bodyMaxWidth) {
88 customStyles[heroBodyMaxWidth.name] = bodyMaxWidth;
89 }
90
91 return (
92 <div
93 className={css(styles.hero, isGlass && styles.modifiers.glass, className)}
94 style={{ ...props.style, ...customStyles }}
95 {...props}
96 >
97 <div className={css(styles.heroBody)}>{children}</div>
98 </div>
99 );
100 };
101
102 Hero.displayName = 'Hero';