From 29101618a050d60bedcbb4527ce473c712d80568 Mon Sep 17 00:00:00 2001 From: aammami-ledger Date: Wed, 25 Nov 2026 11:15:07 +0100 Subject: [PATCH 1/7] feat(Card): add truncate prop to CardContentTitle and CardContentDescription Co-Authored-By: Claude Sonnet 5.5 --- .../version-plan-1795539502000-ui-react.md | 5 ++ .../version-plan-1795539502001-ui-rnative.md | 5 ++ .../src/lib/Components/core/Card/Card.mdx | 10 +++- .../lib/Components/core/Card/Card.stories.tsx | 53 +++++++++++++++++++ .../lib/Components/core/Card/Card.test.tsx | 40 ++++++++++++++ .../src/lib/Components/core/Card/Card.tsx | 8 ++- .../src/lib/Components/core/Card/types.ts | 12 +++++ .../src/lib/Components/core/Card/Card.mdx | 10 +++- .../lib/Components/core/Card/Card.stories.tsx | 52 ++++++++++++++++++ .../lib/Components/core/Card/Card.test.tsx | 46 ++++++++++++++++ .../src/lib/Components/core/Card/Card.tsx | 10 ++-- .../src/lib/Components/core/Card/types.ts | 12 +++++ 12 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 .nx/version-plans/version-plan-1795539502000-ui-react.md create mode 100644 .nx/version-plans/version-plan-1795539502001-ui-rnative.md diff --git a/.nx/version-plans/version-plan-1795539502000-ui-react.md b/.nx/version-plans/version-plan-1795539502000-ui-react.md new file mode 100644 index 000000000..e61cc9222 --- /dev/null +++ b/.nx/version-plans/version-plan-1795539502000-ui-react.md @@ -0,0 +1,5 @@ +--- +'@ledgerhq/lumen-ui-react': patch +--- + +feat(Card): add truncate prop to CardContentTitle and CardContentDescription diff --git a/.nx/version-plans/version-plan-1795539502001-ui-rnative.md b/.nx/version-plans/version-plan-1795539502001-ui-rnative.md new file mode 100644 index 000000000..f9925e49d --- /dev/null +++ b/.nx/version-plans/version-plan-1795539502001-ui-rnative.md @@ -0,0 +1,5 @@ +--- +'@ledgerhq/lumen-ui-rnative': patch +--- + +feat(Card): add truncate prop to CardContentTitle and CardContentDescription diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.mdx b/libs/ui-react/src/lib/Components/core/Card/Card.mdx index dd912b88f..4cb28abca 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.mdx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.mdx @@ -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 `truncate`. +- **CardContentDescription**: Secondary muted text. Truncated by default, see `truncate`. - **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`. @@ -69,6 +69,12 @@ Cards stack their content horizontally by default. To build a vertical card, wit +## Truncation + +`CardContentTitle` and `CardContentDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. + + + ## Compositions Cards support various compositions by combining sub-components differently. diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx index 19cce712a..823979ded 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx @@ -542,6 +542,59 @@ export const LayoutShowcase: Story = { ), }; +export const TruncationShowcase: Story = { + args: { + type: 'info', + }, + render: (args) => ( +
+ + + + + + + A very long card title that does not fit on a single line + + + A very long card description that keeps going well past the + width of the card + + + + + + + + + + + + + A very long card title that does not fit on a single line + + + A very long card description that keeps going well past the + width of the card + + + + + +
+ ), +}; + export const CompositionsShowcase: Story = { args: { className: 'w-320', diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx index 06a4ba061..2c118856b 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx @@ -290,4 +290,44 @@ describe('Card', () => { expect(ref.current).toBeInstanceOf(HTMLDivElement); }); }); + + describe('truncate', () => { + const renderText = (props: { truncate?: boolean } = {}) => + render( + + + + + Long title + + Long description + + + + + , + ); + + it('truncates title and description by default', () => { + renderText(); + + expect(screen.getByText('Long title')).toHaveClass('truncate'); + expect(screen.getByText('Long description')).toHaveClass('truncate'); + }); + + it('wraps title and description when truncate is false', () => { + renderText({ truncate: false }); + + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text)).not.toHaveClass('truncate'); + expect(screen.getByText(text)).toHaveClass('wrap-break-word'); + } + }); + + it('does not forward truncate to the DOM', () => { + renderText({ truncate: false }); + + expect(screen.getByText('Long title')).not.toHaveAttribute('truncate'); + }); + }); }); diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.tsx index 8c1a6ed3b..9ec9dde6f 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.tsx @@ -304,6 +304,7 @@ export const CardContentTitle = ({ ref, children, className, + truncate = true, ...props }: CardContentTitleProps) => { const { disabled } = useCardContext({ @@ -315,7 +316,8 @@ export const CardContentTitle = ({
{ const { disabled } = useCardContext({ @@ -344,7 +347,8 @@ export const CardContentDescription = ({
+## Truncation + +`CardContentTitle` and `CardContentDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. + + + ## Compositions Cards support various compositions by combining sub-components differently. diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx index e76d5ab8f..c1668d677 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx @@ -485,6 +485,58 @@ export const LayoutShowcase: Story = { ), }; +export const TruncationShowcase: Story = { + parameters: { docs: { source: { type: 'dynamic' } } }, + args: { + type: 'info', + children: null, + }, + render: (args) => ( + + + + + + + + A very long card title that does not fit on a single line + + + A very long card description that keeps going well past the + width of the card + + + + + + + + + + + + + A very long card title that does not fit on a single line + + + A very long card description that keeps going well past the + width of the card + + + + + + + ), +}; + export const CompositionsShowcase: Story = { args: { children: null, diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx index 490548d0b..fbc587005 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx @@ -223,4 +223,50 @@ describe('Card', () => { expect(screen.getByText('BTC')).toBeTruthy(); }); }); + + describe('truncate', () => { + const renderText = ( + props: { truncate?: boolean; numberOfLines?: number } = {}, + ) => + render( + + + + + + Long title + + Long description + + + + + + , + ); + + it('truncates title and description to one line by default', () => { + renderText(); + + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text).props.numberOfLines).toBe(1); + expect(screen.getByText(text).props.ellipsizeMode).toBe('tail'); + } + }); + + it('does not clamp title and description when truncate is false', () => { + renderText({ truncate: false }); + + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text).props.numberOfLines).toBeUndefined(); + expect(screen.getByText(text).props.ellipsizeMode).toBeUndefined(); + } + }); + + it('lets an explicit numberOfLines win over truncate', () => { + renderText({ numberOfLines: 2 }); + + expect(screen.getByText('Long title').props.numberOfLines).toBe(2); + }); + }); }); diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx index 2194a05fd..0e13c0339 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx @@ -467,6 +467,7 @@ export const CardContentTitle = ({ children, lx = {}, style, + truncate = true, ...props }: CardContentTitleProps & { ref?: Ref }) => { const { disabled } = useCardContext({ @@ -505,8 +506,8 @@ export const CardContentTitle = ({ ref={ref as Ref>} lx={lx} style={StyleSheet.flatten([styles.asText, style])} - numberOfLines={1} - ellipsizeMode='tail' + numberOfLines={truncate ? 1 : undefined} + ellipsizeMode={truncate ? 'tail' : undefined} {...props} > {children} @@ -534,6 +535,7 @@ export const CardContentDescription = ({ children, lx = {}, style, + truncate = true, ...props }: CardContentDescriptionProps & { ref?: Ref }) => { const { disabled } = useCardContext({ @@ -572,8 +574,8 @@ export const CardContentDescription = ({ ref={ref as Ref>} lx={lx} style={StyleSheet.flatten([styles.asText, style])} - numberOfLines={1} - ellipsizeMode='tail' + numberOfLines={truncate ? 1 : undefined} + ellipsizeMode={truncate ? 'tail' : undefined} {...props} > {children} diff --git a/libs/ui-rnative/src/lib/Components/core/Card/types.ts b/libs/ui-rnative/src/lib/Components/core/Card/types.ts index 10cef6840..48d6d9c9d 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/types.ts +++ b/libs/ui-rnative/src/lib/Components/core/Card/types.ts @@ -79,6 +79,12 @@ export type CardContentTitleProps = { * The title text or custom inline content. */ children: ReactNode; + /** + * Whether the text is clamped to a single line with an ellipsis. + * When `false`, the text wraps. Only applies to text children. + * @default true + */ + truncate?: boolean; } & Omit; export type CardContentDescriptionProps = { @@ -86,6 +92,12 @@ export type CardContentDescriptionProps = { * The description text or custom inline content. */ children: ReactNode; + /** + * Whether the text is clamped to a single line with an ellipsis. + * When `false`, the text wraps. Only applies to text children. + * @default true + */ + truncate?: boolean; } & Omit; export type CardContentRowProps = { From d2641fcceb8b22882a845434976d707f9fb4f5c2 Mon Sep 17 00:00:00 2001 From: aammami-ledger Date: Wed, 25 Nov 2026 12:01:55 +0100 Subject: [PATCH 2/7] fix(Card): let unbroken text shrink when truncate is off Add min-w-0 to the non-truncated title and description so long unbroken values wrap inside CardContentRow instead of pushing siblings out of the card, and use a dynamic docs source for the web TruncationShowcase story. Co-Authored-By: Claude Sonnet 5.5 --- libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx | 1 + libs/ui-react/src/lib/Components/core/Card/Card.test.tsx | 5 ++++- libs/ui-react/src/lib/Components/core/Card/Card.tsx | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx index 823979ded..816dee6ff 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx @@ -543,6 +543,7 @@ export const LayoutShowcase: Story = { }; export const TruncationShowcase: Story = { + parameters: { docs: { source: { type: 'dynamic' } } }, args: { type: 'info', }, diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx index 2c118856b..41fcc6f51 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx @@ -320,7 +320,10 @@ describe('Card', () => { for (const text of ['Long title', 'Long description']) { expect(screen.getByText(text)).not.toHaveClass('truncate'); - expect(screen.getByText(text)).toHaveClass('wrap-break-word'); + expect(screen.getByText(text)).toHaveClass( + 'min-w-0', + 'wrap-break-word', + ); } }); diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.tsx index 9ec9dde6f..faa4f3847 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.tsx @@ -317,7 +317,7 @@ export const CardContentTitle = ({ ref={ref} className={cn( 'body-2-semi-bold', - truncate ? 'truncate' : 'wrap-break-word', + truncate ? 'truncate' : 'min-w-0 wrap-break-word', disabled && 'text-disabled', className, )} @@ -348,7 +348,7 @@ export const CardContentDescription = ({ ref={ref} className={cn( 'body-3', - truncate ? 'truncate' : 'wrap-break-word', + truncate ? 'truncate' : 'min-w-0 wrap-break-word', disabled ? 'text-disabled' : 'text-muted', className, )} From 8f10e128183cae10b37e557d5cddf0a0d2e5f48d Mon Sep 17 00:00:00 2001 From: aammami-ledger Date: Wed, 25 Nov 2026 12:01:55 +0100 Subject: [PATCH 3/7] chore(skills): allow TruncationShowcase alongside ResponsivenessShowcase for stories Co-Authored-By: Claude Sonnet 5.5 --- .claude/skills/component-stories/SKILL.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.claude/skills/component-stories/SKILL.md b/.claude/skills/component-stories/SKILL.md index 1eb04b380..681400a98 100644 --- a/.claude/skills/component-stories/SKILL.md +++ b/.claude/skills/component-stories/SKILL.md @@ -164,9 +164,10 @@ 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 `TruncationShowcase` for how text is clamped or wraps (e.g. a `truncate` or `numberOfLines` prop). - Do not use: `TruncateShowcase`, `Truncation`, `LongLabel` ## Comments @@ -187,7 +188,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={}` / `args: { data: }` 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 | From de8e4558b120cd923a850a4f3d340ce690024544 Mon Sep 17 00:00:00 2001 From: aammami-ledger Date: Wed, 25 Nov 2026 16:14:31 +0100 Subject: [PATCH 4/7] feat(Tile): add truncate prop to TileTitle and TileDescription Co-Authored-By: Claude Sonnet 5.5 --- .../version-plan-1795619083512-ui-react.md | 5 +++ .../version-plan-1795619083513-ui-rnative.md | 5 +++ .../src/lib/Components/core/Tile/Tile.mdx | 6 ++++ .../lib/Components/core/Tile/Tile.stories.tsx | 31 +++++++++++++++++ .../lib/Components/core/Tile/Tile.test.tsx | 29 ++++++++++++++++ .../src/lib/Components/core/Tile/Tile.tsx | 12 ++++--- .../src/lib/Components/core/Tile/types.ts | 12 +++++++ .../src/lib/Components/core/Tile/Tile.mdx | 6 ++++ .../lib/Components/core/Tile/Tile.stories.tsx | 34 +++++++++++++++++++ .../lib/Components/core/Tile/Tile.test.tsx | 31 +++++++++++++++++ .../src/lib/Components/core/Tile/Tile.tsx | 16 ++++++--- .../src/lib/Components/core/Tile/types.ts | 12 +++++++ 12 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 .nx/version-plans/version-plan-1795619083512-ui-react.md create mode 100644 .nx/version-plans/version-plan-1795619083513-ui-rnative.md diff --git a/.nx/version-plans/version-plan-1795619083512-ui-react.md b/.nx/version-plans/version-plan-1795619083512-ui-react.md new file mode 100644 index 000000000..0aa03a94a --- /dev/null +++ b/.nx/version-plans/version-plan-1795619083512-ui-react.md @@ -0,0 +1,5 @@ +--- +'@ledgerhq/lumen-ui-react': patch +--- + +feat(Tile): add truncate prop to TileTitle and TileDescription diff --git a/.nx/version-plans/version-plan-1795619083513-ui-rnative.md b/.nx/version-plans/version-plan-1795619083513-ui-rnative.md new file mode 100644 index 000000000..4178ada1a --- /dev/null +++ b/.nx/version-plans/version-plan-1795619083513-ui-rnative.md @@ -0,0 +1,5 @@ +--- +'@ledgerhq/lumen-ui-rnative': patch +--- + +feat(Tile): add truncate prop to TileTitle and TileDescription diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.mdx b/libs/ui-react/src/lib/Components/core/Tile/Tile.mdx index b75956e14..1fceaab4d 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.mdx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.mdx @@ -69,6 +69,12 @@ By default the tile fills the width of its container. The title and description +### Truncation + +`TileTitle` and `TileDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. The tile grows taller. + + + ### Centered Content Use the `centered` prop to vertically center tile content. This is useful when a tile has less content than its neighbors, like a "Show more" tile in a grid. diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx index ca24c3ca0..21ff54e7f 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx @@ -205,6 +205,37 @@ export const ResponsiveLayout: Story = { ), }; +export const TruncationShowcase: Story = { + render: () => ( +
+ + + + + A very long tile title that does not fit on one line + + + A very long tile description that keeps going well past the width of + the tile + + + + + + + + A very long tile title that does not fit on one line + + + A very long tile description that keeps going well past the width of + the tile + + + +
+ ), +}; + export const AppearanceShowcase: Story = { render: () => (
diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx index 8c84ce299..97285f067 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx @@ -334,4 +334,33 @@ describe('Tile Component', () => { expect(screen.getByText('Second')).toBeInTheDocument(); }); }); + + describe('truncate', () => { + const renderText = (props: { truncate?: boolean } = {}) => + render( + + + + Long title + Long description + + , + ); + + it('truncates title and description by default', () => { + renderText(); + + expect(screen.getByText('Long title')).toHaveClass('truncate'); + expect(screen.getByText('Long description')).toHaveClass('truncate'); + }); + + it('wraps title and description when truncate is false', () => { + renderText({ truncate: false }); + + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text)).not.toHaveClass('truncate'); + expect(screen.getByText(text)).toHaveClass('wrap-break-word'); + } + }); + }); }); diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx index a380c7edf..03d018f4b 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx @@ -140,11 +140,12 @@ export const TileContent = ({ /** * The primary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width. + * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. */ export const TileTitle = ({ children, className, + truncate = true, ...props }: TileTitleProps) => { const disabled = useDisabledContext({ @@ -154,7 +155,8 @@ export const TileTitle = ({ return (
{ const disabled = useDisabledContext({ @@ -181,7 +184,8 @@ export const TileDescription = ({ return (
+### Truncation + +`TileTitle` and `TileDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. The tile grows taller. + + + ### Centered Content Use the `centered` prop to vertically center tile content. This is useful when a tile has less content than its neighbors, like a "Show more" tile in a grid. diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx index 55600a418..d5a07e8f5 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx @@ -221,6 +221,40 @@ export const ResponsiveLayout: Story = { ), }; +export const TruncationShowcase: Story = { + args: { + children: null, + }, + render: () => ( + + + + + + A very long tile title that does not fit on one line + + + A very long tile description that keeps going well past the width of + the tile + + + + + + + + A very long tile title that does not fit on one line + + + A very long tile description that keeps going well past the width of + the tile + + + + + ), +}; + export const AppearanceShowcase: Story = { args: { children: null, diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx index 8c5379bfd..cc86c9e8c 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx @@ -224,4 +224,35 @@ describe('Tile Component', () => { expect(getByText(tagText)).toBeTruthy(); }); }); + + describe('truncate', () => { + const renderText = (props: { truncate?: boolean } = {}) => + render( + + + + + Long title + Long description + + + , + ); + + it('truncates title and description to one line by default', () => { + const { getByTestId } = renderText(); + + expect(getByTestId('tile-title').props.numberOfLines).toBe(1); + expect(getByTestId('tile-description').props.numberOfLines).toBe(1); + }); + + it('does not clamp title and description when truncate is false', () => { + const { getByTestId } = renderText({ truncate: false }); + + expect(getByTestId('tile-title').props.numberOfLines).toBeUndefined(); + expect( + getByTestId('tile-description').props.numberOfLines, + ).toBeUndefined(); + }); + }); }); diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx index 87d888946..042b10056 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx @@ -230,10 +230,15 @@ const useTitleStyles = ({ disabled }: { disabled: boolean }) => { /** * The primary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width. + * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. * If children is a string, it will be automatically wrapped in a Text component. */ -export const TileTitle = ({ children, lx, style }: TileTitleProps) => { +export const TileTitle = ({ + children, + lx, + style, + truncate = true, +}: TileTitleProps) => { const disabled = useDisabledContext({ consumerName: 'TileTitle', contextRequired: true, @@ -244,7 +249,7 @@ export const TileTitle = ({ children, lx, style }: TileTitleProps) => { return ( @@ -287,7 +292,7 @@ const useDescriptionStyles = ({ disabled }: { disabled: boolean }) => { /** * The secondary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width. + * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. * If children is a string, it will be automatically wrapped in a Text component. * * @example @@ -302,6 +307,7 @@ export const TileDescription = ({ children, lx, style, + truncate = true, }: TileDescriptionProps) => { const disabled = useDisabledContext({ consumerName: 'TileDescription', @@ -313,7 +319,7 @@ export const TileDescription = ({ return ( diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/types.ts b/libs/ui-rnative/src/lib/Components/core/Tile/types.ts index 176cbf106..f3b2a8da5 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/types.ts +++ b/libs/ui-rnative/src/lib/Components/core/Tile/types.ts @@ -57,6 +57,12 @@ export type TileTitleProps = { * The title text to display. */ children: ReactNode; + /** + * Whether the text is clamped to a single line with an ellipsis. + * When `false`, the text wraps and the tile grows taller. Only applies to text children. + * @default true + */ + truncate?: boolean; } & StyledTextProps; export type TileDescriptionProps = { @@ -64,6 +70,12 @@ export type TileDescriptionProps = { * The description text to display. */ children: ReactNode; + /** + * Whether the text is clamped to a single line with an ellipsis. + * When `false`, the text wraps and the tile grows taller. Only applies to text children. + * @default true + */ + truncate?: boolean; } & StyledTextProps; export type TileTrailingContentProps = { From af0c1e9432c7785262d25bc9e014d04857b35343 Mon Sep 17 00:00:00 2001 From: aammami-ledger Date: Thu, 26 Nov 2026 11:25:06 +0100 Subject: [PATCH 5/7] fix(Card,Tile): use wrap-anywhere when truncate is off wrap-break-word keeps the longest unbroken word as the minimum width, so a Tile used as a flex or grid item could still overflow. wrap-anywhere lets the text shrink and wrap, and Card now matches Tile. Co-Authored-By: Claude Sonnet 5.5 --- .../src/lib/Components/core/Card/Card.test.tsx | 11 +---------- libs/ui-react/src/lib/Components/core/Card/Card.tsx | 4 ++-- .../src/lib/Components/core/Tile/Tile.test.tsx | 2 +- libs/ui-react/src/lib/Components/core/Tile/Tile.tsx | 4 ++-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx index 41fcc6f51..4a1d13e3a 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx @@ -320,17 +320,8 @@ describe('Card', () => { for (const text of ['Long title', 'Long description']) { expect(screen.getByText(text)).not.toHaveClass('truncate'); - expect(screen.getByText(text)).toHaveClass( - 'min-w-0', - 'wrap-break-word', - ); + expect(screen.getByText(text)).toHaveClass('wrap-anywhere'); } }); - - it('does not forward truncate to the DOM', () => { - renderText({ truncate: false }); - - expect(screen.getByText('Long title')).not.toHaveAttribute('truncate'); - }); }); }); diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.tsx index faa4f3847..0e3de0ced 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.tsx @@ -317,7 +317,7 @@ export const CardContentTitle = ({ ref={ref} className={cn( 'body-2-semi-bold', - truncate ? 'truncate' : 'min-w-0 wrap-break-word', + truncate ? 'truncate' : 'wrap-anywhere', disabled && 'text-disabled', className, )} @@ -348,7 +348,7 @@ export const CardContentDescription = ({ ref={ref} className={cn( 'body-3', - truncate ? 'truncate' : 'min-w-0 wrap-break-word', + truncate ? 'truncate' : 'wrap-anywhere', disabled ? 'text-disabled' : 'text-muted', className, )} diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx index 97285f067..e71707923 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx @@ -359,7 +359,7 @@ describe('Tile Component', () => { for (const text of ['Long title', 'Long description']) { expect(screen.getByText(text)).not.toHaveClass('truncate'); - expect(screen.getByText(text)).toHaveClass('wrap-break-word'); + expect(screen.getByText(text)).toHaveClass('wrap-anywhere'); } }); }); diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx index 03d018f4b..b658994c1 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx @@ -156,7 +156,7 @@ export const TileTitle = ({
Date: Fri, 27 Nov 2026 11:08:24 +0100 Subject: [PATCH 6/7] fix(Card): show truncate in the TruncationShowcase source The dynamic source mode dropped truncate={false} from the snippet. Write the props inline and use the default code source, like the Tile story. Co-Authored-By: Claude Sonnet 5.5 --- .../src/lib/Components/core/Card/Card.stories.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx index 816dee6ff..985455124 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx @@ -543,13 +543,9 @@ export const LayoutShowcase: Story = { }; export const TruncationShowcase: Story = { - parameters: { docs: { source: { type: 'dynamic' } } }, - args: { - type: 'info', - }, - render: (args) => ( + render: () => (
- + - + Date: Mon, 30 Nov 2026 17:11:10 +0100 Subject: [PATCH 7/7] feat(Card,Tile): replace truncate with numberOfLines CardContentTitle, CardContentDescription, TileTitle and TileDescription take the same numberOfLines API on web and React Native: 1 by default, 2 or more to clamp (web: 2 to 9), and 0 for no limit, like React Native. An explicit numberOfLines={undefined} now falls back to the default of one line on React Native Card parts instead of removing the limit. A migration covers it. Co-Authored-By: Claude Sonnet 5.5 --- .claude/skills/component-stories/SKILL.md | 3 +- .../version-plan-1795539502000-ui-react.md | 2 +- .../version-plan-1795539502001-ui-rnative.md | 2 +- .../version-plan-1795619083512-ui-react.md | 2 +- .../version-plan-1795619083513-ui-rnative.md | 2 +- .../version-plan-1795619083515-migrations.md | 5 ++ .../src/app/(blocks)/Cards.tsx | 55 +++++++++++++++++++ .../src/app/(blocks)/Tiles.tsx | 36 ++++++++++++ .../src/card-number-of-lines-undefined.md | 52 ++++++++++++++++++ .../src/lib/Components/core/Card/Card.mdx | 14 +++-- .../lib/Components/core/Card/Card.stories.tsx | 36 ++++++++++-- .../lib/Components/core/Card/Card.test.tsx | 24 ++++++-- .../src/lib/Components/core/Card/Card.tsx | 9 +-- .../src/lib/Components/core/Card/types.ts | 17 +++--- .../src/lib/Components/core/Tile/Tile.mdx | 10 +++- .../lib/Components/core/Tile/Tile.stories.tsx | 32 ++++++++--- .../lib/Components/core/Tile/Tile.test.tsx | 24 ++++++-- .../src/lib/Components/core/Tile/Tile.tsx | 19 ++++--- .../src/lib/Components/core/Tile/types.ts | 17 +++--- .../getNumberOfLinesClass.test.ts | 18 ++++++ .../getNumberOfLinesClass.ts | 24 ++++++++ .../src/lib/Components/core/Card/Card.mdx | 14 +++-- .../lib/Components/core/Card/Card.stories.tsx | 31 +++++++++-- .../lib/Components/core/Card/Card.test.tsx | 30 ++++++---- .../src/lib/Components/core/Card/Card.tsx | 12 ++-- .../src/lib/Components/core/Card/types.ts | 16 +++--- .../src/lib/Components/core/Tile/Tile.mdx | 10 +++- .../lib/Components/core/Tile/Tile.stories.tsx | 32 ++++++++--- .../lib/Components/core/Tile/Tile.test.tsx | 28 +++++++--- .../src/lib/Components/core/Tile/Tile.tsx | 12 ++-- .../src/lib/Components/core/Tile/types.ts | 18 +++--- 31 files changed, 472 insertions(+), 134 deletions(-) create mode 100644 .nx/version-plans/version-plan-1795619083515-migrations.md create mode 100644 libs/migrations/src/card-number-of-lines-undefined.md create mode 100644 libs/ui-react/src/utils/getNumberOfLinesClass/getNumberOfLinesClass.test.ts create mode 100644 libs/ui-react/src/utils/getNumberOfLinesClass/getNumberOfLinesClass.ts diff --git a/.claude/skills/component-stories/SKILL.md b/.claude/skills/component-stories/SKILL.md index 681400a98..14ba7db6b 100644 --- a/.claude/skills/component-stories/SKILL.md +++ b/.claude/skills/component-stories/SKILL.md @@ -167,7 +167,8 @@ Stories highlighting specific features. Stories that demonstrate how a component truncates text or adapts to constrained space. - Use `ResponsivenessShowcase` for how the component adapts to constrained space or width. -- Use `TruncationShowcase` for how text is clamped or wraps (e.g. a `truncate` or `numberOfLines` prop). +- 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 diff --git a/.nx/version-plans/version-plan-1795539502000-ui-react.md b/.nx/version-plans/version-plan-1795539502000-ui-react.md index e61cc9222..19e41b484 100644 --- a/.nx/version-plans/version-plan-1795539502000-ui-react.md +++ b/.nx/version-plans/version-plan-1795539502000-ui-react.md @@ -2,4 +2,4 @@ '@ledgerhq/lumen-ui-react': patch --- -feat(Card): add truncate prop to CardContentTitle and CardContentDescription +feat(Card): add numberOfLines to CardContentTitle and CardContentDescription diff --git a/.nx/version-plans/version-plan-1795539502001-ui-rnative.md b/.nx/version-plans/version-plan-1795539502001-ui-rnative.md index f9925e49d..bce91f468 100644 --- a/.nx/version-plans/version-plan-1795539502001-ui-rnative.md +++ b/.nx/version-plans/version-plan-1795539502001-ui-rnative.md @@ -2,4 +2,4 @@ '@ledgerhq/lumen-ui-rnative': patch --- -feat(Card): add truncate prop to CardContentTitle and CardContentDescription +feat(Card): default numberOfLines to 1 on CardContentTitle and CardContentDescription diff --git a/.nx/version-plans/version-plan-1795619083512-ui-react.md b/.nx/version-plans/version-plan-1795619083512-ui-react.md index 0aa03a94a..f6a88fee9 100644 --- a/.nx/version-plans/version-plan-1795619083512-ui-react.md +++ b/.nx/version-plans/version-plan-1795619083512-ui-react.md @@ -2,4 +2,4 @@ '@ledgerhq/lumen-ui-react': patch --- -feat(Tile): add truncate prop to TileTitle and TileDescription +feat(Tile): add numberOfLines to TileTitle and TileDescription diff --git a/.nx/version-plans/version-plan-1795619083513-ui-rnative.md b/.nx/version-plans/version-plan-1795619083513-ui-rnative.md index 4178ada1a..a4f01047e 100644 --- a/.nx/version-plans/version-plan-1795619083513-ui-rnative.md +++ b/.nx/version-plans/version-plan-1795619083513-ui-rnative.md @@ -2,4 +2,4 @@ '@ledgerhq/lumen-ui-rnative': patch --- -feat(Tile): add truncate prop to TileTitle and TileDescription +feat(Tile): honor numberOfLines on TileTitle and TileDescription diff --git a/.nx/version-plans/version-plan-1795619083515-migrations.md b/.nx/version-plans/version-plan-1795619083515-migrations.md new file mode 100644 index 000000000..82d48d923 --- /dev/null +++ b/.nx/version-plans/version-plan-1795619083515-migrations.md @@ -0,0 +1,5 @@ +--- +'@ledgerhq/lumen-migrations': patch +--- + +feat(migrations): add card-number-of-lines-undefined diff --git a/apps/app-sandbox-rnative/src/app/(blocks)/Cards.tsx b/apps/app-sandbox-rnative/src/app/(blocks)/Cards.tsx index 1c75ca9b7..515ffd144 100644 --- a/apps/app-sandbox-rnative/src/app/(blocks)/Cards.tsx +++ b/apps/app-sandbox-rnative/src/app/(blocks)/Cards.tsx @@ -316,6 +316,61 @@ export default function Cards() { + + + + + + + A very long card title that is cut after one line (default) + + + A very long card description that is cut after one line + (default), the rest stays hidden + + + + + + + + + + + + + A very long card title that should be truncated at 2 lines, but + not at 3 lines + + + 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 + + + + + + + + + + + + + A very long card title that does not fit on a single line but it + will never truncate because numberOfLines is set to 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. + + + + + + { diff --git a/apps/app-sandbox-rnative/src/app/(blocks)/Tiles.tsx b/apps/app-sandbox-rnative/src/app/(blocks)/Tiles.tsx index 374975903..152efff5d 100644 --- a/apps/app-sandbox-rnative/src/app/(blocks)/Tiles.tsx +++ b/apps/app-sandbox-rnative/src/app/(blocks)/Tiles.tsx @@ -46,6 +46,42 @@ export default function Tiles() { + + + + + Title cut after one line (default) + + Description cut after one line (default) + + + + + + + + Title cut after two lines, but not after three + + + Description cut after three lines, but not after two lines, so the + rest stays hidden + + + + + + + + Title never cut because numberOfLines is 0 + + + Description never cut because numberOfLines is 0, so the whole + text stays visible + + + + + diff --git a/libs/migrations/src/card-number-of-lines-undefined.md b/libs/migrations/src/card-number-of-lines-undefined.md new file mode 100644 index 000000000..db291addc --- /dev/null +++ b/libs/migrations/src/card-number-of-lines-undefined.md @@ -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: ']*\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 +{name}; + +// A wrapper that forwards an optional prop: omitting it showed the full text +const AssetName = ({ numberOfLines }: { numberOfLines?: number }) => {name}; +``` + +```tsx after +{name}; + +// Default the forwarded prop to 0 to keep the full text when it is omitted +const AssetName = ({ numberOfLines = 0 }: { numberOfLines?: number }) => {name}; +``` + +## 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` + (``) 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. diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.mdx b/libs/ui-react/src/lib/Components/core/Card/Card.mdx index 4cb28abca..07d660efe 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.mdx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.mdx @@ -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. Truncated by default, see `truncate`. -- **CardContentDescription**: Secondary muted text. Truncated by default, see `truncate`. +- **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`. @@ -69,11 +69,15 @@ Cards stack their content horizontally by default. To build a vertical card, wit -## Truncation +## Number of lines -`CardContentTitle` and `CardContentDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. +`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. + + ## Compositions diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx index 985455124..6247c5304 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.stories.tsx @@ -542,7 +542,7 @@ export const LayoutShowcase: Story = { ), }; -export const TruncationShowcase: Story = { +export const NumberOfLinesShowcase: Story = { render: () => (
@@ -577,12 +577,38 @@ export const TruncationShowcase: Story = { alt='Bitcoin' /> - - A very long card title that does not fit on a single line + + A very long card title that should be truncated at 2 lines, but + not at 3 lines - + A very long card description that keeps going well past the - width of the card + width of the card and should be truncated at 3 lines but should + not be truncated at 2 lines + + + + + + + + + + + + + A very long card title that does not fit on a single line but it + will never truncate because numberOfLines is set to 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. diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx index 4a1d13e3a..108b1a5d1 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.test.tsx @@ -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, @@ -291,8 +292,8 @@ describe('Card', () => { }); }); - describe('truncate', () => { - const renderText = (props: { truncate?: boolean } = {}) => + describe('numberOfLines', () => { + const renderText = (props: { numberOfLines?: NumberOfLines } = {}) => render( @@ -308,19 +309,32 @@ describe('Card', () => { , ); - it('truncates title and description by default', () => { + 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('wraps title and description when truncate is false', () => { - renderText({ truncate: false }); + 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'); } }); }); diff --git a/libs/ui-react/src/lib/Components/core/Card/Card.tsx b/libs/ui-react/src/lib/Components/core/Card/Card.tsx index 0e3de0ced..8b5d2be6f 100644 --- a/libs/ui-react/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-react/src/lib/Components/core/Card/Card.tsx @@ -6,6 +6,7 @@ import { } from '@ledgerhq/lumen-utils-shared'; import { cva } from 'class-variance-authority'; import { useMemo } from 'react'; +import { getNumberOfLinesClass } from '../../../../utils/getNumberOfLinesClass/getNumberOfLinesClass'; import { ChevronDown, ChevronUp } from '../../symbols'; import type { CardContentAlignContextValue, @@ -304,7 +305,7 @@ export const CardContentTitle = ({ ref, children, className, - truncate = true, + numberOfLines = 1, ...props }: CardContentTitleProps) => { const { disabled } = useCardContext({ @@ -316,8 +317,8 @@ export const CardContentTitle = ({
{ const { disabled } = useCardContext({ @@ -347,8 +348,8 @@ export const CardContentDescription = ({
-### Truncation +### Number of lines -`TileTitle` and `TileDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. The tile grows taller. +`TileTitle` and `TileDescription` 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. + + ### Centered Content diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx index 21ff54e7f..16fa1a99f 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.stories.tsx @@ -205,30 +205,44 @@ export const ResponsiveLayout: Story = { ), }; -export const TruncationShowcase: Story = { +export const NumberOfLinesShowcase: Story = { render: () => (
- A very long tile title that does not fit on one line + A very long tile title that is cut after one line - A very long tile description that keeps going well past the width of - the tile + A very long tile description that is cut after one line, the rest + stays hidden - - A very long tile title that does not fit on one line + + A very long tile title that is cut after two lines, but not after + three lines - - A very long tile description that keeps going well past the width of - the tile + + A very long tile description that is cut after three lines, but not + after two lines, so the rest of this text stays hidden + + + + + + + + A very long tile title that is never cut because numberOfLines is + set to 0 + + + A very long tile description that is never cut because numberOfLines + is set to 0, so the whole text stays visible diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx index e71707923..a9137362f 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.test.tsx @@ -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 { Settings, MoreVertical } from '../../symbols'; import { Spot } from '../Spot'; import { Tag } from '../Tag'; @@ -335,8 +336,8 @@ describe('Tile Component', () => { }); }); - describe('truncate', () => { - const renderText = (props: { truncate?: boolean } = {}) => + describe('numberOfLines', () => { + const renderText = (props: { numberOfLines?: NumberOfLines } = {}) => render( @@ -347,19 +348,32 @@ describe('Tile Component', () => { , ); - it('truncates title and description by default', () => { + 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('wraps title and description when truncate is false', () => { - renderText({ truncate: false }); + it('clamps title and description to the given number of lines', () => { + renderText({ numberOfLines: 3 }); for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text)).toHaveClass( + 'wrap-anywhere', + 'line-clamp-3', + ); 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'); } }); }); diff --git a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx index b658994c1..bdc50da06 100644 --- a/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx +++ b/libs/ui-react/src/lib/Components/core/Tile/Tile.tsx @@ -5,6 +5,7 @@ import { } from '@ledgerhq/lumen-utils-shared'; import { cva } from 'class-variance-authority'; import { useCallback } from 'react'; +import { getNumberOfLinesClass } from '../../../../utils/getNumberOfLinesClass/getNumberOfLinesClass'; import { InteractiveIcon } from '../InteractiveIcon'; import type { TileContentProps, @@ -140,12 +141,12 @@ export const TileContent = ({ /** * The primary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. + * Text will truncate with ellipsis if it exceeds the available width, unless `numberOfLines` is raised. */ export const TileTitle = ({ children, className, - truncate = true, + numberOfLines = 1, ...props }: TileTitleProps) => { const disabled = useDisabledContext({ @@ -155,8 +156,9 @@ export const TileTitle = ({ return (
{ const disabled = useDisabledContext({ @@ -184,8 +186,9 @@ export const TileDescription = ({ return (
{ + it('truncates on a single line', () => { + expect(getNumberOfLinesClass(1)).toBe('truncate'); + }); + + it('wraps without a limit for 0', () => { + expect(getNumberOfLinesClass(0)).toBe('wrap-anywhere'); + }); + + it.each([2, 3, 4, 5, 6, 7, 8, 9] as const)('clamps to %i lines', (lines) => { + expect(getNumberOfLinesClass(lines)).toBe( + `wrap-anywhere line-clamp-${lines}`, + ); + }); +}); diff --git a/libs/ui-react/src/utils/getNumberOfLinesClass/getNumberOfLinesClass.ts b/libs/ui-react/src/utils/getNumberOfLinesClass/getNumberOfLinesClass.ts new file mode 100644 index 000000000..c8bb57d19 --- /dev/null +++ b/libs/ui-react/src/utils/getNumberOfLinesClass/getNumberOfLinesClass.ts @@ -0,0 +1,24 @@ +export type NumberOfLines = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; + +// Tailwind only generates classes it can read literally, so no string building. +const LINE_CLAMP_CLASSES = { + 2: 'wrap-anywhere line-clamp-2', + 3: 'wrap-anywhere line-clamp-3', + 4: 'wrap-anywhere line-clamp-4', + 5: 'wrap-anywhere line-clamp-5', + 6: 'wrap-anywhere line-clamp-6', + 7: 'wrap-anywhere line-clamp-7', + 8: 'wrap-anywhere line-clamp-8', + 9: 'wrap-anywhere line-clamp-9', +} as const; + +/** + * Classes that limit a block of text to `numberOfLines`. A single line uses + * `truncate` so unbroken text stays on one line, and `0` removes the limit, + * like React Native. + */ +export const getNumberOfLinesClass = (numberOfLines: NumberOfLines): string => { + if (numberOfLines === 1) return 'truncate'; + if (numberOfLines === 0) return 'wrap-anywhere'; + return LINE_CLAMP_CLASSES[numberOfLines]; +}; diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.mdx b/libs/ui-rnative/src/lib/Components/core/Card/Card.mdx index a55494517..6f6d62405 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.mdx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.mdx @@ -40,8 +40,8 @@ Card is a flexible container component that uses a composite pattern for display - **CardLeading**: Left section containing visual element and content. Reusable in both header and footer. - **CardContent**: Column wrapper for title + description. Supports right alignment when inside `CardTrailing`. - **CardContentRow**: Horizontal row for placing title/description alongside additional inline content (e.g. Tag). -- **CardContentTitle**: Primary text label. Truncated to a single line by default, see `truncate`. -- **CardContentDescription**: Secondary muted text. Truncated to a single line by default, see `truncate`. +- **CardContentTitle**: Primary text label. Truncated to a single line by default, see `numberOfLines`. +- **CardContentDescription**: Secondary muted text. Truncated to a single line 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 animation when `expanded === false`. - **CardFooterActions**: Horizontal row for action buttons. @@ -93,11 +93,15 @@ Cards stack their content horizontally by default. To build a vertical card, wit -## Truncation +## Number of lines -`CardContentTitle` and `CardContentDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. +`CardContentTitle` and `CardContentDescription` take a `numberOfLines` prop: - +- `1` (default): one line, cut with an ellipsis. +- `2` or more: up to that many lines, then cut with an ellipsis. +- `0`: no limit, the text wraps fully. + + ## Compositions diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx index c1668d677..dd32b3995 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.stories.tsx @@ -485,7 +485,7 @@ export const LayoutShowcase: Story = { ), }; -export const TruncationShowcase: Story = { +export const NumberOfLinesShowcase: Story = { parameters: { docs: { source: { type: 'dynamic' } } }, args: { type: 'info', @@ -522,12 +522,33 @@ export const TruncationShowcase: Story = { - - A very long card title that does not fit on a single line + + A very long card title that should be truncated at 2 lines, but + not at 3 lines - + A very long card description that keeps going well past the - width of the card + width of the card and should be truncated at 3 lines but should + not be truncated at 2 lines + + + + + + + + + + + + + A very long card title that does not fit on a single line but it + will never truncate because numberOfLines is set to 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. diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx index fbc587005..7dd369338 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.test.tsx @@ -224,10 +224,8 @@ describe('Card', () => { }); }); - describe('truncate', () => { - const renderText = ( - props: { truncate?: boolean; numberOfLines?: number } = {}, - ) => + describe('numberOfLines', () => { + const renderText = (props: { numberOfLines?: number } = {}) => render( @@ -254,19 +252,29 @@ describe('Card', () => { } }); - it('does not clamp title and description when truncate is false', () => { - renderText({ truncate: false }); + 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).props.numberOfLines).toBeUndefined(); - expect(screen.getByText(text).props.ellipsizeMode).toBeUndefined(); + expect(screen.getByText(text).props.numberOfLines).toBe(2); + expect(screen.getByText(text).props.ellipsizeMode).toBe('tail'); } }); - it('lets an explicit numberOfLines win over truncate', () => { - renderText({ numberOfLines: 2 }); + it('falls back to one line when numberOfLines is undefined', () => { + renderText({ numberOfLines: undefined }); - expect(screen.getByText('Long title').props.numberOfLines).toBe(2); + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text).props.numberOfLines).toBe(1); + } + }); + + it('removes the limit when numberOfLines is 0', () => { + renderText({ numberOfLines: 0 }); + + for (const text of ['Long title', 'Long description']) { + expect(screen.getByText(text).props.numberOfLines).toBe(0); + } }); }); }); diff --git a/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx b/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx index 0e13c0339..780019eea 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Card/Card.tsx @@ -467,7 +467,7 @@ export const CardContentTitle = ({ children, lx = {}, style, - truncate = true, + numberOfLines = 1, ...props }: CardContentTitleProps & { ref?: Ref }) => { const { disabled } = useCardContext({ @@ -506,8 +506,8 @@ export const CardContentTitle = ({ ref={ref as Ref>} lx={lx} style={StyleSheet.flatten([styles.asText, style])} - numberOfLines={truncate ? 1 : undefined} - ellipsizeMode={truncate ? 'tail' : undefined} + numberOfLines={numberOfLines} + ellipsizeMode='tail' {...props} > {children} @@ -535,7 +535,7 @@ export const CardContentDescription = ({ children, lx = {}, style, - truncate = true, + numberOfLines = 1, ...props }: CardContentDescriptionProps & { ref?: Ref }) => { const { disabled } = useCardContext({ @@ -574,8 +574,8 @@ export const CardContentDescription = ({ ref={ref as Ref>} lx={lx} style={StyleSheet.flatten([styles.asText, style])} - numberOfLines={truncate ? 1 : undefined} - ellipsizeMode={truncate ? 'tail' : undefined} + numberOfLines={numberOfLines} + ellipsizeMode='tail' {...props} > {children} diff --git a/libs/ui-rnative/src/lib/Components/core/Card/types.ts b/libs/ui-rnative/src/lib/Components/core/Card/types.ts index 48d6d9c9d..fdae0ea5f 100644 --- a/libs/ui-rnative/src/lib/Components/core/Card/types.ts +++ b/libs/ui-rnative/src/lib/Components/core/Card/types.ts @@ -80,11 +80,11 @@ export type CardContentTitleProps = { */ children: ReactNode; /** - * Whether the text is clamped to a single line with an ellipsis. - * When `false`, the text wraps. Only applies to text children. - * @default true + * Maximum number of lines before the text is cut with an ellipsis. + * `0` means no limit: the text wraps fully. Only applies to text children. + * @default 1 */ - truncate?: boolean; + numberOfLines?: number; } & Omit; export type CardContentDescriptionProps = { @@ -93,11 +93,11 @@ export type CardContentDescriptionProps = { */ children: ReactNode; /** - * Whether the text is clamped to a single line with an ellipsis. - * When `false`, the text wraps. Only applies to text children. - * @default true + * Maximum number of lines before the text is cut with an ellipsis. + * `0` means no limit: the text wraps fully. Only applies to text children. + * @default 1 */ - truncate?: boolean; + numberOfLines?: number; } & Omit; export type CardContentRowProps = { diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.mdx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.mdx index 2df11c95d..02c833117 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.mdx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.mdx @@ -72,11 +72,15 @@ By default the tile fills the width of its container. The title and description -### Truncation +### Number of lines -`TileTitle` and `TileDescription` clamp to a single line with an ellipsis by default. Set `truncate={false}` to let the text wrap instead. The tile grows taller. +`TileTitle` and `TileDescription` take a `numberOfLines` prop: - +- `1` (default): one line, cut with an ellipsis. +- `2` or more: up to that many lines, then cut with an ellipsis. +- `0`: no limit, the text wraps fully. + + ### Centered Content diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx index d5a07e8f5..ede055c49 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.stories.tsx @@ -221,7 +221,7 @@ export const ResponsiveLayout: Story = { ), }; -export const TruncationShowcase: Story = { +export const NumberOfLinesShowcase: Story = { args: { children: null, }, @@ -231,23 +231,37 @@ export const TruncationShowcase: Story = { - A very long tile title that does not fit on one line + A very long tile title that is cut after one line - A very long tile description that keeps going well past the width of - the tile + A very long tile description that is cut after one line, the rest + stays hidden - - A very long tile title that does not fit on one line + + A very long tile title that is cut after two lines, but not after + three lines - - A very long tile description that keeps going well past the width of - the tile + + A very long tile description that is cut after three lines, but not + after two lines, so the rest of this text stays hidden + + + + + + + + A very long tile title that is never cut because numberOfLines is + set to 0 + + + A very long tile description that is never cut because numberOfLines + is set to 0, so the whole text stays visible diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx index cc86c9e8c..5d1382c8b 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.test.tsx @@ -225,8 +225,8 @@ describe('Tile Component', () => { }); }); - describe('truncate', () => { - const renderText = (props: { truncate?: boolean } = {}) => + describe('numberOfLines', () => { + const renderText = (props: { numberOfLines?: number } = {}) => render( @@ -246,13 +246,25 @@ describe('Tile Component', () => { expect(getByTestId('tile-description').props.numberOfLines).toBe(1); }); - it('does not clamp title and description when truncate is false', () => { - const { getByTestId } = renderText({ truncate: false }); + it('clamps title and description to the given number of lines', () => { + const { getByTestId } = renderText({ numberOfLines: 3 }); - expect(getByTestId('tile-title').props.numberOfLines).toBeUndefined(); - expect( - getByTestId('tile-description').props.numberOfLines, - ).toBeUndefined(); + expect(getByTestId('tile-title').props.numberOfLines).toBe(3); + expect(getByTestId('tile-description').props.numberOfLines).toBe(3); + }); + + it('falls back to one line when numberOfLines is undefined', () => { + const { getByTestId } = renderText({ numberOfLines: undefined }); + + expect(getByTestId('tile-title').props.numberOfLines).toBe(1); + expect(getByTestId('tile-description').props.numberOfLines).toBe(1); + }); + + it('removes the limit when numberOfLines is 0', () => { + const { getByTestId } = renderText({ numberOfLines: 0 }); + + expect(getByTestId('tile-title').props.numberOfLines).toBe(0); + expect(getByTestId('tile-description').props.numberOfLines).toBe(0); }); }); }); diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx index 042b10056..a1f40d3d0 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx +++ b/libs/ui-rnative/src/lib/Components/core/Tile/Tile.tsx @@ -230,14 +230,14 @@ const useTitleStyles = ({ disabled }: { disabled: boolean }) => { /** * The primary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. + * Text will truncate with ellipsis if it exceeds the available width, unless `numberOfLines` is changed. * If children is a string, it will be automatically wrapped in a Text component. */ export const TileTitle = ({ children, lx, style, - truncate = true, + numberOfLines = 1, }: TileTitleProps) => { const disabled = useDisabledContext({ consumerName: 'TileTitle', @@ -249,7 +249,7 @@ export const TileTitle = ({ return ( @@ -292,7 +292,7 @@ const useDescriptionStyles = ({ disabled }: { disabled: boolean }) => { /** * The secondary text label for a Tile. Automatically inherits the disabled state from the parent Tile. - * Text will truncate with ellipsis if it exceeds the available width, unless `truncate` is `false`. + * Text will truncate with ellipsis if it exceeds the available width, unless `numberOfLines` is changed. * If children is a string, it will be automatically wrapped in a Text component. * * @example @@ -307,7 +307,7 @@ export const TileDescription = ({ children, lx, style, - truncate = true, + numberOfLines = 1, }: TileDescriptionProps) => { const disabled = useDisabledContext({ consumerName: 'TileDescription', @@ -319,7 +319,7 @@ export const TileDescription = ({ return ( diff --git a/libs/ui-rnative/src/lib/Components/core/Tile/types.ts b/libs/ui-rnative/src/lib/Components/core/Tile/types.ts index f3b2a8da5..10ccd1d7a 100644 --- a/libs/ui-rnative/src/lib/Components/core/Tile/types.ts +++ b/libs/ui-rnative/src/lib/Components/core/Tile/types.ts @@ -58,11 +58,12 @@ export type TileTitleProps = { */ children: ReactNode; /** - * Whether the text is clamped to a single line with an ellipsis. - * When `false`, the text wraps and the tile grows taller. Only applies to text children. - * @default true + * Maximum number of lines before the text is cut with an ellipsis. + * `0` or an explicit `undefined` means no limit: the text wraps fully. + * Only applies to text children. + * @default 1 */ - truncate?: boolean; + numberOfLines?: number; } & StyledTextProps; export type TileDescriptionProps = { @@ -71,11 +72,12 @@ export type TileDescriptionProps = { */ children: ReactNode; /** - * Whether the text is clamped to a single line with an ellipsis. - * When `false`, the text wraps and the tile grows taller. Only applies to text children. - * @default true + * Maximum number of lines before the text is cut with an ellipsis. + * `0` or an explicit `undefined` means no limit: the text wraps fully. + * Only applies to text children. + * @default 1 */ - truncate?: boolean; + numberOfLines?: number; } & StyledTextProps; export type TileTrailingContentProps = {