-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PULSE-42] feat: text alignment for all editors (#5847)
* feat: text alignment for editors * fix: text alignment types * fix: build errors * fix: build error * fix: toolbar movement post alignment selection * fix: callout type * fix: image node types * chore: add ts error warning
- Loading branch information
Showing
27 changed files
with
641 additions
and
324 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
91 changes: 91 additions & 0 deletions
91
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx
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,91 @@ | ||
import { Editor } from "@tiptap/core"; | ||
import { AlignCenter, AlignLeft, AlignRight, LucideIcon } from "lucide-react"; | ||
// components | ||
import { TextAlignItem } from "@/components/menus"; | ||
// helpers | ||
import { cn } from "@/helpers/common"; | ||
// types | ||
import { TEditorCommands } from "@/types"; | ||
|
||
type Props = { | ||
editor: Editor; | ||
onClose: () => void; | ||
}; | ||
|
||
export const TextAlignmentSelector: React.FC<Props> = (props) => { | ||
const { editor, onClose } = props; | ||
|
||
const menuItem = TextAlignItem(editor); | ||
|
||
const textAlignmentOptions: { | ||
itemKey: TEditorCommands; | ||
renderKey: string; | ||
icon: LucideIcon; | ||
command: () => void; | ||
isActive: () => boolean; | ||
}[] = [ | ||
{ | ||
itemKey: "text-align", | ||
renderKey: "text-align-left", | ||
icon: AlignLeft, | ||
command: () => | ||
menuItem.command({ | ||
alignment: "left", | ||
}), | ||
isActive: () => | ||
menuItem.isActive({ | ||
alignment: "left", | ||
}), | ||
}, | ||
{ | ||
itemKey: "text-align", | ||
renderKey: "text-align-center", | ||
icon: AlignCenter, | ||
command: () => | ||
menuItem.command({ | ||
alignment: "center", | ||
}), | ||
isActive: () => | ||
menuItem.isActive({ | ||
alignment: "center", | ||
}), | ||
}, | ||
{ | ||
itemKey: "text-align", | ||
renderKey: "text-align-right", | ||
icon: AlignRight, | ||
command: () => | ||
menuItem.command({ | ||
alignment: "right", | ||
}), | ||
isActive: () => | ||
menuItem.isActive({ | ||
alignment: "right", | ||
}), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div className="flex gap-0.5 px-2"> | ||
{textAlignmentOptions.map((item) => ( | ||
<button | ||
key={item.renderKey} | ||
type="button" | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
item.command(); | ||
onClose(); | ||
}} | ||
className={cn( | ||
"size-7 grid place-items-center rounded text-custom-text-300 hover:bg-custom-background-80 active:bg-custom-background-80 transition-colors", | ||
{ | ||
"bg-custom-background-80 text-custom-text-100": item.isActive(), | ||
} | ||
)} | ||
> | ||
<item.icon className="size-4" /> | ||
</button> | ||
))} | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.