Skip to content

Commit

Permalink
Fix onLoadingStatusChange missing from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Jan 31, 2025
1 parent 8c0e720 commit df65f19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/reference/generated/avatar-image.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "AvatarImage",
"description": "The image to be displayed in the avatar.\nRenders an `<img>` element.",
"props": {
"onLoadingStatusChange": {
"type": "function",
"description": "Callback fired when the loading status changes."
},
"className": {
"type": "string | (state) => string",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
Expand Down
15 changes: 12 additions & 3 deletions packages/react/src/avatar/image/AvatarImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ const AvatarImage = React.forwardRef<HTMLImageElement, AvatarImage.Props>(functi
props: AvatarImage.Props,
forwardedRef,
) {
const { className, render, onLoadingStatusChange = NOOP, referrerPolicy, ...otherProps } = props;
const {
className,
render,
onLoadingStatusChange: onLoadingStatusChangeProp,
referrerPolicy,
...otherProps
} = props;

const context = useAvatarRootContext();
const imageLoadingStatus = useImageLoadingStatus(props.src, referrerPolicy);

const handleLoadingStatusChange = useEventCallback((status: ImageLoadingStatus) => {
onLoadingStatusChange(status);
onLoadingStatusChangeProp?.(status);
context.setImageLoadingStatus(status);
});

Expand Down Expand Up @@ -56,6 +62,9 @@ const AvatarImage = React.forwardRef<HTMLImageElement, AvatarImage.Props>(functi

export namespace AvatarImage {
export interface Props extends BaseUIComponentProps<'img', AvatarRoot.State> {
/**
* Callback fired when the loading status changes.
*/
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
}
}
Expand All @@ -77,7 +86,7 @@ AvatarImage.propTypes /* remove-proptypes */ = {
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* @ignore
* Callback fired when the loading status changes.
*/
onLoadingStatusChange: PropTypes.func,
/**
Expand Down

0 comments on commit df65f19

Please sign in to comment.