From 10c2b69bf303d5ebe2c4ac4ed6f7ff9eb36d7b29 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 18 Oct 2022 10:14:30 +0200 Subject: [PATCH] Implement `useExtensionButton()` --- .../src/shared/utils/useExtensionButton.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/playground/src/shared/utils/useExtensionButton.ts diff --git a/packages/playground/src/shared/utils/useExtensionButton.ts b/packages/playground/src/shared/utils/useExtensionButton.ts new file mode 100644 index 0000000..dbc03fd --- /dev/null +++ b/packages/playground/src/shared/utils/useExtensionButton.ts @@ -0,0 +1,36 @@ +import studio from '@theatre/studio' +import {useEffect, useMemo, useRef} from 'react' + +let idCounter = 0 + +export function useExtensionButton( + title: string, + callback: () => void, + svgSource: string = stepForward, +) { + const refs = useRef({callback, svgSource}) + const id = useMemo(() => 'useExtensionButton#' + idCounter++, []) + useEffect(() => { + studio.extend({ + id: id, + toolbars: { + global(set) { + set([ + { + type: 'Icon', + title, + onClick() { + refs.current.callback() + }, + svgSource: refs.current.svgSource, + }, + ]) + return () => {} + }, + }, + }) + }, [id]) +} + +// FontAwesome FaStepForward +const stepForward = ``