Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [0.14.7] - 2020-04-29
### Changed
- `lib/avatar.js`: fix Avatar defaultSrc behavior when src is null / undefined

## [0.14.6] - 2020-04-23
Add EditableProjectDomain and a back arrow icon

Expand Down
25 changes: 23 additions & 2 deletions lib/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import { CodeExample, PropsDefinition, Prop } from './story-utils';
import { TextInput } from './text-input';

const Image = React.forwardRef(({ src, defaultSrc, alt, ...props }, ref) => {
const [activeSrc, setActiveSrc] = React.useState(src || defaultSrc);
React.useEffect(() => {
setActiveSrc(src);
}, [src]);
setActiveSrc(src || defaultSrc);
}, [src, defaultSrc]);

const onError = () => {
if (defaultSrc && activeSrc !== defaultSrc) {
Expand Down Expand Up @@ -117,3 +118,23 @@ export const StoryAvatar_variants = () => (
</div>
</Flex>
);

const AvatarContainer = styled.div`
width: 100px;
margin: var(--space-2);
`;

export const StoryAvatar_defaultSrc = () => {
const [src, setSrc] = React.useState(null);
return (
<>
<p>If src is not present or the image at the URL does not load, Avatar shows the image at defaultSrc instead.</p>
<div>
<TextInput value={src} onChange={setSrc} placeholder="img src" label="img src" />
</div>
<AvatarContainer>
<Avatar variant="square" src={src} defaultSrc={DEFAULT_PROJECT_AVATAR_URL} alt="" />
</AvatarContainer>
</>
);
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@glitchdotcom/shared-components",
"version": "0.14.6",
"version": "0.14.7",
"description": "Shared components",
"main": "build/main.js",
"module": "build/module.js",
Expand Down