-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[field] Expose annotated tooltip components, refactor diff components
- Loading branch information
Showing
25 changed files
with
401 additions
and
319 deletions.
There are no files selected for viewing
61 changes: 0 additions & 61 deletions
61
packages/@sanity/desk-tool/src/diffs/annotationTooltip/annotationTooltip.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/@sanity/desk-tool/src/diffs/annotationTooltip/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 10 additions & 19 deletions
29
packages/@sanity/desk-tool/src/diffs/boolean/BooleanFieldDiff.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,19 @@ | ||
import {useUserColorManager} from '@sanity/base/user-color' | ||
import React from 'react' | ||
import {DiffComponent, BooleanDiff} from '@sanity/field/diff' | ||
import {AnnotationTooltip} from '../annotationTooltip' | ||
import {getAnnotationColor} from '../helpers' | ||
|
||
import {DiffComponent, BooleanDiff, DiffAnnotation} from '@sanity/field/diff' | ||
import styles from './BooleanFieldDiff.css' | ||
|
||
export const BooleanFieldDiff: DiffComponent<BooleanDiff> = ({diff}) => { | ||
const userColorManager = useUserColorManager() | ||
const {fromValue, toValue} = diff | ||
const annotation = diff.isChanged ? diff.annotation : null | ||
const color = getAnnotationColor(userColorManager, annotation) | ||
|
||
return ( | ||
<AnnotationTooltip annotation={annotation}> | ||
<div className={styles.root} style={{background: color.background, color: color.text}}> | ||
{fromValue !== undefined && fromValue !== null && ( | ||
<input type="checkbox" checked={fromValue} readOnly /> | ||
)} | ||
{diff.action === 'changed' && <span>→</span>} | ||
{toValue !== undefined && toValue !== null && ( | ||
<input type="checkbox" checked={toValue} readOnly /> | ||
)} | ||
</div> | ||
</AnnotationTooltip> | ||
<DiffAnnotation as="div" className={styles.root} diff={diff}> | ||
{fromValue !== undefined && fromValue !== null && ( | ||
<input type="checkbox" checked={fromValue} readOnly /> | ||
)} | ||
{diff.action === 'changed' && <span>→</span>} | ||
{toValue !== undefined && toValue !== null && ( | ||
<input type="checkbox" checked={toValue} readOnly /> | ||
)} | ||
</DiffAnnotation> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 10 additions & 23 deletions
33
packages/@sanity/desk-tool/src/diffs/number/NumberFieldDiff.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,20 @@ | ||
import React from 'react' | ||
import {useUserColorManager} from '@sanity/base/user-color' | ||
import {DiffComponent, NumberDiff} from '@sanity/field/diff' | ||
import {AnnotationTooltip} from '../annotationTooltip' | ||
import {getAnnotationColor} from '../helpers' | ||
import {DiffComponent, NumberDiff, DiffAnnotation} from '@sanity/field/diff' | ||
|
||
import styles from './NumberFieldDiff.css' | ||
|
||
export const NumberFieldDiff: DiffComponent<NumberDiff> = ({diff}) => { | ||
const userColorManager = useUserColorManager() | ||
const {fromValue, toValue} = diff | ||
const annotation = diff.isChanged ? diff.annotation : null | ||
const color = getAnnotationColor(userColorManager, annotation) | ||
|
||
const inlineStyle = { | ||
background: color.background, | ||
color: color.text | ||
} | ||
|
||
return ( | ||
<AnnotationTooltip annotation={annotation}> | ||
<div className={styles.root}> | ||
{fromValue !== undefined && ( | ||
<> | ||
<del style={inlineStyle}>{fromValue}</del> | ||
<span>→</span> | ||
</> | ||
)} | ||
<ins style={inlineStyle}>{toValue}</ins> | ||
</div> | ||
</AnnotationTooltip> | ||
<DiffAnnotation as="div" className={styles.root} diff={diff}> | ||
{fromValue !== undefined && ( | ||
<> | ||
<del>{fromValue}</del> | ||
<span>→</span> | ||
</> | ||
)} | ||
<ins>{toValue}</ins> | ||
</DiffAnnotation> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.