Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .dependency-cruiser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* guards paths inside a lib. Run: `npm run check:layers`.
*
* Layer order inside `src/lib/Components` (a layer may import the ones below):
* visualization, core -> internal -> primitives / animations (RN) / symbols -> utils
* visualization, lottie, core -> internal -> primitives / animations (RN) / symbols -> utils
* `internal` may import `core` only for Spinner and InteractiveIcon.
* Tests, stories, Code Connect and docs are not cruised: they legitimately
* reach across layers (e.g. a `ThemeProvider` wrapper).
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = {
comment:
'symbols, primitives and animations are the lowest component layers.',
from: { path: `${C}/(symbols|primitives|animations)/` },
to: { path: `${C}/(core|internal|visualization)/` },
to: { path: `${C}/(core|internal|visualization|lottie)/` },
},
{
name: 'visualization-subpath-only',
Expand All @@ -43,6 +43,14 @@ module.exports = {
from: { path: UI, pathNot: `${C}/visualization/` },
to: { path: `${C}/visualization/` },
},
{
name: 'lottie-subpath-only',
severity: 'error',
comment:
'lottie is imported only via its own /lottie subpath.',
from: { path: UI, pathNot: `${C}/lottie/` },
to: { path: `${C}/lottie/` },
},
{
name: 'utils-not-to-components',
severity: 'error',
Expand Down
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1794944820231-ui-react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ledgerhq/lumen-ui-react': patch
---

feat(LottieView): add LottieView at the `/lottie` subpath, on an optional dotlottie-react peer
8 changes: 4 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Import rules are enforced in CI at two levels. Don't import across a boundary.
- **Inside `ui-react` / `ui-rnative`** — dependency-cruiser,
`.dependency-cruiser.cjs`, `npm run check:layers`. Under
`src/lib/Components`, a layer imports only the ones below:
`visualization`, `core` → `internal` → `primitives` / `animations` /
`symbols` → `utils`. An `internal` Base never imports the `core` components
built on it (`BASE_FAMILIES` in the config), and `visualization` is reached
only through its own subpath.
`visualization`, `lottie`, `core` → `internal` → `primitives` /
`animations` / `symbols` → `utils`. An `internal` Base never imports the
`core` components built on it (`BASE_FAMILIES` in the config), and
`visualization` and `lottie` are reached only through their own subpaths.

## Internals

Expand Down
4 changes: 3 additions & 1 deletion apps/app-sandbox-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"vite build --config tests/treeShaking/vite.treeshaking.config.ts",
"node tests/treeShaking/verify-bundle.mjs --profile=main --dist=dist",
"vite build --config tests/treeShaking/vite.visualization.config.ts",
"node tests/treeShaking/verify-bundle.mjs --profile=visualization --dist=dist/visualization"
"node tests/treeShaking/verify-bundle.mjs --profile=visualization --dist=dist/visualization",
"vite build --config tests/treeShaking/vite.lottie.config.ts",
"node tests/treeShaking/verify-bundle.mjs --profile=lottie --dist=dist/lottie"
],
"cwd": "apps/app-sandbox-react",
"parallel": false
Expand Down
1 change: 0 additions & 1 deletion apps/app-sandbox-react/tests/treeShaking/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
<script type="module" src="/main.treeshaking.tsx"></script>
</body>
</html>

12 changes: 12 additions & 0 deletions apps/app-sandbox-react/tests/treeShaking/lottie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lottie Subpath Test</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/main.lottie.tsx"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions apps/app-sandbox-react/tests/treeShaking/main.lottie.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ThemeProvider } from '@ledgerhq/lumen-ui-react';
import { LottieView } from '@ledgerhq/lumen-ui-react/lottie';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import '../../src/global.css';

const root = document.getElementById('root');
if (root) {
createRoot(root).render(
<StrictMode>
<ThemeProvider colorScheme='light'>
<LottieView animation='/success.lottie' />
</ThemeProvider>
</StrictMode>,
);
}
18 changes: 18 additions & 0 deletions apps/app-sandbox-react/tests/treeShaking/verify-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const PROFILES = {
{ name: 'visualization components', path: 'Components/visualization/' },
{ name: 'd3 (any package)', path: 'node_modules/d3-' },
{ name: 'internmap (d3-scale dep)', path: 'internmap' },
// LottieView ships at the ./lottie subpath only, with its optional peer.
{ name: 'lottie components', path: 'Components/lottie/' },
{ name: 'dotlottie runtime', path: 'node_modules/@lottiefiles/' },
],
},
visualization: {
Expand All @@ -110,6 +113,21 @@ const PROFILES = {
{ name: 'AddressInput component', path: 'Components/core/AddressInput/' },
],
},
lottie: {
description: 'LottieView, imported from the ./lottie subpath',
required: [
{ name: 'LottieView component', path: 'Components/lottie/LottieView/' },
{
name: 'dotlottie-react',
path: 'node_modules/@lottiefiles/dotlottie-react',
},
],
excluded: [
{ name: 'visualization components', path: 'Components/visualization/' },
{ name: 'Dialog component', path: 'Components/core/Dialog/' },
{ name: 'DataTable component', path: 'Components/core/DataTable/' },
],
},
};

const profile = PROFILES[profileName];
Expand Down
26 changes: 26 additions & 0 deletions apps/app-sandbox-react/tests/treeShaking/vite.lottie.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference types='vitest' />
import { resolve } from 'path';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

