npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@leafygreen-ui/preview-card

v0.2.8

Published

LeafyGreen UI Kit Preview Card

Readme

Preview Card

npm (scoped)

View on MongoDB.design

Installation

PNPM

pnpm add @leafygreen-ui/preview-card

Yarn

yarn add @leafygreen-ui/preview-card

NPM

npm install @leafygreen-ui/preview-card

Description

The PreviewCard component is a container that can be expanded and collapsed to show or hide content. It's useful for displaying a preview of content that can be revealed in full by the user.

Example

Uncontrolled

import { PreviewCard } from '@leafygreen-ui/preview-card';
import { Body } from '@leafygreen-ui/typography';

<PreviewCard>
  <Body>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id elit non
    mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo,
    tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
    Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
  </Body>
</PreviewCard>;

Controlled

import { useState } from 'react';
import { PreviewCard } from '@leafygreen-ui/preview-card';
import { Body } from '@leafygreen-ui/typography';

const [isOpen, setIsOpen] = useState(false);

<PreviewCard isOpen={isOpen} onOpenChange={setIsOpen}>
  <Body>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id elit non
    mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo,
    tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
    Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
  </Body>
</PreviewCard>;

Properties

| Prop | Type | Description | Default | | :---------------- | :---------------------------- | :-------------------------------------------------------------------------------------------------- | :------------ | | children | React.ReactNode | The content to be displayed inside the card. | | | collapsedHeight | number \| string | The height of the card when it is collapsed. Can be a number (in pixels) or a string (e.g., '50%'). | 140 | | defaultOpen | boolean | The default open state of the card when it is uncontrolled. | false | | isOpen | boolean | The open state of the card. Providing this prop will switch the component to controlled mode. | | | onOpenChange | ChangeEventHandler<boolean> | The event handler called when the open state of the card changes. | | | viewLessText | React.ReactNode | The button text displayed when the card is expanded. | "View less" | | viewMoreText | React.ReactNode | The button text displayed when the card is collapsed. | "View more" |

Test Harnesses

getTestUtils

getTestUtils() is a util that allows consumers to reliably interact with LG PreviewCard in a product test suite. If the PreviewCard instance cannot be found, an error will be thrown.

Usage

import { getTestUtils } from '@leafygreen-ui/preview-card/testing';

const utils = getTestUtils(lgId?: `lg-${string}`); // lgId refers to the custom `data-lgid` attribute passed to a `PreviewCard` instance. It defaults to `lg-preview_card` if undefined.

Single PreviewCard

import { getTestUtils, renderPreviewCard } from '@leafygreen-ui/preview-card/testing';

...

test('single preview card', () => {
  renderPreviewCard();
  const { getPreviewCard } = getTestUtils();

  expect(getPreviewCard()).toBeInTheDocument();
});

Multiple PreviewCard components

When testing multiple PreviewCard components it is recommended to add the custom data-lgid attribute to each PreviewCard.

import { getTestUtils, renderMultiplePreviewCards } from '@leafygreen-ui/preview-card/testing';

...

test('multiple preview cards', () => {
  renderMultiplePreviewCards();
  const utilsOne = getTestUtils('lg-preview_card-1');
  const utilsTwo = getTestUtils('lg-preview_card-2');

  // First PreviewCard
  expect(utilsOne.getPreviewCard()).toBeInTheDocument();
  expect(utilsOne.isExpanded()).toBeFalsy();

  // Second PreviewCard
  expect(utilsTwo.getPreviewCard()).toBeInTheDocument();
  expect(utilsTwo.isExpanded()).toBeTruthy();
});

Test Utils

const {
  findPreviewCard,
  getContent,
  getPreviewCard,
  getToggle,
  isExpanded,
  queryPreviewCard,
} = getTestUtils();

| Util | Description | Returns | | ------------------ | ---------------------------------------------------------------- | ------------------------- | | findPreviewCard | Returns a promise that resolves to the component's root element. | Promise<HTMLDivElement> | | getContent | Returns the component's content element. | HTMLDivElement | | getPreviewCard | Returns the component's root element. | HTMLDivElement | | getToggle | Returns the component's toggle button element. | HTMLButtonElement | | isExpanded | Returns a boolean indicating whether the card is expanded. | boolean | | queryPreviewCard | Returns the component's root element or null if not found. | HTMLDivElement \| null |