-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add BaseImage component with image fallback display (#2193)
- Loading branch information
1 parent
3c2da43
commit 6bcf06a
Showing
37 changed files
with
1,021 additions
and
59 deletions.
There are no files selected for viewing
Binary file added
BIN
+374 KB
docusaurus/docs/React/assets/base-image-fallback-in-attachment-gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.5 KB
docusaurus/docs/React/assets/base-image-fallback-in-attachment-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.2 KB
docusaurus/docs/React/assets/base-image-fallback-in-image-attachment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
docusaurus/docs/React/components/utility-components/base-image.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
id: base-image | ||
sidebar_position: 9 | ||
title: BaseImage | ||
--- | ||
|
||
import ImageShowcase from '@site/src/components/ImageShowcase'; | ||
import BaseImageInGallery from '../../assets/base-image-fallback-in-attachment-gallery.png' | ||
import BaseImageInAttachmentPreview from '../../assets/base-image-fallback-in-attachment-preview.png' | ||
import BaseImageInImageAttachment from '../../assets/base-image-fallback-in-image-attachment.png' | ||
|
||
The `BaseImage` component's purpose is to display an image or a fallback if loading the resource has failed. The component is used internally by: | ||
|
||
- `Image` component - used to display image attachments in `Message` | ||
- `Gallery` component - used to display image gallery among `Message` attachments | ||
- `AttachmentPreviewList` component - used to display attachment previews in `MessageInput` | ||
|
||
The default image fallbacks are rendered as follows: | ||
|
||
<ImageShowcase | ||
border | ||
items={[ | ||
{ | ||
image: BaseImageInImageAttachment, | ||
caption: <span>BaseImage in image attachment</span>, | ||
alt: 'BaseImage in image attachment', | ||
}, | ||
{ | ||
image: BaseImageInGallery, | ||
caption: <span>BaseImage in image attachment gallery</span>, | ||
alt: 'BaseImage in image attachment gallery', | ||
}, | ||
{ | ||
image: BaseImageInAttachmentPreview, | ||
caption: <span>BaseImage in attachment preview</span>, | ||
alt: 'BaseImage in attachment preview', | ||
}, | ||
]} | ||
/> | ||
|
||
## Usage | ||
|
||
### Custom image fallback | ||
|
||
The default image fallback can be changed by applying a new CSS data image to the fallback mask in the `BaseImage`'s `<img/>` element. The data image has to be assigned to a CSS variable `--str-chat__image-fallback-icon` within the scope of `.str-chat` class. An example follows: | ||
|
||
```css | ||
|
||
.str-chat { | ||
--str-chat__image-fallback-icon: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEwIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJNOS4xOTk0OSAwLjMwNTY3MUM4LjkzOTQ5IDAuMDQ1NjcwNyA4LjUxOTQ5IDAuMDQ1NjcwNyA4LjI1OTQ5IDAuMzA1NjcxTDQuOTk5NDkgMy41NTlMMS43Mzk0OSAwLjI5OTAwNEMxLjQ3OTQ5IDAuMDM5MDAzOSAxLjA1OTQ5IDAuMDM5MDAzOSAwLjc5OTQ5MiAwLjI5OTAwNEMwLjUzOTQ5MiAwLjU1OTAwNCAwLjUzOTQ5MiAwLjk3OTAwNCAwLjc5OTQ5MiAxLjIzOUw0LjA1OTQ5IDQuNDk5TDAuNzk5NDkyIDcuNzU5QzAuNTM5NDkyIDguMDE5IDAuNTM5NDkyIDguNDM5IDAuNzk5NDkyIDguNjk5QzEuMDU5NDkgOC45NTkgMS40Nzk0OSA4Ljk1OSAxLjczOTQ5IDguNjk5TDQuOTk5NDkgNS40MzlMOC4yNTk0OSA4LjY5OUM4LjUxOTQ5IDguOTU5IDguOTM5NDkgOC45NTkgOS4xOTk0OSA4LjY5OUM5LjQ1OTQ5IDguNDM5IDkuNDU5NDkgOC4wMTkgOS4xOTk0OSA3Ljc1OUw1LjkzOTQ5IDQuNDk5TDkuMTk5NDkgMS4yMzlDOS40NTI4MyAwLjk4NTY3MSA5LjQ1MjgzIDAuNTU5MDA0IDkuMTk5NDkgMC4zMDU2NzFaIiBmaWxsPSIjNzI3NjdFIi8+Cjwvc3ZnPgo="); | ||
} | ||
``` | ||
|
||
We can change the mask dimensions or color by applying the following rules to the image's class `.str-chat__base-image--load-failed`, that signals the image load has failed: | ||
|
||
```css | ||
:root{ | ||
--custom-icon-fill-color: #223344; | ||
--custom-icon-width-and-height: 4rem 4rem; | ||
} | ||
|
||
.str-chat__base-image--load-failed { | ||
mask-size: var(--custom-icon-width-and-height); | ||
-webkit-mask-size: var(--custom-icon-width-and-height); | ||
background-color: var(--custom-icon-fill-color); | ||
} | ||
``` | ||
|
||
### Custom BaseImage | ||
|
||
The default `BaseImage` can be overridden by passing a custom component to `Channel` props: | ||
|
||
|
||
```tsx | ||
import {ComponentProps } from 'react'; | ||
import { Channel } from 'stream-chat-react'; | ||
|
||
const CustomBaseImage = (props: ComponentProps<'img'>) => { | ||
// your implementation... | ||
} | ||
|
||
export const MyUI = () => { | ||
return ( | ||
<Channel BaseImage={CustomBaseImage}> | ||
{{/* more components */ }} | ||
</Channel> | ||
); | ||
}; | ||
``` | ||
|
||
## Props | ||
|
||
The component accepts the `img` component props. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.