Skip to content
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

fix(brand): allowed heights/widths to be set together and be used when no children are passed #9342

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/react-core/src/components/Brand/Brand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ export const Brand: React.FunctionComponent<BrandProps> = ({
...props
}: BrandProps) => {
let responsiveStyles;
if (children !== undefined && widths !== undefined) {
if (widths !== undefined) {
responsiveStyles = {
...setBreakpointCssVars(widths, '--pf-v5-c-brand--Width')
};
}

if (children !== undefined && heights !== undefined) {
if (heights !== undefined) {
responsiveStyles = {
...responsiveStyles,
...setBreakpointCssVars(heights, '--pf-v5-c-brand--Height')
};
}
Expand All @@ -67,7 +68,7 @@ export const Brand: React.FunctionComponent<BrandProps> = ({
<img src={src} alt={alt} />
</picture>
) : (
<img {...props} className={css(styles.brand, className)} style={style} src={src} alt={alt} />
<img {...props} className={css(styles.brand, className)} style={{ ...style, ...responsiveStyles }} src={src} alt={alt} />
)
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/components/Brand/examples/Brand.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import logoBase from './pf-c-brand--logo-base.jpg';

### Responsive

Passing `<source>` elements as children to `Brand` will change the component from an `<img>` to a `<picture>` element. In this form, breakpoint modifiers for width and height may be passed to `Brand`. The `src` and `alt` properties should still be passed to populate the fallback `img` of the brand.
Passing `<source>` elements as children to `Brand` will change the component from an `<img>` to a `<picture>` element. The `src` and `alt` properties should still be passed to populate the fallback `img` of the brand.

```ts file="./BrandResponsive.tsx"
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import React from 'react';
import { Brand } from '@patternfly/react-core';
import pfLogo from './pfLogo.svg';

export const BrandBasic: React.FunctionComponent = () => <Brand src={pfLogo} alt="Patternfly Logo" />;
export const BrandBasic: React.FunctionComponent = () => <Brand src={pfLogo} alt="Patternfly Logo" widths={{ default: '200px', md: '400px', xl: '600px' }} />;