Skip to content

Commit 439f0f6

Browse files
committed
docs: Example live prices animate on transition
1 parent 61fc4f3 commit 439f0f6

File tree

14 files changed

+161
-189
lines changed

14 files changed

+161
-189
lines changed

docs/core/shared/_useLive.mdx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import HooksPlayground from '@site/src/components/HooksPlayground';
22

3-
<HooksPlayground row>
3+
<HooksPlayground row defaultTab={props.defaultTab}>
44

55
```typescript title="Ticker" {32} collapsed
66
import { Entity, RestEndpoint } from '@data-client/rest';
@@ -47,7 +47,10 @@ function AssetPrice({ productId }: Props) {
4747
return (
4848
<center>
4949
{productId}{' '}
50-
<Formatted value={ticker.price} formatter="currency" />
50+
<NumberFlow
51+
value={ticker.price}
52+
format={{ style: 'currency', currency: 'USD' }}
53+
/>
5154
</center>
5255
);
5356
}

docs/rest/guides/network-transform.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ function AssetPrice({ productId }: Props) {
249249
return (
250250
<center>
251251
{productId}{' '}
252-
<Formatted value={ticker.price} formatter="currency" />
252+
<NumberFlow
253+
value={ticker.price}
254+
format={{ style: 'currency', currency: 'USD' }}
255+
/>
253256
</center>
254257
);
255258
}

examples/nextjs/components/AssetPrice.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
'use client';
22
import { useLive } from '@data-client/react';
3+
import NumberFlow from '@number-flow/react';
34

45
import { getTicker } from '@/resources/Ticker';
56

6-
import { Formatted } from './Formatted';
7-
87
export default function AssetPrice({ symbol }: Props) {
98
const product_id = `${symbol}-USD`;
109
// Learn more about Reactive Data Client: https://dataclient.io/docs
1110
const ticker = useLive(getTicker, { product_id });
1211
return (
1312
<span>
14-
{symbol} <Formatted value={ticker.price} formatter="currency" />
13+
{symbol}{' '}
14+
<NumberFlow
15+
value={ticker.price}
16+
format={{ style: 'currency', currency: 'USD' }}
17+
/>
1518
</span>
1619
);
1720
}

examples/nextjs/components/Formatted.tsx

-133
This file was deleted.

examples/nextjs/components/formatters/index.ts

-44
This file was deleted.

examples/nextjs/package-lock.json

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nextjs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@babel/core": "^7.24.7",
1515
"@data-client/react": "^0.14.0",
1616
"@data-client/rest": "^0.14.0",
17+
"@number-flow/react": "^0.2.1",
1718
"@types/node": "22.7.7",
1819
"@types/react": "npm:types-react@rc",
1920
"@types/react-dom": "npm:types-react-dom@rc",

website/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@docusaurus/theme-mermaid": "^3.0.1",
4747
"@js-temporal/polyfill": "^0.4.4",
4848
"@monaco-editor/react": "^4.4.6",
49+
"@number-flow/react": "^0.2.1",
4950
"bignumber.js": "9.1.2",
5051
"clsx": "2.1.1",
5152
"monaco-editor": "^0.52.0",

website/src/components/Demo/code/live-app/polling/AssetPrice.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export default function AssetPrice({ symbol }: { symbol: string }) {
77
<tr>
88
<th>{symbol}</th>
99
<td>
10-
<Formatted value={ticker.price} formatter="currency" />
10+
<NumberFlow
11+
value={ticker.price}
12+
format={{ style: 'currency', currency: 'USD' }}
13+
/>
1114
</td>
1215
</tr>
1316
);

website/src/components/Playground/DesignSystem/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { TextInput } from './TextInput';
77
export { TextArea } from './TextArea';
88
export { SearchIcon } from './SearchIcon';
99
export { Loading } from './Loading';
10+
export { default as NumberFlow } from '@number-flow/react';

website/src/components/Playground/PreviewWithScope.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as rest from '@data-client/rest';
55
import type { Fixture, Interceptor } from '@data-client/test';
66
import { Temporal, Intl as PolyIntl } from '@js-temporal/polyfill';
77
import BigNumber from 'bignumber.js';
8-
import React from 'react';
98
import { LiveProvider } from 'react-live';
109
import { v4 as uuid } from 'uuid';
1110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { NumberFlowLite, Value, Format } from 'number-flow';
2+
import * as React from 'react';
3+
export { Format, Trend, Value } from 'number-flow';
4+
5+
declare const OBSERVED_ATTRIBUTES: readonly ['parts'];
6+
type ObservedAttribute = (typeof OBSERVED_ATTRIBUTES)[number];
7+
declare class NumberFlowElement extends NumberFlowLite {
8+
static observedAttributes: readonly ['parts'];
9+
attributeChangedCallback(
10+
attr: ObservedAttribute,
11+
_oldValue: string,
12+
newValue: string,
13+
): void;
14+
}
15+
type NumberFlowProps = React.HTMLAttributes<NumberFlowElement> & {
16+
value: Value;
17+
locales?: Intl.LocalesArgument;
18+
format?: Format;
19+
isolate?: boolean;
20+
animated?: boolean;
21+
respectMotionPreference?: boolean;
22+
willChange?: boolean;
23+
onAnimationsStart?: () => void;
24+
onAnimationsFinish?: () => void;
25+
trend?: (typeof NumberFlowElement)['prototype']['trend'];
26+
opacityTiming?: (typeof NumberFlowElement)['prototype']['opacityTiming'];
27+
transformTiming?: (typeof NumberFlowElement)['prototype']['transformTiming'];
28+
spinTiming?: (typeof NumberFlowElement)['prototype']['spinTiming'];
29+
};
30+
declare const NumberFlow: (
31+
options: React.HTMLAttributes<NumberFlowElement> & {
32+
value: Value;
33+
locales?: Intl.LocalesArgument;
34+
format?: Format;
35+
isolate?: boolean;
36+
animated?: boolean;
37+
respectMotionPreference?: boolean;
38+
willChange?: boolean;
39+
onAnimationsStart?: () => void;
40+
onAnimationsFinish?: () => void;
41+
trend?: (typeof NumberFlowElement)['prototype']['trend'];
42+
opacityTiming?: (typeof NumberFlowElement)['prototype']['opacityTiming'];
43+
transformTiming?: (typeof NumberFlowElement)['prototype']['transformTiming'];
44+
spinTiming?: (typeof NumberFlowElement)['prototype']['spinTiming'];
45+
} & React.RefAttributes<NumberFlowElement>,
46+
) => JSX.Element;
47+
48+
declare function useCanAnimate({
49+
respectMotionPreference,
50+
}?: {
51+
respectMotionPreference?: boolean | undefined;
52+
}): boolean;
53+
54+
export {
55+
NumberFlowElement,
56+
type NumberFlowProps,
57+
NumberFlow as default,
58+
useCanAnimate,
59+
};

0 commit comments

Comments
 (0)