LeafyGreen UI Kit Gallery Indicator
npm install @leafygreen-ui/gallery-indicator``shell`
pnpm add @leafygreen-ui/gallery-indicator
`shell`
yarn add @leafygreen-ui/gallery-indicator
`shell`
npm install @leafygreen-ui/gallery-indicator
`js@leafygreen-ui/gallery-indicator
import { GalleryIndicator } from ;
activeIndex={0}
darkMode
/>
`
| Prop | Type | Description | Default |
| ------------- | --------- | ---------------------------------------------------- | ------- |
| length | number | The total number of dots to render | |activeIndex
| | number | The index of the active dot | |darkMode
| | boolean | Determines if the component will render in dark mode | false |
getTestUtils() is a util that allows consumers to reliably interact with LG GalleryIndicator in a product test suite. If the GalleryIndicator component cannot be found, an error will be thrown.
`tsx
import { getTestUtils } from '@leafygreen-ui/gallery-indicator';
const utils = getTestUtils(lgId?: string); // lgId refers to the custom data-lgid attribute passed to GalleryIndicator. It defaults to 'lg-gallery_indicator' if left empty.`
#### Single GalleryIndicator component
`tsx
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { GalleryIndicator, getTestUtils } from '@leafygreen-ui/gallery-indicator';
...
test('Gallery Indicator', () => {
render(
activeIndex={0}
darkMode
/>
);
const { getIndicatorlength, getActiveIndex } = getTestUtils();
expect(getIndicatorlength()).toBe(4);
expect(getActiveIndex()).toBe(0);
});
`
#### Multiple GalleryIndicator components
When testing multiple GalleryIndicator components, it is recommended to add the custom data-lgid attribute to each GalleryIndicator.
`tsx
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { GalleryIndicator, getTestUtils } from '@leafygreen-ui/gallery-indicator';
...
test('GalleryIndicator', () => {
render(
<>
activeIndex={0}
darkMode
data-lgid="gallery-indicator-abc"
/>
activeIndex={1}
darkMode
data-lgid="gallery-indicator-xyz"
/>
>
);
const testUtils1 = getTestUtils('gallery-indicator-abc');
const testUtils2 = getTestUtils('gallery-indicator-xy');
// First GalleryIndicator
expect(testUtils1.getIndicatorlength()).toBe(4);
expect(testUtils1.getActiveIndex()).toBe(1);
// Second GalleryIndicator
expect(testUtils2.getIndicatorlength()).toBe(5);
expect(testUtils2.getActiveIndex()).toBe(0);
});
`
`tsx`
const { getIndicatorlength, getActiveIndex } = getTestUtils();
| Util | Description | Returns |
| ---------------------- | ------------------------------------- | -------- |
| getIndicatorlength() | Returns the number of indicators/dots | number |getActiveIndex()
| | Returns the active indicator index | number` |