-
Notifications
You must be signed in to change notification settings - Fork 375
fix(BackgroundImage): Added src URL back, improved unit tests, updated screenshot #9199
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
Merged
Merged
Changes from all commits
Commits
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
25 changes: 12 additions & 13 deletions
25
packages/react-core/src/components/BackgroundImage/BackgroundImage.tsx
This file contains hidden or 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,30 +1,29 @@ | ||
| import * as React from 'react'; | ||
| import React from 'react'; | ||
|
|
||
| import { css } from '@patternfly/react-styles'; | ||
| import styles from '@patternfly/react-styles/css/components/BackgroundImage/background-image'; | ||
| // eslint-disable-next-line camelcase | ||
| // import c_background_image_BackgroundImage from '@patternfly/react-tokens/dist/esm/c_background_image_BackgroundImage'; | ||
|
|
||
| export interface BackgroundImageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'src'> { | ||
| /** Additional classes added to the background image. */ | ||
| className?: string; | ||
| export interface BackgroundImageProps extends React.HTMLProps<HTMLDivElement> { | ||
| /** The URL or file path of the image for the background */ | ||
| src: string; | ||
| /** Additional classes added to the background image. */ | ||
| className?: string; | ||
| } | ||
|
|
||
| export const BackgroundImage: React.FunctionComponent<BackgroundImageProps> = ({ | ||
| className, | ||
| // src, | ||
| src, | ||
| ...props | ||
| }: BackgroundImageProps) => ( | ||
| <div | ||
| className={css(styles.backgroundImage, className)} | ||
| /* eslint-disable camelcase */ | ||
| style={{ | ||
| // [c_background_image_BackgroundImage.name as string]: `url(${src})` | ||
| }} | ||
| /* eslint-enable camelcase */ | ||
| style={ | ||
| { | ||
| '--pf-v5-c-background-image--BackgroundImage': `url(${src})` | ||
| } as React.CSSProperties | ||
| } | ||
| {...props} | ||
| ></div> | ||
| /> | ||
| ); | ||
|
|
||
| BackgroundImage.displayName = 'BackgroundImage'; | ||
29 changes: 14 additions & 15 deletions
29
packages/react-core/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx
This file contains hidden or 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,21 +1,20 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { BackgroundImage } from '../BackgroundImage'; | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| const images = { | ||
| lg: '/assets/images/pfbg_1200.jpg', | ||
| sm: '/assets/images/pfbg_768.jpg', | ||
| sm2x: '/assets/images/pfbg_768@2x.jpg', | ||
| xs: '/assets/images/pfbg_576.jpg', | ||
| xs2x: '/assets/images/pfbg_576@2x.jpg' | ||
| }; | ||
| test('has default className and src URL applied to style', () => { | ||
| render(<BackgroundImage src="/image/url.png" data-testid="test-id" />); | ||
|
|
||
| test('BackgroundImage', () => { | ||
| const { asFragment } = render(<BackgroundImage src={images} />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| const backgroundImage = screen.getByTestId('test-id'); | ||
| const backgroundImageStyle = backgroundImage.getAttribute('style'); | ||
|
|
||
| expect(backgroundImage).toHaveClass('pf-v5-c-background-image'); | ||
| expect(backgroundImageStyle).toContain('--pf-v5-c-background-image--BackgroundImage'); | ||
| expect(backgroundImageStyle).toContain('/image/url.png'); | ||
| }); | ||
|
|
||
| test('allows passing in a single string as the image src', () => { | ||
| const { asFragment } = render(<BackgroundImage src={images.lg} />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| test('has additional className when one is provided', () => { | ||
| render(<BackgroundImage src="/image/url.png" className="another-class" data-testid="test-id" />); | ||
|
|
||
| expect(screen.getByTestId('test-id')).toHaveClass('another-class'); | ||
| }); |
19 changes: 0 additions & 19 deletions
19
...core/src/components/BackgroundImage/__tests__/__snapshots__/BackgroundImage.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Binary file modified
BIN
-180 KB
(13%)
...eact-docs/patternfly-docs/generated/components/background-image/react/basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
it would be nice if we had a token/css prop for this - preventing future "replace hard coded values" work
@tlabaj - would it be worth combining with base css prop like
--${styles.backgroundImage}--BackgroundImage?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.
cc @mcoker
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.
Agree - this PR should add a token you can set patternfly/patternfly#5633
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.
@gitdallas @mcoker I think we can take this PR in as is and ope na follow up issue to the core PR.