-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
[Avatar] Add avatar component #1210
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy preview |
Hey @acomanescu thanks for the contribution. We will be working soon on the roadmap for Base UI, where we will share the next components we have in the pipeline. As of now, the Avatar component is not planned, but please keep an eye on the GH Roadmap/issues if you want to contribute with something else. If you are interested in Base UI introducing an Avatar component, please create an issue for it. Thank you! |
Hi @mnajdova, thank you for your response. I am closing this PR. |
I've created an issue for Avatar and added it to the current cycle. I'll reopen this PR and take a look soon. Thanks @acomanescu! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I left some initial feedback. I will let Colm review the docs demo
/** | ||
* Time in milliseconds to wait before showing the fallback. | ||
*/ | ||
delayMs: PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Time in milliseconds to wait before showing the fallback. | |
*/ | |
delayMs: PropTypes.number, | |
/** | |
* How long to wait before showing the fallback. Specified in milliseconds. | |
*/ | |
delay: PropTypes.number, |
To be consistent with the other components.
const { className, render, delayMs, ...otherProps } = props; | ||
|
||
const context = useAvatarRootContext(); | ||
const [canRender, setCanRender] = React.useState(delayMs === undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [canRender, setCanRender] = React.useState(delayMs === undefined); | |
const [delayPassed, setDelayPassed] = React.useState(delayMs === undefined); |
extraProps: otherProps, | ||
}); | ||
|
||
return canRender && context.imageLoadingStatus !== 'loaded' ? renderElement() : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return canRender && context.imageLoadingStatus !== 'loaded' ? renderElement() : null; | |
const canRender = delayPassed && context.imageLoadingStatus !== 'loaded' ; | |
return canRender ? renderElement() : null; |
To improve readability a bit.
|
||
export default function ExampleAvatar() { | ||
return ( | ||
<Avatar.Root className={styles.Root}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extend the hero demo so also show an Avatar with initials only, something like:
<Avatar.Root>
MN
</Avatar.Root>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I would make the avatars a bit smaller :)
describeConformance(<Avatar.Root />, () => ({ | ||
render, | ||
refInstanceof: window.HTMLSpanElement, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add more tests to make sure the fallback behavior is working as expected.
@acomanescu Good work 🙏
|
This PR adds the Avatar component. I wasn't able to run the tests due to some Mocha run errors that happen even when I run the tests on a fresh clone.