okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221rc1 merge ds-coder (d6a5a7837)4fb068a8c

main
958 B15 linesraw
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 }) {
9  const open = useSelectedPreviewId() === artifact.id;
10  const label = tr(open ? 'Close preview' : 'Open preview');
11  return <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}
12    onClick={() => (open && onClose ? onClose(artifact.id) : onPreview(artifact))}>
13    <Icon name="panel" size={19}/>
14  </button>;
15}