CommandButtonItem.size is defined in schema but ignored by prebuilt toolbar renderer

Aperta
#875 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start in the toolbar item renderer where a command-button item is turned into a CommandButton element; the payload's bundled snippet passes commandId, documentId, itemId and variant but drops item.size. Then read the CommandButton props type and the icon className line that hardcodes "h-5 w-5". Done means item.size flows through to CommandButton and the button and icon classes change for sm, md and lg, verified by rendering a command-button with size 'lg'.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

CommandButtonItem.size is exposed in the public UI schema type, but the prebuilt toolbar renderer does not pass item.size to the command button component. As a result, setting size: 'sm' | 'md' | 'lg' on a command-button toolbar item has no visual effect.

The icon size is also hardcoded as h-5 w-5, so toolbar icons cannot be resized through the documented schema.

Version

@embedpdf/react-pdf-viewer: 2.15.1
@embedpdf/snippet: 2.15.1

Expected behavior

Given this toolbar item:

{
  type: 'command-button',
  id: 'print-button',
  commandId: 'custom.print',
  variant: 'icon',
  size: 'lg',
}

the rendered button/icon should use the large size.

Actual behavior

The rendered SVG keeps h-5 w-5.

Evidence

The schema supports size:

export interface CommandButtonItem {
    type: 'command-button';
    id: string;
    commandId: string;
    variant?: 'icon' | 'text' | 'icon-text' | 'tab';
    size?: 'sm' | 'md' | 'lg';
}

But the rendered command button props do not include size:

type CommandButtonProps = {
    commandId: string;
    documentId: string;
    variant?: 'icon' | 'text' | 'icon-text' | 'tab';
    itemId?: string;
    className?: string;
};

And the bundled renderer drops item.size:

j(ax, {
  commandId: t.commandId,
  documentId: n,
  itemId: t.id,
  variant: t.variant
})

The icon is hardcoded:

className: pb("h-5 w-5", c.className)

Suggested fix

Pass item.size from the toolbar item renderer into CommandButton, then map the size to button/icon classes.

Pseudo-code:

<CommandButton
    commandId={item.commandId}
    documentId={documentId}
    itemId={item.id}
    variant={item.variant}
    size={item.size}
/>

Then:

type CommandButtonSize = 'sm' | 'md' | 'lg';

const buttonSizeClass: Record<CommandButtonSize, string> = {
    sm: 'p-1',
    md: 'p-1.5',
    lg: 'p-2',
};

const iconSizeClass: Record<CommandButtonSize, string> = {
    sm: 'h-4 w-4',
    md: 'h-5 w-5',
    lg: 'h-8 w-8',
};

Use the mapped classes instead of hardcoded h-5 w-5.

Reproduction

  1. Register a custom command.
  2. Add it to the toolbar schema as a command-button.
  3. Set size: 'lg'.
  4. Observe that the rendered icon remains h-5 w-5.
Lingua principale
TypeScript
Stelle
4.5k
Fork
317
Merge medio
10h 16m
PR unite (30g)
174

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di embedpdf/embed-pdf-viewer

Tutte le issue di embedpdf/embed-pdf-viewer

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.