Skip to content
Open
8 changes: 5 additions & 3 deletions .claude/skills/component-stories/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ Stories highlighting specific features.

#### 4. Truncation / Responsiveness Stories

Stories that demonstrate how a component truncates or adapts to constrained space.
Stories that demonstrate how a component truncates text or adapts to constrained space.

- Use: `ResponsivenessShowcase`
- Use `ResponsivenessShowcase` for how the component adapts to constrained space or width.
- Use `NumberOfLinesShowcase` for how text is clamped or wraps when a `numberOfLines` prop controls it (the `{Property}Showcase` rule). Show the default, a line count and `0` (no limit).
- Use `TruncationShowcase` only when truncation is fixed and no prop controls it.
- Do not use: `TruncateShowcase`, `Truncation`, `LongLabel`

## Comments
Expand All @@ -187,7 +189,7 @@ Rules verifiable from a diff.
| Check | Applies to | Detect | Skip |
| ----------------------------------------------------------------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| Base story named `Default`/`Primary`/`Basic` instead of `Base` | all stories | export name | — |
| Showcase/feature story off-convention | all stories | not `{Property}Showcase` / `With{Feature}` / `ResponsivenessShowcase` | — |
| Showcase/feature story off-convention | all stories | not `{Property}Showcase` / `With{Feature}` / `ResponsivenessShowcase` / `TruncationShowcase` | — |
| Missing `layout: 'centered'` + `backgrounds: { default: 'light' }` | all stories | `Base` parameters | — |
| `Base` or a feature story (`With{Feature}`) reads its data from a module-level const instead of inlining it | all stories | `data={<const>}` / `args: { data: <const> }` in `Base` or `With{Feature}` | `{Property}Showcase` and variation stories |
| `type: 'dynamic'` applied to a story with function props, hooks, state or handlers | all stories | `docs.source.type: 'dynamic'` (on `meta` or the story) where a story has `use*` hooks, component or icon references (`icon={Settings}`), or function props with a meaningful body (`render*`, `get*`, function children, multi-statement handlers, helpers) | stories with plain-data props only |
Expand Down
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1795539502000-ui-react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-ui-react': patch
---

feat(Card): add numberOfLines to CardContentTitle and CardContentDescription
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1795539502001-ui-rnative.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-ui-rnative': patch
---

feat(Card): default numberOfLines to 1 on CardContentTitle and CardContentDescription
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1795619083512-ui-react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-ui-react': patch
---

feat(Tile): add numberOfLines to TileTitle and TileDescription
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1795619083513-ui-rnative.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-ui-rnative': patch
---

feat(Tile): honor numberOfLines on TileTitle and TileDescription
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1795619083515-migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-migrations': patch
---

feat(migrations): add card-number-of-lines-undefined
55 changes: 55 additions & 0 deletions apps/app-sandbox-rnative/src/app/(blocks)/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,61 @@ export default function Cards() {
</CardFooter>
</Card>

<Card lx={{ maxWidth: 'full' }} type='info'>
<CardHeader>
<CardLeading>
<Spot icon={Wallet} />
<CardContent>
<CardContentTitle>
A very long card title that is cut after one line (default)
</CardContentTitle>
<CardContentDescription>
A very long card description that is cut after one line
(default), the rest stays hidden
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>

<Card lx={{ maxWidth: 'full' }} type='info'>
<CardHeader>
<CardLeading>
<Spot icon={Wallet} />
<CardContent>
<CardContentTitle numberOfLines={2}>
A very long card title that should be truncated at 2 lines, but
not at 3 lines
</CardContentTitle>
<CardContentDescription numberOfLines={3}>
A very long card description that keeps going well past the
width of the card and should be truncated at 3 lines but should
not be truncated at 2 lines
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>

<Card lx={{ maxWidth: 'full' }} type='info'>
<CardHeader>
<CardLeading>
<Spot icon={Wallet} />
<CardContent>
<CardContentTitle numberOfLines={0}>
A very long card title that does not fit on a single line but it
will never truncate because numberOfLines is set to 0.
</CardContentTitle>
<CardContentDescription numberOfLines={0}>
A very long card description that should keep going well past
the width of the card but it will never truncate because
numberOfLines is set to 0.
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>

<Card
lx={{ width: 's112' }}
onPress={() => {
Expand Down
36 changes: 36 additions & 0 deletions apps/app-sandbox-rnative/src/app/(blocks)/Tiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ export default function Tiles() {
</Tile>
</Box>

<Box lx={{ flexDirection: 'row', gap: 's8', alignItems: 'flex-start' }}>
<Tile lx={{ width: 's112' }} appearance='card'>
<Spot icon={Settings} />
<TileContent>
<TileTitle>Title cut after one line (default)</TileTitle>
<TileDescription>
Description cut after one line (default)
</TileDescription>
</TileContent>
</Tile>
<Tile lx={{ width: 's112' }} appearance='card'>
<Spot icon={Settings} />
<TileContent>
<TileTitle numberOfLines={2}>
Title cut after two lines, but not after three
</TileTitle>
<TileDescription numberOfLines={3}>
Description cut after three lines, but not after two lines, so the
rest stays hidden
</TileDescription>
</TileContent>
</Tile>
<Tile lx={{ width: 's112' }} appearance='card'>
<Spot icon={Settings} />
<TileContent>
<TileTitle numberOfLines={0}>
Title never cut because numberOfLines is 0
</TileTitle>
<TileDescription numberOfLines={0}>
Description never cut because numberOfLines is 0, so the whole
text stays visible
</TileDescription>
</TileContent>
</Tile>
</Box>

<Tile>
<Spot appearance='muted' icon={InformationFill} />
<TileContent>
Expand Down
52 changes: 52 additions & 0 deletions libs/migrations/src/card-number-of-lines-undefined.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
changes:
- change: changed
surface: value
ref: '@ledgerhq/lumen-ui-rnative#CardContent*.numberOfLines=undefined'
signal: silent # undefined used to lift the limit; it now means the default of one line
detect:
- { pattern: '<CardContent(Title|Description)\b[^>]*\bnumberOfLines=\{(?!\s*\d+\s*\})', expect: review }
---

## Before → after

React Native (`@ledgerhq/lumen-ui-rnative`), `undefined` no longer lifts the
limit on `CardContentTitle` and `CardContentDescription`. This covers any value
that can be `undefined`: a conditional, an optional variable, or a prop that a
wrapper component forwards.

```tsx before
<CardContentTitle numberOfLines={contact ? 1 : undefined}>{name}</CardContentTitle>;

// A wrapper that forwards an optional prop: omitting it showed the full text
const AssetName = ({ numberOfLines }: { numberOfLines?: number }) => <CardContentTitle numberOfLines={numberOfLines}>{name}</CardContentTitle>;
```

```tsx after
<CardContentTitle numberOfLines={contact ? 1 : 0}>{name}</CardContentTitle>;

// Default the forwarded prop to 0 to keep the full text when it is omitted
const AssetName = ({ numberOfLines = 0 }: { numberOfLines?: number }) => <CardContentTitle numberOfLines={numberOfLines}>{name}</CardContentTitle>;
```

## Decide

`CardContentTitle` and `CardContentDescription` now default `numberOfLines` to
`1`, and `undefined` gets that default like an omitted prop. Before, an
explicit `undefined` overrode the default and removed the limit. `0` still
means no limit, as in React Native.

- `numberOfLines={undefined}`, or any expression that can be `undefined`, used
to remove the limit: a conditional, an optional variable, or a prop a wrapper
forwards. It now falls back to one line. Default: use `0` where the full text
was shown, and give a forwarded prop a default of `0` (`numberOfLines = 0`).
- An object spread that carries `numberOfLines: undefined`
(`<CardContentTitle {...textProps} />`) has the same effect, and `detect`
can't see it. Check the spreads on these parts.

## Verify

Every `numberOfLines={…}` on a Card part that is not a plain number reviewed:
each one still shows the text as before (the full text where it was not
limited, `0` where it must stay unlimited). Open each screen where these texts
wrapped or were clamped: they look as before.
14 changes: 12 additions & 2 deletions libs/ui-react/src/lib/Components/core/Card/Card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Card is a flexible container component that uses a composite pattern for display
- **CardHeader**: Horizontal layout for the header row. Becomes the click target when `type="expandable"`.
- **CardLeading**: Left section containing visual element and content. Reusable in both header and footer.
- **CardContent**: Column wrapper for title + description.
- **CardContentTitle**: Primary text label with truncation.
- **CardContentDescription**: Secondary muted text with truncation.
- **CardContentTitle**: Primary text label. Truncated by default, see `numberOfLines`.
- **CardContentDescription**: Secondary muted text. Truncated by default, see `numberOfLines`.
- **CardTrailing**: Right section for trailing content (Button, Tag, right-aligned values, etc.).
- **CardFooter**: Footer container. `appearance="plain"` (default) uses a muted background; `appearance="no-background"` blends with the card surface. Collapses with a 300ms transition when `expanded === false`.

Expand Down Expand Up @@ -69,6 +69,16 @@ Cards stack their content horizontally by default. To build a vertical card, wit

<Canvas of={CardStories.WithVerticalLayout} />

## Number of lines

`CardContentTitle` and `CardContentDescription` take a `numberOfLines` prop:

- `1` (default): one line, cut with an ellipsis.
- `2` to `9`: up to that many lines, then cut with an ellipsis.
- `0`: no limit, the text wraps fully.

<Canvas of={CardStories.NumberOfLinesShowcase} />

## Compositions

Cards support various compositions by combining sub-components differently.
Expand Down
76 changes: 76 additions & 0 deletions libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,82 @@ export const LayoutShowcase: Story = {
),
};

export const NumberOfLinesShowcase: Story = {
render: () => (
<div className='flex w-480 flex-col gap-32'>
<Card type='info' className='w-320'>
<CardHeader>
<CardLeading>
<CryptoIcon
ledgerId='bitcoin'
ticker='BTC'
size={48}
alt='Bitcoin'
/>
<CardContent>
<CardContentTitle>
A very long card title that does not fit on a single line
</CardContentTitle>
<CardContentDescription>
A very long card description that keeps going well past the
width of the card
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>

<Card type='info' className='w-320'>
<CardHeader>
<CardLeading>
<CryptoIcon
ledgerId='bitcoin'
ticker='BTC'
size={48}
alt='Bitcoin'
/>
<CardContent>
<CardContentTitle numberOfLines={2}>
A very long card title that should be truncated at 2 lines, but
not at 3 lines
</CardContentTitle>
<CardContentDescription numberOfLines={3}>
A very long card description that keeps going well past the
width of the card and should be truncated at 3 lines but should
not be truncated at 2 lines
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>

<Card type='info' className='w-320'>
<CardHeader>
<CardLeading>
<CryptoIcon
ledgerId='bitcoin'
ticker='BTC'
size={48}
alt='Bitcoin'
/>
<CardContent>
<CardContentTitle numberOfLines={0}>
A very long card title that does not fit on a single line but it
will never truncate because numberOfLines is set to 0.
</CardContentTitle>
<CardContentDescription numberOfLines={0}>
A very long card description that should keep going well past
the width of the card but it will never truncate because
numberOfLines is set to 0.
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>
</div>
),
};

export const CompositionsShowcase: Story = {
args: {
className: 'w-320',
Expand Down
48 changes: 48 additions & 0 deletions libs/ui-react/src/lib/Components/core/Card/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import '@testing-library/jest-dom';

import type { NumberOfLines } from '../../../../utils/getNumberOfLinesClass/getNumberOfLinesClass';
import {
Card,
CardHeader,
Expand Down Expand Up @@ -290,4 +291,51 @@ describe('Card', () => {
expect(ref.current).toBeInstanceOf(HTMLDivElement);
});
});

describe('numberOfLines', () => {
const renderText = (props: { numberOfLines?: NumberOfLines } = {}) =>
render(
<Card type='info'>
<CardHeader>
<CardLeading>
<CardContent>
<CardContentTitle {...props}>Long title</CardContentTitle>
<CardContentDescription {...props}>
Long description
</CardContentDescription>
</CardContent>
</CardLeading>
</CardHeader>
</Card>,
);

it('truncates title and description to one line by default', () => {
renderText();

expect(screen.getByText('Long title')).toHaveClass('truncate');
expect(screen.getByText('Long description')).toHaveClass('truncate');
});

it('clamps title and description to the given number of lines', () => {
renderText({ numberOfLines: 2 });

for (const text of ['Long title', 'Long description']) {
expect(screen.getByText(text)).toHaveClass(
'wrap-anywhere',
'line-clamp-2',
);
expect(screen.getByText(text)).not.toHaveClass('truncate');
}
});

it('removes the limit when numberOfLines is 0', () => {
renderText({ numberOfLines: 0 });

for (const text of ['Long title', 'Long description']) {
expect(screen.getByText(text)).toHaveClass('wrap-anywhere');
expect(screen.getByText(text)).not.toHaveClass('truncate');
expect(screen.getByText(text).className).not.toContain('line-clamp');
}
});
});
});
Loading
Loading