From 3bc6703f33b1dfdeab75fe36eada074d1b0cd0c1 Mon Sep 17 00:00:00 2001 From: swve Date: Sun, 6 Apr 2025 14:58:09 +0200 Subject: [PATCH] feat: enhance ToolbarButtons with improved heading selection and styling --- .../Extensions/Video/VideoBlockComponent.tsx | 24 ++++++---- .../Objects/Editor/Toolbar/ToolbarButtons.tsx | 44 +++++++++++++++---- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/apps/web/components/Objects/Editor/Extensions/Video/VideoBlockComponent.tsx b/apps/web/components/Objects/Editor/Extensions/Video/VideoBlockComponent.tsx index ef07af8f..ad3603c3 100644 --- a/apps/web/components/Objects/Editor/Extensions/Video/VideoBlockComponent.tsx +++ b/apps/web/components/Objects/Editor/Extensions/Video/VideoBlockComponent.tsx @@ -1,4 +1,5 @@ -import { NodeViewWrapper } from '@tiptap/react' +import { NodeViewProps, NodeViewWrapper } from '@tiptap/react' +import { Node } from '@tiptap/core' import { Loader2, Video, Upload, X, HelpCircle, Maximize2, Minimize2, ArrowLeftRight, @@ -133,23 +134,30 @@ interface VideoBlockObject { size: VideoSize } -interface VideoBlockProps { - node: { - attrs: { - blockObject: VideoBlockObject | LegacyVideoBlockObject | null +interface VideoBlockAttrs { + blockObject: VideoBlockObject | LegacyVideoBlockObject | null +} + +interface VideoBlockExtension { + options: { + activity: { + activity_uuid: string } } - extension: { +} + +interface ExtendedNodeViewProps extends Omit { + extension: Node & { options: { activity: { activity_uuid: string } } } - updateAttributes: (attrs: { blockObject: VideoBlockObject | null }) => void } -function VideoBlockComponent({ node, extension, updateAttributes }: VideoBlockProps) { +function VideoBlockComponent(props: ExtendedNodeViewProps) { + const { node, extension, updateAttributes } = props const org = useOrg() as Organization | null const course = useCourse() as Course | null const editorState = useEditorProvider() as EditorState diff --git a/apps/web/components/Objects/Editor/Toolbar/ToolbarButtons.tsx b/apps/web/components/Objects/Editor/Toolbar/ToolbarButtons.tsx index d79a547b..320d36b7 100644 --- a/apps/web/components/Objects/Editor/Toolbar/ToolbarButtons.tsx +++ b/apps/web/components/Objects/Editor/Toolbar/ToolbarButtons.tsx @@ -116,14 +116,24 @@ export const ToolbarButtons = ({ editor, props }: any) => { - editor - .chain() - .focus() - .toggleHeading({ level: parseInt(e.target.value) }) - .run() + value={ + editor.isActive('heading', { level: 1 }) ? "1" : + editor.isActive('heading', { level: 2 }) ? "2" : + editor.isActive('heading', { level: 3 }) ? "3" : + editor.isActive('heading', { level: 4 }) ? "4" : + editor.isActive('heading', { level: 5 }) ? "5" : + editor.isActive('heading', { level: 6 }) ? "6" : "0" } + onChange={(e) => { + const value = e.target.value; + if (value === "0") { + editor.chain().focus().setParagraph().run(); + } else { + editor.chain().focus().toggleHeading({ level: parseInt(value) }).run(); + } + }} > + @@ -351,13 +361,31 @@ const ToolSelect = styled.select` display: flex; background: rgba(217, 217, 217, 0.185); border-radius: 6px; - width: 100px; + width: 120px; border: none; height: 25px; - padding: 5px; + padding: 2px 5px; font-size: 11px; font-family: 'DM Sans'; margin-right: 5px; + cursor: pointer; + appearance: none; + -webkit-appearance: none; + -moz-appearance: none; + background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); + background-repeat: no-repeat; + background-position: right 5px center; + background-size: 12px; + padding-right: 20px; + + &:hover { + background-color: rgba(217, 217, 217, 0.3); + } + + &:focus { + outline: none; + box-shadow: 0 0 0 2px rgba(217, 217, 217, 0.5); + } ` const TableMenuWrapper = styled.div`