tldraw / tldraw

SDK for creating whiteboards and canvas experiences on the web.
https://tldraw.dev
Other
33.04k stars 1.98k forks source link

[Example Request]: How to change the size of the draw tool in the Custom UI #3694

Closed mochizuki-pg closed 1 week ago

mochizuki-pg commented 2 weeks ago

What's the example?

スクリーンショット 2024-05-03 23 13 07

Custom UI is creating using SDK I need to know how to call the resize button in the Custom UI when the draw tool (pen) is selected

Sorry for the rudimentary question

The image looks like this I want to know which method to call in the SDK

function ExternalToolbar({ currentToolId, editor }: { currentToolId: string | undefined; editor: Editor | null }) {
 const tools = ['select', 'eraser', 'text', 'draw']

 const handleChangePenSize = (size: "s" | "m" | "l" | "xl") => {

   ~~~~~~~~~
  }
};
};
 return (
   <div className="flex items-center">
     {tools.map((toolId) => (
       <button
         key={toolId}
         className={`px-3 py-2 rounded-md ${
           currentToolId === toolId ? 'bg-gray-200' : 'bg-white'
         }`}
         onClick={() => editor?.setCurrentTool(toolId)}
       >
         {toolId}
       </button>
     ))}
     {currentToolId === 'draw' && (
       <div>
         <button onClick={() => handleChangePenSize("s")}>Small</button>
         <button onClick={() => handleChangePenSize("m")}>Medium</button>
         <button onClick={() => handleChangePenSize("l")}>Large</button>
         <button onClick={() => handleChangePenSize("xl")}>Extra Large</button>
       </div>
     )}
     <MakeLiveButton />
   </div>

Code of Conduct

linear[bot] commented 2 weeks ago

TLD-2490 [Example Request]: How to change the size of the draw tool in the Custom UI

steveruizok commented 1 week ago
import { DefaultSizeStyle } from "tldraw"

editor.setStyleForSelectedShapes(DefaultSizeStyle, 's')
editor.setStyleForNextShapes(DefaultSizeStyle, 'm')