Skip to content

Commit

Permalink
[desk-tool] Add placeholder boolean field diff component
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent 305e16d commit 971e5e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@sanity/desk-tool/src/diffs/BooleanFieldDiff.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.root {
}
29 changes: 29 additions & 0 deletions packages/@sanity/desk-tool/src/diffs/BooleanFieldDiff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {useUserColorManager} from '@sanity/base'
import {BooleanDiff} from '@sanity/diff'
import React from 'react'
import {Annotation} from '../panes/documentPane/history/types'
import {AnnotationTooltip} from './annotationTooltip'
import {getAnnotationColor} from './helpers'
import {DiffComponent} from './types'

import styles from './BooleanFieldDiff.css'

export const BooleanFieldDiff: DiffComponent<BooleanDiff<Annotation>> = ({diff}) => {
const userColorManager = useUserColorManager()
const {fromValue, toValue, annotation} = diff
const color = getAnnotationColor(userColorManager, annotation)

return (
<AnnotationTooltip annotation={annotation}>
<div className={styles.root} style={{background: color.bg, color: color.fg}}>
{fromValue !== undefined && (
<>
<input type="checkbox" checked={fromValue} readOnly />
<span>&rarr;</span>
</>
)}
<input type="checkbox" checked={toValue} readOnly />
</div>
</AnnotationTooltip>
)
}
4 changes: 3 additions & 1 deletion packages/@sanity/desk-tool/src/diffs/defaultComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {NumberFieldDiff} from './NumberFieldDiff'
import {StringFieldDiff} from './StringFieldDiff'
import {ReferenceFieldDiff} from './ReferenceFieldDiff'
import {ImageFieldDiff} from './ImageFieldDiff'
import {BooleanFieldDiff} from './BooleanFieldDiff'

export const defaultComponents: {[key: string]: DiffComponent<any>} = {
string: StringFieldDiff,
number: NumberFieldDiff,
reference: ReferenceFieldDiff,
image: ImageFieldDiff
image: ImageFieldDiff,
boolean: BooleanFieldDiff
}

0 comments on commit 971e5e8

Please sign in to comment.