AncrelDocumentationv0.3.0

Search documentation

    Playground / fe.unified-diff-block

    UnifiedDiffBlock playground

    Read a unified diff with line numbers, literal operation signs and theme-aware change colors.

    Preview

    --- a/notes.txt
    +++ b/notes.txt
    @@ -1 +1 @@
    -Draft
    +Published

    Example controls

    State matrix

    dark / comfortable
    VariantDefault
    Sample
    --- a/notes.txt
    +++ b/notes.txt
    @@ -1 +1 @@
    -Draft
    +Published

    Published example

    API reference
    'use client'
    
    import { useState } from 'react'
    import { UnifiedDiffBlock, computeClientFileDiffs } from '@ancrel/workspace/diff'
    
    const serverDiff = '--- a/notes.txt\n+++ b/notes.txt\n@@ -1,2 +1,2 @@\n Title\n-First edition\n+Second edition'
    const files = computeClientFileDiffs({ 'notes.txt': 'Title\nFirst edition\n' },
      { 'notes.txt': 'Title\nWorking draft\n' })
    
    export default function App() {
      const [local, setLocal] = useState(false)
      return <>
        <label><input type="checkbox" checked={local} onChange={event => setLocal(event.target.checked)} />
          Show local preview</label>
        <UnifiedDiffBlock label={local ? 'Local preview' : 'Server diff'} diff={local ? files[0].diff : serverDiff} />
      </>
    }