@dopaminefx/react 0.1.0

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.
@@ -0,0 +1,24 @@
1
+ import { type DopamineMood } from "@dopaminefx/effects";
2
+ export interface DopamineSuccessProps {
3
+ /**
4
+ * Change this value to fire the celebration. The effect plays whenever
5
+ * `trigger` changes to a new value (the initial mount does not fire).
6
+ */
7
+ trigger: unknown;
8
+ mood?: DopamineMood;
9
+ intensity?: number;
10
+ whimsy?: number;
11
+ seed?: number;
12
+ /** Called when the animation finishes. */
13
+ onDone?: () => void;
14
+ }
15
+ /**
16
+ * Declarative success effect. Drops an invisible marker into the layout and
17
+ * anchors the full-page bloom at its center.
18
+ *
19
+ * ```tsx
20
+ * <DopamineSuccess trigger={orderId} mood="celebratory" intensity={0.8} />
21
+ * ```
22
+ */
23
+ export declare function DopamineSuccess({ trigger, mood, intensity, whimsy, seed, onDone, }: DopamineSuccessProps): JSX.Element;
24
+ //# sourceMappingURL=DopamineSuccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DopamineSuccess.d.ts","sourceRoot":"","sources":["../src/DopamineSuccess.tsx"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnE,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,GACP,EAAE,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAsBpC"}
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { celebrate } from "@dopaminefx/effects";
4
+ /**
5
+ * Declarative success effect. Drops an invisible marker into the layout and
6
+ * anchors the full-page bloom at its center.
7
+ *
8
+ * ```tsx
9
+ * <DopamineSuccess trigger={orderId} mood="celebratory" intensity={0.8} />
10
+ * ```
11
+ */
12
+ export function DopamineSuccess({ trigger, mood, intensity, whimsy, seed, onDone, }) {
13
+ const ref = useRef(null);
14
+ const first = useRef(true);
15
+ useEffect(() => {
16
+ if (first.current) {
17
+ first.current = false;
18
+ return;
19
+ }
20
+ const el = ref.current;
21
+ const origin = el
22
+ ? (() => {
23
+ const r = el.getBoundingClientRect();
24
+ return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
25
+ })()
26
+ : undefined;
27
+ void celebrate({ mood, intensity, whimsy, seed, origin }).then(() => onDone?.());
28
+ // Intentionally only re-run when `trigger` changes.
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [trigger]);
31
+ return _jsx("span", { ref: ref, "aria-hidden": true, style: { display: "contents" } });
32
+ }
33
+ //# sourceMappingURL=DopamineSuccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DopamineSuccess.js","sourceRoot":"","sources":["../src/DopamineSuccess.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AAgBnE;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,GACe;IACrB,MAAM,GAAG,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;YACtB,OAAO;QACT,CAAC;QACD,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;QACvB,MAAM,MAAM,GAAG,EAAE;YACf,CAAC,CAAC,CAAC,GAAG,EAAE;gBACJ,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;gBACrC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9D,CAAC,CAAC,EAAE;YACN,CAAC,CAAC,SAAS,CAAC;QACd,KAAK,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjF,oDAAoD;QACpD,uDAAuD;IACzD,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,eAAM,GAAG,EAAE,GAAG,uBAAc,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,GAAI,CAAC;AACxE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { DopamineSuccess, type DopamineSuccessProps } from "./DopamineSuccess.js";
2
+ export { useDopamine } from "./useDopamine.js";
3
+ export type { DopamineMood, DopamineSuccessOptions } from "@dopaminefx/core";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { DopamineSuccess } from "./DopamineSuccess.js";
2
+ export { useDopamine } from "./useDopamine.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA6B,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type DopamineSuccessOptions } from "@dopaminefx/effects";
2
+ /**
3
+ * Returns a stable `celebrate` function for imperative use:
4
+ *
5
+ * ```tsx
6
+ * const celebrate = useDopamine();
7
+ * <button onClick={() => celebrate({ mood: "electric" })}>Done</button>
8
+ * ```
9
+ */
10
+ export declare function useDopamine(): (options?: DopamineSuccessOptions) => Promise<void>;
11
+ //# sourceMappingURL=useDopamine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDopamine.d.ts","sourceRoot":"","sources":["../src/useDopamine.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAEjF"}
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import { celebrate } from "@dopaminefx/effects";
3
+ /**
4
+ * Returns a stable `celebrate` function for imperative use:
5
+ *
6
+ * ```tsx
7
+ * const celebrate = useDopamine();
8
+ * <button onClick={() => celebrate({ mood: "electric" })}>Done</button>
9
+ * ```
10
+ */
11
+ export function useDopamine() {
12
+ return useCallback((options) => celebrate(options), []);
13
+ }
14
+ //# sourceMappingURL=useDopamine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDopamine.js","sourceRoot":"","sources":["../src/useDopamine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,SAAS,EAA+B,MAAM,qBAAqB,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,WAAW,CAAC,CAAC,OAAgC,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACnF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@dopaminefx/react",
3
+ "version": "0.1.0",
4
+ "description": "React bindings for Dopamine visual effects.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json"
21
+ },
22
+ "peerDependencies": {
23
+ "react": ">=18"
24
+ },
25
+ "dependencies": {
26
+ "@dopaminefx/core": "^0.1.0",
27
+ "@dopaminefx/effects": "^0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^18.3.12",
31
+ "react": "^18.3.1"
32
+ },
33
+ "license": "MIT",
34
+ "author": "10in30",
35
+ "homepage": "https://github.com/10in30/dopamine#readme",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/10in30/dopamine.git",
39
+ "directory": "packages/react"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/10in30/dopamine/issues"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }
@@ -0,0 +1,55 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { celebrate, type DopamineMood } from "@dopaminefx/effects";
3
+
4
+ export interface DopamineSuccessProps {
5
+ /**
6
+ * Change this value to fire the celebration. The effect plays whenever
7
+ * `trigger` changes to a new value (the initial mount does not fire).
8
+ */
9
+ trigger: unknown;
10
+ mood?: DopamineMood;
11
+ intensity?: number;
12
+ whimsy?: number;
13
+ seed?: number;
14
+ /** Called when the animation finishes. */
15
+ onDone?: () => void;
16
+ }
17
+
18
+ /**
19
+ * Declarative success effect. Drops an invisible marker into the layout and
20
+ * anchors the full-page bloom at its center.
21
+ *
22
+ * ```tsx
23
+ * <DopamineSuccess trigger={orderId} mood="celebratory" intensity={0.8} />
24
+ * ```
25
+ */
26
+ export function DopamineSuccess({
27
+ trigger,
28
+ mood,
29
+ intensity,
30
+ whimsy,
31
+ seed,
32
+ onDone,
33
+ }: DopamineSuccessProps): JSX.Element {
34
+ const ref = useRef<HTMLSpanElement>(null);
35
+ const first = useRef(true);
36
+
37
+ useEffect(() => {
38
+ if (first.current) {
39
+ first.current = false;
40
+ return;
41
+ }
42
+ const el = ref.current;
43
+ const origin = el
44
+ ? (() => {
45
+ const r = el.getBoundingClientRect();
46
+ return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
47
+ })()
48
+ : undefined;
49
+ void celebrate({ mood, intensity, whimsy, seed, origin }).then(() => onDone?.());
50
+ // Intentionally only re-run when `trigger` changes.
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [trigger]);
53
+
54
+ return <span ref={ref} aria-hidden style={{ display: "contents" }} />;
55
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { DopamineSuccess, type DopamineSuccessProps } from "./DopamineSuccess.js";
2
+ export { useDopamine } from "./useDopamine.js";
3
+ export type { DopamineMood, DopamineSuccessOptions } from "@dopaminefx/core";
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import { celebrate, type DopamineSuccessOptions } from "@dopaminefx/effects";
3
+
4
+ /**
5
+ * Returns a stable `celebrate` function for imperative use:
6
+ *
7
+ * ```tsx
8
+ * const celebrate = useDopamine();
9
+ * <button onClick={() => celebrate({ mood: "electric" })}>Done</button>
10
+ * ```
11
+ */
12
+ export function useDopamine(): (options?: DopamineSuccessOptions) => Promise<void> {
13
+ return useCallback((options?: DopamineSuccessOptions) => celebrate(options), []);
14
+ }