-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* β¨ Customize studio theme, upgrade sanity for copy/paste #1045 * π Prevent document copy #1045 * π Prevent copy paste on lang #1045
- Loading branch information
Showing
6 changed files
with
990 additions
and
299 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CopyIcon } from '@sanity/icons' | ||
import { Toast, useToast } from '@sanity/ui' | ||
import { useCallback } from 'react' | ||
|
||
import { defineDocumentFieldAction } from 'sanity' | ||
import { useTranslation } from 'sanity' | ||
import { useCopyPaste } from 'sanity' | ||
import { useGetFormValue } from 'sanity' | ||
import { type FormDocumentValue } from 'sanity' | ||
|
||
export const copyAction = defineDocumentFieldAction({ | ||
name: 'copyField', | ||
useAction({ path }) { | ||
const getFormValue = useGetFormValue() | ||
const { onCopy } = useCopyPaste() | ||
const { t } = useTranslation('copy-paste') | ||
|
||
const isDocument = path.length === 0 | ||
|
||
const documentTitle = t('copy-paste.field-action-copy-button.document.title') | ||
const fieldTitle = t('copy-paste.field-action-copy-button.field.title') | ||
const title = isDocument ? documentTitle : fieldTitle | ||
const toast = useToast() | ||
|
||
const onAction = useCallback(() => { | ||
if (path.length === 0) { | ||
toast.push({ | ||
title: 'Cannot copy document', | ||
description: 'Cannot copy document. Use duplicate instead.', | ||
}) | ||
return | ||
} else if (path[0] === 'lang') { | ||
toast.push({ | ||
title: 'Cannot copy language', | ||
description: 'Copying language is not allowed.', | ||
}) | ||
return | ||
} | ||
const value = getFormValue([]) as FormDocumentValue | ||
onCopy(path, value, { | ||
context: { source: isDocument ? 'documentFieldAction' : 'fieldAction' }, | ||
}) | ||
}, [path, isDocument, onCopy, getFormValue]) | ||
|
||
return { | ||
type: 'action', | ||
icon: CopyIcon, | ||
onAction, | ||
title, | ||
} | ||
}, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* To change toggle color of sanity ui | ||
*/ | ||
[data-ui='Switch'] input:checked + * { | ||
--switch-bg-color: #0f9d58 !important; | ||
} |
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.