StatusBar.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable @typescript-eslint/no-non-null-assertion */
  2. /* eslint-disable @typescript-eslint/no-explicit-any */
  3. import * as React from 'react'
  4. import { observer } from 'mobx-react-lite'
  5. import { useApp } from '@tldraw/react'
  6. import type { Shape } from '../../lib'
  7. const HistoryStack = observer(function HistoryStack() {
  8. const app = useApp<Shape>()
  9. return (
  10. <div className="fixed left-4 top-4 flex gap-4">
  11. {app.history.stack.map((item, i) => (
  12. <div
  13. style={{
  14. background: app.history.pointer === i ? 'pink' : 'grey',
  15. }}
  16. key={i}
  17. onClick={() => app.history.setPointer(i)}
  18. className="flex items-center rounded-lg p-4"
  19. >
  20. {item.pages[0].nonce}
  21. </div>
  22. ))}
  23. </div>
  24. )
  25. })
  26. export const StatusBar = observer(function StatusBar() {
  27. const app = useApp<Shape>()
  28. React.useEffect(() => {
  29. const canvas = document.querySelector<HTMLElement>('.logseq-tldraw-wrapper .tl-canvas')
  30. const actionBar = document.querySelector<HTMLElement>('.logseq-tldraw-wrapper .tl-action-bar')
  31. if (canvas) {
  32. canvas.style.height = 'calc(100% - 32px)'
  33. }
  34. if (actionBar) {
  35. actionBar.style.marginBottom = '32px'
  36. }
  37. return () => {
  38. if (canvas) {
  39. canvas.style.height = '100%'
  40. }
  41. if (actionBar) {
  42. actionBar.style.marginBottom = '0px'
  43. }
  44. }
  45. })
  46. return (
  47. <div className="tl-statusbar">
  48. <HistoryStack />
  49. {app.selectedTool.id} | {app.selectedTool.currentState.id}
  50. <div style={{ flex: 1 }} />
  51. <div id="tl-statusbar-anchor" style={{ display: 'flex' }} />
  52. </div>
  53. )
  54. })