Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
2.4 KB
Raw Blame
// Copyright (c) Meta Platforms, Inc. and affiliates.

import type {Meta, StoryObj} from '@storybook/react';
import {LineClamp} from '@astryxdesign/lab/LineClamp';

const LONG_TEXT =
  'Astryx is an open source design system that grew inside Meta over the last eight years, where it became the most-used and largest design system in the company — powering thousands of apps and shaped by the engineers, designers, and product teams who depend on it every day.';

const meta: Meta<typeof LineClamp> = {
  title: 'Lab/LineClamp',
  component: LineClamp,
  tags: ['autodocs'],
  argTypes: {
    maxLines: {
      control: {type: 'number', min: 1, max: 6, step: 1},
      description: 'Maximum number of lines before clamping',
    },
    hasTruncateTooltip: {
      control: 'boolean',
      description: 'Show full content in a tooltip when clamped',
    },
    truncateTooltipPlacement: {
      control: 'select',
      options: ['above', 'below', 'start', 'end'],
      description: 'Where the truncation tooltip opens',
    },
    as: {
      control: 'select',
      options: ['div', 'span', 'p'],
      description: 'HTML element to render',
    },
  },
  decorators: [
    Story => (
      <div style={{maxWidth: 320}}>
        <Story />
      </div>
    ),
  ],
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
  args: {
    maxLines: 3,
    children: LONG_TEXT,
  },
};

export const TwoLines: Story = {
  args: {
    maxLines: 2,
    children: LONG_TEXT,
  },
};

export const SingleLine: Story = {
  args: {
    maxLines: 1,
    children: LONG_TEXT,
  },
};

export const WithoutTooltip: Story = {
  args: {
    maxLines: 2,
    hasTruncateTooltip: false,
    children: LONG_TEXT,
  },
};

export const MixedContent: Story = {
  args: {
    maxLines: 2,
    children: (
      <>
        This card description mixes <strong>bold</strong>, <em>italic</em>, and
        plain text. LineClamp clamps all of it as one block and adds no
        typography of its own.
      </>
    ),
  },
};

export const ShortContentNotClamped: Story = {
  args: {
    maxLines: 3,
    children: 'This content is short enough that it never clamps.',
  },
};

export const WithClippedLink: Story = {
  args: {
    maxLines: 2,
    children: (
      <>
        {LONG_TEXT}{' '}
        <a href="https://example.com" data-testid="trailing-link">
          Read the full story
        </a>
      </>
    ),
  },
};