Merge pull request #1223 from buster-so/big-nate-bus-1991-add-caption-doesnt-change-to-remove-caption-until-you-type

copy change when open
This commit is contained in:
Nate Kelley 2025-09-30 13:47:13 -06:00 committed by GitHub
commit 6d951e1d9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import {
import type { VariantProps } from 'class-variance-authority'; import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority'; import { cva } from 'class-variance-authority';
import type { TElement } from 'platejs'; import type { TElement } from 'platejs';
import { usePluginOption } from 'platejs/react';
import type * as React from 'react'; import type * as React from 'react';
import { Button } from '@/components/ui/buttons'; import { Button } from '@/components/ui/buttons';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
@ -49,11 +50,12 @@ export function CaptionTextarea(props: React.ComponentProps<typeof CaptionTextar
export const CaptionButton = (props: React.ComponentProps<typeof Button>) => { export const CaptionButton = (props: React.ComponentProps<typeof Button>) => {
const captionButtonState = useCaptionButtonState(); const captionButtonState = useCaptionButtonState();
const visibleId = usePluginOption(CaptionPlugin, 'visibleId');
const hasCaption = (captionButtonState.element?.caption as TElement[])?.length > 0; const element = captionButtonState.element;
const isOpen = visibleId === element.id;
const hasCaption = (captionButtonState.element?.caption as TElement[]) !== undefined || isOpen;
const text = hasCaption ? NodeTypeLabels.removeCaption.label : NodeTypeLabels.addCaption.label; const text = hasCaption ? NodeTypeLabels.removeCaption.label : NodeTypeLabels.addCaption.label;
const editor = captionButtonState.editor; const editor = captionButtonState.editor;
const element = captionButtonState.element;
const addCaption = () => { const addCaption = () => {
const path = editor.api.findPath(element); const path = editor.api.findPath(element);

View File

@ -72,10 +72,6 @@ export function MetricToolbar({
onOpenAutoFocus={(e) => e.preventDefault()} onOpenAutoFocus={(e) => e.preventDefault()}
> >
<div className="box-content flex items-center space-x-2"> <div className="box-content flex items-center space-x-2">
{/* <Button onClick={onOpenEdit} variant="ghost">
{NodeTypeLabels.editMetric?.label}
</Button> */}
<CaptionButton /> <CaptionButton />
<Separator orientation="vertical" className=" h-6" /> <Separator orientation="vertical" className=" h-6" />