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 = ``