Skip to content

Commit

Permalink
add Smart Picker button to Tool Bar
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Aug 8, 2024
1 parent 089a605 commit d874915
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { Icon } from '@mdi/react'
import { mdiShape } from '@mdi/js'

import { createRoot } from 'react-dom'
import {
Excalidraw,
MainMenu,
Expand Down Expand Up @@ -76,6 +76,16 @@ export default function App({ fileId, isEmbedded, fileName }: WhiteboardAppProps

if (excalidrawAPI && !collab) setCollab(new Collab(excalidrawAPI, fileId))
if (collab && !collab.portal.socket) collab.startCollab()
useEffect(() => {
const extraTools = document.getElementsByClassName('App-toolbar__extra-tools-trigger')[0]
const smartPick = document.createElement('label')
smartPick.classList.add(...['ToolIcon', 'Shape'])
if (extraTools) {
extraTools.parentNode?.insertBefore(smartPick, extraTools.nextElementSibling)
const root = createRoot(smartPick)
root.render(renderSmartPicker())
}
})

useEffect(() => {
return () => {
Expand Down Expand Up @@ -166,19 +176,11 @@ export default function App({ fileId, isEmbedded, fileName }: WhiteboardAppProps
)
}

const renderTopRightUI = () => {
const renderSmartPicker = () => {
return (
<label title='filepicker'>
<input className="ToolIcon_type_checkbox" type="checkbox" aria-label="Library" aria-keyshortcuts="0" onClick={pickFile}/>
<div className="sidebar-trigger default-sidebar-trigger">
<div>
<Icon path={mdiShape} size={1} />
</div>
<div className='sidegbar-trigger__label'>
Smart Picker
</div>
</div>
</label>
<button className="dropdown-menu-button App-toolbar__extra-tools-trigger" aria-label="Library" aria-keyshortcuts="0" onClick={pickFile} title='Smart Picker'>
<Icon path={mdiShape} size={1} />
</button>
)
}

Expand All @@ -187,7 +189,6 @@ export default function App({ fileId, isEmbedded, fileName }: WhiteboardAppProps
<div className="excalidraw-wrapper">
<Excalidraw
validateEmbeddable={() => true}
renderTopRightUI={renderTopRightUI}
renderEmbeddable={ Embeddable }
excalidrawAPI={(api: ExcalidrawImperativeAPI) => {
console.log(api)
Expand Down

0 comments on commit d874915

Please sign in to comment.