cabbage-react 1.0.0-beta.26 → 1.0.0-beta.27

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 +87 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,19 +1,100 @@
1
1
  # Cabbage-React
2
2
 
3
- This project provides hooks that allow you to synchronize [Cabbage](https://cabbageaudio.com) with [React](https://github.com/facebook/react).
3
+ Cabbage-React provides React hooks for synchronizing [Cabbage](https://cabbageaudio.com) with [React](https://github.com/facebook/react), making it easier to build UI components that communicate with the Cabbage host.
4
4
 
5
- An example of implementation can be found [here](https://github.com/hdale94/cabbage-react-example).
5
+ ## Example Project
6
6
 
7
- ## Install
7
+ An example of implementation is available [here](https://github.com/hdale94/cabbage-react-example).
8
+
9
+ ## Installation
8
10
 
9
11
  yarn add cabbage-react
12
+ # or
13
+ npm install cabbage-react
10
14
 
11
15
  ## Hooks
12
16
 
13
17
  ### useCabbageState
14
18
 
15
- Sync a parameter with Cabbage. This hook listens for updates to a parameter value from Cabbage and sends updates to Cabbage when the parameter value changes locally (e.g., through a UI slider).
19
+ Synchronize a parameter with Cabbage. This hook:
20
+
21
+ - Listens for value updates from Cabbage.
22
+ - Sends local changes (e.g., via sliders, knobs) back to Cabbage.
23
+
24
+ ### useCabbageProperties
25
+
26
+ Get properties for a parameter from Cabbage.
27
+ This hook:
28
+
29
+ - Listens for property updates from Cabbage.
30
+ - Updates local state automatically when data changes.
31
+
32
+ ## Usage
33
+
34
+ ```
35
+ import { InputHTMLAttributes } from "react";
36
+ import { useCabbageProperties, useCabbageState } from "cabbage-react";
37
+
38
+ const HorizontalSlider = ({
39
+ channel,
40
+ paramIdx,
41
+ inputProps,
42
+ }: {
43
+ channel: string;
44
+ paramIdx: number;
45
+ inputProps?: InputHTMLAttributes<HTMLInputElement>;
46
+ }) => {
47
+ const { properties } = useCabbageProperties(channel);
48
+ const { value, setValue } = useCabbageState<number>(channel, paramIdx);
49
+
50
+ return (
51
+ <div>
52
+ <input
53
+ type="range"
54
+ min={properties?.range?.min ?? 0}
55
+ max={properties?.range?.max ?? 1}
56
+ step={properties?.range?.increment ?? 0.01}
57
+ value={value}
58
+ onChange={(e) => setValue(e.target.valueAsNumber)}
59
+ {...inputProps}
60
+ style={{
61
+ accentColor: "rgb(147,210,0)",
62
+ ...inputProps?.style,
63
+ }}
64
+ />
65
+
66
+ {/* Displaying the value */}
67
+ <p style={{ margin: 0 }}>{value ?? 0}</p>
68
+ </div>
69
+ );
70
+ };
71
+
72
+ export default HorizontalSlider;
73
+ ```
74
+
75
+ ## Interact directly with Cabbage
76
+
77
+ You can also import the [Cabbage class](https://github.com/hdale94/cabbage-react/blob/main/src/cabbage/cabbage.js) to send custom messages or interact directly with Cabbage.
78
+
79
+ ## Notify Cabbage When UI Is Ready
80
+
81
+ To let Cabbage know your UI is ready to receive data, send a `cabbageIsReadyToLoad` message when your app initializes.
82
+
83
+ Place this call before rendering your app — typically in your main.tsx or index.tsx file:
84
+
85
+ ```
86
+ import { StrictMode } from "react";
87
+ import { createRoot } from "react-dom/client";
88
+ import "./index.css";
89
+ import App from "./App.tsx";
90
+ import { Cabbage } from "cabbage-react";
16
91
 
17
- ### useGetCabbageFormData
92
+ // Notify Cabbage that the UI is ready to receive data
93
+ Cabbage.sendCustomCommand("cabbageIsReadyToLoad");
18
94
 
19
- Get form data from Cabbage. This hook listens for updates to form data via Cabbage and updates the local state whenever new data is received.
95
+ createRoot(document.getElementById("root")!).render(
96
+ <StrictMode>
97
+ <App />
98
+ </StrictMode>
99
+ );
100
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.0-beta.26",
3
+ "version": "1.0.0-beta.27",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",