mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-09 19:00:53 -04:00
fix(client): navigation profile image (#52087)
This commit is contained in:
@@ -46,7 +46,7 @@ function AvatarRenderer({
|
||||
{isPlaceHolderImage ? (
|
||||
<DefaultAvatar className='avatar default-avatar' />
|
||||
) : (
|
||||
<Image alt='' className='avatar' src={picture} />
|
||||
<Image alt='' src={picture} responsive />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,26 +2,37 @@ import { Story } from '@storybook/react';
|
||||
import React from 'react';
|
||||
import { Image } from './image';
|
||||
import { ImageProps } from './image.types';
|
||||
|
||||
const story = {
|
||||
title: 'Example/Image',
|
||||
component: Image
|
||||
component: Image,
|
||||
argTypes: {
|
||||
responsive: {
|
||||
control: { type: 'boolean' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const Template: Story<ImageProps> = args => {
|
||||
return <Image {...args} />;
|
||||
return (
|
||||
<div style={{ width: '100px', height: '100px' }}>
|
||||
<Image {...args} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Default = Template.bind({});
|
||||
Default.args = {
|
||||
alt: "Quincy Larson's signature",
|
||||
src: 'https://cdn.freecodecamp.org/platform/english/images/quincy-larson-signature.svg'
|
||||
};
|
||||
|
||||
export const Avatar = Template.bind({});
|
||||
Avatar.args = {
|
||||
alt: "camper's avatar",
|
||||
src: 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png',
|
||||
className: 'object-cover img-fluid max-w-full h-auto'
|
||||
responsive: false
|
||||
};
|
||||
|
||||
export const Responsive = Template.bind({});
|
||||
Responsive.args = {
|
||||
alt: "camper's avatar",
|
||||
src: 'https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png',
|
||||
responsive: true
|
||||
};
|
||||
|
||||
export default story;
|
||||
|
||||
@@ -2,8 +2,16 @@ import React from 'react';
|
||||
import { ImageProps } from './image.types';
|
||||
|
||||
export const Image = React.forwardRef<HTMLImageElement, ImageProps>(
|
||||
({ alt, src, ...props }, ref): JSX.Element => {
|
||||
return <img ref={ref} alt={alt} src={src} {...props} />;
|
||||
({ alt, src, responsive, ...props }, ref): JSX.Element => {
|
||||
// If `responsive` is `true`:
|
||||
// - Set `display` to `block`
|
||||
// - Set a maximum relative to the parent
|
||||
// - Scale the height according to the width, otherwise the image is stretched
|
||||
const className = responsive ? 'block max-w-full h-auto' : '';
|
||||
|
||||
return (
|
||||
<img ref={ref} alt={alt} src={src} className={className} {...props} />
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -2,4 +2,8 @@ import React from 'react';
|
||||
export interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
|
||||
alt: string;
|
||||
src: string;
|
||||
/**
|
||||
* Whether the image should be resized and contained within its parent.
|
||||
*/
|
||||
responsive?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user