Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})`
Copy link
Contributor

@gitdallas gitdallas May 30, 2023

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @mcoker

Copy link
Contributor

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

Copy link
Contributor

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.

} as React.CSSProperties
}
{...props}
></div>
/>
);

BackgroundImage.displayName = 'BackgroundImage';
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');
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`check loginpage example against snapshot 1`] = `
<DocumentFragment>
<div
class="pf-v5-c-background-image"
src="Background src"
style="--pf-v5-c-background-image--BackgroundImage: url(Background src);"
/>
<div
class="pf-v5-c-login"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.