@lightfin/react 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +84 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @lightfin/react
2
+
3
+ React bindings for
4
+ [@lightfin/core](https://github.com/lightfin-io/lightfin-mono/tree/main/packages/core):
5
+ `<LightfinChart>` owns the
6
+ chart's lifecycle, `useChartEffect` wires features onto it imperatively, and
7
+ `useChart` reads the instance from context. A thin wrapper — the chart engine
8
+ itself is framework-agnostic vanilla TypeScript.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ bun add @lightfin/react @lightfin/core
14
+ ```
15
+
16
+ `@lightfin/core` and `react` (>=18) are peer dependencies.
17
+
18
+ ## Quick start
19
+
20
+ ```tsx
21
+ import type { Bar } from '@lightfin/core'
22
+ import { LightfinChart, useChartEffect } from '@lightfin/react'
23
+
24
+ function Candles({ bars }: { bars: Bar[] }) {
25
+ useChartEffect(
26
+ chart => {
27
+ chart.addCandlestickSeries().setData(bars)
28
+ },
29
+ [bars],
30
+ )
31
+ return null
32
+ }
33
+
34
+ function App({ bars }: { bars: Bar[] }) {
35
+ return (
36
+ <LightfinChart style={{ height: 420 }}>
37
+ <Candles bars={bars} />
38
+ </LightfinChart>
39
+ )
40
+ }
41
+ ```
42
+
43
+ `<LightfinChart>` creates the chart on mount and removes it on unmount. Give
44
+ it a size via `className`/`style` on the outer container. Everything else —
45
+ series, indicators, chrome, annotations, price lines — is wired on
46
+ imperatively by child components using `useChartEffect`, the same escape
47
+ hatch the core API uses directly.
48
+
49
+ ## API
50
+
51
+ - **`<LightfinChart>`** — `options` (applied once; give the component a new
52
+ `key` to recreate it with different options), `instrument`, event props
53
+ (`onCrosshairMove`, `onDataChange`, `onSeriesChange`, `onIndicatorsChange`,
54
+ `onLayoutChange`, `onInstrumentChange`, `onOrderIntent`), `onCreate`, and a
55
+ `ref` to the underlying `Chart`.
56
+ - **`useChartEffect(effect, deps)`** — runs `effect(chart)` once the chart
57
+ exists and on every `deps` change, cleaning up the returned function on
58
+ rerun/unmount. The general-purpose hook for anything imperative:
59
+ `chart.addCandlestickSeries()`, `chart.addIndicator(...)`,
60
+ `createChrome(chart, ...)`, `createAnnotations(chart, ...)`,
61
+ `chart.addPriceLine(...)`.
62
+ - **`useChart()`** — the `Chart` instance from the nearest `<LightfinChart>`,
63
+ or `null` until it's created (one frame after mount). Throws outside a
64
+ `<LightfinChart>`.
65
+
66
+ ## Order intent
67
+
68
+ Pass `onOrderIntent` to opt in to the chart's "+" button; it only shows while
69
+ the handler is set. The host owns the order form — the callback just receives
70
+ price and coordinates.
71
+
72
+ ## Development
73
+
74
+ From the monorepo root (see the
75
+ [root README](https://github.com/lightfin-io/lightfin-mono/)):
76
+
77
+ ```sh
78
+ bun run --filter @lightfin/react test
79
+ bun run --filter @lightfin/react build
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@lightfin/react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "React bindings for @lightfin/core: <LightfinChart> plus hooks.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "homepage": "https://lightfin.io",
7
8
  "publishConfig": {
8
9
  "access": "public"
9
10
  },