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

Image customCss Implementation #186

Merged
merged 5 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -18,5 +18,6 @@ export const Playground = () => (
),
}}
onLoad={action('Image loaded')}
customCss={text('Custom css', "custom")}
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a valid css that actually modify the component somehow

/>
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { StyledCssProps } from 'components/Components.styled.types';
import styled from 'styled-components';
import { customCss } from 'utils/customCss';

export const StyledSource = styled.source`
user-select: none;
`;
type Props = StyledCssProps;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this type is never used


export const StyledImage = styled.img`
export const StyledImage = styled.img<StyledCssProps>`
user-select: none;

${(props) => customCss(props)}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ describe('Image', () => {
fireEvent.load(image);
expect(mockOnLoad).toHaveBeenCalledTimes(1);
});
it('should render custom CSS as a class', () => {
render(<Image image={imageType} customCss="customCss" />);
const image = screen.getByTestId(imageContentTestId);
expect(image).toHaveClass('custom');
});
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import React from 'react';
import cn from 'classnames';
import { Props } from './Image.types';
import { StyledImage, StyledSource } from './Image.styled';
import { StyledImage } from './Image.styled';

export const Image = ({
className,
imageClassName,
customCss,
image: { title, url },
testId = 'image',
onLoad,
}: Props) => {
return (
<picture className={className}>
<StyledSource
className={imageClassName}
<StyledImage
as="source"
css={customCss}
className={cn(imageClassName, { custom: customCss })}
Copy link
Collaborator

Choose a reason for hiding this comment

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

not necessary with the new approach

data-testid={testId}
type="image/webp"
srcSet={`${url}?fm=webp`}
/>
<StyledImage
data-testid="imageContent"
onLoad={onLoad}
className={imageClassName}
css={customCss}
className={cn(imageClassName, { custom: customCss })}
Copy link
Collaborator

Choose a reason for hiding this comment

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

not necessary with the new approach

alt={title}
src={url}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseProps } from 'components/Components.types';
import { CssCustomizableProps } from 'components/Components.types';

export type Props = BaseProps & {
export type Props = CssCustomizableProps & {
imageClassName?: string;
image: Image;
onLoad?: () => void;
Expand Down