mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
Added common members avatar component
refs https://github.com/TryGhost/members.js/issues/20 - Adds a common component to render member gravatar with backup of user icon where gravatar is not available or is blank. - Used in both Trigger component for logged in member as well as account areas.
This commit is contained in:
parent
462eb1c1b2
commit
d2098a783e
38
ghost/portal/src/components/common/MemberGravatar.js
Normal file
38
ghost/portal/src/components/common/MemberGravatar.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import {ReactComponent as UserIcon} from '../../images/icons/user.svg';
|
||||
|
||||
const Styles = ({style = {}}) => {
|
||||
return {
|
||||
userIcon: {
|
||||
width: '20px',
|
||||
height: '20px',
|
||||
color: '#fff',
|
||||
...(style.userIcon || {}) // Override any custom style
|
||||
},
|
||||
gravatar: {
|
||||
display: 'block',
|
||||
position: 'absolute',
|
||||
top: '-1px',
|
||||
right: '-1px',
|
||||
bottom: '-1px',
|
||||
left: '-1px',
|
||||
width: 'calc(100% + 2px)',
|
||||
height: 'calc(100% + 2px)',
|
||||
opacity: '1',
|
||||
maxWidth: 'unset',
|
||||
...(style.gravatar || {}) // Override any custom style
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function MemberGravatar({gravatar, style}) {
|
||||
let Style = Styles({style});
|
||||
return (
|
||||
<figure>
|
||||
<UserIcon style={Style.userIcon} />
|
||||
{gravatar ? <img src={gravatar} alt="Gravatar" style={Style.gravatar} /> : null}
|
||||
</figure>
|
||||
);
|
||||
}
|
||||
|
||||
export default MemberGravatar;
|
31
ghost/portal/src/components/common/MemberGravatar.test.js
Normal file
31
ghost/portal/src/components/common/MemberGravatar.test.js
Normal file
@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import {render} from '@testing-library/react';
|
||||
import MemberGravatar from './MemberGravatar';
|
||||
|
||||
const setup = (overrides = {}) => {
|
||||
const props = {
|
||||
gravatar: 'https://gravatar.com/avatar/76a4c5450dbb6fde8a293a811622aa6f?s=250&d=blank'
|
||||
};
|
||||
const utils = render(
|
||||
<MemberGravatar {...props} />
|
||||
);
|
||||
|
||||
const figureEl = utils.container.querySelector('figure');
|
||||
const userIconEl = utils.container.querySelector('svg');
|
||||
const imgEl = utils.container.querySelector('img');
|
||||
return {
|
||||
figureEl,
|
||||
userIconEl,
|
||||
imgEl,
|
||||
...utils
|
||||
};
|
||||
};
|
||||
|
||||
describe('MemberGravatar', () => {
|
||||
test('renders', () => {
|
||||
const {figureEl, userIconEl, imgEl} = setup();
|
||||
expect(figureEl).toBeInTheDocument();
|
||||
expect(userIconEl).toBeInTheDocument();
|
||||
expect(imgEl).toBeInTheDocument();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user