export default defineConfig(() => ({
root: resolve(__dirname),
plugins: [react()],
css: {
postcss: resolve(__dirname, '../../postcss.config.js'),
},
build: {
outDir: './dist/lottie',
emptyOutDir: true,
reportCompressedSize: true,
minify: true,
sourcemap: true,
rollupOptions: {
input: resolve(__dirname, 'lottie.html'),
output: {
manualChunks: undefined,
inlineDynamicImports: true,
},
},
},
}));
3 changes: 3 additions & 0 deletions apps/app-sandbox-rnative/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
{
"path": "../../libs/ui-rnative/tsconfig.lib.json"
},
{
"path": "../../libs/symbols/tsconfig.lib.json"
},
{
"path": "../../libs/design-core/tsconfig.lib.json"
}
Expand Down
3 changes: 3 additions & 0 deletions apps/app-sandbox-rnative/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{
"path": "../../libs/ui-rnative"
},
{
"path": "../../libs/symbols"
},
{
"path": "../../libs/design-core"
},
Expand Down
2 changes: 1 addition & 1 deletion libs/symbols/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Import each symbol by its own path. There is deliberately no index re-exporting
import { star } from '@ledgerhq/lumen-symbols/lotties/star';
```

Each animation is a `{ light, dark }` pair of `.lottie` archives, so your bundler must treat `.lottie` as an asset (on Metro, add `lottie` to `resolver.assetExts`) and that rule must also cover `node_modules/@ledgerhq/lumen-symbols`.
Each animation is a `{ light, dark }` pair of `.lottie` archives, so your bundler must treat `.lottie` as an asset (on Metro, add `lottie` to `resolver.assetExts`; on Vite, add `'**/*.lottie'` to `assetsInclude`) and that rule must also cover `node_modules/@ledgerhq/lumen-symbols`.
2 changes: 2 additions & 0 deletions libs/ui-react/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const config: StorybookConfig = {

return mergeConfig(viteConfig, {
plugins: [nxViteTsPaths()],
// `@ledgerhq/lumen-symbols` imports its `.lottie` archives as assets.
assetsInclude: ['**/*.lottie'],
css: {
postcss: {
plugins: [(await import('@tailwindcss/postcss')).default],
Expand Down
1 change: 1 addition & 0 deletions libs/ui-react/ai-rules/RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Import components from `@ledgerhq/lumen-ui-react`
- Import icons from `@ledgerhq/lumen-ui-react/symbols` (not from main package)
- Import charts from `@ledgerhq/lumen-ui-react/visualization` (not from main package)
- Import `LottieView` from `@ledgerhq/lumen-ui-react/lottie` (not from main package); it needs `@lottiefiles/dotlottie-react` installed
- Import design tokens/presets from `@ledgerhq/lumen-design-core`
- Import `cn` from `@ledgerhq/lumen-design-core/cn` (subpath only, not the package root)

Expand Down
18 changes: 16 additions & 2 deletions libs/ui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"types": "./dist/lib/Components/visualization/index.d.ts",
"import": "./dist/lib/Components/visualization/index.js",
"default": "./dist/lib/Components/visualization/index.js"
},
"./lottie": {
"types": "./dist/lib/Components/lottie/index.d.ts",
"import": "./dist/lib/Components/lottie/index.js",
"default": "./dist/lib/Components/lottie/index.js"
}
},
"files": [
Expand All @@ -62,15 +67,24 @@
"d3-scale": "^4.0.2",
"d3-shape": "^3.2.0"
},
"devDependencies": {
"@ledgerhq/lumen-symbols": "0.0.3"
},
"peerDependencies": {
"@base-ui/react": "^1.3.0",
"@ledgerhq/lumen-design-core": "0.1.38",
"@lottiefiles/dotlottie-react": "^0.22.3",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-slot": "^1.2.3",
"@radix-ui/react-tooltip": "^1.2.8",
"class-variance-authority": "^0.7.1",
"@tanstack/react-table": "^8.21.3",
"@ledgerhq/lumen-design-core": "0.1.38",
"class-variance-authority": "^0.7.1",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"@lottiefiles/dotlottie-react": {
"optional": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { success } from '@ledgerhq/lumen-symbols/lotties/success';
import type { LottieViewRef } from '@ledgerhq/lumen-utils-shared';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { useRef, useState } from 'react';
import { Button } from '../../core/Button';
import { LottieView } from './LottieView';

const meta = {
id: 'react-lottieview',
title: 'Core/LottieView',
component: LottieView,
parameters: {
layout: 'centered',
backgrounds: { default: 'light' },
docs: { source: { language: 'tsx', format: true, type: 'code' } },
chromatic: { disableSnapshot: true },
},
} satisfies Meta<typeof LottieView>;

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

export const Base: Story = {
parameters: {
docs: { source: { type: 'dynamic' } },
},
args: {
animation: success,
loop: true,
className: 'size-80',
},
};

export const WithRef: Story = {
render: () => {
const ref = useRef<LottieViewRef>(null);
const [status, setStatus] = useState<'playing' | 'paused' | 'stopped'>(
'playing',
);

const togglePlayback = (): void => {
if (status === 'playing') {
ref.current?.pause();
setStatus('paused');
} else {
// eslint-disable-next-line storybook/context-in-play-function -- LottieViewRef.play, not a story play function
ref.current?.play();
setStatus('playing');
}
};

const stop = (): void => {
ref.current?.stop();
setStatus('stopped');
};

const toggleLabel = {
playing: 'Pause',
paused: 'Resume',
stopped: 'Start',
}[status];

return (
<div className='flex flex-col items-center gap-16'>
<LottieView ref={ref} animation={success} loop className='size-80' />
<div className='flex gap-8'>
<Button size='sm' onClick={togglePlayback}>
{toggleLabel}
</Button>
<Button size='sm' onClick={stop}>
Stop
</Button>
</div>
</div>
);
},
};
Loading
Loading