Skip to content

Commit

Permalink
doc(form): add doc and example for components extention of block type (
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Oct 31, 2023
1 parent 4984007 commit 10d1b59
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/sanity/src/core/form/types/definitionExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,35 @@ declare module '@sanity/types' {

export interface BlockDefinition {
/**
* Components for the block schema type
*
* @hidden
* @beta
* @public
* @remarks - This only applies to the block text type, and not block object types (like images).
* - Don't render arbitrary text nodes inside regular text blocks, as this will confuse the editor with
* what is editable text and not. Make sure to wrap all nodes which are NOT part of the edited text inside a
* container with `contentEditable={false}` and with `style={{userSelection: 'none'}}` so that
* the editor can distinguish between editable text and non-editable text.
* @example Example of custom block component with delete button next to it that removes the block.
* ```ts
* {
* block: (blockProps) => {
* return (
* <Flex>
* <Box flex={1}>{blockProps.renderDefault(blockProps)}</Box>
* <Box contentEditable={false} style={{userSelect: 'none'}}>
* <Button
* icon={TrashIcon}
* onClick={(event) => {
* event.preventDefault()
* blockProps.onRemove()
* }}
* />
* </Box>
* </Flex>
* )
* },
* },
* ```
*/
components?: {
block?: ComponentType<BlockProps>
Expand Down

0 comments on commit 10d1b59

Please sign in to comment.