|
| 1 | +--- |
| 2 | +title: Image |
| 3 | +description: Image component |
| 4 | +version: 2.0+ |
| 5 | +--- |
| 6 | +# Image |
| 7 | + |
| 8 | +The Image component is used to display images with support for fallback. |
| 9 | + |
| 10 | +## Import |
| 11 | + |
| 12 | +```js |
| 13 | +import { CImage } from "@chakra-ui/vue-next" |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +::showcase |
| 19 | +:simple-image |
| 20 | +:: |
| 21 | + |
| 22 | + |
| 23 | +```html |
| 24 | +<CBox w="sm"> |
| 25 | + <CImage src="https://bit.ly/chakra-jonathan-bakebwa" alt="Jonathan Bakebwa" /> |
| 26 | +</CBox> |
| 27 | +``` |
| 28 | + |
| 29 | +## Size |
| 30 | + |
| 31 | +The size of the image can be adjusted using the `box-size` prop. |
| 32 | + |
| 33 | +::showcase |
| 34 | +:box-image |
| 35 | +:: |
| 36 | + |
| 37 | + |
| 38 | +```html |
| 39 | +<CStack direction='row'> |
| 40 | + <CImage box-size='100px' object-fit='cover' src="https://bit.ly/chakra-jonathan-bakebwa" alt="Jonathan Bakebwa" /> |
| 41 | + <CImage box-size='150px' object-fit='cover' src="https://bit.ly/chakra-jonathan-bakebwa" alt="Jonathan Bakebwa" /> |
| 42 | + <CImage box-size='200px' src="https://bit.ly/chakra-jonathan-bakebwa" alt="Jonathan Bakebwa" /> |
| 43 | +</CStack> |
| 44 | +``` |
| 45 | + |
| 46 | +## Image with border radius |
| 47 | + |
| 48 | +::showcase |
| 49 | +:rounded-image |
| 50 | +:: |
| 51 | + |
| 52 | + |
| 53 | +```html |
| 54 | +<CBox w="sm"> |
| 55 | + <CImage border-radius='full' box-size='150px' src="https://bit.ly/chakra-jonathan-bakebwa" alt="Jonathan Bakebwa" /> |
| 56 | +</CBox> |
| 57 | +``` |
| 58 | + |
| 59 | +## Fallback support |
| 60 | + |
| 61 | +The Image component allows you provide a fallback placeholder. The placeholder is displayed when: |
| 62 | + |
| 63 | +- The fallback or `fallback-src` prop is provided |
| 64 | +- The image provided in `src` is currently loading |
| 65 | +- An error occurred while loading the image `src` |
| 66 | +- No `src` prop was passed |
| 67 | + |
| 68 | +> You can also opt out of this behavior by passing the ignoreFallback prop. |
| 69 | +
|
| 70 | +::showcase |
| 71 | +::fallback-image |
| 72 | +:: |
| 73 | +:: |
| 74 | + |
| 75 | +```html |
| 76 | +<CImage src="gibberesh.png" fallbackSrc="https://via.placeholder.com/150" /> |
| 77 | +``` |
| 78 | + |
| 79 | +## Props |
| 80 | + |
| 81 | +| Name | Type | Default | Description | |
| 82 | +|------------------|-----------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------| |
| 83 | +| `src` | `string` | | The path to the image source | |
| 84 | +| `fallback-src` | `string` | | In event there was an error loading the `src`, specify a fallback. In most cases, this can be an avatar or image placeholder | |
| 85 | +| `alt` | `string` | | The alt text that describes the image | |
| 86 | +| `ignoreFallback` | `boolean` | `false` | Opt out of the `fallback-src` logic and use the `CImage` directly | |
0 commit comments