Skip to content

Commit

Permalink
feat: add icon to BlockStyleDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon committed May 10, 2024
1 parent c43ccf4 commit c150712
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const allowedKeys = [
'validation',
]
const allowedMarkKeys = ['decorators', 'annotations']
const allowedStyleKeys = ['blockEditor', 'title', 'value', 'component']
const allowedStyleKeys = ['blockEditor', 'title', 'value', 'icon', 'component']
const allowedDecoratorKeys = ['blockEditor', 'title', 'value', 'icon', 'component']
const allowedListKeys = ['title', 'value', 'icon', 'component']
const supportedBuiltInObjectTypes = ['file', 'image', 'object', 'reference']
Expand Down
32 changes: 32 additions & 0 deletions packages/@sanity/schema/test/validation/validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {describe, expect, test} from '@jest/globals'
import {SquareIcon} from '@sanity/icons'
import {flatten} from 'lodash'

import {validateSchema} from '../../src/sanity/validateSchema'
Expand Down Expand Up @@ -171,4 +172,35 @@ describe('Validation test', () => {
helpId: 'schema-array-of-type-builtin-type-conflict',
})
})

test('accepts blocks with a style icon', () => {
const schemaDef = [
{
name: 'testBlock',
type: 'block',
styles: [{icon: SquareIcon, title: 'Normal text', value: 'normal'}],
},
]

const validation = validateSchema(schemaDef).get('testBlock')
const validationErrors = validation._problems.filter(
(problem: any) => problem.severity === 'error',
)
expect(validationErrors).toHaveLength(0)
})
test('accepts blocks without a style icon', () => {
const schemaDef = [
{
name: 'testBlock',
type: 'block',
styles: [{title: 'Normal text', value: 'normal'}],
},
]

const validation = validateSchema(schemaDef).get('testBlock')
const validationErrors = validation._problems.filter(
(problem: any) => problem.severity === 'error',
)
expect(validationErrors).toHaveLength(0)
})
})
1 change: 1 addition & 0 deletions packages/@sanity/types/src/schema/definition/type/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface BlockStyleDefinition {
title: string
value: string
i18nTitleKey?: string
icon?: ReactNode | ComponentType
}

/**
Expand Down

0 comments on commit c150712

Please sign in to comment.