okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
1import { tr } from '../lib/i18n' ; 2import { cx } from '../lib/format' ; 3import { Icon } from './ui' ; 4import { useSelectedPreviewId } from '../lib/code-preview' ; 5import type { PreviewArtifact } from '../lib/artifacts' ; 6 7/** The preview control of a code block: an icon button like Copy, on its left. It shows both states: closed, and open (filled, "Close preview"). */ 8export function CodePreviewBtn ({ artifact, onPreview, onClose} :{ artifact :PreviewArtifact ; onPreview :( a :PreviewArtifact ) => void ; onClose ?:( id :string ) => void }) { 9const open = useSelectedPreviewId () === artifact . id ; 10const label = tr ( open ?'Close preview' :'Open preview' ); 11return < button type = "button" className = { cx ( 'st-btn st-btn--icon' , open && 'is-open' )} data-open = { open || undefined } aria-pressed = { open } aria-label = { label } title = { label } 12onClick = {() => ( open && onClose ?onClose ( artifact . id ) :onPreview ( artifact ))}> 13< Icon name = "panel" size = { 19 }/> 14</ button >; 15}