-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add callout node as per design along with its button #2803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahtesham-quraish
wants to merge
6
commits into
main
Choose a base branch
from
ahtesham/quote-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08c03a6
add quote node as per design along with its button
b90b26e
Merge branch 'main' into ahtesham/quote-branch
14e8692
add paragraph after quote node
432b14d
merge with main
dfe8972
add callout node
72005a1
remove blockquote node
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
frontends/ol-components/src/components/TiptapEditor/extensions/node/Quote/Quote.ts
This file contains hidden or 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,17 @@ | ||
| import Blockquote from "@tiptap/extension-blockquote" | ||
|
|
||
| export const Quote = Blockquote.extend({ | ||
| name: "quote", | ||
|
|
||
| parseHTML() { | ||
| return [ | ||
| { tag: "quote" }, // Custom tag | ||
| { tag: "blockquote" }, // Fallback for pasted content | ||
| ] | ||
| }, | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| renderHTML({ HTMLAttributes }: { HTMLAttributes: { [key: string]: any } }) { | ||
| return ["quote", HTMLAttributes, 0] | ||
| }, | ||
| }) | ||
114 changes: 114 additions & 0 deletions
114
frontends/ol-components/src/components/TiptapEditor/extensions/ui/Quote/QuoteButton.tsx
This file contains hidden or 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,114 @@ | ||
| import React, { forwardRef, useCallback } from "react" | ||
|
|
||
| // --- Tiptap UI --- | ||
| import type { UseQuoteConfig } from "./" | ||
| import { QUOTE_SHORTCUT_KEY, useQuote } from "./" | ||
|
|
||
| // --- Hooks --- | ||
| import { useTiptapEditor } from "../../../vendor/hooks/use-tiptap-editor" | ||
|
|
||
| // --- Lib --- | ||
| import { parseShortcutKeys } from "../../../vendor/lib/tiptap-utils" | ||
|
|
||
| // --- UI Primitives --- | ||
| import type { ButtonProps } from "../../../vendor/components/tiptap-ui-primitive/button" | ||
| import { Button } from "../../../vendor/components/tiptap-ui-primitive/button" | ||
| import { Badge } from "../../../vendor/components/tiptap-ui-primitive/badge" | ||
|
|
||
| export interface QuoteButtonProps | ||
| extends Omit<ButtonProps, "type">, | ||
| UseQuoteConfig { | ||
| /** | ||
| * Optional text to display alongside the icon. | ||
| */ | ||
| text?: string | ||
| /** | ||
| * Optional show shortcut keys in the button. | ||
| * @default false | ||
| */ | ||
| showShortcut?: boolean | ||
| } | ||
|
|
||
| export function QuoteShortcutBadge({ | ||
| shortcutKeys = QUOTE_SHORTCUT_KEY, | ||
| }: { | ||
| shortcutKeys?: string | ||
| }) { | ||
| return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge> | ||
| } | ||
|
|
||
| /** | ||
| * Button component for toggling blockquote in a Tiptap editor. | ||
| * | ||
| * For custom button implementations, use the `useQuote` hook instead. | ||
| */ | ||
| export const QuoteButton = forwardRef<HTMLButtonElement, QuoteButtonProps>( | ||
| ( | ||
| { | ||
| editor: providedEditor, | ||
| text, | ||
| hideWhenUnavailable = false, | ||
| onToggled, | ||
| showShortcut = false, | ||
| onClick, | ||
| children, | ||
| ...buttonProps | ||
| }, | ||
| ref, | ||
| ) => { | ||
| const { editor } = useTiptapEditor(providedEditor) | ||
| const { | ||
| isVisible, | ||
| canToggle, | ||
| isActive, | ||
| handleToggle, | ||
| label, | ||
| shortcutKeys, | ||
| Icon, | ||
| } = useQuote({ | ||
| editor, | ||
| hideWhenUnavailable, | ||
| onToggled, | ||
| }) | ||
|
|
||
| const handleClick = useCallback( | ||
| (event: React.MouseEvent<HTMLButtonElement>) => { | ||
| onClick?.(event) | ||
| if (event.defaultPrevented) return | ||
| handleToggle() | ||
| }, | ||
| [handleToggle, onClick], | ||
| ) | ||
|
|
||
| if (!isVisible) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <Button | ||
| type="button" | ||
| data-style="ghost" | ||
| data-active-state={isActive ? "on" : "off"} | ||
| tabIndex={-1} | ||
| disabled={!canToggle} | ||
| data-disabled={!canToggle} | ||
| aria-label={label} | ||
| aria-pressed={isActive} | ||
| tooltip="Quote" | ||
| onClick={handleClick} | ||
| {...buttonProps} | ||
| ref={ref} | ||
| > | ||
| {children ?? ( | ||
| <> | ||
| <Icon className="tiptap-button-icon" /> | ||
| {text && <span className="tiptap-button-text">{text}</span>} | ||
| {showShortcut && <QuoteShortcutBadge shortcutKeys={shortcutKeys} />} | ||
| </> | ||
| )} | ||
| </Button> | ||
| ) | ||
| }, | ||
| ) | ||
|
|
||
| QuoteButton.displayName = "QuoteButton" |
2 changes: 2 additions & 0 deletions
2
frontends/ol-components/src/components/TiptapEditor/extensions/ui/Quote/index.tsx
This file contains hidden or 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,2 @@ | ||
| export * from "./QuoteButton" | ||
| export * from "./useQuote" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment: Let's stick to regular / valid HTML tags unless there's a very good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are adding a custom tag because it would not be possible to reliably distinguish it from other regular HTML tags. Even Tiptap uses the
<blockquote>tag to represent its default quote behavior.To give a simple example: when we need to insert a paragraph after a quote node, we must be able to clearly identify what type of node it is. If we used a regular
<div>tag, it could conflict with other<div>elements used elsewhere, making it difficult to determine the correct context.Using a dedicated tag avoids these conflicts and allows us to handle quote-specific behavior more reliably.