-
Notifications
You must be signed in to change notification settings - Fork 5
feat(apollo-wind): add PromptEditor component [MST-10659] #784
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
fikewa-olatunji
wants to merge
7
commits into
main
Choose a base branch
from
feat/apollo-wind-prompt-editor
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c83a7ce
feat(apollo-wind): add PromptEditor component
fikewa-olatunji e69ae8e
fix(apollo-wind): address PromptEditor PR review feedback
fikewa-olatunji 8cc3431
chore(repo): exempt lexical from dep-version-consistency check
fikewa-olatunji cecde50
fix(apollo-wind): address PromptEditor review feedback (autocomplete …
fikewa-olatunji 368ac01
test(apollo-wind): cover PromptEditor serialization/autocomplete/equa…
fikewa-olatunji 527ff0a
fix(apollo-wind): drop redundant .sb-story preview-head override
fikewa-olatunji 4bd9882
fix(apollo-react): align lexical to 0.42 and drop dep-consistency exe…
fikewa-olatunji 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
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
159 changes: 159 additions & 0 deletions
159
packages/apollo-wind/src/components/ui/prompt-editor/components/EditorToolbar.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,159 @@ | ||
| import { Bold, Italic, List, ListOrdered, Maximize2, Strikethrough } from 'lucide-react'; | ||
| import { cn } from '@/lib'; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; | ||
| import type { PromptEditorMode, PromptEditorToolbarActionsRef } from '../types'; | ||
|
|
||
| export interface EditorToolbarProps { | ||
| mode: PromptEditorMode; | ||
| onModeChange: (mode: PromptEditorMode) => void; | ||
| disabled?: boolean; | ||
| actionsRef?: React.RefObject<PromptEditorToolbarActionsRef | null>; | ||
| onFullscreen?: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Toolbar formatting button: 28×28 px tap target, 4 px border-radius, 14 px lucide icon. | ||
| */ | ||
| const ToolbarButton = ({ | ||
| icon: Icon, | ||
| label, | ||
| disabled, | ||
| onClick, | ||
| }: { | ||
| icon: React.ComponentType<{ className?: string }>; | ||
| label: string; | ||
| disabled?: boolean; | ||
| onClick?: () => void; | ||
| }) => ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <button | ||
| type="button" | ||
| aria-label={label} | ||
| disabled={disabled} | ||
| onClick={onClick} | ||
| className={cn( | ||
| 'inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground', | ||
| 'hover:bg-accent hover:text-accent-foreground', | ||
| 'disabled:opacity-50 disabled:pointer-events-none' | ||
| )} | ||
| > | ||
| <Icon className="h-3.5 w-3.5" /> | ||
| </button> | ||
| </TooltipTrigger> | ||
| <TooltipContent side="bottom"> | ||
| <span className="text-xs">{label}</span> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
|
|
||
| const ToolbarSeparator = () => <span aria-hidden className="mx-1 h-4 w-px bg-border/60" />; | ||
|
|
||
| export const EditorToolbar = ({ | ||
| mode, | ||
| onModeChange, | ||
| disabled, | ||
| actionsRef, | ||
| onFullscreen, | ||
| }: EditorToolbarProps) => { | ||
| const isEditMode = mode === 'edit'; | ||
|
|
||
| const handleFormat = (actionName: keyof PromptEditorToolbarActionsRef) => () => { | ||
| if (!disabled && isEditMode) { | ||
| const fn = actionsRef?.current?.[actionName]; | ||
| if (typeof fn === 'function') fn(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| // No bottom border on the toolbar itself — the separator is drawn by the absolute hairline | ||
| // `<span>` below at full width so the L/R outlines stay continuous with the editor body's | ||
| // `border-t-0` border underneath. | ||
| className="relative flex items-center justify-between gap-1 overflow-hidden rounded-t-md border border-b-0 bg-background px-2 py-1" | ||
| data-testid="editor-toolbar" | ||
| > | ||
| <span | ||
| aria-hidden | ||
| data-testid="editor-toolbar-separator" | ||
| className="pointer-events-none absolute bottom-0 left-0 h-px w-full bg-border/40" | ||
| /> | ||
| {/* Left: Edit/Preview mode switcher */} | ||
| <div className="flex items-center gap-1 shrink-0"> | ||
| <div className="flex items-center rounded-md bg-muted p-0.5"> | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| 'rounded px-2 py-0.5 text-[11px] font-semibold transition-colors', | ||
| mode === 'edit' ? 'bg-primary/20 text-primary' : 'text-foreground hover:bg-accent' | ||
| )} | ||
| disabled={disabled} | ||
| onClick={() => onModeChange('edit')} | ||
| > | ||
| Edit | ||
| </button> | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| 'rounded px-2 py-0.5 text-[11px] font-semibold transition-colors', | ||
| mode === 'preview' ? 'bg-primary/20 text-primary' : 'text-foreground hover:bg-accent' | ||
| )} | ||
| disabled={disabled} | ||
| onClick={() => onModeChange('preview')} | ||
| > | ||
| Preview | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Right: formatting cluster (Bold/Italic/Strike) → list cluster (Numbered/Bullet) → Expand. */} | ||
| <div className="flex items-center gap-0.5 overflow-hidden"> | ||
| <ToolbarButton | ||
| icon={Bold} | ||
| label="Bold" | ||
| disabled={disabled || !isEditMode} | ||
| onClick={handleFormat('formatBold')} | ||
| /> | ||
| <ToolbarButton | ||
| icon={Italic} | ||
| label="Italic" | ||
| disabled={disabled || !isEditMode} | ||
| onClick={handleFormat('formatItalic')} | ||
| /> | ||
| <ToolbarButton | ||
| icon={Strikethrough} | ||
| label="Strikethrough" | ||
| disabled={disabled || !isEditMode} | ||
| onClick={handleFormat('formatStrikethrough')} | ||
| /> | ||
|
|
||
| <ToolbarSeparator /> | ||
|
|
||
| <ToolbarButton | ||
| icon={ListOrdered} | ||
| label="Numbered List" | ||
| disabled={disabled || !isEditMode} | ||
| onClick={handleFormat('formatNumberedList')} | ||
| /> | ||
| <ToolbarButton | ||
| icon={List} | ||
| label="Bulleted List" | ||
| disabled={disabled || !isEditMode} | ||
| onClick={handleFormat('formatBulletedList')} | ||
| /> | ||
|
|
||
| {onFullscreen && ( | ||
| <> | ||
| <ToolbarSeparator /> | ||
| <ToolbarButton | ||
| icon={Maximize2} | ||
| label="Expand" | ||
| disabled={disabled} | ||
| onClick={onFullscreen} | ||
| /> | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.