| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/Brand/brand'; |
| 3 |
import { setBreakpointCssVars } from '../../helpers'; |
| 4 |
import cssBrandHeight from '@patternfly/react-tokens/dist/esm/c_brand_Height'; |
| 5 |
import cssBrandWidth from '@patternfly/react-tokens/dist/esm/c_brand_Width'; |
| 6 |
|
| 7 |
export interface BrandProps extends React.DetailedHTMLProps< |
| 8 |
React.ImgHTMLAttributes<HTMLImageElement>, |
| 9 |
HTMLImageElement |
| 10 |
> { |
| 11 |
/** Transforms the Brand into a <picture> element from an <img> element. Container for <source> child elements. */ |
| 12 |
children?: React.ReactNode; |
| 13 |
/** Additional classes added to the either type of Brand. */ |
| 14 |
className?: string; |
| 15 |
/** Attribute that specifies the URL of a <img> Brand. For a <picture> Brand this specifies the fallback <img> URL. */ |
| 16 |
src?: string; |
| 17 |
/** Attribute that specifies the alt text of a <img> Brand. For a <picture> Brand this specifies the fallback <img> alt text. */ |
| 18 |
alt: string; |
| 19 |
/** Widths at various breakpoints for a <picture> Brand. */ |
| 20 |
widths?: { |
| 21 |
default?: string; |
| 22 |
sm?: string; |
| 23 |
md?: string; |
| 24 |
lg?: string; |
| 25 |
xl?: string; |
| 26 |
'2xl'?: string; |
| 27 |
}; |
| 28 |
/** Heights at various breakpoints for a <picture> Brand. */ |
| 29 |
heights?: { |
| 30 |
default?: string; |
| 31 |
sm?: string; |
| 32 |
md?: string; |
| 33 |
lg?: string; |
| 34 |
xl?: string; |
| 35 |
'2xl'?: string; |
| 36 |
}; |
| 37 |
} |
| 38 |
|
| 39 |
export const Brand: React.FunctionComponent<BrandProps> = ({ |
| 40 |
className = '', |
| 41 |
src = '', |
| 42 |
alt, |
| 43 |
children, |
| 44 |
widths, |
| 45 |
heights, |
| 46 |
style, |
| 47 |
...props |
| 48 |
}: BrandProps) => { |
| 49 |
let responsiveStyles; |
| 50 |
if (widths !== undefined) { |
| 51 |
responsiveStyles = { |
| 52 |
...setBreakpointCssVars(widths, cssBrandWidth.name) |
| 53 |
}; |
| 54 |
} |
| 55 |
|
| 56 |
if (heights !== undefined) { |
| 57 |
responsiveStyles = { |
| 58 |
...responsiveStyles, |
| 59 |
...setBreakpointCssVars(heights, cssBrandHeight.name) |
| 60 |
}; |
| 61 |
} |
| 62 |
|
| 63 |
return ( |
| 64 |
/** the brand component currently contains no styling the 'pf-v6-c-brand' string will be used for the className */ |
| 65 |
children !== undefined ? ( |
| 66 |
<picture |
| 67 |
className={css(styles.brand, styles.modifiers.picture, className)} |
| 68 |
style={{ ...style, ...responsiveStyles }} |
| 69 |
{...props} |
| 70 |
> |
| 71 |
{children} |
| 72 |
<img src={src} alt={alt} /> |
| 73 |
</picture> |
| 74 |
) : ( |
| 75 |
<img |
| 76 |
{...props} |
| 77 |
className={css(styles.brand, className)} |
| 78 |
style={{ ...style, ...responsiveStyles }} |
| 79 |
src={src} |
| 80 |
alt={alt} |
| 81 |
/> |
| 82 |
) |
| 83 |
); |
| 84 |
}; |
| 85 |
Brand.displayName = 'Brand'; |