import {Path, SchemaType} from '@sanity/types' import React, {createElement, CSSProperties} from 'react' import {getChangeVerb, Diff} from '../../diff' import {PreviewComponent} from '../../preview/types' import {DiffCard} from './DiffCard' import {DiffTooltip} from './DiffTooltip' import {FromTo} from './FromTo' interface DiffFromToProps { align?: 'top' | 'center' | 'bottom' cardClassName?: string diff: Diff layout?: 'grid' | 'inline' path?: Path | string previewComponent: PreviewComponent schemaType: SchemaType } const cardStyles: CSSProperties = { flex: 1, minWidth: 0, display: 'block', whiteSpace: 'break-spaces', } export function DiffFromTo(props: DiffFromToProps) { const {align, cardClassName, diff, layout, path, previewComponent, schemaType} = props const {action} = diff const changeVerb = getChangeVerb(diff) if (action === 'unchanged') { return ( {createElement(previewComponent, {schemaType, value: diff.toValue})} ) } const from = diff.fromValue !== undefined && diff.fromValue !== null && ( {createElement(previewComponent, {schemaType, value: diff.fromValue})} ) const to = diff.toValue !== undefined && diff.toValue !== null && ( {createElement(previewComponent, {schemaType, value: diff.toValue})} ) if (from && !to) { return ( {from} ) } if (!from && to) { return ( {to} ) } return ( ) }