-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use client'; | ||
|
||
import { ArrowsUpDownIcon } from '@heroicons/react/24/outline'; | ||
import clsx from 'clsx'; | ||
import { BLUR_COMMAND, COMMAND_PRIORITY_LOW } from 'lexical'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { IconButton } from '@/components/common/client/icon-button'; | ||
import { BlockTypeActions } from '@/components/review/client/block-type-actions'; | ||
import { HistoryActions } from '@/components/review/client/history-actions'; | ||
import { TextFormatActions } from '@/components/review/client/text-format-actions'; | ||
|
||
import { useEditable } from '@/context/editor/editable-context'; | ||
import { useEditorRef } from '@/context/editor/editor-ref-context'; | ||
|
||
import { useStickyIOS } from '@/hooks/common/use-sticky-ios'; | ||
|
||
export function EditorStickyToolbar() { | ||
const { isEditable } = useEditable() ?? {}; | ||
|
||
if (isEditable === false) { | ||
return null; | ||
} | ||
|
||
return <EditorToolbarInner />; | ||
} | ||
|
||
function EditorToolbarInner() { | ||
const { handleBlur, stickyRef, wrapperRef } = useStickyIOS(); | ||
|
||
const { editorRef } = useEditorRef() ?? {}; | ||
|
||
const editor = editorRef?.current; | ||
|
||
useEffect(() => { | ||
if (!editor) { | ||
return; | ||
} | ||
|
||
return editor.registerCommand( | ||
BLUR_COMMAND, | ||
() => { | ||
handleBlur(); | ||
return false; | ||
}, | ||
COMMAND_PRIORITY_LOW | ||
); | ||
}, [editor, handleBlur]); | ||
|
||
const [barType, setBarType] = useState<'text' | 'block'>('text'); | ||
|
||
return ( | ||
<div ref={wrapperRef} className="sticky top-[67px] z-20 h-12 w-full bg-white backface-hidden"> | ||
<div | ||
ref={stickyRef} | ||
className="absolute left-0 right-0 p-2 space-x-2 flex border-b z-20 bg-white" | ||
> | ||
<HistoryActions editor={editor} /> | ||
|
||
<IconButton | ||
onClick={() => setBarType((prev) => (prev === 'text' ? 'block' : 'text'))} | ||
icon={<ArrowsUpDownIcon className="w-5" />} | ||
/> | ||
|
||
<div className="relative w-full"> | ||
<div | ||
className={clsx('absolute top-0 transition-all duration-500 w-full', { | ||
'top-0 -translate-y-1/2 opacity-0 pointer-events-none': barType === 'block', | ||
'top-0': barType === 'text', | ||
})} | ||
> | ||
<TextFormatActions editor={editor} /> | ||
</div> | ||
|
||
<div | ||
className={clsx('absolute top-0 transition-all duration-500 w-full', { | ||
'top-0 -translate-y-1/2 opacity-0 pointer-events-none': barType === 'text', | ||
'top-0': barType === 'block', | ||
})} | ||
> | ||
<BlockTypeActions editor={editor} /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |