---
title: ImageAccordion
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, FigmaEmbed, PropsTable } from '../../src/components'
import { ImageAccordion } from '@telus-uds/components-community'
import { ChevronLink } from '@telus-uds/components-web'
import { Box } from '@telus-uds/components-web'
import { ImageAccordion as WebDocs } from 'docs/@telus-uds/components-community'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'

# ImageAccordion

<LibraryInfo packageType="Web Component" packageName="components-community.image-accordion" />

```jsx live
<ImageAccordion
  accordionHeading="Welcome To TELUS"
  subHeading="Let’s make the future friendly"
  accordionItems={AccordionData}
  reverseColumns={false}
  vertImageAlign="center"
/>
```

## Introduction

```jsx
import { ImageAccordion } from '@telus-uds/components-community.image-accordion'
```

This is an introduction to the ImageAccordion component.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

ImageAccordion is designed for flexibility - Each expandable item can take in any other component to be displayed
when it is expanded, and each Item has it's own image to display along side it.

It has no margins or borders on the outside and it will fill it's parent container meaning it can also be placed inside other
components without causing layout issues.

### `headerImage`

The `headerImage` prop accepts an image that will be placed just before the Heading of the accordion.

```jsx live
<ImageAccordion
  headerImage={
    <Image
      src={'/universal-design-system/img/smartenergy-accordion-icon.png'}
      alt="Smart Energy Icon"
      width={60}
      height={60}
    />
  }
  accordionHeading="Welcome To TELUS"
  subHeading="Let’s make the future friendly"
  accordionItems={AccordionData}
  reverseColumns={false}
/>
```

### `ImageAccordion`

The `ImageAccordion` takes in 6 props that allow customization. All content for the accordion is passed in
through the `accordionItems` prop.

#### `accordionItems` prop

The `accordionItems` prop accepts an `array` of `objects` with the following structure:

```js
const items = [
  {
    desktopImageBlock: desktopImageBlock(),
    mobileImageBlock: mobileImageBlock(),
    desktopImage: {
      src: '',
      width: 1010,
      height: 600,
      alt: ''
    },
    mobileImage: {
      src: '',
      width: 505,
      height: 300,
      alt: ''
    }
    heading: 'Accordion Item Heading',
    children: child()
  }
]
```

#### `desktopImageBlock` and `desktopImage` props

ImageAccordion supports rendering images using only one of two props: `desktopImageBlock` or `desktopImage`. These props determine how an image is displayed upon the expansion of the item.

##### `desktopImageBlock` prop

- **Primary Choice:** By default, `desktopImageBlock` is used for rendering images.
- **Functionality:** This prop contains a function that returns JSX. The JSX typically includes an external image component optimized for rendering within the Site Builder V2 environment.
- **Optimization:** The `desktopImageBlock` leverages the core image from SiteBuilderV2 `next/image` component for optimized image rendering, ensuring efficient image display with built-in performance enhancements.
- **Usage:** Utilize `desktopImageBlock` when you need a customizable and optimized image rendering solution within the Site Builder.

##### `desktopImage` prop

- **Fallback Option:** In cases where `desktopImageBlock` is undefined or holds a falsy value, `desktopImage` is used as a fallback to render the image.
- **Structure:** `desktopImage` is an object that is utilized to render the UDS (Universal Design System) Image component.
- **Props Compatibility:** It accepts all the props compatible with the UDS Image component, ensuring versatility in image rendering.
- **Requirements:** When using `desktopImage`, ensure that it includes all the necessary props required by the UDS Image component for proper functionality.
- **Example of Usage**: Here is an example of how the UDS Image component can be used with `desktopImage`:

```jsx
<Image src="" width={} height={} alt="" />
```

`children` should contain a function that returns the JSX to be displayed when the item is expanded.

#### `accordionHeading` and `subHeading` props

Both of these props are optional and can be left blank if you want your own heading styles or want the accordion to fit inside a different component, however, the subHeading will not render by itself if the `accordionHeading` is left blank

```jsx live
<ImageAccordion accordionItems={AccordionData} reverseColumns={false} />
```

#### `children` prop

`children` prop is optional but can be used to render other components within `ImageAccordion`

```jsx live
<ImageAccordion
  accordionHeading="Welcome To TELUS"
  subHeading="Let’s make the future friendly"
  accordionItems={AccordionData}
  reverseColumns={false}
  vertImageAlign="center"
>
  <ChevronLink href="https://www.telus.com">Go to telus.com</ChevronLink>
</ImageAccordion>
```

#### `reverseColumns` prop

If `reverseColumns` is true, it will reverse the accordion, putting the expandable items on the right, and the images on the left.

```jsx live
<ImageAccordion
  accordionHeading="Welcome To TELUS"
  subHeading="Let’s make the future friendly"
  accordionItems={AccordionData}
  reverseColumns={true}
/>
```

#### `mobileImageBlock` and `mobileImage` props

The handling of `mobileImageBlock` and `mobileImage` props follows a similar logic to the previously described `desktopImageBlock` and `desktopImage` props, but with a focus on mobile optimization in which only one of two props is used for image rendering upon the expansion of each item. If the `mobileImageBlock` prop is true, the accordion will render each accordionItem with it's corresponding Image underneath the rest of it's children on mobile screen sizes.

##### `mobileImageBlock`

- **Usage:** `mobileImageBlock` is the primary prop for rendering mobile-optimized images. It contains a function that returns JSX for the core image component, tailored for mobile display.
- **Functionality:** When `mobileImageBlock` is true, it allows the accordion to render each item with its corresponding image, along with other children, specifically for mobile screen sizes.
- **Optimization:** This prop is designed to ensure images are appropriately displayed on mobile devices, enhancing the user experience on smaller screens.

##### `mobileImage`

- **Fallback:** In scenarios where `mobileImageBlock` is not defined or is falsy, `mobileImage` acts as the fallback option.
- **Structure and Compatibility:** `mobileImage` functions similarly to its desktop counterpart, accepting the same props and providing a mobile-friendly image display.

### Accessibility

`imageAccordion` uses an accessibility package from npm called `react-accessible-accordion`

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable web={WebDocs} />

## Variants

### Inverse

This variant is used when the accordion is rendered on dark backgrounds.

```jsx live
<Box variant={{ background: 'brand' }} space={4}>
  <ImageAccordion
    accordionHeading="Welcome To TELUS"
    subHeading="Let’s make the future friendly"
    accordionItems={AccordionData}
    reverseColumns={false}
    variant="inverse"
  />
</Box>
```

## Feedback

<Feedback component="ImageAccordion" />
